* [PATCH] watchdog: s3c2410: Fix potential deadlock on &wdt->lock
@ 2023-06-28 16:47 Chengfeng Ye
2023-07-04 7:53 ` Krzysztof Kozlowski
0 siblings, 1 reply; 4+ messages in thread
From: Chengfeng Ye @ 2023-06-28 16:47 UTC (permalink / raw)
To: krzysztof.kozlowski, alim.akhtar, wim, linux
Cc: linux-arm-kernel, linux-samsung-soc, linux-watchdog,
linux-kernel, Chengfeng Ye
As &wdt->lock is acquired by hard irq s3c2410wdt_irq(),
other acquisition of the same lock under process context should
disable irq, otherwise deadlock could happen if the
irq preempt the execution while the lock is held in process context
on the same CPU.
[Interrupt]: s3c2410wdt_irq
-->/root/linux/drivers/watchdog/s3c2410_wdt.c:547
-->/root/linux/drivers/watchdog/s3c2410_wdt.c:383
-->spin_lock(&wdt->lock);
[Process Context]: s3c2410wdt_suspend
-->/root/linux/drivers/watchdog/s3c2410_wdt.c:764
-->/root/linux/drivers/watchdog/s3c2410_wdt.c:403
-->spin_lock(&wdt->lock);
[Process Context]: s3c2410wdt_probe
-->/root/linux/drivers/watchdog/s3c2410_wdt.c:710
-->/root/linux/drivers/watchdog/s3c2410_wdt.c:415
-->spin_lock(&wdt->lock);
This flaw was found by an experimental static analysis tool I am
developing for irq-related deadlock, which reported the above
warning when analyzing the linux kernel 6.4-rc7 release.
The tentative patch fix the potential deadlock by spin_lock_irqsave().
Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
drivers/watchdog/s3c2410_wdt.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 95416a9bdd4b..2dfc0d6a3004 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -399,10 +399,11 @@ static void __s3c2410wdt_stop(struct s3c2410_wdt *wdt)
static int s3c2410wdt_stop(struct watchdog_device *wdd)
{
struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd);
+ unsigned long flags;
- spin_lock(&wdt->lock);
+ spin_lock_irqsave(&wdt->lock, flags);
__s3c2410wdt_stop(wdt);
- spin_unlock(&wdt->lock);
+ spin_unlock_irqrestore(&wdt->lock, flags);
return 0;
}
@@ -411,8 +412,9 @@ static int s3c2410wdt_start(struct watchdog_device *wdd)
{
unsigned long wtcon;
struct s3c2410_wdt *wdt = watchdog_get_drvdata(wdd);
+ unsigned long flags;
- spin_lock(&wdt->lock);
+ spin_lock_irqsave(&wdt->lock, flags);
__s3c2410wdt_stop(wdt);
@@ -433,7 +435,7 @@ static int s3c2410wdt_start(struct watchdog_device *wdd)
writel(wdt->count, wdt->reg_base + S3C2410_WTDAT);
writel(wdt->count, wdt->reg_base + S3C2410_WTCNT);
writel(wtcon, wdt->reg_base + S3C2410_WTCON);
- spin_unlock(&wdt->lock);
+ spin_unlock_irqrestore(&wdt->lock, flags);
return 0;
}
--
2.17.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] watchdog: s3c2410: Fix potential deadlock on &wdt->lock
2023-06-28 16:47 [PATCH] watchdog: s3c2410: Fix potential deadlock on &wdt->lock Chengfeng Ye
@ 2023-07-04 7:53 ` Krzysztof Kozlowski
[not found] ` <CAAo+4rUzusAyyffkCvEq+wJQacqfrcTx-SviqXaTzPsqOkjB7w@mail.gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2023-07-04 7:53 UTC (permalink / raw)
To: Chengfeng Ye, alim.akhtar, wim, linux
Cc: linux-arm-kernel, linux-samsung-soc, linux-watchdog, linux-kernel
On 28/06/2023 18:47, Chengfeng Ye wrote:
> As &wdt->lock is acquired by hard irq s3c2410wdt_irq(),
> other acquisition of the same lock under process context should
> disable irq, otherwise deadlock could happen if the
> irq preempt the execution while the lock is held in process context
> on the same CPU.
>
> [Interrupt]: s3c2410wdt_irq
> -->/root/linux/drivers/watchdog/s3c2410_wdt.c:547
> -->/root/linux/drivers/watchdog/s3c2410_wdt.c:383
> -->spin_lock(&wdt->lock);
This interrupt is a threaded interrupt. Therefore the
s3c2410wdt_keepalive() will be called again from process thread. Are you
sure there is deadlock?
Anyway, please also strip unrelated paths and rather use function names,
not references to lines, because these might be not accurate.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-05 8:55 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-28 16:47 [PATCH] watchdog: s3c2410: Fix potential deadlock on &wdt->lock Chengfeng Ye
2023-07-04 7:53 ` Krzysztof Kozlowski
[not found] ` <CAAo+4rUzusAyyffkCvEq+wJQacqfrcTx-SviqXaTzPsqOkjB7w@mail.gmail.com>
2023-07-04 16:18 ` Chengfeng Ye
2023-07-05 8:55 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®