[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20210506170241.72133-1-jon@nutanix.com>
Date: Thu, 6 May 2021 13:02:41 -0400
From: Jon Kohler <jon@...anix.com>
To: unlisted-recipients:; (no To-header on input)
Cc: Jon Kohler <jon@...anix.com>, stable@...r.kernel.org,
Babu Moger <babu.moger@....com>,
Paolo Bonzini <pbonzini@...hat.com>,
Radim Krčmář <rkrcmar@...hat.com>,
Sean Christopherson <sean.j.christopherson@...el.com>,
Vitaly Kuznetsov <vkuznets@...hat.com>,
Wanpeng Li <wanpengli@...cent.com>,
Jim Mattson <jmattson@...gle.com>,
Joerg Roedel <joro@...tes.org>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"H. Peter Anvin" <hpa@...or.com>, x86@...nel.org,
kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] KVM: x86: move saving of arch.host_pkru to kvm_arch_vcpu_load in 5.4.y
commit 37486135d3a7b03acc7755b63627a130437f066a upstream.
In 5.4.y only, vcpu->arch.host_pkru is being set on every run thru
of vcpu_enter_guest, when it really only needs to be set on load. As
a result, we're doing a rdpkru on supported CPUs on every iteration
of vcpu_enter_guest even though the value never changes.
Mainline and 5.10.y already has host_pkru being initialized in
kvm_arch_vcpu_load. This change is 5.4.y specific and moves
host_pkru save to kvm_arch_vcpu_load.
Fixes: 99e392a4979b ("KVM: x86: Fix pkru save/restore when guest CR4.PKE=0, move it to x86.c")
Cc: stable@...r.kernel.org # 5.4.y
Cc: Babu Moger <babu.moger@....com>
Signed-off-by: Jon Kohler <jon@...anix.com>
---
arch/x86/kvm/x86.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 153659e8f403..1f7521752a94 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3507,6 +3507,9 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
kvm_x86_ops->vcpu_load(vcpu, cpu);
+ /* Save host pkru register if supported */
+ vcpu->arch.host_pkru = read_pkru();
+
/* Apply any externally detected TSC adjustments (due to suspend) */
if (unlikely(vcpu->arch.tsc_offset_adjustment)) {
adjust_tsc_offset_host(vcpu, vcpu->arch.tsc_offset_adjustment);
@@ -8253,9 +8256,6 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
trace_kvm_entry(vcpu->vcpu_id);
guest_enter_irqoff();
- /* Save host pkru register if supported */
- vcpu->arch.host_pkru = read_pkru();
-
fpregs_assert_state_consistent();
if (test_thread_flag(TIF_NEED_FPU_LOAD))
switch_fpu_return();
--
2.30.1 (Apple Git-130)
Powered by blists - more mailing lists