Skip to content

Commit fa89d31

Browse files
Dave MartinMarc Zyngier
authored andcommitted
KVM: arm64: Repurpose vcpu_arch.debug_flags for general-purpose flags
In struct vcpu_arch, the debug_flags field is used to store debug-related flags about the vcpu state. Since we are about to add some more flags related to FPSIMD and SVE, it makes sense to add them to the existing flags field rather than adding new fields. Since there is only one debug_flags flag defined so far, there is plenty of free space for expansion. In preparation for adding more flags, this patch renames the debug_flags field to simply "flags", and updates comments appropriately. The flag definitions are also moved to <asm/kvm_host.h>, since their presence in <asm/kvm_asm.h> was for purely historical reasons: these definitions are not used from asm any more, and not very likely to be as more Hyp asm is migrated to C. KVM_ARM64_DEBUG_DIRTY_SHIFT has not been used since commit 1ea66d2 ("arm64: KVM: Move away from the assembly version of the world switch"), so this patch gets rid of that too. No functional change. Signed-off-by: Dave Martin <[email protected]> Reviewed-by: Marc Zyngier <[email protected]> Reviewed-by: Alex Bennée <[email protected]> Acked-by: Christoffer Dall <[email protected]> [maz: fixed minor conflict] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 0cff8e7 commit fa89d31

File tree

6 files changed

+18
-19
lines changed

6 files changed

+18
-19
lines changed

arch/arm64/include/asm/kvm_asm.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@
3030
/* The hyp-stub will return this for any kvm_call_hyp() call */
3131
#define ARM_EXCEPTION_HYP_GONE HVC_STUB_ERR
3232

33-
#define KVM_ARM64_DEBUG_DIRTY_SHIFT 0
34-
#define KVM_ARM64_DEBUG_DIRTY (1 << KVM_ARM64_DEBUG_DIRTY_SHIFT)
35-
3633
#ifndef __ASSEMBLY__
3734

3835
#include <linux/mm.h>

arch/arm64/include/asm/kvm_host.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ struct kvm_vcpu_arch {
216216
/* Exception Information */
217217
struct kvm_vcpu_fault_info fault;
218218

219-
/* Guest debug state */
220-
u64 debug_flags;
219+
/* Miscellaneous vcpu state flags */
220+
u64 flags;
221221

222222
/*
223223
* We maintain more than a single set of debug registers to support
@@ -293,6 +293,9 @@ struct kvm_vcpu_arch {
293293
bool sysregs_loaded_on_cpu;
294294
};
295295

296+
/* vcpu_arch flags field values: */
297+
#define KVM_ARM64_DEBUG_DIRTY (1 << 0)
298+
296299
#define vcpu_gp_regs(v) (&(v)->arch.ctxt.gp_regs)
297300

298301
/*

arch/arm64/kvm/debug.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ void kvm_arm_reset_debug_ptr(struct kvm_vcpu *vcpu)
103103
*
104104
* Additionally, KVM only traps guest accesses to the debug registers if
105105
* the guest is not actively using them (see the KVM_ARM64_DEBUG_DIRTY
106-
* flag on vcpu->arch.debug_flags). Since the guest must not interfere
106+
* flag on vcpu->arch.flags). Since the guest must not interfere
107107
* with the hardware state when debugging the guest, we must ensure that
108108
* trapping is enabled whenever we are debugging the guest using the
109109
* debug registers.
110110
*/
111111

112112
void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
113113
{
114-
bool trap_debug = !(vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY);
114+
bool trap_debug = !(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY);
115115
unsigned long mdscr;
116116

117117
trace_kvm_arm_setup_debug(vcpu, vcpu->guest_debug);
@@ -184,7 +184,7 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
184184
vcpu_write_sys_reg(vcpu, mdscr, MDSCR_EL1);
185185

186186
vcpu->arch.debug_ptr = &vcpu->arch.external_debug_state;
187-
vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY;
187+
vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
188188
trap_debug = true;
189189

190190
trace_kvm_arm_set_regset("BKPTS", get_num_brps(),
@@ -206,7 +206,7 @@ void kvm_arm_setup_debug(struct kvm_vcpu *vcpu)
206206

207207
/* If KDE or MDE are set, perform a full save/restore cycle. */
208208
if (vcpu_read_sys_reg(vcpu, MDSCR_EL1) & (DBG_MDSCR_KDE | DBG_MDSCR_MDE))
209-
vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY;
209+
vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
210210

211211
trace_kvm_arm_set_dreg32("MDCR_EL2", vcpu->arch.mdcr_el2);
212212
trace_kvm_arm_set_dreg32("MDSCR_EL1", vcpu_read_sys_reg(vcpu, MDSCR_EL1));

arch/arm64/kvm/hyp/debug-sr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void __hyp_text __debug_switch_to_guest(struct kvm_vcpu *vcpu)
163163
if (!has_vhe())
164164
__debug_save_spe_nvhe(&vcpu->arch.host_debug_state.pmscr_el1);
165165

166-
if (!(vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY))
166+
if (!(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY))
167167
return;
168168

169169
host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
@@ -185,7 +185,7 @@ void __hyp_text __debug_switch_to_host(struct kvm_vcpu *vcpu)
185185
if (!has_vhe())
186186
__debug_restore_spe_nvhe(vcpu->arch.host_debug_state.pmscr_el1);
187187

188-
if (!(vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY))
188+
if (!(vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY))
189189
return;
190190

191191
host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
@@ -196,7 +196,7 @@ void __hyp_text __debug_switch_to_host(struct kvm_vcpu *vcpu)
196196
__debug_save_state(vcpu, guest_dbg, guest_ctxt);
197197
__debug_restore_state(vcpu, host_dbg, host_ctxt);
198198

199-
vcpu->arch.debug_flags &= ~KVM_ARM64_DEBUG_DIRTY;
199+
vcpu->arch.flags &= ~KVM_ARM64_DEBUG_DIRTY;
200200
}
201201

202202
u32 __hyp_text __kvm_get_mdcr_el2(void)

arch/arm64/kvm/hyp/sysreg-sr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void __hyp_text __sysreg32_save_state(struct kvm_vcpu *vcpu)
196196
sysreg[DACR32_EL2] = read_sysreg(dacr32_el2);
197197
sysreg[IFSR32_EL2] = read_sysreg(ifsr32_el2);
198198

199-
if (has_vhe() || vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY)
199+
if (has_vhe() || vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY)
200200
sysreg[DBGVCR32_EL2] = read_sysreg(dbgvcr32_el2);
201201
}
202202

@@ -218,7 +218,7 @@ void __hyp_text __sysreg32_restore_state(struct kvm_vcpu *vcpu)
218218
write_sysreg(sysreg[DACR32_EL2], dacr32_el2);
219219
write_sysreg(sysreg[IFSR32_EL2], ifsr32_el2);
220220

221-
if (has_vhe() || vcpu->arch.debug_flags & KVM_ARM64_DEBUG_DIRTY)
221+
if (has_vhe() || vcpu->arch.flags & KVM_ARM64_DEBUG_DIRTY)
222222
write_sysreg(sysreg[DBGVCR32_EL2], dbgvcr32_el2);
223223
}
224224

