Skip to content

Commit 7e814a2

Browse files
Fuad Tabbaoupton
authored andcommitted
KVM: arm64: Tidying up PAuth code in KVM
Tidy up some of the PAuth trapping code to clear up some comments and avoid clang/checkpatch warnings. Also, don't bother setting PAuth HCR_EL2 bits in pKVM, since it's handled by the hypervisor. Signed-off-by: Fuad Tabba <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent 01ab08c commit 7e814a2

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

arch/arm64/include/asm/kvm_ptrauth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ alternative_else_nop_endif
104104

105105
#define __ptrauth_save_key(ctxt, key) \
106106
do { \
107-
u64 __val; \
107+
u64 __val; \
108108
__val = read_sysreg_s(SYS_ ## key ## KEYLO_EL1); \
109109
ctxt_sys_reg(ctxt, key ## KEYLO_EL1) = __val; \
110110
__val = read_sysreg_s(SYS_ ## key ## KEYHI_EL1); \

arch/arm64/kvm/arm.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu)
522522

523523
static void vcpu_set_pauth_traps(struct kvm_vcpu *vcpu)
524524
{
525-
if (vcpu_has_ptrauth(vcpu)) {
525+
if (vcpu_has_ptrauth(vcpu) && !is_protected_kvm_enabled()) {
526526
/*
527-
* Either we're running running an L2 guest, and the API/APK
528-
* bits come from L1's HCR_EL2, or API/APK are both set.
527+
* Either we're running an L2 guest, and the API/APK bits come
528+
* from L1's HCR_EL2, or API/APK are both set.
529529
*/
530530
if (unlikely(vcpu_has_nv(vcpu) && !is_hyp_ctxt(vcpu))) {
531531
u64 val;
@@ -542,16 +542,10 @@ static void vcpu_set_pauth_traps(struct kvm_vcpu *vcpu)
542542
* Save the host keys if there is any chance for the guest
543543
* to use pauth, as the entry code will reload the guest
544544
* keys in that case.
545-
* Protected mode is the exception to that rule, as the
546-
* entry into the EL2 code eagerly switch back and forth
547-
* between host and hyp keys (and kvm_hyp_ctxt is out of
548-
* reach anyway).
549545
*/
550-
if (is_protected_kvm_enabled())
551-
return;
552-
553546
if (vcpu->arch.hcr_el2 & (HCR_API | HCR_APK)) {
554547
struct kvm_cpu_context *ctxt;
548+
555549
ctxt = this_cpu_ptr_hyp_sym(kvm_hyp_ctxt);
556550
ptrauth_save_keys(ctxt);
557551
}

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <asm/kvm_hyp.h>
2828
#include <asm/kvm_mmu.h>
2929
#include <asm/kvm_nested.h>
30-
#include <asm/kvm_ptrauth.h>
3130
#include <asm/fpsimd.h>
3231
#include <asm/debug-monitors.h>
3332
#include <asm/processor.h>

arch/arm64/kvm/hyp/nvhe/switch.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,8 @@ static void __pmu_switch_to_host(struct kvm_vcpu *vcpu)
173173
static bool kvm_handle_pvm_sys64(struct kvm_vcpu *vcpu, u64 *exit_code)
174174
{
175175
/*
176-
* Make sure we handle the exit for workarounds and ptrauth
177-
* before the pKVM handling, as the latter could decide to
178-
* UNDEF.
176+
* Make sure we handle the exit for workarounds before the pKVM
177+
* handling, as the latter could decide to UNDEF.
179178
*/
180179
return (kvm_hyp_handle_sysreg(vcpu, exit_code) ||
181180
kvm_handle_pvm_sysreg(vcpu, exit_code));

0 commit comments

Comments
 (0)