* [PATCH AUTOSEL 5.1 033/375] leds: avoid races with workqueue
[not found] <20190522192115.22666-1-sashal@kernel.org>
@ 2019-05-22 19:15 ` Sasha Levin
2019-05-24 22:55 ` Pavel Machek
0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2019-05-22 19:15 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Pavel Machek, Jacek Anaszewski, Sasha Levin, linux-leds
From: Pavel Machek <pavel@ucw.cz>
[ Upstream commit 0db37915d912e8dc6588f25da76d3ed36718d92f ]
There are races between "main" thread and workqueue. They manifest
themselves on Thinkpad X60:
This should result in LED blinking, but it turns it off instead:
root@amd:/data/pavel# cd /sys/class/leds/tpacpi\:\:power
root@amd:/sys/class/leds/tpacpi::power# echo timer > trigger
root@amd:/sys/class/leds/tpacpi::power# echo timer > trigger
It should be possible to transition from blinking to solid on by echo
0 > brightness; echo 1 > brightness... but that does not work, either,
if done too quickly.
Synchronization of the workqueue fixes both.
Fixes: 1afcadfcd184 ("leds: core: Use set_brightness_work for the blocking op")
Signed-off-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/leds/led-class.c | 1 +
drivers/leds/led-core.c | 5 +++++
2 files changed, 6 insertions(+)
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 3c7e3487b373b..85848c5da705f 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -57,6 +57,7 @@ static ssize_t brightness_store(struct device *dev,
if (state == LED_OFF)
led_trigger_remove(led_cdev);
led_set_brightness(led_cdev, state);
+ flush_work(&led_cdev->set_brightness_work);
ret = size;
unlock:
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index e3da7c03da1b5..e9ae7f87ab900 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -164,6 +164,11 @@ static void led_blink_setup(struct led_classdev *led_cdev,
unsigned long *delay_on,
unsigned long *delay_off)
{
+ /*
+ * If "set brightness to 0" is pending in workqueue, we don't
+ * want that to be reordered after blink_set()
+ */
+ flush_work(&led_cdev->set_brightness_work);
if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) &&
led_cdev->blink_set &&
!led_cdev->blink_set(led_cdev, delay_on, delay_off))
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH AUTOSEL 5.1 033/375] leds: avoid races with workqueue
2019-05-22 19:15 ` [PATCH AUTOSEL 5.1 033/375] leds: avoid races with workqueue Sasha Levin
@ 2019-05-24 22:55 ` Pavel Machek
2019-05-29 18:51 ` Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2019-05-24 22:55 UTC (permalink / raw)
To: Sasha Levin; +Cc: linux-kernel, stable, Jacek Anaszewski, linux-leds
[-- Attachment #1: Type: text/plain, Size: 2012 bytes --]
Hi!
Could we hold this patch for now?
> From: Pavel Machek <pavel@ucw.cz>
>
> [ Upstream commit 0db37915d912e8dc6588f25da76d3ed36718d92f ]
>
> There are races between "main" thread and workqueue. They manifest
> themselves on Thinkpad X60:
>
> This should result in LED blinking, but it turns it off instead:
>
> root@amd:/data/pavel# cd /sys/class/leds/tpacpi\:\:power
> root@amd:/sys/class/leds/tpacpi::power# echo timer > trigger
> root@amd:/sys/class/leds/tpacpi::power# echo timer > trigger
>
> It should be possible to transition from blinking to solid on by echo
> 0 > brightness; echo 1 > brightness... but that does not work, either,
> if done too quickly.
>
> Synchronization of the workqueue fixes both.
>
> Fixes: 1afcadfcd184 ("leds: core: Use set_brightness_work for the blocking op")
> Signed-off-by: Pavel Machek <pavel@ucw.cz>
> Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
> Signed-off-by: Sasha Levin <sashal@kernel.org>
> ---
> drivers/leds/led-class.c | 1 +
> drivers/leds/led-core.c | 5 +++++
> 2 files changed, 6 insertions(+)
> index e3da7c03da1b5..e9ae7f87ab900 100644
> --- a/drivers/leds/led-core.c
> +++ b/drivers/leds/led-core.c
> @@ -164,6 +164,11 @@ static void led_blink_setup(struct led_classdev *led_cdev,
> unsigned long *delay_on,
> unsigned long *delay_off)
> {
> + /*
> + * If "set brightness to 0" is pending in workqueue, we don't
> + * want that to be reordered after blink_set()
> + */
> + flush_work(&led_cdev->set_brightness_work);
> if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) &&
> led_cdev->blink_set &&
> !led_cdev->blink_set(led_cdev, delay_on, delay_off))
This part is likely buggy. It seems triggers are using this from
atomic context... ledtrig-disk for example.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH AUTOSEL 5.1 033/375] leds: avoid races with workqueue
2019-05-24 22:55 ` Pavel Machek
@ 2019-05-29 18:51 ` Sasha Levin
2019-06-17 15:57 ` Pavel Machek
0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2019-05-29 18:51 UTC (permalink / raw)
To: Pavel Machek; +Cc: linux-kernel, stable, Jacek Anaszewski, linux-leds
On Sat, May 25, 2019 at 12:55:05AM +0200, Pavel Machek wrote:
>Hi!
>
>Could we hold this patch for now?
Sure, dropped. Thanks!
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH AUTOSEL 5.1 033/375] leds: avoid races with workqueue
2019-05-29 18:51 ` Sasha Levin
@ 2019-06-17 15:57 ` Pavel Machek
0 siblings, 0 replies; 4+ messages in thread
From: Pavel Machek @ 2019-06-17 15:57 UTC (permalink / raw)
To: Sasha Levin; +Cc: linux-kernel, stable, Jacek Anaszewski, linux-leds
[-- Attachment #1: Type: text/plain, Size: 409 bytes --]
Hi!
> >Could we hold this patch for now?
>
> Sure, dropped. Thanks!
So... fix for this now should be in mainline. But as original problem
is not too severe, I don't think we need to apply this or the fixed
version to stable.
Best regards,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-06-17 15:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20190522192115.22666-1-sashal@kernel.org>
2019-05-22 19:15 ` [PATCH AUTOSEL 5.1 033/375] leds: avoid races with workqueue Sasha Levin
2019-05-24 22:55 ` Pavel Machek
2019-05-29 18:51 ` Sasha Levin
2019-06-17 15:57 ` Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).