From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 85E7E33374F for ; Tue, 30 Jun 2026 22:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782860208; cv=none; b=SpICHs03k22p4w71ln4JQb+bnO+HzfwQrVRrWZmDuqJl3liTfZNT6MYP57X+XMvRz+tM2/5kWJGmw9p8bOlH16bUTyfY+fTlnNPduW9mIIpavJ3x8xDuF3NQJqiRWpjaLcPytaulPUajM6Qq4+aWxnPSoVA+heVVqbSjW9eyp7g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782860208; c=relaxed/simple; bh=MJMJSRlF5r3+tmZ0m1lotCOKLe9s9kaI30CjRDVM5h8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jmNe3uErh9JYMobMnlYYD3bpA0rUHzjI5bsCF7c585t3vTt1nFC8eMW8wbwT0w0TVUSXXf/dqDaoGPSc+OVKE8YNSZQqaoDkRFTKadhgr+zFqPbjti1bzlAK3EgrPv137XEQdtj6GGhP4uwT04j9UCLDDuv7nTQQlxhxfsegnZk= 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=KiX+nuqe; arc=none smtp.client-ip=209.85.214.202 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="KiX+nuqe" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ca1f16e391so262505ad.2 for ; Tue, 30 Jun 2026 15:56:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782860191; x=1783464991; 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=saiGWJ+1qIp4vGwoKItcqKkB3ikEVHldv3doWsecfgE=; b=KiX+nuqeFAwoMVF4jzvZqXtidhyTXNhV1afuSg0CGdkCH+nKDR0xcM8OIhUzHd0dv4 o8CAHCVlL3C2e+1vv+jwCqaE5px4nZx1ak3fLAd86ztiMM+6mSwU4/JKRidxwZsgd8xv o3SyMlGbMMdR7zXc3ki7zGfMyZvv69nWU8ooz3/smpmTtEVHiOAYwlJ0NyX8gvuULlKr tJD0ULSjRrVizLTIeHTyjQJ8ZCch2bPX6BcoPNmTIliNlnlSYR248PrHZN76r2bzVHqC mcR2K6WNBc09qeW4ujRfRvpTi0p2TlStg7jI6Mr7u7DntFlQoe9G1Y/frj5No0Vs5d95 2uxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782860191; x=1783464991; 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=saiGWJ+1qIp4vGwoKItcqKkB3ikEVHldv3doWsecfgE=; b=DOGTKKbYUq9sVnyrWC6f3gb2ZZUKLL+POLOxTL60GsIm9zg5F/HGswY//e+3zd1Mvd m3SJeRPLNYaDFkl6ijANGxwIyrL82Y3F8SAN1HdtcUihTqd1cNuoHO0gAEJUew3aaPmH s0sivnGzH7AKudCRkw9OQPE1FvaX0lPnkZcD6s7+l18UOwBqzXpNrRpJajAV2XQ8l/br u7JbrshYqe+R0UR5UMmbJ0YoH7i0Q4z1XqVxzyqQVxdeOFLVvQWjddQHsf6Rhp8pAD5Q /nBjdZrrOsRHhcmhtAuhLTjO8h8bOxijkEJiD0EeH3HeFqAzJcpt7pDnz+NGhfn4ymPO xz5Q== X-Forwarded-Encrypted: i=1; AHgh+RqiynFs66JFJBwx3xSBLNFgt2h2XSkvz0mzJFsAmW8AIW1ihbabo79+4CuR1HVdkvCKMQOpxb6PhUJAIuA=@vger.kernel.org X-Gm-Message-State: AOJu0YyxrAtsUK1IyjNKejcDpDb5ghdIb/BFVTduuDlQM5qEy6zxUUyS dEgG3aaYzG8K1NLluvo/Hp8hnb5pQbbAmFyhuemvO0Z33s16Yhb0ZQE3nCaxONbrO3SnZejtsrd Obex+hQ== X-Received: from plbmg11.prod.google.com ([2002:a17:903:348b:b0:2bd:8434:6d14]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:2349:b0:2c9:99a3:911d with SMTP id d9443c01a7336-2ca5a52fae2mr21898975ad.9.1782860190491; Tue, 30 Jun 2026 15:56:30 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 30 Jun 2026 15:56:16 -0700 In-Reply-To: <20260630225619.511632-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: <20260630225619.511632-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260630225619.511632-10-seanjc@google.com> Subject: [PATCH v4 09/11] KVM: x86: Treat a vCPU as unreachable if its index is invalid From: Sean Christopherson To: Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , David Woodhouse , Paul Durrant Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+5b32c49cd8f005e65654@syzkaller.appspotmail.com, syzbot+5d2b94b77112148d1744@syzkaller.appspotmail.com, David Woodhouse Content-Type: text/plain; charset="UTF-8" In the "vCPU locked or unreachable" lockdep assertion, treat a vCPU as unreachable if its index is invalid, i.e. if the vCPU is in the process of being created. Until the vCPU is inserted into the array of vCPUs, the only way to get at the vCPU is via kvm_vm_ioctl_create_vcpu(). Note, the actual index is set _before_ adding the vCPU to the array, i.e. there's no risk of a false negative on the lockdep assertion. Signed-off-by: Sean Christopherson --- include/linux/kvm_host.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index b10814f99a50..0bdfa3699352 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -992,6 +992,7 @@ static inline struct kvm_io_bus *kvm_get_bus(struct kvm *kvm, enum kvm_bus idx) static inline void kvm_lockdep_assert_vcpu_is_locked_or_unreachable(struct kvm_vcpu *vcpu) { lockdep_assert_once(lockdep_is_held(&vcpu->mutex) || + vcpu->vcpu_idx < 0 || !refcount_read(&vcpu->kvm->users_count)); } -- 2.55.0.rc0.799.gd6f94ed593-goog