lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <567481c3-08bc-3bb8-5538-0d296ee539d9@xs4all.nl>
Date:   Thu, 29 Jun 2023 09:03:42 +0200
From:   Hans Verkuil <hverkuil@...all.nl>
To:     Nathan Chancellor <nathan@...nel.org>,
        Arnd Bergmann <arnd@...nel.org>
Cc:     Ezequiel Garcia <ezequiel@...guardiasur.com.ar>,
        Philipp Zabel <p.zabel@...gutronix.de>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Hans Verkuil <hverkuil-cisco@...all.nl>,
        Benjamin Gaignard <benjamin.gaignard@...labora.com>,
        Nicolas Dufresne <nicolas.dufresne@...labora.com>,
        Arnd Bergmann <arnd@...db.de>,
        kernel test robot <lkp@...el.com>,
        Jernej Skrabec <jernej.skrabec@...il.com>,
        linux-media@...r.kernel.org, linux-rockchip@...ts.infradead.org,
        linux-kernel@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH 1/2] media: verisilicon: fix excessive stack usage

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 <arnd@...db.de>
>>
>> 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 <lkp@...el.com>
>> 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 <arnd@...db.de>
> 
> 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 <nathan@...nel.org>
> 
>> ---
>>   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
>>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