[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240613092830.15761-1-brgl@bgdev.pl>
Date: Thu, 13 Jun 2024 11:28:28 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Linus Walleij <linus.walleij@...aro.org>,
Jonathan Corbet <corbet@....net>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Arnd Bergmann <arnd@...db.de>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc: linux-gpio@...r.kernel.org,
linux-doc@...r.kernel.org,
linux-kernel@...r.kernel.org,
Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: [PATCH v8 0/2] misc: add a virtual driver for testing the GPIO API
From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
The GPIO subsystem used to have a serious problem with undefined behavior
and use-after-free bugs on hot-unplug of GPIO chips. This can be
considered a corner-case by some as most GPIO controllers are enabled
early in the boot process and live until the system goes down but most
GPIO drivers do allow unbind over sysfs, many are loadable modules that
can be (force) unloaded and there are also GPIO devices that can be
dynamically detached, for instance CP2112 which is a USB GPIO expender.
Bugs can be triggered both from user-space as well as by in-kernel users.
We have the means of testing it from user-space via the character device
but the issues manifest themselves differently in the kernel.
This is a proposition of adding a new virtual driver - a configurable
GPIO consumer that can be configured over configfs (similarly to
gpio-sim) or described on the device-tree.
This driver is aimed as a helper in spotting any regressions in
hot-unplug handling in GPIOLIB.
v7 -> v8:
- move the driver to drivers/misc/ as it's not a GPIO provider and so
its place is not in drivers/gpio/
- rework the data structures to make them more compact using unions
- use correct string helpers for given use-cases
- drop dependency on the gpio/driver.h, string.h and kernel.h headers
- add a patch exporting to_ext_attribute() to be used by this driver
- various minor improvements suggested by Andy
Link to v7: https://lore.kernel.org/linux-gpio/20240527144054.155503-1-brgl@bgdev.pl/
v6 -> v7:
- this is a complete rewrite of the original idea, the entire interface
has changed so it warrants a new round of reviews
Link to v6: https://lore.kernel.org/linux-gpio/20230817184356.25020-1-brgl@bgdev.pl/
v5 -> v6:
- initialize the flags temp variables at declaration and hopefully make
Andy happy finally :)
v4 -> v5:
- add the gpio-consumer docs to the admin-guide/gpio/ index (reported
by kernel test robot <lkp@...el.com>)
v3 -> v4:
- fix the toggle value assignment
- use guard(mutex)() wherever we can return directly from the subsequent
function call
- use skip_spaces() + strim() to avoid having to do a memmove() when
stripping strings off whitespaces
- DON'T try to save a couple LOC in ifdefs if that makes them less
readable (Andy :) )
v2 -> v3:
- use cleanup.h interfaces
- add some clarifying commets
- more minor code tweaks
RFC -> v2:
- add documentation
- fix various issues pointed out by Andy: use struct_size() where
applicable, improve the logic when storing the 'live' property,
improve log messages, remove commas in terminators, etc.
Bartosz Golaszewski (2):
drivers: export to_ext_attr()
misc: gpio-virtuser: new virtual testing driver for the GPIO API
.../admin-guide/gpio/gpio-virtuser.rst | 176 ++
Documentation/admin-guide/gpio/index.rst | 1 +
MAINTAINERS | 8 +
drivers/base/core.c | 2 -
drivers/misc/Kconfig | 8 +
drivers/misc/Makefile | 1 +
drivers/misc/gpio-virtuser.c | 1790 +++++++++++++++++
include/linux/device.h | 6 +
8 files changed, 1990 insertions(+), 2 deletions(-)
create mode 100644 Documentation/admin-guide/gpio/gpio-virtuser.rst
create mode 100644 drivers/misc/gpio-virtuser.c
--
2.43.0
Powered by blists - more mailing lists