Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp480646rwr; Wed, 19 Apr 2023 09:01:27 -0700 (PDT) X-Google-Smtp-Source: AKy350ZV7tD6Pz25ELFhXlz0jYkhi3d8licdNTvwUSKbLzrQCW1qrFFnknpAMw1zQ3Cf2+TOvgdO X-Received: by 2002:a17:902:f20c:b0:1a6:9f9b:1330 with SMTP id m12-20020a170902f20c00b001a69f9b1330mr4621346plc.47.1681920087322; Wed, 19 Apr 2023 09:01:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681920087; cv=none; d=google.com; s=arc-20160816; b=Cs4nMSXUhAqZscbDEG6ZIeGVNjxWDWEpR7pWNR0Yj/aJJo2QlcVNYSDrstYoCbuAy1 w9sjXwig8Mi/forDEwfzyZvrbjF+jZiH69DGEFrPQWaNObXFE8IzjbU7wet4BL3mE9z4 xjF1Ajq7P8dAa1NRvYOQezXyOiDhmaM+lx4AQwnBbhUrRSAmXFCt0Bn7QZxz7rlS/Bhe HkkzvHio3azIjLQu3ng8+y68K3zG40RZY7ZFzHlEiG+0cqw14E8vJUDFyUz65WSwqTVu K0HFjvH/9URzMWsLCB8+Tk3sWB/AG0DdUxbODuOmF2yGwaBi3WFFCxBXuBRr1agJLpbx SlZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=g/GTR56/jYK73G/VxnNJz7rrSu7NU9Sh8nrZKYGlySw=; b=t+zV9QChNdaYVplBeOdhN8JMpQIiAXB5KBDleVhSPzRl8A/PqKXIvrggcmfoaeGNZz kYKE6y2EWNdlb6kRXgqaykge+40KBQIdYp9RMmbgHFHyVfYRUiQ9Y3QsEPpdj1KYZmLN wUGufQflNFNGD3SOH8fkrd1xA7nnVSNvandQWJmpG+EFK66Xsxpk7wjGk2PL0hH8E0DO 28uYatzJw9e4r9i73JL5UrNs5TDuaJyByqBELJKk4Ik1ENWN6B2XM/Uoir/EAxyc7znZ emUGMfhDp1iJt8qGp7Y6BF1g3+iP7zPPlkRlPDu5Cglq1arqyjMaqY4pOJofpq0V9tkM eTAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=Pq5aqMHU; 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=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r3-20020a170902be0300b001a19bb822f6si4589220pls.282.2023.04.19.09.00.55; Wed, 19 Apr 2023 09:01:27 -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=@efficios.com header.s=smtpout1 header.b=Pq5aqMHU; 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=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233743AbjDSPv3 (ORCPT + 99 others); Wed, 19 Apr 2023 11:51:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233704AbjDSPvO (ORCPT ); Wed, 19 Apr 2023 11:51:14 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B222A5C7 for ; Wed, 19 Apr 2023 08:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1681919416; bh=jG8tTXCR9Ya7nvQsevu7MKGN0o0nozXlruFMc2npb60=; h=From:To:Cc:Subject:Date:From; b=Pq5aqMHUlJGsJNwFBbACVYp9o9kotaGSVMKFvl8XHfLnB9+xGaKX3KSGvwx3rkVxO 5NNUSIKV/wIWT5rRHj4geZcLyqRz+3pEpQ4g1EnD+pGoXXKKMxua2Y5SrwM0Ha6DMA dceLciZLbMEknVEMvi7oMTZaojytidaRNu/xXNcCp3ovqwdCRgary2icIgavb1mhtc TXIFimY6O0CSjEAdrHZc4TO35r3yVKEiq4xidUxovkYEG1S+1tfxJthA4ms1RrUPJS +3/nckw1LdyC5BV+CdCyT85yLssAPwj3wGsjbuli1IQZ3XpDGmTBU2O9h1C745/g0A kD+doFhpKAVvQ== Received: from localhost.localdomain (192-222-143-198.qc.cable.ebox.net [192.222.143.198]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4Q1lc81g12zwF9; Wed, 19 Apr 2023 11:50:16 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Mathieu Desnoyers , Aaron Lu Subject: [RFC PATCH v9 1/2] sched: Fix: Handle target_cpu offlining in active_load_balance_cpu_stop Date: Wed, 19 Apr 2023 11:50:11 -0400 Message-Id: <20230419155012.63901-1-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Handle scenario where the target cpu is going offline concurrently with execution of active_load_balance_cpu_stop, which can cause __sched_core_flip to flip rq->core_enabled without rq lock held, which can trigger lockdep_assert_rq_held() warnings. This scenario possibly has other unwanted effects such as migrating tasks to offline cpus, which may prevent their execution for a long time until the cpu is brought back online. Signed-off-by: Mathieu Desnoyers Cc: Peter Zijlstra Cc: Aaron Lu --- kernel/sched/fair.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5f6587d94c1d..1c837ba41704 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8744,6 +8744,27 @@ static void attach_one_task(struct rq *rq, struct task_struct *p) rq_unlock(rq, &rf); } +/* + * try_attach_one_task() -- attaches the task returned from detach_one_task() to + * its new rq if the rq is online. Returns false if the rq is not online. + */ +static bool try_attach_one_task(struct rq *rq, struct task_struct *p) +{ + struct rq_flags rf; + bool result = true; + + rq_lock(rq, &rf); + if (!rq->online) { + result = false; + goto unlock; + } + update_rq_clock(rq); + attach_task(rq, p); +unlock: + rq_unlock(rq, &rf); + return result; +} + /* * attach_tasks() -- attaches all tasks detached by detach_tasks() to their * new rq. @@ -11048,8 +11069,17 @@ static int active_load_balance_cpu_stop(void *data) busiest_rq->active_balance = 0; rq_unlock(busiest_rq, &rf); - if (p) - attach_one_task(target_rq, p); + if (p) { + if (!try_attach_one_task(target_rq, p)) { + /* + * target_rq was offlined concurrently. There is no + * guarantee that the busiest cpu is still online at + * this point. Fallback on using the CPU on which the + * stopper thread is running as target. + */ + attach_one_task(this_rq(), p); + } + } local_irq_enable(); -- 2.25.1