From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B00C630149E for ; Wed, 5 Nov 2025 10:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762338487; cv=none; b=a6JtIVBBhpw77JBNLC0TcFzSHH7rEysDCT8op8w4vUgf9lbjWdVX75EU/OfaiVYbHaz2znoVOpTfei34wKHGcaQt5mIlq7+z4HVnOA5Q2eijhM0rcGVVYvM9Sa4A8XYPlg6bcUjbq7TEJO7WQvRiaRdVoSzubus4Y3vi+55wYsE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762338487; c=relaxed/simple; bh=C45/cuTSmD46uS37xO2m8wTaJvEVZMK1MdEsT9dCOR4=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=LdRwAY8KZD320FJEvSKsQxiYvWvJIcX8jTIB5scMKNC5CeLndJb5msHI8iNEyez5twB412yZPCfps6gQ1jYgdMLVbJ4uMXXYkVyH0U7E8h7PU8BjzAoDzUH5N1Nxu5/uxUsWFAwxToEdJS5ZoRvCtdbGLI4fZj2L+J+9A3aNS8A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Am1Dheis; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Am1Dheis" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8639AC116D0; Wed, 5 Nov 2025 10:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1762338487; bh=C45/cuTSmD46uS37xO2m8wTaJvEVZMK1MdEsT9dCOR4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Am1DheisxzMZNpkiyktmApCvZFsg2BfS02Jb8wbvkyJ/VfpWqh7aiLpDYivsK1TGB qkmXSsK1mzPNcga9kT9InCVW/nQGTkHh6KIxGyv+gYE81KNatueOBOhF2MIo0LrZGa Wx6EWEod0oCA+52lBh6wZ++o59UcFzGPHhaPJ/SvwVlgdH/kwZ5OJnx3t1JrRgqkpE bgW7bsH99rvXl56oqjoYoLf4GtzuZyZ8cfeX+P7ILcDCiUo7TQ8xfzcyRgkEaiGmIJ zs8NLCvRpCAqZ0cgmtMWqQM59d9VVQa2LycUvXpXlVtF7Tt6Iw0m7Q6oqhnFrlRl0H btRwceglc8oPg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1vGakH-00000002Yp1-0smb; Wed, 05 Nov 2025 10:28:05 +0000 Date: Wed, 05 Nov 2025 10:28:04 +0000 Message-ID: <86cy5wvknf.wl-maz@kernel.org> From: Marc Zyngier To: Zenghui Yu Cc: Oliver Upton , , Joey Gouly , Suzuki K Poulose , Ben Horgan Subject: Re: [PATCH v2 6/6] KVM: arm64: vgic-v3: Indicate vgic_put_irq() may take LPI xarray lock In-Reply-To: References: <20250905100531.282980-1-oliver.upton@linux.dev> <20250905100531.282980-7-oliver.upton@linux.dev> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: yuzenghui@huawei.com, oliver.upton@linux.dev, kvmarm@lists.linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, ben.horgan@arm.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Wed, 05 Nov 2025 09:37:10 +0000, Zenghui Yu wrote: > > Hi Oliver, > > On 2025/9/5 18:05, Oliver Upton wrote: > > The release path on LPIs is quite rare, meaning it can be difficult to > > find lock ordering bugs on the LPI xarray's spinlock. Tell lockdep that > > vgic_put_irq() might acquire the xa_lock to make unsafe patterns more > > obvious. > > > > Reviewed-by: Marc Zyngier > > Signed-off-by: Oliver Upton > > --- > > arch/arm64/kvm/vgic/vgic.c | 3 +++ > > 1 file changed, 3 insertions(+) > > > > diff --git a/arch/arm64/kvm/vgic/vgic.c b/arch/arm64/kvm/vgic/vgic.c > > index a21b482844ce..3b247041a130 100644 > > --- a/arch/arm64/kvm/vgic/vgic.c > > +++ b/arch/arm64/kvm/vgic/vgic.c > > @@ -142,6 +142,9 @@ void vgic_put_irq(struct kvm *kvm, struct vgic_irq *irq) > > { > > struct vgic_dist *dist = &kvm->arch.vgic; > > > > + if (irq->intid >= VGIC_MIN_LPI) > > + might_lock(&dist->lpi_xa.xa_lock); > > I got the following splat on a lockdep kernel. The reproducing step can > be easily inferred from the backtrace (i.e., starting a guest with an > assigned device). > > ================================ > WARNING: inconsistent lock state > 6.18.0-rc4-00019-g284922f4c563-dirty #2390 Not tainted > -------------------------------- > inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. > swapper/10/0 [HC1[1]:SC0[0]:HE0:SE1] takes: > ffff8000a504de18 (&xa->xa_lock#19){?.+.}-{3:3}, at: vgic_put_irq+0x28/0x110 > {HARDIRQ-ON-W} state was registered at: > lock_acquire+0x1c8/0x354 > _raw_spin_lock+0x48/0x60 > vgic_add_lpi.part.0+0x70/0x2f8 > vgic_its_cmd_handle_mapi.isra.0+0x398/0x418 > vgic_its_process_commands.part.0+0x4d4/0xfa0 > vgic_mmio_write_its_cwriter+0x80/0xa4 > dispatch_mmio_write+0xd0/0x128 > __kvm_io_bus_write+0xb4/0xe8 > kvm_io_bus_write+0x58/0x98 > io_mem_abort+0xe8/0x3f0 > kvm_handle_guest_abort+0x4d0/0x1414 > handle_exit+0x6c/0x1c4 > kvm_arch_vcpu_ioctl_run+0x678/0xbfc > kvm_vcpu_ioctl+0x1ac/0xb24 > __arm64_sys_ioctl+0xac/0x104 > invoke_syscall+0x48/0x10c > el0_svc_common.constprop.0+0x40/0xe0 > do_el0_svc+0x1c/0x28 > el0_svc+0x50/0x2c0 > el0t_64_sync_handler+0xa0/0xe4 > el0t_64_sync+0x198/0x19c > irq event stamp: 5415534 > hardirqs last enabled at (5415533): [] > default_idle_call+0x7c/0x138 > hardirqs last disabled at (5415534): [] > enter_from_kernel_mode+0x10/0x3c > softirqs last enabled at (5415516): [] > handle_softirqs+0x4ac/0x4c4 > softirqs last disabled at (5415511): [] > __do_softirq+0x14/0x20 > > other info that might help us debug this: > Possible unsafe locking scenario: > > CPU0 > ---- > lock(&xa->xa_lock#19); > > lock(&xa->xa_lock#19); > > *** DEADLOCK *** > > 2 locks held by swapper/10/0: > #0: ffff00280db646a0 (&ctx->wqh#2){-...}-{3:3}, at: > eventfd_signal_mask+0x38/0xc0 > #1: ffff8000a504e480 (&kvm->irq_srcu){.?.+}-{0:0}, at: > irqfd_wakeup+0x88/0x2ac > > stack backtrace: > CPU: 10 UID: 0 PID: 0 Comm: swapper/10 Kdump: loaded Not tainted > 6.18.0-rc4-00019-g284922f4c563-dirty #2390 PREEMPT > Call trace: > show_stack+0x18/0x24 (C) > dump_stack_lvl+0x90/0xd0 > dump_stack+0x18/0x24 > print_usage_bug.part.0+0x29c/0x358 > mark_lock+0x6c0/0x960 > __lock_acquire+0xd4c/0x20fc > lock_acquire+0x1c8/0x354 > vgic_put_irq+0x54/0x110 > vgic_its_inject_cached_translation+0x178/0x25c > kvm_arch_set_irq_inatomic+0xac/0x124 Right. This might_lock() is gross, and clearly doesn't do the right thing outside of direct injection of LPIs. I think we should drop it, but we should ensure that lpi_xa.xa_lock is never taken in interrupt context. Oliver, what do you think? M. -- Without deviation from the norm, progress is not possible.