Skip to content

Commit 720ef46

Browse files
committed
KVM: arm64: Factor out helper for selecting exception target EL
Pull out the exception target selection from pend_sync_exception() for general use. Use PSR_MODE_ELxh as a shorthand for the target EL, as SP_ELx selection is handled further along in the hyp's exception emulation. Reviewed-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent abc693f commit 720ef46

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

arch/arm64/kvm/inject_fault.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
#include <asm/kvm_nested.h>
1616
#include <asm/esr.h>
1717

18-
static void pend_sync_exception(struct kvm_vcpu *vcpu)
18+
static unsigned int exception_target_el(struct kvm_vcpu *vcpu)
1919
{
2020
/* If not nesting, EL1 is the only possible exception target */
21-
if (likely(!vcpu_has_nv(vcpu))) {
22-
kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);
23-
return;
24-
}
21+
if (likely(!vcpu_has_nv(vcpu)))
22+
return PSR_MODE_EL1h;
2523

2624
/*
2725
* With NV, we need to pick between EL1 and EL2. Note that we
@@ -32,23 +30,25 @@ static void pend_sync_exception(struct kvm_vcpu *vcpu)
3230
switch(*vcpu_cpsr(vcpu) & PSR_MODE_MASK) {
3331
case PSR_MODE_EL2h:
3432
case PSR_MODE_EL2t:
35-
kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SYNC);
36-
break;
33+
return PSR_MODE_EL2h;
3734
case PSR_MODE_EL1h:
3835
case PSR_MODE_EL1t:
39-
kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);
40-
break;
36+
return PSR_MODE_EL1h;
4137
case PSR_MODE_EL0t:
42-
if (vcpu_el2_tge_is_set(vcpu))
43-
kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SYNC);
44-
else
45-
kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);
46-
break;
38+
return vcpu_el2_tge_is_set(vcpu) ? PSR_MODE_EL2h : PSR_MODE_EL1h;
4739
default:
4840
BUG();
4941
}
5042
}
5143

44+
static void pend_sync_exception(struct kvm_vcpu *vcpu)
45+
{
46+
if (exception_target_el(vcpu) == PSR_MODE_EL1h)
47+
kvm_pend_exception(vcpu, EXCEPT_AA64_EL1_SYNC);
48+
else
49+
kvm_pend_exception(vcpu, EXCEPT_AA64_EL2_SYNC);
50+
}
51+
5252
static bool match_target_el(struct kvm_vcpu *vcpu, unsigned long target)
5353
{
5454
return (vcpu_get_flag(vcpu, EXCEPT_MASK) == target);

0 commit comments

Comments
 (0)