From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) (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 8AF6C367296 for ; Wed, 13 May 2026 02:07:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778638034; cv=none; b=c2beP7wzCYHw8MtGtk54R2Qj9LpEYrcP+liKizbu7STr3H2vi9jQ5flZSPyvaasCoOs1WQtawHpjM/XzVxhGBr9BlzXYAoBZBtbHrstUXHVyw2fXHhLu9Gdn0KfSqOKmQbLpaw1sultIuKk3yKEqNbrPWJ5OxM/TIv7ZuahRXOM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778638034; c=relaxed/simple; bh=jprJhpld/Mk2XlinAxM/3WSlkZ8NEDLsKiq2VYww0aA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sLDmX09sofWerd2Y9ogDYf+PRsu6fDKiLSpRT44wDvn7Hg50Hc9t+uKhZYLxP4PPkTJJiTe7r5j+LX5akOG0P6lHtEHbOXCiqv1AAj+xt7XwR+MvE4T7wm5rOxi6Z0tkGmBsQCRSDL0bv+baiKxO9iDZpbP82L2SWjJXIjK06OY= 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=C9Hh1Kwf; arc=none smtp.client-ip=209.85.210.47 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="C9Hh1Kwf" Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-7d1872504cbso5678018a34.0 for ; Tue, 12 May 2026 19:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778638031; x=1779242831; 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=IDZwW21tBDiD5Djz5iGheLqVcuwXEHQGYpEEmxE1AJg=; b=C9Hh1KwfdEwYkCMIyNLCbwljqF1Oe6k8WDlgXOv7O/9JqQ6XGcSsxnwDh+7ZofW9NA 9INKffq5I6e5JZWr1FpSx014U5U1O0AnP0UPjgaiM+gZXb2uhwGxLW/sA0/e63M21Q5B /C4+lrLdyqwi5JAga7VM2/+LHrLSn48vn4OZ9GwcDbET6YYSFFP6hZ0a2SnFaEntMd9V 5pobnY+/ziG80d3DfG+fLXowsQrdGyJOuSKej9ZdU9rWVJIz8jLk4Y3sMpMbFZuT/CqV hqoeFsCh8KhbMlpAE7R5yQRffUfYfBEFzsQ5GWYVKpj3G2tltAdyImfk+I4eqoSZLL1S NuwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778638031; x=1779242831; 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=IDZwW21tBDiD5Djz5iGheLqVcuwXEHQGYpEEmxE1AJg=; b=N4cM9opbp2MgX981Xo9MtX1XfibvL/lGGgjgBKmKvsi7hpZXVMHBU68jUnhTnBQuaJ RBxN7/ryJoktaP2VK0LoNMvsRjhxEEdFzwggIk0WEDpoiLIWAwsyqYnBFO4pMUe4QK1C pnB6x8yyseWFLn65gpVDixnQAOx7wPJTR0BjSDGdNChOGFh+hTKUs7VMYK9xRZ30qKeg FgbmayEf+z8diAr5XJFc/dfdgnGazfWuouDFAxPEwWWXAayiD9QZoN81opY9bjLKJoZQ F/5h8uiL7h2L31goGQqKUnxWz3dvxpJmawVgirfpXnu2ZzoyOn8sN4NVLMIqTV9oVOXl aQsQ== X-Forwarded-Encrypted: i=1; AFNElJ/yiRa7IY/1Mmv7B6GwL2piomVqjAuTU02voDqZ8QOPaiLGYDrbB0tCLdPp5k4DxiZFQJDFyM+qZJN9XF4=@vger.kernel.org X-Gm-Message-State: AOJu0Ywi75RRjbwxDjPxEhxa1ljnCYyA+zw6FldoFjiYb/yu8IuVKgvk 8AgOCHpnLWderpWnbMOgb7getbYJz3P68kzkdHg9aAl20Ngyc+v/iQzu X-Gm-Gg: Acq92OEqYw3CBqFsqmzHFWymFHecrbkgYBdBG1XS9k6yqkcP12wL9APtvGbEuDVdw8t yzPFokglfH5s/g+7bSp9hIT13Y/V8wbHXYoAEnNBgb3Pv0tlk/fHDtu75nE7bp/Fc9FVKiImNWd KdCiRZJoUtjayDfGUemJ1NG+h5ozxBSRY5kZy9EvrcENgVdZNW2aUG6wKP9QHsN8MBvKezfqNwP BTzZAcXN7qYiSEe4B88R0x0cGqXSu/9dQ8w5iMqOcEVQbNnaDSltHKL4pZCiieeZc2jlR3nXnR3 iv3NIThsHos6RT9JNgdsWvxPjP9SlC9nUfPQ9zspaTPDWONFz5ntZtok4Rl+SGwk+lLbJEo/uXl b9GSRV8Jqu8iPijz44aIG5fff3BJeZTHyKZjZGHjcAW/XKVHIxiz6b8QLWhqNY2ukJelBtVyZ8R AJDh9E6Fd9bkl3qF/aI5k92SEdx79lMlMOePk99oMLJvOHl+PnDx2B09XfSSjMFgjqhgE/Q8ch4 8jyhQwzZkxWRg4k27nE4lqx8EboQWY= X-Received: by 2002:a05:6830:6484:b0:7dc:a51c:9197 with SMTP id 46e09a7af769-7e3d885bdaamr873084a34.7.1778638031241; Tue, 12 May 2026 19:07:11 -0700 (PDT) Received: from fedora ([172.245.82.59]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e367c05393sm10616856a34.9.2026.05.12.19.07.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 19:07:10 -0700 (PDT) Date: Wed, 13 May 2026 10:07:03 +0800 From: Ming Lei To: Tejun Heo Cc: Peter Zijlstra , 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> 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: 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, however block layer plug list isn't flushed before this 'sleep', which is absolutely fragile to cause deadlock. Thanks, Ming