All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
@ 2026-11-26  8:42 Zqiang
  2026-11-26  8:42 ` [PATCH] gpiolib: Use srcu_dereference() in gpiod_get_label() Zqiang
  2026-11-26  8:52 ` [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release() sashiko-bot
  0 siblings, 2 replies; 9+ messages in thread
From: Zqiang @ 2026-11-26  8:42 UTC (permalink / raw)
  To: linusw, brgl, paulmck; +Cc: linux-gpio, linux-kernel, qiang.zhang

The gpio_desc_label object are freed asynchronously via call_srcu() on
gdev->desc_srcu (see desc_set_label()). to drain these pending SRCU
callbacks before cleanup the SRCU structure, gpiodev_release() currently
calls synchronize_srcu(&gdev->desc_srcu).

However, synchronize_srcu() only waits for a grace period to elapse and
for its own wakeme_after_rcu callback to be invoked. it does not guarantee
that callbacks queued on other CPUs have actually been invoked by the time
it returns. The following race may happen:

              CPUA                                        CPUB
call_srcu(desc_srcu, desc_free_label)

                                               gpiodev_release()
                                               ->synchronize_srcu()
                                                 ->call_srcu() queue wakeme_after_rcu()

SRCU GP end
timer_reduce(delay_work)

                                               SRCU GP end
                                                synchronize_srcu() return
                                               ->cleanup_srcu_struct()
/* timer still pending! */                        ->for CPUA timer_delete_sync() return true
                                                    and cblist not empty. tigger WARN_ON()

This commit therefore use srcu_barrier() instead of synchronize_srcu() on
gdev->desc_srcu,  it entrains a barrier callback on every CPU that has callbacks
queued and waits until all of them have been invoked.

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index c09342fc52cb..5dd4d142cf52 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -898,7 +898,7 @@ static void gpiodev_release(struct device *dev)
 	struct gpio_device *gdev = to_gpio_device(dev);
 
 	/* Call pending kfree()s for descriptor labels. */
-	synchronize_srcu(&gdev->desc_srcu);
+	srcu_barrier(&gdev->desc_srcu);
 	cleanup_srcu_struct(&gdev->desc_srcu);
 
 	if (gdev->line_state_wq)
-- 
2.17.1


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

* [PATCH] gpiolib: Use srcu_dereference() in gpiod_get_label()
  2026-11-26  8:42 [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release() Zqiang
@ 2026-11-26  8:42 ` Zqiang
  2026-11-26 14:59   ` Bartosz Golaszewski
  2026-11-26  8:52 ` [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release() sashiko-bot
  1 sibling, 1 reply; 9+ messages in thread
From: Zqiang @ 2026-11-26  8:42 UTC (permalink / raw)
  To: linusw, brgl, paulmck; +Cc: linux-gpio, linux-kernel, qiang.zhang

The srcu_dereference_check() already evaluates 'srcu_read_lock_held(ssp)'
internally, so passing srcu_read_lock_held() as the extra condition is
redundant. all callers of gpiod_get_label() hold the desc_srcu read lock,
so replace it with srcu_dereference(), which provides identical lockdep
coverage.

No functional changes.

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 drivers/gpio/gpiolib.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5dd4d142cf52..47ce89bfb578 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -124,8 +124,7 @@ const char *gpiod_get_label(struct gpio_desc *desc)
 
 	flags = READ_ONCE(desc->flags);
 
-	label = srcu_dereference_check(desc->label, &desc->gdev->desc_srcu,
-				srcu_read_lock_held(&desc->gdev->desc_srcu));
+	label = srcu_dereference(desc->label, &desc->gdev->desc_srcu);
 
 	if (test_bit(GPIOD_FLAG_USED_AS_IRQ, &flags))
 		return label ? label->str : "interrupt";
-- 
2.17.1


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

* Re: [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
  2026-11-26  8:42 [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release() Zqiang
  2026-11-26  8:42 ` [PATCH] gpiolib: Use srcu_dereference() in gpiod_get_label() Zqiang
@ 2026-11-26  8:52 ` sashiko-bot
  1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-26  8:52 UTC (permalink / raw)
  To: Zqiang; +Cc: linux-gpio

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] gpiolib: missing Fixes trailer for srcu_barrier() fix in
  gpiodev_release()
--

commit a9a1a00addf42a3f612e043479c9501ad1c6053c
Author: Zqiang <qiang.zhang@linux.dev>

> gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
>
> The gpio_desc_label object are freed asynchronously via call_srcu() on
> gdev->desc_srcu (see desc_set_label()). to drain these pending SRCU
> callbacks before cleanup the SRCU structure, gpiodev_release() currently
> calls synchronize_srcu(&gdev->desc_srcu).
>
> However, synchronize_srcu() only waits for a grace period to elapse and
> for its own wakeme_after_rcu callback to be invoked. it does not guarantee
> that callbacks queued on other CPUs have actually been invoked by the time
> it returns. The following race may happen:
>
>               CPUA                                        CPUB
> call_srcu(desc_srcu, desc_free_label)
>
>                                                gpiodev_release()
>                                                ->synchronize_srcu()
>                                                  ->call_srcu() queue wakeme_after_rcu()
>
> SRCU GP end
> timer_reduce(delay_work)
>
>                                                SRCU GP end
>                                                 synchronize_srcu() return
>                                                ->cleanup_srcu_struct()
> /* timer still pending! */                        ->for CPUA timer_delete_sync() return true
>                                                     and cblist not empty. tigger WARN_ON()
>
> This commit therefore use srcu_barrier() instead of synchronize_srcu() on
> gdev->desc_srcu,  it entrains a barrier callback on every CPU that has callbacks
> queued and waits until all of them have been invoked.
>
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>

[Severity: Low]
Since this fixes the use of synchronize_srcu() to drain call_srcu()
callbacks before cleanup_srcu_struct() in gpiodev_release(), should this
include:

  Fixes: a86d27693066 ("gpiolib: fix the speed of descriptor label setting with SRCU")
  Fixes: 7765ffed533d ("gpiolib: use a single SRCU struct for all GPIO descriptors")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126084233.17381-1-qiang.zhang@linux.dev?part=1

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

* Re: [PATCH] gpiolib: Use srcu_dereference() in gpiod_get_label()
  2026-11-26  8:42 ` [PATCH] gpiolib: Use srcu_dereference() in gpiod_get_label() Zqiang
@ 2026-11-26 14:59   ` Bartosz Golaszewski
  2026-11-26 23:11     ` Zqiang
  0 siblings, 1 reply; 9+ messages in thread
From: Bartosz Golaszewski @ 2026-11-26 14:59 UTC (permalink / raw)
  To: Zqiang; +Cc: linusw, paulmck, linux-gpio, linux-kernel

On Thu, Nov 26, 2026 at 04:42:33PM +0800, Zqiang wrote:
> The srcu_dereference_check() already evaluates 'srcu_read_lock_held(ssp)'
> internally, so passing srcu_read_lock_held() as the extra condition is
> redundant. all callers of gpiod_get_label() hold the desc_srcu read lock,
> so replace it with srcu_dereference(), which provides identical lockdep
> coverage.
> 
> No functional changes.
> 
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> ---
>  drivers/gpio/gpiolib.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 5dd4d142cf52..47ce89bfb578 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -124,8 +124,7 @@ const char *gpiod_get_label(struct gpio_desc *desc)
>  
>  	flags = READ_ONCE(desc->flags);
>  
> -	label = srcu_dereference_check(desc->label, &desc->gdev->desc_srcu,
> -				srcu_read_lock_held(&desc->gdev->desc_srcu));
> +	label = srcu_dereference(desc->label, &desc->gdev->desc_srcu);
>  
>  	if (test_bit(GPIOD_FLAG_USED_AS_IRQ, &flags))
>  		return label ? label->str : "interrupt";
> -- 
> 2.17.1
>

What is this patch? A v2 to the one it's replying to? A separate change
(in which case it should be a new thread, not a reply)?

I'm confused by this thread.

Bart

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

* Re: [PATCH] gpiolib: Use srcu_dereference() in gpiod_get_label()
  2026-11-26 14:59   ` Bartosz Golaszewski
@ 2026-11-26 23:11     ` Zqiang
  0 siblings, 0 replies; 9+ messages in thread
From: Zqiang @ 2026-11-26 23:11 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linusw, paulmck, linux-gpio, linux-kernel

> 
> On Thu, Nov 26, 2026 at 04:42:33PM +0800, Zqiang wrote:
> 
> > 
> > The srcu_dereference_check() already evaluates 'srcu_read_lock_held(ssp)'
> >  internally, so passing srcu_read_lock_held() as the extra condition is
> >  redundant. all callers of gpiod_get_label() hold the desc_srcu read lock,
> >  so replace it with srcu_dereference(), which provides identical lockdep
> >  coverage.
> >  
> >  No functional changes.
> >  
> >  Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> >  ---
> >  drivers/gpio/gpiolib.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >  
> >  diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> >  index 5dd4d142cf52..47ce89bfb578 100644
> >  --- a/drivers/gpio/gpiolib.c
> >  +++ b/drivers/gpio/gpiolib.c
> >  @@ -124,8 +124,7 @@ const char *gpiod_get_label(struct gpio_desc *desc)
> >  
> >  flags = READ_ONCE(desc->flags);
> >  
> >  - label = srcu_dereference_check(desc->label, &desc->gdev->desc_srcu,
> >  - srcu_read_lock_held(&desc->gdev->desc_srcu));
> >  + label = srcu_dereference(desc->label, &desc->gdev->desc_srcu);
> >  
> >  if (test_bit(GPIOD_FLAG_USED_AS_IRQ, &flags))
> >  return label ? label->str : "interrupt";
> >  -- 
> >  2.17.1
> > 
> What is this patch? A v2 to the one it's replying to? A separate change
> (in which case it should be a new thread, not a reply)?
> 
> I'm confused by this thread.

This are two separate thread, I sent them together at the time, but it seems
that the title was lost, sorry, I caused your misunderstanding, I will resend it.

Thanks
Zqiang


> 
> Bart
>

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

* [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
@ 2026-11-27  2:31 Zqiang
  2026-11-27  2:41 ` sashiko-bot
  2026-11-27  7:09 ` Adrian Ambrozewicz
  0 siblings, 2 replies; 9+ messages in thread
From: Zqiang @ 2026-11-27  2:31 UTC (permalink / raw)
  To: linusw, brgl, paulmck; +Cc: linux-gpio, linux-kernel, qiang.zhang

The gpio_desc_label object are freed asynchronously via call_srcu() on
gdev->desc_srcu (see desc_set_label()). to drain these pending SRCU
callbacks before cleanup the SRCU structure, gpiodev_release() currently
calls synchronize_srcu(&gdev->desc_srcu).

However, synchronize_srcu() only waits for a grace period to elapse and
for its own wakeme_after_rcu callback to be invoked. it does not guarantee
that callbacks queued on other CPUs have actually been invoked by the time
it returns. The following race may happen:

              CPUA                                        CPUB
call_srcu(desc_srcu, desc_free_label)

                                               gpiodev_release()
                                               ->synchronize_srcu()
                                                 ->call_srcu() queue wakeme_after_rcu()

SRCU GP end
timer_reduce(delay_work)

                                               SRCU GP end
                                                synchronize_srcu() return
                                               ->cleanup_srcu_struct()
/* timer still pending! */                        ->for CPUA timer_delete_sync() return true
                                                    and cblist not empty. tigger WARN_ON()

This commit therefore use srcu_barrier() instead of synchronize_srcu() on
gdev->desc_srcu,  it entrains a barrier callback on every CPU that has callbacks
queued and waits until all of them have been invoked.

Signed-off-by: Zqiang <qiang.zhang@linux.dev>
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index c09342fc52cb..5dd4d142cf52 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -898,7 +898,7 @@ static void gpiodev_release(struct device *dev)
 	struct gpio_device *gdev = to_gpio_device(dev);
 
 	/* Call pending kfree()s for descriptor labels. */
-	synchronize_srcu(&gdev->desc_srcu);
+	srcu_barrier(&gdev->desc_srcu);
 	cleanup_srcu_struct(&gdev->desc_srcu);
 
 	if (gdev->line_state_wq)
-- 
2.17.1


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

* Re: [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
  2026-11-27  2:31 Zqiang
@ 2026-11-27  2:41 ` sashiko-bot
  2026-11-27  7:09 ` Adrian Ambrozewicz
  1 sibling, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-27  2:41 UTC (permalink / raw)
  To: Zqiang; +Cc: linux-gpio

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] gpiolib: missing Fixes trailer for srcu_barrier() fix in
  gpiodev_release()
--

commit 7bde1b2938982ae74ae917349eb9ea19f1b65da8
Author: Zqiang <qiang.zhang@linux.dev>

> gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
>
> The gpio_desc_label object are freed asynchronously via call_srcu() on
> gdev->desc_srcu (see desc_set_label()). to drain these pending SRCU
> callbacks before cleanup the SRCU structure, gpiodev_release() currently
> calls synchronize_srcu(&gdev->desc_srcu).
>
> However, synchronize_srcu() only waits for a grace period to elapse and
> for its own wakeme_after_rcu callback to be invoked. it does not guarantee
> that callbacks queued on other CPUs have actually been invoked by the time
> it returns. The following race may happen:
>
>               CPUA                                        CPUB
> call_srcu(desc_srcu, desc_free_label)
>
>                                                gpiodev_release()
>                                                ->synchronize_srcu()
>                                                  ->call_srcu() queue wakeme_after_rcu()
>
> SRCU GP end
> timer_reduce(delay_work)
>
>                                                SRCU GP end
>                                                 synchronize_srcu() return
>                                                ->cleanup_srcu_struct()
> /* timer still pending! */                        ->for CPUA timer_delete_sync() return true
>                                                     and cblist not empty. tigger WARN_ON()
>
> This commit therefore use srcu_barrier() instead of synchronize_srcu() on
> gdev->desc_srcu,  it entrains a barrier callback on every CPU that has callbacks
> queued and waits until all of them have been invoked.
>
> Signed-off-by: Zqiang <qiang.zhang@linux.dev>

[Severity: Low]
Should this include a Fixes tag for commit 7765ffed533d ("gpiolib: use a
single SRCU struct for all GPIO descriptors") (or commit a86d27693066
("gpiolib: fix the speed of descriptor label setting with SRCU"), which
originally paired call_srcu() with synchronize_srcu() before
cleanup_srcu_struct())?

  Fixes: 7765ffed533d ("gpiolib: use a single SRCU struct for all GPIO descriptors")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261127023101.27568-1-qiang.zhang@linux.dev?part=1

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

* Re: [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
  2026-11-27  2:31 Zqiang
  2026-11-27  2:41 ` sashiko-bot
@ 2026-11-27  7:09 ` Adrian Ambrozewicz
  2026-11-27 11:39   ` Zqiang
  1 sibling, 1 reply; 9+ messages in thread
From: Adrian Ambrozewicz @ 2026-11-27  7:09 UTC (permalink / raw)
  To: Zqiang
  Cc: Linus Walleij, Bartosz Golaszewski, Paul E. McKenney, linux-gpio,
	linux-kernel

On Fri, Nov 27, 2026 at 10:31:01AM +0800, Zqiang wrote:
> The gpio_desc_label object are freed asynchronously via call_srcu() on
> gdev->desc_srcu (see desc_set_label()). to drain these pending SRCU
> callbacks before cleanup the SRCU structure, gpiodev_release() currently
> calls synchronize_srcu(&gdev->desc_srcu).

[...]

>  	/* Call pending kfree()s for descriptor labels. */
> -	synchronize_srcu(&gdev->desc_srcu);
> +	srcu_barrier(&gdev->desc_srcu);
>  	cleanup_srcu_struct(&gdev->desc_srcu);

Hi Zqiang,

Bartosz already has this exact change in gpio/for-current, applied on
2026-11-24 as commit c901e8fddd3a ("gpiolib: wait for pending label
frees before cleaning up desc_srcu"):

https://git.kernel.org/brgl/c/c901e8fddd3a23353bb12c9d93b9a5fc482ac8f5

It carries Fixes: a86d27693066 and Cc: stable.

Thanks,
Adrian

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

* Re: [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release()
  2026-11-27  7:09 ` Adrian Ambrozewicz
@ 2026-11-27 11:39   ` Zqiang
  0 siblings, 0 replies; 9+ messages in thread
From: Zqiang @ 2026-11-27 11:39 UTC (permalink / raw)
  To: Adrian Ambrozewicz
  Cc: Linus Walleij, Bartosz Golaszewski, Paul E. McKenney, linux-gpio,
	linux-kernel

> 
> On Fri, Nov 27, 2026 at 10:31:01AM +0800, Zqiang wrote:
> 
> > 
> > The gpio_desc_label object are freed asynchronously via call_srcu() on
> >  gdev->desc_srcu (see desc_set_label()). to drain these pending SRCU
> >  callbacks before cleanup the SRCU structure, gpiodev_release() currently
> >  calls synchronize_srcu(&gdev->desc_srcu).
> > 
> [...]
> 
> > 
> > /* Call pending kfree()s for descriptor labels. */
> >  - synchronize_srcu(&gdev->desc_srcu);
> >  + srcu_barrier(&gdev->desc_srcu);
> >  cleanup_srcu_struct(&gdev->desc_srcu);
> > 
> Hi Zqiang,
> 
> Bartosz already has this exact change in gpio/for-current, applied on
> 2026-11-24 as commit c901e8fddd3a ("gpiolib: wait for pending label
> frees before cleaning up desc_srcu"):
> 
> https://git.kernel.org/brgl/c/c901e8fddd3a23353bb12c9d93b9a5fc482ac8f5
> 
> It carries Fixes: a86d27693066 and Cc: stable.

Hi Adrian,

I didn't keep eye with the latest tree, Thank you very much for pointing it.

Thanks
Zqiang

> 
> Thanks,
> Adrian
>

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

end of thread, other threads:[~2026-11-27 11:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  8:42 [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release() Zqiang
2026-11-26  8:42 ` [PATCH] gpiolib: Use srcu_dereference() in gpiod_get_label() Zqiang
2026-11-26 14:59   ` Bartosz Golaszewski
2026-11-26 23:11     ` Zqiang
2026-11-26  8:52 ` [PATCH] gpiolib: Use srcu_barrier() instead of synchronize_srcu() in gpiodev_release() sashiko-bot
  -- strict thread matches above, loose matches on Subject: below --
2026-11-27  2:31 Zqiang
2026-11-27  2:41 ` sashiko-bot
2026-11-27  7:09 ` Adrian Ambrozewicz
2026-11-27 11:39   ` Zqiang

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.