[PATCH] mei: me: fix a lost wake-up in mei_me_pg_legacy_intr()
From: Zhenwen Liang
Date: Sat Nov 28 2026 - 21:47:29 EST
mei_me_pg_legacy_intr() sets dev->pg_event and hw->pg_state and then
calls wake_up(&dev->wait_pg) only if waitqueue_active() finds a waiter.
The waiter, mei_me_pg_legacy_exit_sync(), drops device_lock before
wait_event_timeout(), so the lock does not order the two sides, and
nothing orders the store to pg_event before the lockless
waitqueue_active() load. As described in the comment above
waitqueue_active(), the waker can then see an empty queue while the
waiter still reads the old pg_event, and the waiter is not woken.
The waiter's wait_event_timeout() expires after dev->timeouts.pgi (1 s)
and it then rechecks pg_event under device_lock, so the effect is a
delay of up to 1 s, not a hang.
Call wake_up() unconditionally. It takes the wait queue lock, under
which the waiter adds itself to the queue, so either the waiter sees
the new pg_event or the waker sees the waiter. Commit 8c27b1bce059
("mei: me: reduce the scope on unexpected reset") likewise replaced a
waitqueue_active() check with an unconditional wake_up() for
wait_hw_ready in this file.
The same change to this function was posted in 2015 by Kosuke Tatsukawa
as part of a wider patch that also changed client.c and hw-txe.c; it
received no reply. This patch changes only mei_me_pg_legacy_intr(); the
other sites are not addressed here.
In the herd7 x86-TSO model, a litmus test of the pattern is allowed
before this change and forbidden after it.
The problem was independently rediscovered, and this patch prepared,
with the help of a formal analysis tool we are developing that uses AI
assistance; I have reviewed the analysis and the patch.
Compile-tested on x86-64 (clang) with W=1; not runtime-tested.
Fixes: 3dc196eae1db ("mei: me: wait for power gating exit confirmation")
Link: https://lore.kernel.org/all/17EC94B0A072C34B8DCF0D30AD16044A02874774@xxxxxxxxxxxxxxxxxxxxxxx/
Signed-off-by: Zhenwen Liang <zhenwenliang@xxxxxxxxxx>
---
drivers/misc/mei/hw-me.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/misc/mei/hw-me.c b/drivers/misc/mei/hw-me.c
index 1c3ab9eb8b1b..4486209c9be9 100644
--- a/drivers/misc/mei/hw-me.c
+++ b/drivers/misc/mei/hw-me.c
@@ -1099,8 +1099,7 @@ static void mei_me_pg_legacy_intr(struct mei_device *dev)
dev->pg_event = MEI_PG_EVENT_INTR_RECEIVED;
hw->pg_state = MEI_PG_OFF;
- if (waitqueue_active(&dev->wait_pg))
- wake_up(&dev->wait_pg);
+ wake_up(&dev->wait_pg);
}
/**
--
2.56.1.839.g22a8290db9-goog