arch/arm64/kvm/sys_regs.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include <asm/debug-monitors.h>
3232
#include <asm/esr.h>
3333
#include <asm/kvm_arm.h>
34-
#include <asm/kvm_asm.h>
3534
#include <asm/kvm_coproc.h>
3635
#include <asm/kvm_emulate.h>
3736
#include <asm/kvm_host.h>
@@ -338,7 +337,7 @@ static bool trap_debug_regs(struct kvm_vcpu *vcpu,
338337
{
339338
if (p->is_write) {
340339
vcpu_write_sys_reg(vcpu, p->regval, r->reg);
341-
vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY;
340+
vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
342341
} else {
343342
p->regval = vcpu_read_sys_reg(vcpu, r->reg);
344343
}
@@ -369,7 +368,7 @@ static void reg_to_dbg(struct kvm_vcpu *vcpu,
369368
}
370369

371370
*dbg_reg = val;
372-
vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY;
371+
vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
373372
}
374373

375374
static void dbg_to_reg(struct kvm_vcpu *vcpu,
@@ -1441,7 +1440,7 @@ static bool trap_debug32(struct kvm_vcpu *vcpu,
14411440
{
14421441
if (p->is_write) {
14431442
vcpu_cp14(vcpu, r->reg) = p->regval;
1444-
vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY;
1443+
vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
14451444
} else {
14461445
p->regval = vcpu_cp14(vcpu, r->reg);
14471446
}
@@ -1473,7 +1472,7 @@ static bool trap_xvr(struct kvm_vcpu *vcpu,
14731472
val |= p->regval << 32;
14741473
*dbg_reg = val;
14751474

1476-
vcpu->arch.debug_flags |= KVM_ARM64_DEBUG_DIRTY;
1475+
vcpu->arch.flags |= KVM_ARM64_DEBUG_DIRTY;
14771476
} else {
14781477
p->regval = *dbg_reg >> 32;
14791478
}

0 commit comments

Comments
 (0)