]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Exclude host_debug_data from vcpu_arch
authorMarc Zyngier <maz@kernel.org>
Mon, 26 Feb 2024 15:58:46 +0000 (15:58 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 12 Apr 2024 12:57:41 +0000 (13:57 +0100)
Keeping host_debug_state on a per-vcpu basis is completely
pointless. The lifetime of this data is only that of the inner
run-loop, which means it is never accessed outside of the core
EL2 code.

Move the structure into kvm_host_data, and save over 500 bytes
per vcpu.

Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/hyp/include/hyp/debug-sr.h
arch/arm64/kvm/hyp/nvhe/debug-sr.c

index f41db42529df02120ac3d8729917b14319724424..d7bcb8ce1d7b765561b0d17f214c45d624b4bbfb 100644 (file)
@@ -543,6 +543,19 @@ struct kvm_cpu_context {
  */
 struct kvm_host_data {
        struct kvm_cpu_context host_ctxt;
+
+       /*
+        * host_debug_state contains the host registers which are
+        * saved and restored during world switches.
+        */
+        struct {
+               /* {Break,watch}point registers */
+               struct kvm_guest_debug_arch regs;
+               /* Statistical profiling extension */
+               u64 pmscr_el1;
+               /* Self-hosted trace */
+               u64 trfcr_el1;
+       } host_debug_state;
 };
 
 struct kvm_host_psci_config {
@@ -638,11 +651,10 @@ struct kvm_vcpu_arch {
         * We maintain more than a single set of debug registers to support
         * debugging the guest from the host and to maintain separate host and
         * guest state during world switches. vcpu_debug_state are the debug
-        * registers of the vcpu as the guest sees them.  host_debug_state are
-        * the host registers which are saved and restored during
-        * world switches. external_debug_state contains the debug
-        * values we want to debug the guest. This is set via the
-        * KVM_SET_GUEST_DEBUG ioctl.
+        * registers of the vcpu as the guest sees them.
+        *
+        * external_debug_state contains the debug values we want to debug the
+        * guest. This is set via the KVM_SET_GUEST_DEBUG ioctl.
         *
         * debug_ptr points to the set of debug registers that should be loaded
         * onto the hardware when running the guest.
@@ -654,15 +666,6 @@ struct kvm_vcpu_arch {
        struct user_fpsimd_state *host_fpsimd_state;    /* hyp VA */
        struct task_struct *parent_task;
 
-       struct {
-               /* {Break,watch}point registers */
-               struct kvm_guest_debug_arch regs;
-               /* Statistical profiling extension */
-               u64 pmscr_el1;
-               /* Self-hosted trace */
-               u64 trfcr_el1;
-       } host_debug_state;
-
        /* VGIC state */
        struct vgic_cpu vgic_cpu;
        struct arch_timer_cpu timer_cpu;
index eec0f8ccda562095a1ab6822fc59185d506cc062..d00093699aaf1fb8c886b14687867e49f85b0da3 100644 (file)
@@ -137,7 +137,7 @@ static inline void __debug_switch_to_guest_common(struct kvm_vcpu *vcpu)
 
        host_ctxt = host_data_ptr(host_ctxt);
        guest_ctxt = &vcpu->arch.ctxt;
-       host_dbg = &vcpu->arch.host_debug_state.regs;
+       host_dbg = host_data_ptr(host_debug_state.regs);
        guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
 
        __debug_save_state(host_dbg, host_ctxt);
@@ -156,7 +156,7 @@ static inline void __debug_switch_to_host_common(struct kvm_vcpu *vcpu)
 
        host_ctxt = host_data_ptr(host_ctxt);
        guest_ctxt = &vcpu->arch.ctxt;
-       host_dbg = &vcpu->arch.host_debug_state.regs;
+       host_dbg = host_data_ptr(host_debug_state.regs);
        guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
 
        __debug_save_state(guest_dbg, guest_ctxt);
index 7746ea507b6f00ea0214310a5f52c840e3435b11..53efda0235cfe00709ccc89ba9591bb17d672225 100644 (file)
@@ -83,10 +83,10 @@ void __debug_save_host_buffers_nvhe(struct kvm_vcpu *vcpu)
 {
        /* Disable and flush SPE data generation */
        if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_SPE))
-               __debug_save_spe(&vcpu->arch.host_debug_state.pmscr_el1);
+               __debug_save_spe(host_data_ptr(host_debug_state.pmscr_el1));
        /* Disable and flush Self-Hosted Trace generation */
        if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_TRBE))
-               __debug_save_trace(&vcpu->arch.host_debug_state.trfcr_el1);
+               __debug_save_trace(host_data_ptr(host_debug_state.trfcr_el1));
 }
 
 void __debug_switch_to_guest(struct kvm_vcpu *vcpu)
@@ -97,9 +97,9 @@ void __debug_switch_to_guest(struct kvm_vcpu *vcpu)
 void __debug_restore_host_buffers_nvhe(struct kvm_vcpu *vcpu)
 {
        if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_SPE))
-               __debug_restore_spe(vcpu->arch.host_debug_state.pmscr_el1);
+               __debug_restore_spe(*host_data_ptr(host_debug_state.pmscr_el1));
        if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_TRBE))
-               __debug_restore_trace(vcpu->arch.host_debug_state.trfcr_el1);
+               __debug_restore_trace(*host_data_ptr(host_debug_state.trfcr_el1));
 }
 
 void __debug_switch_to_host(struct kvm_vcpu *vcpu)