Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp621619ybb; Wed, 8 Apr 2020 06:44:35 -0700 (PDT) X-Google-Smtp-Source: APiQypIEDw0Pfp6fj8DQlUZKniRHm5OUcAS9pvGGmridefCaIgW1u/wogeRjJuUwWKsrpmY+ho66 X-Received: by 2002:a9d:6ac3:: with SMTP id m3mr5273655otq.175.1586353475642; Wed, 08 Apr 2020 06:44:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586353475; cv=none; d=google.com; s=arc-20160816; b=M0ykmHTdPFykuoorKmD9USQGNAJuKW6I9V1kx0Y7S7LyoF8bMyFiOa+w8hjI8bfiXM eRNTCMFKFuEXLvJiIcT26xZfwBpTijnTGJoC8OJVuA6hfEAJ41qDTkXnDORabNwoOspm PlqBHvcYw6BJ4Sxnh8+B2cwXrAIzOVFS+x8HdBGz7Bm1GN4MR7IiEo3oYdL7nqAbGBwb GFbD8VG4VHaTipqXHMQ67lxadYVDe4M53MfbMB/6cnl5wR6QCBuncUqMfSBszuEo6xKb HxYeA9J++h85WDvCLHsYTC1hXGKL7ATQazCtxoATWUTo8+Gk3sDD/vUiN5kCnuBxVfir Im4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :robot-unsubscribe:robot-id:message-id:mime-version:references :in-reply-to:cc:subject:to:reply-to:from:date; bh=/V4gz7IW8AXsSRGuU9YrEkDONVkt68sz9mpRr73yZKQ=; b=nYhZHiN4ANpPPkR7HV1p72mHfrbOq6iB4t7+plVBuCOE1xSkF7ZP5DypJ1ShvAM0iH b1u5X3F3vXbbVEYSW3+3dkkxNIZsyQcUPxdFka8F27IsJf+hrtWgHzYA0Wt5Wv+c7XId GCd8phFZ6CjS0u21tJSfX1N3+RvDd3juAgSx4KZmvA+Pk/4CwZxom9p3v0EgSVw7d3rD xIH+6cxezkdEtdV8NdrhdgkxDb1M62+RwjpvsYjpXbiX4nk2/JwEAL0I8M50CkX5bs1+ 3wk8482bh2Zf67DsXbpNI8AXVEfHaXTJEr4ZVnMTlJ1igd/EwXyNgbEo4hyQpQvDDnDA Odog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si2577693otj.223.2020.04.08.06.44.21; Wed, 08 Apr 2020 06:44:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728473AbgDHMUk (ORCPT + 99 others); Wed, 8 Apr 2020 08:20:40 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:49664 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728417AbgDHMUg (ORCPT ); Wed, 8 Apr 2020 08:20:36 -0400 Received: from [5.158.153.53] (helo=tip-bot2.lab.linutronix.de) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1jM9gv-000650-QU; Wed, 08 Apr 2020 14:20:25 +0200 Received: from [127.0.1.1] (localhost [IPv6:::1]) by tip-bot2.lab.linutronix.de (Postfix) with ESMTP id 7A12C1C047B; Wed, 8 Apr 2020 14:20:25 +0200 (CEST) Date: Wed, 08 Apr 2020 12:20:25 -0000 From: "tip-bot2 for Sebastian Andrzej Siewior" Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/urgent] workqueue: Remove the warning in wq_worker_sleeping() Cc: kernel test robot , Sebastian Andrzej Siewior , "Peter Zijlstra (Intel)" , Ingo Molnar , Tejun Heo , x86 , LKML In-Reply-To: <20200327074308.GY11705@shao2-debian> References: <20200327074308.GY11705@shao2-debian> MIME-Version: 1.0 Message-ID: <158634842513.28353.14029698174140162537.tip-bot2@tip-bot2> X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the sched/urgent branch of tip: Commit-ID: 62849a9612924a655c67cf6962920544aa5c20db Gitweb: https://git.kernel.org/tip/62849a9612924a655c67cf6962920544aa5c20db Author: Sebastian Andrzej Siewior AuthorDate: Sat, 28 Mar 2020 00:29:59 +01:00 Committer: Ingo Molnar CommitterDate: Wed, 08 Apr 2020 11:35:20 +02:00 workqueue: Remove the warning in wq_worker_sleeping() The kernel test robot triggered a warning with the following race: task-ctx A interrupt-ctx B worker -> process_one_work() -> work_item() -> schedule(); -> sched_submit_work() -> wq_worker_sleeping() -> ->sleeping = 1 atomic_dec_and_test(nr_running) __schedule(); *interrupt* async_page_fault() -> local_irq_enable(); -> schedule(); -> sched_submit_work() -> wq_worker_sleeping() -> if (WARN_ON(->sleeping)) return -> __schedule() -> sched_update_worker() -> wq_worker_running() -> atomic_inc(nr_running); -> ->sleeping = 0; -> sched_update_worker() -> wq_worker_running() if (!->sleeping) return In this context the warning is pointless everything is fine. An interrupt before wq_worker_sleeping() will perform the ->sleeping assignment (0 -> 1 > 0) twice. An interrupt after wq_worker_sleeping() will trigger the warning and nr_running will be decremented (by A) and incremented once (only by B, A will skip it). This is the case until the ->sleeping is zeroed again in wq_worker_running(). Remove the WARN statement because this condition may happen. Document that preemption around wq_worker_sleeping() needs to be disabled to protect ->sleeping and not just as an optimisation. Fixes: 6d25be5782e48 ("sched/core, workqueues: Distangle worker accounting from rq lock") Reported-by: kernel test robot Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Cc: Tejun Heo Link: https://lkml.kernel.org/r/20200327074308.GY11705@shao2-debian --- kernel/sched/core.c | 3 ++- kernel/workqueue.c | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index f6b329b..c3d12e3 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -4120,7 +4120,8 @@ static inline void sched_submit_work(struct task_struct *tsk) * it wants to wake up a task to maintain concurrency. * As this function is called inside the schedule() context, * we disable preemption to avoid it calling schedule() again - * in the possible wakeup of a kworker. + * in the possible wakeup of a kworker and because wq_worker_sleeping() + * requires it. */ if (tsk->flags & (PF_WQ_WORKER | PF_IO_WORKER)) { preempt_disable(); diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 3816a18..891ccad 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -858,7 +858,8 @@ void wq_worker_running(struct task_struct *task) * @task: task going to sleep * * This function is called from schedule() when a busy worker is - * going to sleep. + * going to sleep. Preemption needs to be disabled to protect ->sleeping + * assignment. */ void wq_worker_sleeping(struct task_struct *task) { @@ -875,7 +876,8 @@ void wq_worker_sleeping(struct task_struct *task) pool = worker->pool; - if (WARN_ON_ONCE(worker->sleeping)) + /* Return if preempted before wq_worker_running() was reached */ + if (worker->sleeping) return; worker->sleeping = 1;