diff mbox series

[v2,1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context

Message ID 20201117103751.16131-1-lars@metafoo.de (mailing list archive)
State New, archived
Headers show
Series [v2,1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context | expand

Commit Message

Lars-Peter Clausen Nov. 17, 2020, 10:37 a.m. UTC
On PREEMPT_RT enabled kernels unmarked hrtimers are moved into soft
interrupt expiry mode by default.

The IIO hrtimer-trigger needs to run in hard interrupt context since it
will end up calling generic_handle_irq() which has the requirement to run
in hard interrupt context.

Explicitly specify that the timer needs to run in hard interrupt context by
using the HRTIMER_MODE_REL_HARD flag.

Fixes: f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")
Reported-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
Changes since v1:
	* Also pass HRTIMER_MODE_REL_HARD to hrtimer_start().
---
 drivers/iio/trigger/iio-trig-hrtimer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Sebastian Andrzej Siewior Nov. 17, 2020, 1:03 p.m. UTC | #1
On 2020-11-17 11:37:50 [+0100], Lars-Peter Clausen wrote:
> On PREEMPT_RT enabled kernels unmarked hrtimers are moved into soft
> interrupt expiry mode by default.
> 
> The IIO hrtimer-trigger needs to run in hard interrupt context since it
> will end up calling generic_handle_irq() which has the requirement to run
> in hard interrupt context.
> 
> Explicitly specify that the timer needs to run in hard interrupt context by
> using the HRTIMER_MODE_REL_HARD flag.
> 
> Fixes: f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")
> Reported-by: Christian Eggers <ceggers@arri.de>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

If I remember correctly, this routine should only be used to poll the
primary handler. There were patches for the "other" possible things that
might happen so

Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

for both.

Sebastian
Jonathan Cameron Nov. 21, 2020, 4:12 p.m. UTC | #2
On Tue, 17 Nov 2020 14:03:01 +0100
Sebastian Andrzej Siewior <bigeasy@linutronix.de> wrote:

> On 2020-11-17 11:37:50 [+0100], Lars-Peter Clausen wrote:
> > On PREEMPT_RT enabled kernels unmarked hrtimers are moved into soft
> > interrupt expiry mode by default.
> > 
> > The IIO hrtimer-trigger needs to run in hard interrupt context since it
> > will end up calling generic_handle_irq() which has the requirement to run
> > in hard interrupt context.
> > 
> > Explicitly specify that the timer needs to run in hard interrupt context by
> > using the HRTIMER_MODE_REL_HARD flag.
> > 
> > Fixes: f5c2f0215e36 ("hrtimer: Move unmarked hrtimers to soft interrupt expiry on RT")
> > Reported-by: Christian Eggers <ceggers@arri.de>
> > Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>  
> 
> If I remember correctly, this routine should only be used to poll the
> primary handler. There were patches for the "other" possible things that
> might happen so
> 
> Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
I've applied them both to the fixes-togreg branch fo iio.git but not
marked them for stable. If you want them in specific stable releases
then please request them explicitly after they've merged.

Thanks,

Jonathan

> 
> for both.
> 
> Sebastian
diff mbox series

Patch

diff --git a/drivers/iio/trigger/iio-trig-hrtimer.c b/drivers/iio/trigger/iio-trig-hrtimer.c
index f59bf8d58586..410de837d041 100644
--- a/drivers/iio/trigger/iio-trig-hrtimer.c
+++ b/drivers/iio/trigger/iio-trig-hrtimer.c
@@ -102,7 +102,7 @@  static int iio_trig_hrtimer_set_state(struct iio_trigger *trig, bool state)
 
 	if (state)
 		hrtimer_start(&trig_info->timer, trig_info->period,
-			      HRTIMER_MODE_REL);
+			      HRTIMER_MODE_REL_HARD);
 	else
 		hrtimer_cancel(&trig_info->timer);
 
@@ -132,7 +132,7 @@  static struct iio_sw_trigger *iio_trig_hrtimer_probe(const char *name)
 	trig_info->swt.trigger->ops = &iio_hrtimer_trigger_ops;
 	trig_info->swt.trigger->dev.groups = iio_hrtimer_attr_groups;
 
-	hrtimer_init(&trig_info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+	hrtimer_init(&trig_info->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_HARD);
 	trig_info->timer.function = iio_hrtimer_trig_handler;
 
 	trig_info->sampling_frequency = HRTIMER_DEFAULT_SAMPLING_FREQUENCY;