From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.1 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B13ACCA9EC3 for ; Thu, 31 Oct 2019 05:22:20 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6306A20862 for ; Thu, 31 Oct 2019 05:22:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="rF+/ZRGY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6306A20862 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 473Ybt1PbZzF4wD for ; Thu, 31 Oct 2019 16:22:18 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nvidia.com (client-ip=216.228.121.143; helo=hqemgate14.nvidia.com; envelope-from=jhubbard@nvidia.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=nvidia.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=nvidia.com header.i=@nvidia.com header.b="rF+/ZRGY"; dkim-atps=neutral Received: from hqemgate14.nvidia.com (hqemgate14.nvidia.com [216.228.121.143]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 473YYC0j3jzF3GG for ; Thu, 31 Oct 2019 16:19:58 +1100 (AEDT) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Wed, 30 Oct 2019 22:20:01 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Wed, 30 Oct 2019 22:19:55 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Wed, 30 Oct 2019 22:19:55 -0700 Received: from [10.2.172.9] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 31 Oct 2019 05:19:53 +0000 Subject: Re: [PATCH v2] cpufreq: powernv: fix stack bloat and NR_CPUS limitation To: Michael Ellerman , Viresh Kumar , Shilpasri G Bhat References: <20191018045539.3765565-1-jhubbard@nvidia.com> <87pnidbptw.fsf@mpe.ellerman.id.au> X-Nvconfidentiality: public From: John Hubbard Message-ID: <405c2ac2-a61c-e7e6-3487-c55bcdf1e839@nvidia.com> Date: Wed, 30 Oct 2019 22:17:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <87pnidbptw.fsf@mpe.ellerman.id.au> X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1572499201; bh=Lgg3WPBQcbXMUHYh4dycG3/ll1LXNGzsuqWxnAt4TKM=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=rF+/ZRGYrkR9VRln6J5ePJeOIpT6GvsoLVg88ufoOYIY7pXltVb3YHDWZvgJCIyWo ihWk8+KEWdwR3jW6DpWyPcYl3rvT8NwfjaE6bShuYysDPGs/TFM01m1ogW/jmf7mVM aUjXhy83XPqTOu1Uo/PUt+js7RvguT0tAloLNdtPDAcbljqkBLqrXuPrcbczL+SNN2 gMsxDUxVw+GiXXRLQMnK9Zi36ntanv+qzJFK0Zf7oTyR8RRHghv1IAl1qrfxumvDJv q4kljYJqN8tNueKEaIQZUXvW2SJcAsE7X6ojukF9AXR1DBJlobRAl3j+zSwFbNCLyT DWiZAxhoLJKwg== X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Preeti U Murthy , linuxppc-dev@lists.ozlabs.org, "Rafael J . Wysocki" , LKML , linux-pm@vger.kernel.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 10/30/19 7:39 PM, Michael Ellerman wrote: > Hi John, > > Sorry I didn't reply to this sooner, too many patches :/ > > John Hubbard writes: >> The following build warning occurred on powerpc 64-bit builds: >> >> drivers/cpufreq/powernv-cpufreq.c: In function 'init_chip_info': >> drivers/cpufreq/powernv-cpufreq.c:1070:1: warning: the frame size of 1040 bytes is larger than 1024 bytes [-Wframe-larger-than=] > > Oddly I don't see that warning in my builds, eg with GCC9: > > https://travis-ci.org/linuxppc/linux/jobs/604870722 This is with a cross-compiler based on gcc 8.1.0, which I got from: https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.1.0/ I'll put that in the v3 commit description. > >> This is due to putting 1024 bytes on the stack: >> >> unsigned int chip[256]; >> >> ...and while looking at this, it also has a bug: it fails with a stack >> overrun, if CONFIG_NR_CPUS > 256. > > It _probably_ doesn't, because it only increments the index when the > chip_id of the CPU changes, ie. it doesn't create a chip for every CPU. > But I agree it's flaky the way it's written. I'll soften up the wording accordingly. > >> Fix both problems by dynamically allocating based on CONFIG_NR_CPUS. > > Shouldn't it use num_possible_cpus() ? > > Given the for loop is over possible CPUs that seems like the upper > bound. In practice it should be lower because some CPUs will share a > chip. > OK, I see, that's more consistent with the code, I'll change to that. thanks, -- John Hubbard NVIDIA > > >> Fixes: 053819e0bf840 ("cpufreq: powernv: Handle throttling due to Pmax capping at chip level") >> Cc: Shilpasri G Bhat >> Cc: Preeti U Murthy >> Cc: Viresh Kumar >> Cc: Rafael J. Wysocki >> Cc: linux-pm@vger.kernel.org >> Cc: linuxppc-dev@lists.ozlabs.org >> Signed-off-by: John Hubbard >> --- >> >> Changes since v1: includes Viresh's review commit fixes. >> >> drivers/cpufreq/powernv-cpufreq.c | 17 +++++++++++++---- >> 1 file changed, 13 insertions(+), 4 deletions(-) >> >> diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c >> index 6061850e59c9..5b2e968cb5ea 100644 >> --- a/drivers/cpufreq/powernv-cpufreq.c >> +++ b/drivers/cpufreq/powernv-cpufreq.c >> @@ -1041,9 +1041,14 @@ static struct cpufreq_driver powernv_cpufreq_driver = { >> >> static int init_chip_info(void) >> { >> - unsigned int chip[256]; >> + unsigned int *chip; >> unsigned int cpu, i; >> unsigned int prev_chip_id = UINT_MAX; >> + int ret = 0; >> + >> + chip = kcalloc(CONFIG_NR_CPUS, sizeof(*chip), GFP_KERNEL); >> + if (!chip) >> + return -ENOMEM; >> >> for_each_possible_cpu(cpu) { >> unsigned int id = cpu_to_chip_id(cpu); >> @@ -1055,8 +1060,10 @@ static int init_chip_info(void) >> } >> >> chips = kcalloc(nr_chips, sizeof(struct chip), GFP_KERNEL); >> - if (!chips) >> - return -ENOMEM; >> + if (!chips) { >> + ret = -ENOMEM; >> + goto free_and_return; >> + } >> >> for (i = 0; i < nr_chips; i++) { >> chips[i].id = chip[i]; >> @@ -1066,7 +1073,9 @@ static int init_chip_info(void) >> per_cpu(chip_info, cpu) = &chips[i]; >> } >> >> - return 0; >> +free_and_return: >> + kfree(chip); >> + return ret; >> } >> >> static inline void clean_chip_info(void) >> -- >> 2.23.0