Skip to content

Commit 58db67e

Browse files
ouptonMarc Zyngier
authored andcommitted
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: 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 4cefbec commit 58db67e

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,8 @@ void kvm_debug_set_guest_ownership(struct kvm_vcpu *vcpu);
13571357
#define kvm_vcpu_os_lock_enabled(vcpu) \
13581358
(!!(__vcpu_sys_reg(vcpu, OSLSR_EL1) & OSLSR_EL1_OSLK))
13591359

1360+
#define kvm_debug_regs_in_use(vcpu) \
1361+
((vcpu)->arch.debug_owner != VCPU_DEBUG_FREE)
13601362
#define kvm_host_owns_debug_regs(vcpu) \
13611363
((vcpu)->arch.debug_owner == VCPU_DEBUG_HOST_OWNED)
13621364

arch/arm64/kvm/hyp/include/hyp/debug-sr.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@
8888
default: write_debug(ptr[0], reg, 0); \
8989
}
9090

91+
static struct kvm_guest_debug_arch *__vcpu_debug_regs(struct kvm_vcpu *vcpu)
92+
{
93+
switch (vcpu->arch.debug_owner) {
94+
case VCPU_DEBUG_FREE:
95+
WARN_ON_ONCE(1);
96+
fallthrough;
97+
case VCPU_DEBUG_GUEST_OWNED:
98+
return &vcpu->arch.vcpu_debug_state;
99+
case VCPU_DEBUG_HOST_OWNED:
100+
return &vcpu->arch.external_debug_state;
101+
}
102+
103+
return NULL;
104+
}
105+
91106
static void __debug_save_state(struct kvm_guest_debug_arch *dbg,
92107
struct kvm_cpu_context *ctxt)
93108
{
@@ -132,13 +147,13 @@ static inline void __debug_switch_to_guest_common(struct kvm_vcpu *vcpu)
132147
struct kvm_guest_debug_arch *host_dbg;
133148
struct kvm_guest_debug_arch *guest_dbg;
134149

135-
if (!vcpu_get_flag(vcpu, DEBUG_DIRTY))
150+
if (!kvm_debug_regs_in_use(vcpu))
136151
return;
137152

138153
host_ctxt = host_data_ptr(host_ctxt);
139154
guest_ctxt = &vcpu->arch.ctxt;
140155
host_dbg = host_data_ptr(host_debug_state.regs);
141-
guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
156+
guest_dbg = __vcpu_debug_regs(vcpu);
142157

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

154-
if (!vcpu_get_flag(vcpu, DEBUG_DIRTY))
169+
if (!kvm_debug_regs_in_use(vcpu))
155170
return;
156171

157172
host_ctxt = host_data_ptr(host_ctxt);
158173
guest_ctxt = &vcpu->arch.ctxt;
159174
host_dbg = host_data_ptr(host_debug_state.regs);
160-
guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
175+
guest_dbg = __vcpu_debug_regs(vcpu);
161176

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

0 commit comments

Comments
 (0)