Re: [PATCH v2] xtensa: remove redundant flush_dcache_page and ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE macros

From: Barry Song
Date: Mon Mar 18 2024 - 22:16:25 EST


On Tue, Mar 19, 2024 at 3:12 PM Max Filippov <jcmvbkbc@xxxxxxxxx> wrote:
>
> On Mon, Mar 18, 2024 at 6:27 PM Barry Song <21cnbao@xxxxxxxxx> wrote:
> > On Tue, Mar 19, 2024 at 2:09 PM Barry Song <21cnbao@xxxxxxxxx> wrote:
> > > From: Barry Song <v-songbaohua@xxxxxxxx>
> > >
> > > xtensa's flush_dcache_page() can be a no-op sometimes. There is a
> > > generic implementation for this case in include/asm-generic/
> > > cacheflush.h.
> > > #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
> > > static inline void flush_dcache_page(struct page *page)
> > > {
> > > }
> > >
> > > #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
> > > #endif
> > >
> > > So remove the superfluous flush_dcache_page() definition, which also
> > > helps silence potential build warnings complaining the page variable
> > > passed to flush_dcache_page() is not used.
> > >
> > > In file included from crypto/scompress.c:12:
> > > include/crypto/scatterwalk.h: In function 'scatterwalk_pagedone':
> > > include/crypto/scatterwalk.h:76:30: warning: variable 'page' set but not used [-Wunused-but-set-variable]
> > > 76 | struct page *page;
> > > | ^~~~
> > > crypto/scompress.c: In function 'scomp_acomp_comp_decomp':
> > > >> crypto/scompress.c:174:38: warning: unused variable 'dst_page' [-Wunused-variable]
> > > 174 | struct page *dst_page = sg_page(req->dst);
> > > |
> > >
> > > The issue was originally reported on LoongArch by kernel test
> > > robot (Huacai fixed it on LoongArch), then reported by Guenter
> > > and me on xtensa.
>
> I wonder why this warning is considered useful in the first place?

Guenter reported it as an error not a warning
"

Error log:
crypto/scompress.c: In function 'scomp_acomp_comp_decomp':
crypto/scompress.c:174:38: error: unused variable 'dst_page'"

is it because xtensa's toolchain is different with others?



> If I'm missing something and it's indeed useful, should there be a
> rule in the Documentation/process/coding-style.rst saying that
> function-like macros should evaluate all their arguments?
>
> > > This patch also removes lots of redundant macros which have
> > > been defined by asm-generic/cacheflush.h.
> > >
> > > Cc: Huacai Chen <chenhuacai@xxxxxxxxxxx>
> > > Cc: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
> > > Reported-by: kernel test robot <lkp@xxxxxxxxx>
> > > Closes: https://lore.kernel.org/oe-kbuild-all/202403091614.NeUw5zcv-lkp@xxxxxxxxx/
> > > Reported-by: Barry Song <v-songbaohua@xxxxxxxx>
> > > Closes: https://lore.kernel.org/all/CAGsJ_4yDk1+axbte7FKQEwD7X2oxUCFrEc9M5YOS1BobfDFXPA@xxxxxxxxxxxxxx/
> > > Reported-by: Guenter Roeck <linux@xxxxxxxxxxxx>
> >
> > Hi Guenter,
> > I am not a xtensa guy, so I will need your help for a full test. if
> > turns out it is a too big(ambitious)
> > fix, a minimal fix might be:
> >
> > diff --git a/arch/xtensa/include/asm/cacheflush.h
> > b/arch/xtensa/include/asm/cacheflush.h
> > index 38bcecb0e457..fdc692cf2b78 100644
> > --- a/arch/xtensa/include/asm/cacheflush.h
> > +++ b/arch/xtensa/include/asm/cacheflush.h
> > @@ -145,7 +145,7 @@ void local_flush_cache_page(struct vm_area_struct *vma,
> > #define flush_cache_vunmap(start,end) do { } while (0)
> >
> > #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 0
> > -#define flush_dcache_page(page) do { } while (0)
> > +#define flush_dcache_page(page) do {
> > (void)(page); } while (0)
>
> This looks like a good fix, IMO better than adding __maybe_unused
> to the variables reported in the warnings.

i don't like adding __maybe_unused either as it is not the fault
of the drivers calling flush_dcache_page().

>
> --
> Thanks.
> -- Max