From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (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 4E9E64BE435 for ; Thu, 10 Sep 2026 16:24:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.69 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789057450; cv=none; b=jPSNtObip9vXYRFsHF6gq6QCVYlDrJ0ukye0GqjY/idw6f9QGRR5RdlrnSPthj/gDQeml2WRuGmJdjULzRuTAnQn60v4u673WZC4tR5/DU7okyYnbOuovDHgbBtgwbDYJdyR4fawfHANtx7JP7kJvDUy+XGVI4Ly1b1evdGRISY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789057450; c=relaxed/simple; bh=AHvgtIL5obyEkQeMJj9TEFvDUyBEEuMsjvgCq4Ntp70=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Lf38vxsDboYuBXGsrATKssImphlzr4xQEeJRL0T6aRgN9CjZ9yTQswc3tmRbQDrcgkhEYRXpAppma6SgYWyLtrFt94G6fmMQcVjO5PciEs+QIiV8eKFdyJfYmnWcaKEik5JOHwd7C/qXQoPPXkCVfggBMgnWepCrfvQ7Yi54a9w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--elver.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=evJS0+Ex; arc=none smtp.client-ip=209.85.128.69 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--elver.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="evJS0+Ex" Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4955e865174so16555e9.3 for ; Thu, 10 Sep 2026 09:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1789057445; x=1789662245; darn=lists.linux.dev; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3WjqNYFOMqEwxR4wUCekRhwd9RX45J94sJ1enbo8buA=; b=evJS0+ExlFgPVHJvr64gQaAiVoaEYI8pmpUGzO5QA8Rq5+O5RaPShfXVT4B3WGlbPE 2YMcfehhpzFhsKsuKm38sZ0DPRTn0TeCXCrnW4KBskWjIR8wAvzZco0va0vH+Gr4N96H wERjLGfHsvrg+kHNLXwFeohzoJC0HW7AzNSFSv7y7Wo5c9tAeDNWNzGiqCGwVJSC8xjK FourrL5Yf7YLiNapYZV3+s7nWFcfO3khbb9UxXupZpr9Rmw7E/F0XgsmKzD92bKVRbJR g6n4QR/qmuuSQVHCmHif7ALa6d5GhwhezsAQzyWhonE5PIi7KmAXFEUfv2F0bpLWfrHg W6ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789057445; x=1789662245; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3WjqNYFOMqEwxR4wUCekRhwd9RX45J94sJ1enbo8buA=; b=S92x+QgP3zxwh8jjYnsWvWT6QHMlbtJISdlBV6e02fAD/hiXD8Dh3gBiBIBDk/Cp97 1Kiw1R21sESL9BMSv+/JfhBncWsOnJZW/8hM9TvI8QF+/utLHHbGUXD6bw65sqgL0NVZ EHxslvHvhiUdNrtFRUf42PYTN89n0O9XxYJRQWlWSwxlRlDgeIO/x9vhrse4J0ARxmeJ WqgF42VDLp33mqnkl04z+21f3sInuvTpFXMX+oII33sLjOrdXqJQBvI4B4v4BnBv9pu2 +ZMTmLIysZcXDe9qZl7kcGT0AXMZpZ9JSH11FO5mNYbRmFSFop354FdiMLbmvi36S5YH tLWg== X-Forwarded-Encrypted: i=1; AKwUvByzsoenZnbkDlszS7ArDHpO68FU5jIL1SU4J2iccju47QOBFczI9M3qpDL687PZku/U1VHcXli1hnCL@lists.linux.dev X-Gm-Message-State: AFuF++meXlJaRsApa21IELSP2h4IX44sM/v0ItIAJoh0O7pQB4KmDLUg jITaFQV7/8mE1BBKx7OjMqM2Osuq3DTgylRHTdmk9hQzuXguHVeUdnWwj5bRkC02tJ6171xUsly MLw== X-Received: from wmbb26.prod.google.com ([2002:a05:600c:589a:b0:49e:5ffd:edcc]) (user=elver job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:5493:b0:49b:8f18:714a with SMTP id 5b1f17b1804b1-49cf824a6c5mr440314875e9.12.1789057444629; Thu, 10 Sep 2026 09:24:04 -0700 (PDT) Date: Thu, 10 Sep 2026 16:21:41 +0000 In-Reply-To: <20260910162343.4092060-1-elver@google.com> Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260910162343.4092060-1-elver@google.com> X-Mailer: git-send-email 2.55.0.1003.g10538fe699-goog Message-ID: <20260910162343.4092060-9-elver@google.com> Subject: [PATCH RFC 08/10] KVM: Add guarded_by to members in struct kvm From: Marco Elver To: elver@google.com Cc: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Vitaly Kuznetsov , Kiryl Shutsemau , Rick Edgecombe , David Hildenbrand , kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Add __guarded_by annotations to a subset of members in struct kvm where the protecting locks reside in the same struct scope. Members protected by locks across nested or parent struct boundaries are omitted due to C lexical scoping limitations. No functional change intended. Signed-off-by: Marco Elver --- include/linux/kvm_host.h | 12 ++++++------ virt/kvm/eventfd.c | 4 ++-- virt/kvm/kvm_main.c | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 12f241304228..36edf0a59107 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -771,7 +771,7 @@ struct kvm { /* The two memslot sets - active and inactive (per address space) */ struct kvm_memslots __memslots[KVM_MAX_NR_ADDRESS_SPACES][2]; /* The current active memslot set for each address space */ - struct kvm_memslots __rcu *memslots[KVM_MAX_NR_ADDRESS_SPACES]; + struct kvm_memslots __rcu *memslots[KVM_MAX_NR_ADDRESS_SPACES] __guarded_by(&srcu, &slots_lock, &slots_arch_lock); struct xarray vcpu_array; DECLARE_BITMAP(vcpu_ids, KVM_MAX_VCPU_IDS); /* @@ -787,7 +787,7 @@ struct kvm { /* For management / invalidation of gfn_to_pfn_caches */ spinlock_t gpc_lock; - struct list_head gpc_list; + struct list_head gpc_list __guarded_by(&gpc_lock); /* * created_vcpus is protected by kvm->lock, and is incremented @@ -801,11 +801,11 @@ struct kvm { int last_boosted_vcpu; struct list_head vm_list; struct mutex lock; - struct kvm_io_bus __rcu *buses[KVM_NR_BUSES]; + struct kvm_io_bus __rcu *buses[KVM_NR_BUSES] __guarded_by(&srcu, &slots_lock); #ifdef CONFIG_HAVE_KVM_IRQCHIP struct { spinlock_t lock; - struct list_head items; + struct list_head items __guarded_by(&lock); /* resampler_list update side is protected by resampler_lock. */ struct list_head resampler_list; struct mutex resampler_lock; @@ -826,9 +826,9 @@ struct kvm { /* * Update side is protected by irq_lock. */ - struct kvm_irq_routing_table __rcu *irq_routing; + struct kvm_irq_routing_table __rcu *irq_routing __guarded_by(&irq_srcu, &irq_lock); - struct hlist_head irq_ack_notifier_list; + struct hlist_head irq_ack_notifier_list __guarded_by(&irq_srcu, &irq_lock); #endif struct mmu_notifier mmu_notifier; diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 6701390336f6..6051fec5ec90 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -1046,8 +1046,8 @@ void kvm_eventfd_init(struct kvm *kvm) { #ifdef CONFIG_HAVE_KVM_IRQCHIP - spin_lock_init(&kvm->irqfds.lock); - INIT_LIST_HEAD(&kvm->irqfds.items); + scoped_guard(spinlock_init, &kvm->irqfds.lock) + INIT_LIST_HEAD(&kvm->irqfds.items); INIT_LIST_HEAD(&kvm->irqfds.resampler_list); mutex_init(&kvm->irqfds.resampler_lock); #endif diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 2f22d5439d39..871acc3aebbd 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1111,6 +1111,7 @@ void __weak kvm_arch_create_vm_debugfs(struct kvm *kvm) /* Called only on cleanup and destruction paths when there are no users. */ static inline struct kvm_io_bus *kvm_get_bus_for_destruction(struct kvm *kvm, enum kvm_bus idx) + __context_unsafe(/* destruction */) { return rcu_dereference_protected(kvm->buses[idx], !refcount_read(&kvm->users_count)); @@ -1120,6 +1121,7 @@ static int kvm_enable_virtualization(void); static void kvm_disable_virtualization(void); static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) + __context_unsafe(/* constructor */) { struct kvm *kvm = kvm_arch_alloc_vm(); struct kvm_memslots *slots; @@ -1276,6 +1278,7 @@ static void kvm_destroy_devices(struct kvm *kvm) } static void kvm_destroy_vm(struct kvm *kvm) + __context_unsafe(/* destructor */) { int i; struct mm_struct *mm = kvm->mm; -- 2.55.0.1003.g10538fe699-goog