From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout08.his.huawei.com (canpmsgout08.his.huawei.com [113.46.200.223]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F8CD3E556B for ; Wed, 22 Jul 2026 08:31:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.223 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784709096; cv=none; b=pvuuKc3V06a1x75Ypgn+Ha+wplBkJnJw7zlx3/a7LE1CucKfYJStuYo7jgYXVNft+Bke+kg0AloGZgD8HUGxgi2w2ktTVkR5cmtD0HVP5qV96pk3r+f5CdmLHJOfm3OENZmwBVYKfFQL1bimrcXySiPHuacRoDqX3rlHvwttiGA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784709096; c=relaxed/simple; bh=foT2FNu7ZkA+F9PgGOqoR4/4s4Nr8C2fBYFrms4DKAU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QyCGbrfYM363OoXxFC4Smd0uNDLuoNeTf1XikUwZ9nlEOVhwUMf3F14KM8llKukyEcGncoUs7ETkz5e1zrKiKXZLUPLxalU0xG/ndhbwD5z2v8Z5mgyxMFsQMC3sjFAfLP0CBcv/qmO9MsBrhrlBIGrJWYGP/o1b1Zp9o/2UDZc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=KSgY9vnS; arc=none smtp.client-ip=113.46.200.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="KSgY9vnS" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=SgS/V+WXikCppzBSnMYHrNuEXt834COmPlQW8/AER7Q=; b=KSgY9vnSptGCThq463Cd3NLPUuqXTqGYIUzAUAOKHm7q+HCbLURfxLXKqkKI4pz5ZK9ugJdwt oavxqWdhZMI9Bxob0NNWUxwJvVaCgBeSPiPPiqpiguNlHWfWUuOo7nCxNyxb2iQ3hKyr+wueray SCZ049pJKjKNFBdqoD1g1Ig= Received: from mail.maildlp.com (unknown [172.19.163.200]) by canpmsgout08.his.huawei.com (SkyGuard) with ESMTPS id 4h4nKk3sGWzmV99; Wed, 22 Jul 2026 16:22:02 +0800 (CST) Received: from dggpemr500006.china.huawei.com (unknown [7.185.36.185]) by mail.maildlp.com (Postfix) with ESMTPS id 61A4140563; Wed, 22 Jul 2026 16:31:25 +0800 (CST) Received: from localhost.localdomain (10.50.85.180) by dggpemr500006.china.huawei.com (7.185.36.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 22 Jul 2026 16:31:24 +0800 From: Yao Kai To: CC: , , , , , , , Subject: [PATCH v2 1/2] futex/requeue: Fix rtmutex schedule preparation for requeue PI Date: Wed, 22 Jul 2026 16:51:39 +0800 Message-ID: <20260722085140.1949077-2-yaokai34@huawei.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260722085140.1949077-1-yaokai34@huawei.com> References: <20260722085140.1949077-1-yaokai34@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: kwepems500001.china.huawei.com (7.221.188.70) To dggpemr500006.china.huawei.com (7.185.36.185) A waiter requeued onto a PI futex can reach rt_mutex_wait_proxy_lock() without rtmutex schedule preparation: WARNING: CPU: 0 PID: 293 at kernel/sched/core.c:7606 RIP: rt_mutex_schedule+0x43/0x50 Call Trace: rt_mutex_slowlock_block.constprop.0+0x5b/0x320 rt_mutex_wait_proxy_lock+0x3e/0x80 futex_wait_requeue_pi+0x3ba/0x590 do_futex+0x171/0x1f0 rt_mutex_schedule() requires current->sched_rt_mutex to be set. Normally, rt_mutex_pre_schedule() sets it before an rtmutex waiter can schedule. With requeue PI, another task can enqueue the waiter after its futex_q becomes visible: waiter requeue task ------ ------------ futex_wait_requeue_pi() futex_wait_setup() futex_queue(&q) futex_requeue() rt_mutex_start_proxy_lock() enqueue rt_waiter install pi_blocked_on requeue_futex() plist_del(&q->list) futex_do_wait() plist_node_empty(&q->list) skip schedule() plist_add(&q->list) futex_requeue_pi_complete() IN_PROGRESS -> DONE futex_requeue_pi_wakeup_sync() // DONE rt_mutex_wait_proxy_lock() rt_mutex_schedule() futex_do_wait() mistakes the temporary removal for a wakeup and skips schedule(). The proxy waiter can nevertheless remain blocked on the target rtmutex and subsequently enter rt_mutex_schedule() with current->sched_rt_mutex clear. Call rt_mutex_pre_schedule() and rt_mutex_post_schedule() directly around rt_mutex_wait_proxy_lock() so this second blocking point has the required scheduler preparation. Fixes: d14f9e930b90 ("locking/rtmutex: Use rt_mutex specific scheduler helpers") Suggested-by: Sebastian Andrzej Siewior Cc: stable@vger.kernel.org Signed-off-by: Yao Kai --- kernel/futex/requeue.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c index 79823ad13683..f7889fb2fce4 100644 --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include "futex.h" @@ -865,7 +866,14 @@ int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags, case Q_REQUEUE_PI_DONE: /* Requeue completed. Current is 'pi_blocked_on' the rtmutex */ pi_mutex = &q.pi_state->pi_mutex; + /* + * Requeue temporarily removes q from the hash bucket, so + * futex_do_wait() may skip schedule() even though the proxy + * waiter still has to block on the rtmutex. + */ + rt_mutex_pre_schedule(); ret = rt_mutex_wait_proxy_lock(pi_mutex, to, &rt_waiter); + rt_mutex_post_schedule(); /* * See futex_unlock_pi()'s cleanup: comment. -- 2.43.0