Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
- sound/pci/hda/patch_realtek.c | 1 +
+ sound/pci/hda/patch_realtek.c | 1 +
1 file changed, 1 insertion(+)
-diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
-index 1efaeb09ec3f..afc20f73b42d 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
-@@ -7436,6 +7436,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
+@@ -7436,6 +7436,7 @@ static const struct snd_pci_quirk alc269
SND_PCI_QUIRK(0x1043, 0x18b1, "Asus MJ401TA", ALC256_FIXUP_ASUS_HEADSET_MIC),
SND_PCI_QUIRK(0x1043, 0x18f1, "Asus FX505DT", ALC256_FIXUP_ASUS_HEADSET_MIC),
SND_PCI_QUIRK(0x1043, 0x19ce, "ASUS B9450FA", ALC294_FIXUP_ASUS_HPE),
SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
SND_PCI_QUIRK(0x1043, 0x1a30, "ASUS X705UD", ALC256_FIXUP_ASUS_MIC),
SND_PCI_QUIRK(0x1043, 0x1b11, "ASUS UX431DA", ALC294_FIXUP_ASUS_COEF_1B),
---
-2.25.1
-
--- /dev/null
+From 37486135d3a7b03acc7755b63627a130437f066a Mon Sep 17 00:00:00 2001
+From: Babu Moger <babu.moger@amd.com>
+Date: Tue, 12 May 2020 18:59:06 -0500
+Subject: KVM: x86: Fix pkru save/restore when guest CR4.PKE=0, move it to x86.c
+
+From: Babu Moger <babu.moger@amd.com>
+
+commit 37486135d3a7b03acc7755b63627a130437f066a upstream.
+
+Though rdpkru and wrpkru are contingent upon CR4.PKE, the PKRU
+resource isn't. It can be read with XSAVE and written with XRSTOR.
+So, if we don't set the guest PKRU value here(kvm_load_guest_xsave_state),
+the guest can read the host value.
+
+In case of kvm_load_host_xsave_state, guest with CR4.PKE clear could
+potentially use XRSTOR to change the host PKRU value.
+
+While at it, move pkru state save/restore to common code and the
+host_pkru field to kvm_vcpu_arch. This will let SVM support protection keys.
+
+Cc: stable@vger.kernel.org
+Reported-by: Jim Mattson <jmattson@google.com>
+Signed-off-by: Babu Moger <babu.moger@amd.com>
+Message-Id: <158932794619.44260.14508381096663848853.stgit@naples-babu.amd.com>
+Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ arch/x86/include/asm/kvm_host.h | 1 +
+ arch/x86/kvm/vmx/vmx.c | 18 ------------------
+ arch/x86/kvm/x86.c | 17 +++++++++++++++++
+ 3 files changed, 18 insertions(+), 18 deletions(-)
+
+--- a/arch/x86/include/asm/kvm_host.h
++++ b/arch/x86/include/asm/kvm_host.h
+@@ -550,6 +550,7 @@ struct kvm_vcpu_arch {
+ unsigned long cr4;
+ unsigned long cr4_guest_owned_bits;
+ unsigned long cr8;
++ u32 host_pkru;
+ u32 pkru;
+ u32 hflags;
+ u64 efer;
+--- a/arch/x86/kvm/vmx/vmx.c
++++ b/arch/x86/kvm/vmx/vmx.c
+@@ -1360,7 +1360,6 @@ void vmx_vcpu_load(struct kvm_vcpu *vcpu
+
+ vmx_vcpu_pi_load(vcpu, cpu);
+
+- vmx->host_pkru = read_pkru();
+ vmx->host_debugctlmsr = get_debugctlmsr();
+ }
+
+@@ -6521,11 +6520,6 @@ static void vmx_vcpu_run(struct kvm_vcpu
+
+ kvm_load_guest_xcr0(vcpu);
+
+- if (static_cpu_has(X86_FEATURE_PKU) &&
+- kvm_read_cr4_bits(vcpu, X86_CR4_PKE) &&
+- vcpu->arch.pkru != vmx->host_pkru)
+- __write_pkru(vcpu->arch.pkru);
+-
+ pt_guest_enter(vmx);
+
+ atomic_switch_perf_msrs(vmx);
+@@ -6614,18 +6608,6 @@ static void vmx_vcpu_run(struct kvm_vcpu
+
+ pt_guest_exit(vmx);
+
+- /*
+- * eager fpu is enabled if PKEY is supported and CR4 is switched
+- * back on host, so it is safe to read guest PKRU from current
+- * XSAVE.
+- */
+- if (static_cpu_has(X86_FEATURE_PKU) &&
+- kvm_read_cr4_bits(vcpu, X86_CR4_PKE)) {
+- vcpu->arch.pkru = rdpkru();
+- if (vcpu->arch.pkru != vmx->host_pkru)
+- __write_pkru(vmx->host_pkru);
+- }
+-
+ kvm_put_guest_xcr0(vcpu);
+
+ vmx->nested.nested_run_pending = 0;
+--- a/arch/x86/kvm/x86.c
++++ b/arch/x86/kvm/x86.c
+@@ -832,11 +832,25 @@ void kvm_load_guest_xcr0(struct kvm_vcpu
+ xsetbv(XCR_XFEATURE_ENABLED_MASK, vcpu->arch.xcr0);
+ vcpu->guest_xcr0_loaded = 1;
+ }
++
++ if (static_cpu_has(X86_FEATURE_PKU) &&
++ (kvm_read_cr4_bits(vcpu, X86_CR4_PKE) ||
++ (vcpu->arch.xcr0 & XFEATURE_MASK_PKRU)) &&
++ vcpu->arch.pkru != vcpu->arch.host_pkru)
++ __write_pkru(vcpu->arch.pkru);
+ }
+ EXPORT_SYMBOL_GPL(kvm_load_guest_xcr0);
+
+ void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu)
+ {
++ if (static_cpu_has(X86_FEATURE_PKU) &&
++ (kvm_read_cr4_bits(vcpu, X86_CR4_PKE) ||
++ (vcpu->arch.xcr0 & XFEATURE_MASK_PKRU))) {
++ vcpu->arch.pkru = rdpkru();
++ if (vcpu->arch.pkru != vcpu->arch.host_pkru)
++ __write_pkru(vcpu->arch.host_pkru);
++ }
++
+ if (vcpu->guest_xcr0_loaded) {
+ if (vcpu->arch.xcr0 != host_xcr0)
+ xsetbv(XCR_XFEATURE_ENABLED_MASK, host_xcr0);
+@@ -8222,6 +8236,9 @@ static int vcpu_enter_guest(struct kvm_v
+ 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();