]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: arm64: Reload vCPU for accesses to OSLAR_EL1
authorOliver Upton <oliver.upton@linux.dev>
Thu, 19 Dec 2024 22:41:09 +0000 (14:41 -0800)
committerMarc Zyngier <maz@kernel.org>
Fri, 20 Dec 2024 09:01:25 +0000 (09:01 +0000)
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 <james.clark@linaro.org>
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20241219224116.3941496-13-oliver.upton@linux.dev
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/debug.c
arch/arm64/kvm/sys_regs.c

index a6796a952af7accd3bc9d8771d89b6126a941319..d61b8ed32a21a7f8d90d7c756e8d6acc4bfdd4f5 100644 (file)
@@ -1346,6 +1346,7 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu);
 void kvm_arm_clear_debug(struct kvm_vcpu *vcpu);
 void kvm_vcpu_load_debug(struct kvm_vcpu *vcpu);
 void kvm_debug_set_guest_ownership(struct kvm_vcpu *vcpu);
+void kvm_debug_handle_oslar(struct kvm_vcpu *vcpu, u64 val);
 
 #define kvm_vcpu_os_lock_enabled(vcpu)         \
        (!!(__vcpu_sys_reg(vcpu, OSLSR_EL1) & OSLSR_EL1_OSLK))
index a4ae17c31fa870ceb1344f6551c7856aa250dc66..dec023673d4cee69a1ee8925914b036d6b2dd951 100644 (file)
@@ -288,3 +288,16 @@ void kvm_debug_set_guest_ownership(struct kvm_vcpu *vcpu)
 
        vcpu->arch.debug_owner = VCPU_DEBUG_GUEST_OWNED;
 }
+
+void kvm_debug_handle_oslar(struct kvm_vcpu *vcpu, u64 val)
+{
+       if (val & OSLAR_EL1_OSLK)
+               __vcpu_sys_reg(vcpu, OSLSR_EL1) |= OSLSR_EL1_OSLK;
+       else
+               __vcpu_sys_reg(vcpu, OSLSR_EL1) &= ~OSLSR_EL1_OSLK;
+
+       preempt_disable();
+       kvm_arch_vcpu_put(vcpu);
+       kvm_arch_vcpu_load(vcpu, smp_processor_id());
+       preempt_enable();
+}
index 66db77fb6201e106810ff555d14402c679ac4e0d..ed4adbf5a25e0e75be7f56811196b2c73db707d1 100644 (file)
@@ -570,17 +570,10 @@ static bool trap_oslar_el1(struct kvm_vcpu *vcpu,
                           struct sys_reg_params *p,
                           const struct sys_reg_desc *r)
 {
-       u64 oslsr;
-
        if (!p->is_write)
                return read_from_write_only(vcpu, p, r);
 
-       /* Forward the OSLK bit to OSLSR */
-       oslsr = __vcpu_sys_reg(vcpu, OSLSR_EL1) & ~OSLSR_EL1_OSLK;
-       if (p->regval & OSLAR_EL1_OSLK)
-               oslsr |= OSLSR_EL1_OSLK;
-
-       __vcpu_sys_reg(vcpu, OSLSR_EL1) = oslsr;
+       kvm_debug_handle_oslar(vcpu, p->regval);
        return true;
 }