From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.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 EAD57356765 for ; Wed, 13 May 2026 08:08:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778659728; cv=none; b=F6uBwy6jfj80J5KrX3/sN6SMOvk2UbQaLnG/Ifu6uxkhsGPEYIPO1Z63wcOKMoGSj1ZEnMI6bZv+1IXJEA7wI7p1uqrUX77GUpbzfItWkOXOZGrBibrx2TBjGiQLAfjMxCls52Zm7g2AfEUSLAVDuJoquXK9C1JbGagdDgBTC1o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778659728; c=relaxed/simple; bh=4btVtrjwZj+qvTMRZdaxsK35m7G7BWtAvytYXi/zXOI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=E/QubUZkoySvgUII4viQ6t57gkOY3xt+gg5TM1NzHxbvmUp4LgmFCAEPeDpNq49mC+xlxyEd/CgRHMJsyJRp4Idx5BaRozhqQVFNupV76QYMZRNBTdqlU62qinSSFM6u84yqk4eV2BbUxX56Rz1lqCrCjEApBZQ/DEdUlbvsjzo= 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=lsWSX6j6; arc=none smtp.client-ip=209.85.160.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="lsWSX6j6" Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-43034c0fd27so2410640fac.1 for ; Wed, 13 May 2026 01:08:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778659726; x=1779264526; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WLWC9LhEn5jAtEa1iuRPCWA08PAJdtUr0z7GULsP2M4=; b=lsWSX6j62SG7jYBAv+iuol8lXaCzjZ8dXvVrvBPPfl/zyBfD59HEAhL+idCvm2Sx68 PQhdFCwruWnYHDRjyfnH7+G5PkS8nPUHdWAUfUIqpw2/vIcIUYtAnYiZMHgWt5WCaWUF Yma1fdRL6L0+vRS9k9ZsYYzbEDFfarlF02o7XrhQ7TXvf5PWDNs+XAzsMztiU/dRal+0 PwSFhKDrCMNCO+YIqxC/DbpW8Ch1zQhJ/Fe8fuEOrCcomX7WgVBbsAjk4UdVjDDbVqqk l3o+Cw8Gf0cV5vGZUbOfeSP0LN5W2B4zMd476o/983tYb8IKm/LflFGQKYp3k+oqPX/P YpXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778659726; x=1779264526; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WLWC9LhEn5jAtEa1iuRPCWA08PAJdtUr0z7GULsP2M4=; b=hQpqIT2XYtS5yHpo6Y0+yEnnxNX3j476GC1//ja0trZSSS+ar98xGBnS1SnrbVT6Er F3d9JEoYn6C38uFNvxqWpPTszBbbUY3Pqwl3uariQINraan6L1UfeKyHGXXUVXSLOuu7 NnSQHz8mpmSdSqID/nZWQK+ETQHzFGGw1yugNm8v9IJjYEfu7qsUYEN/Chj71bVKKkEc 6hTbSy+taiS6hHRDkFt8HqunaQNPdce1hpiJ6VZZze6pY2w6IL5OpW3f/RINgTAolz+q JUSCWqiachlbXE9cNt8V7PlMMylviKoE/QAbqDc11stRfCUfaU1ViLENqZOKWl8rhp8M U1Sg== X-Forwarded-Encrypted: i=1; AFNElJ9S7pfNJ7lc2izwqTrdn20HTq7NVT+Ldg7Z4dtcMGvM5w8FWnmQmm4q59H/MvaxZViWI+2rJD6tdCMZlqM=@vger.kernel.org X-Gm-Message-State: AOJu0Yz4QkVjI0X+pUPoXikdX7rv5KlMf7iyDpOpmeVBb5wmNFfj9y+Z auxC2CJc2wG1tEKE1vvHGYuGjAURUNbuPs0k5ckp8gr7jwF8Yb1abJHotIrg+BEg1gs= X-Gm-Gg: Acq92OFpM8vJo3ASu79euZ+cFuZxI7xyYjajhwT70KHkFmnT3CQxa6BHKEDxU4oSkiw FIxbV81dsRuIyvRsHsqY4+WsuFFAPJDToJ+zGUboSQN/LWElkkZtF9YrnCoSVSaGPwgoO7f2cAz AqY9wu6hVbj43blY4r2IhnYsK9x8721UZ/6oMbpdEaQEcAHyVgXJqkPuppF0/O1zIkzLK6835YP 7+rjkeqpgEZUyW37DvaehMkkLyFOk1bCL9cuFCXSyqf4+4eGGZRZQcn5L+tG7ILflm04jiVhLsg Eybc9fsjCea6phzoBpvCqV1B/9UnzNCiw8b5YiuXbkiqoit5/wxUZqvSMarPyi8gW+U+PSsBIHm FAk9nVdusAFyfhyhvaoGiZd7BIANIQrpp1kBwGjWaUyimPds7uEj3WITnbIdOVkPxeqUes5H3JR IkbgtzrUVEGTBpKqg0aiBqVeE0ATaQriwPN+JAvGElHGcubePURsjg4/MM1us/9XxKAj9kkDiLu TuMokk1Z85JzCyOvLwGrOnqdoCnPkA= X-Received: by 2002:a05:6870:c101:b0:42f:af81:276d with SMTP id 586e51a60fabf-439ce4ceca8mr1236116fac.36.1778659725904; Wed, 13 May 2026 01:08:45 -0700 (PDT) Received: from fedora ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4355710cfccsm15347800fac.8.2026.05.13.01.08.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 May 2026 01:08:45 -0700 (PDT) Date: Wed, 13 May 2026 16:08:35 +0800 From: Ming Lei To: Peter Zijlstra Cc: Tejun Heo , Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Ingo Molnar , Juri Lelli , Vincent Guittot , Michael Wu , Xiaosen He , Thomas Gleixner Subject: Re: [PATCH] sched: flush plug in schedule_preempt_disabled() to prevent deadlock Message-ID: References: <20260512085939.1107372-1-tom.leiming@gmail.com> <20260512120431.GC1889694@noisy.programming.kicks-ass.net> <20260512124021.GA2214256@noisy.programming.kicks-ass.net> <20260513073039.GG1889694@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260513073039.GG1889694@noisy.programming.kicks-ass.net> On Wed, May 13, 2026 at 09:30:39AM +0200, Peter Zijlstra wrote: > On Wed, May 13, 2026 at 10:07:03AM +0800, Ming Lei wrote: > > On Tue, May 12, 2026 at 07:16:36AM -1000, Tejun Heo wrote: > > > Hello, Ming. > > > > > > On Tue, May 12, 2026 at 11:45:14PM +0800, Ming Lei wrote: > > > > On Tue, May 12, 2026 at 02:40:21PM +0200, Peter Zijlstra wrote: > > > > > On Tue, May 12, 2026 at 02:04:32PM +0200, Peter Zijlstra wrote: > > > > > > On Tue, May 12, 2026 at 04:59:39PM +0800, Ming Lei wrote: > > > > > > > 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 > > > > > > My memory is hazy around io_schedule but the above reads really weird to me. > > > A task, regardless of its current state stays on the runqueue when > > > preempted, so the condition is temporary. As soon as the preempted task can > > > get CPU, it should unwind the situation. That's not a deadlock. Is the > > > problem that there can be preemption-induced delay in flushing the plugs? > > > > IMO, preempting a `!TASK_RUNNING` task can be thought as effective sleep, > > No it cannot be. Preemption ignores task state. Yeah, I get similar conclusion too with AI's assistance. But both two reports show that the preempted task aren't switched back for long enough time, can you share any idea for Michael & Xiaosen to investigate further from scheduler side? https://lore.kernel.org/linux-block/20260417082744.30124-1-michael@allwinnertech.com/ https://lore.kernel.org/linux-block/5660795d-87de-46f5-add4-7729a02225ef@oss.qualcomm.com/ Thanks, Ming