[PATCH RFC v4 0/9] Add loongarch kvm accel support

xianglai li posted 9 patches 7 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/cover.1696841645.git.lixianglai@loongson.cn
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Cornelia Huck <cohuck@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Thomas Huth <thuth@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Song Gao <gaosong@loongson.cn>, Xiaojuan Yang <yangxiaojuan@loongson.cn>
There is a newer version of this series
linux-headers/asm-loongarch/kvm.h | 100 +++++
linux-headers/linux/kvm.h         |   9 +
meson.build                       |   3 +
target/loongarch/cpu.c            |  23 +-
target/loongarch/cpu.h            |   6 +-
target/loongarch/kvm-stub.c       |  11 +
target/loongarch/kvm.c            | 594 ++++++++++++++++++++++++++++++
target/loongarch/kvm_loongarch.h  |  13 +
target/loongarch/meson.build      |   1 +
target/loongarch/trace-events     |  17 +
target/loongarch/trace.h          |   1 +
11 files changed, 772 insertions(+), 6 deletions(-)
create mode 100644 linux-headers/asm-loongarch/kvm.h
create mode 100644 target/loongarch/kvm-stub.c
create mode 100644 target/loongarch/kvm.c
create mode 100644 target/loongarch/kvm_loongarch.h
create mode 100644 target/loongarch/trace-events
create mode 100644 target/loongarch/trace.h
[PATCH RFC v4 0/9] Add loongarch kvm accel support
Posted by xianglai li 7 months, 1 week ago
This series add loongarch kvm support, mainly implement
some interfaces used by kvm such as kvm_arch_get/set_regs,
kvm_arch_handle_exit, kvm_loongarch_set_interrupt, etc.

Currently, we are able to boot LoongArch KVM Linux Guests.
In loongarch VM, mmio devices and iocsr devices are emulated
in user space such as APIC, IPI, pci devices, etc, other
hardwares such as MMU, timer and csr are emulated in kernel.

It is based on temporarily unaccepted linux kvm:
https://github.com/loongson/linux-loongarch-kvm
And We will remove the RFC flag until the linux kvm patches
are merged.

The running environment of LoongArch virt machine:
1. Get the linux source by the above mentioned link.
   git checkout kvm-loongarch
   make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- loongson3_defconfig
   make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu-
2. Get the qemu source: https://github.com/loongson/qemu
   git checkout kvm-loongarch
   ./configure --target-list="loongarch64-softmmu"  --enable-kvm
   make
3. Get uefi bios of LoongArch virt machine:
   Link: https://github.com/tianocore/edk2-platforms/tree/master/Platform/Loongson/LoongArchQemuPkg#readme
4. Also you can access the binary files we have already build:
   https://github.com/yangxiaojuan-loongson/qemu-binary

The command to boot loongarch virt machine:
   $ qemu-system-loongarch64 -machine virt -m 4G -cpu la464 \
   -smp 1 -bios QEMU_EFI.fd -kernel vmlinuz.efi -initrd ramdisk \
   -serial stdio   -monitor telnet:localhost:4495,server,nowait \
   -append "root=/dev/ram rdinit=/sbin/init console=ttyS0,115200" \
   --nographic

Changes for RFC v4:
1. Added function interfaces kvm_loongarch_get_cpucfg and
kvm_loongarch_put_cpucfg for passing the value of vcpu cfg to kvm.
Move the macro definition KVM_IOC_CSRID from kvm.c to kvm.h.
2.Delete the duplicate CSR_CPUID field in CPUArchState.
3.Add kvm_arch_get_default_type function in kvm.c.
4.Disable LSX,LASX in cpucfg2 in KVM. And disable LBT in cpucfg2 in KVM.

Changes for RFC v3:
1. Move the init mp_state to KVM_MP_STATE_RUNNABLE function into kvm.c.
2. Fix some unstandard code problems in kvm_get/set_regs_ioctl, such as
sort loongarch to keep alphabetic ordering in meson.build, gpr[0] should
be always 0, remove unnecessary inline statement, etc.
3. Rename the counter_value variable to kvm_state_counter in cpu_env,
and add comments for it to explain the meaning.

