From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796319083; b=mHkUjUm5yGlev7Vc/ozbF/l1GOp/90/7SaH9/ype1YW2myni1IHQ39Pe0sbVCGuOMfzS g2egb0JiynOkgD+kiKU/SIJ0n7+RN6xOqdefn5mUOkaCV4e77dCV+3qcSDlhi3uMgGkoW BQVw3JzQcucihihteHLFAkcDUSstHGeVFNSCHVNo6NYdFM/NGr6DPIqXDWHkWla/5sGtf Jhrc9d1pT65MTUS24yer77jb5h5wwuvjcj+OV2YvCwRNVdNHaNFPBLoQtOVD07nxGbOUY tAfRWk3JGugz14kQ1icWLJ5AepMhD3x+h1II8i+7qY6oTEiX++HhJpQqCdszCw4ruYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796319083; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=+VHBzWEIjqFIY7gWCBttFI8czOPVYjkHXpXzdFErnwo=; b=dIn7po8NrOcImLaSKPFDw1+5TmpsDls6BfuzxFk/LyUhXs4AVh7ckcuDQaE+Bav0Mq6v pMMKDLzomziTC7TKtsPZyriXXJLqGHqqRPCiHsNBwGyfS2FcwHQC2Dhxj99R97ArmENr0 91Ul6wV9RPOCltmWmeXh/niVh0iW5hxKarNq2JoNoFwbFU3phszMdeYWKyds7iqwituL3 5QKnnhhXBTtatQ6ErFojKOsyRUYIJ5R4zeV3Rdw2rLujCEn6SCzn61rizwTRt3pDSjANK LFZ0aoHNdq4e2cyMcPmD8+lBmTIiTXfb+xayeF3B74fHwpbZFs68VESms/IgekKB2zQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="dT9xgoa/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61C5A606A32F; Thu, 3 Dec 2026 17:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dT9xgoa/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 555F61F00893; Thu, 3 Dec 2026 17:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796319083; bh=+VHBzWEIjqFIY7gWCBttFI8czOPVYjkHXpXzdFErnwo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dT9xgoa/CC64gCrKHPORhf8qkb1DcTlDQV+tjdztUidEC0mHsElmpVCqUbXbqN6+n x5/DubHCNl+bjWR4pjVvPoRcBT4QU1ukVfj+7qbDmRAuyw9y9wckVcLX3HtD9aChPc UsbsgKo7Rx6MNThiLfOmKQ1TLci6ffu9eu/Jp6hqpQBpzaPEuydVj8qJWPhvW/ex+2 7Z/o1OUBmP3KIvUn2WRK3W2a6Sdk2b1T5hVe3k6sFiiu3E0gJ+N5gbfn1c7k5DzcCa h+jGg+xxgpOd/9oVVO2LTzbhBT0ZAf5EAUqLdNzMWQ5P/2FJ8G5Kh28WYurejR0E4Z I5vLyupnjMjpw== From: Lee Jones To: lee@kernel.org, Wim Van Sebroeck , Guenter Roeck , Aaro Koskinen , Alan Cox , Cavium Inc , David Daney , linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 5/6] watchdog: octeon-wdt: Serialise countdown and IRQ state with raw spinlock Date: Thu, 3 Dec 2026 17:30:08 +0000 Message-ID: <20261203173039.1142495-6-lee@kernel.org> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: <20261203173039.1142495-1-lee@kernel.org> References: <20261203173039.1142495-1-lee@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit octeon_wdt_poke_irq() runs in hardirq context (IRQF_NO_THREAD) and updates per_cpu_countdown[], disables the watchdog IRQ, and clears irq_enabled_cpus without locking. Concurrently, octeon_wdt_ping() writes per_cpu_countdown[] and tests irq_enabled_cpus in process context. This allows octeon_wdt_ping() to miss the cleared bit and leave the watchdog IRQ permanently disabled, or lose a countdown reset. Protect per_cpu_countdown[], irq_enabled_cpus, and do_countdown with a raw_spinlock_t across the IRQ handler, ping, start, stop, and CPU hotplug callbacks, deferring enable_irq() and panic() until after the lock is released, and guard octeon_wdt_ping()'s online-CPU iteration with cpus_read_lock(). Fixes: 4c076fb41ac9 ("WATCHDOG: Add watchdog driver for OCTEON SOCs") Closes: https://sashiko.dev/#/bug/linux-1d98fa88-4055-42e9-b51b-69f0073793a8 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- drivers/watchdog/octeon-wdt-main.c | 43 ++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/octeon-wdt-main.c b/drivers/watchdog/octeon-wdt-main.c index d29a63899847..718617437542 100644 --- a/drivers/watchdog/octeon-wdt-main.c +++ b/drivers/watchdog/octeon-wdt-main.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include @@ -85,6 +86,7 @@ static unsigned int countdown_reset; static unsigned int per_cpu_countdown[NR_CPUS]; static cpumask_t irq_enabled_cpus; +static DEFINE_RAW_SPINLOCK(octeon_wdt_lock); #define WD_TIMO 60 /* Default heartbeat = 60 seconds */ @@ -138,7 +140,10 @@ static irqreturn_t octeon_wdt_poke_irq(int cpl, void *dev_id) int cpu = raw_smp_processor_id(); unsigned int core = cpu2core(cpu); int node = cpu_to_node(cpu); + unsigned long flags; + bool should_panic = false; + raw_spin_lock_irqsave(&octeon_wdt_lock, flags); if (do_countdown) { if (per_cpu_countdown[cpu] > 0) { /* We're alive, poke the watchdog */ @@ -148,13 +153,17 @@ static irqreturn_t octeon_wdt_poke_irq(int cpl, void *dev_id) /* Bad news, you are about to reboot. */ disable_irq_nosync(cpl); cpumask_clear_cpu(cpu, &irq_enabled_cpus); - if (panic_on_timeout) - panic("Watchdog timeout"); + should_panic = panic_on_timeout; } } else { /* Not open, just ping away... */ cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1); } + raw_spin_unlock_irqrestore(&octeon_wdt_lock, flags); + + if (should_panic) + panic("Watchdog timeout"); + return IRQ_HANDLED; } @@ -333,6 +342,7 @@ static int octeon_wdt_cpu_to_irq(int cpu) static int octeon_wdt_cpu_pre_down(unsigned int cpu) { unsigned int core; + unsigned long flags; int node; union cvmx_ciu_wdogx ciu_wdog; @@ -348,6 +358,10 @@ static int octeon_wdt_cpu_pre_down(unsigned int cpu) cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64); free_irq(octeon_wdt_cpu_to_irq(cpu), octeon_wdt_poke_irq); + + raw_spin_lock_irqsave(&octeon_wdt_lock, flags); + cpumask_clear_cpu(cpu, &irq_enabled_cpus); + raw_spin_unlock_irqrestore(&octeon_wdt_lock, flags); return 0; } @@ -355,6 +369,7 @@ static int octeon_wdt_cpu_online(unsigned int cpu) { unsigned int core; unsigned int irq; + unsigned long flags; union cvmx_ciu_wdogx ciu_wdog; int node; struct irq_domain *domain; @@ -369,7 +384,10 @@ static int octeon_wdt_cpu_online(unsigned int cpu) ciu_wdog.u64 = 0; cvmx_write_csr_node(node, CVMX_CIU_WDOGX(core), ciu_wdog.u64); + raw_spin_lock_irqsave(&octeon_wdt_lock, flags); per_cpu_countdown[cpu] = countdown_reset; + cpumask_set_cpu(cpu, &irq_enabled_cpus); + raw_spin_unlock_irqrestore(&octeon_wdt_lock, flags); if (octeon_has_feature(OCTEON_FEATURE_CIU3)) { /* Must get the domain for the watchdog block */ @@ -392,8 +410,6 @@ static int octeon_wdt_cpu_online(unsigned int cpu) irq_set_affinity(irq, cpumask_of(cpu)); } - cpumask_set_cpu(cpu, &irq_enabled_cpus); - /* Poke the watchdog to clear out its state */ cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(core), 1); @@ -415,18 +431,27 @@ static int octeon_wdt_ping(struct watchdog_device __always_unused *wdog) if (disable) return 0; + cpus_read_lock(); for_each_online_cpu(cpu) { + unsigned long flags; + bool need_enable = false; + coreid = cpu2core(cpu); node = cpu_to_node(cpu); + raw_spin_lock_irqsave(&octeon_wdt_lock, flags); cvmx_write_csr_node(node, CVMX_CIU_PP_POKEX(coreid), 1); per_cpu_countdown[cpu] = countdown_reset; if ((countdown_reset || !do_countdown) && !cpumask_test_cpu(cpu, &irq_enabled_cpus)) { /* We have to enable the irq */ - enable_irq(octeon_wdt_cpu_to_irq(cpu)); cpumask_set_cpu(cpu, &irq_enabled_cpus); + need_enable = true; } + raw_spin_unlock_irqrestore(&octeon_wdt_lock, flags); + if (need_enable) + enable_irq(octeon_wdt_cpu_to_irq(cpu)); } + cpus_read_unlock(); return 0; } @@ -488,14 +513,22 @@ static int octeon_wdt_set_timeout(struct watchdog_device *wdog, static int octeon_wdt_start(struct watchdog_device *wdog) { + unsigned long flags; + octeon_wdt_ping(wdog); + raw_spin_lock_irqsave(&octeon_wdt_lock, flags); do_countdown = 1; + raw_spin_unlock_irqrestore(&octeon_wdt_lock, flags); return 0; } static int octeon_wdt_stop(struct watchdog_device *wdog) { + unsigned long flags; + + raw_spin_lock_irqsave(&octeon_wdt_lock, flags); do_countdown = 0; + raw_spin_unlock_irqrestore(&octeon_wdt_lock, flags); octeon_wdt_ping(wdog); return 0; } -- 2.56.1.911.g883d8bcb20-goog