arm64: SVE guest support test hacks
cover arm64: SVE guest support test hacks
This series, based on kvmtool master [1], contains development hacks to accompany the recently posted v4 SVE guest support series for the Linux kernel [2].
This is not proposed for upstreaming in its current form, but some things are probably close to being appropriate for upstream.
Comments and review welcome (but don't sweat the details too much).
[1]git://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git master
https://git.kernel.org/pub/scm/linux/kernel/git/will/kvmtool.git/log/
Specifically, commit fdd26ecb4bc5 ("kvm-cpu: Pause vCPU in signal handler").
[2] [PATCH v4 00/25] KVM: arm64: SVE guest support
https://lists.cs.columbia.edu/pipermail/kvmarm/2019-January/034134.htmlgit://linux-arm.org/linux-dm.git sve-kvm/v4/head
http://linux-arm.org/git?p=linux-dm.git;a=shortlog;h=refs/heads/sve-kvm/v4/head
Dave Martin (12):
guest: Add generated file guest/guest_init.c to .gitignore
update_headers: Sync kvm UAPI headers with linux v5.0-rc2
Makefile: [HACK] Work around GCC 8 warnings :(
Makefile: [HACK] Pass relevant flags when checking for libfdt
arm64: Correct ARM64_CORE_REG() size encodings for all core registers
arm64: [HACK] Pull in kvm UAPI header updates from SVE development
branch
arm64: [HACK] Add option to show the kernel's KVM register ID list
arm64: [HACK] Basic SVE support
arm64: [HACK] Show extra info about SVE with --show-reg-list
arm64: [HACK] Allow configuration of the guest's set of SVE vector
lengths
arm64: [HACK] FPSIMD/SVE register dumping for lkvm debug
arm64: [HACK] Check that out-of-range SVE register IDs can't be dumped
Makefile | 11 +- arm/aarch32/include/asm/kvm.h | 55 ++++++- arm/aarch64/include/asm/kvm.h | 54 ++++++- arm/aarch64/include/kvm/kvm-config-arch.h | 9 ++ arm/aarch64/include/kvm/kvm-cpu-arch.h | 3 +- arm/aarch64/kvm-cpu.c | 209 ++++++++++++++++++++++++- arm/include/arm-common/kvm-config-arch.h | 2 + arm/kvm-cpu.c | 239 ++++++++++++++++++++++++++++ guest/.gitignore | 1 + include/linux/kvm.h | 250 +++++++++++++++++++++++++++++- mips/include/asm/kvm.h | 23 ++- powerpc/include/asm/kvm.h | 39 +++++ x86/include/asm/kvm.h | 69 ++++++++- 13 files changed, 944 insertions(+), 20 deletions(-) create mode 100644 guest/.gitignore
Signature · 1 line
2.1.4
RFC PATCH 1/12 guest: Add generated file guest/guest_init.c to .gitignore
guest/guest_init.c is a generated file, but git doesn't currently ignore it. This can be annoying when running git status etc.
This patch adds a suitable .gitignore entry for this file.
--- guest/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 guest/.gitignore
guest/.gitignore new file +1 -0
@@ -0,0 +1 @@ +guest_init.c
Signature · 1 line
2.1.4
RFC PATCH 2/12 update_headers: Sync kvm UAPI headers with linux v5.0-rc2
In reply to Dave MartinThe local copies of the kvm user API headers are getting stale.
In preparation for some arch-specific updated, this patch reflects a re-run of util/update_headers.sh to pull in upstream updates from linux v5.0-rc2.
--- arm/aarch32/include/asm/kvm.h | 55 +++++++++- arm/aarch64/include/asm/kvm.h | 41 ++++++- include/linux/kvm.h | 248 +++++++++++++++++++++++++++++++++++++++++- mips/include/asm/kvm.h | 23 +++- powerpc/include/asm/kvm.h | 39 +++++++ x86/include/asm/kvm.h | 69 +++++++++++- 6 files changed, 461 insertions(+), 14 deletions(-)
arm/aarch32/include/asm/kvm.h +54 -1
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * Copyright (C) 2012 - Virtual Open Systems and Columbia University * Author: Christoffer Dall <[email protected]>
@@ -26,6 +27,9 @@#define __KVM_HAVE_GUEST_DEBUG#define __KVM_HAVE_IRQ_LINE#define __KVM_HAVE_READONLY_MEM +#define __KVM_HAVE_VCPU_EVENTS + +#define KVM_COALESCED_MMIO_PAGE_OFFSET 1#define KVM_REG_SIZE (id) \ (1U << (((id) & KVM_REG_SIZE_MASK) >> KVM_REG_SIZE_SHIFT))
@@ -88,6 +92,7 @@ struct kvm_regs {#define KVM_VGIC_V3_ADDR_TYPE_DIST 2#define KVM_VGIC_V3_ADDR_TYPE_REDIST 3#define KVM_VGIC_ITS_ADDR_TYPE 4 +#define KVM_VGIC_V3_ADDR_TYPE_REDIST_REGION 5#define KVM_VGIC_V3_DIST_SIZE SZ_64K#define KVM_VGIC_V3_REDIST_SIZE (2 * SZ_64K)
@@ -114,11 +119,25 @@ struct kvm_debug_exit_arch { };struct kvm_sync_regs { +/* Used with KVM_CAP_ARM_USER_IRQ */ +__u64 device_irq_level; };struct kvm_arch_memory_slot { }; +/* for KVM_GET/SET_VCPU_EVENTS */ +struct kvm_vcpu_events { +struct { +__u8 serror_pending; +__u8 serror_has_esr; +/* Align it to 8 bytes */ +__u8 pad[6 ]; +__u64 serror_esr; + } exception; +__u32 reserved[12 ]; +}; +/* If you need to interpret the index values, here is the key: */ #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000#define KVM_REG_ARM_COPROC_SHIFT 16
@@ -130,6 +149,15 @@ struct kvm_arch_memory_slot {#define KVM_REG_ARM_CRM_SHIFT 7#define KVM_REG_ARM_32_CRN_MASK 0x0000000000007800#define KVM_REG_ARM_32_CRN_SHIFT 11 +/* +* For KVM currently all guest registers are nonsecure, but we reserve a bit +* in the encoding to distinguish secure from nonsecure for AArch32 system +* registers that are banked by security. This is 1 for the secure banked +* register, and 0 for the nonsecure banked register or if the register is +* not banked by security. +*/ +#define KVM_REG_ARM_SECURE_MASK 0x0000000010000000 +#define KVM_REG_ARM_SECURE_SHIFT 28#define ARM_CP15_REG_SHIFT_MASK (x,n) \ (((x) << KVM_REG_ARM_ ## n ## _SHIFT) & KVM_REG_ARM_ ## n ## _MASK)
@@ -147,6 +175,12 @@ struct kvm_arch_memory_slot { (__ARM_CP15_REG(op1, 0, crm, 0) | KVM_REG_SIZE_U64)#define ARM_CP15_REG64 (...) __ARM_CP15_REG64(__VA_ARGS__) +/* PL1 Physical Timer Registers */ +#define KVM_REG_ARM_PTIMER_CTL ARM_CP15_REG32(0, 14, 2, 1) +#define KVM_REG_ARM_PTIMER_CNT ARM_CP15_REG64(0, 14) +#define KVM_REG_ARM_PTIMER_CVAL ARM_CP15_REG64(2, 14) + +/* Virtual Timer Registers */ #define KVM_REG_ARM_TIMER_CTL ARM_CP15_REG32(0, 14, 3, 1)#define KVM_REG_ARM_TIMER_CNT ARM_CP15_REG64(1, 14)#define KVM_REG_ARM_TIMER_CVAL ARM_CP15_REG64(3, 14)
@@ -175,6 +209,12 @@ struct kvm_arch_memory_slot {#define KVM_REG_ARM_VFP_FPINST 0x1009#define KVM_REG_ARM_VFP_FPINST2 0x100A +/* KVM-as-firmware specific pseudo-registers */ +#define KVM_REG_ARM_FW (0x0014 << KVM_REG_ARM_COPROC_SHIFT) +#define KVM_REG_ARM_FW_REG (r) (KVM_REG_ARM | KVM_REG_SIZE_U64 | \ + KVM_REG_ARM_FW | ((r) & 0xffff)) +#define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0) +/* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
@@ -192,13 +232,26 @@ struct kvm_arch_memory_slot {#define KVM_DEV_ARM_VGIC_GRP_REDIST_REGS 5#define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6#define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 +#define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT)#define KVM_DEV_ARM_VGIC_LINE_LEVEL_INTID_MASK 0x3ff#define VGIC_LEVEL_INFO_LINE_LEVEL 0 -#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 +/* Device Control API on vcpu fd */ +#define KVM_ARM_VCPU_PMU_V3_CTRL 0 +#define KVM_ARM_VCPU_PMU_V3_IRQ 0 +#define KVM_ARM_VCPU_PMU_V3_INIT 1 +#define KVM_ARM_VCPU_TIMER_CTRL 1 +#define KVM_ARM_VCPU_TIMER_IRQ_VTIMER 0 +#define KVM_ARM_VCPU_TIMER_IRQ_PTIMER 1 + +#define KVM_DEV_ARM_VGIC_CTRL_INIT 0 +#define KVM_DEV_ARM_ITS_SAVE_TABLES 1 +#define KVM_DEV_ARM_ITS_RESTORE_TABLES 2 +#define KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES 3 +#define KVM_DEV_ARM_ITS_CTRL_RESET 4/* KVM_IRQ_LINE irq field index values */ #define KVM_ARM_IRQ_TYPE_SHIFT 24
arm/aarch64/include/asm/kvm.h +40 -1
94 lines not on this page · raw message
include/linux/kvm.h +242 -6
358 lines not on this page · raw message
mips/include/asm/kvm.h +20 -3
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive
@@ -21,6 +22,8 @@#define __KVM_HAVE_READONLY_MEM +#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 +/* * for KVM_GET_REGS and KVM_SET_REGS *
@@ -54,9 +57,14 @@ struct kvm_fpu {* Register set = 0: GP registers from kvm_regs (see definitions below). * * Register set = 1: CP0 registers. -* bits[15..8] - Must be zero. -* bits[7..3] - Register 'rd' index. -* bits[2..0] - Register 'sel' index. +* bits[15..8] - COP0 register set. +* +* COP0 register set = 0: Main CP0 registers. +* bits[7..3] - Register 'rd' index. +* bits[2..0] - Register 'sel' index. +* +* COP0 register set = 1: MAARs. +* bits[7..0] - MAAR index. * * Register set = 2: KVM specific registers (see definitions below). *
@@ -115,6 +123,15 @@ struct kvm_fpu {/* +* KVM_REG_MIPS_CP0 - Coprocessor 0 registers. +*/ + +#define KVM_REG_MIPS_MAAR (KVM_REG_MIPS_CP0 | (1 << 8)) +#define KVM_REG_MIPS_CP0_MAAR (n) (KVM_REG_MIPS_MAAR | \ + KVM_REG_SIZE_U64 | (n)) + + +/* * KVM_REG_MIPS_KVM - KVM specific control registers. */
powerpc/include/asm/kvm.h +39 -0
@@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ /* * 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
@@ -29,6 +30,9 @@#define __KVM_HAVE_IRQ_LINE#define __KVM_HAVE_GUEST_DEBUG +/* Not always available, but if it is, this is the correct offset. */ +#define KVM_COALESCED_MMIO_PAGE_OFFSET 1 +struct kvm_regs {__u64 pc;__u64 cr;
@@ -57,6 +61,12 @@ struct kvm_regs {#define KVM_SREGS_E_FSL_PIDn (1 << 0)/* PID1/PID2 */ +/* flags for kvm_run.flags */ +#define KVM_RUN_PPC_NMI_DISP_MASK (3 << 0) +#define KVM_RUN_PPC_NMI_DISP_FULLY_RECOV (1 << 0) +#define KVM_RUN_PPC_NMI_DISP_LIMITED_RECOV (2 << 0) +#define KVM_RUN_PPC_NMI_DISP_NOT_RECOV (3 << 0) +/* * Feature bits indicate which sections of the sregs struct are valid, * both in KVM_GET_SREGS and KVM_SET_SREGS. On KVM_SET_SREGS, registers
@@ -433,6 +443,31 @@ struct kvm_ppc_rmmu_info {__u32 ap_encodings[8 ]; }; +/* For KVM_PPC_GET_CPU_CHAR */ +struct kvm_ppc_cpu_char { +__u64 character;/* characteristics of the CPU */ +__u64 behaviour;/* recommended software behaviour */ +__u64 character_mask;/* valid bits in character */ +__u64 behaviour_mask;/* valid bits in behaviour */ +}; + +/* +* Values for character and character_mask. +* These are identical to the values used by H_GET_CPU_CHARACTERISTICS. +*/ +#define KVM_PPC_CPU_CHAR_SPEC_BAR_ORI31 (1ULL << 63) +#define KVM_PPC_CPU_CHAR_BCCTRL_SERIALISED (1ULL << 62) +#define KVM_PPC_CPU_CHAR_L1D_FLUSH_ORI30 (1ULL << 61) +#define KVM_PPC_CPU_CHAR_L1D_FLUSH_TRIG2 (1ULL << 60) +#define KVM_PPC_CPU_CHAR_L1D_THREAD_PRIV (1ULL << 59) +#define KVM_PPC_CPU_CHAR_BR_HINT_HONOURED (1ULL << 58) +#define KVM_PPC_CPU_CHAR_MTTRIG_THR_RECONF (1ULL << 57) +#define KVM_PPC_CPU_CHAR_COUNT_CACHE_DIS (1ULL << 56) + +#define KVM_PPC_CPU_BEHAV_FAVOUR_SECURITY (1ULL << 63) +#define KVM_PPC_CPU_BEHAV_L1D_FLUSH_PR (1ULL << 62) +#define KVM_PPC_CPU_BEHAV_BNDS_CHK_SPEC_BAR (1ULL << 61) +/* Per-vcpu XICS interrupt controller state */ #define KVM_REG_PPC_ICP_STATE (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0x8c)
@@ -597,6 +632,10 @@ struct kvm_ppc_rmmu_info {#define KVM_REG_PPC_TIDR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbc)#define KVM_REG_PPC_PSSCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbd) +#define KVM_REG_PPC_DEC_EXPIRY (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xbe) +#define KVM_REG_PPC_ONLINE (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0xbf) +#define KVM_REG_PPC_PTCR (KVM_REG_PPC | KVM_REG_SIZE_U64 | 0xc0) +/* Transactional Memory checkpointed state: * This is all GPRs, all VSX regs and a subset of SPRs */
x86/include/asm/kvm.h +66 -3
106 lines not on this page · raw message
Signature · 1 line
2.1.4
RFC PATCH 3/12 Makefile: [HACK] Work around GCC 8 warnings :(
In reply to Dave MartinSome of these are relatively harmless lazy coding issues; others are overzealousness on the part of the compiler (in some cases, the code is provably safe, yet GCC warns anyway).
Turning the warnings off locally is not nice, but better than turning them off globally.
--- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Makefile +7 -2
@@ -42,6 +42,7 @@ OBJS += builtin-stat.o OBJS += builtin-pause.o OBJS += builtin-resume.o OBJS += builtin-run.o +CFLAGS-builtin-run.o = -Wno-format-truncation -Wno-stringop-truncation OBJS += builtin-setup.o OBJS += builtin-stop.o OBJS += builtin-version.o
@@ -63,9 +64,11 @@ OBJS += vfio/core.o OBJS += vfio/pci.o OBJS += virtio/blk.o OBJS += virtio/scsi.o +CFLAGS-virtio/scsi.o = -Wno-stringop-truncation OBJS += virtio/console.o OBJS += virtio/core.o OBJS += virtio/net.o +CFLAGS-virtio/net.o = -Wno-sizeof-pointer-memaccess -Wno-stringop-truncation OBJS += virtio/rng.o OBJS += virtio/balloon.o OBJS += virtio/pci.o
@@ -82,6 +85,7 @@ OBJS += net/uip/udp.o OBJS += net/uip/buf.o OBJS += net/uip/csum.o OBJS += net/uip/dhcp.o +CFLAGS-net/uip/dhcp.o = -Wno-stringop-truncation OBJS += kvm-cmd.o OBJS += util/init.o OBJS += util/iovec.o
@@ -93,6 +97,7 @@ OBJS += util/strbuf.o OBJS += util/read-write.o OBJS += util/util.o OBJS += virtio/9p.o +CFLAGS-virtio/9p.o = -Wno-restrict OBJS += virtio/9p-pdu.o OBJS += hw/vesa.o OBJS += hw/pci-shmem.o
@@ -439,10 +444,10 @@ endif %.o: %.c ifeq ($(C),1) $(E) " CHECK " $@ - $(Q) $(CHECK) -c $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@ + $(Q) $(CHECK) -c $(CFLAGS-$@) $(CFLAGS) $(CFLAGS_DYNOPT) $< -o $@ endif $(E) " CC " $@ - $(Q) $(CC) -c $(c_flags) $(CFLAGS_DYNOPT) $< -o $@ + $(Q) $(CC) -c $(CFLAGS-$@) $(c_flags) $(CFLAGS_DYNOPT) $< -o $@ #
Signature · 1 line
2.1.4
RFC PATCH 4/12 Makefile: [HACK] Pass relevant flags when checking for libfdt
In reply to Dave MartinCPPFLAGS and LDFLAGS may be telling us where libdft.h and -lfdt are to be found, so don't ignore them when looking for libfdt.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -310,7 +310,7 @@ $(warning No static libc found. Skipping guest init) endif ifeq (y,$(ARCH_WANT_LIBFDT)) - ifneq ($(call try-build,$(SOURCE_LIBFDT),$(CFLAGS),-lfdt),y) + ifneq ($(call try-build,$(SOURCE_LIBFDT),$(CPPFLAGS) $(CFLAGS) $(LDFLAGS),-lfdt),y) $(error No libfdt found. Please install libfdt-dev package) else CFLAGS_DYNOPT += -DCONFIG_HAS_LIBFDT
Signature · 1 line
2.1.4
RFC PATCH 5/12 arm64: Correct ARM64_CORE_REG() size encodings for all core registers
In reply to Dave MartinARM64_CORE_REG() is currently only used to generate the KVM register IDs for registers that happen to be 64 bits in size, so KVM_REG_SIZE_U64 is hard-coded in the definition.
To enable this macro to generate correct encodings for the FPSIMD registers too (which are a mix of 128-bit and 32-bit registers), this patch extends the macro to encode the correct size for each class of register in KVM_REG_ARM_CORE.
The approach is crude, but because the KVM_REG_ARM_CORE ID arrangement is ABI, it's not expected to evolve.
--- arm/aarch64/kvm-cpu.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
arm/aarch64/kvm-cpu.c +15 -2
@@ -12,8 +12,21 @@#define SCTLR_EL1_E0E_MASK (1 << 24)#define SCTLR_EL1_EE_MASK (1 << 25) -#define ARM64_CORE_REG (x) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ - KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x)) +static __u64 __core_reg_id (__u64 offset) +{ +__u64 id =KVM_REG_ARM64 |KVM_REG_ARM_CORE | offset; + +if (offset <KVM_REG_ARM_CORE_REG (fp_regs)) + id |=KVM_REG_SIZE_U64 ; +else if (offset <KVM_REG_ARM_CORE_REG (fp_regs.fpsr)) + id |=KVM_REG_SIZE_U128 ; +else + id |=KVM_REG_SIZE_U32 ; + +return id; +} + +#define ARM64_CORE_REG (x) __core_reg_id(KVM_REG_ARM_CORE_REG(x))unsigned long kvm_cpu__get_vcpu_mpidr (struct kvm_cpu *vcpu) {
Signature · 1 line
2.1.4
RFC PATCH 6/12 arm64: [HACK] Pull in kvm UAPI header updates from SVE development branch
In reply to Dave MartinThis patch pulls in SVE-related declarations from my kernel SVE development branch, so that kvmtool can make use of them.
--- arm/aarch64/include/asm/kvm.h | 13 +++++++++++++ include/linux/kvm.h | 2 ++ 2 files changed, 15 insertions(+)
arm/aarch64/include/asm/kvm.h +13 -0
@@ -102,6 +102,7 @@ struct kvm_regs {#define KVM_ARM_VCPU_EL1_32BIT 1/* CPU running a 32bit VM */ #define KVM_ARM_VCPU_PSCI_0_2 2/* CPU uses PSCI v0.2 */ #define KVM_ARM_VCPU_PMU_V3 3/* Support guest PMUv3 */ +#define KVM_ARM_VCPU_SVE 4/* enable SVE for this CPU */ struct kvm_vcpu_init {__u32 target;
@@ -226,6 +227,18 @@ struct kvm_vcpu_events { KVM_REG_ARM_FW | ((r) & 0xffff))#define KVM_REG_ARM_PSCI_VERSION KVM_REG_ARM_FW_REG(0) +/* SVE registers */ +#define KVM_REG_ARM64_SVE (0x15 << KVM_REG_ARM_COPROC_SHIFT) +#define KVM_REG_ARM64_SVE_ZREG (n, i) (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ + KVM_REG_SIZE_U2048 | \ + ((n) << 5) | (i)) +#define KVM_REG_ARM64_SVE_PREG (n, i) (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ + KVM_REG_SIZE_U256 | \ + ((n) << 5) | (i) | 0x400) +#define KVM_REG_ARM64_SVE_FFR (i) KVM_REG_ARM64_SVE_PREG(16, i) +#define KVM_REG_ARM64_SVE_VLS (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ + KVM_REG_SIZE_U512 | 0xffff) +/* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
include/linux/kvm.h +2 -0
@@ -988,6 +988,7 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_ARM_VM_IPA_SIZE 165#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166#define KVM_CAP_HYPERV_CPUID 167 +#define KVM_CAP_ARM_SVE 168#ifdef KVM_CAP_IRQ_ROUTING
@@ -1145,6 +1146,7 @@ struct kvm_dirty_tlb {#define KVM_REG_SIZE_U256 0x0050000000000000ULL#define KVM_REG_SIZE_U512 0x0060000000000000ULL#define KVM_REG_SIZE_U1024 0x0070000000000000ULL +#define KVM_REG_SIZE_U2048 0x0080000000000000ULLstruct kvm_reg_list {__u64 n;/* number of regs */
Signature · 1 line
2.1.4
RFC PATCH 7/12 arm64: [HACK] Add option to show the kernel's KVM register ID list
In reply to Dave MartinTo assist with testing and debugging the behaviour of KVM_GET_REG_LIST, this patch adds a crude option --show-reg-list to print out the list of register IDs reported by the kernel on vcpu startup.
This is a development hack only and not currently friendly (or useful) for users.
--- arm/aarch64/include/kvm/kvm-config-arch.h | 2 ++ arm/include/arm-common/kvm-config-arch.h | 1 + arm/kvm-cpu.c | 50 +++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+)
arm/aarch64/include/kvm/kvm-config-arch.h +2 -0
@@ -6,6 +6,8 @@ "Run AArch32 guest"), \OPT_BOOLEAN ('\0' ,"pmu" , &(cfg)->has_pmuv3, \"Create PMUv3 device" ), \ +OPT_BOOLEAN ('\0' ,"show-reg-list" , &(cfg)->show_reg_list, \ +"Show the list of KVM register IDs on startup" ), \OPT_U64 ('\0' ,"kaslr-seed" , &(cfg)->kaslr_seed, \"Specify random seed for Kernel Address Space " \ "Layout Randomization (KASLR)"),
arm/include/arm-common/kvm-config-arch.h +1 -0
@@ -9,6 +9,7 @@ struct kvm_config_arch {bool virtio_trans_pci;bool aarch32_guest;bool has_pmuv3; +bool show_reg_list;u64 kaslr_seed;enum irqchip_type irqchip; };
arm/kvm-cpu.c +50 -0
62 lines not on this page · raw message
Signature · 1 line
2.1.4
RFC PATCH 8/12 arm64: [HACK] Basic SVE support
In reply to Dave MartinFor compatibility reasons, new vcpus created by KVM always have SVE disabled by default.
To enable SVE to be turned on, this patch adds an option --sve.
Currently, no independent control is added per-vcpu. This means that it is not currently possible to create a VM containing a mix of SVE-enabled and non-SVE-enabled vcpus. This functionality could be added later if desired.
--- arm/aarch64/include/kvm/kvm-config-arch.h | 2 ++ arm/aarch64/include/kvm/kvm-cpu-arch.h | 3 ++- arm/include/arm-common/kvm-config-arch.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-)
arm/aarch64/include/kvm/kvm-config-arch.h +2 -0
@@ -6,6 +6,8 @@ "Run AArch32 guest"), \OPT_BOOLEAN ('\0' ,"pmu" , &(cfg)->has_pmuv3, \"Create PMUv3 device" ), \ +OPT_BOOLEAN ('\0' ,"sve" , &(cfg)->has_sve, \ +"Enable SVE for the guest" ), \OPT_BOOLEAN ('\0' ,"show-reg-list" , &(cfg)->show_reg_list, \"Show the list of KVM register IDs on startup" ), \ OPT_U64('\0', "kaslr-seed", &(cfg)->kaslr_seed, \
arm/aarch64/include/kvm/kvm-cpu-arch.h +2 -1
@@ -8,7 +8,8 @@#define ARM_VCPU_FEATURE_FLAGS (kvm, cpuid) { \ [0] = ((!!(cpuid) << KVM_ARM_VCPU_POWER_OFF) | \ (!!(kvm)->cfg.arch.aarch32_guest << KVM_ARM_VCPU_EL1_32BIT) | \ - (!!(kvm)->cfg.arch.has_pmuv3 << KVM_ARM_VCPU_PMU_V3)) \ + (!!(kvm)->cfg.arch.has_pmuv3 << KVM_ARM_VCPU_PMU_V3) | \ + (!!(kvm)->cfg.arch.has_sve << KVM_ARM_VCPU_SVE)) \ }#define ARM_MPIDR_HWID_BITMASK 0xFF00FFFFFFUL
arm/include/arm-common/kvm-config-arch.h +1 -0
@@ -9,6 +9,7 @@ struct kvm_config_arch {bool virtio_trans_pci;bool aarch32_guest;bool has_pmuv3; +bool has_sve;bool show_reg_list;u64 kaslr_seed;enum irqchip_type irqchip;
Signature · 1 line
2.1.4
RFC PATCH 9/12 arm64: [HACK] Show extra info about SVE with --show-reg-list
In reply to Dave MartinThis patch prints out some information about the SVE configuration when --show-reg=list is passed.
This is development hack only (as well as being an abuse of the purpose of that option).
--- arm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-)
arm/kvm-cpu.c +110 -1
@@ -1,3 +1,4 @@ +#include <assert.h> #include <errno.h> #include <stddef.h> #include <stdio.h>
@@ -48,6 +49,112 @@ error:return ret; } +static int kvm_show_sve_info (struct kvm_cpu const *vcpu) +{ +int ret =0 ; +u64 val; +struct kvm_one_reg r; +int have_sve; +u64 vls[9 ]; +unsigned int i; + + r.addr = (u64)&val; + + r.id =ARM64_SYS_REG (3 ,0 ,0 ,4 ,0 );/* ID_AA64PFR0_EL1 */ +assert ((r.id &KVM_REG_SIZE_MASK ) ==KVM_REG_SIZE_U64 ); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , &r)) { +perror ("KVM_GET_ONE_REG(ID_AA64PFR0_EL1)" ); + goto error; + } + +printf ("ID_AA64PFR0_EL1:\t0x%lx\n" , (unsigned long )val); + + have_sve = !!((val >>32 ) &0xf ); + + r.id =ARM64_SYS_REG (3 ,0 ,0 ,4 ,4 ); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , &r)) { +if (errno !=ENOENT || have_sve) { +perror ("KVM_GET_ONE_REG(ID_AA64ZFR0_EL1)" ); + ret =-1 ; + } + }else { +if (!have_sve) { +puts ("ID_AA64ZFR0_EL1 unexpectedly present" ); + ret =-1 ; + } + +printf ("ID_AA64ZFR0_EL1:\t0x%lx\n" , (unsigned long )val); + } + + r.id =ARM64_SYS_REG (3 ,0 ,1 ,2 ,0 ); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , &r)) { +if (errno !=ENOENT || have_sve) { +perror ("KVM_GET_ONE_REG(ZCR_EL1)" ); + ret =-1 ; + } + }else { +if (!have_sve) { +puts ("ZCR_EL1 unexpectedly present" ); + ret =-1 ; + } + +printf ("ZCR_EL1:\t0x%lx\n" , (unsigned long )val); + } + + r.addr = (u64)&vls; + r.id =KVM_REG_ARM64_SVE_VLS ; +assert (8 * (sizeof (vls) -sizeof (*vls)) ==512 && + (r.id &KVM_REG_SIZE_MASK ) ==KVM_REG_SIZE_U512 ); + +/* +* Write some canary data so we can see that the kernel writes +* the expected amount: +*/ +for (i =0 ; i <sizeof (vls) /sizeof (*vls); ++i) + vls[i] =-7 ; + +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , &r)) { +if (errno !=ENOENT || have_sve) { +perror ("KVM_GET_ONE_REG(KVM_REG_ARM64_SVE_VLS)" ); + ret =-1 ; + } + }else { +char const *prefix ="" ; + +if (!have_sve) { +puts ("KVM_REG_ARM64_SVE_VLS unexpectedly present" ); + ret =-1 ; + } + +if (vls[7 ] == (u64)-7 ) { +puts ("KVM_REG_ARM64_SVE_VLS short read?" ); + ret =-1 ; + } + +if (vls[8 ] != (u64)-7 ) { +puts ("KVM_REG_ARM64_SVE_VLS overrun?" ); + ret =-1 ; + } + +fputs ("SVE VQs: " , stdout); + +for (i =0 ; i <512 ; ++i) +if ((vls[i /64 ] >> (i %64 )) &1 ) { +printf ("%s%lu" , prefix, (unsigned long )i +1 ); + prefix ="," ; + } + +putchar ('\n' ); + } + +fflush (stdout); + +return ret; + +error: +return -1 ; +} +static int debug_fd;void kvm_cpu__set_debug_fd (int fd)
@@ -156,8 +263,10 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)if (err || target->init (vcpu))die ("Unable to initialise vcpu" ); -if (kvm->cfg.arch.show_reg_list) +if (kvm->cfg.arch.show_reg_list) { +kvm_show_sve_info (vcpu);kvm_show_reg_list (vcpu); + } coalesced_offset =ioctl (kvm->sys_fd,KVM_CHECK_EXTENSION ,KVM_CAP_COALESCED_MMIO );
Signature · 1 line
2.1.4
RFC PATCH 10/12 arm64: [HACK] Allow configuration of the guest's set of SVE vector lengths
In reply to Dave MartinBy default, for each vcpu KVM enabled the same set of SVE vector as supported by the host.
In order to allow a different set of vector lengths permitted (to the extent supported by the SVE architecture), an option --sve-vqs is added, which accepts a comma-separated list of vector lengths to enable.
This options follows the "vq" convention, describing the vector length as a multiple of 128-bit quadwords. This is largely for developer convenience and may be confusing for users.
Although KVM supports a different set of vector lengths to be enabled on each vcpu, this patch provides no means to request such a configuration for now. Support could be added later, if desired.
--- arm/aarch64/include/kvm/kvm-config-arch.h | 5 ++ arm/kvm-cpu.c | 80 +++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+)
arm/aarch64/include/kvm/kvm-config-arch.h +5 -0
@@ -1,6 +1,8 @@#ifndef KVM__KVM_CONFIG_ARCH_H #define KVM__KVM_CONFIG_ARCH_H +int sve_vls_parser (const struct option *opt,const char *arg,int unset); +#define ARM_OPT_ARCH_RUN (cfg) \ OPT_BOOLEAN('\0', "aarch32", &(cfg)->aarch32_guest, \ "Run AArch32 guest"), \
@@ -10,6 +12,9 @@ "Enable SVE for the guest"), \OPT_BOOLEAN ('\0' ,"show-reg-list" , &(cfg)->show_reg_list, \"Show the list of KVM register IDs on startup" ), \ +OPT_CALLBACK ('\0' ,"sve-vqs" ,NULL ,"comma-separated list" , \ +"Override the SVE vector lengths supported" , \ + sve_vls_parser,NULL ), \OPT_U64 ('\0' ,"kaslr-seed" , &(cfg)->kaslr_seed, \"Specify random seed for Kernel Address Space " \ "Layout Randomization (KASLR)"),
arm/kvm-cpu.c +80 -0
95 lines not on this page · raw message
Signature · 1 line
2.1.4
RFC PATCH 11/12 arm64: [HACK] FPSIMD/SVE register dumping for lkvm debug
In reply to Dave MartinTo assist with debugging, and to exercise the KVM_{GET,SET}_ONE_REG interface extensions for SVE, this patch adds code to dump the full contents of the SVE and/or FPSIMD registers when triggered using lkvm debug -d.
This is a giant ugly hack and also slow (even with hacks to reduce the number of dprintf() calls).
Due to a lack of buffering on one or both ends of the guest socket connection, dumping the vcpu that's running on the same CPU as lkvm debug seems to cause a lot of context switch thrashing also, but no attempt has been made to address this here, since this patch is in any case rather abusing the guest socket. If we want to do something like this for real, some more careful thought about how to optimise the protocol is needed.
--- arm/aarch64/kvm-cpu.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+)
arm/aarch64/kvm-cpu.c +186 -0
@@ -2,6 +2,10 @@#include "kvm/kvm.h" #include "kvm/virtio.h" +#include <assert.h> +#include <errno.h> +#include <stdarg.h> +#include <string.h> #include <asm/ptrace.h> #define COMPAT_PSR_F_BIT 0x00000040
@@ -197,11 +201,128 @@ void kvm_cpu__show_code(struct kvm_cpu *vcpu)kvm__dump_mem (vcpu->kvm, data,32 , debug_fd); } +static void sappendf (char **p,size_t *size,char const *format, ...) +{ +va_list vl; +int n; + +va_start (vl, format); + n =vsnprintf (*p, *size, format, vl); +va_end (vl); + +if (n <0 || (unsigned )n >= *size) +die ("sappendf buffer too small" ); + + *p += n; + *size -= n; +} + +static void sappend_bytes (char **p,size_t *size, +void const *bytes,size_t nbytes) +{ +unsigned char const *b = bytes; + +while (nbytes--) +sappendf (p, size,"%.2x" , *b++); +} + +static void show_sve_zn_slice (int debug_fd,struct kvm_cpu const *vcpu, +unsigned int n,unsigned int i) +{ +struct kvm_one_reg reg; +char bytes[256 ]; +char str[2 *sizeof bytes +9 ], *strp; +size_t strsz; + + reg.id =KVM_REG_ARM64_SVE_ZREG (n, i); + +assert ((size_t )1 << ((reg.id &KVM_REG_SIZE_MASK ) >> +KVM_REG_SIZE_SHIFT ) == +sizeof bytes); + reg.addr = (__u64 )bytes; + + strp = str; + strsz =sizeof str; + +sappendf (&strp, &strsz," Z%.2u/%.2u:" , n, i); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) { +dprintf (debug_fd,"%s(%s)\n" , str,strerror (errno)); +if (vcpu->kvm->cfg.arch.has_sve) +die ("Z-reg unexpectedly absent on SVE vcpu" ); + +return ; + } + +if (!vcpu->kvm->cfg.arch.has_sve) +die ("Z-reg unexpectedly present on non-SVE vcpu" ); + +sappend_bytes (&strp, &strsz, bytes,sizeof bytes); +dprintf (debug_fd,"%s\n" , str); +} + +static void show_sve_zn (int debug_fd,struct kvm_cpu const *vcpu, +unsigned int n) +{ +show_sve_zn_slice (debug_fd, vcpu, n,0 ); +show_sve_zn_slice (debug_fd, vcpu, n,1 ); +} + +static void show_sve_pn_slice (int debug_fd,struct kvm_cpu const *vcpu, +unsigned int n,unsigned int i) +{ +struct kvm_one_reg reg; +char bytes[32 ]; +char str[2 *sizeof bytes +9 ], *strp; +size_t strsz; + + reg.id =KVM_REG_ARM64_SVE_PREG (n, i); + +assert ((size_t )1 << ((reg.id &KVM_REG_SIZE_MASK ) >> +KVM_REG_SIZE_SHIFT ) == +sizeof bytes); + reg.addr = (__u64 )bytes; + + strp = str; + strsz =sizeof str; + +if (reg.id ==KVM_REG_ARM64_SVE_FFR (i)) +sappendf (&strp, &strsz," FFR/%.2u:" , i); +else +sappendf (&strp, &strsz," P%.2u/%.2u:" , n, i); + +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) { +dprintf (debug_fd,"%s(%s)\n" , str,strerror (errno)); +if (vcpu->kvm->cfg.arch.has_sve) +die ("P-reg unexpectedly absent on SVE vcpu" ); + +return ; + } + +if (!vcpu->kvm->cfg.arch.has_sve) +die ("P-reg unexpectedly present on non-SVE vcpu" ); + +sappend_bytes (&strp, &strsz, bytes,sizeof bytes); +dprintf (debug_fd,"%s\n" , str); +} + +static void show_sve_pn (int debug_fd,struct kvm_cpu const *vcpu, +unsigned int n) +{ +show_sve_pn_slice (debug_fd, vcpu, n,0 ); +show_sve_pn_slice (debug_fd, vcpu, n,1 ); +} +void kvm_cpu__show_registers (struct kvm_cpu *vcpu) {struct kvm_one_reg reg;unsigned long data; +unsigned int data32;int debug_fd =kvm_cpu__get_debug_fd (); +unsigned int i; +char bytes[16 ]; +unsigned long vqs[8 ]; +char str[2 *sizeof vqs +1 ], *strp; +size_t strsz; reg.addr = (u64)&data;dprintf (debug_fd,"\n Registers:\n" );
@@ -225,4 +346,69 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu)if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 )die ("KVM_GET_ONE_REG failed (lr)" );dprintf (debug_fd," LR: 0x%lx\n" , data); + + reg.addr = (__u64 )bytes; +for (i =0 ; i <32 ; ++i) { + reg.id =ARM64_CORE_REG (fp_regs.vregs[i]); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) +dprintf (debug_fd," V%.2u: (%s)\n" , + i,strerror (errno)); +else { + strp = str; + strsz =sizeof str; +sappend_bytes (&strp, &strsz, bytes,16 ); +dprintf (debug_fd," V%.2u: %s\n" , i, str); + } + } + + reg.addr = (__u64)&data32; + + reg.id =ARM64_CORE_REG (fp_regs.fpsr); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) +die ("KVM_GET_ONE_REG failed (fpsr)" ); +dprintf (debug_fd," FPSR: 0x%x\n" , data32); + + reg.id =ARM64_CORE_REG (fp_regs.fpcr); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) +die ("KVM_GET_ONE_REG failed (fpcr)" ); +dprintf (debug_fd," FPCR: 0x%x\n" , data32); + + reg.id =KVM_REG_ARM64_SVE_VLS ; +assert ((size_t )1 << ((reg.id &KVM_REG_SIZE_MASK ) >> +KVM_REG_SIZE_SHIFT ) == +sizeof vqs); + reg.addr = (u64)&vqs; + +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) { +dprintf (debug_fd," SVE_VLS:(%s)\n" ,strerror (errno)); +if (vcpu->kvm->cfg.arch.has_sve) +die ("SVE vcpu doesn't have KVM_REG_ARM64_SVE_VLS!" ); + }else { +if (!vcpu->kvm->cfg.arch.has_sve) +die ("KVM_REG_ARM64_SVE_VLS present on non-SVE vcpu!" ); + + strp = str; + strsz =sizeof str; +sappend_bytes (&strp, &strsz, vqs,sizeof vqs); +dprintf (debug_fd," SVE_VLS:%s\n" , str); + } + + reg.addr = (__u64)&data; + reg.id =ARM64_SYS_REG (3 ,0 ,1 ,2 ,0 ); +if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) { +dprintf (debug_fd," ZCR_EL1:(%s)\n" ,strerror (errno)); +if (vcpu->kvm->cfg.arch.has_sve) +die ("ZCR_EL1 unexpectedly absent on SVE vcpu" ); + }else { +if (!vcpu->kvm->cfg.arch.has_sve) +die ("ZCR_EL1 unexpectedly present on non-SVE vcpu" ); + +dprintf (debug_fd," ZCR_EL1:0x%lx\n" , data); + } + +for (i =0 ; i <32 ; ++i) +show_sve_zn (debug_fd, vcpu, i); + +for (i =0 ; i <16 +1 /*FFR*/ ; ++i) +show_sve_pn (debug_fd, vcpu, i); }
Signature · 1 line
2.1.4
RFC PATCH 12/12 arm64: [HACK] Check that out-of-range SVE register IDs can't be dumped
In reply to Dave MartinAs a sanity-check that invalid SVE register IDs can't be accessed via KVM_GET_ONE_REG, this patch adds code to attempt to do just that (at the expense of making dumping even slower).
Because of the way the register IDs are encoded, out-of-range slice IDs may still result in a valid register encoding, so there is nothing to test for that case.
--- arm/aarch64/kvm-cpu.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
arm/aarch64/kvm-cpu.c +10 -4
@@ -247,7 +247,7 @@ static void show_sve_zn_slice(int debug_fd, struct kvm_cpu const *vcpu,sappendf (&strp, &strsz," Z%.2u/%.2u:" , n, i);if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) {dprintf (debug_fd,"%s(%s)\n" , str,strerror (errno)); -if (vcpu->kvm->cfg.arch.has_sve) +if (n <32 && vcpu->kvm->cfg.arch.has_sve)die ("Z-reg unexpectedly absent on SVE vcpu" );return ;
@@ -256,6 +256,9 @@ static void show_sve_zn_slice(int debug_fd, struct kvm_cpu const *vcpu,if (!vcpu->kvm->cfg.arch.has_sve)die ("Z-reg unexpectedly present on non-SVE vcpu" ); +if (n >=32 ) +die ("Out-of-range Z-reg unexpectedly present" ); +sappend_bytes (&strp, &strsz, bytes,sizeof bytes);dprintf (debug_fd,"%s\n" , str); }
@@ -292,7 +295,7 @@ static void show_sve_pn_slice(int debug_fd, struct kvm_cpu const *vcpu,if (ioctl (vcpu->vcpu_fd,KVM_GET_ONE_REG , ®) <0 ) {dprintf (debug_fd,"%s(%s)\n" , str,strerror (errno)); -if (vcpu->kvm->cfg.arch.has_sve) +if (n <16 +1 /* FFR */ && vcpu->kvm->cfg.arch.has_sve)die ("P-reg unexpectedly absent on SVE vcpu" );return ;
@@ -301,6 +304,9 @@ static void show_sve_pn_slice(int debug_fd, struct kvm_cpu const *vcpu,if (!vcpu->kvm->cfg.arch.has_sve)die ("P-reg unexpectedly present on non-SVE vcpu" ); +if (n >=16 && reg.id !=KVM_REG_ARM64_SVE_FFR (i)) +die ("Out-of-range P-reg unexpectedly present" ); +sappend_bytes (&strp, &strsz, bytes,sizeof bytes);dprintf (debug_fd,"%s\n" , str); }
@@ -406,9 +412,9 @@ void kvm_cpu__show_registers(struct kvm_cpu *vcpu)dprintf (debug_fd," ZCR_EL1:0x%lx\n" , data); } -for (i =0 ; i <32 ; ++i) +for (i =0 ; i <32 +1 /* should fail */ ; ++i)show_sve_zn (debug_fd, vcpu, i); -for (i =0 ; i <16 +1 /*FFR*/ ; ++i) +for (i =0 ; i <16 +1 /* FFR */ +1 /* should fail */ ; ++i)show_sve_pn (debug_fd, vcpu, i); }
Signature · 1 line
2.1.4