mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Zhenwen Liang <zhenwenliang@google.com>
To: Alexander Usyskin <alexander.usyskin@intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 linux-kernel@vger.kernel.org
Subject: [PATCH] mei: me: fix a lost wake-up in mei_me_pg_legacy_intr()
Date: Sun, 29 Nov 2026 02:47:22 +0000	[thread overview]
Message-ID: <20261129024722.281255-1-zhenwenliang@google.com> (raw)

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@BPXM09GP.gisp.nec.co.jp/
Signed-off-by: Zhenwen Liang <zhenwenliang@google.com>
---
 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


                 reply	other threads:[~2026-11-29  2:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129024722.281255-1-zhenwenliang@google.com \
    --to=zhenwenliang@google.com \
    --cc=alexander.usyskin@intel.com \
    --cc=arnd@arndb.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®