[PATCH 00/23] kvm: introduce KVMCPUOps

Alex Bennée posted 23 patches 1 month ago
Failed in applying to current master (apply log)
docs/specs/acpi_hest_ghes.rst           |   3 +-
configs/targets/aarch64-softmmu.mak     |   1 -
configs/targets/i386-softmmu.mak        |   1 -
configs/targets/loongarch64-softmmu.mak |   1 -
configs/targets/ppc-softmmu.mak         |   1 -
configs/targets/ppc64-softmmu.mak       |   1 -
configs/targets/riscv64-softmmu.mak     |   1 -
configs/targets/s390x-softmmu.mak       |   1 -
configs/targets/x86_64-softmmu.mak      |   1 -
include/accel/kvm/cpu-ops.h             | 171 ++++++++++++++++++++++
include/hw/core/cpu.h                   |   3 +
include/system/kvm.h                    |  42 +-----
include/system/kvm_int.h                |   2 -
target/i386/kvm/kvm_i386.h              |  20 +++
accel/kvm/kvm-accel-ops.c               |  13 +-
accel/kvm/kvm-all.c                     | 183 +++++++++++++++++-------
accel/tcg/cpu-exec.c                    |   2 +-
hw/i386/kvm/xen_evtchn.c                |   6 +-
hw/intc/openpic_kvm.c                   |   4 +-
hw/intc/spapr_xive_kvm.c                |  10 +-
hw/intc/xics_kvm.c                      |   6 +-
target/arm/kvm.c                        |  96 +++++++------
target/i386/kvm/kvm-cpu.c               |  26 +++-
target/i386/kvm/kvm.c                   |  42 +++---
target/loongarch/cpu.c                  |   8 +-
target/loongarch/kvm/kvm.c              |  96 ++++++-------
target/ppc/kvm.c                        |  75 +++++-----
target/riscv/kvm/kvm-cpu.c              |  95 +++++-------
target/s390x/kvm/kvm.c                  |  89 +++++++-----
29 files changed, 628 insertions(+), 372 deletions(-)
create mode 100644 include/accel/kvm/cpu-ops.h
[PATCH 00/23] kvm: introduce KVMCPUOps
Posted by Alex Bennée 1 month ago
There is a world coming where we can have a KVM interface which
supports multiple architectures. The old style approach of using
linking to resolve per arch kvm_arch_foo handlers won't scale and is
also slightly antithetical to the flexible not-quite object orientated
way we do things in QEMU.

Taking TCGCpuOps as a reference this implements KVMCpuOps as the
shared function dispatcher for CPU specific KVM operations.

A couple of open questions:

  - should we consider some sort of shared AccelInfo region for
  CPUState instead of a bunch of mutually unused bits
  - how can we improve coverage of KVM testing?

The main driver for writing:

  Message-ID: <20261019192704.3220373-1-alex.bennee@linaro.org>
  Date: Mon, 19 Oct 2026 20:26:45 +0100
  Subject: [PATCH v3 00/19] testing/next: functional testing updates for gdb (pre-PR)
  From: =?UTF-8?q?Alex=20Benn=C3=A9e?= <alex.bennee@linaro.org>

was so I could be sure the KVMCpuOps where properly working. I don't
think we have that much that exercises KVM in our CI system anyway
because most runners don't give access to HW virtualisation. I have
tested this on:

  - x86_64 (on my dev box)
  - aarch64 (on my personal dev box and the aarch64 ci machine)
  - s390x (on devcloud instance, same as the s390x runner)

Notably I wasn't able to test the riscv64, loongarch64 or ppc64
behaviour. I do have access to the OSUL ppc runner but it doesn't
support nested virt and testing on that machine needs some love anyway
(see #3207).

Anyway I await your discussion ;-)

Alex.

