Skip to content

Commit fc27932

Browse files
author
Marc Zyngier
committed
Merge branch 'kvm-arm64/ptrauth-nvhe' into kvmarm-master/next-WIP
Signed-off-by: Marc Zyngier <[email protected]>
2 parents 300dca6 + 11ac16a commit fc27932

File tree

4 files changed

+29
-35
lines changed

4 files changed

+29
-35
lines changed

arch/arm64/Kconfig

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,6 @@ menu "ARMv8.3 architectural features"
15161516
config ARM64_PTR_AUTH
15171517
bool "Enable support for pointer authentication"
15181518
default y
1519-
depends on !KVM || ARM64_VHE
15201519
depends on (CC_HAS_SIGN_RETURN_ADDRESS || CC_HAS_BRANCH_PROT_PAC_RET) && AS_HAS_PAC
15211520
# Modern compilers insert a .note.gnu.property section note for PAC
15221521
# which is only understood by binutils starting with version 2.33.1.
@@ -1543,8 +1542,7 @@ config ARM64_PTR_AUTH
15431542

15441543
The feature is detected at runtime. If the feature is not present in
15451544
hardware it will not be advertised to userspace/KVM guest nor will it
1546-
be enabled. However, KVM guest also require VHE mode and hence
1547-
CONFIG_ARM64_VHE=y option to use this feature.
1545+
be enabled.
15481546

15491547
If the feature is present on the boot CPU but not on a late CPU, then
15501548
the late CPU will be parked. Also, if the boot CPU does not have

arch/arm64/include/asm/kvm_ptrauth.h

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,44 +61,36 @@
6161

6262
/*
6363
* Both ptrauth_switch_to_guest and ptrauth_switch_to_host macros will
64-
* check for the presence of one of the cpufeature flag
65-
* ARM64_HAS_ADDRESS_AUTH_ARCH or ARM64_HAS_ADDRESS_AUTH_IMP_DEF and
64+
* check for the presence ARM64_HAS_ADDRESS_AUTH, which is defined as
65+
* (ARM64_HAS_ADDRESS_AUTH_ARCH || ARM64_HAS_ADDRESS_AUTH_IMP_DEF) and
6666
* then proceed ahead with the save/restore of Pointer Authentication
67-
* key registers.
67+
* key registers if enabled for the guest.
6868
*/
6969
.macro ptrauth_switch_to_guest g_ctxt, reg1, reg2, reg3
70-
alternative_if ARM64_HAS_ADDRESS_AUTH_ARCH
71-
b 1000f
70+
alternative_if_not ARM64_HAS_ADDRESS_AUTH
71+
b .L__skip_switch\@
7272
alternative_else_nop_endif
73-
alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF
74-
b 1001f
75-
alternative_else_nop_endif
76-
1000:
77-
ldr \reg1, [\g_ctxt, #(VCPU_HCR_EL2 - VCPU_CONTEXT)]
73+
mrs \reg1, hcr_el2
7874
and \reg1, \reg1, #(HCR_API | HCR_APK)
79-
cbz \reg1, 1001f
75+
cbz \reg1, .L__skip_switch\@
8076
add \reg1, \g_ctxt, #CPU_APIAKEYLO_EL1
8177
ptrauth_restore_state \reg1, \reg2, \reg3
82-
1001:
78+
.L__skip_switch\@:
8379
.endm
8480

8581
.macro ptrauth_switch_to_host g_ctxt, h_ctxt, reg1, reg2, reg3
86-
alternative_if ARM64_HAS_ADDRESS_AUTH_ARCH
87-
b 2000f
88-
alternative_else_nop_endif
89-
alternative_if_not ARM64_HAS_ADDRESS_AUTH_IMP_DEF
90-
b 2001f
82+
alternative_if_not ARM64_HAS_ADDRESS_AUTH
83+
b .L__skip_switch\@
9184
alternative_else_nop_endif
92-
2000:
93-
ldr \reg1, [\g_ctxt, #(VCPU_HCR_EL2 - VCPU_CONTEXT)]
85+
mrs \reg1, hcr_el2
9486
and \reg1, \reg1, #(HCR_API | HCR_APK)
95-
cbz \reg1, 2001f
87+
cbz \reg1, .L__skip_switch\@
9688
add \reg1, \g_ctxt, #CPU_APIAKEYLO_EL1
9789
ptrauth_save_state \reg1, \reg2, \reg3
9890
add \reg1, \h_ctxt, #CPU_APIAKEYLO_EL1
9991
ptrauth_restore_state \reg1, \reg2, \reg3
10092
isb
101-
2001:
93+
.L__skip_switch\@:
10294
.endm
10395

10496
#else /* !CONFIG_ARM64_PTR_AUTH */

arch/arm64/kvm/hyp/nvhe/hyp-init.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ alternative_else_nop_endif
104104
*/
105105
mov_q x4, (SCTLR_EL2_RES1 | (SCTLR_ELx_FLAGS & ~SCTLR_ELx_A))
106106
CPU_BE( orr x4, x4, #SCTLR_ELx_EE)
107+
alternative_if ARM64_HAS_ADDRESS_AUTH
108+
mov_q x5, (SCTLR_ELx_ENIA | SCTLR_ELx_ENIB | \
109+
SCTLR_ELx_ENDA | SCTLR_ELx_ENDB)
110+
orr x4, x4, x5
111+
alternative_else_nop_endif
107112
msr sctlr_el2, x4
108113
isb
109114

arch/arm64/kvm/reset.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ static u32 kvm_ipa_limit;
4242
#define VCPU_RESET_PSTATE_SVC (PSR_AA32_MODE_SVC | PSR_AA32_A_BIT | \
4343
PSR_AA32_I_BIT | PSR_AA32_F_BIT)
4444

45+
static bool system_has_full_ptr_auth(void)
46+
{
47+
return system_supports_address_auth() && system_supports_generic_auth();
48+
}
49+
4550
/**
4651
* kvm_arch_vm_ioctl_check_extension
4752
*
@@ -80,8 +85,7 @@ int kvm_arch_vm_ioctl_check_extension(struct kvm *kvm, long ext)
8085
break;
8186
case KVM_CAP_ARM_PTRAUTH_ADDRESS:
8287
case KVM_CAP_ARM_PTRAUTH_GENERIC:
83-
r = has_vhe() && system_supports_address_auth() &&
84-
system_supports_generic_auth();
88+
r = system_has_full_ptr_auth();
8589
break;
8690
default:
8791
r = 0;
@@ -205,19 +209,14 @@ static void kvm_vcpu_reset_sve(struct kvm_vcpu *vcpu)
205209

206210
static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu)
207211
{
208-
/* Support ptrauth only if the system supports these capabilities. */
209-
if (!has_vhe())
210-
return -EINVAL;
211-
212-
if (!system_supports_address_auth() ||
213-
!system_supports_generic_auth())
214-
return -EINVAL;
215212
/*
216213
* For now make sure that both address/generic pointer authentication
217-
* features are requested by the userspace together.
214+
* features are requested by the userspace together and the system
215+
* supports these capabilities.
218216
*/
219217
if (!test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) ||
220-
!test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features))
218+
!test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features) ||
219+
!system_has_full_ptr_auth())
221220
return -EINVAL;
222221

223222
vcpu->arch.flags |= KVM_ARM64_GUEST_HAS_PTRAUTH;

0 commit comments

Comments
 (0)