Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20362681rwd; Thu, 29 Jun 2023 00:59:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlEu1OAXVNVgp1Bzs5F6WKjQiEkE5Yg7IVLhefur/eOJvpBmPOug6rYCxDdHo3k2QyaDgCR/ X-Received: by 2002:a17:90b:157:b0:263:5637:abf8 with SMTP id em23-20020a17090b015700b002635637abf8mr933611pjb.13.1688025577535; Thu, 29 Jun 2023 00:59:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688025577; cv=none; d=google.com; s=arc-20160816; b=XJuayqWdtVtS22lUs2FHgRez7jMjbJcq34VZME5SxN3dzs3hvx6TsioY1ZJrOWCyYB bEcbt6OtBDo8NTPHmIqD6LpZ7wKWZ1r6c0hA/imfQOXFpg/YwVKAiDhuZvGJ9DXX0iYe lI/yA6i4nxXYSeRsP0fFmVsDZWvw5QZc7i8eMzvddgau0op6dq4wAi2niqjnNwGkQnQU 9rkj6MmHY2LRUMnVakDE98E96ftwf5DMvRxApAl/Z5pvlee+wVt+97vzzWGJ1N2HIJR9 vUYnVoIDjHKaKTKvaziHlCbhl7YaATYVw18pDiXoScAXTK7FfY2OWAoLMFZS1fK26rwI IXNw== 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:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=C6fArsiWEwtar2WSArq5lOhei5J9Yc822vUMBhWs9BQ=; fh=3TPWx1Lsje+lP/EXV/SMHxVN+5cUBEw1Ccu4hyvVaKA=; b=BYvB48ycxSqrnTG10Lf+D6DpYonlP1quV+Ps7J++SmefBeaJXw+vjt57R7kIfNMgOy zIZ3CmLLW/vSYVVYnRHbYx0iwhHJ5ln4ozUH55mtBgYpAuCw8MKQjGmAwbkvdBfoHHJ9 y5l5UDl5RLP1Y+GGNlBXz+OzYedcTtMWKcvOFplKepECint1jusxPkLd0lCiBC6PEKX0 3U3Ud+Qj1i98s0fPBiMUF4PqTKipEv4gLakLTa7ADqO/+ZCcHA5zWMWoZn/0fTPrYWaX CqSgezpwUIidsoKJbU8Fc82qlrBqVWBprfI8CiCZxxvg4ZCENmHBTsFA0HLIB/BBpJHm mZfQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h17-20020a17090ac39100b00256615e8d90si6084900pjt.49.2023.06.29.00.59.23; Thu, 29 Jun 2023 00:59:37 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231910AbjF2HDx (ORCPT + 99 others); Thu, 29 Jun 2023 03:03:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231430AbjF2HDu (ORCPT ); Thu, 29 Jun 2023 03:03:50 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1D5A1BE1; Thu, 29 Jun 2023 00:03:48 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3BA3B6148F; Thu, 29 Jun 2023 07:03:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 994CEC433C0; Thu, 29 Jun 2023 07:03:44 +0000 (UTC) Message-ID: <567481c3-08bc-3bb8-5538-0d296ee539d9@xs4all.nl> Date: Thu, 29 Jun 2023 09:03:42 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 1/2] media: verisilicon: fix excessive stack usage To: Nathan Chancellor , Arnd Bergmann Cc: Ezequiel Garcia , Philipp Zabel , Mauro Carvalho Chehab , Hans Verkuil , Benjamin Gaignard , Nicolas Dufresne , Arnd Bergmann , kernel test robot , Jernej Skrabec , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev References: <20230616144854.3818934-1-arnd@kernel.org> <20230628182617.GA911656@dev-arch.thelio-3990X> Content-Language: en-US From: Hans Verkuil In-Reply-To: <20230628182617.GA911656@dev-arch.thelio-3990X> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,NICE_REPLY_A,RCVD_IN_DNSWL_MED, 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 Hi all, On 6/28/23 20:26, Nathan Chancellor wrote: > On Fri, Jun 16, 2023 at 04:48:47PM +0200, Arnd Bergmann wrote: >> From: Arnd Bergmann >> >> In some configurations, gcc decides not to inline the register accessor functions, >> which in turn leads to lots of temporary hantro_reg structures on the stack that >> cannot be eliminated because they escape into an uninlined function: >> >> drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c:1022:1: warning: the frame size of 1112 bytes is larger than 1024 bytes [-Wframe-larger-than=] >> >> Mark all of these as __always_inline so the compiler is able to completely >> eliminate the temporary structures instead, which brings the stack usage >> back down to just the normal local variables. >> >> Reported-by: kernel test robot >> Closes: https://lore.kernel.org/oe-kbuild-all/202306151506.goHEegOd-lkp@intel.com/ >> Fixes: 727a400686a2c ("media: verisilicon: Add Rockchip AV1 decoder") >> Signed-off-by: Arnd Bergmann > > For what it's worth, this patch massively helps with avoiding a warning > with clang 16.x and older, for presumably a similar reason, since this > happens with allmodconfig, which turns on a bunch of sanitizers. > > https://github.com/ClangBuiltLinux/linux/issues/1875 > > Before this change: > > drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c:2097:5: error: stack frame size (2096) exceeds limit (2048) in 'rockchip_vpu981_av1_dec_run' [-Werror,-Wframe-larger-than] > int rockchip_vpu981_av1_dec_run(struct hantro_ctx *ctx) > ^ > 238/2096 (11.35%) spills, 1858/2096 (88.65%) variables > > After this change: > > drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c:2097:5: error: stack frame size (496) exceeds limit (200) in 'rockchip_vpu981_av1_dec_run' [-Werror,-Wframe-larger-than] > int rockchip_vpu981_av1_dec_run(struct hantro_ctx *ctx) > ^ > 265/496 (53.43%) spills, 231/496 (46.57%) variables > > If this could be picked up either before the 6.5 media pull goes out or > at some point during the -rc cycle, that would be great! Once the merge window closes I'll make a PR to get it in 6.5. Regards, Hans > > Tested-by: Nathan Chancellor > >> --- >> drivers/media/platform/verisilicon/hantro.h | 22 ++++++++++----------- >> 1 file changed, 11 insertions(+), 11 deletions(-) >> >> diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h >> index 6523ffb748812..6c5e56ce5b351 100644 >> --- a/drivers/media/platform/verisilicon/hantro.h >> +++ b/drivers/media/platform/verisilicon/hantro.h >> @@ -370,26 +370,26 @@ extern int hantro_debug; >> pr_err("%s:%d: " fmt, __func__, __LINE__, ##args) >> >> /* Structure access helpers. */ >> -static inline struct hantro_ctx *fh_to_ctx(struct v4l2_fh *fh) >> +static __always_inline struct hantro_ctx *fh_to_ctx(struct v4l2_fh *fh) >> { >> return container_of(fh, struct hantro_ctx, fh); >> } >> >> /* Register accessors. */ >> -static inline void vepu_write_relaxed(struct hantro_dev *vpu, >> +static __always_inline void vepu_write_relaxed(struct hantro_dev *vpu, >> u32 val, u32 reg) >> { >> vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val); >> writel_relaxed(val, vpu->enc_base + reg); >> } >> >> -static inline void vepu_write(struct hantro_dev *vpu, u32 val, u32 reg) >> +static __always_inline void vepu_write(struct hantro_dev *vpu, u32 val, u32 reg) >> { >> vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val); >> writel(val, vpu->enc_base + reg); >> } >> >> -static inline u32 vepu_read(struct hantro_dev *vpu, u32 reg) >> +static __always_inline u32 vepu_read(struct hantro_dev *vpu, u32 reg) >> { >> u32 val = readl(vpu->enc_base + reg); >> >> @@ -397,27 +397,27 @@ static inline u32 vepu_read(struct hantro_dev *vpu, u32 reg) >> return val; >> } >> >> -static inline void vdpu_write_relaxed(struct hantro_dev *vpu, >> +static __always_inline void vdpu_write_relaxed(struct hantro_dev *vpu, >> u32 val, u32 reg) >> { >> vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val); >> writel_relaxed(val, vpu->dec_base + reg); >> } >> >> -static inline void vdpu_write(struct hantro_dev *vpu, u32 val, u32 reg) >> +static __always_inline void vdpu_write(struct hantro_dev *vpu, u32 val, u32 reg) >> { >> vpu_debug(6, "0x%04x = 0x%08x\n", reg / 4, val); >> writel(val, vpu->dec_base + reg); >> } >> >> -static inline void hantro_write_addr(struct hantro_dev *vpu, >> +static __always_inline void hantro_write_addr(struct hantro_dev *vpu, >> unsigned long offset, >> dma_addr_t addr) >> { >> vdpu_write(vpu, addr & 0xffffffff, offset); >> } >> >> -static inline u32 vdpu_read(struct hantro_dev *vpu, u32 reg) >> +static __always_inline u32 vdpu_read(struct hantro_dev *vpu, u32 reg) >> { >> u32 val = readl(vpu->dec_base + reg); >> >> @@ -425,7 +425,7 @@ static inline u32 vdpu_read(struct hantro_dev *vpu, u32 reg) >> return val; >> } >> >> -static inline u32 vdpu_read_mask(struct hantro_dev *vpu, >> +static __always_inline u32 vdpu_read_mask(struct hantro_dev *vpu, >> const struct hantro_reg *reg, >> u32 val) >> { >> @@ -437,14 +437,14 @@ static inline u32 vdpu_read_mask(struct hantro_dev *vpu, >> return v; >> } >> >> -static inline void hantro_reg_write(struct hantro_dev *vpu, >> +static __always_inline void hantro_reg_write(struct hantro_dev *vpu, >> const struct hantro_reg *reg, >> u32 val) >> { >> vdpu_write_relaxed(vpu, vdpu_read_mask(vpu, reg, val), reg->base); >> } >> >> -static inline void hantro_reg_write_s(struct hantro_dev *vpu, >> +static __always_inline void hantro_reg_write_s(struct hantro_dev *vpu, >> const struct hantro_reg *reg, >> u32 val) >> { >> -- >> 2.39.2 >>