All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpiolib: fix line event timestamps for nested irqs
@ 2019-01-04 10:32 Bartosz Golaszewski
  2019-01-11 12:19 ` Linus Walleij
  0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2019-01-04 10:32 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Nested interrupts run inside the calling thread's context and the top
half handler is never called which means that we never read the
timestamp.

This issue came up when trying to read line events from a gpiochip
using regmap_irq_chip for interrupts.

Fix it by reading the timestamp from the irq thread function if it's
still 0 by the time the second handler is called.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
---
 drivers/gpio/gpiolib.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1651d7f0a303..330c52e19b7e 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -828,6 +828,13 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p)
 	/* Do not leak kernel stack to userspace */
 	memset(&ge, 0, sizeof(ge));
 
+	/*
+	 * We may be running from a nested threaded interrupt in which case
+	 * we didn't get the timestamp from lineevent_irq_handler().
+	 */
+	if (!le->timestamp)
+		le->timestamp = ktime_get_real_ns();
+
 	ge.timestamp = le->timestamp;
 
 	if (le->eflags & GPIOEVENT_REQUEST_RISING_EDGE
-- 
2.19.1

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

* Re: [PATCH] gpiolib: fix line event timestamps for nested irqs
  2019-01-04 10:32 [PATCH] gpiolib: fix line event timestamps for nested irqs Bartosz Golaszewski
@ 2019-01-11 12:19 ` Linus Walleij
  2019-01-11 13:45   ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Walleij @ 2019-01-11 12:19 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski

On Fri, Jan 4, 2019 at 11:32 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Nested interrupts run inside the calling thread's context and the top
> half handler is never called which means that we never read the
> timestamp.
>
> This issue came up when trying to read line events from a gpiochip
> using regmap_irq_chip for interrupts.
>
> Fix it by reading the timestamp from the irq thread function if it's
> still 0 by the time the second handler is called.
>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Oh that's right. Should this not have Fixes: and Cc: stable?

> +       /*
> +        * We may be running from a nested threaded interrupt in which case
> +        * we didn't get the timestamp from lineevent_irq_handler().
> +        */
> +       if (!le->timestamp)
> +               le->timestamp = ktime_get_real_ns();
> +
>         ge.timestamp = le->timestamp;

I would merge these:

if (!le->timestamp)
    ge.timestamp = ktime_get_real_ns();
else
    ge.timestamp = le->timestamp;

Yours,
Linus Walleij

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

* Re: [PATCH] gpiolib: fix line event timestamps for nested irqs
  2019-01-11 12:19 ` Linus Walleij
@ 2019-01-11 13:45   ` Bartosz Golaszewski
  0 siblings, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2019-01-11 13:45 UTC (permalink / raw)
  To: Linus Walleij; +Cc: open list:GPIO SUBSYSTEM, linux-kernel, Bartosz Golaszewski

pt., 11 sty 2019 o 13:19 Linus Walleij <linus.walleij@linaro.org> napisał(a):
>
> On Fri, Jan 4, 2019 at 11:32 AM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> > From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> >
> > Nested interrupts run inside the calling thread's context and the top
> > half handler is never called which means that we never read the
> > timestamp.
> >
> > This issue came up when trying to read line events from a gpiochip
> > using regmap_irq_chip for interrupts.
> >
> > Fix it by reading the timestamp from the irq thread function if it's
> > still 0 by the time the second handler is called.
> >
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> Oh that's right. Should this not have Fixes: and Cc: stable?
>
> > +       /*
> > +        * We may be running from a nested threaded interrupt in which case
> > +        * we didn't get the timestamp from lineevent_irq_handler().
> > +        */
> > +       if (!le->timestamp)
> > +               le->timestamp = ktime_get_real_ns();
> > +
> >         ge.timestamp = le->timestamp;
>
> I would merge these:
>
> if (!le->timestamp)
>     ge.timestamp = ktime_get_real_ns();
> else
>     ge.timestamp = le->timestamp;
>
> Yours,
> Linus Walleij

I'll fix both issues and resend.

Bart

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

end of thread, other threads:[~2019-01-11 13:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-04 10:32 [PATCH] gpiolib: fix line event timestamps for nested irqs Bartosz Golaszewski
2019-01-11 12:19 ` Linus Walleij
2019-01-11 13:45   ` Bartosz Golaszewski

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.