From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>,
Kent Gibson <warthog618@gmail.com>, Alex Elder <elder@linaro.org>,
Geert Uytterhoeven <geert+renesas@glider.be>,
"Paul E . McKenney" <paulmck@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Wolfram Sang <wsa@the-dreams.de>, Mark Brown <broonie@kernel.org>,
Dan Carpenter <dan.carpenter@linaro.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
kernel test robot <oliver.sang@intel.com>
Subject: [PATCH v2 3/4] gpio: use srcu_dereference() with SRCU-protected pointers
Date: Wed, 14 Feb 2024 09:44:18 +0100 [thread overview]
Message-ID: <20240214084419.6194-4-brgl@bgdev.pl> (raw)
In-Reply-To: <20240214084419.6194-1-brgl@bgdev.pl>
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Lockdep with CONFIG_PROVE_RCU enabled reports false positives about
suspicious rcu_dereference() usage. Let's silence it by using
srcu_dereference() which is the correct helper with SRCU.
Fixes: d83cee3d2bb1 ("gpio: protect the pointer to gpio_chip in gpio_device with SRCU")
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
drivers/gpio/gpiolib-sysfs.c | 5 +++--
drivers/gpio/gpiolib.c | 16 ++++++++--------
drivers/gpio/gpiolib.h | 3 ++-
3 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index 6285fa5afbb1..71ba2a774197 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -14,6 +14,7 @@
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/string.h>
+#include <linux/srcu.h>
#include <linux/sysfs.h>
#include <linux/types.h>
@@ -756,7 +757,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev)
guard(srcu)(&gdev->srcu);
- chip = rcu_dereference(gdev->chip);
+ chip = srcu_dereference(gdev->chip, &gdev->srcu);
if (!chip)
return -ENODEV;
@@ -800,7 +801,7 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev)
guard(srcu)(&gdev->srcu);
- chip = rcu_dereference(gdev->chip);
+ chip = srcu_dereference(gdev->chip, &gdev->srcu);
if (chip)
return;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 439d32d5aa38..b095f475805f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -109,7 +109,7 @@ const char *gpiod_get_label(struct gpio_desc *desc)
return "interrupt";
return test_bit(FLAG_REQUESTED, &flags) ?
- rcu_dereference(desc->label) : NULL;
+ srcu_dereference(desc->label, &desc->srcu) : NULL;
}
static int desc_set_label(struct gpio_desc *desc, const char *label)
@@ -447,7 +447,7 @@ static struct gpio_desc *gpio_name_to_desc(const char * const name)
srcu_read_lock_held(&gpio_devices_srcu)) {
guard(srcu)(&gdev->srcu);
- gc = rcu_dereference(gdev->chip);
+ gc = srcu_dereference(gdev->chip, &gdev->srcu);
if (!gc)
continue;
@@ -1190,7 +1190,7 @@ struct gpio_device *gpio_device_find(void *data,
srcu_read_lock_held(&gpio_devices_srcu)) {
guard(srcu)(&gdev->srcu);
- gc = rcu_dereference(gdev->chip);
+ gc = srcu_dereference(gdev->chip, &gdev->srcu);
if (gc && match(gc, data))
return gpio_device_get(gdev);
@@ -2978,7 +2978,7 @@ static int gpiod_get_raw_value_commit(const struct gpio_desc *desc)
guard(srcu)(&gdev->srcu);
- gc = rcu_dereference(gdev->chip);
+ gc = srcu_dereference(gdev->chip, &gdev->srcu);
if (!gc)
return -ENODEV;
@@ -3012,7 +3012,7 @@ static bool gpio_device_chip_cmp(struct gpio_device *gdev, struct gpio_chip *gc)
{
guard(srcu)(&gdev->srcu);
- return gc == rcu_dereference(gdev->chip);
+ return gc == srcu_dereference(gdev->chip, &gdev->srcu);
}
int gpiod_get_array_value_complex(bool raw, bool can_sleep,
@@ -3593,7 +3593,7 @@ int gpiod_to_irq(const struct gpio_desc *desc)
gdev = desc->gdev;
/* FIXME Cannot use gpio_chip_guard due to const desc. */
guard(srcu)(&gdev->srcu);
- gc = rcu_dereference(gdev->chip);
+ gc = srcu_dereference(gdev->chip, &gdev->srcu);
if (!gc)
return -ENODEV;
@@ -4787,7 +4787,7 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_device *gdev)
guard(srcu)(&gdev->srcu);
- gc = rcu_dereference(gdev->chip);
+ gc = srcu_dereference(gdev->chip, &gdev->srcu);
if (!gc) {
seq_puts(s, "Underlying GPIO chip is gone\n");
return;
@@ -4872,7 +4872,7 @@ static int gpiolib_seq_show(struct seq_file *s, void *v)
guard(srcu)(&gdev->srcu);
- gc = rcu_dereference(gdev->chip);
+ gc = srcu_dereference(gdev->chip, &gdev->srcu);
if (!gc) {
seq_printf(s, "%s%s: (dangling chip)",
priv->newline ? "\n" : "",
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index 07443d26cbca..ada36aa0f81a 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -202,7 +202,8 @@ DEFINE_CLASS(gpio_chip_guard,
_guard.gdev = desc->gdev;
_guard.idx = srcu_read_lock(&_guard.gdev->srcu);
- _guard.gc = rcu_dereference(_guard.gdev->chip);
+ _guard.gc = srcu_dereference(_guard.gdev->chip,
+ &_guard.gdev->srcu);
_guard;
}),
--
2.40.1
next prev parent reply other threads:[~2024-02-14 8:44 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 8:44 [PATCH v2 0/4] gpio: fix SRCU bugs Bartosz Golaszewski
2024-02-14 8:44 ` [PATCH v2 1/4] gpio: take the SRCU read lock in gpiod_hog() Bartosz Golaszewski
2024-02-14 8:44 ` [PATCH v2 2/4] gpio: cdev: use correct pointer accessors with SRCU Bartosz Golaszewski
2024-02-16 10:31 ` Marek Szyprowski
2024-02-16 10:50 ` Bartosz Golaszewski
2024-02-26 14:27 ` kernel test robot
2024-02-27 16:44 ` Bartosz Golaszewski
2024-02-14 8:44 ` Bartosz Golaszewski [this message]
2024-02-14 8:44 ` [PATCH v2 4/4] gpio: don't let lockdep complain about inherently dangerous RCU usage Bartosz Golaszewski
2024-02-14 12:53 ` [PATCH v2 0/4] gpio: fix SRCU bugs Andy Shevchenko
2024-02-14 13:02 ` Bartosz Golaszewski
2024-02-14 13:17 ` Mark Brown
2024-02-14 13:22 ` Bartosz Golaszewski
2024-02-14 18:44 ` Paul E. McKenney
2024-02-14 19:08 ` Bartosz Golaszewski
2024-02-14 20:44 ` Paul E. McKenney
2024-02-21 21:45 ` Linus Walleij
2024-02-15 7:43 ` Bartosz Golaszewski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240214084419.6194-4-brgl@bgdev.pl \
--to=brgl@bgdev.pl \
--cc=andriy.shevchenko@linux.intel.com \
--cc=bartosz.golaszewski@linaro.org \
--cc=broonie@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=elder@linaro.org \
--cc=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oliver.sang@intel.com \
--cc=paulmck@kernel.org \
--cc=warthog618@gmail.com \
--cc=wsa@the-dreams.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox