Skip to content

Commit 6db5573

Browse files
author
Marc Zyngier
committed
KVM: arm64: Exclude host_debug_data from vcpu_arch
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>
1 parent 87f842c commit 6db5573

3 files changed

Lines changed: 23 additions & 20 deletions

File tree

arch/arm64/include/asm/kvm_host.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,19 @@ struct kvm_cpu_context {
543543
*/
544544
struct kvm_host_data {
545545
struct kvm_cpu_context host_ctxt;
546+
547+
/*
548+
* host_debug_state contains the host registers which are
549+
* saved and restored during world switches.
550+
*/
551+
struct {
552+
/* {Break,watch}point registers */
553+
struct kvm_guest_debug_arch regs;
554+
/* Statistical profiling extension */
555+
u64 pmscr_el1;
556+
/* Self-hosted trace */
557+
u64 trfcr_el1;
558+
} host_debug_state;
546559
};
547560

548561
struct kvm_host_psci_config {
@@ -638,11 +651,10 @@ struct kvm_vcpu_arch {
638651
* We maintain more than a single set of debug registers to support
639652
* debugging the guest from the host and to maintain separate host and
640653
* guest state during world switches. vcpu_debug_state are the debug
641-
* registers of the vcpu as the guest sees them. host_debug_state are
642-
* the host registers which are saved and restored during
643-
* world switches. external_debug_state contains the debug
644-
* values we want to debug the guest. This is set via the
645-
* KVM_SET_GUEST_DEBUG ioctl.
654+
* registers of the vcpu as the guest sees them.
655+
*
656+
* external_debug_state contains the debug values we want to debug the
657+
* guest. This is set via the KVM_SET_GUEST_DEBUG ioctl.
646658
*
647659
* debug_ptr points to the set of debug registers that should be loaded
648660
* onto the hardware when running the guest.
@@ -654,15 +666,6 @@ struct kvm_vcpu_arch {
654666
struct user_fpsimd_state *host_fpsimd_state; /* hyp VA */
655667
struct task_struct *parent_task;
656668

657-
struct {
658-
/* {Break,watch}point registers */
659-
struct kvm_guest_debug_arch regs;
660-
/* Statistical profiling extension */
661-
u64 pmscr_el1;
662-
/* Self-hosted trace */
663-
u64 trfcr_el1;
664-
} host_debug_state;
665-
666669
/* VGIC state */
667670
struct vgic_cpu vgic_cpu;
668671
struct arch_timer_cpu timer_cpu;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static inline void __debug_switch_to_guest_common(struct kvm_vcpu *vcpu)
137137

138138
host_ctxt = host_data_ptr(host_ctxt);
139139
guest_ctxt = &vcpu->arch.ctxt;
140-
host_dbg = &vcpu->arch.host_debug_state.regs;
140+
host_dbg = host_data_ptr(host_debug_state.regs);
141141
guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
142142

143143
__debug_save_state(host_dbg, host_ctxt);
@@ -156,7 +156,7 @@ static inline void __debug_switch_to_host_common(struct kvm_vcpu *vcpu)
156156

157157
host_ctxt = host_data_ptr(host_ctxt);
158158
guest_ctxt = &vcpu->arch.ctxt;
159-
host_dbg = &vcpu->arch.host_debug_state.regs;
159+
host_dbg = host_data_ptr(host_debug_state.regs);
160160
guest_dbg = kern_hyp_va(vcpu->arch.debug_ptr);
161161

162162
__debug_save_state(guest_dbg, guest_ctxt);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ void __debug_save_host_buffers_nvhe(struct kvm_vcpu *vcpu)
8383
{
8484
/* Disable and flush SPE data generation */
8585
if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_SPE))
86-
__debug_save_spe(&vcpu->arch.host_debug_state.pmscr_el1);
86+
__debug_save_spe(host_data_ptr(host_debug_state.pmscr_el1));
8787
/* Disable and flush Self-Hosted Trace generation */
8888
if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_TRBE))
89-
__debug_save_trace(&vcpu->arch.host_debug_state.trfcr_el1);
89+
__debug_save_trace(host_data_ptr(host_debug_state.trfcr_el1));
9090
}
9191

9292
void __debug_switch_to_guest(struct kvm_vcpu *vcpu)
@@ -97,9 +97,9 @@ void __debug_switch_to_guest(struct kvm_vcpu *vcpu)
9797
void __debug_restore_host_buffers_nvhe(struct kvm_vcpu *vcpu)
9898
{
9999
if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_SPE))
100-
__debug_restore_spe(vcpu->arch.host_debug_state.pmscr_el1);
100+
__debug_restore_spe(*host_data_ptr(host_debug_state.pmscr_el1));
101101
if (vcpu_get_flag(vcpu, DEBUG_STATE_SAVE_TRBE))
102-
__debug_restore_trace(vcpu->arch.host_debug_state.trfcr_el1);
102+
__debug_restore_trace(*host_data_ptr(host_debug_state.trfcr_el1));
103103
}
104104

105105
void __debug_switch_to_host(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)