public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] KVM: x86: Clear "has_error_code", not "error_code", for RM" failed to apply to 5.10-stable tree
@ 2023-04-11 11:00 gregkh
  2024-05-10 13:12 ` [PATCH 5.10.y] KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection Nicolas Saenz Julienne
  0 siblings, 1 reply; 4+ messages in thread
From: gregkh @ 2023-04-11 11:00 UTC (permalink / raw)
  To: seanjc, mlevitsk, pbonzini; +Cc: stable


The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

To reproduce the conflict and resubmit, you may use the following commands:

git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y
git checkout FETCH_HEAD
git cherry-pick -x 6c41468c7c12d74843bb414fc00307ea8a6318c3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<stable@vger.kernel.org>' --in-reply-to '2023041135-yippee-shabby-b9ad@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^..

Possible dependencies:

6c41468c7c12 ("KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection")
d4963e319f1f ("KVM: x86: Make kvm_queued_exception a properly named, visible struct")
6ad75c5c99f7 ("KVM: x86: Rename kvm_x86_ops.queue_exception to inject_exception")
5623f751bd9c ("KVM: x86: Treat #DBs from the emulator as fault-like (code and DR7.GD=1)")
8d178f460772 ("KVM: nVMX: Treat General Detect #DB (DR7.GD=1) as fault-like")
eba9799b5a6e ("KVM: VMX: Drop bits 31:16 when shoving exception error code into VMCS")
a61d7c5432ac ("KVM: x86: Trace re-injected exceptions")
6ef88d6e36c2 ("KVM: SVM: Re-inject INT3/INTO instead of retrying the instruction")
3741aec4c38f ("KVM: SVM: Stuff next_rip on emulated INT3 injection if NRIPS is supported")
cd9e6da8048c ("KVM: SVM: Unwind "speculative" RIP advancement if INTn injection "fails"")
00f08d99dd7d ("KVM: nSVM: Sync next_rip field from vmcb12 to vmcb02")
9bd1f0efa859 ("KVM: nVMX: Clear IDT vectoring on nested VM-Exit for double/triple fault")
c3634d25fbee ("KVM: nVMX: Leave most VM-Exit info fields unmodified on failed VM-Entry")
1d5a1b5860ed ("KVM: x86: nSVM: correctly virtualize LBR msrs when L2 is running")
db663af4a001 ("kvm: x86: SVM: use vmcb* instead of svm->vmcb where it makes sense")
b9f3973ab3a8 ("KVM: x86: nSVM: implement nested VMLOAD/VMSAVE")
23e5092b6e2a ("KVM: SVM: Rename hook implementations to conform to kvm_x86_ops' names")
e27bc0440ebd ("KVM: x86: Rename kvm_x86_ops pointers to align w/ preferred vendor names")
068f7ea61895 ("KVM: SVM: improve split between svm_prepare_guest_switch and sev_es_prepare_guest_switch")
e1779c2714c3 ("KVM: x86: nSVM: fix potential NULL derefernce on nested migration")

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 6c41468c7c12d74843bb414fc00307ea8a6318c3 Mon Sep 17 00:00:00 2001
From: Sean Christopherson <seanjc@google.com>
Date: Wed, 22 Mar 2023 07:32:59 -0700
Subject: [PATCH] KVM: x86: Clear "has_error_code", not "error_code", for RM
 exception injection

When injecting an exception into a vCPU in Real Mode, suppress the error
code by clearing the flag that tracks whether the error code is valid, not
by clearing the error code itself.  The "typo" was introduced by recent
fix for SVM's funky Paged Real Mode.

Opportunistically hoist the logic above the tracepoint so that the trace
is coherent with respect to what is actually injected (this was also the
behavior prior to the buggy commit).

Fixes: b97f07458373 ("KVM: x86: determine if an exception has an error code only when injecting it.")
Cc: stable@vger.kernel.org
Cc: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20230322143300.2209476-2-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 45017576ad5e..7d6f98b7635f 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -9908,13 +9908,20 @@ int kvm_check_nested_events(struct kvm_vcpu *vcpu)
 
 static void kvm_inject_exception(struct kvm_vcpu *vcpu)
 {
+	/*
+	 * Suppress the error code if the vCPU is in Real Mode, as Real Mode
+	 * exceptions don't report error codes.  The presence of an error code
+	 * is carried with the exception and only stripped when the exception
+	 * is injected as intercepted #PF VM-Exits for AMD's Paged Real Mode do
+	 * report an error code despite the CPU being in Real Mode.
+	 */
+	vcpu->arch.exception.has_error_code &= is_protmode(vcpu);
+
 	trace_kvm_inj_exception(vcpu->arch.exception.vector,
 				vcpu->arch.exception.has_error_code,
 				vcpu->arch.exception.error_code,
 				vcpu->arch.exception.injected);
 
-	if (vcpu->arch.exception.error_code && !is_protmode(vcpu))
-		vcpu->arch.exception.error_code = false;
 	static_call(kvm_x86_inject_exception)(vcpu);
 }
 


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 5.10.y] KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection
  2023-04-11 11:00 FAILED: patch "[PATCH] KVM: x86: Clear "has_error_code", not "error_code", for RM" failed to apply to 5.10-stable tree gregkh
@ 2024-05-10 13:12 ` Nicolas Saenz Julienne
  2024-05-10 15:42   ` Sean Christopherson
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2024-05-10 13:12 UTC (permalink / raw)
  To: stable
  Cc: Sean Christopherson, Maxim Levitsky, Paolo Bonzini,
	Nicolas Saenz Julienne

From: Sean Christopherson <seanjc@google.com>

When injecting an exception into a vCPU in Real Mode, suppress the error
code by clearing the flag that tracks whether the error code is valid, not
by clearing the error code itself.  The "typo" was introduced by recent
fix for SVM's funky Paged Real Mode.

Opportunistically hoist the logic above the tracepoint so that the trace
is coherent with respect to what is actually injected (this was also the
behavior prior to the buggy commit).

Fixes: b97f07458373 ("KVM: x86: determine if an exception has an error code only when injecting it.")
Cc: stable@vger.kernel.org
Cc: Maxim Levitsky <mlevitsk@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20230322143300.2209476-2-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
(cherry picked from commit 6c41468c7c12d74843bb414fc00307ea8a6318c3)
[nsaenz: backport to 5.10.y]
Signed-off-by: Nicolas Saenz Julienne <nsaenz@amazon.com>

Conflicts:
	arch/x86/kvm/x86.c: Patch offsets had to be corrected.
---
Testing: Kernel build and VM launch with KVM.
Unfortunately I don't have a repro for the issue this solves, but the
patch is straightforward, so I believe the testing above is good enough.

 arch/x86/kvm/x86.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 8e0b957c6219..bc295439360e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -8501,13 +8501,20 @@ static void update_cr8_intercept(struct kvm_vcpu *vcpu)
 
 static void kvm_inject_exception(struct kvm_vcpu *vcpu)
 {
+	/*
+	 * Suppress the error code if the vCPU is in Real Mode, as Real Mode
+	 * exceptions don't report error codes.  The presence of an error code
+	 * is carried with the exception and only stripped when the exception
+	 * is injected as intercepted #PF VM-Exits for AMD's Paged Real Mode do
+	 * report an error code despite the CPU being in Real Mode.
+	 */
+	vcpu->arch.exception.has_error_code &= is_protmode(vcpu);
+
 	trace_kvm_inj_exception(vcpu->arch.exception.nr,
 				vcpu->arch.exception.has_error_code,
 				vcpu->arch.exception.error_code,
 				vcpu->arch.exception.injected);
 
-	if (vcpu->arch.exception.error_code && !is_protmode(vcpu))
-		vcpu->arch.exception.error_code = false;
 	kvm_x86_ops.queue_exception(vcpu);
 }
 
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.10.y] KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection
  2024-05-10 13:12 ` [PATCH 5.10.y] KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection Nicolas Saenz Julienne
