Skip to content

Commit b0ee510

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: nv: Honor MDCR_EL2.TDE routing for debug exceptions
Inject debug exceptions into vEL2 if MDCR_EL2.TDE is set. Tested-by: James Clark <[email protected]> Signed-off-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 2ca3f03 commit b0ee510

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

arch/arm64/include/asm/kvm_nested.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static inline u64 translate_ttbr0_el2_to_ttbr0_el1(u64 ttbr0)
6464
}
6565

6666
extern bool forward_smc_trap(struct kvm_vcpu *vcpu);
67+
extern bool forward_debug_exception(struct kvm_vcpu *vcpu);
6768
extern void kvm_init_nested(struct kvm *kvm);
6869
extern int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu);
6970
extern void kvm_init_nested_s2_mmu(struct kvm_s2_mmu *mmu);

arch/arm64/kvm/emulate-nested.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2345,24 +2345,39 @@ bool triage_sysreg_trap(struct kvm_vcpu *vcpu, int *sr_index)
23452345
return true;
23462346
}
23472347

2348-
static bool forward_traps(struct kvm_vcpu *vcpu, u64 control_bit)
2348+
static bool __forward_traps(struct kvm_vcpu *vcpu, unsigned int reg, u64 control_bit)
23492349
{
23502350
bool control_bit_set;
23512351

23522352
if (!vcpu_has_nv(vcpu))
23532353
return false;
23542354

2355-
control_bit_set = __vcpu_sys_reg(vcpu, HCR_EL2) & control_bit;
2355+
control_bit_set = __vcpu_sys_reg(vcpu, reg) & control_bit;
23562356
if (!is_hyp_ctxt(vcpu) && control_bit_set) {
23572357
kvm_inject_nested_sync(vcpu, kvm_vcpu_get_esr(vcpu));
23582358
return true;
23592359
}
23602360
return false;
23612361
}
23622362

2363+
static bool forward_hcr_traps(struct kvm_vcpu *vcpu, u64 control_bit)
2364+
{
2365+
return __forward_traps(vcpu, HCR_EL2, control_bit);
2366+
}
2367+
23632368
bool forward_smc_trap(struct kvm_vcpu *vcpu)
23642369
{
2365-
return forward_traps(vcpu, HCR_TSC);
2370+
return forward_hcr_traps(vcpu, HCR_TSC);
2371+
}
2372+
2373+
static bool forward_mdcr_traps(struct kvm_vcpu *vcpu, u64 control_bit)
2374+
{
2375+
return __forward_traps(vcpu, MDCR_EL2, control_bit);
2376+
}
2377+
2378+
bool forward_debug_exception(struct kvm_vcpu *vcpu)
2379+
{
2380+
return forward_mdcr_traps(vcpu, MDCR_EL2_TDE);
23662381
}
23672382

23682383
static u64 kvm_check_illegal_exception_return(struct kvm_vcpu *vcpu, u64 spsr)
@@ -2406,7 +2421,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu)
24062421
* Forward this trap to the virtual EL2 if the virtual
24072422
* HCR_EL2.NV bit is set and this is coming from !EL2.
24082423
*/
2409-
if (forward_traps(vcpu, HCR_NV))
2424+
if (forward_hcr_traps(vcpu, HCR_NV))
24102425
return;
24112426

24122427
spsr = vcpu_read_sys_reg(vcpu, SPSR_EL2);

arch/arm64/kvm/handle_exit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu)
183183
struct kvm_run *run = vcpu->run;
184184
u64 esr = kvm_vcpu_get_esr(vcpu);
185185

186+
if (!vcpu->guest_debug && forward_debug_exception(vcpu))
187+
return 1;
188+
186189
run->exit_reason = KVM_EXIT_DEBUG;
187190
run->debug.arch.hsr = lower_32_bits(esr);
188191
run->debug.arch.hsr_high = upper_32_bits(esr);

0 commit comments

Comments
 (0)