Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1582342rwb; Thu, 15 Dec 2022 11:56:10 -0800 (PST) X-Google-Smtp-Source: AA0mqf7F9uriTg1CjhyyIeWDrG41BdCTH8TekPraVHHFGNCinBA9VSQT1odq9TqTdy9wHrlmRsqU X-Received: by 2002:a05:6a00:1513:b0:576:f7bd:92d4 with SMTP id q19-20020a056a00151300b00576f7bd92d4mr39083767pfu.30.1671134170363; Thu, 15 Dec 2022 11:56:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671134170; cv=none; d=google.com; s=arc-20160816; b=T4P+5EYPj7BSDXLsDGp3lpHFJjaR5K7F2Eod1jJo+N5YtDGnfgAMy4UsknZku7/4tv 1Ux9mMEq9NcCyogo69RU0AxtKC+/lFxtsIZKBJK63SG4UTPATjsTmnSn3gpii7CvgJFB +PlxhySuJuuv8JtKxdtKfRfe608Si+qsbp5LfH+DkgiGP2NpgN5I8+SguNtvFZgYAC0D XKNn1PmXzuOEW4TaD3/cTXOebaWWQG+mlmVcxxwEGIKGIOvq1U+P+xR/AoKjiqiTwyIx OKt5aAOxXSvEi2bm4vxXMkFewLIH75+7/tQDKqR3R0PLFZFLtEXWuyXkMYR34iEx54U+ Kp+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:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id; bh=Pr41AnuKpI1R4bKDndWvtCUV/lbtkGwHKldk9WUKlrA=; b=fsdS15TRw5FhKdIXLXTRgfpMmyq/RYYjOmuyYRB9IEk35E9HM37i7TgxOxJqYXNa+5 hqRYXw4OtF3GV7ncZ+YUaqMkNmp4YLyc0A/oqlffiEWclqtu84bYqdj+sAEfK/LgXoPd Ws3TV5ZzH0+ZGqEC3wpXWW5w3dRTUNZt7TZr6WK6NAX2Ef6Im5P7B0HIZDuCY3++80ce Mu/c8e7EJzPJIhoFavEUsQlx0pZmL3fdPiSELEst787iistbB/uH/ymVw/DY5VkuAQOy W2CdC38rd52LOxIpswWsEwWda1ONvgo1W8ob/QfRp97Wi2pWyxar7Py3x6lCUiyY+pOM gUDg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dc8-20020a056a0035c800b00566a131ea12si3429475pfb.289.2022.12.15.11.56.01; Thu, 15 Dec 2022 11:56:10 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbiLOTtO (ORCPT + 68 others); Thu, 15 Dec 2022 14:49:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229820AbiLOTtK (ORCPT ); Thu, 15 Dec 2022 14:49:10 -0500 Received: from smtp.smtpout.orange.fr (smtp-17.smtpout.orange.fr [80.12.242.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AE55537F8 for ; Thu, 15 Dec 2022 11:49:08 -0800 (PST) Received: from [192.168.1.18] ([86.243.100.34]) by smtp.orange.fr with ESMTPA id 5uE3pbl9p4s3d5uE4pTEzM; Thu, 15 Dec 2022 20:49:07 +0100 X-ME-Helo: [192.168.1.18] X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 15 Dec 2022 20:49:07 +0100 X-ME-IP: 86.243.100.34 Message-ID: <24af516c-53db-c4f5-6745-7e3a4a2fdf26@wanadoo.fr> Date: Thu, 15 Dec 2022 20:49:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] drm/amd/pm: avoid large variable on kernel stack Content-Language: fr From: Marion & Christophe JAILLET To: arnd@kernel.org Cc: Hawking.Zhang@amd.com, Jack.Gui@amd.com, KevinYang.Wang@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, alexander.deucher@amd.com, amd-gfx@lists.freedesktop.org, arnd@arndb.de, christian.koenig@amd.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, evan.quan@amd.com, kenneth.feng@amd.com, linux-kernel@vger.kernel.org, llvm@lists.linux.dev, nathan@kernel.org, ndesaulniers@google.com, trix@redhat.com References: <20221215163649.386750-1-arnd@kernel.org> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, 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 Le 15/12/2022 à 20:46, Christophe JAILLET a écrit : > Le 15/12/2022 à 17:36, Arnd Bergmann a écrit : >> From: Arnd Bergmann >> >> The activity_monitor_external[] array is too big to fit on the >> kernel stack, resulting in this warning with clang: >> >> drivers/gpu/drm/amd/amdgpu/../pm/swsmu/smu13/smu_v13_0_7_ppt.c:1438:12: error: stack frame size (1040) exceeds limit (1024) in 'smu_v13_0_7_get_power_profile_mode' [-Werror,-Wframe-larger-than] >> >> Use dynamic allocation instead. It should also be possible to >> have single element here instead of the array, but this seems >> easier. >> >> Fixes: 334682ae8151 ("drm/amd/pm: enable workload type change on >> smu_v13_0_7") >> Signed-off-by: Arnd Bergmann >> --- >>   .../drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c  | 21 ++++++++++++++----- >>   1 file changed, 16 insertions(+), 5 deletions(-) >> >> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> index c270f94a1b86..7eba854e09ec 100644 >> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c >> @@ -1439,7 +1439,7 @@ static int smu_v13_0_7_get_power_limit(struct >> smu_context *smu, >>   static int smu_v13_0_7_get_power_profile_mode(struct smu_context >> *smu, char *buf) >>   { >> -    DpmActivityMonitorCoeffIntExternal_t >> activity_monitor_external[PP_SMC_POWER_PROFILE_COUNT]; >> +    DpmActivityMonitorCoeffIntExternal_t *activity_monitor_external; >>       uint32_t i, j, size = 0; >>       int16_t workload_type = 0; >>       int result = 0; >> @@ -1447,6 +1447,12 @@ static int >> smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf >>       if (!buf) >>           return -EINVAL; >> +    activity_monitor_external = >> kcalloc(sizeof(activity_monitor_external), > > Hi, > > Before, 'activity_monitor_external' was not initialized. > Maybe kcalloc() is enough? Read kmalloc_array() > > sizeof(*activity_monitor_external)? >      ~~~~ > >> +                        PP_SMC_POWER_PROFILE_COUNT, >> +                        GFP_KERNEL); >> +    if (!activity_monitor_external) >> +        return -ENOMEM; >> + >>       size += sysfs_emit_at(buf, size, "                              "); >>       for (i = 0; i <= PP_SMC_POWER_PROFILE_WINDOW3D; i++) > > Unrelated, but wouldn't it be more straightforward with "< > PP_SMC_POWER_PROFILE_COUNT"? > >>           size += sysfs_emit_at(buf, size, "%-14s%s", >> amdgpu_pp_profile_name[i], >> @@ -1459,15 +1465,17 @@ static int >> smu_v13_0_7_get_power_profile_mode(struct smu_context *smu, char *buf >>           workload_type = smu_cmn_to_asic_specific_index(smu, >>                                      CMN2ASIC_MAPPING_WORKLOAD, >>                                      i); >> -        if (workload_type < 0) >> -            return -EINVAL; >> +        if (workload_type < 0) { >> +            result = -EINVAL; >> +            goto out; >> +        } >>           result = smu_cmn_update_table(smu, >>                         SMU_TABLE_ACTIVITY_MONITOR_COEFF, workload_type, >>                         (void *)(&activity_monitor_external[i]), false); >>           if (result) { >>               dev_err(smu->adev->dev, "[%s] Failed to get activity >> monitor!", __func__); >> -            return result; >> +            goto out; >>           } >>       } >> @@ -1495,7 +1503,10 @@ do >> {                                                    \ >>       PRINT_DPM_MONITOR(Fclk_BoosterFreq); >>   #undef PRINT_DPM_MONITOR >> -    return size; >> +    result = size; >> +out: >> +    kfree(activity_monitor_external); >> +    return result; >>   } >>   static int smu_v13_0_7_set_power_profile_mode(struct smu_context >> *smu, long *input, uint32_t size) > >