All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maciej S. Szmigiero" <mail@maciej.szmigiero.name>
To: Paolo Bonzini <pbonzini@redhat.com>,
	Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
	Maxim Levitsky <mlevitsk@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v3 04/12] KVM: SVM: Stuff next_rip on emulated INT3 injection if NRIPS is supported
Date: Mon,  2 May 2022 00:07:28 +0200	[thread overview]
Message-ID: <cd328309a3b88604daa2359ad56f36cb565ce2d4.1651440202.git.maciej.szmigiero@oracle.com> (raw)
In-Reply-To: <cover.1651440202.git.maciej.szmigiero@oracle.com>

From: Sean Christopherson <seanjc@google.com>

If NRIPS is supported in hardware but disabled in KVM, set next_rip to
the next RIP when advancing RIP as part of emulating INT3 injection.
There is no flag to tell the CPU that KVM isn't using next_rip, and so
leaving next_rip is left as is will result in the CPU pushing garbage
onto the stack when vectoring the injected event.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
Fixes: 66b7138f9136 ("KVM: SVM: Emulate nRIP feature when reinjecting INT3")
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com>
---
 arch/x86/kvm/svm/svm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 1a719f47a964..a05a4e521400 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -392,6 +392,10 @@ static void svm_queue_exception(struct kvm_vcpu *vcpu)
 		 */
 		(void)svm_skip_emulated_instruction(vcpu);
 		rip = kvm_rip_read(vcpu);
+
+		if (boot_cpu_has(X86_FEATURE_NRIPS))
+			svm->vmcb->control.next_rip = rip;
+
 		svm->int3_rip = rip + svm->vmcb->save.cs.base;
 		svm->int3_injected = rip - old_rip;
 	}
@@ -3701,7 +3705,7 @@ static void svm_complete_interrupts(struct kvm_vcpu *vcpu)
 	/*
 	 * If NextRIP isn't enabled, KVM must manually advance RIP prior to
 	 * injecting the soft exception/interrupt.  That advancement needs to
-	 * be unwound if vectoring didn't complete.  Note, the _new_ event may
+	 * be unwound if vectoring didn't complete.  Note, the new event may
 	 * not be the injected event, e.g. if KVM injected an INTn, the INTn
 	 * hit a #NP in the guest, and the #NP encountered a #PF, the #NP will
 	 * be the reported vectored event, but RIP still needs to be unwound.

  parent reply	other threads:[~2022-05-01 22:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-01 22:07 [PATCH v3 00/12] KVM: SVM: Fix soft int/ex re-injection Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 01/12] KVM: nSVM: Sync next_rip field from vmcb12 to vmcb02 Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 02/12] KVM: SVM: Don't BUG if userspace injects an interrupt with GIF=0 Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 03/12] KVM: SVM: Unwind "speculative" RIP advancement if INTn injection "fails" Maciej S. Szmigiero
2022-05-01 22:07 ` Maciej S. Szmigiero [this message]
2022-05-01 22:07 ` [PATCH v3 05/12] KVM: SVM: Re-inject INT3/INTO instead of retrying the instruction Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 06/12] KVM: SVM: Re-inject INTn instead of retrying the insn on "failure" Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 07/12] KVM: x86: Trace re-injected exceptions Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 08/12] KVM: x86: Print error code in exception injection tracepoint iff valid Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 09/12] KVM: x86: Differentiate Soft vs. Hard IRQs vs. reinjected in tracepoint Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 10/12] KVM: nSVM: Transparently handle L1 -> L2 NMI re-injection Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 11/12] KVM: selftests: nSVM: Add svm_nested_soft_inject_test Maciej S. Szmigiero
2022-05-01 22:07 ` [PATCH v3 12/12] KVM: nSVM: Drop support for CPUs without NRIPS (NextRIP Save) support Maciej S. Szmigiero
2022-05-03 18:48 ` [PATCH v3 00/12] KVM: SVM: Fix soft int/ex re-injection Sean Christopherson
2022-05-04 12:40   ` Maxim Levitsky
2022-05-17 12:28 ` Maciej S. Szmigiero
2022-05-17 16:46   ` Paolo Bonzini
2022-05-17 21:17     ` Maciej S. Szmigiero

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd328309a3b88604daa2359ad56f36cb565ce2d4.1651440202.git.maciej.szmigiero@oracle.com \
    --to=mail@maciej.szmigiero.name \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlevitsk@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.