Skip to content

Commit 8c02c2b

Browse files
ouptonMarc Zyngier
authored andcommitted
KVM: arm64: Avoid reading ID_AA64DFR0_EL1 for debug save/restore
Similar to other per-CPU profiling/debug features we handle, store the number of breakpoints/watchpoints in kvm_host_data to avoid reading the ID register 4 times on every guest entry/exit. And if you're in the nested virt business that's quite a few avoidable exits to the L0 hypervisor. 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 b0ee510 commit 8c02c2b

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

arch/arm64/include/asm/kvm_host.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,10 @@ struct kvm_host_data {
661661

662662
/* Number of programmable event counters (PMCR_EL0.N) for this CPU */
663663
unsigned int nr_event_counters;
664+
665+
/* Number of debug breakpoints/watchpoints for this CPU (minus 1) */
666+
unsigned int debug_brps;
667+
unsigned int debug_wrps;
664668
};
665669

666670
struct kvm_host_psci_config {

arch/arm64/kvm/debug.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ void kvm_init_host_debug_data(void)
7171
*host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
7272
read_sysreg(pmcr_el0));
7373

74+
*host_data_ptr(debug_brps) = SYS_FIELD_GET(ID_AA64DFR0_EL1, BRPs, dfr0);
75+
*host_data_ptr(debug_wrps) = SYS_FIELD_GET(ID_AA64DFR0_EL1, WRPs, dfr0);
76+
7477
if (has_vhe())
7578
return;
7679

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,8 @@ static struct kvm_guest_debug_arch *__vcpu_debug_regs(struct kvm_vcpu *vcpu)
106106
static void __debug_save_state(struct kvm_guest_debug_arch *dbg,
107107
struct kvm_cpu_context *ctxt)
108108
{
109-
u64 aa64dfr0;
110-
int brps, wrps;
111-
112-
aa64dfr0 = read_sysreg(id_aa64dfr0_el1);
113-
brps = (aa64dfr0 >> 12) & 0xf;
114-
wrps = (aa64dfr0 >> 20) & 0xf;
109+
int brps = *host_data_ptr(debug_brps);
110+
int wrps = *host_data_ptr(debug_wrps);
115111

116112
save_debug(dbg->dbg_bcr, dbgbcr, brps);
117113
save_debug(dbg->dbg_bvr, dbgbvr, brps);
@@ -124,13 +120,8 @@ static void __debug_save_state(struct kvm_guest_debug_arch *dbg,
124120
static void __debug_restore_state(struct kvm_guest_debug_arch *dbg,
125121
struct kvm_cpu_context *ctxt)
126122
{
127-
u64 aa64dfr0;
128-
int brps, wrps;
129-
130-
aa64dfr0 = read_sysreg(id_aa64dfr0_el1);
131-
132-
brps = (aa64dfr0 >> 12) & 0xf;
133-
wrps = (aa64dfr0 >> 20) & 0xf;
123+
int brps = *host_data_ptr(debug_brps);
124+
int wrps = *host_data_ptr(debug_wrps);
134125

135126
restore_debug(dbg->dbg_bcr, dbgbcr, brps);
136127
restore_debug(dbg->dbg_bvr, dbgbvr, brps);

0 commit comments

Comments
 (0)