Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp673761pxb; Tue, 5 Apr 2022 18:13:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqSPYcI6bwcws6D1a81PyUqSErB7JopyXJwuLljjNIpYK3o+if9aNPUCcisaXV/oNy8sC9 X-Received: by 2002:a05:6402:26d3:b0:418:d202:d5dc with SMTP id x19-20020a05640226d300b00418d202d5dcmr6321136edd.138.1649207627134; Tue, 05 Apr 2022 18:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649207627; cv=none; d=google.com; s=arc-20160816; b=hNkmNFSwq5sOK42Rvnnwu/OkjLKlIeFTzGuBY8rE7YDFzdKEvS+P/jwDNX/SVbRR1g vCh7yLyOZt7ZHTvNUPIfM9ieI8iD7K5YvQSK5VPdFbztoo+djeTmTqkDFDkwftyQbAFc lNLmHX00NXrzwbQR19iKmBGQkD+yoyYXFROcj04jhhCePF3ITgcbbijGJlP7pQGYrSgs Vf+2GyU3Zj8GXYIIdDvBoAbVzz8Kn8isKzAScVRfKRt3LWM6rwweQaPiNos33Jfr8jW0 6D2BN+yiI+pGpqGG99dLQt9wM7G2BnureQjU/8ZSMQwuPF2BwZsq1O6L7cNWyK8OC1aB TO/w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QkCLb2uHApPUbe7Gnr24VZznwGOCtyEcB1fOYi1WqhM=; b=PweSdOgzCfTfLx6HcpQJrAEBCoBTfxbKsBl+cfV6x7a4KcyVBdXlWre5HM8+VCg/iv lptChY/dfwPYk6YnmlEQYF6CNzB5p2gS3MPRCNTHn6v3X2PVG1TPijiTXbaW+HfLgH0T LwfYFU9FWA9jBaagfs7q3tNJDhp4ZriOYosS6+Qe2nLfCjQuN0H0SxZN9KjNr1YKoNZo 2qOzhC/icTcveEOIFWxDXbDh/e/zjuWsTiR2vx4h9+lmGUFebqugWeL0nWGSstRP4yno EwLQsZ9EYs17mODsd2B8+MOXVTUC+RJhfgvhSomhc9x9hJMfOKFb6YU6fK6XM2m9QBML 3Igg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="OYHu23M/"; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a50cf86000000b0041978294066si10180840edk.275.2022.04.05.18.13.20; Tue, 05 Apr 2022 18:13:47 -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=@linuxfoundation.org header.s=korg header.b="OYHu23M/"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349993AbiDEPLq (ORCPT + 99 others); Tue, 5 Apr 2022 11:11:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345995AbiDEJoQ (ORCPT ); Tue, 5 Apr 2022 05:44:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E6E5C6EC2; Tue, 5 Apr 2022 02:29:54 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BC980616B6; Tue, 5 Apr 2022 09:29:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C02CFC385A4; Tue, 5 Apr 2022 09:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150993; bh=f7lk/uatWZehCCEatvm6qnumEhlCGUuUHdGZqbrb3Fw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OYHu23M/P8LgKmDUonyIo8DyaS7veL0Knj4HdzUyOhupWOE6LM4FqiBVGdeOyDBlU 46/sZ8UVU00xQUO+eqea/6UJ2uyiz/ZFCFmzhxGIZWyC3mzl0Lu3YSawqowfEUyTYZ E+VBB/UYmJVgN0pcuXkTnrHbhcfXUEytuTn2+UDY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Minye Zhu , Chengming Zhou , "Peter Zijlstra (Intel)" , Tejun Heo , Sasha Levin Subject: [PATCH 5.15 256/913] sched/cpuacct: Fix charge percpu cpuusage Date: Tue, 5 Apr 2022 09:21:58 +0200 Message-Id: <20220405070347.528824559@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Chengming Zhou [ Upstream commit 248cc9993d1cc12b8e9ed716cc3fc09f6c3517dd ] The cpuacct_account_field() is always called by the current task itself, so it's ok to use __this_cpu_add() to charge the tick time. But cpuacct_charge() maybe called by update_curr() in load_balance() on a random CPU, different from the CPU on which the task is running. So __this_cpu_add() will charge that cputime to a random incorrect CPU. Fixes: 73e6aafd9ea8 ("sched/cpuacct: Simplify the cpuacct code") Reported-by: Minye Zhu Signed-off-by: Chengming Zhou Signed-off-by: Peter Zijlstra (Intel) Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20220220051426.5274-1-zhouchengming@bytedance.com Signed-off-by: Sasha Levin --- kernel/sched/cpuacct.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index ab67d97a8442..cacc2076ad21 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c @@ -328,12 +328,13 @@ static struct cftype files[] = { */ void cpuacct_charge(struct task_struct *tsk, u64 cputime) { + unsigned int cpu = task_cpu(tsk); struct cpuacct *ca; rcu_read_lock(); for (ca = task_ca(tsk); ca; ca = parent_ca(ca)) - __this_cpu_add(*ca->cpuusage, cputime); + *per_cpu_ptr(ca->cpuusage, cpu) += cputime; rcu_read_unlock(); } -- 2.34.1