From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBBDD3DBD7F for ; Fri, 12 Jun 2026 23:06:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781305593; cv=none; b=uNxRqIpZjv7Glr2xdCRrR1iwNMK/oL5EfQMSf5sEZkpXLld7eHfwXY7NGnibivKHCyX2VvvB5kPAGxoYXigLE62wXScm90lUzVPJv/x25pLHmuVNf3YGKLkffM8hDDRViOo9+JIpJBHL6phJO+vCGLDIEKYRnS9mbP1nAP3pdqk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781305593; c=relaxed/simple; bh=6eQiEssKQC2c4js1UbQi49lxWZxkjELs+LqLjtbU2Uo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JsYIkwKATa0CD7JJjW1/rr3uT/dMnEnVN7NH7v32NF/FsSZIZOfyWp3Q5VtjBgMNx4kIULQreD2cL3ZWTRjzAhE51ZDvZ/1pFasNHJ0x3gSP+7GWaimFFwJcXPpEU5yC6T7fC/6s3+zpdf5byka1DoH0jhgYlJ0SgKXu6kc1Qn4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=SHJZDT7d; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SHJZDT7d" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-8423970cb30so1044759b3a.2 for ; Fri, 12 Jun 2026 16:06:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1781305591; x=1781910391; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=qhTktuVCXULSuX/UFAv1vCF49/raqu6/3zhwlwCn86w=; b=SHJZDT7dOoflOP5nZwVxND/NnMTp9jcaAJEP5MvM3bNVDKWi9Xs0z66L2VzzvUhCUb LEoVvMvHJVAYL19CvXwexiBFEE1ScIwcNvtgurZFempoViu/+nTJyiddRLsHDWuwNYJB HTuEyTWTVy3jAtRupqEmwINxtCKG2iPRaL1d0sjyFLBcfCbHjXDb+Vn5PbBExJLGnSpv rCpZHdARfrIFXAa18YRpAlOkiGcAAB8QDR/hQDTdZNiv9Nn1ONRZK10jXhJugiPGb6eN NCLrJJSRdPOtZII173ZtbewsUPJylFhdP0maHe9Odc1z/Gcgt9mRpRU3WE1y9wpWz5Wi 5xZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781305591; x=1781910391; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qhTktuVCXULSuX/UFAv1vCF49/raqu6/3zhwlwCn86w=; b=MXXw9UDHFIC2qd9wbFJB7E3MvKcsVDMOzCAnkm67/x9xgF3wV+BHEAibFDeq1UUshF MwBfbSr9h43Sdyc2AmqTrhU2IZrAD1xXS/EbX2c0grc+9ulTyZYrvGdSVZyULNxTwQ7a VfZIL45CrwPGxxhF3DVXNMPU/1C7i1ui5hwusG2uK7uO1SufCofpHWa1yH1pQ4kj6gUE CfqVYnRtNmRWktFveEIeAUtgAfjvBRwRx0v4hzejwsUsstApY/yOZzsBQbbMHa0KJBe2 nnC9ZV0HdSMngT11uizYvjAyLFx0noUb+Vx7Yz9WCaL8A35YIu538+jmL0t8Q8lnC1lm mjVA== X-Forwarded-Encrypted: i=1; AFNElJ8kGV92fqBMKmfW/tFOJDQ8HR0nWNN53gKYuzkQvfQ+vlhRO11BuN8dP1F9GkL6ZOOp5gSePtHViLuhofo=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3SfwzaMkgcNj5hVniunCGFW2oN0iyIwxz2vUigvapB3I5tQ6Z wSCsXsirCmBYWuRl7IKLhJ7cn0pXl2+G/VMcl2u3ARbUn/MXs79dyeK4bSHNgRdyF7TKkY63xXe lCzAwSA== X-Received: from pfjq17.prod.google.com ([2002:a05:6a00:891:b0:82f:473b:a2d5]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2e12:b0:83c:928:6e5a with SMTP id d2e1a72fcca58-844e196615bmr1794416b3a.13.1781305591149; Fri, 12 Jun 2026 16:06:31 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 12 Jun 2026 16:06:18 -0700 In-Reply-To: <20260612230622.687665-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260612230622.687665-1-seanjc@google.com> X-Mailer: git-send-email 2.54.0.1136.gdb2ca164c4-goog Message-ID: <20260612230622.687665-5-seanjc@google.com> Subject: [PATCH v2 4/8] KVM: Initialize a vCPU's index to '-1' while it's being created From: Sean Christopherson To: Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+5b32c49cd8f005e65654@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" Invalidate a vCPU's index immediately after allocating storage for the vCPU so that KVM doesn't incorrectly treat a vCPU that is the process of being created as being vCPU0. This will also allow detecting that a vCPU is in the process of being created and thus otherwise unreachable, which is useful for avoiding false positives in lockdep assertions on vcpu->mutex. Note, kvm_wait_for_vcpu_online() naturally does the right thing thanks to vcpu->vcpu_idx and kvm->online_vcpus being signed values. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index e44c20c04961..b3d2a678210c 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -4188,6 +4188,8 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, unsigned long id) goto vcpu_decrement; } + vcpu->vcpu_idx = -1; + BUILD_BUG_ON(sizeof(struct kvm_run) > PAGE_SIZE); page = alloc_page(GFP_KERNEL_ACCOUNT | __GFP_ZERO); if (!page) { -- 2.54.0.1136.gdb2ca164c4-goog