Changes for RFC v2:
1. Mark the "Add KVM headers for loongarch" patch as a placeholder,
as we will use the update-linux-headers.sh to generate the kvm headers
when the linux loongarch KVM patch series are accepted.
2. Remove the DPRINTF macro in kvm.c and use trace events to replace
it, we add some trace functions such as trace_kvm_handle_exit,
trace_kvm_set_intr, trace_kvm_failed_get_csr, etc.
3. Remove the unused functions in kvm_stub.c and move stub function into
the suitable patch.

Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Cornelia Huck <cohuck@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>
Cc: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: Thomas Huth <thuth@redhat.com>
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: Richard Henderson <richard.henderson@linaro.org>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Bibo Mao <maobibo@loongson.cn>
Cc: Song Gao <gaosong@loongson.cn>
Cc: Xiaojuan Yang <yangxiaojuan@loongson.cn>
Cc: Tianrui Zhao <zhaotianrui@loongson.cn>

Tianrui Zhao (9):
  linux-headers: Add KVM headers for loongarch
  target/loongarch: Define some kvm_arch interfaces
  target/loongarch: Supplement vcpu env initial when vcpu reset
  target/loongarch: Implement kvm get/set registers
  target/loongarch: Implement kvm_arch_init function
  target/loongarch: Implement kvm_arch_init_vcpu
  target/loongarch: Implement kvm_arch_handle_exit
  target/loongarch: Implement set vcpu intr for kvm
  target/loongarch: Add loongarch kvm into meson build

 linux-headers/asm-loongarch/kvm.h | 100 +++++
 linux-headers/linux/kvm.h         |   9 +
 meson.build                       |   3 +
 target/loongarch/cpu.c            |  23 +-
 target/loongarch/cpu.h            |   6 +-
 target/loongarch/kvm-stub.c       |  11 +
 target/loongarch/kvm.c            | 594 ++++++++++++++++++++++++++++++
 target/loongarch/kvm_loongarch.h  |  13 +
 target/loongarch/meson.build      |   1 +
 target/loongarch/trace-events     |  17 +
 target/loongarch/trace.h          |   1 +
 11 files changed, 772 insertions(+), 6 deletions(-)
 create mode 100644 linux-headers/asm-loongarch/kvm.h
 create mode 100644 target/loongarch/kvm-stub.c
 create mode 100644 target/loongarch/kvm.c
 create mode 100644 target/loongarch/kvm_loongarch.h
 create mode 100644 target/loongarch/trace-events
 create mode 100644 target/loongarch/trace.h

-- 
2.39.1


Re: [PATCH RFC v4 0/9] Add loongarch kvm accel support
Posted by Philippe Mathieu-Daudé 7 months ago
Hi,

On 9/10/23 11:01, xianglai li wrote:
> This series add loongarch kvm support, mainly implement
> some interfaces used by kvm such as kvm_arch_get/set_regs,
> kvm_arch_handle_exit, kvm_loongarch_set_interrupt, etc.
> 
> Currently, we are able to boot LoongArch KVM Linux Guests.
> In loongarch VM, mmio devices and iocsr devices are emulated
> in user space such as APIC, IPI, pci devices, etc, other
> hardwares such as MMU, timer and csr are emulated in kernel.
> 
> It is based on temporarily unaccepted linux kvm:
> https://github.com/loongson/linux-loongarch-kvm
> And We will remove the RFC flag until the linux kvm patches
> are merged.
> 
> The running environment of LoongArch virt machine:
> 1. Get the linux source by the above mentioned link.
>     git checkout kvm-loongarch
>     make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- loongson3_defconfig
>     make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu-
> 2. Get the qemu source: https://github.com/loongson/qemu
>     git checkout kvm-loongarch
>     ./configure --target-list="loongarch64-softmmu"  --enable-kvm
>     make
> 3. Get uefi bios of LoongArch virt machine:
>     Link: https://github.com/tianocore/edk2-platforms/tree/master/Platform/Loongson/LoongArchQemuPkg#readme
> 4. Also you can access the binary files we have already build:
>     https://github.com/yangxiaojuan-loongson/qemu-binary
> 
> The command to boot loongarch virt machine:
>     $ qemu-system-loongarch64 -machine virt -m 4G -cpu la464 \
>     -smp 1 -bios QEMU_EFI.fd -kernel vmlinuz.efi -initrd ramdisk \
>     -serial stdio   -monitor telnet:localhost:4495,server,nowait \
>     -append "root=/dev/ram rdinit=/sbin/init console=ttyS0,115200" \
>     --nographic

