From: Sohil Mehta <sohil.mehta@intel.com>
To: <sashiko-reviews@lists.linux.dev>, <kvm@vger.kernel.org>
Cc: 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>,
David Woodhouse <dwmw@amazon.co.uk>,
Chao Gao <chao.gao@intel.com>,
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 3/4] KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception
Date: Thu, 3 Dec 2026 00:25:21 -0800 [thread overview]
Message-ID: <6294e225-2479-4bfc-b4d5-60d290f74009@intel.com> (raw)
In-Reply-To: <sashiko-outbox-245215@kernel.org>
+ Everyone from the main thread (because I am not sure how to dispose this)
On 12/2/2026 12:35 AM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] KVM: x86: unhandled ICEBP payload in
> kvm_vcpu_ioctl_x86_get_vcpu_events()
> --
> [Severity: Medium]
> Can queueing an ICEBP #DB with a payload and EVENT_TYPE_PRIV_SWEXC corrupt
> guest state if KVM exits to userspace (for example on a pending signal)
> before injecting the exception?
>
The window seems real. It happens because patch 2 leaves a queued INT1
out of the vCPU events like INT3 and INTO, but those don't carry a
payload. So the payload of a #DB that isn't saved still leaks out, to
userspace or into DR6. However, I don't see how the guest state can be
corrupted.
My LLM says:
- Without KVM_CAP_EXCEPTION_PAYLOAD, KVM writes the payload to DR6 when
userspace saves the vCPU state. After a restore, the guest
re-executes the ICEBP, and the new #DB writes the same DR6 bits
again.
- With KVM_CAP_EXCEPTION_PAYLOAD, KVM_GET_VCPU_EVENTS reports the
payload without a pending or injected exception, and
KVM_SET_VCPU_EVENTS drops it.
IIUC, the fix would be to leave the payload of a queued INT1 out of the
vCPU events too, and not deliver it early when userspace saves the vCPU
state. Maybe something like this (tested with a throwaway selftest),
folded into patch 2:
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2978,6 +2978,17 @@ static struct kvm_queued_exception *kvm_
return &vcpu->arch.exception;
}
+/*
+ * The vCPU events API doesn't provide the instruction length that software
+ * exceptions and INT1 need, so KVM doesn't report them. As long as the
guest
+ * RIP isn't advanced, the guest encounters the exception again.
+ */
+static bool kvm_exception_is_reportable(struct kvm_queued_exception *ex)
+{
+ return !kvm_exception_is_soft(ex->vector) &&
+ ex->event_type != EVENT_TYPE_PRIV_SWEXC;
+}
+
void kvm_handle_exception_payload_quirk(struct kvm_vcpu *vcpu)
{
struct kvm_queued_exception *ex = kvm_get_exception_to_save(vcpu);
@@ -2996,7 +3007,7 @@ void kvm_handle_exception_payload_quirk(
* safely defer delivery of the payload.
*/
if (!vcpu->kvm->arch.exception_payload_enabled &&
- ex->pending && ex->has_payload)
+ ex->pending && ex->has_payload && kvm_exception_is_reportable(ex))
kvm_deliver_exception_payload(vcpu, ex);
}
@@ -3016,14 +3027,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_
memset(events, 0, sizeof(*events));
- /*
- * The API doesn't provide the instruction length that software
- * exceptions and INT1 need, so don't report them. As long as the
- * guest RIP isn't advanced, we should expect to encounter the
- * exception again.
- */
- if (!kvm_exception_is_soft(ex->vector) &&
- ex->event_type != EVENT_TYPE_PRIV_SWEXC) {
+ if (kvm_exception_is_reportable(ex)) {
events->exception.injected = ex->injected;
events->exception.pending = ex->pending;
/*
@@ -3033,12 +3037,12 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_
*/
if (!vcpu->kvm->arch.exception_payload_enabled)
events->exception.injected |= ex->pending;
+ events->exception_has_payload = ex->has_payload;
+ events->exception_payload = ex->payload;
}
events->exception.nr = ex->vector;
events->exception.has_error_code = ex->has_error_code;
events->exception.error_code = ex->error_code;
- events->exception_has_payload = ex->has_payload;
- events->exception_payload = ex->payload;
events->interrupt.injected =
vcpu->arch.interrupt.injected && !vcpu->arch.interrupt.soft;
I think even though it doesn't fix a guest-visible problem, it does make
the handling of exception payloads more consistent with the API's
limitations. KVM_GET_VCPU_EVENTS stops reporting a payload without an
exception, and saving the vCPU state no longer writes DR6 for a #DB that
isn't saved.
This isn't really my area of expertise, so I would appreciate feedback
on this. Does this seem worth fixing?
next prev parent reply other threads:[~2026-12-03 8:25 UTC|newest]
Thread overview: 6+ 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-02 8:02 ` [PATCH 3/4] KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception Sohil Mehta
[not found] ` <sashiko-outbox-245215@kernel.org>
2026-12-03 8:25 ` Sohil Mehta [this message]
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=6294e225-2479-4bfc-b4d5-60d290f74009@intel.com \
--to=sohil.mehta@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=binbin.wu@linux.intel.com \
--cc=bp@alien8.de \
--cc=chang.seok.bae@intel.com \
--cc=chao.gao@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=sashiko-reviews@lists.linux.dev \
--cc=seanjc@google.com \
--cc=shivansh.dhiman@amd.com \
--cc=skhan@linuxfoundation.org \
--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