@ 2024-05-10 15:42   ` Sean Christopherson
  2024-05-23 11:54     ` Greg KH
  0 siblings, 1 reply; 4+ messages in thread
From: Sean Christopherson @ 2024-05-10 15:42 UTC (permalink / raw)
  To: Nicolas Saenz Julienne; +Cc: stable, Maxim Levitsky, Paolo Bonzini

On Fri, May 10, 2024, Nicolas Saenz Julienne wrote:
> From: Sean Christopherson <seanjc@google.com>
> 
> When injecting an exception into a vCPU in Real Mode, suppress the error
> code by clearing the flag that tracks whether the error code is valid, not
> by clearing the error code itself.  The "typo" was introduced by recent
> fix for SVM's funky Paged Real Mode.
> 
> Opportunistically hoist the logic above the tracepoint so that the trace
> is coherent with respect to what is actually injected (this was also the
> behavior prior to the buggy commit).
> 
> Fixes: b97f07458373 ("KVM: x86: determine if an exception has an error code only when injecting it.")
> Cc: stable@vger.kernel.org
> Cc: Maxim Levitsky <mlevitsk@redhat.com>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> Message-Id: <20230322143300.2209476-2-seanjc@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> (cherry picked from commit 6c41468c7c12d74843bb414fc00307ea8a6318c3)
> [nsaenz: backport to 5.10.y]
> Signed-off-by: Nicolas Saenz Julienne <nsaenz@amazon.com>
> 
> Conflicts:
> 	arch/x86/kvm/x86.c: Patch offsets had to be corrected.
> ---
> Testing: Kernel build and VM launch with KVM.
> Unfortunately I don't have a repro for the issue this solves, but the
> patch is straightforward, so I believe the testing above is good enough.

