RFC Allow using KVM UAPI headers for mixed architectures
Get series with b4
b4 am [email protected]Versions newest first
- v1 RFC Latest8 patches 2 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/8 | hw/hyperv: Move hyperv.c to specific_sshw/ | +1 | 0 replies | |
| 2/8 | kvm: Add header dependency in system/kvm.h explicitlyinclude/ | +1 | 0 replies | |
| 3/8 | kvm: Prefer including "system/kvm.h" over <linux/kvm.h>accel/ accel/ backends/ +24 more | +10 | 0 replies | |
| 4/8 | scripts/update-linux-headers: Post-process KVM UAPI kernel headersscripts/ | +41 | 0 replies | |
| 5/8 | scripts/update-linux-headers: Vendor hwcap.h and ptrace.h for arm64scripts/ | +2 | 0 replies | |
| 6/8 | linux-headers: Update to post-processed KVM headerslinux-headers/ linux-headers/ linux-headers/ +8 more | +518 | 0 replies | |
| 7/8 | kvm: Adjust system/kvm.h for updated KVM kernel headersinclude/ | +8 | 0 replies | |
| 8/8 | kvm: Explicitly include ARM-specific KVM UAPI headersinclude/ | +5 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [RFC 0/8] Allow using KVM UAPI headers for mixed architectures
Recently, there has been made efforts in the Linux kernel [to bring arm64 KVM to the s390 platform][1]. In part, this is done by sharing the ARM kernel headers with s390 code. Similarly, it is expected that any userspace application on S390 will pull in the ARM KVM UAPI headers to get access to ARM-related API definitions.
[1]: https://lore.kernel.org/all/[email protected]
QEMU, as of now, has one implicit assumption when building KVM-enabled
code: the host architecture is equal to the guest (target) architecture. This is enforced by symlinking the vendored kernel headers in linux-headers to the corresponding architecture of the host CPU at configure-time. The KVM API is included via <linux/kvm.h> which in turn pulls in architecture-specific definitions from <asm/kvm.h> from the forementioned linked directory.
This approach does not work in a mixed-architecture build, i.e. building KVM-accelerated ARM CPU virtualisation on an s390 host.
This RFC suggests one possible solution by trying to split off the architecture-specific definitions in <asm/kvm.h> from the generic definitions in <linux/kvm.h> and allowing QEMU code directly to include architecture-specific definitions based on the compiled target. For common code, QEMU stubs the architecture-specific definitions in the KVM API and poisons them for direct use.
This requires some rearranging of header files. This is peformed by a series of steps:
0. The first two patches do some housekeeping that arose as a fallout from the rest of the patches.
1. We declare the already existing include file "system/kvm.h" for the preferred entry point to the KVM API, allowing us to consolidate the architecture-specific handling at a single origin.
2. We need to adjust the vendored kernel headers for KVM. One part is that we need to split off the architecture-specific defintions from generic definitions. We can do this by simply removing the include of <asm/kvm.h> in <linux/kvm.h> and require QEMU source code to include the relevant <asm/kvm.h> manually.
The other part is to adjust include paths of transient dependencies to refer explicitly to the architecture they do belong to. For example, on ARM, <asm/linux.h> includes <asm/ptrace.h>. We need to change those includes to refer to "asm-arm64/ptrace.h". This is unproblematic, since we should never expect that individual kernel files are mixed within architectures.
3. Now we can extent "system/kvm.h" with the logic required to pull in the parts of the KVM API that is needed in the source code. For target-specific code which requires definitions from the architecture-specific KVM API, we make this selection based on the TARGET_* macros. For common code which should only ever required generic definitions from the KVM API, we stub the architecture-specific definitions and just include the stripped <linux/kvm.h>.
This allows for example to build a native qemu-system-arm64 binary on an s390 host with ARM KVM acceleration as demonstrated by the last patch (which is not considered part of this RFC).
Tree: https://github.ibm.com/linuxonz/qemu/tree/canton/kvm-uapi-header-changes/rfc
Bjoern Walk (8):
hw/hyperv: move hyperv.c to specific_ss
include: add header dependencies explicitly
Prefer including "system/kvm.h" over <linux/kvm.h> scripts/update-linux-headers: Post-process KVM UAPI kernel headers scripts/update-linux-headers: Vendor hwcap.h and ptrace.h for arm64
linux-headers: Update to post-processed KVM headers
kvm: Adjust system/kvm.h for updated KVM kernel headers
include: Explicitly include ARM-specific KVM UAPI headers
Nina Schoetterl-Glausch (1):
meson: enable aarch64 KVM target on s390x host
accel/kvm/kvm-accel-ops.c | 1 - accel/kvm/kvm-all.c | 2 +- backends/hostmem-memfd.c | 1 - hw/hyperv/hyperv.c | 1 - hw/hyperv/meson.build | 2 +- hw/i386/kvm/clock.c | 1 - hw/i386/kvm/i8254.c | 1 - hw/i386/kvm/xen_evtchn.c | 1 - hw/i386/kvm/xen_overlay.c | 1 - hw/intc/loongarch_dintc_kvm.c | 2 +- hw/intc/loongarch_extioi_kvm.c | 1 - hw/s390x/s390-pci-kvm.c | 2 +- hw/vfio/kvm-helpers.c | 1 - hw/vfio/kvm-spapr.c | 2 +- include/system/kvm.h | 14 + linux-headers/asm-arm64/hwcap.h | 159 ++++++++++++ linux-headers/asm-arm64/kvm.h | 4 +- linux-headers/asm-arm64/ptrace.h | 337 +++++++++++++++++++++++++ linux-headers/asm-arm64/unistd.h | 2 +- linux-headers/asm-loongarch/unistd.h | 6 +- linux-headers/asm-mips/unistd.h | 8 +- linux-headers/asm-powerpc/unistd.h | 4 +- linux-headers/asm-riscv/kvm.h | 4 +- linux-headers/asm-riscv/unistd.h | 6 +- linux-headers/asm-s390/unistd.h | 2 +- linux-headers/linux/kvm.h | 5 +- meson.build | 2 +- scripts/update-linux-headers.sh | 63 +++-- target/arm/kvm-consts.h | 3 +- target/arm/kvm.c | 2 - target/i386/kvm/kvm.c | 2 +- target/i386/kvm/kvm_i386.h | 2 - target/i386/sev.c | 1 - target/loongarch/cpu.c | 3 - target/loongarch/kvm/kvm.c | 1 - target/ppc/kvm.c | 2 - target/riscv/kvm/kvm-cpu.c | 2 - target/s390x/kvm/kvm.c | 2 +- target/s390x/kvm/pv.c | 2 - tests/qtest/migration/framework.c | 2 +- tests/qtest/migration/migration-util.c | 2 +- 41 files changed, 588 insertions(+), 73 deletions(-) create mode 100644 linux-headers/asm-arm64/hwcap.h create mode 100644 linux-headers/asm-arm64/ptrace.h
Signature · 1 line
2.56.0