Allow using KVM UAPI headers for mixed architectures
Subsystems (4)
cover 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
RFC PATCH 1/8 hw/hyperv: Move hyperv.c to specific_ss
hyperv_set_event_flag_handler() uses a symbol (KVM_HYPERV_EVENTFD_DEASSIGN) from the architecture-specific KVM UAPI header file and therefore is target-dependent code.
Move this file to the target-dependent sourceset specific_ss.
--- hw/hyperv/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/hyperv/meson.build +1 -1
@@ -1,4 +1,4 @@ -system_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c')) +specific_ss.add(when: 'CONFIG_HYPERV', if_true: files('hyperv.c')) system_ss.add(when: 'CONFIG_HYPERV_TESTDEV', if_true: files('hyperv_testdev.c')) system_ss.add(when: 'CONFIG_VMBUS', if_true: files('vmbus.c')) system_ss.add(when: 'CONFIG_SYNDBG', if_true: files('syndbg.c'))
Signature · 1 line
2.56.0
RFC PATCH 2/8 kvm: Add header dependency in system/kvm.h explicitly
In reply to Bjoern WalkThe target-specific code in system/kvm.h requires definitions from hw/core/cpu.h (technichally exec/vaddr.h for vaddr and qemu/queue.h for QTAILQ_ENTRY).
Add the dependency explicitly to avoid headaches with unknown type names later on.
--- include/system/kvm.h | 1 + 1 file changed, 1 insertion(+)
include/system/kvm.h +1 -0
@@ -222,6 +222,7 @@ void kvm_irqchip_change_notify(void);#ifdef COMPILING_PER_TARGET #include "cpu.h" +#include "hw/core/cpu.h" /** * kvm_update_guest_debug(): ensure KVM debug structures updated
Signature · 1 line
2.56.0
RFC PATCH 3/8 kvm: Prefer including "system/kvm.h" over <linux/kvm.h>
In reply to Bjoern Walk"system/kvm.h" provides scaffolding around usage of KVM definitions from <linux/kvm.h> and can act as the central include for KVM-related definitions.
--- accel/kvm/kvm-accel-ops.c | 1 - accel/kvm/kvm-all.c | 2 +- backends/hostmem-memfd.c | 1 - hw/hyperv/hyperv.c | 1 - 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 | 1 - 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 | 1 + 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 +- 27 files changed, 10 insertions(+), 33 deletions(-)
accel/kvm/kvm-accel-ops.c +0 -1
@@ -25,7 +25,6 @@#include "qemu/guest-random.h" #include "qapi/error.h" -#include <linux/kvm.h> #include "kvm-cpus.h" static void *kvm_vcpu_thread_fn (void *arg)
accel/kvm/kvm-all.c +1 -1
@@ -17,7 +17,7 @@#include <sys/ioctl.h> #include <poll.h> -#include <linux/kvm.h> +#include "system/kvm.h" #include "qemu/atomic.h" #include "qemu/option.h"
backends/hostmem-memfd.c +0 -1
@@ -20,7 +20,6 @@#include "qom/object.h" #include "migration/cpr.h" #include "system/kvm.h" -#include <linux/kvm.h> #include "qapi/qapi-type-infos-common.h" OBJECT_DECLARE_SIMPLE_TYPE (HostMemoryBackendMemfd,MEMORY_BACKEND_MEMFD )
hw/hyperv/hyperv.c +0 -1
@@ -15,7 +15,6 @@#include "system/memory.h" #include "exec/target_page.h" #include "exec/cpu-common.h" -#include "linux/kvm.h" #include "system/kvm.h" #include "system/physmem.h" #include "qemu/bitops.h"
hw/i386/kvm/clock.c +0 -1
@@ -27,7 +27,6 @@#include "exec/cpu-common.h" #include "qapi/error.h" -#include <linux/kvm.h> #include "qom/object.h" #define TYPE_KVM_CLOCK "kvmclock"
hw/i386/kvm/i8254.c +0 -1
@@ -24,7 +24,6 @@*/ #include "qemu/osdep.h" -#include <linux/kvm.h> #include "qapi/qapi-types-machine.h" #include "qapi/error.h" #include "qemu/module.h"
hw/i386/kvm/xen_evtchn.c +0 -1
@@ -43,7 +43,6 @@#include "system/kvm.h" #include "system/kvm_xen.h" -#include <linux/kvm.h> #include <sys/eventfd.h> #include "hw/xen/interface/memory.h"
hw/i386/kvm/xen_overlay.c +0 -1
@@ -25,7 +25,6 @@#include "system/kvm.h" #include "system/kvm_xen.h" -#include <linux/kvm.h> #include "hw/xen/interface/memory.h"
hw/intc/loongarch_dintc_kvm.c +0 -1
@@ -7,7 +7,6 @@#include "qemu/osdep.h" #include "hw/intc/loongarch_dintc.h" -#include "linux/kvm.h" #include "qapi/error.h" #include "system/kvm.h"
hw/intc/loongarch_extioi_kvm.c +0 -1
@@ -7,7 +7,6 @@#include "qemu/osdep.h" #include "hw/intc/loongarch_extioi.h" -#include "linux/kvm.h" #include "qapi/error.h" #include "system/kvm.h"
hw/s390x/s390-pci-kvm.c +1 -1
@@ -11,7 +11,7 @@#include "qemu/osdep.h" -#include <linux/kvm.h> +#include "system/kvm.h" #include "kvm/kvm_s390x.h" #include "target/s390x/kvm/pv.h"
hw/vfio/kvm-helpers.c +0 -1
@@ -21,7 +21,6 @@#include "qemu/osdep.h" #include <sys/ioctl.h> -#include <linux/kvm.h> #include "system/kvm.h" #include "exec/cpu-common.h" #include "hw/vfio/vfio-device.h"
hw/vfio/kvm-spapr.c +1 -1
@@ -7,7 +7,7 @@#include "qemu/osdep.h" #include <sys/ioctl.h> #include <linux/vfio.h> -#include <linux/kvm.h> +#include "system/kvm.h" #include "hw/vfio/vfio-container-legacy.h" #include "hw/vfio/kvm-spapr.h"
include/system/kvm.h +1 -0
@@ -29,6 +29,7 @@# endif #else # define CONFIG_KVM_IS_POSSIBLE +# include <linux/kvm.h> #endif #ifdef CONFIG_KVM_IS_POSSIBLE
target/arm/kvm-consts.h +2 -1
@@ -14,9 +14,10 @@#ifndef ARM_KVM_CONSTS_H #define ARM_KVM_CONSTS_H +#include "system/kvm.h" +#ifdef COMPILING_PER_TARGET #ifdef CONFIG_KVM -#include <linux/kvm.h> #include <linux/psci.h> #define MISMATCH_CHECK (X ,Y ) QEMU_BUILD_BUG_ON(X != Y)#endif
target/arm/kvm.c +0 -2
@@ -13,8 +13,6 @@#include "qemu/osdep.h" #include <sys/ioctl.h> -#include <linux/kvm.h> -#include "qemu/timer.h" #include "qemu/error-report.h" #include "qemu/main-loop.h"
target/i386/kvm/kvm.c +1 -1
@@ -24,7 +24,7 @@#include <sys/syscall.h> #include <sys/resource.h> -#include <linux/kvm.h> +#include "system/kvm.h" #include <linux/kvm_para.h> #include "standard-headers/asm-x86/kvm_para.h" #include "hw/xen/interface/arch-x86/cpuid.h"
target/i386/kvm/kvm_i386.h +0 -2
@@ -44,8 +44,6 @@ void kvm_request_xsave_components(X86CPU *cpu, uint64_t mask); #ifdef CONFIG_KVM -#include <linux/kvm.h> - typedef struct KvmCpuidInfo { struct kvm_cpuid2 cpuid; struct kvm_cpuid_entry2 entries[KVM_MAX_CPUID_ENTRIES];
target/i386/sev.c +0 -1
@@ -13,7 +13,6 @@#include "qemu/osdep.h" -#include <linux/kvm.h> #include <linux/kvm_para.h> #include <linux/psp-sev.h>
target/loongarch/cpu.c +0 -3
@@ -25,9 +25,6 @@#include "system/reset.h" #endif #include "vec.h" -#ifdef CONFIG_KVM -#include <linux/kvm.h> -#endif #include "tcg/tcg_loongarch.h" #include "disas/capstone.h"
target/loongarch/kvm/kvm.c +0 -1
@@ -8,7 +8,6 @@#include "qemu/osdep.h" #include "exec/target_long.h" #include <sys/ioctl.h> -#include <linux/kvm.h> #include "asm-loongarch/kvm_para.h" #include "qapi/error.h" #include "qemu/timer.h"
target/ppc/kvm.c +0 -2
@@ -19,8 +19,6 @@#include <sys/ioctl.h> #include <sys/vfs.h> -#include <linux/kvm.h> -#include "qapi/error.h" #include "qemu/error-report.h" #include "cpu.h"
target/riscv/kvm/kvm-cpu.c +0 -2
@@ -20,8 +20,6 @@#include <sys/ioctl.h> #include <sys/prctl.h> -#include <linux/kvm.h> -#include "qemu/timer.h" #include "qapi/error.h" #include "qapi/qapi-builtin-type-infos.h"
target/s390x/kvm/kvm.c +1 -1
@@ -21,7 +21,7 @@#include "qemu/osdep.h" #include <sys/ioctl.h> -#include <linux/kvm.h> +#include "system/kvm.h" #include <asm/ptrace.h> #include "cpu.h"
target/s390x/kvm/pv.c +0 -2
@@ -11,8 +11,6 @@*/ #include "qemu/osdep.h" -#include <linux/kvm.h> -#include "qemu/units.h" #include "qapi/error.h" #include "qemu/error-report.h"
tests/qtest/migration/framework.c +1 -1
@@ -27,7 +27,7 @@#include "qemu/sockets.h" #ifdef CONFIG_LINUX -#include <linux/kvm.h> +#include "system/kvm.h" #include <sys/ioctl.h> #endif
tests/qtest/migration/migration-util.c +1 -1
@@ -35,7 +35,7 @@/* For dirty ring test; so far only x86_64 is supported */ #if defined(__linux__) && defined(HOST_X86_64 ) -#include "linux/kvm.h" +#include "system/kvm.h" #endif GQueue *tests;
Signature · 1 line
2.56.0
RFC PATCH 4/8 scripts/update-linux-headers: Post-process KVM UAPI kernel headers
In reply to Bjoern WalkTo give QEMU more control over the selection of KVM UAPI architecture, we need to post-process the kernel headers.
First, we need to make the paths of transient include dependencies explicitly refer to the architecture they belong to. This change doesn't affect anything and is safe, since it is never sensible to mix UAPI header files from different architectures.
Second, we need to drop the include of <asm/kvm.h> in <linux/kvm.h> so that we can delegate the inclusion of architecture-dependent UAPI headers to the QEMU source code (in "system/kvm.h"). This change makes <linux/kvm.h> defunct by itself, so we guard it from being included at compile time.
--- scripts/update-linux-headers.sh | 60 ++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 19 deletions(-)
scripts/update-linux-headers.sh +41 -19
@@ -46,6 +46,20 @@ if [ -z "$output" ]; then output="$PWD" fi +cp_asm() { + f=$1 + to=$2 + + if test -z "$arch"; then + exit 2 + fi + + header=$(basename "$f"); + + sed -e '/\#include/s/<asm\/\([^>]*\)>/"asm-'$arch'\/\1"/' \ + $f > "$to/$header" +} + cp_portable() { f=$1 to=$2
@@ -132,7 +146,7 @@ for arch in $ARCHLIST; do mkdir -p "$output/linux-headers/asm-$arch" for header in kvm.h unistd.h bitsperlong.h mman.h; do if test -f "$hdrdir/include/asm/$header"; then - cp "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch" + cp_asm "$hdrdir/include/asm/$header" "$output/linux-headers/asm-$arch" elif test -f "$hdrdir/include/asm-generic/$header"; then # not installed as <asm/$header>, but used as such in kernel sources cat <<EOF >$output/linux-headers/asm-$arch/$header
@@ -142,30 +156,30 @@ EOF done if [ $arch = mips ]; then - cp "$hdrdir/include/asm/sgidefs.h" "$output/linux-headers/asm-mips/" - cp "$hdrdir/include/asm/unistd_o32.h" "$output/linux-headers/asm-mips/" - cp "$hdrdir/include/asm/unistd_n32.h" "$output/linux-headers/asm-mips/" - cp "$hdrdir/include/asm/unistd_n64.h" "$output/linux-headers/asm-mips/" + cp_asm "$hdrdir/include/asm/sgidefs.h" "$output/linux-headers/asm-mips/" + cp_asm "$hdrdir/include/asm/unistd_o32.h" "$output/linux-headers/asm-mips/" + cp_asm "$hdrdir/include/asm/unistd_n32.h" "$output/linux-headers/asm-mips/" + cp_asm "$hdrdir/include/asm/unistd_n64.h" "$output/linux-headers/asm-mips/" fi if [ $arch = powerpc ]; then - cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-powerpc/" - cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/" + cp_asm "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-powerpc/" + cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-powerpc/" fi rm -rf "$output/include/standard-headers/asm-$arch" mkdir -p "$output/include/standard-headers/asm-$arch" if [ $arch = s390 ]; then cp_portable "$hdrdir/include/asm/virtio-ccw.h" "$output/include/standard-headers/asm-s390/" - cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-s390/" + cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-s390/" fi if [ $arch = arm64 ]; then - cp "$hdrdir/include/asm/sve_context.h" "$output/linux-headers/asm-arm64/" - cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-arm64/" + cp_asm "$hdrdir/include/asm/sve_context.h" "$output/linux-headers/asm-arm64/" + cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-arm64/" fi if [ $arch = x86 ]; then - cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-x86/" - cp "$hdrdir/include/asm/unistd_x32.h" "$output/linux-headers/asm-x86/" - cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-x86/" + cp_asm "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-x86/" + cp_asm "$hdrdir/include/asm/unistd_x32.h" "$output/linux-headers/asm-x86/" + cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-x86/" cp_portable "$hdrdir/include/asm/kvm_para.h" "$output/include/standard-headers/asm-$arch" cat <<EOF >$output/linux-headers/asm-$arch/kvm_para.h
@@ -182,20 +196,28 @@ EOF "$output/include/standard-headers/asm-x86" fi if [ $arch = riscv ]; then - cp "$hdrdir/include/asm/ptrace.h" "$output/linux-headers/asm-riscv/" - cp "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-riscv/" - cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-riscv/" + cp_asm "$hdrdir/include/asm/ptrace.h" "$output/linux-headers/asm-riscv/" + cp_asm "$hdrdir/include/asm/unistd_32.h" "$output/linux-headers/asm-riscv/" + cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-riscv/" fi if [ $arch = loongarch ]; then - cp "$hdrdir/include/asm/kvm_para.h" "$output/linux-headers/asm-loongarch/" - cp "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-loongarch/" + cp_asm "$hdrdir/include/asm/kvm_para.h" "$output/linux-headers/asm-loongarch/" + cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-loongarch/" fi done arch= rm -rf "$output/linux-headers/linux" mkdir -p "$output/linux-headers/linux" -for header in const.h stddef.h kvm.h vfio.h vfio_ccw.h vfio_zdev.h vhost.h \ + +# Including architecture-dependent KVM UAPI header files is delegated to +# "system/kvm.h". Remove including <asm/kvm.h> and add a guard to prevent +# including <linux/kvm.h> in QEMU source code directly. +sed -e '/\#define __LINUX_KVM_H/a \\n#ifndef QEMU_KVM_H\n#error Including <linux\/kvm.h> directly is prohibited, use "system\/kvm.h" instead\n#endif' \ + -e '/\#include <asm\/kvm.h>/d' \ + "$hdrdir/include/linux/kvm.h" >$output/linux-headers/linux/kvm.h + +for header in const.h stddef.h vfio.h vfio_ccw.h vfio_zdev.h vhost.h \ psci.h psp-sev.h userfaultfd.h memfd.h mman.h nvme_ioctl.h \ vduse.h iommufd.h bits.h mshv.h; do cp "$hdrdir/include/linux/$header" "$output/linux-headers/linux"
Signature · 1 line
2.56.0
RFC PATCH 5/8 scripts/update-linux-headers: Vendor hwcap.h and ptrace.h for arm64
In reply to Bjoern WalkBoth files are transient dependencies on ARM included in <asm/kvm.h> and might not be available on other platforms.
--- scripts/update-linux-headers.sh | 2 ++ 1 file changed, 2 insertions(+)
scripts/update-linux-headers.sh +2 -0
@@ -173,6 +173,8 @@ EOF cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-s390/" fi if [ $arch = arm64 ]; then + cp_asm "$hdrdir/include/asm/hwcap.h" "$output/linux-headers/asm-arm64/" + cp_asm "$hdrdir/include/asm/ptrace.h" "$output/linux-headers/asm-arm64/" cp_asm "$hdrdir/include/asm/sve_context.h" "$output/linux-headers/asm-arm64/" cp_asm "$hdrdir/include/asm/unistd_64.h" "$output/linux-headers/asm-arm64/" fi
Signature · 1 line
2.56.0
Bjoern Walk <[email protected]> [2026-11-09, 06:10PM +0100]:
Quoted 1 line
Tree: https://github.ibm.com/linuxonz/qemu/tree/canton/kvm-uapi-header-changes/rfc
Sorry, wrong link. Here's the correct one:
https://gitlab.com/bwalk/qemu/-/tree/canton/kvm-uapi-header-changes/rfc
RFC PATCH 6/8 linux-headers: Update to post-processed KVM headers
In reply to Bjoern WalkNote: This is just to show the result of running scripts/update-linux-headers and should be merged with the previous patch.
Note: This commit fails to compile because it is missing the adjustments to "system/kvm.h" from the next patch.
--- 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 +- 11 files changed, 518 insertions(+), 19 deletions(-) create mode 100644 linux-headers/asm-arm64/hwcap.h create mode 100644 linux-headers/asm-arm64/ptrace.h
linux-headers/asm-arm64/hwcap.h new file +159 -0
@@ -0,0 +1,159 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef _UAPI__ASM_HWCAP_H +#define _UAPI__ASM_HWCAP_H + +/* +* HWCAP flags - for AT_HWCAP +* +* Bits 62 and 63 are reserved for use by libc. +* Bits 33-61 are unallocated for potential use by libc. +*/ +#define HWCAP_FP (1 << 0) +#define HWCAP_ASIMD (1 << 1) +#define HWCAP_EVTSTRM (1 << 2) +#define HWCAP_AES (1 << 3) +#define HWCAP_PMULL (1 << 4) +#define HWCAP_SHA1 (1 << 5) +#define HWCAP_SHA2 (1 << 6) +#define HWCAP_CRC32 (1 << 7) +#define HWCAP_ATOMICS (1 << 8) +#define HWCAP_FPHP (1 << 9) +#define HWCAP_ASIMDHP (1 << 10) +#define HWCAP_CPUID (1 << 11) +#define HWCAP_ASIMDRDM (1 << 12) +#define HWCAP_JSCVT (1 << 13) +#define HWCAP_FCMA (1 << 14) +#define HWCAP_LRCPC (1 << 15) +#define HWCAP_DCPOP (1 << 16) +#define HWCAP_SHA3 (1 << 17) +#define HWCAP_SM3 (1 << 18) +#define HWCAP_SM4 (1 << 19) +#define HWCAP_ASIMDDP (1 << 20) +#define HWCAP_SHA512 (1 << 21) +#define HWCAP_SVE (1 << 22) +#define HWCAP_ASIMDFHM (1 << 23) +#define HWCAP_DIT (1 << 24) +#define HWCAP_USCAT (1 << 25) +#define HWCAP_ILRCPC (1 << 26) +#define HWCAP_FLAGM (1 << 27) +#define HWCAP_SSBS (1 << 28) +#define HWCAP_SB (1 << 29) +#define HWCAP_PACA (1 << 30) +#define HWCAP_PACG (1UL << 31) +#define HWCAP_GCS (1UL << 32) +#define HWCAP_CMPBR (1UL << 33) +#define HWCAP_FPRCVT (1UL << 34) +#define HWCAP_F8MM8 (1UL << 35) +#define HWCAP_F8MM4 (1UL << 36) +#define HWCAP_SVE_F16MM (1UL << 37) +#define HWCAP_SVE_ELTPERM (1UL << 38) +#define HWCAP_SVE_AES2 (1UL << 39) +#define HWCAP_SVE_BFSCALE (1UL << 40) +#define HWCAP_SVE2P2 (1UL << 41) +#define HWCAP_SME2P2 (1UL << 42) +#define HWCAP_SME_SBITPERM (1UL << 43) +#define HWCAP_SME_AES (1UL << 44) +#define HWCAP_SME_SFEXPA (1UL << 45) +#define HWCAP_SME_STMOP (1UL << 46) +#define HWCAP_SME_SMOP4 (1UL << 47) + +/* +* HWCAP2 flags - for AT_HWCAP2 +*/ +#define HWCAP2_DCPODP (1 << 0) +#define HWCAP2_SVE2 (1 << 1) +#define HWCAP2_SVEAES (1 << 2) +#define HWCAP2_SVEPMULL (1 << 3) +#define HWCAP2_SVEBITPERM (1 << 4) +#define HWCAP2_SVESHA3 (1 << 5) +#define HWCAP2_SVESM4 (1 << 6) +#define HWCAP2_FLAGM2 (1 << 7) +#define HWCAP2_FRINT (1 << 8) +#define HWCAP2_SVEI8MM (1 << 9) +#define HWCAP2_SVEF32MM (1 << 10) +#define HWCAP2_SVEF64MM (1 << 11) +#define HWCAP2_SVEBF16 (1 << 12) +#define HWCAP2_I8MM (1 << 13) +#define HWCAP2_BF16 (1 << 14) +#define HWCAP2_DGH (1 << 15) +#define HWCAP2_RNG (1 << 16) +#define HWCAP2_BTI (1 << 17) +#define HWCAP2_MTE (1 << 18) +#define HWCAP2_ECV (1 << 19) +#define HWCAP2_AFP (1 << 20) +#define HWCAP2_RPRES (1 << 21) +#define HWCAP2_MTE3 (1 << 22) +#define HWCAP2_SME (1 << 23) +#define HWCAP2_SME_I16I64 (1 << 24) +#define HWCAP2_SME_F64F64 (1 << 25) +#define HWCAP2_SME_I8I32 (1 << 26) +#define HWCAP2_SME_F16F32 (1 << 27) +#define HWCAP2_SME_B16F32 (1 << 28) +#define HWCAP2_SME_F32F32 (1 << 29) +#define HWCAP2_SME_FA64 (1 << 30) +#define HWCAP2_WFXT (1UL << 31) +#define HWCAP2_EBF16 (1UL << 32) +#define HWCAP2_SVE_EBF16 (1UL << 33) +#define HWCAP2_CSSC (1UL << 34) +#define HWCAP2_RPRFM (1UL << 35) +#define HWCAP2_SVE2P1 (1UL << 36) +#define HWCAP2_SME2 (1UL << 37) +#define HWCAP2_SME2P1 (1UL << 38) +#define HWCAP2_SME_I16I32 (1UL << 39) +#define HWCAP2_SME_BI32I32 (1UL << 40) +#define HWCAP2_SME_B16B16 (1UL << 41) +#define HWCAP2_SME_F16F16 (1UL << 42) +#define HWCAP2_MOPS (1UL << 43) +#define HWCAP2_HBC (1UL << 44) +#define HWCAP2_SVE_B16B16 (1UL << 45) +#define HWCAP2_LRCPC3 (1UL << 46) +#define HWCAP2_LSE128 (1UL << 47) +#define HWCAP2_FPMR (1UL << 48) +#define HWCAP2_LUT (1UL << 49) +#define HWCAP2_FAMINMAX (1UL << 50) +#define HWCAP2_F8CVT (1UL << 51) +#define HWCAP2_F8FMA (1UL << 52) +#define HWCAP2_F8DP4 (1UL << 53) +#define HWCAP2_F8DP2 (1UL << 54) +#define HWCAP2_F8E4M3 (1UL << 55) +#define HWCAP2_F8E5M2 (1UL << 56) +#define HWCAP2_SME_LUTV2 (1UL << 57) +#define HWCAP2_SME_F8F16 (1UL << 58) +#define HWCAP2_SME_F8F32 (1UL << 59) +#define HWCAP2_SME_SF8FMA (1UL << 60) +#define HWCAP2_SME_SF8DP4 (1UL << 61) +#define HWCAP2_SME_SF8DP2 (1UL << 62) +#define HWCAP2_POE (1UL << 63) + +/* +* HWCAP3 flags - for AT_HWCAP3 +*/ +#define HWCAP3_MTE_FAR (1UL << 0) +#define HWCAP3_MTE_STORE_ONLY (1UL << 1) +#define HWCAP3_LSFE (1UL << 2) +#define HWCAP3_LS64 (1UL << 3) +#define HWCAP3_SVE_B16MM (1UL << 4) +#define HWCAP3_SVE2P3 (1UL << 5) +#define HWCAP3_SME_LUT6 (1UL << 6) +#define HWCAP3_SME2P3 (1UL << 7) +#define HWCAP3_F16MM (1UL << 8) +#define HWCAP3_F16F32DOT (1UL << 9) +#define HWCAP3_F16F32MM (1UL << 10) +#define HWCAP3_SVE_LUT6 (1UL << 11) + +#endif /* _UAPI__ASM_HWCAP_H */
linux-headers/asm-arm64/kvm.h +2 -2
@@ -34,8 +34,8 @@#ifndef __ASSEMBLER__#include <linux/psci.h> #include <linux/types.h> -#include <asm/ptrace.h> -#include <asm/sve_context.h> +#include "asm-arm64/ptrace.h" +#include "asm-arm64/sve_context.h" #define __KVM_HAVE_IRQ_LINE#define __KVM_HAVE_VCPU_EVENTS
linux-headers/asm-arm64/ptrace.h new file +337 -0
337 lines not on this page · raw message
linux-headers/asm-arm64/unistd.h +1 -1
@@ -1,2 +1,2 @@/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#include <asm/unistd_64.h> +#include "asm-arm64/unistd_64.h"
linux-headers/asm-loongarch/unistd.h +3 -3
@@ -1,9 +1,9 @@/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#include <asm/bitsperlong.h> +#include "asm-loongarch/bitsperlong.h" #if __BITS_PER_LONG ==32 -#include <asm/unistd_32.h> +#include "asm-loongarch/unistd_32.h" #else -#include <asm/unistd_64.h> +#include "asm-loongarch/unistd_64.h" #endif
linux-headers/asm-mips/unistd.h +4 -4
@@ -13,26 +13,26 @@#ifndef _ASM_UNISTD_H#define _ASM_UNISTD_H -#include <asm/sgidefs.h> +#include "asm-mips/sgidefs.h" #if _MIPS_SIM == _MIPS_SIM_ABI32#define __NR_Linux 4000 -#include <asm/unistd_o32.h> +#include "asm-mips/unistd_o32.h" #endif /* _MIPS_SIM == _MIPS_SIM_ABI32 */ #if _MIPS_SIM == _MIPS_SIM_ABI64#define __NR_Linux 5000 -#include <asm/unistd_n64.h> +#include "asm-mips/unistd_n64.h" #endif /* _MIPS_SIM == _MIPS_SIM_ABI64 */ #if _MIPS_SIM == _MIPS_SIM_NABI32#define __NR_Linux 6000 -#include <asm/unistd_n32.h> +#include "asm-mips/unistd_n32.h" #endif /* _MIPS_SIM == _MIPS_SIM_NABI32 */
linux-headers/asm-powerpc/unistd.h +2 -2
@@ -11,9 +11,9 @@#define _ASM_POWERPC_UNISTD_H_#ifndef __powerpc64__ -#include <asm/unistd_32.h> +#include "asm-powerpc/unistd_32.h" #else -#include <asm/unistd_64.h> +#include "asm-powerpc/unistd_64.h" #endif #endif /* _ASM_POWERPC_UNISTD_H_ */
linux-headers/asm-riscv/kvm.h +2 -2
@@ -12,8 +12,8 @@#ifndef __ASSEMBLER__#include <linux/types.h> -#include <asm/bitsperlong.h> -#include <asm/ptrace.h> +#include "asm-riscv/bitsperlong.h" +#include "asm-riscv/ptrace.h" #define __KVM_HAVE_IRQ_LINE
linux-headers/asm-riscv/unistd.h +3 -3
@@ -14,10 +14,10 @@* You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#include <asm/bitsperlong.h> +#include "asm-riscv/bitsperlong.h" #if __BITS_PER_LONG ==64 -#include <asm/unistd_64.h> +#include "asm-riscv/unistd_64.h" #else -#include <asm/unistd_32.h> +#include "asm-riscv/unistd_32.h" #endif
linux-headers/asm-s390/unistd.h +1 -1
@@ -8,6 +8,6 @@#ifndef _ASM_S390_UNISTD_H_#define _ASM_S390_UNISTD_H_ -#include <asm/unistd_64.h> +#include "asm-s390/unistd_64.h" #endif /* _ASM_S390_UNISTD_H_ */
linux-headers/linux/kvm.h +4 -1
@@ -2,6 +2,10 @@#ifndef __LINUX_KVM_H#define __LINUX_KVM_H +#ifndef QEMU_KVM_H +#error Including <linux/kvm.h> directly is prohibited, use "system/kvm.h" instead +#endif +/* * Userspace interface for /dev/kvm - kernel based virtual machine *
@@ -13,7 +17,6 @@#include <linux/stddef.h> #include <linux/ioctl.h> -#include <asm/kvm.h> #define KVM_API_VERSION 12
Signature · 1 line
2.56.0
RFC PATCH 7/8 kvm: Adjust system/kvm.h for updated KVM kernel headers
In reply to Bjoern WalkFor the per-target code path which needs architecture-specific definitions, include <asm/kvm.h>.
For the common code path, declare structs that <linux/kvm.h> consumes from <asm/kvm.h> as empty and poison all identifiers that are size dependent. This should allow common files to consume "system/kvm.h" with a guarantee that there is no size inconsistency.
--- include/system/kvm.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/system/kvm.h +8 -0
@@ -24,12 +24,20 @@#ifdef COMPILING_PER_TARGET # ifdef CONFIG_KVM +# include <asm/kvm.h> # include <linux/kvm.h> # define CONFIG_KVM_IS_POSSIBLE # endif #else # define CONFIG_KVM_IS_POSSIBLE +struct kvm_debug_exit_arch {}; +struct kvm_sync_regs {}; +struct kvm_guest_debug_arch {};# include <linux/kvm.h> +# pragma GCC poison kvm_debug_exit_arch +# pragma GCC poison kvm_sync_regs +# pragma GCC poison kvm_guest_debug_arch +# pragma GCC poison kvm_guest_debug#endif #ifdef CONFIG_KVM_IS_POSSIBLE
Signature · 1 line
2.56.0
RFC PATCH 8/8 kvm: Explicitly include ARM-specific KVM UAPI headers
In reply to Bjoern WalkWhen compiling target-specific code for TARGET_AARCH64, explicitly include the ARM-specific KVM UAPI headers in linux-headers/asm-arm64. This allows other platforms to build KVM-enabled qemu-system-arm64.
--- include/system/kvm.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
include/system/kvm.h +5 -1
@@ -24,7 +24,11 @@#ifdef COMPILING_PER_TARGET # ifdef CONFIG_KVM -# include <asm/kvm.h> +# ifdef TARGET_AARCH64 +# include <asm-arm64/kvm.h> +# else +# include <asm/kvm.h> +# endif # include <linux/kvm.h> # define CONFIG_KVM_IS_POSSIBLE # endif
Signature · 1 line
2.56.0
[RFC Patch 9/8] meson: Enable aarch64 KVM target on s390x host
In reply to Bjoern WalkFrom: Nina Schoetterl-Glausch <[email protected]>
NOTE: This is not part of the RFC and meant to be a motivating outlook why we want to discuss those changes.
--- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meson.build +1 -1
@@ -285,7 +285,7 @@ if cpu == 'x86_64' elif cpu == 'aarch64' kvm_targets = ['aarch64-softmmu'] elif cpu == 's390x' - kvm_targets = ['s390x-softmmu'] + kvm_targets = ['s390x-softmmu', 'aarch64-softmmu'] elif cpu == 'ppc64' kvm_targets = ['ppc-softmmu', 'ppc64-softmmu'] elif cpu == 'riscv64'
Signature · 1 line
2.56.0