Alex Bennée (23):
  accel: introduce KVMAccelClass and KVMCPUOps
  target/i386: wire up empty KVMAccelCPUClass
  target/ppc: wire up empty KVMAccelCPUClass
  target/riscv: wire up empty KVMAccelCPUClass
  target/arm: wire up empty KVMAccelCPUClass
  target/s390x: wire up empty KVMAccelCPUClass
  target/loongarch: wire up empty KVMAccelCPUClass
  accel/kvm: port kvm_arch_pre_run to KVMCPUOps
  accel/kvm: port kvm_arch_post_run to KVMCPUOps
  accel/kvm: port kvm_arch_handle_exit to KVMCPUOps
  accel/kvm: port kvm_arch_process_async_events to KVMCPUOps
  accel/kvm: port kvm_arch_[put|get]_registers to KVMCPUOps
  accel/kvm: port kvm_arch_pre_create_vcpu to KVMCPUOps
  accel/kvm: port kvm_arch_init_vcpu to KVMCPUOps
  accel/kvm: port kvm_arch_destroy_vcpu to KVMCPUOps
  accel/kvm: port kvm_arch_vpcu_id to KVMCPUOps
  accel/kvm: port kvm_arch_update_guest_debug to KVMCPUOps
  accel/kvm: port kvm_arch_[insert|remove]_hw_breakpoints to KVMCPUOps
  accel/kvm: remove TARGET_KVM_HAVE_GUEST_DEBUG
  accel/kvm: port kvm_arch_stop_on_emulation_error to KVMCPUOps
  accel/kvm: port kvm_arch_on_sigbus_vcpu to KVMCPUOps
  accel/kvm: cache KVMCPUOps
  accel/kvm: remove redundant ops checks for kvm_get_cpu_ops

 docs/specs/acpi_hest_ghes.rst           |   3 +-
 configs/targets/aarch64-softmmu.mak     |   1 -
 configs/targets/i386-softmmu.mak        |   1 -
 configs/targets/loongarch64-softmmu.mak |   1 -
 configs/targets/ppc-softmmu.mak         |   1 -
 configs/targets/ppc64-softmmu.mak       |   1 -
 configs/targets/riscv64-softmmu.mak     |   1 -
 configs/targets/s390x-softmmu.mak       |   1 -
 configs/targets/x86_64-softmmu.mak      |   1 -
 include/accel/kvm/cpu-ops.h             | 171 ++++++++++++++++++++++
 include/hw/core/cpu.h                   |   3 +
 include/system/kvm.h                    |  42 +-----
 include/system/kvm_int.h                |   2 -
 target/i386/kvm/kvm_i386.h              |  20 +++
 accel/kvm/kvm-accel-ops.c               |  13 +-
 accel/kvm/kvm-all.c                     | 183 +++++++++++++++++-------
 accel/tcg/cpu-exec.c                    |   2 +-
 hw/i386/kvm/xen_evtchn.c                |   6 +-
 hw/intc/openpic_kvm.c                   |   4 +-
 hw/intc/spapr_xive_kvm.c                |  10 +-
 hw/intc/xics_kvm.c                      |   6 +-
 target/arm/kvm.c                        |  96 +++++++------
 target/i386/kvm/kvm-cpu.c               |  26 +++-
 target/i386/kvm/kvm.c                   |  42 +++---
 target/loongarch/cpu.c                  |   8 +-
 target/loongarch/kvm/kvm.c              |  96 ++++++-------
 target/ppc/kvm.c                        |  75 +++++-----
 target/riscv/kvm/kvm-cpu.c              |  95 +++++-------
 target/s390x/kvm/kvm.c                  |  89 +++++++-----
 29 files changed, 628 insertions(+), 372 deletions(-)
 create mode 100644 include/accel/kvm/cpu-ops.h

-- 
2.47.3


Re: [PATCH 00/23] kvm: introduce KVMCPUOps
Posted by Alex Bennée 1 month ago
Alex Bennée <alex.bennee@linaro.org> writes:

