All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context
@ 2020-11-17 10:37 Lars-Peter Clausen
  2020-11-17 10:37 ` [PATCH v2 2/2] iio: sysfs-trigger: Mark irq_work to expire in hardirq context Lars-Peter Clausen
  2020-11-17 13:03 ` [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context Sebastian Andrzej Siewior
  0 siblings, 2 replies; 4+ messages in thread
From: Lars-Peter Clausen @ 2020-11-17 10:37 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Peter Meerwald-Stadler, Sebastian Andrzej Siewior,
	Christian Eggers, Thomas Gleixner, linux-iio, Lars-Peter Clausen

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(-)

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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] iio: sysfs-trigger: Mark irq_work to expire in hardirq context
  2020-11-17 10:37 [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context Lars-Peter Clausen
@ 2020-11-17 10:37 ` Lars-Peter Clausen
  2020-11-17 13:03 ` [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context Sebastian Andrzej Siewior
  1 sibling, 0 replies; 4+ messages in thread
From: Lars-Peter Clausen @ 2020-11-17 10:37 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Peter Meerwald-Stadler, Sebastian Andrzej Siewior,
	Christian Eggers, Thomas Gleixner, linux-iio, Lars-Peter Clausen

Mark the IIO sysfs-trigger irq_work with IRQ_WORK_HARD_IRQ to ensure that
it is always executed in hard interrupt context, even with PREEMPT_RT=y.

The IIO sysfs-trigger irq_work 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.

Note that the IRQ_WORK_HARD_IRQ flag, while it exists, does not seem to do
anything in the mainline kernel yet. It does have an effect in the RT
patchset though and presumably this is sooner or later going to be added to
mainline as well.

Reported-by: Christian Eggers <ceggers@arri.de>
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
No changes since v1.
---
 drivers/iio/trigger/iio-trig-sysfs.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/trigger/iio-trig-sysfs.c b/drivers/iio/trigger/iio-trig-sysfs.c
index e09e58072872..10a3fd29362b 100644
--- a/drivers/iio/trigger/iio-trig-sysfs.c
+++ b/drivers/iio/trigger/iio-trig-sysfs.c
@@ -161,6 +161,7 @@ static int iio_sysfs_trigger_probe(int id)
 	iio_trigger_set_drvdata(t->trig, t);
 
 	init_irq_work(&t->work, iio_sysfs_trigger_work);
+	atomic_set(&t->work.flags, IRQ_WORK_HARD_IRQ);
 
 	ret = iio_trigger_register(t->trig);
 	if (ret)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context
  2020-11-17 10:37 [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context Lars-Peter Clausen
  2020-11-17 10:37 ` [PATCH v2 2/2] iio: sysfs-trigger: Mark irq_work to expire in hardirq context Lars-Peter Clausen
@ 2020-11-17 13:03 ` Sebastian Andrzej Siewior
  2020-11-21 16:12   ` Jonathan Cameron
  1 sibling, 1 reply; 4+ messages in thread
From: Sebastian Andrzej Siewior @ 2020-11-17 13:03 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Peter Meerwald-Stadler, Christian Eggers,
	Thomas Gleixner, linux-iio

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context
  2020-11-17 13:03 ` [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context Sebastian Andrzej Siewior
@ 2020-11-21 16:12   ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2020-11-21 16:12 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Lars-Peter Clausen, Peter Meerwald-Stadler, Christian Eggers,
	Thomas Gleixner, linux-iio

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-21 16:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-17 10:37 [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context Lars-Peter Clausen
2020-11-17 10:37 ` [PATCH v2 2/2] iio: sysfs-trigger: Mark irq_work to expire in hardirq context Lars-Peter Clausen
2020-11-17 13:03 ` [PATCH v2 1/2] iio: hrtimer-trigger: Mark hrtimer to expire in hard interrupt context Sebastian Andrzej Siewior
2020-11-21 16:12   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.