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 D1BE93B841C for ; Thu, 25 Jun 2026 22:36:34 +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=1782426996; cv=none; b=EyWF7o6T+Y3+wAUkvVCh/ceR0As9nWKIJg7LTKPS3WtJUh/8AFEPzwiZaOo4nLpM6xzKXalm58t9LR4zqgFL/o5J54zPm9CaWbCJ6zhJVe9BIs1trJS44NzFzEEV/OYneHqhA+fJ1w1UbLCpI/k4EmxufKst75pyYVvDWhdQa+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782426996; c=relaxed/simple; bh=MJMJSRlF5r3+tmZ0m1lotCOKLe9s9kaI30CjRDVM5h8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=byKGqjc5MriVSUM9bet584ty8wl2fr2sSJOwJkaZYBxHOhYgLh5CzHshALIauRmsjKsMhE5M6RFN1JMgLMlfPpQOpJdSr3U+kKKEODw4+hAdkoUMO/kPN9jWTI4pxKncnfQtGkSmPh+y1apa5FCs1MeZ0X72C0z2nED1DlJWqT0= 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=qPCkLYkh; 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="qPCkLYkh" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2c80be91ea3so5225865ad.1 for ; Thu, 25 Jun 2026 15:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782426994; x=1783031794; 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=qPCkLYkh/yOD88x9oVTAn2Yk7HDix34jG9if8amo7lySdn7v1eZpAF0YN/ZaPtAaJ5 iN6/nr06ihOsWLRorGzEpPYjcJcPUb4aZbZ15DAssVY6Qaks2rr2qS2/FQ5vMKo5Q5rE dxO6IUsNBiv4mFBuIXLyO+rh62a6CQbQF2IkgtOkP2WRYBAdO+cRaHmw1qDKn7MXAUXz ymoNIzcmGcvjbBl4fRwL+qNCgqe4sc9CB8eDctHj72uK+gGc675cadxA+PG18V4jmiL5 Oo7NWlne+KXea4Xi5G/90SaKxN1PRvQ1InB4A7Jy4eyXAIFS4t+l0dO9duy0pOf8Z2vX u3VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782426994; x=1783031794; 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=o9UoWPIxfdRhIwHXI7LmXHVJr0Gq7XsRTX4lCsLymBNLsLUZVQyaO242Ve/D/S7hVQ 5h1yQ7j6SXefIrvc9qTEe1ahbHoE2grAe5tilRLXKxAfLc7XLlBYnK35czkzvoMF33hm f8KZTYvJeFggP37NypCm9pKE7CIA4hBX4pvlsmvRZneHDJEh5He5dnpnBUBoC0mGx7yL zJ/Utw8Bdr+Zpblqn2y8bMGiEawijsYqZbeRFsJqaX2rf6ZKVoNosAeSLzcVLWH4BQDG Yo1VI55Fo0WFDTySyrHD4nml/Yhpo7eyGvltTjUOg2Qnl5KoyjWmdU5J37UKKg3unaRA eUAQ== X-Forwarded-Encrypted: i=1; AHgh+RrqBV09qLFCLKqxUZMdoHny2pWBJCODlQfN75pBUab3m0SGQEopG4lzggMZQdr6zpY95EhxPkoWQ14VuCE=@vger.kernel.org X-Gm-Message-State: AOJu0Yy95CSn1WmPwY+QBSrFMOljeZ5TLuw5rBNkTcQCp8tD6F8lM3ep CLWrGkJ+b8y3HHM933S/YhdPjTI9H79L51uvP27XIIv2Jfqw/YrDsBeewf4nfVXQq4RAGaOGSnE Bpi+LTQ== X-Received: from plka7.prod.google.com ([2002:a17:903:f87:b0:2c7:ef8a:f87f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:46c3:b0:2c1:f262:4962 with SMTP id d9443c01a7336-2c7fc6f45d4mr41405045ad.20.1782426993903; Thu, 25 Jun 2026 15:36:33 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 25 Jun 2026 15:36:21 -0700 In-Reply-To: <20260625223623.3376478-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: <20260625223623.3376478-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260625223623.3376478-9-seanjc@google.com> Subject: [PATCH v3 08/10] 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 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