Skip to content

Commit 06d22a9

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Reload vCPU for accesses to OSLAR_EL1
KVM takes ownership of the debug regs if the guest enables the OS lock, as it needs to use MDSCR_EL1 to mask debug exceptions. Just reload the vCPU if the guest toggles the OS lock, relying on kvm_vcpu_load_debug() to update the debug owner and get the right trap configuration in place. 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 beb470d commit 06d22a9

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,7 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu);
13461346
void kvm_arm_clear_debug(struct kvm_vcpu *vcpu);
13471347
void kvm_vcpu_load_debug(struct kvm_vcpu *vcpu);
13481348
void kvm_debug_set_guest_ownership(struct kvm_vcpu *vcpu);
1349+
void kvm_debug_handle_oslar(struct kvm_vcpu *vcpu, u64 val);
13491350

13501351
#define kvm_vcpu_os_lock_enabled(vcpu) \
13511352
(!!(__vcpu_sys_reg(vcpu, OSLSR_EL1) & OSLSR_EL1_OSLK))

arch/arm64/kvm/debug.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,16 @@ void kvm_debug_set_guest_ownership(struct kvm_vcpu *vcpu)
288288

289289
vcpu->arch.debug_owner = VCPU_DEBUG_GUEST_OWNED;
290290
}
291+
292+
void kvm_debug_handle_oslar(struct kvm_vcpu *vcpu, u64 val)
293+
{
294+
if (val & OSLAR_EL1_OSLK)
295+
__vcpu_sys_reg(vcpu, OSLSR_EL1) |= OSLSR_EL1_OSLK;
296+
else
297+
__vcpu_sys_reg(vcpu, OSLSR_EL1) &= ~OSLSR_EL1_OSLK;
298+
299+
preempt_disable();
300+
kvm_arch_vcpu_put(vcpu);
301+
kvm_arch_vcpu_load(vcpu, smp_processor_id());
302+
preempt_enable();
303+
}

arch/arm64/kvm/sys_regs.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,17 +570,10 @@ static bool trap_oslar_el1(struct kvm_vcpu *vcpu,
570570
struct sys_reg_params *p,
571571
const struct sys_reg_desc *r)
572572
{
573-
u64 oslsr;
574-
575573
if (!p->is_write)
576574
return read_from_write_only(vcpu, p, r);
577575

578-
/* Forward the OSLK bit to OSLSR */
579-
oslsr = __vcpu_sys_reg(vcpu, OSLSR_EL1) & ~OSLSR_EL1_OSLK;
580-
if (p->regval & OSLAR_EL1_OSLK)
581-
oslsr |= OSLSR_EL1_OSLK;
582-
583-
__vcpu_sys_reg(vcpu, OSLSR_EL1) = oslsr;
576+
kvm_debug_handle_oslar(vcpu, p->regval);
584577
return true;
585578
}
586579

0 commit comments

Comments
 (0)