Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sean Christopherson" <seanjc@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 13/15] KVM: VMX: Explicitly remove dying vCPUs from the PI wakeup list
Date: Tue, 27 Oct 2026 22:32:42 +0000	[thread overview]
Message-ID: <sashiko-outbox-187163@kernel.org> (raw)
In-Reply-To: <20261027221209.1560865-14-seanjc@google.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] KVM: VMX: userspace WARN_ON_ONCE() in vt_vcpu_pi_remove_from_wakeup_list()
--

commit 8f6f619224b282626da2d8fdae4dd65b668b2bef
Author: Sean Christopherson <seanjc@google.com>

KVM: VMX: Explicitly remove dying vCPUs from the PI wakeup list

This commit adds vt_vcpu_pi_remove_from_wakeup_list() and calls it from
vmx_vcpu_free() so dying vCPUs that were blocking when the VM was released are
explicitly removed from the Posted Interrupts wakeup list.

> diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
> index 2644add54b76b..7414fb551d2e9 100644
> --- a/arch/x86/kvm/vmx/posted_intr.c
> +++ b/arch/x86/kvm/vmx/posted_intr.c

[ ... ]

> @@ -146,6 +149,19 @@ void vt_vcpu_pi_load(struct kvm_vcpu *vcpu, int cpu)
>  		pi_set_on(pi_desc);
>  }
>  
> +void vt_vcpu_pi_remove_from_wakeup_list(struct kvm_vcpu *vcpu)
> +{
> +	WARN_ON_ONCE(refcount_read(&vcpu->kvm->users_count));

[Severity: High]
Can this WARN_ON_ONCE() be triggered from host userspace if KVM_CREATE_VCPU
fails after kvm_arch_vcpu_create()?

In virt/kvm/kvm_main.c:kvm_vm_ioctl_create_vcpu(), if kvm_dirty_ring_alloc(),
xa_insert(), or create_vcpu_fd() (for example when RLIMIT_NOFILE is reached)
fails, the error path tears down the partially created vCPU while the VM is
still live and vcpu->kvm->users_count is non-zero:

virt/kvm/kvm_main.c:kvm_vm_ioctl_create_vcpu() {
    ...
	r = create_vcpu_fd(vcpu);
	if (r < 0)
		goto kvm_put_xa_erase;
    ...
kvm_put_xa_erase:
	mutex_unlock(&vcpu->mutex);
	kvm_put_kvm_no_destroy(kvm);
	xa_erase(&kvm->vcpu_array, vcpu->vcpu_idx);
unlock_vcpu_destroy:
	vcpu->vcpu_idx = -1;
	kvm_dirty_ring_free(&vcpu->dirty_ring);
arch_vcpu_destroy:
	kvm_arch_vcpu_destroy(vcpu);
}

kvm_arch_vcpu_destroy() calls into vmx_vcpu_free(), which unconditionally
calls vt_vcpu_pi_remove_from_wakeup_list(vcpu). Since the assertion runs
before checking whether the vCPU is actually on the wakeup list (or checking
vcpu->vcpu_idx >= 0), wouldn't a failed KVM_CREATE_VCPU ioctl hit this warning?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261027221209.1560865-1-seanjc@google.com?part=13

  reply	other threads:[~2026-10-27 22:32 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27 22:11 [PATCH v3 00/15] KVM: Fix+harden against bad uaccess using dying VM Sean Christopherson
2026-10-27 22:11 ` [PATCH v3 01/15] KVM: Reject user accesses to guest memory if current->mm != kvm->mm Sean Christopherson
2026-10-27 22:11 ` [PATCH v3 02/15] KVM: nVMX: Don't force a full nested VM-Exit when destroying a vCPU Sean Christopherson
2026-10-27 22:54   ` Sean Christopherson
2026-10-27 22:11 ` [PATCH v3 03/15] KVM: PPC: Flush/zap all memslots on kvm_arch_flush_shadow_all() Sean Christopherson
2026-10-27 22:11 ` [PATCH v3 04/15] KVM: x86: Unmap VMAs for KVM-internal memslots when the memslot is freed Sean Christopherson
2026-10-27 22:27   ` sashiko-bot
2026-10-27 22:11 ` [PATCH v3 05/15] KVM: Disallow setting memslots when the VM is being destroyed Sean Christopherson
2026-10-27 22:11 ` [PATCH v3 06/15] KVM: Destroy memslots immediately after mmu_notifiers are unregistered Sean Christopherson
2026-10-27 22:12 ` [PATCH v3 07/15] KVM: WARN if KVM attempts to do guest-related uaccess with "wrong" process Sean Christopherson
2026-10-27 22:12 ` [PATCH v3 08/15] KVM: WARN and reject guest-based uaccess if VM is dying Sean Christopherson
2026-10-28  0:26   ` James Houghton
2026-10-27 22:12 ` [PATCH v3 09/15] KVM: Pre-check uaccesses in KVM's APIs to read/write guest memory Sean Christopherson
2026-10-28  0:22   ` James Houghton
2026-10-27 22:12 ` [PATCH v3 10/15] KVM: VMX: Explicility free vmcs01, not the current VMCS, in vCPU free paths Sean Christopherson
2026-10-28  0:33   ` James Houghton
2026-10-27 22:12 ` [PATCH v3 11/15] KVM: nVMX: Don't explicitly VMCLEAR+free() vmcs01's shadow VMCS when freeing vCPU Sean Christopherson
2026-10-27 22:12 ` [PATCH v3 12/15] KVM: nVMX: Cancel the nested VMX Preemption Timer's hrtimer in free_nested() Sean Christopherson
2026-10-27 22:12 ` [PATCH v3 13/15] KVM: VMX: Explicitly remove dying vCPUs from the PI wakeup list Sean Christopherson
2026-10-27 22:32   ` sashiko-bot [this message]
2026-10-27 22:12 ` [PATCH v3 14/15] KVM: nVMX: Don't switch to vmcs01 when freeing a vCPU Sean Christopherson
2026-10-27 22:12 ` [PATCH v3 15/15] KVM: nVMX: Don't load+put the vCPU when freeing nested state for a dying vCPU Sean Christopherson
2026-10-28  9:18 ` [syzbot ci] Re: KVM: Fix+harden against bad uaccess using dying VM syzbot ci

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-187163@kernel.org \
    --to=sashiko-bot@kernel.org \
    --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