]> www.infradead.org Git - users/hch/misc.git/commitdiff
KVM: arm64: Avoid reading ID_AA64DFR0_EL1 for debug save/restore
authorOliver Upton <oliver.upton@linux.dev>
Thu, 19 Dec 2024 22:41:14 +0000 (14:41 -0800)
committerMarc Zyngier <maz@kernel.org>
Fri, 20 Dec 2024 09:04:14 +0000 (09:04 +0000)
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 <james.clark@linaro.org>
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20241219224116.3941496-18-oliver.upton@linux.dev
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/debug.c
arch/arm64/kvm/hyp/include/hyp/debug-sr.h

index d48516de778dd7bf828aedd1c762d4be9dd7256a..e7c740c99ee399bc8ea77325db96bba4dcfee81f 100644 (file)
@@ -661,6 +661,10 @@ struct kvm_host_data {
 
        /* Number of programmable event counters (PMCR_EL0.N) for this CPU */
        unsigned int nr_event_counters;
+
+       /* Number of debug breakpoints/watchpoints for this CPU (minus 1) */
+       unsigned int debug_brps;
+       unsigned int debug_wrps;
 };
 
 struct kvm_host_psci_config {
index 7d3c71d65518779807e2e2fd14559c6f422537ce..d921e7f7bd59c66be357f765def1801d17a780ee 100644 (file)
@@ -71,6 +71,9 @@ void kvm_init_host_debug_data(void)
                *host_data_ptr(nr_event_counters) = FIELD_GET(ARMV8_PMU_PMCR_N,
                                                              read_sysreg(pmcr_el0));
 
+       *host_data_ptr(debug_brps) = SYS_FIELD_GET(ID_AA64DFR0_EL1, BRPs, dfr0);
+       *host_data_ptr(debug_wrps) = SYS_FIELD_GET(ID_AA64DFR0_EL1, WRPs, dfr0);
+
        if (has_vhe())
                return;
 
index c14586d8736144407f6c46f8504009dce94ee134..502a5b73ee70c21f59bf00d19ab8450d2b14943c 100644 (file)
@@ -106,12 +106,8 @@ static struct kvm_guest_debug_arch *__vcpu_debug_regs(struct kvm_vcpu *vcpu)
 static void __debug_save_state(struct kvm_guest_debug_arch *dbg,
                               struct kvm_cpu_context *ctxt)
 {
-       u64 aa64dfr0;
-       int brps, wrps;
-
-       aa64dfr0 = read_sysreg(id_aa64dfr0_el1);
-       brps = (aa64dfr0 >> 12) & 0xf;
-       wrps = (aa64dfr0 >> 20) & 0xf;
+       int brps = *host_data_ptr(debug_brps);
+       int wrps = *host_data_ptr(debug_wrps);
 
        save_debug(dbg->dbg_bcr, dbgbcr, brps);
        save_debug(dbg->dbg_bvr, dbgbvr, brps);
@@ -124,13 +120,8 @@ static void __debug_save_state(struct kvm_guest_debug_arch *dbg,
 static void __debug_restore_state(struct kvm_guest_debug_arch *dbg,
                                  struct kvm_cpu_context *ctxt)
 {
-       u64 aa64dfr0;
-       int brps, wrps;
-
-       aa64dfr0 = read_sysreg(id_aa64dfr0_el1);
-
-       brps = (aa64dfr0 >> 12) & 0xf;
-       wrps = (aa64dfr0 >> 20) & 0xf;
+       int brps = *host_data_ptr(debug_brps);
+       int wrps = *host_data_ptr(debug_wrps);
 
        restore_debug(dbg->dbg_bcr, dbgbcr, brps);
        restore_debug(dbg->dbg_bvr, dbgbvr, brps);