From: Santosh Shukla <santosh.shukla@amd.com>
To: <kvm@vger.kernel.org>, <seanjc@google.com>
Cc: <pbonzini@redhat.com>, <jmattson@google.com>, <joro@8bytes.org>,
<linux-kernel@vger.kernel.org>, <mail@maciej.szmigiero.name>,
<mlevitsk@redhat.com>, <thomas.lendacky@amd.com>,
<vkuznets@redhat.com>
Subject: [PATCHv4 03/11] KVM: nSVM: Raise event on nested VM exit if L1 doesn't intercept IRQs
Date: Mon, 27 Feb 2023 14:10:08 +0530 [thread overview]
Message-ID: <20230227084016.3368-4-santosh.shukla@amd.com> (raw)
In-Reply-To: <20230227084016.3368-1-santosh.shukla@amd.com>
From: Maxim Levitsky <mlevitsk@redhat.com>
If the L1 doesn't intercept interrupts, then the KVM will use vmcb02's
V_IRQ for L1 (to detect an interrupt window)
In this case on nested VM exit KVM might need to copy the V_IRQ bit
from the vmcb02 to the vmcb01, to continue waiting for the
interrupt window.
To make it simple, just raise the KVM_REQ_EVENT request, which
execution will lead to the reenabling of the interrupt
window if needed.
Note that this is a theoretical bug because KVM already does raise
KVM_REQ_EVENT request on each nested VM exit because the nested
VM exit resets RFLAGS and the kvm_set_rflags() raises the
KVM_REQ_EVENT request in the response.
However raising this request explicitly, together with
documenting why this is needed, is still preferred.
Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
[reworded description as per Sean's v2 comment]
Signed-off-by: Santosh Shukla <Santosh.Shukla@amd.com>
---
v3:
Reworded commit description per Sean's v2 comment:
https://lore.kernel.org/all/Y9RypRsfpLteK51v@google.com/
arch/x86/kvm/svm/nested.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 107258ed46ee..74e9e9e76d77 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1025,6 +1025,31 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
svm_switch_vmcb(svm, &svm->vmcb01);
+ /* Note about synchronizing some of int_ctl bits from vmcb02 to vmcb01:
+ *
+ * V_IRQ, V_IRQ_VECTOR, V_INTR_PRIO_MASK, V_IGN_TPR:
+ * If the L1 doesn't intercept interrupts, then
+ * (even if the L1 does use virtual interrupt masking),
+ * KVM will use the vmcb02's V_INTR to detect interrupt window.
+ *
+ * In this case, the KVM raises KVM_REQ_EVENT to ensure that interrupt
+ * window is not lost and KVM implicitly V_IRQ bit from vmcb02 to vmcb01
+ *
+ * V_TPR:
+ * If the L1 doesn't use virtual interrupt masking, then the L1's vTPR
+ * is stored in the vmcb02 but its value doesn't need to be copied
+ * from/to vmcb01 because it is copied from/to the TPR APIC's register
+ * on each VM entry/exit.
+ *
+ * V_GIF:
+ * If the nested vGIF is not used, KVM uses vmcb02's V_GIF for L1's
+ * V_GIF, however, the L1 vGIF is reset to false on each VM exit, thus
+ * there is no need to copy it from vmcb02 to vmcb01.
+ */
+
+ if (!nested_exit_on_intr(svm))
+ kvm_make_request(KVM_REQ_EVENT, &svm->vcpu);
+
if (unlikely(svm->lbrv_enabled && (svm->nested.ctl.virt_ext & LBR_CTL_ENABLE_MASK))) {
svm_copy_lbrs(vmcb12, vmcb02);
svm_update_lbrv(vcpu);
--
2.25.1
next prev parent reply other threads:[~2023-02-27 8:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-27 8:40 [PATCHv4 00/11] SVM: virtual NMI Santosh Shukla
2023-02-27 8:40 ` [PATCHv4 01/11] KVM: nSVM: Don't sync vmcb02 V_IRQ back to vmcb12 if KVM (L0) is intercepting VINTR Santosh Shukla
2023-02-27 8:40 ` [PATCHv4 02/11] KVM: nSVM: Disable intercept of VINTR if saved RFLAG.IF is 0 Santosh Shukla
2023-02-27 8:40 ` Santosh Shukla [this message]
2023-02-27 8:40 ` [PATCHv4 04/11] KVM: SVM: add wrappers to enable/disable IRET interception Santosh Shukla
2023-02-27 8:40 ` [PATCHv4 05/11] KVM: x86: Raise an event request when processing NMIs if an NMI is pending Santosh Shukla
2023-02-27 8:40 ` [PATCHv4 06/11] KVM: x86: Tweak the code and comment related to handling concurrent NMIs Santosh Shukla
2023-02-27 8:40 ` [PATCHv4 07/11] KVM: x86: Save/restore all NMIs when multiple NMIs are pending Santosh Shukla
2023-02-27 8:40 ` [PATCHv4 08/11] x86/cpu: Add CPUID feature bit for VNMI Santosh Shukla
2023-03-22 19:07 ` Sean Christopherson
2023-02-27 8:40 ` [PATCHv4 09/11] KVM: SVM: Add VNMI bit definition Santosh Shukla
2023-03-23 0:54 ` Sean Christopherson
2023-02-27 8:40 ` [PATCHv4 10/11] KVM: x86: add support for delayed virtual NMI injection interface Santosh Shukla
2023-03-23 0:49 ` Sean Christopherson
2023-02-27 8:40 ` [PATCHv4 11/11] KVM: nSVM: implement support for nested VNMI Santosh Shukla
2023-03-23 0:50 ` Sean Christopherson
2023-03-10 9:19 ` [PATCHv4 00/11] SVM: virtual NMI Santosh Shukla
2023-03-10 17:02 ` Sean Christopherson
2023-03-23 0:57 ` Sean Christopherson
2023-03-23 1:14 ` Sean Christopherson
2023-03-23 22:53 ` Sean Christopherson
2023-03-24 8:25 ` Santosh Shukla
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=20230227084016.3368-4-santosh.shukla@amd.com \
--to=santosh.shukla@amd.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@maciej.szmigiero.name \
--cc=mlevitsk@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
--cc=vkuznets@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®