From: Sean Christopherson <seanjc@google.com>
To: Yosry Ahmed <yosry.ahmed@linux.dev>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Michael Larabel <Michael@michaellarabel.com>,
Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH v2] KVM: SVM: Set/clear SRSO's BP_SPEC_REDUCE on 0 <=> 1 VM count transitions
Date: Tue, 6 May 2025 07:16:06 -0700 [thread overview]
Message-ID: <aBoZpr2HNPysavjd@google.com> (raw)
In-Reply-To: <aBnbBL8Db0rHXxFX@google.com>
On Tue, May 06, 2025, Yosry Ahmed wrote:
> On Mon, May 05, 2025 at 11:03:00AM -0700, Sean Christopherson wrote:
> > +static void svm_srso_vm_destroy(void)
> > +{
> > + if (!cpu_feature_enabled(X86_FEATURE_SRSO_BP_SPEC_REDUCE))
> > + return;
> > +
> > + if (atomic_dec_return(&srso_nr_vms))
> > + return;
> > +
> > + guard(spinlock)(&srso_lock);
> > +
> > + /*
> > + * Verify a new VM didn't come along, acquire the lock, and increment
> > + * the count before this task acquired the lock.
> > + */
> > + if (atomic_read(&srso_nr_vms))
> > + return;
> > +
> > + on_each_cpu(svm_srso_clear_bp_spec_reduce, NULL, 1);
>
> Just a passing-by comment. I get worried about sending IPIs while
> holding a spinlock because if someone ever tries to hold that spinlock
> with IRQs disabled, it may cause a deadlock.
>
> This is not the case for this lock, but it's not obvious (at least to
> me) that holding it in a different code path that doesn't send IPIs with
> IRQs disabled could cause a problem.
>
> You could add a comment, convert it to a mutex to make this scenario
> impossible,
Using a mutex doesn't make deadlock impossible, it's still perfectly legal to
disable IRQs while holding a mutex.
Similarly, I don't want to add a comment, because there is absolutely nothing
special/unique about this situation/lock. E.g. KVM has tens of calls to
smp_call_function_many_cond() while holding a spinlock equivalent, in the form
of kvm_make_all_cpus_request() while holding mmu_lock.
smp_call_function_many_cond() already asserts that IRQs are disabled, so I have
zero concerns about this flow breaking in the future.
> or dismiss my comment as being too paranoid/ridiculous :)
I wouldn't say your thought process is too paranoid; when writing the code, I had
to pause and think to remember whether or not using on_each_cpu() while holding a
spinlock is allowed. But I do think the conclusion is wrong :-)
next prev parent reply other threads:[~2025-05-06 14:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 18:03 [PATCH v2] KVM: SVM: Set/clear SRSO's BP_SPEC_REDUCE on 0 <=> 1 VM count transitions Sean Christopherson
2025-05-06 9:48 ` Yosry Ahmed
2025-05-06 14:16 ` Sean Christopherson [this message]
2025-05-06 14:29 ` Yosry Ahmed
2025-05-06 15:57 ` Sean Christopherson
2025-05-07 7:05 ` Yosry Ahmed
2025-05-07 13:19 ` Sean Christopherson
2025-05-06 14:22 ` Borislav Petkov
2025-05-08 23:04 ` Sean Christopherson
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=aBoZpr2HNPysavjd@google.com \
--to=seanjc@google.com \
--cc=Michael@michaellarabel.com \
--cc=bp@alien8.de \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=yosry.ahmed@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox