Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp667166pxb; Tue, 5 Apr 2022 18:00:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfphI7Td0pHfUuMtqu4dLP/qvVHIXYzA+vnAFkZQPr66TzON68ZhnY1Ol3sht7ODm2xYbN X-Received: by 2002:a17:906:3a55:b0:6ce:c2ee:3e10 with SMTP id a21-20020a1709063a5500b006cec2ee3e10mr5680810ejf.210.1649206826845; Tue, 05 Apr 2022 18:00:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649206826; cv=none; d=google.com; s=arc-20160816; b=hSCRUQ18PTVwgxAqpYGSYBoygYYYXhonsyYtRetqF+oabdkmCnGwq8cJPb4UrjS/Lu 0jXieDbPb3NRKlDCuv6EuDJa/cLEilyPwjIpk8np59hp3fhvEcygSm2KZNelEHsSOdrD 8Ya0ivUZIuo9Mv1x1O/d9p+Ig4s4/FD0OOuEU42PBCsWu93mGP+9WIuo064+seNUSr4b PFMVbS1yattXCuqTYCItUnroOV0uyOR2J3GTE9c6I+5sVQp6lQd/7/pQbnPcdxTlMF6Q cKWMhuucp0JHEwTNGjywoDg/UEn4b+raCx/9k+YdQ1h2EP9itcckwOHoxn5xSV9tQvBq ipGA== 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=UYpbpH0JX0VF3kD6lhMK6fOjiF4fSBzlA0MDWjur8hg=; b=UbzAteUDz9UeprM42wAD4hM8wc8Xrpr/p46cjpNEH8xmHeiWMw0luLvOna3A1XPVll Sd99m2g72FprtvxnGZi5xHF1wjo5CTA8qgCNgv903yqwFe5TFcuQF7O8J6oR8by4q/jt C43aDHmvgN02PMPuzEK+zMdL8rxXLjqNVi/4E4C4CYk0tCdgq2XpElhyqtB8o6aLreKN kW/+mYtwsnCf+4GzNAgGCkDoGQd2X6Fr8LFtmJbgwp/c0wVYXBwJWuS4Js5DIQrTauh8 P6Mw2Trwqo/7J6J8WPKKCt/OTZpMk3cwiRTy7H1ZtjEXCVi6nvuLG85Oex1nTTlUYbz2 rXrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=svAhnZb6; 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 jx7-20020a170907760700b006df76385db2si5437052ejc.594.2022.04.05.18.00.00; Tue, 05 Apr 2022 18:00:26 -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=svAhnZb6; 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 S234303AbiDEIMv (ORCPT + 99 others); Tue, 5 Apr 2022 04:12:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233863AbiDEH5r (ORCPT ); Tue, 5 Apr 2022 03:57:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D826553739; Tue, 5 Apr 2022 00:51:33 -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 ams.source.kernel.org (Postfix) with ESMTPS id AAFCAB81B16; Tue, 5 Apr 2022 07:51:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 083FCC340EE; Tue, 5 Apr 2022 07:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649145088; bh=pSydohIEH8hAnUftG32WzdKMxDIz2MIh7j3q0vM9n6U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=svAhnZb6o5NpDW2oTrumtUFOCl/Y5044pVzRlos7+YkIWrd0gvpYZ0JwPkYcrtv9f skovc18z2ncsoM/1wKxgHYD7uCnS6oOIWjUyB/7igKsRtRZ+HwFxFp5MY/1qJUqBaV u7SHKIy/eXFTYlsOyzdomT630gErE4TQcQdQRLK0= 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.17 0280/1126] sched/cpuacct: Fix charge percpu cpuusage Date: Tue, 5 Apr 2022 09:17:07 +0200 Message-Id: <20220405070415.828840858@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@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 3d06c5e4220d..307800586ac8 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c @@ -334,12 +334,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