Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: "Pratik R. Sampat" <prsampat@amd.com>
To: Sean Christopherson <seanjc@google.com>
Cc: sashiko-reviews@lists.linux.dev, kvm@vger.kernel.org
Subject: Re: [PATCH 1/3] KVM: SVM: Re-queue events that were never injected
Date: Tue, 22 Sep 2026 16:45:18 -0400	[thread overview]
Message-ID: <23c9be41-c8a8-4499-9310-fc4e6247f55d@amd.com> (raw)
In-Reply-To: <arFYHRzNFT886BME@google.com>

Hi Sean,

On 9/21/26 12:15 PM, Sean Christopherson wrote:
>>>> +     /*
>>>> +      * Hardware clears EVENTINJ field when it injects an event.
>>>> +      * A non-empty EVENTINJ on #VMEXIT means the vCPU never entered guest
>>>> +      * mode, and thus that the event was never delivered.  Migrate the event
>>>> +      * to EXITINTINFO so that it's requeued instead of being dropped.
>>>> +      *
>>>> +      * An undelivered event doesn't imply a fatal VMEXIT_INVALID. With
>>>> +      * Enhanced SMT Protection, VMRUN may exit with an ordinary #VMEXIT
>>>> +      * without having injected that event into the guest.
>>>> +      *
>>>> +      * Clobbering EXITINTINFO is safe precisely because the vCPU never
>>>> +      * entered guest mode.
>>>> +      */
>>>> +     if (control->event_inj) {
>>> [Severity: High]
>>> Does this code silently drop valid hardware-reported events?
>>>
>>> If an L1 hypervisor sets event_inj to a non-zero value but leaves the
>>> SVM_EVTINJ_VALID bit clear, hardware will ignore the injection and won't
>>> clear EVENTINJ.
>>
>> The first half is right, nested_svm_check_event_inj() intentionally returns
>> true when V is clear, so vmcb02->control.event_inj can be non-zero with V=0.
>>
>> The second half isn't. Clearing EVENTINJ is not part of injection, it's part of
>> #VMEXIT, and it's unconditional. 
> So that doesn't mesh with the above comment, which says:
> 
>   Hardware clears EVENTINJ field when it injects an event.
> 
> And it begs the question of how this patch is at all useful.  Because all this
> fancy new paranoia is clearly generating #VMEXITs, and if #VMEXIT unconditionally
> clears control->event_inj, I don't see how control->event_inj can be non-zero if
> KVM attempted VMRUN.
> 
> I.e. either this is all broken, or the APM is buggy.

My wording in the comment is misleading. The clear is part of the #VMEXIT path
out of guest mode, where it is indeed unconditional. However, VMRUN can
terminate even before the guest mode is ever entered. With ESMTP, the hardware
can give out a garden variety of exits at the sync point. In this case we
get a VMEXIT that implies the VMRUN never actually ran any guest code then
EVENTINJ won't be cleared. Since the exit code isn't a reliable discriminator,
a non-zero EVENTINJ is the only way to tell.

Thanks,
--Pratik

  reply	other threads:[~2026-09-22 20:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14 16:55 [PATCH 0/3] Introduce Enhanced SMT Protection for SEV-SNP Pratik R. Sampat
2026-09-14 16:55 ` [PATCH 1/3] KVM: SVM: Re-queue events that were never injected Pratik R. Sampat
2026-09-14 17:16   ` sashiko-bot
2026-09-17 15:07     ` Pratik R. Sampat
2026-09-21 16:15       ` Sean Christopherson
2026-09-22 20:45         ` Pratik R. Sampat [this message]
2026-09-21 13:16   ` Sean Christopherson
2026-09-22 20:45     ` Pratik R. Sampat
2026-09-14 16:55 ` [PATCH 2/3] KVM: SVM: Add host support for Enhanced SMT Protection Pratik R. Sampat
2026-09-14 17:13   ` sashiko-bot
2026-09-17 15:07     ` Pratik R. Sampat
2026-09-16 19:56   ` Borislav Petkov
2026-09-17 15:07     ` Pratik R. Sampat
2026-09-14 16:55 ` [PATCH 3/3] x86/sev: Add guest " Pratik R. Sampat
2026-09-14 17:11   ` sashiko-bot
2026-09-17 15:07     ` Pratik R. Sampat

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=23c9be41-c8a8-4499-9310-fc4e6247f55d@amd.com \
    --to=prsampat@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=seanjc@google.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