2 years ago Song helped with an access to a LoongArch 3a5000 machine but
it stopped working (IP was x.242.206.180).

Would it be possible to add a Loongarch64 runner to our CI
(ideally with KVM support, but that can come later)? See:
https://www.qemu.org/docs/master/devel/ci.html#jobs-on-custom-runners

Regards,

Phil.
Re: [PATCH RFC v4 0/9] Add loongarch kvm accel support
Posted by lixianglai 7 months ago
Hi Philippe Mathieu-Daudé :
> Hi,
>
> On 9/10/23 11:01, xianglai li wrote:
>> This series add loongarch kvm support, mainly implement
>> some interfaces used by kvm such as kvm_arch_get/set_regs,
>> kvm_arch_handle_exit, kvm_loongarch_set_interrupt, etc.
>>
>> Currently, we are able to boot LoongArch KVM Linux Guests.
>> In loongarch VM, mmio devices and iocsr devices are emulated
>> in user space such as APIC, IPI, pci devices, etc, other
>> hardwares such as MMU, timer and csr are emulated in kernel.
>>
>> It is based on temporarily unaccepted linux kvm:
>> https://github.com/loongson/linux-loongarch-kvm
>> And We will remove the RFC flag until the linux kvm patches
>> are merged.
>>
>> The running environment of LoongArch virt machine:
>> 1. Get the linux source by the above mentioned link.
>>     git checkout kvm-loongarch
>>     make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu- 
>> loongson3_defconfig
>>     make ARCH=loongarch CROSS_COMPILE=loongarch64-unknown-linux-gnu-
>> 2. Get the qemu source: https://github.com/loongson/qemu
>>     git checkout kvm-loongarch
>>     ./configure --target-list="loongarch64-softmmu" --enable-kvm
>>     make
>> 3. Get uefi bios of LoongArch virt machine:
>>     Link: 
>> https://github.com/tianocore/edk2-platforms/tree/master/Platform/Loongson/LoongArchQemuPkg#readme
>> 4. Also you can access the binary files we have already build:
>>     https://github.com/yangxiaojuan-loongson/qemu-binary
>>
>> The command to boot loongarch virt machine:
>>     $ qemu-system-loongarch64 -machine virt -m 4G -cpu la464 \
>>     -smp 1 -bios QEMU_EFI.fd -kernel vmlinuz.efi -initrd ramdisk \
>>     -serial stdio   -monitor telnet:localhost:4495,server,nowait \
>>     -append "root=/dev/ram rdinit=/sbin/init console=ttyS0,115200" \
>>     --nographic
>
> 2 years ago Song helped with an access to a LoongArch 3a5000 machine but
> it stopped working (IP was x.242.206.180).
>
> Would it be possible to add a Loongarch64 runner to our CI
> (ideally with KVM support, but that can come later)? See:
> https://www.qemu.org/docs/master/devel/ci.html#jobs-on-custom-runners
>

Ok, Song Gao will rebuild the Loongarch64 runner environment in the next 
few days,

and we will publish it to the community as soon as it is completed.

Thanks,

Xianglai.



> Regards,
>
> Phil.