Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp455964imw; Thu, 14 Jul 2022 04:51:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vNmI7mWiQxxk23Nex2poB7SpQ15nmJOCmoWGQodcGgXs+AqgeEMFUiPNyCJe/4obaszAS8 X-Received: by 2002:a17:90a:c906:b0:1f0:47ed:59bd with SMTP id v6-20020a17090ac90600b001f047ed59bdmr15931287pjt.40.1657799475251; Thu, 14 Jul 2022 04:51:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657799475; cv=none; d=google.com; s=arc-20160816; b=TadoFvILX43du68FLSObgQ5itCqVNSaQ5uswF9yCn1lSfX8jvXetWncegD2Q3KUchH SBpdpk1ZMlw04ibIjKRhIjzy00RO0ZEjMOnR6ural3upuzdroOXNwUfAEIOG3DsJ3FY7 DEgyLMWfF+hU7L2LL4QkJqd7Xoje/k274Duft+flhK6CWkBnaktaQWuweZU0Th+394ZV Ece0xUJcOOpINahdgmxAWOQI/eSvm3iC87CeqwbMC4JcqVvLqOlgnXoOH1xPahc4wUMv bgHdxmNi0qaOIJrCHQ5J4C6a3ycWMFTzN9AWPCmWCfj/7JQNWE6c2/Ux/Euj4r+d0e3i uaHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=dw5dKPMBF5qgiL0iVEeFmaNXlyBwXMe/WNaUeMeWCig=; b=pezGqM7zY5N1NhUeFvqEOvMYUUnj5Y+2cr/v3CznqUss8TCqQz1oqINd3k+Lp8l1Wd QmD8TXhRfSV3Djd5ictrcQYRgDsCvPpW81FyhqlfXXmMmcYQZJMqYpVzmfiFV4e+MKmz 9dx1Sqt9sH3U9MTHmhNQgB5Xwqwg8GOdRlZJMAC4UxqMzi2BzmNVw2EKJJENxPTj+qOH X+Sk5sXlV5ACoNDjSL0lE/0fuM3KaSgjunNiAy3i942QPVW6WWtPPoEDbZMVqnms3tHl 4Qp5mo/BntWFNRJ4d8zOTgaiChLPrn38rkGiMH4+1QShzVS1k59aI1GzG9DlFnU3u34U hsiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AB1CtqAg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i190-20020a6387c7000000b0040cf2ca7411si1522694pge.600.2022.07.14.04.51.03; Thu, 14 Jul 2022 04:51:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=AB1CtqAg; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238980AbiGNLfi (ORCPT + 99 others); Thu, 14 Jul 2022 07:35:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238966AbiGNLfg (ORCPT ); Thu, 14 Jul 2022 07:35:36 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F5EA5A2DE; Thu, 14 Jul 2022 04:35:33 -0700 (PDT) Date: Thu, 14 Jul 2022 11:35:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1657798532; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dw5dKPMBF5qgiL0iVEeFmaNXlyBwXMe/WNaUeMeWCig=; b=AB1CtqAg02nkJfhKCJlYBhDZsFTOh+ZWV5O9JZouHgEhysqH0c4IdGSIT81QIiIpSMjxCU HBs7s6CkkzXWW+hWGte11Jd2DIueE0okrzXsT8IGcXENprtb8rIW7fZDrMqvgAwZoqfmoW fcIoe3CGEMgXu2CB5+04kpBifVlvaf2C0J0wukjvxDwIJADRJStIMhl2PO7RzOLvftUlYg ZBAaZboFNOQcJyi28no0vm/16eITQzpY108TqtB/vCnye+7YIdzQg5yRgfc+2tUEcbeyzy SQAjITj19Xjf1jGRnZ/xOqzPSGntK/4t0uUCbQlgRryg8msmdiiMAP5K7F8z8g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1657798532; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dw5dKPMBF5qgiL0iVEeFmaNXlyBwXMe/WNaUeMeWCig=; b=bkBgjlcQWZQ9X3mqQfCJ3NUzoHpsZK8KGuxjvRbjfVVyiZxwJBC7QqDxVNfKm0ZzLXeQ3V BaaxmjQKk0nar3Aw== From: "tip-bot2 for John Keeping" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/core: Always flush pending blk_plug Cc: John Keeping , "Peter Zijlstra (Intel)" , "Steven Rostedt (Google)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220708162702.1758865-1-john@metanate.com> References: <20220708162702.1758865-1-john@metanate.com> MIME-Version: 1.0 Message-ID: <165779853104.15455.16915451211318324333.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/core branch of tip: Commit-ID: 401e4963bf45c800e3e9ea0d3a0289d738005fd4 Gitweb: https://git.kernel.org/tip/401e4963bf45c800e3e9ea0d3a0289d738005fd4 Author: John Keeping AuthorDate: Fri, 08 Jul 2022 17:27:02 +01:00 Committer: Peter Zijlstra CommitterDate: Wed, 13 Jul 2022 11:29:17 +02:00 sched/core: Always flush pending blk_plug With CONFIG_PREEMPT_RT, it is possible to hit a deadlock between two normal priority tasks (SCHED_OTHER, nice level zero): INFO: task kworker/u8:0:8 blocked for more than 491 seconds. Not tainted 5.15.49-rt46 #1 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. task:kworker/u8:0 state:D stack: 0 pid: 8 ppid: 2 flags:0x00000000 Workqueue: writeback wb_workfn (flush-7:0) [] (__schedule) from [] (schedule+0xdc/0x134) [] (schedule) from [] (rt_mutex_slowlock_block.constprop.0+0xb8/0x174) [] (rt_mutex_slowlock_block.constprop.0) from [] +(rt_mutex_slowlock.constprop.0+0xac/0x174) [] (rt_mutex_slowlock.constprop.0) from [] (fat_write_inode+0x34/0x54) [] (fat_write_inode) from [] (__writeback_single_inode+0x354/0x3ec) [] (__writeback_single_inode) from [] (writeback_sb_inodes+0x250/0x45c) [] (writeback_sb_inodes) from [] (__writeback_inodes_wb+0x7c/0xb8) [] (__writeback_inodes_wb) from [] (wb_writeback+0x2c8/0x2e4) [] (wb_writeback) from [] (wb_workfn+0x1a4/0x3e4) [] (wb_workfn) from [] (process_one_work+0x1fc/0x32c) [] (process_one_work) from [] (worker_thread+0x22c/0x2d8) [] (worker_thread) from [] (kthread+0x16c/0x178) [] (kthread) from [] (ret_from_fork+0x14/0x38) Exception stack(0xc10e3fb0 to 0xc10e3ff8) 3fa0: 00000000 00000000 00000000 00000000 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 INFO: task tar:2083 blocked for more than 491 seconds. Not tainted 5.15.49-rt46 #1 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. task:tar state:D stack: 0 pid: 2083 ppid: 2082 flags:0x00000000 [] (__schedule) from [] (schedule+0xdc/0x134) [] (schedule) from [] (io_schedule+0x14/0x24) [] (io_schedule) from [] (bit_wait_io+0xc/0x30) [] (bit_wait_io) from [] (__wait_on_bit_lock+0x54/0xa8) [] (__wait_on_bit_lock) from [] (out_of_line_wait_on_bit_lock+0x84/0xb0) [] (out_of_line_wait_on_bit_lock) from [] (fat_mirror_bhs+0xa0/0x144) [] (fat_mirror_bhs) from [] (fat_alloc_clusters+0x138/0x2a4) [] (fat_alloc_clusters) from [] (fat_alloc_new_dir+0x34/0x250) [] (fat_alloc_new_dir) from [] (vfat_mkdir+0x58/0x148) [] (vfat_mkdir) from [] (vfs_mkdir+0x68/0x98) [] (vfs_mkdir) from [] (do_mkdirat+0xb0/0xec) [] (do_mkdirat) from [] (ret_fast_syscall+0x0/0x1c) Exception stack(0xc2e1bfa8 to 0xc2e1bff0) bfa0: 01ee42f0 01ee4208 01ee42f0 000041ed 00000000 00004000 bfc0: 01ee42f0 01ee4208 00000000 00000027 01ee4302 00000004 000dcb00 01ee4190 bfe0: 000dc368 bed11924 0006d4b0 b6ebddfc Here the kworker is waiting on msdos_sb_info::s_lock which is held by tar which is in turn waiting for a buffer which is locked waiting to be flushed, but this operation is plugged in the kworker. The lock is a normal struct mutex, so tsk_is_pi_blocked() will always return false on !RT and thus the behaviour changes for RT. It seems that the intent here is to skip blk_flush_plug() in the case where a non-preemptible lock (such as a spinlock) has been converted to a rtmutex on RT, which is the case covered by the SM_RTLOCK_WAIT schedule flag. But sched_submit_work() is only called from schedule() which is never called in this scenario, so the check can simply be deleted. Looking at the history of the -rt patchset, in fact this change was present from v5.9.1-rt20 until being dropped in v5.13-rt1 as it was part of a larger patch [1] most of which was replaced by commit b4bfa3fcfe3b ("sched/core: Rework the __schedule() preempt argument"). As described in [1]: The schedule process must distinguish between blocking on a regular sleeping lock (rwsem and mutex) and a RT-only sleeping lock (spinlock and rwlock): - rwsem and mutex must flush block requests (blk_schedule_flush_plug()) even if blocked on a lock. This can not deadlock because this also happens for non-RT. There should be a warning if the scheduling point is within a RCU read section. - spinlock and rwlock must not flush block requests. This will deadlock if the callback attempts to acquire a lock which is already acquired. Similarly to being preempted, there should be no warning if the scheduling point is within a RCU read section. and with the tsk_is_pi_blocked() in the scheduler path, we hit the first issue. [1] https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/tree/patches/0022-locking-rtmutex-Use-custom-scheduling-function-for-s.patch?h=linux-5.10.y-rt-patches Signed-off-by: John Keeping Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Steven Rostedt (Google) Link: https://lkml.kernel.org/r/20220708162702.1758865-1-john@metanate.com --- include/linux/sched/rt.h | 8 -------- kernel/sched/core.c | 8 ++++++-- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/linux/sched/rt.h b/include/linux/sched/rt.h index e5af028..994c256 100644 --- a/include/linux/sched/rt.h +++ b/include/linux/sched/rt.h @@ -39,20 +39,12 @@ static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *p) } extern void rt_mutex_setprio(struct task_struct *p, struct task_struct *pi_task); extern void rt_mutex_adjust_pi(struct task_struct *p); -static inline bool tsk_is_pi_blocked(struct task_struct *tsk) -{ - return tsk->pi_blocked_on != NULL; -} #else static inline struct task_struct *rt_mutex_get_top_task(struct task_struct *task) { return NULL; } # define rt_mutex_adjust_pi(p) do { } while (0) -static inline bool tsk_is_pi_blocked(struct task_struct *tsk) -{ - return false; -} #endif extern void normalize_rt_tasks(void); diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c703d17..a463dbc 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6470,8 +6470,12 @@ static inline void sched_submit_work(struct task_struct *tsk) io_wq_worker_sleeping(tsk); } - if (tsk_is_pi_blocked(tsk)) - return; + /* + * spinlock and rwlock must not flush block requests. This will + * deadlock if the callback attempts to acquire a lock which is + * already acquired. + */ + SCHED_WARN_ON(current->__state & TASK_RTLOCK_WAIT); /* * If we are going to sleep and we have plugged IO queued,