From: "Huang, Kai" <kai.huang@intel.com>
To: "seanjc@google.com" <seanjc@google.com>
Cc: "Gao, Chao" <chao.gao@intel.com>,
"aashish@aashishsharma.net" <aashish@aashishsharma.net>,
"guang.zeng@intel.com" <guang.zeng@intel.com>,
"dmaluka@chromium.org" <dmaluka@chromium.org>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"vineeth@bitbyteword.org" <vineeth@bitbyteword.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"jaszczyk@chromium.org" <jaszczyk@chromium.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
"pbonzini@redhat.com" <pbonzini@redhat.com>,
"Dong, Chuanxiao" <chuanxiao.dong@intel.com>
Subject: Re: [PATCH] KVM: VMX: Postpone IPIv setup after successful vCPU creation
Date: Mon, 20 Jul 2026 23:10:44 +0000 [thread overview]
Message-ID: <a4f683a52c096d8a7cd7d6c4ab895fd41f197eda.camel@intel.com> (raw)
In-Reply-To: <al6eg7C-2sDBEAFD@google.com>
>
> In other words, I want to fix this entire class of bugs, not play a game of
> whack-a-mole with bugs that humans are all but guaranteed to overlook.
I was thinking yet another xarray could make the overall logic more complicated,
but yeah, agreed that rejecting the duplicated vcpu_id asap is the right
solution to avoid such bugs (my first glance too in the first reply).
>
> My other concern with the proposed change is that the vCPU becomes reachable
> before long before kvm_arch_vcpu_postcreate(). Which should be fine" for IPI
> virtualization, but sets a precedence I'd rather not exist, because initializing
> vCPU state _after_ it's reachable is rarely correct. E.g. msr_kvm_poll_control
> is initialized in postcreate for some reason, and that's technically buggy
> because it's possible, albeit extremely unlikely, that MSR_KVM_POLL_CONTROL could
> be written by userspace before postcreate() runs.
Fair enough. This didn't ring a bell to me. Thanks for mentioning it.
>
> E.g. for the xarray approacy (sketch only, completely untested):
>
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index fdbd697d0337..e34ca5920393 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -791,6 +791,7 @@ struct kvm {
> /* The current active memslot set for each address space */
> struct kvm_memslots __rcu *memslots[KVM_MAX_NR_ADDRESS_SPACES];
> struct xarray vcpu_array;
> + struct xarray pending_vcpu_ids;
> /*
> * Protected by slots_lock, but can be read outside if an
> * incorrect answer is acceptable.
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 2df8ee9ecf6c..8bc4f7ffd76d 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -4179,6 +4179,12 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id)
> return r;
> }
>
> + r = xa_insert(&kvm->pending_vcpu_ids, id, xa_mk_value(id), GFP_KERNEL);
> + if (r) {
> + mutex_unlock(&kvm->lock);
> + return r;
> + }
> +
(No preference between xarray vs bitmap)
Should we move this before kvm_arch_vcpu_precreate() to avoid any "precreate"
for duplicated vcpu_id?
next prev parent reply other threads:[~2026-07-20 23:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 16:08 Dmytro Maluka
2026-07-17 12:59 ` Huang, Kai
2026-07-17 16:20 ` Dmytro Maluka
2026-07-17 21:21 ` Huang, Kai
2026-07-20 22:17 ` Sean Christopherson
2026-07-20 23:10 ` Huang, Kai [this message]
2026-07-20 23:15 ` Sean Christopherson
2026-07-20 23:22 ` Huang, Kai
2026-07-21 9:26 ` Dmytro Maluka
2026-07-20 6:29 ` Chao Gao
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=a4f683a52c096d8a7cd7d6c4ab895fd41f197eda.camel@intel.com \
--to=kai.huang@intel.com \
--cc=aashish@aashishsharma.net \
--cc=chao.gao@intel.com \
--cc=chuanxiao.dong@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=dmaluka@chromium.org \
--cc=guang.zeng@intel.com \
--cc=jaszczyk@chromium.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vineeth@bitbyteword.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
all inboxes | Powered by JetHome®