> There is a world coming where we can have a KVM interface which
> supports multiple architectures. The old style approach of using
> linking to resolve per arch kvm_arch_foo handlers won't scale and is
> also slightly antithetical to the flexible not-quite object orientated
> way we do things in QEMU.

In case it's not obvious I intended the prefix to be RFC as it needs
discussion ;-)

-- 
Alex Bennée
Virtualisation Tech Lead @ Linaro
Re: [PATCH 00/23] kvm: introduce KVMCPUOps
Posted by Paolo Bonzini 1 month ago
On 10/20/26 13:21, Alex Bennée wrote:
> Alex Bennée <alex.bennee@linaro.org> writes:
> 
>> There is a world coming where we can have a KVM interface which
>> supports multiple architectures. The old style approach of using
>> linking to resolve per arch kvm_arch_foo handlers won't scale and is
>> also slightly antithetical to the flexible not-quite object orientated
>> way we do things in QEMU.
> 
> In case it's not obvious I intended the prefix to be RFC as it needs
> discussion ;-)
This generally seems like a good idea, but would this be needed for the 
arm-on-s390 support?  Would it use the "single binary" support or would 
there be simply two system emulators with KVM support, 
qemu-system-aarch64 and qemu-system-s390x?

Thanks,

Paolo


Re: [PATCH 00/23] kvm: introduce KVMCPUOps
Posted by Cornelia Huck 1 month ago
On Wed, Oct 21 2026, Paolo Bonzini <pbonzini@redhat.com> wrote:

> On 10/20/26 13:21, Alex Bennée wrote:
>> Alex Bennée <alex.bennee@linaro.org> writes:
>> 
>>> There is a world coming where we can have a KVM interface which
>>> supports multiple architectures. The old style approach of using
>>> linking to resolve per arch kvm_arch_foo handlers won't scale and is
>>> also slightly antithetical to the flexible not-quite object orientated
>>> way we do things in QEMU.
>> 
>> In case it's not obvious I intended the prefix to be RFC as it needs
>> discussion ;-)
> This generally seems like a good idea, but would this be needed for the 
> arm-on-s390 support?  Would it use the "single binary" support or would 
> there be simply two system emulators with KVM support, 
> qemu-system-aarch64 and qemu-system-s390x?

What would make the most sense logically to me is to use
qemu-system-aarch64 to launch an aarch64 machine and qemu-system-s390x
to launch an s390x machine (at least from an user perspective.) That
said, I haven't looked at this series yet, but it does sound like a good
idea in general regardless of how we plan to launch different arch guests.
Re: [PATCH 00/23] kvm: introduce KVMCPUOps
Posted by Andreas Grapentin 1 month ago
On Oct 22 26, Cornelia Huck wrote:
> What would make the most sense logically to me is to use
> qemu-system-aarch64 to launch an aarch64 machine and qemu-system-s390x
> to launch an s390x machine (at least from an user perspective.) That
> said, I haven't looked at this series yet, but it does sound like a good
> idea in general regardless of how we plan to launch different arch guests.

Just to clarify -- nobody has any intention of using anything other than
qemu-system-aarch64 to start aarch64 guests, especially not
qemu-system-s390x. What we are doing for arm64-on-s390 KVM is enable KVM
accel for qemu-system-aarch64 on s390x hosts, alongside the KVM accel
for qemu-system-s390x.

that being said, if it were ever the case that qemu-system-s390x and
qemu-system-aarch64 were the same binary (which is what I understand
qemu is moving towards) then this would require that single binary to
understand both s390x and aarch64 flavours of KVM, warts and all.

There is another technical challenge in all of this, which is how the
qemu build can consume the arm64 KVM uapi when built on and for an s390x
host. I'm hoping that this will also be a lot easier to do if the
surface of the KVM architecture details is contained behind a KVMCpuOps
structure.

Best,
-A