All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marco Elver" <elver@google.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH RFC 09/10] KVM: x86: Add guarded_by annotations for kvm_arch, kvm_hv, and ioapic
Date: Thu, 10 Sep 2026 16:46:11 +0000	[thread overview]
Message-ID: <20260910164611.8A61E1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260910162343.4092060-10-elver@google.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Low] Mixing goto-based error handling and scope-based cleanup in the same function.

Pre-existing issues:
- [High] Lockless traversal of the global vm_list can race with VM creation and destruction.
--

commit b3fea266e46bae40374748855ac1c207f8a8f74f
Author: Marco Elver <elver@google.com>

    KVM: x86: Add guarded_by annotations for kvm_arch, kvm_hv, and ioapic
    
    Add __guarded_by annotations to a subset of fields across x86 state
    (struct kvm_hv, struct kvm_arch, and struct kvm_ioapic) where the
    protecting locks reside in the same struct scope. Mark deliberate
    lockless updates with data_race().

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index de7c6eb1a64f5..af03911f0c4fa 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -9813,8 +9813,8 @@ int kvm_arch_enable_virtualization_cpu(void)
>  			 * you may have some problem.  Solving this issue is
>  			 * left as an exercise to the reader.
>  			 */
> -			kvm->arch.last_tsc_nsec = 0;
> -			kvm->arch.last_tsc_write = 0;
> +			data_race(kvm->arch.last_tsc_nsec = 0);
> +			data_race(kvm->arch.last_tsc_write = 0);

[Severity: High]
This isn't a bug introduced by this patch, but does this lockless traversal of
the global vm_list in kvm_arch_enable_virtualization_cpu() race with VM
creation and destruction?

If a user concurrently creates a VM (kvm_create_vm) or destroys a VM
(kvm_destroy_vm) while CPU hotplug is running via kvm_online_cpu(), the
list_add() or list_del() executed under kvm_lock will race with this traversal.
This can potentially lead to list corruption, use-after-free, or infinite
loops.

While this patch masks static analyzer warnings by adding data_race()
annotations here, shouldn't the broader list traversal safety be addressed?

[ ... ]

> @@ -9927,8 +9927,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>  	kvm->arch.enable_pmu = enable_pmu && !kvm->arch.has_protected_pmu;
>  
>  #if IS_ENABLED(CONFIG_HYPERV)
> -	spin_lock_init(&kvm->arch.hv_root_tdp_lock);
> -	kvm->arch.hv_root_tdp = INVALID_PAGE;
> +	scoped_guard(spinlock_init, &kvm->arch.hv_root_tdp_lock)
> +		kvm->arch.hv_root_tdp = INVALID_PAGE;

[Severity: Low]
Does introducing scoped_guard() here mix scope-based cleanup with goto-based
error handling in the same function?

kvm_arch_init_vm() already relies on goto labels (e.g., goto out_uninit_mmu,
goto out_cleanup_page_track) for its error paths. According to the subsystem
coding standards, a function must exclusively use either goto-based cleanup or
scope-based cleanup helpers, but never mix both to prevent confusing ownership
semantics and lifecycle bugs.

Could this be kept as goto-based, or should the entire function be converted
to scope-based cleanup?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260910162343.4092060-1-elver@google.com?part=9

  reply	other threads:[~2026-09-10 16:46 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 16:21 [PATCH RFC 00/10] KVM: Enable Clang Context Analysis Marco Elver
2026-09-10 16:21 ` [PATCH RFC 01/10] KVM: x86/pmu: Acquire SRCU in pmc_is_event_allowed() to protect filter lookup Marco Elver
2026-09-10 16:46   ` Sean Christopherson
2026-09-10 16:21 ` [PATCH RFC 02/10] KVM: Allow reading memslots while holding slots_arch_lock Marco Elver
2026-09-10 16:30   ` Sean Christopherson
2026-09-10 17:11     ` Marco Elver
2026-09-10 17:52       ` Sean Christopherson
2026-09-10 19:05         ` Marco Elver
2026-09-10 16:39   ` sashiko-bot
2026-09-10 16:21 ` [PATCH RFC 03/10] KVM: guest_memfd: Avoid conditional mmu_lock acquisition Marco Elver
2026-09-10 16:42   ` sashiko-bot
2026-09-10 16:21 ` [PATCH RFC 04/10] KVM: Refactor kvm_handle_hva_range() to avoid conditional mmu_lock Marco Elver
2026-09-10 16:38   ` Sean Christopherson
2026-09-10 16:21 ` [PATCH RFC 05/10] KVM: Refactor kvm_handle_gfn_range() " Marco Elver
2026-09-10 16:21 ` [PATCH RFC 06/10] KVM: Add basic lock context annotations Marco Elver
2026-09-10 16:34   ` sashiko-bot
2026-09-10 16:53     ` Marco Elver
2026-09-10 16:21 ` [PATCH RFC 07/10] KVM: x86: " Marco Elver
2026-09-10 16:21 ` [PATCH RFC 08/10] KVM: Add guarded_by to members in struct kvm Marco Elver
2026-09-10 16:21 ` [PATCH RFC 09/10] KVM: x86: Add guarded_by annotations for kvm_arch, kvm_hv, and ioapic Marco Elver
2026-09-10 16:46   ` sashiko-bot [this message]
2026-09-10 16:21 ` [PATCH RFC 10/10] KVM: x86: Enable CONTEXT_ANALYSIS with opt-outs Marco Elver
2026-09-10 16:55 ` [PATCH RFC 00/10] KVM: Enable Clang Context Analysis Sean Christopherson
2026-09-10 19:19   ` Marco Elver

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=20260910164611.8A61E1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=elver@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.