From patchwork Tue Oct 24 08:52:27 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: 157304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce89:0:b0:403:3b70:6f57 with SMTP id p9csp1805320vqx; Tue, 24 Oct 2023 01:52:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMh8L1O1klIp3O1gG65R99LvyVK5q7C7e1XHNa/GCIfsAwGuLp8vtatjM1hPHduX6ClrLY X-Received: by 2002:a05:6a00:1789:b0:6ba:4f2e:33ca with SMTP id s9-20020a056a00178900b006ba4f2e33camr15082748pfg.2.1698137573474; Tue, 24 Oct 2023 01:52:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698137573; cv=none; d=google.com; s=arc-20160816; b=RYQ5JiSXL9qRCc0yjVMHFIQHA0/EchSe1W9KWSmZnmq0SbWcTW1wiW9F0OVEDbEBTb yY+7fJJNokD5Vxl64S2bJvciad51IPLqq4uGh2r9HfWNeuDcgNTcT2Phs+ErZYXVRQbk jCqgqcujG3RDDdBY5puxRgevgddBNuYydTmC4YqOPI+LFoLtJX3McYuxxWw8IABGurfb xy9VKgH0EKqNWhou+HbiuzRuShhR49bk31/QQiSgYexwK2hyZE7uJa1mMzpH6YhAoEDX TS1HCpg3brog4YFn735bdaJdNymGEU+ovbiiB7dKUglvawQ/m+fKCQCZAfnT5TJEL4RT d3bw== 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=6mc2ImTGynSFGgCS40b/9mff9y6G7SrJMB/hVyO1Y/0=; fh=ZASG3onKgAveZ6TNxpl7900VyZ5Kfj0y29rPfJiRy+E=; b=ugSqalVLywHz4IOfi0PuDoS4wm/2h0i1QkJdlUTEJmPltU35aPdu02vEMXOqmz0eF8 Mgn4rtO48SN20IBTQX3XR8xoqavTs+2XFOAs6mzQmd7BvW7G/HvcwM+VmwTMxLy33HtY P6WOF3cZoHzCJ01FOrolzPedA6LQukx+X+37zzsaJAishU3gjlwEZbrvbx+SsHYUUkdy ER5+IK/XxFvcufsDgsiNafWDMMZPpiW+lX67gPqvhCGvpxYtWllOHf/5V0RARuKQnMNJ lxAE8aItLxcAEBNveeEoZh9PGmMyU+W7MPOrKthAvBxgGAruA1qxaOWPXoNHdqipc4u7 evKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yNs2o+s7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LkCkGGNM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id f22-20020a633816000000b005af9c2da89esi8062884pga.74.2023.10.24.01.52.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 01:52:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=yNs2o+s7; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=LkCkGGNM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 8B42B8030BB7; Tue, 24 Oct 2023 01:52:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233977AbjJXIwp (ORCPT + 26 others); Tue, 24 Oct 2023 04:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233903AbjJXIwc (ORCPT ); Tue, 24 Oct 2023 04:52:32 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C6C5128; Tue, 24 Oct 2023 01:52:29 -0700 (PDT) Date: Tue, 24 Oct 2023 08:52:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1698137547; 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=6mc2ImTGynSFGgCS40b/9mff9y6G7SrJMB/hVyO1Y/0=; b=yNs2o+s7Q1vyhVddEyHUUTuzpl/CtVi1bapzZqwPgm4o/tpIaElFfDhgexdKQy+Y3k3Knw g11mynAPTR4zs3PjA3Nms1cz97sHrNfoo0MxCeE/QuM5J3W3pFR8KYs1eiwNqV9uQoelkV LK0oIh96kmkVLtMhaVF14fLplkVN96nForL9eVaY3wuiRoUz9Fc2I4d+vKJ0Zpmm9yMi+F fUuCrOu++JNQD1L8ucvrfRg3v/TClJmuMh8LnL1WaVpVJFYGpStdL3RD4mvWFKszDDOC4D kxLg/1W3NiITvYXfIXb0BH61/xJcmQGAEVBa3LrWsOgqVG3ujy18SOAdiV9tNg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1698137547; 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=6mc2ImTGynSFGgCS40b/9mff9y6G7SrJMB/hVyO1Y/0=; b=LkCkGGNMjmk2f1j/fJUdiiZy/WMpB6+Zi/YMpSjbCAlEYVGplMmZ/PnkcLvrvyyY5hAX7d 0MX6QZa2iZMgnwCQ== From: "tip-bot2 for Hao Jia" 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: Fix RQCF_ACT_SKIP leak Cc: Igor Raits , Bagas Sanjaya , "Peter Zijlstra (Intel)" , Hao Jia , stable@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: References: MIME-Version: 1.0 Message-ID: <169813754711.3135.4535193844351356313.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails 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 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 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 01:52:52 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780626304519868860 X-GMAIL-MSGID: 1780626304519868860 The following commit has been merged into the sched/core branch of tip: Commit-ID: 5ebde09d91707a4a9bec1e3d213e3c12ffde348f Gitweb: https://git.kernel.org/tip/5ebde09d91707a4a9bec1e3d213e3c12ffde348f Author: Hao Jia AuthorDate: Thu, 12 Oct 2023 17:00:03 +08:00 Committer: Peter Zijlstra CommitterDate: Tue, 24 Oct 2023 10:38:42 +02:00 sched/core: Fix RQCF_ACT_SKIP leak Igor Raits and Bagas Sanjaya report a RQCF_ACT_SKIP leak warning. This warning may be triggered in the following situations: CPU0 CPU1 __schedule() *rq->clock_update_flags <<= 1;* unregister_fair_sched_group() pick_next_task_fair+0x4a/0x410 destroy_cfs_bandwidth() newidle_balance+0x115/0x3e0 for_each_possible_cpu(i) *i=0* rq_unpin_lock(this_rq, rf) __cfsb_csd_unthrottle() raw_spin_rq_unlock(this_rq) rq_lock(*CPU0_rq*, &rf) rq_clock_start_loop_update() rq->clock_update_flags & RQCF_ACT_SKIP <-- raw_spin_rq_lock(this_rq) The purpose of RQCF_ACT_SKIP is to skip the update rq clock, but the update is very early in __schedule(), but we clear RQCF_*_SKIP very late, causing it to span that gap above and triggering this warning. In __schedule() we can clear the RQCF_*_SKIP flag immediately after update_rq_clock() to avoid this RQCF_ACT_SKIP leak warning. And set rq->clock_update_flags to RQCF_UPDATED to avoid rq->clock_update_flags < RQCF_ACT_SKIP warning that may be triggered later. Fixes: ebb83d84e49b ("sched/core: Avoid multiple calling update_rq_clock() in __cfsb_csd_unthrottle()") Closes: https://lore.kernel.org/all/20230913082424.73252-1-jiahao.os@bytedance.com Reported-by: Igor Raits Reported-by: Bagas Sanjaya Suggested-by: Peter Zijlstra (Intel) Signed-off-by: Hao Jia Signed-off-by: Peter Zijlstra (Intel) Cc: stable@vger.kernel.org Link: https://lore.kernel.org/all/a5dd536d-041a-2ce9-f4b7-64d8d85c86dc@gmail.com --- kernel/sched/core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 264c2eb..dc724f5 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -5361,8 +5361,6 @@ context_switch(struct rq *rq, struct task_struct *prev, /* switch_mm_cid() requires the memory barriers above. */ switch_mm_cid(rq, prev, next); - rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP); - prepare_lock_switch(rq, next, rf); /* Here we just switch the register state and the stack. */ @@ -6600,6 +6598,7 @@ static void __sched notrace __schedule(unsigned int sched_mode) /* Promote REQ to ACT */ rq->clock_update_flags <<= 1; update_rq_clock(rq); + rq->clock_update_flags = RQCF_UPDATED; switch_count = &prev->nivcsw; @@ -6679,8 +6678,6 @@ static void __sched notrace __schedule(unsigned int sched_mode) /* Also unlocks the rq: */ rq = context_switch(rq, prev, next, &rf); } else { - rq->clock_update_flags &= ~(RQCF_ACT_SKIP|RQCF_REQ_SKIP); - rq_unpin_lock(rq, &rf); __balance_callbacks(rq); raw_spin_rq_unlock_irq(rq);