Commit 58db67e9 authored by Oliver Upton's avatar Oliver Upton Committed by Marc Zyngier
Browse files

KVM: arm64: Select debug state to save/restore based on debug owner



Select the set of debug registers to use based on the owner rather than
relying on debug_ptr. Besides the code cleanup, this allows us to
eliminate a couple instances kern_hyp_va() as well.

Tested-by: default avatarJames Clark <james.clark@linaro.org>
Signed-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20241219224116.3941496-9-oliver.upton@linux.dev


Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
parent 4cefbec9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1357,6 +1357,8 @@ void kvm_debug_set_guest_ownership(struct kvm_vcpu *vcpu);
#define kvm_vcpu_os_lock_enabled(vcpu)		\
	(!!(__vcpu_sys_reg(vcpu, OSLSR_EL1) & OSLSR_EL1_OSLK))

#define kvm_debug_regs_in_use(vcpu)		\
	((vcpu)->arch.debug_owner != VCPU_DEBUG_FREE)
#define kvm_host_owns_debug_regs(vcpu)		\
	((vcpu)->arch.debug_owner == VCPU_DEBUG_HOST_OWNED)

+19 −4
Original line number Diff line number Diff line
@@ -88,6 +88,21 @@
	default:	write_debug(ptr[0], reg, 0);			\
	}

static struct kvm_guest_debug_arch *__vcpu_debug_regs(struct kvm_vcpu *vcpu)
{
	switch (vcpu->arch.debug_owner) {
	case VCPU_DEBUG_FREE:
		WARN_ON_ONCE(1);
		fallthrough;
	case VCPU_DEBUG_GUEST_OWNED:
		return &vcpu->arch.vcpu_debug_state;
	case VCPU_DEBUG_HOST_OWNED:
		return &vcpu->arch.external_debug_state;
	}

	return NULL;
}

static void __debug_save_state(struct kvm_guest_debug_arch *dbg,
			       struct kvm_cpu_context *ctxt)
{
@@ -132,13 +147,13 @@ static inline void __debug_switch_to_guest_common(struct kvm_vcpu *vcpu)
	struct kvm_guest_debug_arch *host_dbg;
	struct kvm_guest_debug_arch *guest_dbg;

	if (!vcpu_get_flag(vcpu, DEBUG_DIRTY))
	if (!kvm_debug_regs_in_use(vcpu))
		return;

	host_ctxt = host_data_ptr(host_ctxt);
	guest_ctxt = &vcpu->arch.ctxt;
	host_dbg = host_data_ptr(host_debug_state.regs);
	guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
	guest_dbg = __vcpu_debug_regs(vcpu);

	__debug_save_state(host_dbg, host_ctxt);
	__debug_restore_state(guest_dbg, guest_ctxt);
@@ -151,13 +166,13 @@ static inline void __debug_switch_to_host_common(struct kvm_vcpu *vcpu)
	struct kvm_guest_debug_arch *host_dbg;
	struct kvm_guest_debug_arch *guest_dbg;

	if (!vcpu_get_flag(vcpu, DEBUG_DIRTY))
	if (!kvm_debug_regs_in_use(vcpu))
		return;

	host_ctxt = host_data_ptr(host_ctxt);
	guest_ctxt = &vcpu->arch.ctxt;
	host_dbg = host_data_ptr(host_debug_state.regs);
	guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
	guest_dbg = __vcpu_debug_regs(vcpu);

	__debug_save_state(guest_dbg, guest_ctxt);
	__debug_restore_state(host_dbg, host_ctxt);