* [PATCH] gpio: initialize descriptor SRCU structure before adding OF-based chips
@ 2024-02-12 21:39 Bartosz Golaszewski
2024-02-13 14:42 ` Andy Shevchenko
2024-02-14 8:35 ` Bartosz Golaszewski
0 siblings, 2 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2024-02-12 21:39 UTC (permalink / raw)
To: Linus Walleij, Kent Gibson, Alex Elder, Geert Uytterhoeven,
Paul E . McKenney, Andy Shevchenko, Wolfram Sang
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, kernel test robot
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
In certain situations we may end up taking the GPIO descriptor SRCU read
lock in of_gpiochip_add() before the SRCU struct is initialized. Move
the initialization before the call to of_gpiochip_add().
Fixes: be711caa87c5 ("gpio: add SRCU infrastructure to struct gpio_desc")
Fixes: 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202402122228.e607a080-lkp@intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpiolib.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 82811d9a4477..f5434e559382 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -991,10 +991,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
if (ret)
goto err_cleanup_gdev_srcu;
- ret = of_gpiochip_add(gc);
- if (ret)
- goto err_free_gpiochip_mask;
-
for (i = 0; i < gc->ngpio; i++) {
struct gpio_desc *desc = &gdev->descs[i];
@@ -1002,7 +998,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
if (ret) {
for (j = 0; j < i; j++)
cleanup_srcu_struct(&gdev->descs[j].srcu);
- goto err_remove_of_chip;
+ goto err_free_gpiochip_mask;
}
if (gc->get_direction && gpiochip_line_is_valid(gc, i)) {
@@ -1014,10 +1010,14 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
}
}
- ret = gpiochip_add_pin_ranges(gc);
+ ret = of_gpiochip_add(gc);
if (ret)
goto err_cleanup_desc_srcu;
+ ret = gpiochip_add_pin_ranges(gc);
+ if (ret)
+ goto err_remove_of_chip;
+
acpi_gpiochip_add(gc);
machine_gpiochip_add(gc);
@@ -1055,12 +1055,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
gpiochip_irqchip_free_valid_mask(gc);
err_remove_acpi_chip:
acpi_gpiochip_remove(gc);
-err_cleanup_desc_srcu:
- for (i = 0; i < gdev->ngpio; i++)
- cleanup_srcu_struct(&gdev->descs[i].srcu);
err_remove_of_chip:
gpiochip_free_hogs(gc);
of_gpiochip_remove(gc);
+err_cleanup_desc_srcu:
+ for (i = 0; i < gdev->ngpio; i++)
+ cleanup_srcu_struct(&gdev->descs[i].srcu);
err_free_gpiochip_mask:
gpiochip_remove_pin_ranges(gc);
gpiochip_free_valid_mask(gc);
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] gpio: initialize descriptor SRCU structure before adding OF-based chips
2024-02-12 21:39 [PATCH] gpio: initialize descriptor SRCU structure before adding OF-based chips Bartosz Golaszewski
@ 2024-02-13 14:42 ` Andy Shevchenko
2024-02-13 15:05 ` Bartosz Golaszewski
2024-02-14 8:35 ` Bartosz Golaszewski
1 sibling, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2024-02-13 14:42 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Linus Walleij, Kent Gibson, Alex Elder, Geert Uytterhoeven,
Paul E . McKenney, Wolfram Sang, linux-gpio, linux-kernel,
Bartosz Golaszewski, kernel test robot
On Mon, Feb 12, 2024 at 10:39:20PM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> In certain situations we may end up taking the GPIO descriptor SRCU read
> lock in of_gpiochip_add() before the SRCU struct is initialized. Move
> the initialization before the call to of_gpiochip_add().
...
This is a bit unclear why you moved to that place and how it had been tested.
> @@ -991,10 +991,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
> if (ret)
> goto err_cleanup_gdev_srcu;
>
> - ret = of_gpiochip_add(gc);
> - if (ret)
> - goto err_free_gpiochip_mask;
> -
> for (i = 0; i < gc->ngpio; i++) {
> struct gpio_desc *desc = &gdev->descs[i];
>
> if (ret) {
> for (j = 0; j < i; j++)
> cleanup_srcu_struct(&gdev->descs[j].srcu);
> - goto err_remove_of_chip;
> + goto err_free_gpiochip_mask;
> }
>
> if (gc->get_direction && gpiochip_line_is_valid(gc, i)) {
> }
> }
>
> - ret = gpiochip_add_pin_ranges(gc);
> + ret = of_gpiochip_add(gc);
> if (ret)
> goto err_cleanup_desc_srcu;
>
> + ret = gpiochip_add_pin_ranges(gc);
> + if (ret)
> + goto err_remove_of_chip;
> +
> acpi_gpiochip_add(gc);
My logic tells me that if you need to call gpiochip_add_pin_ranges() before
calling of_gpiochip_add(). It won't collide right now, but allows to cleanup
further (with the gpio-ranges parser be generalized for fwnodes and be moved
to gpiolib.c from gpiolib-of.c).
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] gpio: initialize descriptor SRCU structure before adding OF-based chips
2024-02-13 14:42 ` Andy Shevchenko
@ 2024-02-13 15:05 ` Bartosz Golaszewski
0 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2024-02-13 15:05 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Linus Walleij, Kent Gibson, Alex Elder, Geert Uytterhoeven,
Paul E . McKenney, Wolfram Sang, linux-gpio, linux-kernel,
Bartosz Golaszewski, kernel test robot
On Tue, Feb 13, 2024 at 3:43 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Mon, Feb 12, 2024 at 10:39:20PM +0100, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > In certain situations we may end up taking the GPIO descriptor SRCU read
> > lock in of_gpiochip_add() before the SRCU struct is initialized. Move
> > the initialization before the call to of_gpiochip_add().
>
> ...
>
> This is a bit unclear why you moved to that place and how it had been tested.
>
I didn't move it, I just added SRCU before it. It can be triggered by
a simple hog from DT. The link leads to a crash report.
> > @@ -991,10 +991,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
> > if (ret)
> > goto err_cleanup_gdev_srcu;
> >
> > - ret = of_gpiochip_add(gc);
> > - if (ret)
> > - goto err_free_gpiochip_mask;
> > -
> > for (i = 0; i < gc->ngpio; i++) {
> > struct gpio_desc *desc = &gdev->descs[i];
> >
>
> > if (ret) {
> > for (j = 0; j < i; j++)
> > cleanup_srcu_struct(&gdev->descs[j].srcu);
> > - goto err_remove_of_chip;
> > + goto err_free_gpiochip_mask;
> > }
> >
> > if (gc->get_direction && gpiochip_line_is_valid(gc, i)) {
>
> > }
> > }
> >
> > - ret = gpiochip_add_pin_ranges(gc);
> > + ret = of_gpiochip_add(gc);
> > if (ret)
> > goto err_cleanup_desc_srcu;
> >
> > + ret = gpiochip_add_pin_ranges(gc);
> > + if (ret)
> > + goto err_remove_of_chip;
> > +
> > acpi_gpiochip_add(gc);
>
> My logic tells me that if you need to call gpiochip_add_pin_ranges() before
> calling of_gpiochip_add(). It won't collide right now, but allows to cleanup
> further (with the gpio-ranges parser be generalized for fwnodes and be moved
> to gpiolib.c from gpiolib-of.c).
>
But it was already called before gpiochip_add_pin_ranges() so it's
material for another patch.
Bart
> --
> With Best Regards,
> Andy Shevchenko
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] gpio: initialize descriptor SRCU structure before adding OF-based chips
2024-02-12 21:39 [PATCH] gpio: initialize descriptor SRCU structure before adding OF-based chips Bartosz Golaszewski
2024-02-13 14:42 ` Andy Shevchenko
@ 2024-02-14 8:35 ` Bartosz Golaszewski
1 sibling, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2024-02-14 8:35 UTC (permalink / raw)
To: Linus Walleij, Kent Gibson, Alex Elder, Geert Uytterhoeven,
Paul E . McKenney, Andy Shevchenko, Wolfram Sang
Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, kernel test robot
On Mon, Feb 12, 2024 at 10:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> In certain situations we may end up taking the GPIO descriptor SRCU read
> lock in of_gpiochip_add() before the SRCU struct is initialized. Move
> the initialization before the call to of_gpiochip_add().
>
> Fixes: be711caa87c5 ("gpio: add SRCU infrastructure to struct gpio_desc")
> Fixes: 1f2bcb8c8ccd ("gpio: protect the descriptor label with SRCU")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202402122228.e607a080-lkp@intel.com
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> ---
I'm queuing this quickly because next is currently broken for many platforms.
Bartosz
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-14 8:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-12 21:39 [PATCH] gpio: initialize descriptor SRCU structure before adding OF-based chips Bartosz Golaszewski
2024-02-13 14:42 ` Andy Shevchenko
2024-02-13 15:05 ` Bartosz Golaszewski
2024-02-14 8:35 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox