From: David Woodhouse <dwmw2@infradead.org>
To: Yao Yuan <yaoyuan@linux.alibaba.com>
Cc: Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
Joey Gouly <joey.gouly@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Sascha Bischoff <Sascha.Bischoff@arm.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Jonathan Cameron <jic23@kernel.org>,
Eric Auger <eric.auger@redhat.com>,
Raghavendra Rao Ananta <rananta@google.com>,
Maxim Levitsky <mlevitsk@redhat.com>,
linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev,
kvm@vger.kernel.org
Subject: Re: [RFC PATCH] KVM: arm64: vgic: Skip vCPU trylock for pre-init register access
Date: Mon, 11 May 2026 12:52:17 +0100 [thread overview]
Message-ID: <a2e61e574cf2eba24d41834abbc5e466bbcbe1e7.camel@infradead.org> (raw)
In-Reply-To: <3ijnoudux4iyddpd25yr53s2zqrslplixjqfod225ix43y4z4a@heoklijpq45f>
[-- Attachment #1: Type: text/plain, Size: 1454 bytes --]
On Mon, 2026-05-11 at 19:03 +0800, Yao Yuan wrote:
>
> > + /*
> > + * If the VGIC becomes initialized between the above check and taking
> > + * config_lock, drop config_lock to lock the VCPUS.
> > + */
> > + if (vgic_initialized(dev->kvm) && !vcpus_locked) {
> > + mutex_unlock(&dev->kvm->arch.config_lock);
> > + if (kvm_trylock_all_vcpus(dev->kvm)) {
> > + mutex_unlock(&dev->kvm->lock);
> > + return -EBUSY;
> > + }
> > + mutex_lock(&dev->kvm->arch.config_lock);
> > + vcpus_locked = true;
>
> Question: Why not do vgic_initialized(dev->kvm) and
> reg_allowed_pre_init(attr) checking after take config_lock,
> and depends on the checking result to decide trylocak all
> vcpus or not ?
Yeah... I didn't like that either.
If we attempt to take the vCPU locks while *holding* config_lock, that
gives us a classic ABBA deadlock with the code paths that hold the vCPU
locks first.
Well, maybe it doesn't because we'd only be doing a *trylock*... but
lockdep wouldn't know that and it's fugly as hell. So I settled on the
above.
The long term fix, as I noted, is to kill kvm_trylock_all_vcpus() with
fire in *all* cases, not just the !vgic_initialized() case. On x86 we'd
do this with something like KVM_REQ_MCLOCK_INPROGRESS to kick vCPUs out
of guest mode to prevent concurrent access. Which isn't my favourite
code *either* but at least it works without imposing the awfulness on
the userspace API.
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
prev parent reply other threads:[~2026-05-11 11:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-10 22:11 [RFC PATCH] KVM: arm64: vgic: Skip vCPU trylock for pre-init register access David Woodhouse
2026-05-11 11:03 ` Yao Yuan
2026-05-11 11:52 ` David Woodhouse [this message]
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=a2e61e574cf2eba24d41834abbc5e466bbcbe1e7.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=Sascha.Bischoff@arm.com \
--cc=catalin.marinas@arm.com \
--cc=eric.auger@redhat.com \
--cc=jic23@kernel.org \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=mlevitsk@redhat.com \
--cc=oupton@kernel.org \
--cc=pbonzini@redhat.com \
--cc=rananta@google.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yaoyuan@linux.alibaba.com \
--cc=yuzenghui@huawei.com \
/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