Re: [PATCH v3 22/24] gpio: protect the pointer to gpio_chip in gpio_device with SRCU

Bartosz Golaszewski
2024-02-12T16:56:36Z

On Mon, Feb 12, 2024 at 4:11 PM kernel test robot <oliver.sang@intel.com> wrote:
>
>
>
> Hello,
>
> kernel test robot noticed "WARNING:suspicious_RCU_usage" on:
>
> commit: c21131f83abc1f7227e7a6d5311e1df68bfa44e0 ("[PATCH v3 22/24] gpio: protect the pointer to gpio_chip in gpio_device with SRCU")
> url: https://github.com/intel-lab-lkp/linux/commits/Bartosz-Golaszewski/gpio-protect-the-list-of-GPIO-devices-with-SRCU/20240208-180822
> base: https://git.kernel.org/cgit/linux/kernel/git/brgl/linux.git gpio/for-next
> patch link: https://lore.kernel.org/all/20240208095920.8035-23-brgl@bgdev.pl/
> patch subject: [PATCH v3 22/24] gpio: protect the pointer to gpio_chip in gpio_device with SRCU
>
> in testcase: boot
>
> compiler: gcc-12
> test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G
>
> (please refer to attached dmesg/kmsg for entire log/backtrace)
>
>
> +-----------------------------------------------------------------+------------+------------+
> | | a3dfc11062 | c21131f83a |
> +-----------------------------------------------------------------+------------+------------+
> | drivers/gpio/gpiolib.c:#suspicious_rcu_dereference_check()usage | 0 | 8 |
> | drivers/gpio/gpiolib.h:#suspicious_rcu_dereference_check()usage | 0 | 8 |
> +-----------------------------------------------------------------+------------+------------+
>
>
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <oliver.sang@intel.com>
> | Closes: https://lore.kernel.org/oe-lkp/202402122234.d85cca9b-lkp@intel.com
>
>
>
> [ 76.432519][ T1] gpiochip_find_base_unlocked: found new base at 512
> [ 76.434591][ T1]
> [ 76.435240][ T1] =============================
> [ 76.436545][ T1] WARNING: suspicious RCU usage
> [ 76.437813][ T1] 6.8.0-rc1-00050-gc21131f83abc #1 Tainted: G N
> [ 76.439873][ T1] -----------------------------
> [ 76.441158][ T1] drivers/gpio/gpiolib.c:219 suspicious rcu_dereference_check() usage!
> [ 76.443364][ T1]
> [ 76.443364][ T1] other info that might help us debug this:
> [ 76.443364][ T1]
> [ 76.446059][ T1]
> [ 76.446059][ T1] rcu_scheduler_active = 2, debug_locks = 1
> [ 76.448217][ T1] 1 lock held by swapper/1:
> [ 76.449412][ T1] #0: ffff88816954f0f0 (&dev->mutex){....}-{3:3}, at: __driver_attach (drivers/base/dd.c:1216)
> [ 76.451938][ T1]
> [ 76.451938][ T1] stack backtrace:
> [ 76.453486][ T1] CPU: 0 PID: 1 Comm: swapper Tainted: G N 6.8.0-rc1-00050-gc21131f83abc #1
> [ 76.456114][ T1] Call Trace:
> [ 76.456936][ T1] <TASK>
> [ 76.457682][ T1] dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
> [ 76.458833][ T1] lockdep_rcu_suspicious (include/linux/context_tracking.h:153 kernel/locking/lockdep.c:6713)
> [ 76.460205][ T1] gpiod_to_chip (drivers/gpio/gpiolib.c:219 (discriminator 9))
> [ 76.461346][ T1] gpiod_hog (drivers/gpio/gpiolib.h:243 drivers/gpio/gpiolib.c:4502)

Ah, gpiod_hog() is not taking the SRCU read lock as it should. I'll send a fix.

Bart

[snip]