From: Chao Gao <chao.gao@intel.com>
To: Sohil Mehta <sohil.mehta@intel.com>
Cc: <kvm@vger.kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
"Sean Christopherson" <seanjc@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
"Borislav Petkov" <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>, Xin Li <xin@zytor.com>,
Peter Zijlstra <peterz@infradead.org>,
Andrew Cooper <andrew.cooper3@citrix.com>,
"Tom Lendacky" <thomas.lendacky@amd.com>,
Nikunj A Dadhania <nikunj@amd.com>,
Shivansh Dhiman <shivansh.dhiman@amd.com>,
Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>,
David Woodhouse <dwmw@amazon.co.uk>,
Binbin Wu <binbin.wu@linux.intel.com>,
Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>,
"Chang S . Bae" <chang.seok.bae@intel.com>,
Yosry Ahmed <yosry@kernel.org>,
David Matlack <dmatlack@google.com>, <x86@kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-kselftest@vger.kernel.org>
Subject: Re: [PATCH 2/4] KVM: nVMX: Don't drop an L1-injected INT1 whose delivery is interrupted
Date: Fri, 4 Dec 2026 17:40:52 +0800 [thread overview]
Message-ID: <axKKpPK-3suA4ZIu@intel.com> (raw)
In-Reply-To: <20261202080224.4165883-3-sohil.mehta@intel.com>
On Wed, Dec 02, 2026 at 04:02:22PM +0800, Sohil Mehta wrote:
>diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
>index 1a98f28651f7..6cb07873998d 100644
>--- a/arch/x86/kvm/vmx/nested.c
>+++ b/arch/x86/kvm/vmx/nested.c
>@@ -3970,12 +3970,17 @@ static void vmcs12_save_pending_event(struct kvm_vcpu *vcpu,
> nr = vcpu->arch.exception.vector;
> idt_vectoring = nr | VECTORING_INFO_VALID_MASK;
>
>- if (kvm_exception_is_soft(nr)) {
>+ if (vcpu->arch.exception.event_type == EVENT_TYPE_PRIV_SWEXC) {
>+ vmcs12->vm_exit_instruction_len =
>+ vcpu->arch.event_exit_inst_len;
>+ idt_vectoring |= INTR_TYPE_PRIV_SW_EXCEPTION;
>+ } else if (kvm_exception_is_soft(nr)) {
> vmcs12->vm_exit_instruction_len =
> vcpu->arch.event_exit_inst_len;
> idt_vectoring |= INTR_TYPE_SOFT_EXCEPTION;
>- } else
>+ } else {
> idt_vectoring |= INTR_TYPE_HARD_EXCEPTION;
>+ }
Can we derive the type in idt_vectoring from the event type?
idt_vectoring |= vcpu->arch.exception.event_type << 8;
And then set vm_exit_instruction_len only if the event is a software
exception or a privileged software exception.
if (vcpu->arch.exception.event_type == EVENT_TYPE_PRIV_SWEXC ||
vcpu->arch.exception.event_type == EVENT_TYPE_SWEXC)
vmcs12->vm_exit_instruction_len =
vcpu->arch.event_exit_inst_len;
This is much more readable than the if/else chain. The same applies to
nested_vmx_inject_exception_vmexit() and vmx_inject_exception() below.
>diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
>index a6c0e8ccdfad..fdc531a61fd3 100644
>--- a/arch/x86/kvm/vmx/vmx.c
>+++ b/arch/x86/kvm/vmx/vmx.c
>@@ -1973,12 +1973,18 @@ void vmx_inject_exception(struct kvm_vcpu *vcpu)
>
> WARN_ON_ONCE(vmx->vt.emulation_required);
>
>- if (kvm_exception_is_soft(ex->vector)) {
>+ /* L1 can inject a privileged software exception with any vector. */
If the event type is the only source of the type here, you don't need
to worry about the order of the event type and vector checks, and this
comment can go.
>+ if (ex->event_type == EVENT_TYPE_PRIV_SWEXC) {
>+ vmcs_write32(VM_ENTRY_INSTRUCTION_LEN,
>+ vmx->vcpu.arch.event_exit_inst_len);
>+ intr_info |= INTR_TYPE_PRIV_SW_EXCEPTION;
>+ } else if (kvm_exception_is_soft(ex->vector)) {
>diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>index c27813bde407..b58518a777de 100644
>--- a/arch/x86/kvm/x86.c
>+++ b/arch/x86/kvm/x86.c
>@@ -3010,12 +3010,13 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
> */
>- if (!kvm_exception_is_soft(ex->vector)) {
>+ if (!kvm_exception_is_soft(ex->vector) &&
>+ ex->event_type != EVENT_TYPE_PRIV_SWEXC) {
With the event type, this becomes a check for a software exception or
a privileged software exception.
ex->event_type == EVENT_TYPE_PRIV_SWEXC ||
ex->event_type == EVENT_TYPE_SWEXC
That check then occurs in a few places, so we can probably add a helper
for it.
next prev parent reply other threads:[~2026-12-04 9:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 8:02 [PATCH 0/4] KVM: VMX: Handle the #DB of an ICEBP as a privileged software exception Sohil Mehta
2026-12-02 8:02 ` [PATCH 1/4] KVM: x86: Track the event type of a queued exception Sohil Mehta
2026-12-02 8:02 ` [PATCH 2/4] KVM: nVMX: Don't drop an L1-injected INT1 whose delivery is interrupted Sohil Mehta
2026-12-04 9:40 ` Chao Gao [this message]
2026-12-02 8:02 ` [PATCH 3/4] KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception Sohil Mehta
2026-12-02 8:35 ` sashiko-bot
2026-12-03 8:25 ` Sohil Mehta
2026-12-02 8:02 ` [PATCH 4/4] KVM: selftests: Test how L1 sees the #DB of an ICEBP in L2 Sohil Mehta
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=axKKpPK-3suA4ZIu@intel.com \
--to=chao.gao@intel.com \
--cc=Neeraj.Upadhyay@amd.com \
--cc=andrew.cooper3@citrix.com \
--cc=binbin.wu@linux.intel.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dmatlack@google.com \
--cc=dwmw@amazon.co.uk \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=maciej.wieczor-retman@intel.com \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=shivansh.dhiman@amd.com \
--cc=skhan@linuxfoundation.org \
--cc=sohil.mehta@intel.com \
--cc=tglx@kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
--cc=yosry@kernel.org \
/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