KVM/arm64: Enable PtrAuth on non-VHE KVM
Marc Zyngier
maintainercover KVM/arm64: Enable PtrAuth on non-VHE KVM
Not having PtrAuth on non-VHE KVM (for whatever reason VHE is not enabled on a v8.3 system) has always looked like an oddity. This trivial series remedies it, and allows a non-VHE KVM to offer PtrAuth to its guests.
In the tradition of not having separate security between host-EL1 and EL2, EL2 reuses the keys set up by host-EL1. It is likely that, should we switch to a mode where EL2 is more distrusting of EL1, we'd have private keys there.
The last patch is just an optimisation which I've lobbed with the rest of the series in order not to forget it.
Marc Zyngier (4):
KVM: arm64: Enable Pointer Authentication at EL2 if available
KVM: arm64: Allow ARM64_PTR_AUTH when ARM64_VHE=n
KVM: arm64: Allow PtrAuth to be enabled from userspace on non-VHE
systems
KVM: arm64: Check HCR_EL2 instead of shadow copy to swap PtrAuth
registers
arch/arm64/Kconfig | 4 +--- arch/arm64/include/asm/kvm_ptrauth.h | 4 ++-- arch/arm64/kvm/hyp-init.S | 11 +++++++++++ arch/arm64/kvm/reset.c | 21 ++++++++++----------- 4 files changed, 24 insertions(+), 16 deletions(-)
Signature · 1 line
2.27.0
Marc Zyngier
maintainerPATCH 1/4 KVM: arm64: Enable Pointer Authentication at EL2 if available
While initializing EL2, switch Pointer Authentication if detected from EL1. We use the EL1-provided keys though.
--- arch/arm64/kvm/hyp-init.S | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/kvm/hyp-init.S +11 -0
@@ -104,6 +104,17 @@ alternative_else_nop_endif */ mov_q x4, (SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A)) CPU_BE( orr x4, x4, #SCTLR_ELx_EE) +alternative_if ARM64_HAS_ADDRESS_AUTH_ARCH + b 1f +alternative_else_nop_endif +alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF + b 2f +alternative_else_nop_endif +1: + orr x4, x4, #(SCTLR_ELx_ENIA | SCTLR_ELx_ENIB) + orr x4, x4, #SCTLR_ELx_ENDA + orr x4, x4, #SCTLR_ELx_ENDB +2: msr sctlr_el2, x4 isb
Signature · 1 line
2.27.0
Re: [PATCH 1/4] KVM: arm64: Enable Pointer Authentication at EL2 if available
Quoted 1 line · Marc Zyngier
While initializing EL2, switch Pointer Authentication if detected
^ nit: on?
Quoted 15 lines
from EL1. We use the EL1-provided keys though.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp-init.S | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/arm64/kvm/hyp-init.S +0
-0@@ -104,6 +104,17 @@ alternative_else_nop_endif */ mov_q x4, (SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A)) CPU_BE( orr x4, x4, #SCTLR_ELx_EE)
arch/arm64/kvm/hyp-init.S alternative_else_nop_endif · line 116
Quoted 10 lines
arch/arm64/kvm/hyp-init.S +10
-0+alternative_if ARM64_HAS_ADDRESS_AUTH_ARCH + b 1f +alternative_else_nop_endif +alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF + b 2f +alternative_else_nop_endif +1: + orr x4, x4, #(SCTLR_ELx_ENIA | SCTLR_ELx_ENIB) + orr x4, x4, #SCTLR_ELx_ENDA + orr x4, x4, #SCTLR_ELx_ENDB
mm/proc.S builds the mask with ldr and ors it in one go, would be nice to use the same pattern.
arch/arm64/kvm/hyp-init.S alternative_else_nop_endif · line 119
Quoted 3 lines
arch/arm64/kvm/hyp-init.S +1
-0+2: msr sctlr_el2, x4 isb
Marc Zyngier
maintainerRe: [PATCH 1/4] KVM: arm64: Enable Pointer Authentication at EL2 if available
Hi Andrew,
Quoted 4 lines · Andrew Scull
Quoted 1 line · Marc Zyngier
While initializing EL2, switch Pointer Authentication if detected
^ nit: on?
Yes.
Quoted 21 lines
Quoted 21 lines
from EL1. We use the EL1-provided keys though.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp-init.S | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/arm64/kvm/hyp-init.S +5
-0@@ -104,6 +104,17 @@ alternative_else_nop_endif */ mov_q x4, (SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A)) CPU_BE( orr x4, x4, #SCTLR_ELx_EE) +alternative_if ARM64_HAS_ADDRESS_AUTH_ARCH + b 1f +alternative_else_nop_endif +alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF + b 2f
Quoted 8 lines
arch/arm64/kvm/hyp-init.S alternative_else_nop_endif · line 116
Quoted 5 lines
arch/arm64/kvm/hyp-init.S +5
-0+alternative_else_nop_endif +1: + orr x4, x4, #(SCTLR_ELx_ENIA | SCTLR_ELx_ENIB) + orr x4, x4, #SCTLR_ELx_ENDA + orr x4, x4, #SCTLR_ELx_ENDB
mm/proc.Sbuilds the mask with ldr and ors it in one go, would be nice to use the same pattern.
Do you actually mean kernel/head.S, or even __ptrauth_keys_init_cpu in asm/asm_pointer_auth.h?
If so, I agree that it'd be good to make it look similar by using the mov_q macro, at the expense of a spare register (which we definitely can afford here).
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Mark Rutland
reviewerRe: [PATCH 1/4] KVM: arm64: Enable Pointer Authentication at EL2 if available
In reply to Marc ZyngierQuoted 2 lines · Marc Zyngier
While initializing EL2, switch Pointer Authentication if detected from EL1. We use the EL1-provided keys though.
Perhaps "enable address authentication", to avoid confusion with context-switch, and since generic authentication cannot be disabled locally at EL2.
Quoted 11 lines
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp-init.S | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/arm64/kvm/hyp-init.S +0
-0
arch/arm64/kvm/hyp-init.S alternative_else_nop_endif · line 112
Quoted 9 lines
arch/arm64/kvm/hyp-init.S +6
-0@@ -104,6 +104,17 @@ alternative_else_nop_endif */ mov_q x4, (SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A)) CPU_BE( orr x4, x4, #SCTLR_ELx_EE) +alternative_if ARM64_HAS_ADDRESS_AUTH_ARCH + b 1f +alternative_else_nop_endif +alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF + b 2f +alternative_else_nop_endif
I see this is the same pattern we use in the kvm context switch, but I think we can use the ARM64_HAS_ADDRESS_AUTH cap instead (likewise in the existing code).
AFAICT that won't permit mismatch given both ARM64_HAS_ADDRESS_AUTH_ARCH and ARM64_HAS_ADDRESS_AUTH_IMP_DEF are dealt with as ARM64_CPUCAP_BOOT_CPU_FEATURE.
arch/arm64/kvm/hyp-init.S alternative_else_nop_endif · line 116
Quoted 4 lines
arch/arm64/kvm/hyp-init.S +4
-0+1: + orr x4, x4, #(SCTLR_ELx_ENIA | SCTLR_ELx_ENIB) + orr x4, x4, #SCTLR_ELx_ENDA + orr x4, x4, #SCTLR_ELx_ENDB
Assuming we have a spare register, it would be nice if we could follow the same pattern as in proc.S, where we do:
| ldr x2, =SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | \ | SCTLR_ELx_ENDA | SCTLR_ELx_ENDB | orr x0, x0, x2
... though we could/should use mov_q rather than a load literal, here and in proc.S.
... otherwise this looks sound to me.
Thanks,
Mark.
Quoted 11 lines
arch/arm64/kvm/hyp-init.S +1
-0+2: msr sctlr_el2, x4 isbSignature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerRe: [PATCH 1/4] KVM: arm64: Enable Pointer Authentication at EL2 if available
Quoted 7 lines · Mark Rutland
Quoted 2 lines · Marc Zyngier
While initializing EL2, switch Pointer Authentication if detected from EL1. We use the EL1-provided keys though.
Perhaps "enable address authentication", to avoid confusion with context-switch, and since generic authentication cannot be disabled locally at EL2.
Ah, fair enough.
Quoted 25 lines
Quoted 11 lines
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/hyp-init.S | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/arm64/kvm/hyp-init.S +0
-0arch/arm64/kvm/hyp-init.S alternative_else_nop_endif · line 112
Quoted 9 lines
arch/arm64/kvm/hyp-init.S +6
-0@@ -104,6 +104,17 @@ alternative_else_nop_endif */ mov_q x4, (SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A)) CPU_BE( orr x4, x4, #SCTLR_ELx_EE) +alternative_if ARM64_HAS_ADDRESS_AUTH_ARCH + b 1f +alternative_else_nop_endif +alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF + b 2f +alternative_else_nop_endifI see this is the same pattern we use in the kvm context switch, but I think we can use the
ARM64_HAS_ADDRESS_AUTHcap instead (likewise in the existing code).
Quoted 3 lines
AFAICT that won't permit mismatch given both
ARM64_HAS_ADDRESS_AUTH_ARCHandARM64_HAS_ADDRESS_AUTH_IMP_DEFare dealt with asARM64_CPUCAP_BOOT_CPU_FEATURE.
That'd be a nice cleanup, as the two back to back alternatives are a bit hard to read.
Quoted 9 lines
arch/arm64/kvm/hyp-init.S alternative_else_nop_endif · line 116
Quoted 5 lines
arch/arm64/kvm/hyp-init.S +4
-0+1: + orr x4, x4, #(SCTLR_ELx_ENIA | SCTLR_ELx_ENIB) + orr x4, x4, #SCTLR_ELx_ENDA + orr x4, x4, #SCTLR_ELx_ENDBAssuming we have a spare register, it would be nice if we could follow the same pattern as in
proc.S, where we do:
Quoted 6 lines
| ldr x2, =SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | \ | SCTLR_ELx_ENDA | SCTLR_ELx_ENDB | orr x0, x0, x2... though we could/should use
mov_qrather than a load literal, here and inproc.S.
Looks like this code isn't in -rc1 anymore, replaced with a mov_q in __ptrauth_keys_init_cpu.
I'll switch to that in v2.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Marc Zyngier
maintainerPATCH 2/4 KVM: arm64: Allow ARM64_PTR_AUTH when ARM64_VHE=n
In reply to Marc ZyngierWe currently prevent PtrAuth from even being built if KVM is selected, but VHE isn't. It is a bit of a pointless restriction, since we also check this at run time (rejecting the enabling of PtrAuth for the vcpu if we're not running with VHE).
Just drop this apparently useless restriction.
--- arch/arm64/Kconfig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm64/Kconfig +1 -3
@@ -1516,7 +1516,6 @@ menu "ARMv8.3 architectural features" config ARM64_PTR_AUTH bool "Enable support for pointer authentication" default y - depends on !KVM || ARM64_VHE depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC # GCC 9.1 and later inserts a .note.gnu.property section note for PAC # which is only understood by binutils starting with version 2.33.1.
@@ -1543,8 +1542,7 @@ config ARM64_PTR_AUTH The feature is detected at runtime. If the feature is not present in hardware it will not be advertised to userspace/KVM guest nor will it - be enabled. However, KVM guest also require VHE mode and hence - CONFIG_ARM64_VHE=y option to use this feature. + be enabled. If the feature is present on the boot CPU but not on a late CPU, then the late CPU will be parked. Also, if the boot CPU does not have
Signature · 1 line
2.27.0
Re: [PATCH 2/4] KVM: arm64: Allow ARM64_PTR_AUTH when ARM64_VHE=n
Quoted 25 lines · Marc Zyngier
We currently prevent PtrAuth from even being built if KVM is selected, but VHE isn't. It is a bit of a pointless restriction, since we also check this at run time (rejecting the enabling of PtrAuth for the vcpu if we're not running with VHE).
Just drop this apparently useless restriction.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/Kconfig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)arch/arm64/Kconfig +0
-1@@ -1516,7 +1516,6 @@ menu "ARMv8.3 architectural features" config ARM64_PTR_AUTH bool "Enable support for pointer authentication" default y - depends on !KVM || ARM64_VHE depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC # GCC 9.1 and later inserts a .note.gnu.property section note for PAC # which is only understood by binutils starting with version 2.33.1.
arch/arm64/Kconfig config ARM64_PTR_AUTH · line 1548
Quoted 9 lines
arch/arm64/Kconfig +1
-2@@ -1543,8 +1542,7 @@ config ARM64_PTR_AUTH The feature is detected at runtime. If the feature is not present in hardware it will not be advertised to userspace/KVM guest nor will it - be enabled. However, KVM guest also require VHE mode and hence - CONFIG_ARM64_VHE=y option to use this feature. + be enabled. If the feature is present on the boot CPU but not on a late CPU, then the late CPU will be parked. Also, if the boot CPU does not have
...and we just got the patch to let EL2 use the ptrauth instructions for the save restore in hyp/entry.S!
Re: [PATCH 2/4] KVM: arm64: Allow ARM64_PTR_AUTH when ARM64_VHE=n
In reply to Marc ZyngierQuoted 8 lines · Marc Zyngier
We currently prevent PtrAuth from even being built if KVM is selected, but VHE isn't. It is a bit of a pointless restriction, since we also check this at run time (rejecting the enabling of PtrAuth for the vcpu if we're not running with VHE).
Just drop this apparently useless restriction.
Signed-off-by Marc Zyngier <[email protected]>
I can't recall exactly why we had this limitation to begin with, but given we now save/restore the keys in common hyp code, I don't see a reason to forbid this, and agree the limitation is pointless, so:
Mark.
Quoted 33 lines
--- arch/arm64/Kconfig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)arch/arm64/Kconfig +1
-3@@ -1516,7 +1516,6 @@ menu "ARMv8.3 architectural features" config ARM64_PTR_AUTH bool "Enable support for pointer authentication" default y - depends on !KVM || ARM64_VHE depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC # GCC 9.1 and later inserts a .note.gnu.property section note for PAC # which is only understood by binutils starting with version 2.33.1.@@ -1543,8 +1542,7 @@ config ARM64_PTR_AUTH The feature is detected at runtime. If the feature is not present in hardware it will not be advertised to userspace/KVM guest nor will it - be enabled. However, KVM guest also require VHE mode and hence - CONFIG_ARM64_VHE=y option to use this feature. + be enabled. If the feature is present on the boot CPU but not on a late CPU, then the late CPU will be parked. Also, if the boot CPU does not haveSignature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 3/4 KVM: arm64: Allow PtrAuth to be enabled from userspace on non-VHE systems
In reply to Marc ZyngierNow that the scene is set for enabling PtrAuth on non-VHE, drop the restrictions preventing userspace from enabling it.
--- arch/arm64/kvm/reset.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
arch/arm64/kvm/reset.c +10 -11
@@ -42,6 +42,11 @@ static u32 kvm_ipa_limit;#define VCPU_RESET_PSTATE_SVC (PSR_AA32_MODE_SVC | PSR_AA32_A_BIT | \ PSR_AA32_I_BIT | PSR_AA32_F_BIT) +static bool system_has_full_ptr_auth (void ) +{ +return system_supports_address_auth () &&system_supports_generic_auth (); +} +/** * kvm_arch_vm_ioctl_check_extension *
@@ -80,8 +85,7 @@ int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext)break ;case KVM_CAP_ARM_PTRAUTH_ADDRESS :case KVM_CAP_ARM_PTRAUTH_GENERIC : - r =has_vhe () &&system_supports_address_auth () && -system_supports_generic_auth (); + r =system_has_full_ptr_auth ();break ;default : r =0 ;
@@ -205,19 +209,14 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)static int kvm_vcpu_enable_ptrauth (struct kvm_vcpu *vcpu) { -/* Support ptrauth only if the system supports these capabilities. */ -if (!has_vhe ()) -return -EINVAL ; - -if (!system_supports_address_auth () || - !system_supports_generic_auth ()) -return -EINVAL ;/* * For now make sure that both address/generic pointer authentication -* features are requested by the userspace together. +* features are requested by the userspace together and the system +* supports these capabilities. */ if (!test_bit (KVM_ARM_VCPU_PTRAUTH_ADDRESS , vcpu->arch.features) || - !test_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , vcpu->arch.features)) + !test_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , vcpu->arch.features) || + !system_has_full_ptr_auth ())return -EINVAL ; vcpu->arch.flags |=KVM_ARM64_GUEST_HAS_PTRAUTH ;
Signature · 1 line
2.27.0
Re: [PATCH 3/4] KVM: arm64: Allow PtrAuth to be enabled from userspace on non-VHE systems
Quoted 48 lines · Marc Zyngier
Now that the scene is set for enabling PtrAuth on non-VHE, drop the restrictions preventing userspace from enabling it.
Signed-off-by Marc Zyngier <[email protected]>--- arch/arm64/kvm/reset.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)arch/arm64/kvm/reset.c +6
-10@@ -42,6 +42,11 @@ static u32 kvm_ipa_limit;#define VCPU_RESET_PSTATE_SVC (PSR_AA32_MODE_SVC | PSR_AA32_A_BIT | \ PSR_AA32_I_BIT | PSR_AA32_F_BIT) +static bool system_has_full_ptr_auth (void ) +{ +return system_supports_address_auth () &&system_supports_generic_auth (); +} +/** * kvm_arch_vm_ioctl_check_extension * @@ -80,8 +85,7 @@ int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext)break ;case KVM_CAP_ARM_PTRAUTH_ADDRESS :case KVM_CAP_ARM_PTRAUTH_GENERIC : - r =has_vhe () &&system_supports_address_auth () && -system_supports_generic_auth (); + r =system_has_full_ptr_auth ();break ;default : r =0 ;@@ -205,19 +209,14 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)static int kvm_vcpu_enable_ptrauth (struct kvm_vcpu *vcpu) { -/* Support ptrauth only if the system supports these capabilities. */ -if (!has_vhe ()) -return -EINVAL ; - -if (!system_supports_address_auth () || - !system_supports_generic_auth ()) -return -EINVAL ;/* * For now make sure that both address/generic pointer authentication -* features are requested by the userspace together.
arch/arm64/kvm/reset.c static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu) · line 222
Quoted 10 lines
arch/arm64/kvm/reset.c +4
-1+* features are requested by the userspace together and the system +* supports these capabilities. */ if (!test_bit (KVM_ARM_VCPU_PTRAUTH_ADDRESS , vcpu->arch.features) || - !test_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , vcpu->arch.features)) + !test_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , vcpu->arch.features) || + !system_has_full_ptr_auth ())return -EINVAL ; vcpu->arch.flags |=KVM_ARM64_GUEST_HAS_PTRAUTH ;
That was easy. Let EL2 use ptrauth and it can save and restore the guest's state and done.
Re: [PATCH 3/4] KVM: arm64: Allow PtrAuth to be enabled from userspace on non-VHE systems
In reply to Marc ZyngierQuoted 4 lines · Marc Zyngier
Now that the scene is set for enabling PtrAuth on non-VHE, drop the restrictions preventing userspace from enabling it.
Signed-off-by Marc Zyngier <[email protected]>
Other than dropping the has_vhe() check this appears to be functionally equivalent and easier to follow, so:
Mark.
Quoted 61 lines
--- arch/arm64/kvm/reset.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)arch/arm64/kvm/reset.c +10
-11@@ -42,6 +42,11 @@ static u32 kvm_ipa_limit;#define VCPU_RESET_PSTATE_SVC (PSR_AA32_MODE_SVC | PSR_AA32_A_BIT | \ PSR_AA32_I_BIT | PSR_AA32_F_BIT) +static bool system_has_full_ptr_auth (void ) +{ +return system_supports_address_auth () &&system_supports_generic_auth (); +} +/** * kvm_arch_vm_ioctl_check_extension * @@ -80,8 +85,7 @@ int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext)break ;case KVM_CAP_ARM_PTRAUTH_ADDRESS :case KVM_CAP_ARM_PTRAUTH_GENERIC : - r =has_vhe () &&system_supports_address_auth () && -system_supports_generic_auth (); + r =system_has_full_ptr_auth ();break ;default : r =0 ;@@ -205,19 +209,14 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)static int kvm_vcpu_enable_ptrauth (struct kvm_vcpu *vcpu) { -/* Support ptrauth only if the system supports these capabilities. */ -if (!has_vhe ()) -return -EINVAL ; - -if (!system_supports_address_auth () || - !system_supports_generic_auth ()) -return -EINVAL ;/* * For now make sure that both address/generic pointer authentication -* features are requested by the userspace together. +* features are requested by the userspace together and the system +* supports these capabilities. */ if (!test_bit (KVM_ARM_VCPU_PTRAUTH_ADDRESS , vcpu->arch.features) || - !test_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , vcpu->arch.features)) + !test_bit (KVM_ARM_VCPU_PTRAUTH_GENERIC , vcpu->arch.features) || + !system_has_full_ptr_auth ())return -EINVAL ; vcpu->arch.flags |=KVM_ARM64_GUEST_HAS_PTRAUTH ;Signature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Marc Zyngier
maintainerPATCH 4/4 KVM: arm64: Check HCR_EL2 instead of shadow copy to swap PtrAuth registers
In reply to Marc ZyngierWhen save/restoring PtrAuth registers between host and guest, it is pretty useless to fetch the in-memory state, while we have the right state in the HCR_EL2 system register. Use that instead.
--- arch/arm64/include/asm/kvm_ptrauth.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/kvm_ptrauth.h +2 -2
@@ -74,7 +74,7 @@ alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF b 1001f alternative_else_nop_endif 1000: - ldr \reg1, [\g_ctxt, #(VCPU_HCR_EL2 - VCPU_CONTEXT)] + mrs \reg1, hcr_el2 and \reg1, \reg1, #(HCR_API | HCR_APK) cbz \reg1, 1001f add \reg1, \g_ctxt, #CPU_APIAKEYLO_EL1
@@ -90,7 +90,7 @@ alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF b 2001f alternative_else_nop_endif 2000: - ldr \reg1, [\g_ctxt, #(VCPU_HCR_EL2 - VCPU_CONTEXT)] + mrs \reg1, hcr_el2 and \reg1, \reg1, #(HCR_API | HCR_APK) cbz \reg1, 2001f add \reg1, \g_ctxt, #CPU_APIAKEYLO_EL1
Signature · 1 line
2.27.0
Re: [PATCH 4/4] KVM: arm64: Check HCR_EL2 instead of shadow copy to swap PtrAuth registers
Quoted 5 lines · Marc Zyngier
When save/restoring PtrAuth registers between host and guest, it is pretty useless to fetch the in-memory state, while we have the right state in the
HCR_EL2system register. Use that instead.Signed-off-by Marc Zyngier <[email protected]>
It took me a while to spot that we switched the guest/host hcr_el2 value in the __activate_traps() and __deactivate_traps() paths, but given that this is only called in the __kvm_vcpu_run_*() paths called between those, I agree this is sound. Given that:
Mark.
Quoted 33 lines
--- arch/arm64/include/asm/kvm_ptrauth.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)arch/arm64/include/asm/kvm_ptrauth.h +2
-2@@ -74,7 +74,7 @@ alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF b 1001f alternative_else_nop_endif 1000: - ldr \reg1, [\g_ctxt, #(VCPU_HCR_EL2 - VCPU_CONTEXT)] + mrs \reg1, hcr_el2 and \reg1, \reg1, #(HCR_API | HCR_APK) cbz \reg1, 1001f add \reg1, \g_ctxt, #CPU_APIAKEYLO_EL1@@ -90,7 +90,7 @@ alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF b 2001f alternative_else_nop_endif 2000: - ldr \reg1, [\g_ctxt, #(VCPU_HCR_EL2 - VCPU_CONTEXT)] + mrs \reg1, hcr_el2 and \reg1, \reg1, #(HCR_API | HCR_APK) cbz \reg1, 2001f add \reg1, \g_ctxt, #CPU_APIAKEYLO_EL1Signature · 6 lines
2.27.0 _______________________________________________ kvmarm mailing list [email protected] https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
Quoted 4 lines · Marc Zyngier
Not having PtrAuth on non-VHE KVM (for whatever reason VHE is not enabled on a v8.3 system) has always looked like an oddity. This trivial series remedies it, and allows a non-VHE KVM to offer PtrAuth to its guests.
How likely do you think it is that people will use such a configuration?
The only reason I can see for people to build a kernel with CONFIG_VHE=n is as a workaround for broken hardware, or because the kernel is too old to support VHE (in which case it doesn't understand ptrauth either, so it is irrelevant whether ptrauth depends on VHE).
I wonder whether it's therefore better to "encourage" people to turn VHE on by making subsequent features depend on it where appropriate. We do want multiplatform kernels to be configured with CONFIG_VHE=y for example.
I ask this, because SVE suffers the same "oddity". If SVE can be enabled for non-VHE kernels straightforwardly then there's no reason not to do so, but I worried in the past that this would duplicate complex code that would never be tested or used.
If supporting ptrauth with !VHE is as simple as this series suggests, then it's low-risk. Perhaps SVE isn't much worse. I was chasing nasty bugs around at the time the SVE KVM support was originally written, and didn't want to add more unknowns into the mix...
(Note, this is not an offer from me to do the SVE work!)
[...]
Cheers
---Dave
Marc Zyngier
maintainerHi Dave,
Quoted 7 lines · Dave Martin
Quoted 4 lines · Marc Zyngier
Not having PtrAuth on non-VHE KVM (for whatever reason VHE is not enabled on a v8.3 system) has always looked like an oddity. This trivial series remedies it, and allows a non-VHE KVM to offer PtrAuth to its guests.
How likely do you think it is that people will use such a configuration?
Depending on the use case, very. See below.
Quoted 4 lines
The only reason I can see for people to build a kernel with
CONFIG_VHE=nis as a workaround for broken hardware, or because the kernel is too old to support VHE (in which case it doesn't understand ptrauth either, so it is irrelevant whether ptrauth depends on VHE).
Part of the work happening around running protected VMs (which cannot be tampered with from EL1/0 host) makes it mandatory to disable VHE, so that we can wrap the host EL1 in its own Stage-2 page tables. We (the Android kernel team) are actively working on enabling this feature.
Quoted 4 lines
I wonder whether it's therefore better to "encourage" people to turn VHE on by making subsequent features depend on it where appropriate. We do want multiplatform kernels to be configured with
CONFIG_VHE=yfor example.
I'm all for having VHE on for platforms that support it. Which is why CONFIG_VHE=y is present in defconfig. However, we cannot offer the same level of guarantee as we can hopefully achieve with non-VHE (we can drop mappings from Stage-1, but can't protect VMs from an evil or compromised host). This is a very different use case from the usual "reduced hypervisor overhead" that we want in the general case.
Quoted 4 lines
I ask this, because SVE suffers the same "oddity". If SVE can be enabled for non-VHE kernels straightforwardly then there's no reason not to do so, but I worried in the past that this would duplicate complex code that would never be tested or used.
It is a concern. I guess that if we manage to get some traction on Android, then the feature will get some testing! And yes, SVE is next on my list.
Quoted 4 lines
If supporting ptrauth with !VHE is as simple as this series suggests, then it's low-risk. Perhaps SVE isn't much worse. I was chasing nasty bugs around at the time the SVE KVM support was originally written, and didn't want to add more unknowns into the mix...
I think having started with a slightly smaller problem space was the right thing to do at the time. We are now reasonably confident that KVM and SVE are working correctly together, and we can now try to enable it on !VHE.
Thanks,
M.
Signature · 1 line
Jazz is not dead. It just smells funny...
Quoted 50 lines · Marc Zyngier
Hi Dave,
Quoted 7 lines · Dave Martin
Quoted 4 lines · Marc Zyngier
Not having PtrAuth on non-VHE KVM (for whatever reason VHE is not enabled on a v8.3 system) has always looked like an oddity. This trivial series remedies it, and allows a non-VHE KVM to offer PtrAuth to its guests.
How likely do you think it is that people will use such a configuration?
Depending on the use case, very. See below.
Quoted 4 lines
The only reason I can see for people to build a kernel with
CONFIG_VHE=nis as a workaround for broken hardware, or because the kernel is too old to support VHE (in which case it doesn't understand ptrauth either, so it is irrelevant whether ptrauth depends on VHE).Part of the work happening around running protected VMs (which cannot be tampered with from EL1/0 host) makes it mandatory to disable VHE, so that we can wrap the host EL1 in its own Stage-2 page tables. We (the Android kernel team) are actively working on enabling this feature.
Quoted 4 lines
I wonder whether it's therefore better to "encourage" people to turn VHE on by making subsequent features depend on it where appropriate. We do want multiplatform kernels to be configured with
CONFIG_VHE=yfor example.I'm all for having VHE on for platforms that support it. Which is why
CONFIG_VHE=yis present in defconfig. However, we cannot offer the same level of guarantee as we can hopefully achieve with non-VHE (we can drop mappings from Stage-1, but can't protect VMs from an evil or compromised host). This is a very different use case from the usual "reduced hypervisor overhead" that we want in the general case.Quoted 4 lines
I ask this, because SVE suffers the same "oddity". If SVE can be enabled for non-VHE kernels straightforwardly then there's no reason not to do so, but I worried in the past that this would duplicate complex code that would never be tested or used.
It is a concern. I guess that if we manage to get some traction on Android, then the feature will get some testing! And yes, SVE is next on my list.
Quoted 4 lines
If supporting ptrauth with !VHE is as simple as this series suggests, then it's low-risk. Perhaps SVE isn't much worse. I was chasing nasty bugs around at the time the SVE KVM support was originally written, and didn't want to add more unknowns into the mix...
Quoted 4 lines
I think having started with a slightly smaller problem space was the right thing to do at the time. We are now reasonably confident that KVM and SVE are working correctly together, and we can now try to enable it on !VHE.
Cool, now I understand.
Cheers
---Dave