From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f53.google.com (mail-ot1-f53.google.com [209.85.210.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A1E13A5E8C for ; Tue, 12 May 2026 08:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778576403; cv=none; b=ulFGHP+ZIEnGS05An2CY5UvjOztcY5nLpNxm0c5UtZ8mWibhDziI+ypclYscYrJo0/GUSE/doM0Nb2ysZMUn7dnNRQ2Frw9cltzbMsieHWRgtz+KfVgYBfdpwphiJ8pUgRb3hQB43nEUBgG6NA9RjdV66i27BeH1/n2/nxps2xM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778576403; c=relaxed/simple; bh=Q+QHwwgYYTgOE6IMG48xeqIiYes94pcMNAmk+a/eooo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=SZO5jbccJGwqXWhltJMIBTMFDDB6P7SjKwkAhFwpxFByzIhZI/A4goqTRWptihqoiaCm+EfbRNK8Wxn6zIvh/ahW3wQNbWUPkLuvZHV1YFoYS1daaf8D/iTN814jDwILQEHCjPYzqpa9IzBRUZO3IiihPG7sA03cOV5WzpyXM5s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=o+sSIOxM; arc=none smtp.client-ip=209.85.210.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o+sSIOxM" Received: by mail-ot1-f53.google.com with SMTP id 46e09a7af769-7d55b97f358so3684512a34.3 for ; Tue, 12 May 2026 01:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778576398; x=1779181198; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=oaFtxWK89jaAnT34s5zWN9wQ86Ea5BISvP/eISI2Ato=; b=o+sSIOxMBtyaJeITe/y+yPPPDCyMZfU3JnJybzyvFrKUYzrw5sbLthrLB6+qh2ZYwO GoTV0ynmEtldvXtCVAWSOw5YJTfWWyeVzwRgNEyO3vQCoZXpc/CBHWCZ5ePBQeqO1NhK lPYdIzBUSgTrlvLO7Bu6oCJ5136TULUPuGy40Plf+zTwINaRoZlA8SKVVWtDIJwcKgi3 eSlPOECofDLCBvgVlk42G80PR6X0oNQszMAAkjZqm8fa0SiHASdRRrjH3x4g7feyYjXT +owYL5iw6YKnQY0pdkBJMW70cTs1Rma99gWHPrF5HdbL6w47HlN77ha4MaakKEm5lXNv AZVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778576398; x=1779181198; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=oaFtxWK89jaAnT34s5zWN9wQ86Ea5BISvP/eISI2Ato=; b=ZzaQ0+c0otHntzq0dhEirrsRiL76oCQS8AtfRweL/pkkN2eAy9K/8Dxuc+XYlgRB+l ZbY4SY2t1GCymxqvlz3lrxqamMk0SBVWDNiSHnBVkuOywnwlDM63QpOQ40mysmefRKTN 5SNiw9CvLH4xsF+2Izhzst6qrF0cE8y9UycTnQKhs+EWriHZVs82Qq5Zr/345RJjz6Sc wMXT6HmrEAIjqif0Kxc4w3bVfc5EJdUTBtQ8GMypRlocSUT9iajDfpDWXcXnL07tMxeO VHopu8q8gmSyv8lol192pehq3Ctop9NerN2rXv2vx95Q5+BeLLs+qrXID6W1zX4DQLD7 L1lQ== X-Forwarded-Encrypted: i=1; AFNElJ+SkKJUq56K79O0zTNtvI8uUVZWy6abjb86mX/+Bkcadhoon7fOzPxe2NvbBirLoaknWKDtElyeS+zBEdI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzrj6uSS/xVoUwyckb6eFQ4yhXq6Y+D6dOwZmepWNsfmxndqfwB V+ZlTggZJ0O4MMx0gnIqeY8EEfOji+nbTrlhHF8TNQM5g5MECLuCl1pX X-Gm-Gg: Acq92OHzgKbOKbQ04AS9owAII1P2o7TE97uNmu1vXpPE2+Ul/oRCZf/jef/zpvGV/uH srZft6IwwIssrHuLV7+FV34uIQkmdSqZyzu3c3pMtawt/35S4TyIjg5YlkRJ06MR9mFwm4shCva PKo6/Nwshet/1lmSJKcOhFm1Zs6bPDDzEh9iItbmopxM2int/zo+vj36IE2Wm5ZX2nn7zMX1KTN dXiC8VMGdZEvte4TjkRevNde+onbEHlWapyJ8fc6WRxjc9Ab0WNen6DVic5LE/FcZ5TXPqnUzOC YrQbrFegP3llVNCBwAgy2Ln6u6aSJfGaJrzgrcHTHRtUCElcg8KoR6UOht2PoGDjjMAMd70gML1 BwSVCKHVf4vn+sZklcwwUkx9gFPHf+scpB85xF6rG4RIZQM3rtG7Sy9szk6ULnN+DwWdv88GAc8 fzOM9hWTY+TQ/366Dmp9nw3gB00WiQqMVIUCpmIHbHiHCV/ADn58z28TOzrKgJOh5NZJt3pOQHz sfGwwTuxPUgTN3LqxSd X-Received: by 2002:a05:6830:44aa:b0:7db:a184:2b35 with SMTP id 46e09a7af769-7e1def0c8f1mr16773819a34.8.1778576397965; Tue, 12 May 2026 01:59:57 -0700 (PDT) Received: from fedora ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e367df7a26sm8501737a34.26.2026.05.12.01.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 01:59:57 -0700 (PDT) From: Ming Lei To: Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Ming Lei , Michael Wu , Xiaosen He Subject: [PATCH] sched: flush plug in schedule_preempt_disabled() to prevent deadlock Date: Tue, 12 May 2026 16:59:39 +0800 Message-ID: <20260512085939.1107372-1-tom.leiming@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On preemptible kernels, a deadlock can occur when a task with plugged IO calls schedule_preempt_disabled(): schedule_preempt_disabled() sched_preempt_enable_no_resched() // preemption now enabled schedule() // <-- preemption can happen here sched_submit_work() blk_flush_plug() After sched_preempt_enable_no_resched() re-enables preemption, the task can be preempted (e.g., by a higher-priority RT task) before reaching blk_flush_plug() in sched_submit_work(). Since the task's state is already TASK_UNINTERRUPTIBLE (set by the mutex/rwsem slowpath caller), requests in current->plug remain unflushed for an unbounded time. If another task depends on those plugged requests to make progress (e.g., to release a lock the sleeping task needs), a deadlock results: - Task A (writeback worker): holds plugged IO, preempted before flushing, stuck on run queue behind higher-priority work - Task B: waiting for IO completion from Task A's plug, holds a lock that Task A needs to be woken up Both reported deadlocks involve mutex/rwsem slowpaths, which are the primary callers of schedule_preempt_disabled() with non-running task state. Fix by flushing the plug in schedule_preempt_disabled() while preemption is still disabled. This ensures the plug is empty before the preemption window opens. Fixes: 73c101011926 ("block: initial patch for on-stack per-task plugging") Reported-by: Michael Wu Tested-by: Michael Wu Reported-by: Xiaosen He Link: https://lore.kernel.org/linux-block/20260417082744.30124-1-michael@allwinnertech.com/ Signed-off-by: Ming Lei --- kernel/sched/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b8871449d3c6..c1efe110c54d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -7336,6 +7336,8 @@ asmlinkage __visible void __sched schedule_user(void) */ void __sched schedule_preempt_disabled(void) { + if (!task_is_running(current)) + blk_flush_plug(current->plug, true); sched_preempt_enable_no_resched(); schedule(); preempt_disable(); -- 2.53.0