From: KhaiWenTan <khai.wen.tan@linux.intel.com>
To: Rodolfo Giometti <giometti@enneenne.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jonathan Corbet <corbet@lwn.net>
Cc: Thomas Gleixner <tglx@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
david.zage@intel.com, weifeng.voon@intel.com,
hong.aun.looi@intel.com, christopher.s.hall@intel.com,
khai.wen.tan@intel.com, linux-kernel@vger.kernel.org,
linux-doc@vger.kernel.org
Subject: [PATCH 2/4] pps: generators: cancel TIO timer outside spinlock
Date: Thu, 3 Dec 2026 01:21:56 +0800 [thread overview]
Message-ID: <20261202172254.1188109-3-khai.wen.tan@linux.intel.com> (raw)
In-Reply-To: <20261202172254.1188109-1-khai.wen.tan@linux.intel.com>
From: Voon Weifeng <weifeng.voon@intel.com>
Move hrtimer_cancel() out of the spinlocked section. The timer
callback takes the same lock, so cancelling while holding it can
deadlock. Serialize enable, disable and removal with a mutex.
Fixes: c89755d1111f ("pps: generators: Add PPS Generator TIO Driver")
Signed-off-by: Voon Weifeng <weifeng.voon@intel.com>
Signed-off-by: KhaiWenTan <khai.wen.tan@linux.intel.com>
---
drivers/pps/generators/pps_gen_tio.c | 25 +++++++++++++++++++++----
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/drivers/pps/generators/pps_gen_tio.c b/drivers/pps/generators/pps_gen_tio.c
index c6d41fb2105f..9e3142041269 100644
--- a/drivers/pps/generators/pps_gen_tio.c
+++ b/drivers/pps/generators/pps_gen_tio.c
@@ -13,6 +13,7 @@
#include <linux/hrtimer.h>
#include <linux/io-64-nonatomic-hi-lo.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/pps_gen_kernel.h>
#include <linux/timekeeping.h>
@@ -44,6 +45,7 @@ struct pps_tio {
struct hrtimer timer;
void __iomem *base;
u32 prev_count;
+ struct mutex mutex;
spinlock_t lock;
struct device *dev;
};
@@ -167,22 +169,31 @@ static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer)
static int pps_tio_gen_enable(struct pps_gen_device *pps_gen, bool enable)
{
struct pps_tio *tio = container_of(pps_gen->info, struct pps_tio, gen_info);
+ unsigned long flags;
+ int ret = 0;
+ mutex_lock(&tio->mutex);
if (!timekeeping_clocksource_has_base(CSID_X86_ART)) {
dev_err_once(tio->dev, "PPS cannot be used as clock is not related to ART");
- return -ENODEV;
+ ret = -ENODEV;
+ goto out_mutex;
}
- guard(spinlock_irqsave)(&tio->lock);
+ if (!enable)
+ hrtimer_cancel(&tio->timer);
+
+ spin_lock_irqsave(&tio->lock, flags);
if (enable && !pps_gen->enabled) {
pps_tio_direction_output(tio);
hrtimer_start(&tio->timer, first_event(tio), HRTIMER_MODE_ABS);
} else if (!enable && pps_gen->enabled) {
- hrtimer_cancel(&tio->timer);
pps_tio_disable(tio);
}
+ spin_unlock_irqrestore(&tio->lock, flags);
- return 0;
+out_mutex:
+ mutex_unlock(&tio->mutex);
+ return ret;
}
static int pps_tio_get_time(struct pps_gen_device *pps_gen,
@@ -206,6 +217,7 @@ static int pps_gen_tio_probe(struct platform_device *pdev)
tio = devm_kzalloc_obj(dev, *tio);
if (!tio)
return -ENOMEM;
+ mutex_init(&tio->mutex);
tio->gen_info.use_system_clock = true;
tio->gen_info.enable = pps_tio_gen_enable;
@@ -233,9 +245,14 @@ static int pps_gen_tio_probe(struct platform_device *pdev)
static void pps_gen_tio_remove(struct platform_device *pdev)
{
struct pps_tio *tio = platform_get_drvdata(pdev);
+ unsigned long flags;
+ mutex_lock(&tio->mutex);
hrtimer_cancel(&tio->timer);
+ spin_lock_irqsave(&tio->lock, flags);
pps_tio_disable(tio);
+ spin_unlock_irqrestore(&tio->lock, flags);
+ mutex_unlock(&tio->mutex);
pps_gen_unregister_source(tio->pps_gen);
}
--
2.43.0
next prev parent reply other threads:[~2026-12-02 9:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 17:21 [PATCH 0/4] pps: add Intel Timed I/O PPS input support KhaiWenTan
2026-12-02 17:21 ` [PATCH 1/4] pps: generators: synchronize sysfs and registration failure KhaiWenTan
2026-12-02 17:21 ` KhaiWenTan [this message]
2026-12-02 17:21 ` [PATCH 3/4] pps: generators: move TIO ownership to auxiliary parent KhaiWenTan
2026-12-02 17:21 ` [PATCH 4/4] pps: clients: add Intel TIO PPS capture KhaiWenTan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202172254.1188109-3-khai.wen.tan@linux.intel.com \
--to=khai.wen.tan@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=christopher.s.hall@intel.com \
--cc=corbet@lwn.net \
--cc=david.zage@intel.com \
--cc=giometti@enneenne.com \
--cc=gregkh@linuxfoundation.org \
--cc=hong.aun.looi@intel.com \
--cc=khai.wen.tan@intel.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=weifeng.voon@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®