Hi,
This is version 2 of my attempt to get rid of a clang -Wnull-pointer-arithmetic
warning for the use of PCI_IOBASE in asm-generic/io.h. This was originally
found on s390 but should apply to all platforms leaving PCI_IOBASE undefined
while making use of the inb() and friends helpers from asm-generic/io.h.
Thanks,
Niklas
Changes since v1:
- Added patch to explicitly set PCI_IOBASE to 0 on sparc as suggested by Arnd
Bergmann
- Instead of working around the warning with a uintptr_t PCI_IOBASE make inb()
and friends explicitly WARN_ONCE() and return 0xff... (Arnd)
Niklas Schnelle (2):
sparc: explicitly set PCI_IOBASE to 0
asm-generic/io.h: Silence -Wnull-pointer-arithmetic warning on
PCI_IOBASE
arch/sparc/include/asm/io.h | 4 +++
include/asm-generic/io.h | 55 ++++++++++++++++++++++++++++++++++---
2 files changed, 55 insertions(+), 4 deletions(-)
--
2.25.1
When PCI_IOBASE is not defined, it is set to 0 such that it is ignored
in calls to the readX/writeX primitives. This triggers clang's
-Wnull-pointer-arithmetic warning and will result in illegal accesses on
platforms that do not support I/O ports if drivers do still attempt to
access them.
Make things explicit and silence the warning by letting inb() and
friends fail with WARN_ONCE() and a 0xff... return in case PCI_IOBASE is
not defined.
Signed-off-by: Niklas Schnelle <[email protected]>
---
v1 -> v2:
- Instead of working around the warning with a uintptr_t PCI_IOBASE make inb()
and friends explicitly WARN_ONCE() and return 0xff... (Arnd)
include/asm-generic/io.h | 55 +++++++++++++++++++++++++++++++++++++---
1 file changed, 51 insertions(+), 4 deletions(-)
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index c6af40ce03be..e6c549b678c4 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -440,10 +440,6 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
#endif
#endif /* CONFIG_64BIT */
-#ifndef PCI_IOBASE
-#define PCI_IOBASE ((void __iomem *)0)
-#endif
-
#ifndef IO_SPACE_LIMIT
#define IO_SPACE_LIMIT 0xffff
#endif
@@ -458,12 +454,17 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,
#define _inb _inb
static inline u8 _inb(unsigned long addr)
{
+#ifdef PCI_IOBASE
u8 val;
__io_pbr();
val = __raw_readb(PCI_IOBASE + addr);
__io_par(val);
return val;
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+ return ~0;
+#endif
}
#endif
@@ -471,12 +472,17 @@ static inline u8 _inb(unsigned long addr)
#define _inw _inw
static inline u16 _inw(unsigned long addr)
{
+#ifdef PCI_IOBASE
u16 val;
__io_pbr();
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
__io_par(val);
return val;
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+ return ~0;
+#endif
}
#endif
@@ -484,12 +490,17 @@ static inline u16 _inw(unsigned long addr)
#define _inl _inl
static inline u32 _inl(unsigned long addr)
{
+#ifdef PCI_IOBASE
u32 val;
__io_pbr();
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
__io_par(val);
return val;
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+ return ~0;
+#endif
}
#endif
@@ -497,9 +508,13 @@ static inline u32 _inl(unsigned long addr)
#define _outb _outb
static inline void _outb(u8 value, unsigned long addr)
{
+#ifdef PCI_IOBASE
__io_pbw();
__raw_writeb(value, PCI_IOBASE + addr);
__io_paw();
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -507,9 +522,13 @@ static inline void _outb(u8 value, unsigned long addr)
#define _outw _outw
static inline void _outw(u16 value, unsigned long addr)
{
+#ifdef PCI_IOBASE
__io_pbw();
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
__io_paw();
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -517,9 +536,13 @@ static inline void _outw(u16 value, unsigned long addr)
#define _outl _outl
static inline void _outl(u32 value, unsigned long addr)
{
+#ifdef PCI_IOBASE
__io_pbw();
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
__io_paw();
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -606,7 +629,11 @@ static inline void outl_p(u32 value, unsigned long addr)
#define insb insb
static inline void insb(unsigned long addr, void *buffer, unsigned int count)
{
+#ifdef PCI_IOBASE
readsb(PCI_IOBASE + addr, buffer, count);
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -614,7 +641,11 @@ static inline void insb(unsigned long addr, void *buffer, unsigned int count)
#define insw insw
static inline void insw(unsigned long addr, void *buffer, unsigned int count)
{
+#ifdef PCI_IOBASE
readsw(PCI_IOBASE + addr, buffer, count);
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -622,7 +653,11 @@ static inline void insw(unsigned long addr, void *buffer, unsigned int count)
#define insl insl
static inline void insl(unsigned long addr, void *buffer, unsigned int count)
{
+#ifdef PCI_IOBASE
readsl(PCI_IOBASE + addr, buffer, count);
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -631,7 +666,11 @@ static inline void insl(unsigned long addr, void *buffer, unsigned int count)
static inline void outsb(unsigned long addr, const void *buffer,
unsigned int count)
{
+#ifdef PCI_IOBASE
writesb(PCI_IOBASE + addr, buffer, count);
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -640,7 +679,11 @@ static inline void outsb(unsigned long addr, const void *buffer,
static inline void outsw(unsigned long addr, const void *buffer,
unsigned int count)
{
+#ifdef PCI_IOBASE
writesw(PCI_IOBASE + addr, buffer, count);
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
@@ -649,7 +692,11 @@ static inline void outsw(unsigned long addr, const void *buffer,
static inline void outsl(unsigned long addr, const void *buffer,
unsigned int count)
{
+#ifdef PCI_IOBASE
writesl(PCI_IOBASE + addr, buffer, count);
+#else
+ WARN_ONCE(1, "No I/O port support\n");
+#endif
}
#endif
--
2.25.1
Instead of relying on the fallback in asm-generic/io.h which sets
PCI_IOBASE 0 if it is not defined set it explicitly.
Link: https://lore.kernel.org/lkml/CAK8P3a3PK9zyeP4ymELtc2ZYnymECoACiigw9Za+pvSJpCk5=g@mail.gmail.com/
Signed-off-by: Niklas Schnelle <[email protected]>
---
arch/sparc/include/asm/io.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/sparc/include/asm/io.h b/arch/sparc/include/asm/io.h
index 2eefa526b38f..100992ba1317 100644
--- a/arch/sparc/include/asm/io.h
+++ b/arch/sparc/include/asm/io.h
@@ -1,6 +1,10 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef ___ASM_SPARC_IO_H
#define ___ASM_SPARC_IO_H
+
+/* On LEON I/O Space is accessed through low iomem */
+#define PCI_IOBASE ((void __iomem *)0)
+
#if defined(__sparc__) && defined(__arch64__)
#include <asm/io_64.h>
#else
--
2.25.1
Hi Niklas,
I love your patch! Yet something to improve:
[auto build test ERROR on soc/for-next]
[also build test ERROR on sparc/master asm-generic/master sparc-next/master v5.12-rc7 next-20210415]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Niklas-Schnelle/asm-generic-io-h-Silence-Wnull-pointer-arithmetic-warning-on-PCI_IOBASE/20210415-203919
base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
config: nds32-allnoconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/f0394115b166f960f12fc7bc48362d0d19f67883
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Niklas-Schnelle/asm-generic-io-h-Silence-Wnull-pointer-arithmetic-warning-on-PCI_IOBASE/20210415-203919
git checkout f0394115b166f960f12fc7bc48362d0d19f67883
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross W=1 ARCH=nds32
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All errors (new ones prefixed by >>):
In file included from arch/nds32/include/asm/io.h:82,
from arch/nds32/kernel/vdso/gettimeofday.c:7:
include/asm-generic/io.h: In function 'ioport_map':
>> include/asm-generic/io.h:1071:44: error: 'PCI_IOBASE' undeclared (first use in this function)
1071 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ^~~~~~~~~~
include/asm-generic/io.h:1071:44: note: each undeclared identifier is reported only once for each function it appears in
include/asm-generic/io.h: In function '__pci_ioport_unmap':
include/asm-generic/io.h:1076:32: error: 'PCI_IOBASE' undeclared (first use in this function)
1076 | uintptr_t start = (uintptr_t) PCI_IOBASE;
| ^~~~~~~~~~
arch/nds32/kernel/vdso/gettimeofday.c: At top level:
arch/nds32/kernel/vdso/gettimeofday.c:158:13: warning: no previous prototype for '__vdso_clock_gettime' [-Wmissing-prototypes]
158 | notrace int __vdso_clock_gettime(clockid_t clkid, struct __kernel_old_timespec *ts)
| ^~~~~~~~~~~~~~~~~~~~
arch/nds32/kernel/vdso/gettimeofday.c:206:13: warning: no previous prototype for '__vdso_clock_getres' [-Wmissing-prototypes]
206 | notrace int __vdso_clock_getres(clockid_t clk_id, struct __kernel_old_timespec *res)
| ^~~~~~~~~~~~~~~~~~~
arch/nds32/kernel/vdso/gettimeofday.c:246:13: warning: no previous prototype for '__vdso_gettimeofday' [-Wmissing-prototypes]
246 | notrace int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
| ^~~~~~~~~~~~~~~~~~~
--
<stdin>:1511:2: warning: #warning syscall clone3 not implemented [-Wcpp]
In file included from arch/nds32/include/asm/io.h:82,
from arch/nds32/kernel/vdso/gettimeofday.c:7:
include/asm-generic/io.h: In function 'ioport_map':
>> include/asm-generic/io.h:1071:44: error: 'PCI_IOBASE' undeclared (first use in this function)
1071 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ^~~~~~~~~~
include/asm-generic/io.h:1071:44: note: each undeclared identifier is reported only once for each function it appears in
include/asm-generic/io.h: In function '__pci_ioport_unmap':
include/asm-generic/io.h:1076:32: error: 'PCI_IOBASE' undeclared (first use in this function)
1076 | uintptr_t start = (uintptr_t) PCI_IOBASE;
| ^~~~~~~~~~
arch/nds32/kernel/vdso/gettimeofday.c: At top level:
arch/nds32/kernel/vdso/gettimeofday.c:158:13: warning: no previous prototype for '__vdso_clock_gettime' [-Wmissing-prototypes]
158 | notrace int __vdso_clock_gettime(clockid_t clkid, struct __kernel_old_timespec *ts)
| ^~~~~~~~~~~~~~~~~~~~
arch/nds32/kernel/vdso/gettimeofday.c:206:13: warning: no previous prototype for '__vdso_clock_getres' [-Wmissing-prototypes]
206 | notrace int __vdso_clock_getres(clockid_t clk_id, struct __kernel_old_timespec *res)
| ^~~~~~~~~~~~~~~~~~~
arch/nds32/kernel/vdso/gettimeofday.c:246:13: warning: no previous prototype for '__vdso_gettimeofday' [-Wmissing-prototypes]
246 | notrace int __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
| ^~~~~~~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:271: arch/nds32/kernel/vdso/gettimeofday.o] Error 1
make[2]: Target 'include/generated/vdso-offsets.h' not remade because of errors.
make[1]: *** [arch/nds32/Makefile:63: vdso_prepare] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:215: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/PCI_IOBASE +1071 include/asm-generic/io.h
7c566bb5e4d5fb0 Hector Martin 2021-02-11 1063
ce816fa88cca083 Uwe Kleine-K?nig 2014-04-07 1064 #ifdef CONFIG_HAS_IOPORT_MAP
3f7e212df82ca04 Arnd Bergmann 2009-05-13 1065 #ifndef CONFIG_GENERIC_IOMAP
9216efafc52ff99 Thierry Reding 2014-10-01 1066 #ifndef ioport_map
9216efafc52ff99 Thierry Reding 2014-10-01 1067 #define ioport_map ioport_map
3f7e212df82ca04 Arnd Bergmann 2009-05-13 1068 static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
3f7e212df82ca04 Arnd Bergmann 2009-05-13 1069 {
500dd232449e7c0 Andrew Murray 2018-09-13 1070 port &= IO_SPACE_LIMIT;
500dd232449e7c0 Andrew Murray 2018-09-13 @1071 return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
3f7e212df82ca04 Arnd Bergmann 2009-05-13 1072 }
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1073 #define __pci_ioport_unmap __pci_ioport_unmap
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1074 static inline void __pci_ioport_unmap(void __iomem *p)
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1075 {
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1076 uintptr_t start = (uintptr_t) PCI_IOBASE;
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1077 uintptr_t addr = (uintptr_t) p;
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1078
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1079 if (addr >= start && addr < start + IO_SPACE_LIMIT)
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1080 return;
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1081 iounmap(p);
f5810e5c329238b Lorenzo Pieralisi 2020-09-16 1082 }
9216efafc52ff99 Thierry Reding 2014-10-01 1083 #endif
3f7e212df82ca04 Arnd Bergmann 2009-05-13 1084
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
From: Niklas Schnelle
> Sent: 15 April 2021 13:37
>
> Instead of relying on the fallback in asm-generic/io.h which sets
> PCI_IOBASE 0 if it is not defined set it explicitly.
>
> Link: https://lore.kernel.org/lkml/CAK8P3a3PK9zyeP4ymELtc2ZYnymECoACiigw9Za+pvSJpCk5=g@mail.gmail.com/
> Signed-off-by: Niklas Schnelle <[email protected]>
> ---
> arch/sparc/include/asm/io.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/sparc/include/asm/io.h b/arch/sparc/include/asm/io.h
> index 2eefa526b38f..100992ba1317 100644
> --- a/arch/sparc/include/asm/io.h
> +++ b/arch/sparc/include/asm/io.h
> @@ -1,6 +1,10 @@
> /* SPDX-License-Identifier: GPL-2.0 */
> #ifndef ___ASM_SPARC_IO_H
> #define ___ASM_SPARC_IO_H
> +
> +/* On LEON I/O Space is accessed through low iomem */
> +#define PCI_IOBASE ((void __iomem *)0)
> +
> #if defined(__sparc__) && defined(__arch64__)
> #include <asm/io_64.h>
> #else
> --
> 2.25.1
Not sure the comment is informative enough.
Maybe something like:
/*
* On LEON PCI addresses below 64k are converted to IO accesses.
* io_remap_xxx() (whatever is it called) returns a kernel virtual
* address in the PCI window so inb() doesn't need to add an offset.
*/
That'll save the next person doing a lot of digging.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
Hi Niklas,
I love your patch! Yet something to improve:
[auto build test ERROR on soc/for-next]
[also build test ERROR on sparc/master asm-generic/master v5.12-rc7 next-20210415]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Niklas-Schnelle/asm-generic-io-h-Silence-Wnull-pointer-arithmetic-warning-on-PCI_IOBASE/20210415-203919
base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next
config: arc-randconfig-s031-20210415 (attached as .config)
compiler: arc-elf-gcc (GCC) 9.3.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# apt-get install sparse
# sparse version: v0.6.3-280-g2cd6d34e-dirty
# https://github.com/0day-ci/linux/commit/f0394115b166f960f12fc7bc48362d0d19f67883
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Niklas-Schnelle/asm-generic-io-h-Silence-Wnull-pointer-arithmetic-warning-on-PCI_IOBASE/20210415-203919
git checkout f0394115b166f960f12fc7bc48362d0d19f67883
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=arc
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All errors (new ones prefixed by >>):
In file included from arch/arc/include/asm/io.h:233,
from drivers/w1/w1_io.c:6:
include/asm-generic/io.h: In function '_inb':
>> include/asm-generic/io.h:465:2: error: implicit declaration of function 'WARN_ONCE' [-Werror=implicit-function-declaration]
465 | WARN_ONCE(1, "No I/O port support\n");
| ^~~~~~~~~
cc1: some warnings being treated as errors
vim +/WARN_ONCE +465 include/asm-generic/io.h
446
447 /*
448 * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be
449 * implemented on hardware that needs an additional delay for I/O accesses to
450 * take effect.
451 */
452
453 #if !defined(inb) && !defined(_inb)
454 #define _inb _inb
455 static inline u8 _inb(unsigned long addr)
456 {
457 #ifdef PCI_IOBASE
458 u8 val;
459
460 __io_pbr();
461 val = __raw_readb(PCI_IOBASE + addr);
462 __io_par(val);
463 return val;
464 #else
> 465 WARN_ONCE(1, "No I/O port support\n");
466 return ~0;
467 #endif
468 }
469 #endif
470
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]