From nobody Sat Jun 13 02:07:31 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 28A0F37AA70; Mon, 11 May 2026 13:00:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778504411; cv=none; b=i0zqf67XT8qpM2tglJ/wCsUQvEDvhAv23mAQ4Tq9a4R12ie1oXZBwmrU+xoGbDGmsCVKYYkPoof7NC19ESpvdh+WiLquCr9x+REaXA+ooWaqDD1jlD//i/2pIOKAbcmRQR1mggKvUMjgtY7fH+UZZKa+dpSakE+k3+wuErL/ci0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778504411; c=relaxed/simple; bh=DNfsT5tNOfUZ0p6xIMCk+T2kDgbKKSOrdJjPNu3xcsg=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=UGoaOf9I4SotwgW9rxxzmdYDpHwkVfo7nZvoy2fB35kKJCpO/GlItbSvUnAowf51OQULCK/BzPmLBmSp+LtEBfJqEq0l/XIZwzl6IkqwMkqYA9ajo9tK/GhcqtAL7muiVl3o7CikYTINf4tPizMuBhk9VJ9cf30isDvGY3FiyXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LypSfoN2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=vYFobTas; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LypSfoN2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vYFobTas" Date: Mon, 11 May 2026 13:00:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1778504408; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sxc8KpLmi2dBaiAXv/wlyglwQ8FG8yQckpJxwOsbNDU=; b=LypSfoN2Vvd1qLlqeASQljigr3YXbzUf0cC6Zzvk7W9WehHBrRtnDqjIt3Smk1iYLXyggf wOiek+7+mEK08zqsWy1LuzhdhGGuPW1KX6DEJ0z54alEkvacdvUQFgRVDHLIAo5s5hSJRL CMFPAt5ev54FM9sjz6OeCH5PIp1S0pnkqLQoud/rjOL3zVWayzjcfj7JS5sdvn7a0uVORm tt8A89Em7U6g0D93K+2kNmbSAeOP6biZjgkDajqgoaSBS4OlyU6+eStfrh2hwtiy1HorUN shyvLD4COuNwfGaT33upgbSnIBvjeF+mnkA1gmWi9Ge8iL9I/vPDQ/51qZgZ0w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1778504408; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sxc8KpLmi2dBaiAXv/wlyglwQ8FG8yQckpJxwOsbNDU=; b=vYFobTasVC5w+jDOurr/M3EtTBp2L7qLNuTrB49ghSavw6h1/XOX6NIv+70b7NHXgtwbR/ sSrkYPTAlX35jRBA== From: "tip-bot2 for Mark Rutland" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/urgent] genirq/chip: Don't call add_interrupt_randomness() for NMIs Cc: Ada Couprie Diaz , Mark Rutland , Thomas Gleixner , Jinjie Ruan , Marc Zyngier , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20260507110518.3128248-1-mark.rutland@arm.com> References: <20260507110518.3128248-1-mark.rutland@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177850440637.188840.15739381127914650487.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the irq/urgent branch of tip: Commit-ID: 512718bbc51b851140380b7068ec7365bd039cba Gitweb: https://git.kernel.org/tip/512718bbc51b851140380b7068ec7365b= d039cba Author: Mark Rutland AuthorDate: Thu, 07 May 2026 12:05:18 +01:00 Committer: Thomas Gleixner CommitterDate: Mon, 11 May 2026 14:56:04 +02:00 genirq/chip: Don't call add_interrupt_randomness() for NMIs Recently handle_percpu_devid_irq() was changed to call add_interrupt_randomness(). This introduced a potential deadlock when handle_percpu_devid_irq() is used to handle an NMI, which can be detected with lockdep, e.g. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D WARNING: inconsistent lock state 7.1.0-rc2-pnmi #465 Not tainted -------------------------------- inconsistent {INITIAL USE} -> {IN-NMI} usage. perf/695 [HC1[1]:SC0[0]:HE0:SE1] takes: ffff00837dfd3a18 (&base->lock){-.-.}-{2:2}, at: lock_timer_base+0x6c/0x= ac {INITIAL USE} state was registered at: _raw_spin_lock_irqsave+0x68/0xb0 lock_timer_base+0x6c/0xac __mod_timer+0x100/0x32c add_timer_global+0x2c/0x40 __queue_delayed_work+0xf0/0x140 queue_delayed_work_on+0x134/0x138 mem_cgroup_css_online+0x30c/0x310 online_css+0x34/0x10c cgroup_init_subsys+0x158/0x1c8 cgroup_init+0x440/0x524 start_kernel+0x888/0x998 other info that might help us debug this: Possible unsafe locking scenario: CPU0 ---- lock(&base->lock); lock(&base->lock); *** DEADLOCK *** Call trace: _raw_spin_lock_irqsave+0x68/0xb0 lock_timer_base+0x6c/0xac add_timer_on+0x78/0x16c add_interrupt_randomness+0x124/0x134 handle_percpu_devid_irq+0xd4/0x16c handle_irq_desc+0x40/0x58 generic_handle_domain_nmi+0x28/0x50 __gic_handle_nmi.isra.0+0x4c/0xa0 gic_handle_irq+0x38/0x2bc call_on_irq_stack+0x30/0x48 do_interrupt_handler+0x80/0x98 el1_interrupt+0x90/0xac el1h_64_irq_handler+0x18/0x24 el1h_64_irq+0x80/0x84 [...] During review, Thomas pointed out it wouldn't be safe for handle_percpu_devid_irq() to call add_interrupt_randomness() if it was used to handle NMIs: https://lore.kernel.org/lkml/87bjgik042.ffs@tglx/ ... but evidently people missed that handle_percpu_devid_irq() *is* used for NMIs. While it might seem that NMIs should be handled with a separate handle_percpu_devid_nmi() function, for various structural reasons this was impractical, and handle_percpu_devid_irq() has been expected to be used for NMIs since commits: 21bbbc50f398f ("irqchip/gic-v3: Switch high priority PPIs over to handle_= percpu_devid_irq()") 5ff78c8de9d83 ("genirq: Kill handle_percpu_devid_fasteoi_nmi()") Taking the above into account, avoid the deadlock by not calling add_interrupt_randomness() when handle_percpu_devid_irq() is called in an NMI context. This is consistent with other NNI handling flows, which do not call add_interrupt_randomness(). At the same time, update the kernel-doc comment to make it clear that handle_percpu_devid_irq() can be called in NMI context. The rest of handle_percpu_devid_irq() is currently NMI safe and doesn't need to change. Fixes: fd7400cfcbaa ("genirq/chip: Invoke add_interrupt_randomness() in han= dle_percpu_devid_irq()") Reported-by: Ada Couprie Diaz Signed-off-by: Mark Rutland Signed-off-by: Thomas Gleixner Reviewed-by: Jinjie Ruan Reviewed-by: Marc Zyngier Link: https://patch.msgid.link/20260507110518.3128248-1-mark.rutland@arm.com --- kernel/irq/chip.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/irq/chip.c b/kernel/irq/chip.c index 6c9b1dc..b635e3c 100644 --- a/kernel/irq/chip.c +++ b/kernel/irq/chip.c @@ -14,6 +14,7 @@ #include #include #include +#include #include =20 #include @@ -893,7 +894,10 @@ void handle_percpu_irq(struct irq_desc *desc) * * action->percpu_dev_id is a pointer to percpu variables which * contain the real device id for the cpu on which this handler is - * called + * called. + * + * May be used for NMI interrupt lines, and so may be called in IRQ or NMI + * context. */ void handle_percpu_devid_irq(struct irq_desc *desc) { @@ -930,7 +934,8 @@ void handle_percpu_devid_irq(struct irq_desc *desc) enabled ? " and unmasked" : "", irq, cpu); } =20 - add_interrupt_randomness(irq); + if (!in_nmi()) + add_interrupt_randomness(irq); =20 if (chip->irq_eoi) chip->irq_eoi(&desc->irq_data);