From nobody Sat Sep 26 08:39:16 2026 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EFD031327F for ; Thu, 3 Sep 2026 01:54:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400477; cv=none; b=bw6OdPt+3ZVTJxKqA73KtpZyIfX+0VB+QET8KaGDcpeUmcIo+TmEtwUhyQK8vx6FMzRfW63chVtLeLec0g/MBsrrzNwFqv/N/u6jgmQ6W6FYjTYkZfHh16sqHYHuZFOYNImxUgVnfPferBYs7MaSWXQksZxqLeZglLFF3F90DZA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400477; c=relaxed/simple; bh=bE2KCEJdrrJw55h1Di5C0KV9/9GsaRt1ZOW67UORtRM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Rwk61PoxSwOW8JC2JTQsnGo6I3EFX1UMFfIdRhCjJVNoQHiCffAoUQtxAdfdgpGQMzpPCQPbupMqBlMq2UqoWoZQlhxl2Hq7XCpUgds3MxchLoqMiupi6w1fJyMkTnUstgbkKwRTx5L5YIFFmnfXxlvfE0h2iHWU4P5uJJhACO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=OhAv1aLe; arc=none smtp.client-ip=209.85.216.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OhAv1aLe" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-38ecc48b3c2so2885634a91.1 for ; Wed, 02 Sep 2026 18:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788400475; x=1789005275; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=68bkm8EEb6YqFfA3bh03KzDOlaOODwR3iq85SSUanRo=; b=OhAv1aLe8PCFn09LrtNSiVfys/A4FFF5KyhM2zTBoKiJU3//yzo7eFok+7E5yDWKBr cre9uDYjTO7rtzQGQLN04smhXmeieWAHPTT4tmzHDRSWdtLaJuTc0RSve/KaVgzmaBb8 mmfJfw1wGzyR+C3DM74Iy25irE3zRgOiHr6XodSHJVMccgvGtaE/5yOK1VgEDb1y7z69 XKRUxLxcOAG2LgDwjQXebwhk1gXFyG3p22TZIG9+o1ycP7YhnayyKHOh0cNSxHsU+0yF /Mn+Xslsv2t0Gyh9VtMy2fuu1x4HDseH5OQ54pAbAu6Oz6hgLw4lpBWOMCx7huuRX6M6 1ptQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788400475; x=1789005275; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=68bkm8EEb6YqFfA3bh03KzDOlaOODwR3iq85SSUanRo=; b=RN1xeh2XZ7TOshWG09qjayCyDAVlQxkRvXGdVRWz6PJ/6jsztfWTqpV/hqNu9cv3Oe sjMWJE7Yx9JQ6GV5Ix6cfVrY4eTkBf2VN/1sHu1240ujeqx1WvWAgkwIU1B26UcZ9ltD 4q2tIFPOrgSk+bc6R/fisIvPWANbT5F5LGN5UNZ6Um0le/vqSlXomJFmAGTW10a0/kBC Es9B9KBka9Ypj0bjIg90k4BgkStG5/Ih4TJiOfBuuXAEgIMkN9lp+u20CUZzR6Q3ROam 4pQHEXQRqDcOork+fm1W2FF3qnWpU+OyKtzcdXvfkOMw7ZrMWv9UW7FX9xZRtT1Rl1rN SMOw== X-Forwarded-Encrypted: i=1; AKwUvBwjzuO9jSIctUpF7O2T7AMpjO6eldi9xpHeK/5SVfC5NNUu9PanrG+x1pSru36d1lAi2aHunMHl6Mrhobk=@vger.kernel.org X-Gm-Message-State: AFuF++kVETyF7FyZ3ZrQ8eFkXfcb+Ccouj1wurloEDlUBMmiTD0MJKhj 9ShupZpNF4mPddN+NF8AipVQJxN7Uc/6Ial7jxgYnVyASEjOk+SviAn15jdxCcPO36tSbeqUX8D 0LTGj1i4mow== X-Received: from dyaz1-n1.prod.google.com ([2002:a05:693c:6381:10b0:328:321b:bc79]) (user=mrungta job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:da8f:b0:398:c8ef:3644 with SMTP id 98e67ed59e1d1-39aee156f4amr13369746a91.15.1788400475319; Wed, 02 Sep 2026 18:54:35 -0700 (PDT) Date: Wed, 02 Sep 2026 18:54:18 -0700 In-Reply-To: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> X-Developer-Key: i=mrungta@google.com; a=ed25519; pk=2Bjwbv/ibL10QnyvK9G7DoKpffXy7z6+M4NawEYgYDI= X-Developer-Signature: v=1; a=ed25519-sha256; t=1788400471; l=3610; i=mrungta@google.com; s=20260212; h=from:subject:message-id; bh=bE2KCEJdrrJw55h1Di5C0KV9/9GsaRt1ZOW67UORtRM=; b=dha/+VPi5wuM7UdPO/1XF9HZSmAR/XqpDTHcJIxBqJzhfyhT19FY80yrKQ+LJzW/o6ROI7Hlg PHNzsL4pmTmD9r5wgrNEtWnXGHm5j9qgAy967G/Z8qtZfDequtawel/ X-Mailer: b4 0.14.3 Message-ID: <20260902-qcom-wdt-nmi-series-v3-1-f3999362a9ea@google.com> Subject: [PATCH v3 1/5] genirq: Synchronize in-flight handlers during NMI teardown From: Mayank Rungta To: Wim Van Sebroeck , Guenter Roeck , Thomas Gleixner , Radu Rendec Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, "Kirill A. Shutemov" , Douglas Anderson , Mayank Rungta Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When freeing an interrupt requested via request_nmi(), __cleanup_nmi() currently tears down the NMI and frees the irqaction structure without waiting for in-flight instances of the handler on other CPUs to complete, which can lead to use-after-free conditions on module unload. Because NMIs cannot acquire desc->lock or set IRQD_IRQ_INPROGRESS without risking deadlocks, synchronizing in-flight NMIs on other CPUs during teardown (__synchronize_hardirq) relies on querying the hardware controller state via __irq_get_irqchip_state(IRQCHIP_STATE_ACTIVE). Enforce that any interrupt controller claiming NMI support via IRQCHIP_SUPPORTS_NMI must implement ->irq_get_irqchip_state(). In __cleanup_nmi(), serialize teardown under desc->request_mutex, shut down the line, call __synchronize_hardirq(desc, true) while keeping desc->action valid to avoid racing with lockless in-flight handlers, and only then clear desc->action, tear down the NMI configuration, deactivate the interrupt domain, and update proc status before freeing the action structure. Also add a WARN(in_interrupt()) check in free_nmi() matching __free_irq() to prevent freeing NMIs from atomic contexts since synchronization and resource cleanup can sleep and spin. Assisted-by: Antigravity:gemini Signed-off-by: Mayank Rungta --- kernel/irq/manage.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 2fbff2618a1e..a9973b61163a 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1379,6 +1379,14 @@ static bool irq_supports_nmi(struct irq_desc *desc) if (d->chip->irq_bus_lock || d->chip->irq_bus_sync_unlock) return false; =20 + /* + * NMIs cannot set IRQD_IRQ_INPROGRESS because they cannot acquire + * spinlocks. Synchronous disable and teardown require querying the + * hardware state via ->irq_get_irqchip_state(). + */ + if (!d->chip->irq_get_irqchip_state) + return false; + return d->chip->flags & IRQCHIP_SUPPORTS_NMI; } =20 @@ -2034,11 +2042,20 @@ static const void *__cleanup_nmi(unsigned int irq, = struct irq_desc *desc) struct irqaction *action =3D NULL; const char *devname =3D NULL; =20 + guard(mutex)(&desc->request_mutex); + scoped_guard(raw_spinlock_irqsave, &desc->lock) { - irq_nmi_teardown(desc); + irq_settings_clr_disable_unlazy(desc); + irq_shutdown(desc); + } =20 - desc->istate &=3D ~IRQS_NMI; + /* + * Ensure all in-flight NMI handlers on other CPUs complete before + * clearing desc->action or tearing down NMI state. + */ + __synchronize_hardirq(desc, true); =20 + scoped_guard(raw_spinlock_irqsave, &desc->lock) { if (!WARN_ON(desc->action =3D=3D NULL)) { action =3D desc->action; irq_pm_remove_action(desc, action); @@ -2046,12 +2063,12 @@ static const void *__cleanup_nmi(unsigned int irq, = struct irq_desc *desc) } desc->action =3D NULL; =20 - irq_settings_clr_disable_unlazy(desc); - irq_shutdown_and_deactivate(desc); + irq_nmi_teardown(desc); + desc->istate &=3D ~IRQS_NMI; + irq_domain_deactivate_irq(&desc->irq_data); + irq_proc_update_valid(desc); } =20 - irq_proc_update_valid(desc); - if (action) unregister_handler_proc(irq, action); kfree(action); @@ -2068,6 +2085,8 @@ const void *free_nmi(unsigned int irq, void *dev_id) { struct irq_desc *desc =3D irq_to_desc(irq); =20 + WARN(in_interrupt(), "Trying to free NMI %d from IRQ context!\n", irq); + if (!desc || WARN_ON(!irq_is_nmi(desc))) return NULL; =20 --=20 2.55.0.970.g62bdec98f9-goog From nobody Sat Sep 26 08:39:16 2026 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0088A3242BD for ; Thu, 3 Sep 2026 01:54:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.69 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400479; cv=none; b=lx28OSTa6IKcPnFaLvGOkP6XlYlSyI/ftFoM4zOvxy7n6JGM+f/Ke2DhSEY7PNfnrJPQN5Ol+SEoZRZJYOv4b+vj/1Q4IxJGMJ2saTRflCakOjJsziaNm2WMF4R33j4u5YHdYa60aREP89Z808gTkhq3CltBrne4HKRbwMoe4hg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400479; c=relaxed/simple; bh=wedRPiAO/DhYjzS65XL5l3RIbBJTHI5WnzKxvRx2w6M=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aed2NgHyjt6RptBAWiq2N9ScErLxG04yvmbLZq/+iV7qWZ4+RrNNmsT7HKYxeLGJx5jxvAtK9uCKKrljsGbZTNf+17HcGCkR1tZ7UWnKAYIwtWfCJCpedutuvNDercmXTpcGOYu3V7Sv0c9pg2Pi4ywdObHpCl90JtsPctjAUME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Rr7trrTp; arc=none smtp.client-ip=209.85.216.69 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Rr7trrTp" Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-398d292eac1so3643484a91.1 for ; Wed, 02 Sep 2026 18:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788400477; x=1789005277; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=0gERcKiJvkri4DmMi/VqLqHTF/JjRCW5D7m7rLo+8Tk=; b=Rr7trrTpEa5AALTc0Y64Q1swCFPhDAt+kwgufDkpkQKv4IQdBr8u8fdS5p153h6CsY wLySNri11D2XbKC0436e53m74JS3yAiq8M6QnICh4BCFGwAq3BIBf16ySxGSdNf45ed/ ZX6THRldnyhhIRAl8a73mxpHP529aqqhBHlmvI98Ye/UbIL5pqxlKG/JJwxiNy13g3fM iJkR8v7wV7yOp6j0QItNtlhKZetXIHpUQjG7tdqpb+iaEqQ2KFPoCK2SGdOHolwZ5CYK vvRtsFmBllThmsWuqXB1ZZeXGXFZcckxovAEHL3ewMBFHuaIQe3CMaBKvwTowLJOdLFD wn0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788400477; x=1789005277; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=0gERcKiJvkri4DmMi/VqLqHTF/JjRCW5D7m7rLo+8Tk=; b=hoH971v0Rsm5ZPv7dVboy2gHKKAorGIWSI1zLJiG3ZjDV6BpdRuGyPSz/EDeCc95A+ BVxTjJTJ3KhIMBCJA0BypQlH75EnL1VHSkOoOUjej1yy0TCjCmkbH/A29pRFuZ1IlmIK 92Qo+VcsJE/m1wmzCsMcD6s558Jh+XRut4Swq188dham/KkfEiSnSWTLTTtgoSH76Z88 Q8PtvucdV9oVVika7wVhPDn86RnfftrqxLAW6o73Iqxlf9rsSXDT3xxV4xZ0TsFdlipN 42jINO7JpfOjaZ4BSChLCXiCDSYnR3cucdxJMoGKTvvHZepDA02JRbWWLZH9rOuJfflL nxOg== X-Forwarded-Encrypted: i=1; AKwUvBzDDTmU8khXy0XFZ6dnL4scp67ht1Si6rczudKHSHV8P4pDspCdw5T9I5bo9eWf7LumAzC+9pxAFSqwCCg=@vger.kernel.org X-Gm-Message-State: AFuF++mvS7H6/3w9ACEp4q1InrXjS+cepGbkqM6cxhw95vPbznGuBACW jyg47SRTnx22nrb0dl7Z+BIihjXZFULB6dFV2HGkG+J4bXbxhxwJidGPB2pJW8N3gdbcxo2TzE+ DI2VvisWaiw== X-Received: from dltt19.prod.google.com ([2002:a05:701a:c973:b0:141:37f6:f90a]) (user=mrungta job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2750:b0:398:e73e:5a0c with SMTP id 98e67ed59e1d1-39aedf5d887mr13782819a91.1.1788400477127; Wed, 02 Sep 2026 18:54:37 -0700 (PDT) Date: Wed, 02 Sep 2026 18:54:19 -0700 In-Reply-To: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> X-Developer-Key: i=mrungta@google.com; a=ed25519; pk=2Bjwbv/ibL10QnyvK9G7DoKpffXy7z6+M4NawEYgYDI= X-Developer-Signature: v=1; a=ed25519-sha256; t=1788400471; l=1942; i=mrungta@google.com; s=20260212; h=from:subject:message-id; bh=wedRPiAO/DhYjzS65XL5l3RIbBJTHI5WnzKxvRx2w6M=; b=Bk+0b9J+Ip6aLIdap95wpcVo+WSJNhfEkYqvG9iufWjfAIILdJI9E93ZPSzsVW9AKSzT0G3JG AQrXvjsTwEpDpuE0LB53ta58tWomN/xbNxv2UYqa6QC1ZNos5kXoTtw X-Mailer: b4 0.14.3 Message-ID: <20260902-qcom-wdt-nmi-series-v3-2-f3999362a9ea@google.com> Subject: [PATCH v3 2/5] genirq: Implement synchronous disable_nmi() From: Mayank Rungta To: Wim Van Sebroeck , Guenter Roeck , Thomas Gleixner , Radu Rendec Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, "Kirill A. Shutemov" , Douglas Anderson , Mayank Rungta Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Currently, disable_nmi_nosync() is the only interface to disable an NMI line. Drivers stopping their devices in process context need a synchronous variant that guarantees any running instance of the NMI handler has completed on other CPUs before returning. Implement disable_nmi() by wrapping disable_irq(). Assisted-by: Antigravity:gemini Reviewed-by: Douglas Anderson Signed-off-by: Mayank Rungta --- include/linux/interrupt.h | 1 + kernel/irq/manage.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h index 3bf969ad8fe0..f13b3ab3829a 100644 --- a/include/linux/interrupt.h +++ b/include/linux/interrupt.h @@ -243,6 +243,7 @@ DEFINE_LOCK_GUARD_1(disable_irq, int, disable_irq(*_T->lock), enable_irq(*_T->lock)) =20 extern void disable_nmi_nosync(unsigned int irq); +extern void disable_nmi(unsigned int irq); extern void disable_percpu_nmi(unsigned int irq); extern void enable_nmi(unsigned int irq); extern void enable_percpu_nmi(unsigned int irq, unsigned int type); diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index a9973b61163a..009633b5b654 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -767,6 +767,21 @@ void disable_nmi_nosync(unsigned int irq) disable_irq_nosync(irq); } =20 +/** + * disable_nmi - disable an nmi and wait for any pending handlers + * @irq: Interrupt to disable + * + * Disable the selected interrupt line. Disables and enables are nested. + * + * The interrupt to disable must have been requested through request_nmi. + * This function ensures existing instances of the NMI handler have + * completed before returning. + */ +void disable_nmi(unsigned int irq) +{ + disable_irq(irq); +} + void __enable_irq(struct irq_desc *desc) { switch (desc->depth) { --=20 2.55.0.970.g62bdec98f9-goog From nobody Sat Sep 26 08:39:16 2026 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0CF1305680 for ; Thu, 3 Sep 2026 01:54:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.70 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400482; cv=none; b=L0BMyWAzPFdZmMQnNVotS2J7SkLdoK62Jj1YEEtoQDkmo1Bv0J538t+S3C5a4buIFCFV1nPFjHyh/sDl3BHHAtCArRT5u3AxAdqLKPDVKRjuzXe5F5QBJCP8k/M80Yn3sMGVP5enrAXyj0jyFJxvhlTOd/+znOi5RQr2XqwbFnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400482; c=relaxed/simple; bh=sHtLbAnHiqVgz+a1ynLID9Y8mgVQLArjzx4ytcT8sdU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q06CW+mtSIeJImn6PLI10jbJ20PzUp7kj7sOAzV6wDs9CpVlOy9KTFNQBuQ0WQjdFaGVmKAWjFS0qTIeXJMi0zJDfi9Kvk9CU9jYgdc1fmw7Kp12Fo2jDigoRBWYGKisrP87w6sZakdHGTiSSbXhXiRe2nrK/JtDkV6zMum+9cE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tq51EJwx; arc=none smtp.client-ip=209.85.216.70 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tq51EJwx" Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-398e1f7d1a5so2870997a91.0 for ; Wed, 02 Sep 2026 18:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788400479; x=1789005279; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=EoKqqWg8bqAtanb9M/zmb/yr36CAI+4ITz7oBEmrMEw=; b=tq51EJwxyx0iH5xpgKhd9z1TUabksBDUl8Nufr5mkd0FZ7ngNwlqcvGaLE12uLS88B hl0+fkJbXMfIFJ6CPWPT4nIYUN0oTy62hU3vFQjDhmZznytRkYtScPQYG+ieWtvjbxOG Smi+o1StZ3V8d73cwPU2/FNjS8hpetyqvr5/OzwujiXQVAmWpfROAoH7ypUPERrFV1C3 aqVT6RWF4e6epB0xASQl9k2yfyMLkuCwRZ7m1jh8mj2dphlQGvZX8KwvMjIP5N3zAXYa z6jbyjDY4ChXvzbKs00je/OoHKrYpcFz15HcYGNIim23JrczePz3nt/1C73zf48tnirY My9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788400479; x=1789005279; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EoKqqWg8bqAtanb9M/zmb/yr36CAI+4ITz7oBEmrMEw=; b=D9KkcWeZAgiYPmJbQ5/SUe4BCoo5je4H4XR+JurKt5UB+yw/tvUgXcc3tMUK7ZRlo6 vTvhOiTZUXODPeKSJBYVy89k6eS0nBsiNYB4j892pxZYmR1UA1oLk+0k1x8kr3PGctUn eiLFGdnu2/83NTslP/SzZftbrEbmZkTObVntdJkHVIUksENqFNkwFkH2zsFP6hMmcnEj lphxSCHFgk7PyepdEXbTemZXHWc+E0LGEj7+kXIlo0K2CeIUskUD4aw9XSv4wjKfU7Ol n6iYbsJ/x7m2L4NQB9wtnVWoorjBUdLIr2zNom0bI3y61XDb51JgH5lL/Q7NcL+naYdL T4Tw== X-Forwarded-Encrypted: i=1; AKwUvBz6GJACLc7JqzT/w13aXhFVKpWN5Q/uk3QApH9dU/IGLvVlHJsgQ5bNnv2xMDMeBVg+631neo417geif+0=@vger.kernel.org X-Gm-Message-State: AFuF++kTaqBOyEbDQIzdWezv3lbm0m/kyGMzc+DJwyIS1JEM22zhF+vd N/iF1zwyl3zQu+26z8znfjIUiK2l+6iNTO5T81Dtru+FiiaSWXbz2Oq1ZPd9miqDdoWT2GtEE/m ml8NAvofByA== X-Received: from dlbvs14.prod.google.com ([2002:a05:7022:3f0e:b0:141:3e0f:b739]) (user=mrungta job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4a4d:b0:380:540:d499 with SMTP id 98e67ed59e1d1-39aedf75c71mr11880424a91.6.1788400479123; Wed, 02 Sep 2026 18:54:39 -0700 (PDT) Date: Wed, 02 Sep 2026 18:54:20 -0700 In-Reply-To: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> X-Developer-Key: i=mrungta@google.com; a=ed25519; pk=2Bjwbv/ibL10QnyvK9G7DoKpffXy7z6+M4NawEYgYDI= X-Developer-Signature: v=1; a=ed25519-sha256; t=1788400471; l=1668; i=mrungta@google.com; s=20260212; h=from:subject:message-id; bh=sHtLbAnHiqVgz+a1ynLID9Y8mgVQLArjzx4ytcT8sdU=; b=5B9upHEjp+OR5r5ijj+Hm7lQqSLhadCiohWfcaV4teu5+dSM/h3juA66MBbKacWwRoq3SjX1C Ss7CaWz2p6pDe1+bIYsFa9Kf9rdL8ah/mzgurbDYVn0DitodwNWBTiB X-Mailer: b4 0.14.3 Message-ID: <20260902-qcom-wdt-nmi-series-v3-3-f3999362a9ea@google.com> Subject: [PATCH v3 3/5] genirq: Export NMI APIs From: Mayank Rungta To: Wim Van Sebroeck , Guenter Roeck , Thomas Gleixner , Radu Rendec Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, "Kirill A. Shutemov" , Douglas Anderson , Mayank Rungta Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Currently, request_nmi(), free_nmi(), enable_nmi(), disable_nmi_nosync(), and disable_nmi() are restricted to built-in kernel code because they are not exported. Export these symbols with EXPORT_SYMBOL_GPL so loadable kernel modules can register and manage NMIs. Assisted-by: Antigravity:gemini Reviewed-by: Douglas Anderson Signed-off-by: Mayank Rungta --- kernel/irq/manage.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 009633b5b654..cb6bad666779 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -766,6 +766,7 @@ void disable_nmi_nosync(unsigned int irq) { disable_irq_nosync(irq); } +EXPORT_SYMBOL_GPL(disable_nmi_nosync); =20 /** * disable_nmi - disable an nmi and wait for any pending handlers @@ -781,6 +782,7 @@ void disable_nmi(unsigned int irq) { disable_irq(irq); } +EXPORT_SYMBOL_GPL(disable_nmi); =20 void __enable_irq(struct irq_desc *desc) { @@ -848,6 +850,7 @@ void enable_nmi(unsigned int irq) { enable_irq(irq); } +EXPORT_SYMBOL_GPL(enable_nmi); =20 static int set_irq_wake_real(unsigned int irq, unsigned int on) { @@ -2114,6 +2117,7 @@ const void *free_nmi(unsigned int irq, void *dev_id) =20 return __cleanup_nmi(irq, desc); } +EXPORT_SYMBOL_GPL(free_nmi); =20 /** * request_threaded_irq - allocate an interrupt line @@ -2376,6 +2380,7 @@ int request_nmi(unsigned int irq, irq_handler_t handl= er, =20 return retval; } +EXPORT_SYMBOL_GPL(request_nmi); =20 void enable_percpu_irq(unsigned int irq, unsigned int type) { --=20 2.55.0.970.g62bdec98f9-goog From nobody Sat Sep 26 08:39:16 2026 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D18DF32E757 for ; Thu, 3 Sep 2026 01:54:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.72 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400483; cv=none; b=FiThyQHYrshgQWCSlYyD8/AXlVQ8r2Jnkfhpb9GFdxtjz4ov3GIa5xW8aq1zRG4BJ06uJk71r0o27iSnXS+u9eVtYpSdRtPFVsdxtdr56ikyrea316gQNmcXMaaQi09Y9LQzHHJ4izqGJ6HT+UrpQaZkNAJWl1P467H4lNg45Ig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400483; c=relaxed/simple; bh=Ly4VtUan1zwedYrGni1f6+QpeHwXTU7FLbsfJvxWpyo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HKPQFNewO37RyEgTjVpX4p18Y+umUMKmPu51Wxj6/zbK0q+IGdewkYE9LXQ1S/VotQPs2rNX3z0MeXDrN/VMDkdGLA9k3aWYaR/nCESnsumFV90ZB7yZo/3sCiKdhgkLi1rTJYDiEOjJlfurdRRf8/PgoK55Ul67GbFrJ5k9q4A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WdxUpjxF; arc=none smtp.client-ip=209.85.216.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WdxUpjxF" Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-38e7ff7b375so2546321a91.1 for ; Wed, 02 Sep 2026 18:54:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788400481; x=1789005281; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BFGT0XaOMkoxcnjGltb7X7sNf6EHxJSYeOr/S3w6LKs=; b=WdxUpjxFCdTU8gFnqWyZ5WBua5pmzj64gJ+bQGUKSQAc3UXUg8GfPVPiNwbi1ruHYx dcUCdtPkzuVdjef85qAxI3DbsazgTarguI3Rizr3qm8muZ83r1cEZqvsb4ATwxlIqe6x SIAHwTfZcBJS7dUxWe5Stg935wWnl0qqlP2KNlOfTVplDC58qG+47RORMRpTvy9pF5X+ KtRuq43IhGhmuMdrAxKp36IBtL3JQwcGlSr8TmtyFPT6qccKEYhQwg1RWQooJB/4L6CZ vxpa7ErzpePnh9qqh9SwftT7j53flUaoC5YflBS4Jzn1+yeYjdsaU7TqcU+Fy3wr7GRS 1x0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788400481; x=1789005281; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=BFGT0XaOMkoxcnjGltb7X7sNf6EHxJSYeOr/S3w6LKs=; b=VJFf2Zw9E0JWesdEVB1JeNTkx+xyJ2QWYgYuEbSRvCqmUhNdBcpTgYGWE5ksHUrfjs cIxsueifnMZ6F2aFUDRPbonicOQGcRkZSzJTL0rYBr6s8dj6OX1WbtUlze4CtvAxFyMy ek7oY3ZfXtD+AS0N30XYA9p/ZrGvraMXRq0lSM9PrJqqi1S//IFX2iiGO57IOmC9qwD8 KlM8iYrdmpmz2e+WmhHP0gmD0k72iuZjLHoYwdrwUK2phLtl+2GZLtdehT1Nwlxc3eDB pOPuhac6ZVTD122C9ZD3mbQzc7wiyxkU/YwLKlAkkkcQpiZqi5lnlhdZjUHR9/mXSGbp Akww== X-Forwarded-Encrypted: i=1; AKwUvBzT+TaV+A3WB2pZIXkJdP68B3l7liXdDBf8NhCH7iQL0cQzpLDLEZIyO50OX5WtO/xT5p2yYg/SWe3B5mI=@vger.kernel.org X-Gm-Message-State: AFuF++m+RN7+uX/SQ1swWQ8zuvFgFijrPkmR/wdHzwIEn3F4FqSjy+At mzSB0iv2cYALjZRJy4Rt7ACLPOcsCmk7Pns0u012Ih0hQUFpyBxNFs7QT9jUxN6rZ/1Odxycto8 ZmSbVJ1eicQ== X-Received: from dyblz13.prod.google.com ([2002:a05:7301:160d:b0:328:3b62:f49]) (user=mrungta job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3f84:b0:381:25ce:bcc2 with SMTP id 98e67ed59e1d1-39aedf1922dmr13504108a91.6.1788400480957; Wed, 02 Sep 2026 18:54:40 -0700 (PDT) Date: Wed, 02 Sep 2026 18:54:21 -0700 In-Reply-To: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> X-Developer-Key: i=mrungta@google.com; a=ed25519; pk=2Bjwbv/ibL10QnyvK9G7DoKpffXy7z6+M4NawEYgYDI= X-Developer-Signature: v=1; a=ed25519-sha256; t=1788400471; l=4831; i=mrungta@google.com; s=20260212; h=from:subject:message-id; bh=Ly4VtUan1zwedYrGni1f6+QpeHwXTU7FLbsfJvxWpyo=; b=OvDGmW9xSU7HxU6eFp8ZazsLXZaPsWyXTu7Wf4JYdlbqH2b1wHTZg5oca8ar3QtfyCSy/x5D/ twYfCE6gRo7CwEySCSzCM8Z0kNvIH/9bryqyAYUTocy1Y1gcoQtc1cc X-Mailer: b4 0.14.3 Message-ID: <20260902-qcom-wdt-nmi-series-v3-4-f3999362a9ea@google.com> Subject: [PATCH v3 4/5] watchdog: pretimeout: Protect governor access with RCU for NMI safety From: Mayank Rungta To: Wim Van Sebroeck , Guenter Roeck , Thomas Gleixner , Radu Rendec Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, "Kirill A. Shutemov" , Douglas Anderson , Mayank Rungta Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When watchdog pretimeout interrupts are configured as NMIs (or pseudo-NMIs), pretimeout handlers execute in NMI context. Accessing the watchdog governor via spinlocks in watchdog_notify_pretimeout() is unsafe in NMI context and can cause deadlocks if an NMI arrives while a spinlock is held. Protect governor assignment and dereference with RCU instead of spinlocks, allowing lockless, NMI-safe governor notifications while preserving safe runtime governor switching. Assisted-by: Antigravity:gemini Reviewed-by: Douglas Anderson Signed-off-by: Mayank Rungta --- drivers/watchdog/watchdog_pretimeout.c | 45 +++++++++++++++++++-----------= ---- include/linux/watchdog.h | 2 +- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/drivers/watchdog/watchdog_pretimeout.c b/drivers/watchdog/watc= hdog_pretimeout.c index 02e09b9e396d..7fb586c77403 100644 --- a/drivers/watchdog/watchdog_pretimeout.c +++ b/drivers/watchdog/watchdog_pretimeout.c @@ -4,6 +4,7 @@ */ =20 #include +#include #include #include #include @@ -67,12 +68,14 @@ int watchdog_pretimeout_available_governors_get(char *b= uf) =20 int watchdog_pretimeout_governor_get(struct watchdog_device *wdd, char *bu= f) { + const struct watchdog_governor *gov; int count =3D 0; =20 - spin_lock_irq(&pretimeout_lock); - if (wdd->gov) - count =3D sysfs_emit(buf, "%s\n", wdd->gov->name); - spin_unlock_irq(&pretimeout_lock); + rcu_read_lock(); + gov =3D rcu_dereference(wdd->gov); + if (gov) + count =3D sysfs_emit(buf, "%s\n", gov->name); + rcu_read_unlock(); =20 return count; } @@ -91,7 +94,7 @@ int watchdog_pretimeout_governor_set(struct watchdog_devi= ce *wdd, } =20 spin_lock_irq(&pretimeout_lock); - wdd->gov =3D priv->gov; + rcu_assign_pointer(wdd->gov, priv->gov); spin_unlock_irq(&pretimeout_lock); =20 mutex_unlock(&governor_lock); @@ -101,16 +104,13 @@ int watchdog_pretimeout_governor_set(struct watchdog_= device *wdd, =20 void watchdog_notify_pretimeout(struct watchdog_device *wdd) { - unsigned long flags; + const struct watchdog_governor *gov; =20 - spin_lock_irqsave(&pretimeout_lock, flags); - if (!wdd->gov) { - spin_unlock_irqrestore(&pretimeout_lock, flags); - return; - } - - wdd->gov->pretimeout(wdd); - spin_unlock_irqrestore(&pretimeout_lock, flags); + rcu_read_lock(); + gov =3D rcu_dereference(wdd->gov); + if (gov) + gov->pretimeout(wdd); + rcu_read_unlock(); } EXPORT_SYMBOL_GPL(watchdog_notify_pretimeout); =20 @@ -140,8 +140,8 @@ int watchdog_register_governor(struct watchdog_governor= *gov) default_gov =3D gov; =20 list_for_each_entry(p, &pretimeout_list, entry) - if (!p->wdd->gov) - p->wdd->gov =3D default_gov; + if (!rcu_access_pointer(p->wdd->gov)) + rcu_assign_pointer(p->wdd->gov, default_gov); spin_unlock_irq(&pretimeout_lock); } =20 @@ -170,11 +170,14 @@ void watchdog_unregister_governor(struct watchdog_gov= ernor *gov) if (default_gov =3D=3D gov) default_gov =3D NULL; list_for_each_entry(p, &pretimeout_list, entry) - if (p->wdd->gov =3D=3D gov) - p->wdd->gov =3D default_gov; + if (rcu_dereference_protected(p->wdd->gov, + lockdep_is_held(&pretimeout_lock)) =3D=3D gov) + rcu_assign_pointer(p->wdd->gov, default_gov); spin_unlock_irq(&pretimeout_lock); =20 mutex_unlock(&governor_lock); + + synchronize_rcu(); } EXPORT_SYMBOL(watchdog_unregister_governor); =20 @@ -192,7 +195,7 @@ int watchdog_register_pretimeout(struct watchdog_device= *wdd) spin_lock_irq(&pretimeout_lock); list_add(&p->entry, &pretimeout_list); p->wdd =3D wdd; - wdd->gov =3D default_gov; + rcu_assign_pointer(wdd->gov, default_gov); spin_unlock_irq(&pretimeout_lock); =20 return 0; @@ -206,7 +209,7 @@ void watchdog_unregister_pretimeout(struct watchdog_dev= ice *wdd) return; =20 spin_lock_irq(&pretimeout_lock); - wdd->gov =3D NULL; + rcu_assign_pointer(wdd->gov, NULL); =20 list_for_each_entry_safe(p, t, &pretimeout_list, entry) { if (p->wdd =3D=3D wdd) { @@ -216,4 +219,6 @@ void watchdog_unregister_pretimeout(struct watchdog_dev= ice *wdd) } } spin_unlock_irq(&pretimeout_lock); + + synchronize_rcu(); } diff --git a/include/linux/watchdog.h b/include/linux/watchdog.h index 29cd03686154..5a3c35968cc8 100644 --- a/include/linux/watchdog.h +++ b/include/linux/watchdog.h @@ -105,7 +105,7 @@ struct watchdog_device { const struct attribute_group **groups; const struct watchdog_info *info; const struct watchdog_ops *ops; - const struct watchdog_governor *gov; + const struct watchdog_governor __rcu *gov; unsigned int bootstatus; unsigned int timeout; unsigned int pretimeout; --=20 2.55.0.970.g62bdec98f9-goog From nobody Sat Sep 26 08:39:16 2026 Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D16A331EBB for ; Thu, 3 Sep 2026 01:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400485; cv=none; b=FsqVCo1xsMLkr1jps50XhEFPKGHBdeLr1oBMaQzeluXewsaLwEBwxfC9yGEmuxcf/xpbjAkRyAQ1Lj05FElwYPcu5ExSolJLWcOJNBDX03abJHPoaOghaVXScI7MEg797zSMHfAKtg1ahjHHg9NF/nRem4NaEhxrGjsI1fmefkw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788400485; c=relaxed/simple; bh=0ZGR/YgV7OEk+X+iRefjExBb64jGwBcbx5DVUTJVoAg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XBUzLEAE1EZFLdBl1+tceVcTcc8nkOH6DVkV36/Oz2aTOfSiOBBRJgkPbzMQIduA+GCB2qEt2E5JDZsoDYHHxNm0vUCCg5tIEMTflJa+gjk9um2DP1cCKsdG99Zfu/p6Oq5uaSexUYAiJRC84+dSIMjBwotEj9+fFVLgaSIq+FE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BvUCi7X0; arc=none smtp.client-ip=209.85.215.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--mrungta.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BvUCi7X0" Received: by mail-pg1-f199.google.com with SMTP id 41be03b00d2f7-cc12e8e22b7so4218087a12.0 for ; Wed, 02 Sep 2026 18:54:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1788400483; x=1789005283; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=xBi3aelOOZxRnPRZaGfB7u7SxHHBTXTNxhOMaECeb/c=; b=BvUCi7X0qY9cbcJ/T/U191iVoL2ri7i4pZcdjAey4HBT8Fq1VBfnUoKrSsT7gOTODx LGu9qifYqZuOOzADKrAPxDuZh3Ree6D2DDnYzko32Ts5oWdYUoHZChdemNpehL+NoqxW 4mwVTcsx03/VdXNeCtMkhugjov3avIEIWJLro8NyfEFkU0YgplY6fNRRquQA0MXcQQV1 SUkEktpQDH/67nt/XtihA3MBOZpjEu9FwOwRKD34M7N3e7TCjIxFXvHpgcqWPlwjuhVE yWa62+ddOmc9vrxqbubzKs0aQ/AQo9jFpcQZXcC6uJ4fhklJN4hteWhIhPTrNg2VoqqA u7FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788400483; x=1789005283; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xBi3aelOOZxRnPRZaGfB7u7SxHHBTXTNxhOMaECeb/c=; b=pq+V3wfa/+SJh35rFcUy7JfKoNH1KI7GnepD8OVJ/i6EbmXqYYZuLO4JB/e6YUxLMq CnrOReEJhuPJGSMDzJpAyIkVnDwt4KWNwr2sDF8x9w5qIJl87tWbiF41j7ggp4EKpskO TIYxMwxr3ca00rOJm+cnRENS20/NKEKceJEf+BhAY6JGnRJ/rYTn0OFwl0FjdeD+P9p0 hs3Bi5dSIxi5us7TfEDiahPtR2D152BxnsisBkxuU9GP2qW+YgyvnpXbHiPF6Zz50A1A FveKgMO8u8BvENt9/XnLtVaBnCXIByvFs2KbiEQFZk18tCXWsGjsT9aznjkyz4RwzebT FkJw== X-Forwarded-Encrypted: i=1; AKwUvBxxuKc9sIG+0ncgVMxF7pZ344Xrt9YWzNjtu1ygpN7QwqZhqDewpRjfFT1Uj05kUxZ69+OiU2/uOmP9uj0=@vger.kernel.org X-Gm-Message-State: AFuF++lglEViZ9fBKZRtUlztR0w1zghWz2wLdL5Sy11GysC94i9I3wZx rKeDXGR9b7giI4HDq+t1FQg7FN2kpyP1ezp6HLk6thGt2krJC/wsX8/MaJPqqe/xzZa15q9cpMn tdfN8W2EeKg== X-Received: from dyff15.prod.google.com ([2002:a05:693c:804f:b0:30f:45f6:de06]) (user=mrungta job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3b81:b0:398:9be5:b41d with SMTP id 98e67ed59e1d1-39aee2650cdmr12947171a91.24.1788400482836; Wed, 02 Sep 2026 18:54:42 -0700 (PDT) Date: Wed, 02 Sep 2026 18:54:22 -0700 In-Reply-To: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260902-qcom-wdt-nmi-series-v3-0-f3999362a9ea@google.com> X-Developer-Key: i=mrungta@google.com; a=ed25519; pk=2Bjwbv/ibL10QnyvK9G7DoKpffXy7z6+M4NawEYgYDI= X-Developer-Signature: v=1; a=ed25519-sha256; t=1788400471; l=2864; i=mrungta@google.com; s=20260212; h=from:subject:message-id; bh=0ZGR/YgV7OEk+X+iRefjExBb64jGwBcbx5DVUTJVoAg=; b=DHstgDkJJZM05Winbe+XcggvVy1V0AGDZoQau5xfIK5izXTlRkTxUuLq2iH0U8nNF3DHv1suD HHeuTBel5EDCPA0CSgXCAqfdW5OVt39YtZ3wj9a3m1LbnLoNFQNAMdg X-Mailer: b4 0.14.3 Message-ID: <20260902-qcom-wdt-nmi-series-v3-5-f3999362a9ea@google.com> Subject: [PATCH v3 5/5] watchdog: qcom: Register pretimeout interrupt as NMI From: Mayank Rungta To: Wim Van Sebroeck , Guenter Roeck , Thomas Gleixner , Radu Rendec Cc: linux-watchdog@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, "Kirill A. Shutemov" , Douglas Anderson , Mayank Rungta Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable When a system is completely unresponsive due to an interrupt storm or deadlocked CPU cores with standard interrupts disabled, a standard watchdog pretimeout bark interrupt will fail to execute, preventing the pretimeout governor from capturing CPU backtraces before the hardware reset bite. Attempt to request the Qualcomm watchdog pretimeout bark interrupt as an NMI (or pseudo-NMI) using request_nmi(). If NMI registration is not supported on the platform (e.g. pseudo-NMIs are disabled), gracefully fall back to a standard interrupt via devm_request_irq(). When NMI is used, enable the NMI during probe to balance IRQF_NO_AUTOEN and register a devres cleanup action to disable and free the NMI upon driver unbind. Assisted-by: Antigravity:gemini Signed-off-by: Mayank Rungta Reviewed-by: Konrad Dybcio --- drivers/watchdog/qcom-wdt.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/qcom-wdt.c b/drivers/watchdog/qcom-wdt.c index 4eb1bf979012..2849dcb1f717 100644 --- a/drivers/watchdog/qcom-wdt.c +++ b/drivers/watchdog/qcom-wdt.c @@ -52,6 +52,7 @@ struct qcom_wdt { unsigned long rate; void __iomem *base; const u32 *layout; + int irq; }; =20 static void __iomem *wdt_addr(struct qcom_wdt *wdt, enum wdt_reg reg) @@ -74,6 +75,14 @@ static irqreturn_t qcom_wdt_isr(int irq, void *arg) return IRQ_HANDLED; } =20 +static void qcom_wdt_free_nmi(void *arg) +{ + struct qcom_wdt *wdt =3D arg; + + disable_nmi(wdt->irq); + free_nmi(wdt->irq, &wdt->wdd); +} + static int qcom_wdt_start(struct watchdog_device *wdd) { struct qcom_wdt *wdt =3D to_qcom_wdt(wdd); @@ -256,6 +265,7 @@ static int qcom_wdt_probe(struct platform_device *pdev) u32 percpu_offset; int irq, ret; struct clk *clk; + unsigned long irq_flags; =20 data =3D of_device_get_match_data(dev); if (!data) { @@ -311,10 +321,25 @@ static int qcom_wdt_probe(struct platform_device *pde= v) if (irq < 0 && irq !=3D -ENXIO) return irq; if (irq > 0) { - ret =3D devm_request_irq(dev, irq, qcom_wdt_isr, 0, - "wdt_bark", &wdt->wdd); - if (ret) - return ret; + wdt->irq =3D irq; + irq_flags =3D IRQF_PERCPU | IRQF_NOBALANCING | + IRQF_NO_AUTOEN | IRQF_NO_THREAD; + + ret =3D request_nmi(irq, qcom_wdt_isr, irq_flags, + "wdt_bark", &wdt->wdd); + if (ret) { + /* Fallback to normal interrupt if NMI not supported */ + ret =3D devm_request_irq(dev, irq, qcom_wdt_isr, 0, + "wdt_bark", &wdt->wdd); + if (ret) + return ret; + } else { + enable_nmi(irq); + ret =3D devm_add_action_or_reset(dev, qcom_wdt_free_nmi, + wdt); + if (ret) + return ret; + } =20 wdt->wdd.info =3D &qcom_wdt_pt_info; wdt->wdd.pretimeout =3D 1; --=20 2.55.0.970.g62bdec98f9-goog