LOL, famous last words.

Acked-by: Sean Christopherson <seanjc@google.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 5.10.y] KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection
  2024-05-10 15:42   ` Sean Christopherson
@ 2024-05-23 11:54     ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2024-05-23 11:54 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Nicolas Saenz Julienne, stable, Maxim Levitsky, Paolo Bonzini

On Fri, May 10, 2024 at 08:42:52AM -0700, Sean Christopherson wrote:
> On Fri, May 10, 2024, Nicolas Saenz Julienne wrote:
> > From: Sean Christopherson <seanjc@google.com>
> > 
> > When injecting an exception into a vCPU in Real Mode, suppress the error
> > code by clearing the flag that tracks whether the error code is valid, not
> > by clearing the error code itself.  The "typo" was introduced by recent
> > fix for SVM's funky Paged Real Mode.
> > 
> > Opportunistically hoist the logic above the tracepoint so that the trace
> > is coherent with respect to what is actually injected (this was also the
> > behavior prior to the buggy commit).
> > 
> > Fixes: b97f07458373 ("KVM: x86: determine if an exception has an error code only when injecting it.")
> > Cc: stable@vger.kernel.org
> > Cc: Maxim Levitsky <mlevitsk@redhat.com>
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > Message-Id: <20230322143300.2209476-2-seanjc@google.com>
> > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > (cherry picked from commit 6c41468c7c12d74843bb414fc00307ea8a6318c3)
> > [nsaenz: backport to 5.10.y]
> > Signed-off-by: Nicolas Saenz Julienne <nsaenz@amazon.com>
> > 
> > Conflicts:
> > 	arch/x86/kvm/x86.c: Patch offsets had to be corrected.
> > ---
> > Testing: Kernel build and VM launch with KVM.
> > Unfortunately I don't have a repro for the issue this solves, but the
> > patch is straightforward, so I believe the testing above is good enough.
> 
> LOL, famous last words.
> 
> Acked-by: Sean Christopherson <seanjc@google.com>
> 

All now queued up, thanks.

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-23 11:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-11 11:00 FAILED: patch "[PATCH] KVM: x86: Clear "has_error_code", not "error_code", for RM" failed to apply to 5.10-stable tree gregkh
2024-05-10 13:12 ` [PATCH 5.10.y] KVM: x86: Clear "has_error_code", not "error_code", for RM exception injection Nicolas Saenz Julienne
2024-05-10 15:42   ` Sean Christopherson
2024-05-23 11:54     ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox