Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sohil Mehta" <sohil.mehta@intel.com>, kvm@vger.kernel.org
Subject: Re: [PATCH 3/4] KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception
Date: Wed, 02 Dec 2026 08:35:47 +0000	[thread overview]
Message-ID: <sashiko-outbox-245215@kernel.org> (raw)
In-Reply-To: <20261202080224.4165883-4-sohil.mehta@intel.com>

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()
--

commit 52a98c13d9a8d8b249575bef58fd19c330f0a0f1
Author: Sohil Mehta <sohil.mehta@intel.com>

KVM: VMX: Re-inject an ICEBP #DB as a privileged software exception

This commit re-injects an intercepted ICEBP #DB on VMX as a privileged
software exception with the VM-exit instruction length instead of skipping
the instruction and queueing a hardware exception.

> diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
> index fdc531a61fd30..72d16282b5598 100644
> --- a/arch/x86/kvm/vmx/vmx.c
> +++ b/arch/x86/kvm/vmx/vmx.c

[ ... ]

> @@ -5533,17 +5532,24 @@ static int handle_exception_nmi(struct kvm_vcpu *vcpu)
>  		if (!(vcpu->guest_debug &
>  		      (KVM_GUESTDBG_SINGLESTEP | KVM_GUESTDBG_USE_HW_BP))) {
>  			/*
> -			 * If the #DB was due to ICEBP, a.k.a. INT1, skip the
> -			 * instruction.  ICEBP generates a trap-like #DB, but
> +			 * ICEBP, a.k.a. INT1, generates a trap-like #DB, but
>  			 * despite its interception control being tied to #DB,
>  			 * is an instruction intercept, i.e. the VM-Exit occurs
> -			 * on the ICEBP itself.  Use the inner "skip" helper to
> -			 * avoid single-step #DB and MTF updates, as ICEBP is
> -			 * higher priority.  Note, skipping ICEBP still clears
> -			 * STI and MOVSS blocking.
> +			 * on the ICEBP itself. Re-inject the #DB as what it
> +			 * is, a privileged software exception, so that VM-Entry
> +			 * advances RIP past the ICEBP using its length. Clear
> +			 * STI and MOVSS blocking, as retiring the ICEBP would.
> +			 * Note, an ICEBP in enclave mode exits as a hardware
> +			 * exception, so it never gets here.
>  			 */
> -			if (is_icebp(intr_info))
> -				WARN_ON_ONCE(!skip_emulated_instruction(vcpu));
> +			if (is_icebp(intr_info)) {
> +				vcpu->arch.event_exit_inst_len =
> +					vmcs_read32(VM_EXIT_INSTRUCTION_LEN);
> +				vmx_set_interrupt_shadow(vcpu, 0);
> +				kvm_queue_exception_p_type(vcpu, DB_VECTOR, dr6,
> +							   EVENT_TYPE_PRIV_SWEXC);
> +				return 1;
> +			}

[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?

Previously, exceptions omitted from KVM_GET_VCPU_EVENTS never had both
ex->pending and ex->has_payload set.  Now an intercepted ICEBP queues a
pending EVENT_TYPE_PRIV_SWEXC with ex->has_payload = true while leaving
GUEST_RIP at the ICEBP instruction:

arch/x86/kvm/x86.c:kvm_handle_exception_payload_quirk() {
	...
	if (!vcpu->kvm->arch.exception_payload_enabled &&
	    ex->pending && ex->has_payload)
		kvm_deliver_exception_payload(vcpu, ex);
}

arch/x86/kvm/x86.c:kvm_vcpu_ioctl_x86_get_vcpu_events() {
	...
	if (!kvm_exception_is_soft(ex->vector) &&
	    ex->event_type != EVENT_TYPE_PRIV_SWEXC) {
		events->exception.injected = ex->injected;
		events->exception.pending = ex->pending;
		...
	}
	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;
	...
}

When KVM_CAP_EXCEPTION_PAYLOAD is disabled,
kvm_handle_exception_payload_quirk() delivers the DR6 payload into
vcpu->arch.dr6 (clearing B0..B3 and updating DR6_RTM) even though
KVM_GET_VCPU_EVENTS drops the exception so the guest will re-execute ICEBP.
When KVM_CAP_EXCEPTION_PAYLOAD is enabled, KVM_GET_VCPU_EVENTS reports
events->exception_has_payload = 1 with pending = 0 and injected = 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202080224.4165883-1-sohil.mehta@intel.com?part=3

  reply	other threads:[~2026-12-02  8:35 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
2026-12-02  8:35   ` sashiko-bot [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=sashiko-outbox-245215@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sohil.mehta@intel.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