iio: trigger: Fix a scheduling whilst atomic issue seen on tsc2046
authorJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 17 Oct 2021 17:22:09 +0000 (18:22 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sun, 12 Dec 2021 17:12:18 +0000 (17:12 +0000)
commit9020ef659885f2622cfb386cc229b6d618362895
tree4ec57bef8fd6418acabcbe82e7790c80b168d323
parentfea251b6a5dbdf8ba8af64abcd013d66ab6b05ee
iio: trigger: Fix a scheduling whilst atomic issue seen on tsc2046

IIO triggers are software IRQ chips that split an incoming IRQ into
separate IRQs routed to all devices using the trigger.
When all consumers are done then a trigger callback reenable() is
called.  There are a few circumstances under which this can happen
in atomic context.

1) A single user of the trigger that calls the iio_trigger_done()
function from interrupt context.
2) A race between disconnecting the last device from a trigger and
the trigger itself sucessfully being disabled.

To avoid a resulting scheduling whilst atomic, close this second corner
by using schedule_work() to ensure the reenable is not done in atomic
context.

Note that drivers must be careful to manage the interaction of
set_state() and reenable() callbacks to ensure appropriate reference
counting if they are relying on the same hardware controls.

Deliberately taking this the slow path rather than via a fixes tree
because the error has hard to hit and I would like it to soak for a while
before hitting a release kernel.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Tested-by: Oleksij Rempel <o.rempel@pengutronix.de>
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20211017172209.112387-1-jic23@kernel.org
drivers/iio/industrialio-trigger.c
include/linux/iio/trigger.h