Re: [PATCH V5 12/20] asm-generic/io.h: iounmap/ioport_unmap cleanup.h support

From: Baoquan He
Date: Sun Dec 10 2023 - 10:26:19 EST


On 11/27/23 at 05:55pm, David E. Box wrote:
> +Baoquan for ioremap question.
>
> On Thu, 2023-11-23 at 16:30 +0200, Ilpo Järvinen wrote:
> > On Wed, 22 Nov 2023, David E. Box wrote:
> >
> > > Add auto-release cleanups for iounmap() and ioport_unmap().
> > >
> > > Signed-off-by: David E. Box <david.e.box@xxxxxxxxxxxxxxx>
> > > Suggested-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
> > > ---
> > > V2 - Move from linux/io.h to asm-generic/io.h. Adds iounmap cleanup if
> > >      iounmap() is defined. Adds ioport_unmap cleanup if CONFIG_IOPORT_MAP
> > >      is defined.
> > >
> > >  include/asm-generic/io.h | 6 ++++++
> > >  1 file changed, 6 insertions(+)
> > >
> > > diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
> > > index bac63e874c7b..9ef0332490b1 100644
> > > --- a/include/asm-generic/io.h
> > > +++ b/include/asm-generic/io.h
> > > @@ -8,6 +8,7 @@
> > >  #define __ASM_GENERIC_IO_H
> > >  
> > >  #include <asm/page.h> /* I/O is all done through memory accesses */
> > > +#include <linux/cleanup.h>
> > >  #include <linux/string.h> /* for memset() and memcpy() */
> > >  #include <linux/types.h>
> > >  #include <linux/instruction_pointer.h>
> > > @@ -1065,6 +1066,10 @@ static inline void __iomem *ioremap(phys_addr_t addr,
> > > size_t size)
> > >  #endif
> > >  #endif /* !CONFIG_MMU || CONFIG_GENERIC_IOREMAP */
> > >  
> > > +#ifdef iounmap
> > > +DEFINE_FREE(iounmap, void __iomem *, iounmap(_T));
> > > +#endif
>
> Baoquan, LKP is reporting an undeclared function 'iounmap' error with the above
> change from this patch when building for s390 with PCI disabled. The ioremap
> defines in arch/s390/include/asm/io.h are not wrapped under the #ifdef
> CONFIG_PCI block. Shouldn't they be since the s390 Kconfig only adds
> GENERIC_IOREMAP if PCI?
>
> https://lore.kernel.org/oe-kbuild-all/202311241214.jcL84du7-lkp@xxxxxxxxx

I tried to reproduce the error, while I got failure as below. I will find a
s390x machine to try again.

---------------------------------------------------------
[root@ linux]# COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang-16 ~/lkp-tests/kbuild/make.cross W=1 O=build_dir ARCH=s390 olddefconfig
Compiler will be installed in /root/0day
PATH=/root/0day/llvm-16.0.6-x86_64/bin:/root/.local/bin:/root/bin:/usr/lib64/ccache:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
make --keep-going HOSTCC=/root/0day/llvm-16.0.6-x86_64/bin/clang CC=/root/0day/llvm-16.0.6-x86_64/bin/clang OBJCOPY=/usr/s390x-linux-gnu/bin/objcopy AR=llvm-ar NM=llvm-nm STRIP=llvm-strip OBJDUMP=llvm-objdump OBJSIZE=llvm-size READELF=llvm-readelf HOSTCXX=clang++ HOSTAR=llvm-ar CROSS_COMPILE=s390x-linux-gnu- --jobs=128 KCFLAGS= -Wtautological-compare -Wno-error=return-type -Wreturn-type -Wcast-function-type -funsigned-char -Wundef -fstrict-flex-arrays=3 -Wenum-conversion W=1 O=build_dir ARCH=s390 olddefconfig
make[1]: Entering directory '/root/linux/build_dir'
GEN Makefile
scripts/Kconfig.include:40: linker 's390x-linux-gnu-ld' not found
make[3]: *** [../scripts/kconfig/Makefile:77: olddefconfig] Error 1
make[2]: *** [/root/linux/Makefile:685: olddefconfig] Error 2
make[1]: *** [/root/linux/Makefile:234: __sub-make] Error 2
make[1]: Target 'olddefconfig' not remade because of errors.
make[1]: Leaving directory '/root/linux/build_dir'
make: *** [Makefile:234: __sub-make] Error 2
make: Target 'olddefconfig' not remade because of errors.
------------------------------------------------------------------

And when I execute the 3rd step of reproducer to apply the required
patch series, I never succeed. Don't know why.

----------------------------------------------------------------
[root@intel-knightslanding-lb-02 linux]# b4 shazam https://lore.kernel.org/r/20231123040355.82139-13-david.e.box@xxxxxxxxxxxxxxx
Grabbing thread from lore.kernel.org/all/20231123040355.82139-13-david.e.box@xxxxxxxxxxxxxxx/t.mbox.gz
Checking for newer revisions
Grabbing search results from lore.kernel.org
Added from v6: 21 patches
Analyzing 63 messages in the thread
Will use the latest revision: v6
You can pick other revisions using the -vN flag
Checking attestation on all messages, may take a moment...
---
✓ [PATCH v6 1/20] platform/x86/intel/vsec: Fix xa_alloc memory leak
----------------------------------------------------------------




>
>
> Note that the report includes pointer arithmetic warnings that are not related
> to this patch. Those warnings occur in mainline as well.
>
> David
>
> > > +
> > >  #ifndef ioremap_wc
> > >  #define ioremap_wc ioremap
> > >  #endif
> > > @@ -1127,6 +1132,7 @@ static inline void ioport_unmap(void __iomem *p)
> > >  extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
> > >  extern void ioport_unmap(void __iomem *p);
> > >  #endif /* CONFIG_GENERIC_IOMAP */
> > > +DEFINE_FREE(ioport_unmap, void __iomem *, ioport_unmap(_T));
> > >  #endif /* CONFIG_HAS_IOPORT_MAP */
> > >  
> > >  #ifndef CONFIG_GENERIC_IOMAP
> >
> > Has this now built successfully with LKP? (I don't think we get success
> > notifications from LKP for patch submissions, only failures).
> >
> > There were some odd errors last time but I think all they were unrelated
> > to this change (besides the checkpatch false positive, I mean).
> >
>