Skip to content

Commit 0f1a6c5

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Flush/sync debug state in protected mode
The recent changes to debug state management broke self-hosted debug for guests when running in protected mode, since both the debug owner and the debug state itself aren't shared with the hyp's view of the vcpu. Fix it by flushing/syncing the relevant bits with the hyp vcpu. Fixes: beb470d ("KVM: arm64: Use debug_owner to track if debug regs need save/restore") Reported-by: Mark Brown <broonie@kernel.org> Closes: https://lore.kernel.org/kvmarm/5f62740f-a065-42d9-9f56-8fb648b9c63f@sirena.org.uk/ Signed-off-by: Oliver Upton <oliver.upton@linux.dev> Link: https://lore.kernel.org/r/20250131222922.1548780-3-oliver.upton@linux.dev Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 9bcbb61 commit 0f1a6c5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

arch/arm64/kvm/hyp/nvhe/hyp-main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,34 @@ static void fpsimd_sve_sync(struct kvm_vcpu *vcpu)
9191
*host_data_ptr(fp_owner) = FP_STATE_HOST_OWNED;
9292
}
9393

94+
static void flush_debug_state(struct pkvm_hyp_vcpu *hyp_vcpu)
95+
{
96+
struct kvm_vcpu *host_vcpu = hyp_vcpu->host_vcpu;
97+
98+
hyp_vcpu->vcpu.arch.debug_owner = host_vcpu->arch.debug_owner;
99+
100+
if (kvm_guest_owns_debug_regs(&hyp_vcpu->vcpu))
101+
hyp_vcpu->vcpu.arch.vcpu_debug_state = host_vcpu->arch.vcpu_debug_state;
102+
else if (kvm_host_owns_debug_regs(&hyp_vcpu->vcpu))
103+
hyp_vcpu->vcpu.arch.external_debug_state = host_vcpu->arch.external_debug_state;
104+
}
105+
106+
static void sync_debug_state(struct pkvm_hyp_vcpu *hyp_vcpu)
107+
{
108+
struct kvm_vcpu *host_vcpu = hyp_vcpu->host_vcpu;
109+
110+
if (kvm_guest_owns_debug_regs(&hyp_vcpu->vcpu))
111+
host_vcpu->arch.vcpu_debug_state = hyp_vcpu->vcpu.arch.vcpu_debug_state;
112+
else if (kvm_host_owns_debug_regs(&hyp_vcpu->vcpu))
113+
host_vcpu->arch.external_debug_state = hyp_vcpu->vcpu.arch.external_debug_state;
114+
}
115+
94116
static void flush_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
95117
{
96118
struct kvm_vcpu *host_vcpu = hyp_vcpu->host_vcpu;
97119

98120
fpsimd_sve_flush();
121+
flush_debug_state(hyp_vcpu);
99122

100123
hyp_vcpu->vcpu.arch.ctxt = host_vcpu->arch.ctxt;
101124

@@ -123,6 +146,7 @@ static void sync_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
123146
unsigned int i;
124147

125148
fpsimd_sve_sync(&hyp_vcpu->vcpu);
149+
sync_debug_state(hyp_vcpu);
126150

127151
host_vcpu->arch.ctxt = hyp_vcpu->vcpu.arch.ctxt;
128152

0 commit comments

Comments
 (0)