arm64: Pointer Authentication and SVE support
v4 cover arm64: Pointer Authentication and SVE support
This series, based on kvmtool master [1], implements basic support for pointer authentication and SVE for guests. This superseded the previous v3 series [2].
A git tree is also available [3].
For pointer auth, I include Amit's v10 patch [4], with some additional refactoring to sit nicely alongside SVE, and some cosmetic / diagnostic tidyups discussed during review on-list. (I've kept the extra changes separate for easier review, but they could be folded if desired.)
[Maintainer note: I'd like Amit to comment on my changes on top of his pointer auth patch so that that can be folded together as appropriate.]
This series has been tested against Linux v5.2-rc1.
After discussion with Will, the command-line options for controlling pointer auth and SVE support have all been dropped, since they are not useful to normal users: instead, we just default to the best configuration that the host supports. There's always the option to add this functionality back in some more appropriate form later, if someone has a use for it.
See the individual patches for other minor changes.
[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/eaeaf60808d6 ("virtio/blk: Avoid taking pointer to packed struct")
[2] [PATCH kvmtool v3 0/9] arm64: Pointer Authentication and SVE support
https://lists.cs.columbia.edu/pipermail/kvmarm/2019-May/036050.html
[3] [PATCH v10 3/5] KVM: arm64: Add userspace flag to enable pointer authentication
https://lore.kernel.org/linux-arm-kernel/[email protected]/
[4]git://linux-arm.org/kvmtool-dm.git sve/v4/head
http://linux-arm.org/git?p=kvmtool-dm.git;a=shortlog;h=refs/heads/sve/v4/head
Amit Daniel Kachhap (1):
KVM: arm/arm64: Add a vcpu feature for pointer authentication
Dave Martin (7):
update_headers.sh: Add missing shell quoting update_headers.sh: Cleanly report failure on error update_headers.sh: arm64: Copy sve_context.h if available
update_headers: Sync kvm UAPI headers with linux v5.2-rc1
KVM: arm/arm64: Back out ptrauth command-line arguments arm/arm64: Factor out ptrauth vcpu feature setup
arm64: Add SVE support
arm/aarch32/include/kvm/kvm-cpu-arch.h | 7 +++++ arm/aarch64/include/asm/kvm.h | 43 +++++++++++++++++++++++++++ arm/aarch64/include/asm/sve_context.h | 53 ++++++++++++++++++++++++++++++++++ arm/aarch64/include/kvm/kvm-cpu-arch.h | 3 ++ arm/aarch64/kvm-cpu.c | 28 ++++++++++++++++++ arm/kvm-cpu.c | 5 ++++ include/linux/kvm.h | 15 ++++++++-- powerpc/include/asm/kvm.h | 48 ++++++++++++++++++++++++++++++ util/update_headers.sh | 26 +++++++++++++---- x86/include/asm/kvm.h | 1 + 10 files changed, 221 insertions(+), 8 deletions(-) create mode 100644 arm/aarch64/include/asm/sve_context.h
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 1/8 update_headers.sh: Add missing shell quoting
update_headers.sh can break if the current working directory has a funny name or if something odd is passed for LINUX_ROOT.
In the interest of cleanliness, quote where appropriate.
--- util/update_headers.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
util/update_headers.sh +5 -5
@@ -11,17 +11,17 @@ if [ "$#" -ge 1 ] then LINUX_ROOT="$1" else - LINUX_ROOT=/lib/modules/$(uname -r)/source + LINUX_ROOT="/lib/modules/$(uname -r)/source" fi -if [ ! -d $LINUX_ROOT/include/uapi/linux ] +if [ ! -d "$LINUX_ROOT/include/uapi/linux" ] then echo "$LINUX_ROOT does not seem to be valid Linux source tree." echo "usage: $0 [path-to-Linux-source-tree]" exit 1 fi -cp $LINUX_ROOT/include/uapi/linux/kvm.h include/linux +cp -- "$LINUX_ROOT/include/uapi/linux/kvm.h" include/linux for arch in arm arm64 mips powerpc x86 do
@@ -30,6 +30,6 @@ do arm64) KVMTOOL_PATH=arm/aarch64 ;; *) KVMTOOL_PATH=$arch ;; esac - cp $LINUX_ROOT/arch/$arch/include/uapi/asm/kvm.h \ - $KVMTOOL_PATH/include/asm + cp -- "$LINUX_ROOT/arch/$arch/include/uapi/asm/kvm.h" \ + "$KVMTOOL_PATH/include/asm" done
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 2/8 update_headers.sh: Cleanly report failure on error
In reply to Dave MartinIf in intermediate step fails, update_headers.sh blindly continues and may return success status.
To avoid errors going unnoticed when driving this script, exit and report failure status as soon as something goes wrong. For good measure, also fail on expansion of undefined shell variables to aid future maintainers.
--- util/update_headers.sh | 2 ++ 1 file changed, 2 insertions(+)
util/update_headers.sh +2 -0
@@ -7,6 +7,8 @@ # using the lib/modules/`uname -r`/source link. ######################################################################## +set -ue + if [ "$#" -ge 1 ] then LINUX_ROOT="$1"
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 3/8 update_headers.sh: arm64: Copy sve_context.h if available
In reply to Dave MartinThe SVE KVM support for arm64 includes the additional backend header <asm/sve_context.h> from <asm/kvm.h>.
So update this header if it is available.
To avoid creating a sudden dependency on a specific minimum kernel version, ignore such optional headers if the source kernel tree doesn't have them.
---
Changes since v3:
* [Andre Przywara]: Quote argument to local (it turns out that some shells, including dash, require this).
* [Andre Przywara]: Factor out copying of possibly-absent arch headers as optional_arch, for easier reuse later.
--- util/update_headers.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
util/update_headers.sh +13 -1
@@ -25,11 +25,23 @@ fi cp -- "$LINUX_ROOT/include/uapi/linux/kvm.h" include/linux +unset KVMTOOL_PATH + +copy_optional_arch () { + local src="$LINUX_ROOT/arch/$arch/include/uapi/$1" + + if [ -r "$src" ] + then + cp -- "$src" "$KVMTOOL_PATH/include/asm/" + fi +} + for arch in arm arm64 mips powerpc x86 do case "$arch" in arm) KVMTOOL_PATH=arm/aarch32 ;; - arm64) KVMTOOL_PATH=arm/aarch64 ;; + arm64) KVMTOOL_PATH=arm/aarch64 + copy_optional_arch asm/sve_context.h ;; *) KVMTOOL_PATH=$arch ;; esac cp -- "$LINUX_ROOT/arch/$arch/include/uapi/asm/kvm.h" \
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 4/8 update_headers: Sync kvm UAPI headers with linux v5.2-rc1
In reply to Dave MartinPull in upstream UAPI headers, for subsequent arm64 SVE / ptrauth support (among other things).
--- arm/aarch64/include/asm/kvm.h | 43 ++++++++++++++++++++++++++++ arm/aarch64/include/asm/sve_context.h | 53 +++++++++++++++++++++++++++++++++++ include/linux/kvm.h | 15 ++++++++-- powerpc/include/asm/kvm.h | 48 +++++++++++++++++++++++++++++++ x86/include/asm/kvm.h | 1 + 5 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 arm/aarch64/include/asm/sve_context.h
arm/aarch64/include/asm/kvm.h +43 -0
@@ -35,6 +35,7 @@#include <linux/psci.h> #include <linux/types.h> #include <asm/ptrace.h> +#include <asm/sve_context.h> #define __KVM_HAVE_GUEST_DEBUG#define __KVM_HAVE_IRQ_LINE
@@ -102,6 +103,9 @@ 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 */ +#define KVM_ARM_VCPU_PTRAUTH_ADDRESS 5/* VCPU uses address authentication */ +#define KVM_ARM_VCPU_PTRAUTH_GENERIC 6/* VCPU uses generic authentication */ struct kvm_vcpu_init {__u32 target;
@@ -226,6 +230,45 @@ 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) + +/* Z- and P-regs occupy blocks at the following offsets within this range: */ +#define KVM_REG_ARM64_SVE_ZREG_BASE 0 +#define KVM_REG_ARM64_SVE_PREG_BASE 0x400 +#define KVM_REG_ARM64_SVE_FFR_BASE 0x600 + +#define KVM_ARM64_SVE_NUM_ZREGS __SVE_NUM_ZREGS +#define KVM_ARM64_SVE_NUM_PREGS __SVE_NUM_PREGS + +#define KVM_ARM64_SVE_MAX_SLICES 32 + +#define KVM_REG_ARM64_SVE_ZREG (n, i) \ + (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_ZREG_BASE | \ + KVM_REG_SIZE_U2048 | \ + (((n) & (KVM_ARM64_SVE_NUM_ZREGS - 1)) << 5) | \ + ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) + +#define KVM_REG_ARM64_SVE_PREG (n, i) \ + (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_PREG_BASE | \ + KVM_REG_SIZE_U256 | \ + (((n) & (KVM_ARM64_SVE_NUM_PREGS - 1)) << 5) | \ + ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) + +#define KVM_REG_ARM64_SVE_FFR (i) \ + (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | KVM_REG_ARM64_SVE_FFR_BASE | \ + KVM_REG_SIZE_U256 | \ + ((i) & (KVM_ARM64_SVE_MAX_SLICES - 1))) + +#define KVM_ARM64_SVE_VQ_MIN __SVE_VQ_MIN +#define KVM_ARM64_SVE_VQ_MAX __SVE_VQ_MAX + +/* Vector lengths pseudo-register: */ +#define KVM_REG_ARM64_SVE_VLS (KVM_REG_ARM64 | KVM_REG_ARM64_SVE | \ + KVM_REG_SIZE_U512 | 0xffff) +#define KVM_ARM64_SVE_VLS_WORDS \ + ((KVM_ARM64_SVE_VQ_MAX - KVM_ARM64_SVE_VQ_MIN) / 64 + 1) +/* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
arm/aarch64/include/asm/sve_context.h new file +53 -0
53 lines not on this page · raw message
include/linux/kvm.h +13 -2
@@ -986,8 +986,13 @@ struct kvm_ppc_resize_hpt {#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163#define KVM_CAP_EXCEPTION_PAYLOAD 164#define KVM_CAP_ARM_VM_IPA_SIZE 165 -#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166 +#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166/* Obsolete */ #define KVM_CAP_HYPERV_CPUID 167 +#define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 168 +#define KVM_CAP_PPC_IRQ_XIVE 169 +#define KVM_CAP_ARM_SVE 170 +#define KVM_CAP_ARM_PTRAUTH_ADDRESS 171 +#define KVM_CAP_ARM_PTRAUTH_GENERIC 172#ifdef KVM_CAP_IRQ_ROUTING
@@ -1145,6 +1150,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 */
@@ -1211,6 +1217,8 @@ enum kvm_device_type {#define KVM_DEV_TYPE_ARM_VGIC_V3 KVM_DEV_TYPE_ARM_VGIC_V3 KVM_DEV_TYPE_ARM_VGIC_ITS,#define KVM_DEV_TYPE_ARM_VGIC_ITS KVM_DEV_TYPE_ARM_VGIC_ITS + KVM_DEV_TYPE_XIVE, +#define KVM_DEV_TYPE_XIVE KVM_DEV_TYPE_XIVE KVM_DEV_TYPE_MAX, };
@@ -1434,12 +1442,15 @@ struct kvm_enc_region {#define KVM_GET_NESTED_STATE _IOWR(KVMIO, 0xbe, struct kvm_nested_state)#define KVM_SET_NESTED_STATE _IOW(KVMIO, 0xbf, struct kvm_nested_state) -/* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT */ +/* Available with KVM_CAP_MANUAL_DIRTY_LOG_PROTECT_2 */ #define KVM_CLEAR_DIRTY_LOG _IOWR(KVMIO, 0xc0, struct kvm_clear_dirty_log)/* Available with KVM_CAP_HYPERV_CPUID */ #define KVM_GET_SUPPORTED_HV_CPUID _IOWR(KVMIO, 0xc1, struct kvm_cpuid2) +/* Available with KVM_CAP_ARM_SVE */ +#define KVM_ARM_VCPU_FINALIZE _IOW(KVMIO, 0xc2, int) +/* Secure Encrypted Virtualization command */ enum sev_cmd_id {/* Guest initialization commands */
powerpc/include/asm/kvm.h +48 -0
68 lines not on this page · raw message
x86/include/asm/kvm.h +1 -0
@@ -381,6 +381,7 @@ struct kvm_sync_regs {#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0)#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1)#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2) +#define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3)#define KVM_STATE_NESTED_GUEST_MODE 0x00000001#define KVM_STATE_NESTED_RUN_PENDING 0x00000002
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 5/8 KVM: arm/arm64: Add a vcpu feature for pointer authentication
In reply to Dave MartinFrom: Amit Daniel Kachhap <[email protected]>
This patch adds a runtime capabality for KVM tool to enable Arm64 8.3 Pointer Authentication in guest kernel. Two vcpu features KVM_ARM_VCPU_PTRAUTH_[ADDRESS/GENERIC] are supplied together to enable Pointer Authentication in KVM guest after checking the capability.
Command line options --enable-ptrauth and --disable-ptrauth are added to use this feature. However, if those options are not provided then also this feature is enabled if host supports this capability.
--- arm/aarch32/include/kvm/kvm-cpu-arch.h | 2 ++ arm/aarch64/include/kvm/kvm-config-arch.h | 6 +++++- arm/aarch64/include/kvm/kvm-cpu-arch.h | 3 +++ arm/include/arm-common/kvm-config-arch.h | 2 ++ arm/kvm-cpu.c | 20 ++++++++++++++++++-- 5 files changed, 30 insertions(+), 3 deletions(-)
arm/aarch32/include/kvm/kvm-cpu-arch.h +2 -0
@@ -13,4 +13,6 @@#define ARM_CPU_ID 0, 0, 0#define ARM_CPU_ID_MPIDR 5 +#define ARM_VCPU_PTRAUTH_FEATURE 0 +#endif /* KVM__KVM_CPU_ARCH_H */
arm/aarch64/include/kvm/kvm-config-arch.h +5 -1
@@ -8,7 +8,11 @@ "Create PMUv3 device"), \OPT_U64 ('\0' ,"kaslr-seed" , &(cfg)->kaslr_seed, \"Specify random seed for Kernel Address Space " \ -"Layout Randomization (KASLR)" ), +"Layout Randomization (KASLR)" ), \ +OPT_BOOLEAN ('\0' ,"enable-ptrauth" , &(cfg)->enable_ptrauth, \ +"Enables pointer authentication" ), \ +OPT_BOOLEAN ('\0' ,"disable-ptrauth" , &(cfg)->disable_ptrauth, \ +"Disables pointer authentication" ), #include "arm-common/kvm-config-arch.h"
arm/aarch64/include/kvm/kvm-cpu-arch.h +3 -0
@@ -17,4 +17,7 @@#define ARM_CPU_CTRL 3, 0, 1, 0#define ARM_CPU_CTRL_SCTLR_EL1 0 +#define ARM_VCPU_PTRAUTH_FEATURE ((1UL << KVM_ARM_VCPU_PTRAUTH_ADDRESS) \ + | (1UL << KVM_ARM_VCPU_PTRAUTH_GENERIC)) +#endif /* KVM__KVM_CPU_ARCH_H */
arm/include/arm-common/kvm-config-arch.h +2 -0
@@ -10,6 +10,8 @@ struct kvm_config_arch {bool aarch32_guest;bool has_pmuv3;u64 kaslr_seed; +bool enable_ptrauth; +bool disable_ptrauth;enum irqchip_type irqchip;u64 fw_addr; };
arm/kvm-cpu.c +18 -2
@@ -68,6 +68,18 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) vcpu_init.features[0 ] |= (1UL <<KVM_ARM_VCPU_PSCI_0_2 ); } +/* Check Pointer Authentication command line arguments. */ +if (kvm->cfg.arch.enable_ptrauth && kvm->cfg.arch.disable_ptrauth) +die ("Both enable-ptrauth and disable-ptrauth option cannot be present" ); +/* +* Always enable Pointer Authentication if system supports +* this extension unless disable-ptrauth option is present. +*/ +if (kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_ADDRESS ) && +kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_GENERIC ) && + !kvm->cfg.arch.disable_ptrauth) + vcpu_init.features[0 ] |=ARM_VCPU_PTRAUTH_FEATURE ; +/* * If the preferred target ioctl is successful then * use preferred target else try each and every target type
@@ -106,8 +118,12 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)die ("Unable to find matching target" ); } -if (err || target->init (vcpu)) -die ("Unable to initialise vcpu" ); +if (err || target->init (vcpu)) { +if (kvm->cfg.arch.enable_ptrauth) +die ("Unable to initialise vcpu with pointer authentication feature" ); +else +die ("Unable to initialise vcpu" ); + } coalesced_offset =ioctl (kvm->sys_fd,KVM_CHECK_EXTENSION ,KVM_CAP_COALESCED_MMIO );
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 6/8 KVM: arm/arm64: Back out ptrauth command-line arguments
In reply to Dave MartinWill says that the command-line arguments for controlling optional vcpu features are superfluous: we don't attempt to support migration, and this isn't QEMU.
So, remove the command-line arguments and just default pointer auth to on if supported.
---
Changes since v3:
* New patch. This should probably be folded into the previous one.
--- arm/aarch64/include/kvm/kvm-config-arch.h | 6 +----- arm/include/arm-common/kvm-config-arch.h | 2 -- arm/kvm-cpu.c | 19 ++++--------------- 3 files changed, 5 insertions(+), 22 deletions(-)
arm/aarch64/include/kvm/kvm-config-arch.h +1 -5
@@ -8,11 +8,7 @@ "Create PMUv3 device"), \OPT_U64 ('\0' ,"kaslr-seed" , &(cfg)->kaslr_seed, \"Specify random seed for Kernel Address Space " \ -"Layout Randomization (KASLR)" ), \ -OPT_BOOLEAN ('\0' ,"enable-ptrauth" , &(cfg)->enable_ptrauth, \ -"Enables pointer authentication" ), \ -OPT_BOOLEAN ('\0' ,"disable-ptrauth" , &(cfg)->disable_ptrauth, \ -"Disables pointer authentication" ), +"Layout Randomization (KASLR)" ), #include "arm-common/kvm-config-arch.h"
arm/include/arm-common/kvm-config-arch.h +0 -2
@@ -10,8 +10,6 @@ struct kvm_config_arch {bool aarch32_guest;bool has_pmuv3;u64 kaslr_seed; -bool enable_ptrauth; -bool disable_ptrauth;enum irqchip_type irqchip;u64 fw_addr; };
arm/kvm-cpu.c +4 -15
@@ -68,16 +68,9 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) vcpu_init.features[0 ] |= (1UL <<KVM_ARM_VCPU_PSCI_0_2 ); } -/* Check Pointer Authentication command line arguments. */ -if (kvm->cfg.arch.enable_ptrauth && kvm->cfg.arch.disable_ptrauth) -die ("Both enable-ptrauth and disable-ptrauth option cannot be present" ); -/* -* Always enable Pointer Authentication if system supports -* this extension unless disable-ptrauth option is present. -*/ +/* Enable pointer authentication if available */ if (kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_ADDRESS ) && -kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_GENERIC ) && - !kvm->cfg.arch.disable_ptrauth) +kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_GENERIC )) vcpu_init.features[0 ] |=ARM_VCPU_PTRAUTH_FEATURE ;/*
@@ -118,12 +111,8 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)die ("Unable to find matching target" ); } -if (err || target->init (vcpu)) { -if (kvm->cfg.arch.enable_ptrauth) -die ("Unable to initialise vcpu with pointer authentication feature" ); -else -die ("Unable to initialise vcpu" ); - } +if (err || target->init (vcpu)) +die ("Unable to initialise vcpu" ); coalesced_offset =ioctl (kvm->sys_fd,KVM_CHECK_EXTENSION ,KVM_CAP_COALESCED_MMIO );
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Re: [PATCH kvmtool v4 6/8] KVM: arm/arm64: Back out ptrauth command-line arguments
Quoted 7 lines · On Fri, 7 Jun 2019 12:26:27 +0100 Dave Martin <[email protected]> wrote:
Will says that the command-line arguments for controlling optional vcpu features are superfluous: we don't attempt to support migration, and this isn't QEMU.
So, remove the command-line arguments and just default pointer auth to on if supported.
Quoted 7 lines
Signed-off-by Dave Martin <[email protected]>---
Changes since v3:
* New patch. This should probably be folded into the previous one.
Yes, absolutely! Those two merged become a so much simpler patch.
For the stashed version:
Cheers,
Andre.
Quoted 64 lines
--- arm/aarch64/include/kvm/kvm-config-arch.h | 6 +----- arm/include/arm-common/kvm-config-arch.h | 2 -- arm/kvm-cpu.c | 19 ++++--------------- 3 files changed, 5 insertions(+), 22 deletions(-)arm/aarch64/include/kvm/kvm-config-arch.h +1
-5@@ -8,11 +8,7 @@ "Create PMUv3 device"), \OPT_U64 ('\0' ,"kaslr-seed" , &(cfg)->kaslr_seed, \"Specify random seed for Kernel Address Space " \ -"Layout Randomization (KASLR)" ), \ -OPT_BOOLEAN ('\0' ,"enable-ptrauth" , &(cfg)->enable_ptrauth, \ -"Enables pointer authentication" ), \ -OPT_BOOLEAN ('\0' ,"disable-ptrauth" , &(cfg)->disable_ptrauth, \ -"Disables pointer authentication" ), +"Layout Randomization (KASLR)" ), #include "arm-common/kvm-config-arch.h"arm/include/arm-common/kvm-config-arch.h +0
-2@@ -10,8 +10,6 @@ struct kvm_config_arch {bool aarch32_guest;bool has_pmuv3;u64 kaslr_seed; -bool enable_ptrauth; -bool disable_ptrauth;enum irqchip_type irqchip;u64 fw_addr; };arm/kvm-cpu.c +2
-10@@ -68,16 +68,9 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) vcpu_init.features[0 ] |= (1UL <<KVM_ARM_VCPU_PSCI_0_2 ); } -/* Check Pointer Authentication command line arguments. */ -if (kvm->cfg.arch.enable_ptrauth && kvm->cfg.arch.disable_ptrauth) -die ("Both enable-ptrauth and disable-ptrauth option cannot be present" ); -/* -* Always enable Pointer Authentication if system supports -* this extension unless disable-ptrauth option is present. -*/ +/* Enable pointer authentication if available */ if (kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_ADDRESS ) && -kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_GENERIC ) && - !kvm->cfg.arch.disable_ptrauth) +kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_GENERIC )) vcpu_init.features[0 ] |=ARM_VCPU_PTRAUTH_FEATURE ;/* @@ -118,12 +111,8 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)die ("Unable to find matching target" ); } -if (err || target->init (vcpu)) {
arm/kvm-cpu.c struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) · line 118
Quoted 10 lines
arm/kvm-cpu.c +2
-5-if (kvm->cfg.arch.enable_ptrauth) -die ("Unable to initialise vcpu with pointer authentication feature" ); -else -die ("Unable to initialise vcpu" ); - } +if (err || target->init (vcpu)) +die ("Unable to initialise vcpu" ); coalesced_offset =ioctl (kvm->sys_fd,KVM_CHECK_EXTENSION ,KVM_CAP_COALESCED_MMIO );
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 7/8 arm/arm64: Factor out ptrauth vcpu feature setup
In reply to Dave MartinIn the interest of readability, factor out the vcpu feature setup for ptrauth into a separate function.
Also, because aarch32 doesn't have this feature or the related command line options anyway, move the actual code into aarch64/.
Since ARM_VCPU_PTRAUTH_FEATURE is only there to make the ptrauth feature setup code compile on arm, it is no longer needed: inline and remove it.
--- arm/aarch32/include/kvm/kvm-cpu-arch.h | 3 ++- arm/aarch64/include/kvm/kvm-cpu-arch.h | 3 +-- arm/aarch64/kvm-cpu.c | 10 ++++++++++ arm/kvm-cpu.c | 5 +---- 4 files changed, 14 insertions(+), 7 deletions(-)
arm/aarch32/include/kvm/kvm-cpu-arch.h +2 -1
@@ -13,6 +13,7 @@#define ARM_CPU_ID 0, 0, 0#define ARM_CPU_ID_MPIDR 5 -#define ARM_VCPU_PTRAUTH_FEATURE 0 +static inline void kvm_cpu__select_features (struct kvm *kvm, +struct kvm_vcpu_init *init) { }#endif /* KVM__KVM_CPU_ARCH_H */
arm/aarch64/include/kvm/kvm-cpu-arch.h +1 -2
@@ -17,7 +17,6 @@#define ARM_CPU_CTRL 3, 0, 1, 0#define ARM_CPU_CTRL_SCTLR_EL1 0 -#define ARM_VCPU_PTRAUTH_FEATURE ((1UL << KVM_ARM_VCPU_PTRAUTH_ADDRESS) \ - | (1UL << KVM_ARM_VCPU_PTRAUTH_GENERIC)) +void kvm_cpu__select_features (struct kvm *kvm,struct kvm_vcpu_init *init);#endif /* KVM__KVM_CPU_ARCH_H */
arm/aarch64/kvm-cpu.c +10 -0
@@ -128,6 +128,16 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) } } +void kvm_cpu__select_features (struct kvm *kvm,struct kvm_vcpu_init *init) +{ +/* Enable pointer authentication if available */ +if (kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_ADDRESS ) && +kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_GENERIC )) { + init->features[0 ] |=1UL <<KVM_ARM_VCPU_PTRAUTH_ADDRESS ; + init->features[0 ] |=1UL <<KVM_ARM_VCPU_PTRAUTH_GENERIC ; + } +} +void kvm_cpu__reset_vcpu (struct kvm_cpu *vcpu) {if (vcpu->kvm->cfg.arch.aarch32_guest)
arm/kvm-cpu.c +1 -4
@@ -68,10 +68,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) vcpu_init.features[0 ] |= (1UL <<KVM_ARM_VCPU_PSCI_0_2 ); } -/* Enable pointer authentication if available */ -if (kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_ADDRESS ) && -kvm__supports_extension (kvm,KVM_CAP_ARM_PTRAUTH_GENERIC )) - vcpu_init.features[0 ] |=ARM_VCPU_PTRAUTH_FEATURE ; +kvm_cpu__select_features (kvm, &vcpu_init);/* * If the preferred target ioctl is successful then
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
PATCH v4 8/8 arm64: Add SVE support
In reply to Dave MartinThis patch enables the Scalable Vector Extension for the guest when the host supports it.
This requires use of the new KVM_ARM_VCPU_FINALIZE ioctl before the vcpu is runnable, so a new hook kvm_cpu__configure_features() is added to provide an appropriate place to do this work.
---
Changes since v3:
* Drop command-line options and simply default SVE to on where supported.
--- arm/aarch32/include/kvm/kvm-cpu-arch.h | 4 ++++ arm/aarch64/include/kvm/kvm-cpu-arch.h | 1 + arm/aarch64/kvm-cpu.c | 18 ++++++++++++++++++ arm/kvm-cpu.c | 3 +++ 4 files changed, 26 insertions(+)
arm/aarch32/include/kvm/kvm-cpu-arch.h +4 -0
@@ -15,5 +15,9 @@static inline void kvm_cpu__select_features (struct kvm *kvm,struct kvm_vcpu_init *init) { } +static inline int kvm_cpu__configure_features (struct kvm_cpu *vcpu) +{ +return 0 ; +}#endif /* KVM__KVM_CPU_ARCH_H */
arm/aarch64/include/kvm/kvm-cpu-arch.h +1 -0
@@ -18,5 +18,6 @@#define ARM_CPU_CTRL_SCTLR_EL1 0void kvm_cpu__select_features (struct kvm *kvm,struct kvm_vcpu_init *init); +int kvm_cpu__configure_features (struct kvm_cpu *vcpu);#endif /* KVM__KVM_CPU_ARCH_H */
arm/aarch64/kvm-cpu.c +18 -0
@@ -136,6 +136,24 @@ void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) init->features[0 ] |=1UL <<KVM_ARM_VCPU_PTRAUTH_ADDRESS ; init->features[0 ] |=1UL <<KVM_ARM_VCPU_PTRAUTH_GENERIC ; } + +/* Enable SVE if available */ +if (kvm__supports_extension (kvm,KVM_CAP_ARM_SVE )) + init->features[0 ] |=1UL <<KVM_ARM_VCPU_SVE ; +} + +int kvm_cpu__configure_features (struct kvm_cpu *vcpu) +{ +if (kvm__supports_extension (vcpu->kvm,KVM_CAP_ARM_SVE )) { +int feature =KVM_ARM_VCPU_SVE ; + +if (ioctl (vcpu->vcpu_fd,KVM_ARM_VCPU_FINALIZE , &feature)) { +pr_err ("KVM_ARM_VCPU_FINALIZE: %s" ,strerror (errno)); +return -1 ; + } + } + +return 0 ; }void kvm_cpu__reset_vcpu (struct kvm_cpu *vcpu)
arm/kvm-cpu.c +3 -0
@@ -124,6 +124,9 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) vcpu->cpu_compatible = target->compatible; vcpu->is_running = true; +if (kvm_cpu__configure_features (vcpu)) +die ("Unable to configure requested vcpu features" ); +return vcpu; }
Signature · 6 lines
2.1.4 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 3 lines · Dave Martin
This series, based on kvmtool master [1], implements basic support for pointer authentication and SVE for guests. This superseded the previous v3 series [2].
I'd prefer to use the release headers for 5.2, so I've taken the first three patches for now, but I'll wait for you to repost once 5.2 is out before I take the rest.
Thanks,
Will
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 8 lines · Will Deacon
Quoted 3 lines · Dave Martin
This series, based on kvmtool master [1], implements basic support for pointer authentication and SVE for guests. This superseded the previous v3 series [2].
I'd prefer to use the release headers for 5.2, so I've taken the first three patches for now, but I'll wait for you to repost once 5.2 is out before I take the rest.
Ack
Cheers
---Dave
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm