From patchwork Wed Sep 20 07:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 142313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp4011641vqi; Wed, 20 Sep 2023 02:59:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5bUmobz5Pj373xYmRRERSCDYHkyu8cySDPXut5bIxKP69MN1NOeWb3/GYFiVtyZhZE3Iz X-Received: by 2002:a05:6102:2841:b0:452:6da0:678f with SMTP id az1-20020a056102284100b004526da0678fmr2277058vsb.9.1695203984900; Wed, 20 Sep 2023 02:59:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695203984; cv=none; d=google.com; s=arc-20160816; b=C4sBGIlV7gH8X9BhRStbJUtiFRJrA1eyIhanJ7ClNpTbqIDjj+4Ke3fEAdVf38iq9P /doZjdKDVyk1rf+kbBLI4mWhVvk6SzX0MjUo5W3Ii9t6w4H1Hb4TNquhcpvlwFkZ4MRq bA1vCT5oR6F3iHZ0hMfEg9DfQ1kod6InZ0BsTuhNOFjNeWCziL7o6lDyfOjGp96i1cHH 1wPfws0hSX7tajhU+q+Abbw+1br4KVJbzk/t0LbiHKM0lGwudLc02qYq0SzUKMOFWraS gotsoS3dIdHlQlyoKWUHYCo3ScNWMafkbttDx0M2Ye2LQ7mzYz+OimB28tr2OEPHrAF3 kjjQ== 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=oYJlot/aScq95AA44zpJ6weT3yzT1qWlFyHFhFCVEfA=; fh=R6JgPdNwJaJpxAw0JtgoQacaE/XRV2qGy3orDHt8oNY=; b=lQ6kxu2l5ZlPQe18gUL4ZAn4FJjXBg5e8TQcKkA9LmUdKaMVJxaTm9eXx/I/MTWBH6 ekgbqjm7TSq1lg/1JsG6wQhVQueRQbiOyfXGXOgUmLyKhp3AC7iyMJb5JC36p4FuX5/1 3r1HtGDNGPIRWVhxSi1l8zwL1z9LnM8eoNjhf9RkwnyCI5KmmGSEJSo64n7F48CHQagN kkq8pnOGmi0yXMHS+Zv8m+ElgxByS65C+5520SxP0RzkHXYLWIJKE74B2GNpMDPe/p8g cAnzI1Fm53awT0yF9f3DX6Pa/IJWiEMLjGKWedO93v0yiRw9gu3YogEvmMOqcPBkBgZb 1heQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=x8s93U0T; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id o25-20020a635a19000000b00563de35d397si11166454pgb.487.2023.09.20.02.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 02:59:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=x8s93U0T; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 77A3A80AD0BE; Wed, 20 Sep 2023 00:36:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233853AbjITHgi (ORCPT + 26 others); Wed, 20 Sep 2023 03:36:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233797AbjITHgU (ORCPT ); Wed, 20 Sep 2023 03:36:20 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 269789E; Wed, 20 Sep 2023 00:36:15 -0700 (PDT) Date: Wed, 20 Sep 2023 07:36:12 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1695195373; 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=oYJlot/aScq95AA44zpJ6weT3yzT1qWlFyHFhFCVEfA=; b=x8s93U0T2L7PWWyTDvg4hWgUGwNgP6VBeNkNiXcd6EzRcgoIoZrUvCcZH0gLt6qvyQz+WJ sfSVWJqKu8erIDCZaFq9MnyyWu/3RZEwLOl/RBfoCsGV2KWEx6nG58x2yuDcfmHbUoXTHW S18g9jx8I/0z8zSyPjvWoFJ5ABZaPtiFom6tArBkWP0+e/FUiqraVUx0xTnOtE8gYwhouN E3I38TJBKKGsqGDa5zHLuEOZQVEyjlxj6O1F+yjZvC/pta/40EIfbxBPkpJy/G6HC0yKk1 s6g6kNMk5V/7AlZ8LIHGFR01ny8glqMilDy46xszUGvFst0Yy6X98mD5njghuA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1695195373; 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=oYJlot/aScq95AA44zpJ6weT3yzT1qWlFyHFhFCVEfA=; b=2RnDIHlsXSQgxucYyz0oCsLl7oMtDhuGxdBdagf0i9eGAZ/7/NmO+37cbYvcLB/vvtnjB2 5tbAIIj+v6cBwcBA== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: locking/core] sched: Constrain locks in sched_submit_work() Cc: "Peter Zijlstra (Intel)" , Sebastian Andrzej Siewior , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230908162254.999499-2-bigeasy@linutronix.de> References: <20230908162254.999499-2-bigeasy@linutronix.de> MIME-Version: 1.0 Message-ID: <169519537258.27769.828089056891859325.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 20 Sep 2023 00:36:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777550213460220452 X-GMAIL-MSGID: 1777550213460220452 The following commit has been merged into the locking/core branch of tip: Commit-ID: 28bc55f654de49f6122c7475b01b5d5ef4bdf0d4 Gitweb: https://git.kernel.org/tip/28bc55f654de49f6122c7475b01b5d5ef4bdf0d4 Author: Peter Zijlstra AuthorDate: Fri, 08 Sep 2023 18:22:48 +02:00 Committer: Peter Zijlstra CommitterDate: Wed, 20 Sep 2023 09:31:11 +02:00 sched: Constrain locks in sched_submit_work() Even though sched_submit_work() is ran from preemptible context, it is discouraged to have it use blocking locks due to the recursion potential. Enforce this. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20230908162254.999499-2-bigeasy@linutronix.de --- kernel/sched/core.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 2299a5c..d555640 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6720,11 +6720,18 @@ void __noreturn do_task_dead(void) static inline void sched_submit_work(struct task_struct *tsk) { + static DEFINE_WAIT_OVERRIDE_MAP(sched_map, LD_WAIT_CONFIG); unsigned int task_flags; if (task_is_running(tsk)) return; + /* + * Establish LD_WAIT_CONFIG context to ensure none of the code called + * will use a blocking primitive -- which would lead to recursion. + */ + lock_map_acquire_try(&sched_map); + task_flags = tsk->flags; /* * If a worker goes to sleep, notify and ask workqueue whether it @@ -6749,6 +6756,8 @@ static inline void sched_submit_work(struct task_struct *tsk) * make sure to submit it to avoid deadlocks. */ blk_flush_plug(tsk->plug, true); + + lock_map_release(&sched_map); } static void sched_update_worker(struct task_struct *tsk)