Re: [PATCH v3 07/24] gpio: protect the descriptor label with SRCU

Mark Brown
2024-02-13T21:16:37Z

[-- Attachment #1: Type: text/plain, Size: 4326 bytes --]

On Thu, Feb 08, 2024 at 10:59:03AM +0100, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> In order to ensure that the label is not freed while it's being
> accessed, let's protect it with SRCU and synchronize it everytime it's
> changed.

This patch, which is now in -next as 1f2bcb8c8ccd, appears to cause a
boot regression on imx8mp-verdin-nonwifi-dahlia with arm64 defconfig.
We die with an invalid pointer dereference after registering the GPIOs:

[ 1.973513] gpio gpiochip3: Static allocation of GPIO base is deprecated, use dynamic allocation.
[ 1.982467] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000078

...

[ 2.161467] Call trace:
[ 2.163915] check_init_srcu_struct+0x1c/0xa0
[ 2.168284] synchronize_srcu+0x1c/0x100
[ 2.172216] gpiod_request_commit+0xec/0x1e0
[ 2.176496] gpiochip_request_own_desc+0x58/0x124
[ 2.181205] gpiod_hog+0x74/0x140
[ 2.184529] of_gpiochip_add+0x208/0x370
[ 2.188456] gpiochip_add_data_with_key+0x720/0xf14

and a bisect appears to converge smoothly onto this commit. None of my
other platforms (including the i.MX8MP EVK with the same SoC in it) are
showing similar issues, I've not checked the CI systems and haven't done
any investigation beyond checking that the commit does look like it
could plausibly be related to the symptom.

You can see a full boot log at:

https://lava.sirena.org.uk/scheduler/job/579038

bisect log:

git bisect start
# good: [7b17b1384cd6454c4ea2744c8e8a06de0d27b5b3] Merge branch 'for-linux-next-fixes' of git://anongit.freedesktop.org/drm/drm-misc
git bisect good 7b17b1384cd6454c4ea2744c8e8a06de0d27b5b3
# bad: [46d4e2eb58e14c8935fa0e27d16d4c62ef82849a] Add linux-next specific files for 20240213
git bisect bad 46d4e2eb58e14c8935fa0e27d16d4c62ef82849a
# good: [f85363faaa040a9b9ac6502464a8b1ed7f711eab] Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git
git bisect good f85363faaa040a9b9ac6502464a8b1ed7f711eab
# good: [0ca88723ff14aa0a28d31772ef330f3eef97cba1] Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/ulfh/mmc.git
git bisect good 0ca88723ff14aa0a28d31772ef330f3eef97cba1
# good: [c9545b54561efbedfe184a97dd07b4cdd8176146] Merge branch 'usb-next' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git
git bisect good c9545b54561efbedfe184a97dd07b4cdd8176146
# good: [4e22a2de97fb3b37e241058a4f9b91f3245590ea] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git
git bisect good 4e22a2de97fb3b37e241058a4f9b91f3245590ea
# bad: [903a65bcdcda676e86b1504f909c6565b1bd9df2] Merge branch 'pwm/for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git
git bisect bad 903a65bcdcda676e86b1504f909c6565b1bd9df2
# good: [a3468cca30fe896b58f9f7b3bb5484f079010a12] Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux.git
git bisect good a3468cca30fe896b58f9f7b3bb5484f079010a12
# bad: [7fe595b3c3cf3f9b8f21fce72f1f48a2cb41522e] gpio: don't dereference gdev->chip in gpiochip_setup_dev()
git bisect bad 7fe595b3c3cf3f9b8f21fce72f1f48a2cb41522e
# good: [f57595788244a838deec2d3be375291327cbc035] gpio: vf610: allow disabling the vf610 driver
git bisect good f57595788244a838deec2d3be375291327cbc035
# good: [ccfb6ff4f6c0574e01fb16934fb60a46285c5f3f] gpio: don't set label from irq helpers
git bisect good ccfb6ff4f6c0574e01fb16934fb60a46285c5f3f
# bad: [b6f87adbacfab9001d08e56ac869e1c75734633d] gpio: remove unneeded code from gpio_device_get_desc()
git bisect bad b6f87adbacfab9001d08e56ac869e1c75734633d
# bad: [2a9101e875bc3aa6423b559e0ea43b2077f3be87] gpio: sysfs: use gpio_device_find() to iterate over existing devices
git bisect bad 2a9101e875bc3aa6423b559e0ea43b2077f3be87
# bad: [1f2bcb8c8ccdf9dc2e46f7986e1e22408506a6d6] gpio: protect the descriptor label with SRCU
git bisect bad 1f2bcb8c8ccdf9dc2e46f7986e1e22408506a6d6
# good: [be711caa87c5c81d5dc00b244cac3a0b775adb18] gpio: add SRCU infrastructure to struct gpio_desc
git bisect good be711caa87c5c81d5dc00b244cac3a0b775adb18
# first bad commit: [1f2bcb8c8ccdf9dc2e46f7986e1e22408506a6d6] gpio: protect the descriptor label with SRCU

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]