From f2660577c8b84bdce385489d31cbae5ab8956e84 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Mon, 19 Jul 2021 14:14:30 +0200 Subject: [PATCH] 4.4-stable patches added patches: kvm-x86-disable-hardware-breakpoints-unconditionally-before-kvm_x86-run.patch kvm-x86-use-guest-maxphyaddr-from-cpuid.0x8000_0008-iff-tdp-is-enabled.patch --- ...s-unconditionally-before-kvm_x86-run.patch | 49 +++++++++++++++++++ ...cpuid.0x8000_0008-iff-tdp-is-enabled.patch | 44 +++++++++++++++++ queue-4.4/series | 2 + 3 files changed, 95 insertions(+) create mode 100644 queue-4.4/kvm-x86-disable-hardware-breakpoints-unconditionally-before-kvm_x86-run.patch create mode 100644 queue-4.4/kvm-x86-use-guest-maxphyaddr-from-cpuid.0x8000_0008-iff-tdp-is-enabled.patch diff --git a/queue-4.4/kvm-x86-disable-hardware-breakpoints-unconditionally-before-kvm_x86-run.patch b/queue-4.4/kvm-x86-disable-hardware-breakpoints-unconditionally-before-kvm_x86-run.patch new file mode 100644 index 00000000000..00f10a8e9bf --- /dev/null +++ b/queue-4.4/kvm-x86-disable-hardware-breakpoints-unconditionally-before-kvm_x86-run.patch @@ -0,0 +1,49 @@ +From f85d40160691881a17a397c448d799dfc90987ba Mon Sep 17 00:00:00 2001 +From: Lai Jiangshan +Date: Tue, 29 Jun 2021 01:26:32 +0800 +Subject: KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() + +From: Lai Jiangshan + +commit f85d40160691881a17a397c448d799dfc90987ba upstream. + +When the host is using debug registers but the guest is not using them +nor is the guest in guest-debug state, the kvm code does not reset +the host debug registers before kvm_x86->run(). Rather, it relies on +the hardware vmentry instruction to automatically reset the dr7 registers +which ensures that the host breakpoints do not affect the guest. + +This however violates the non-instrumentable nature around VM entry +and exit; for example, when a host breakpoint is set on vcpu->arch.cr2, + +Another issue is consistency. When the guest debug registers are active, +the host breakpoints are reset before kvm_x86->run(). But when the +guest debug registers are inactive, the host breakpoints are delayed to +be disabled. The host tracing tools may see different results depending +on what the guest is doing. + +To fix the problems, we clear %db7 unconditionally before kvm_x86->run() +if the host has set any breakpoints, no matter if the guest is using +them or not. + +Signed-off-by: Lai Jiangshan +Message-Id: <20210628172632.81029-1-jiangshanlai@gmail.com> +Cc: stable@vger.kernel.org +[Only clear %db7 instead of reloading all debug registers. - Paolo] +Signed-off-by: Paolo Bonzini +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kvm/x86.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/arch/x86/kvm/x86.c ++++ b/arch/x86/kvm/x86.c +@@ -6724,6 +6724,8 @@ static int vcpu_enter_guest(struct kvm_v + set_debugreg(vcpu->arch.eff_db[3], 3); + set_debugreg(vcpu->arch.dr6, 6); + vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD; ++ } else if (unlikely(hw_breakpoint_active())) { ++ set_debugreg(0, 7); + } + + kvm_x86_ops->run(vcpu); diff --git a/queue-4.4/kvm-x86-use-guest-maxphyaddr-from-cpuid.0x8000_0008-iff-tdp-is-enabled.patch b/queue-4.4/kvm-x86-use-guest-maxphyaddr-from-cpuid.0x8000_0008-iff-tdp-is-enabled.patch new file mode 100644 index 00000000000..fbca5706342 --- /dev/null +++ b/queue-4.4/kvm-x86-use-guest-maxphyaddr-from-cpuid.0x8000_0008-iff-tdp-is-enabled.patch @@ -0,0 +1,44 @@ +From 4bf48e3c0aafd32b960d341c4925b48f416f14a5 Mon Sep 17 00:00:00 2001 +From: Sean Christopherson +Date: Wed, 23 Jun 2021 16:05:46 -0700 +Subject: KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled + +From: Sean Christopherson + +commit 4bf48e3c0aafd32b960d341c4925b48f416f14a5 upstream. + +Ignore the guest MAXPHYADDR reported by CPUID.0x8000_0008 if TDP, i.e. +NPT, is disabled, and instead use the host's MAXPHYADDR. Per AMD'S APM: + + Maximum guest physical address size in bits. This number applies only + to guests using nested paging. When this field is zero, refer to the + PhysAddrSize field for the maximum guest physical address size. + +Fixes: 24c82e576b78 ("KVM: Sanitize cpuid") +Cc: stable@vger.kernel.org +Signed-off-by: Sean Christopherson +Message-Id: <20210623230552.4027702-2-seanjc@google.com> +Signed-off-by: Paolo Bonzini +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kvm/cpuid.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +--- a/arch/x86/kvm/cpuid.c ++++ b/arch/x86/kvm/cpuid.c +@@ -611,8 +611,14 @@ static inline int __do_cpuid_ent(struct + unsigned virt_as = max((entry->eax >> 8) & 0xff, 48U); + unsigned phys_as = entry->eax & 0xff; + +- if (!g_phys_as) ++ /* ++ * Use bare metal's MAXPHADDR if the CPU doesn't report guest ++ * MAXPHYADDR separately, or if TDP (NPT) is disabled, as the ++ * guest version "applies only to guests using nested paging". ++ */ ++ if (!g_phys_as || !tdp_enabled) + g_phys_as = phys_as; ++ + entry->eax = g_phys_as | (virt_as << 8); + entry->edx = 0; + /* diff --git a/queue-4.4/series b/queue-4.4/series index 42d9aa23505..10ed8337a82 100644 --- a/queue-4.4/series +++ b/queue-4.4/series @@ -138,3 +138,5 @@ media-gspca-sq905-fix-control-request-direction.patch media-gspca-sunplus-fix-zero-length-control-requests.patch media-uvcvideo-fix-pixel-format-change-for-elgato-cam-link-4k.patch jfs-fix-gpf-in-difree.patch +kvm-x86-use-guest-maxphyaddr-from-cpuid.0x8000_0008-iff-tdp-is-enabled.patch +kvm-x86-disable-hardware-breakpoints-unconditionally-before-kvm_x86-run.patch -- 2.47.3