Skip to content

Commit 11ac16a

Browse files
author
Marc Zyngier
committed
KVM: arm64: Simplify PtrAuth alternative patching
We currently decide to execute the PtrAuth save/restore code based on a set of branches that evaluate as (ARM64_HAS_ADDRESS_AUTH_ARCH || ARM64_HAS_ADDRESS_AUTH_IMP_DEF). This can be easily replaced by a much simpler test as the ARM64_HAS_ADDRESS_AUTH capability is exactly this expression. Suggested-by: Mark Rutland <[email protected]> Acked-by: Mark Rutland <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 655169c commit 11ac16a

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

arch/arm64/include/asm/kvm_ptrauth.h

Lines changed: 11 additions & 19 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:
7773
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:
9385
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 */

0 commit comments

Comments
 (0)