Message ID | 20210430111641.1911207-1-schnelle@linux.ibm.com |
---|---|
Headers | show |
Series | asm-generic/io.h: Silence -Wnull-pointer-arithmetic warning on PCI_IOBASE | expand |
On Fri, Apr 30, 2021 at 1:16 PM Niklas Schnelle <schnelle@linux.ibm.com> wrote: > > From: Niklas Schnelle <niklas@komani.de> > > This is version 4 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. > > This applies cleanly and was compile tested on top of v5.12 for the > previously broken ARC, nds32, h8300 and risc-v architecture > > I did boot test this only on x86_64 and s390x the former implements > inb() itself while the latter would emit a WARN_ONCE() but no drivers > use inb(). This looks all fine to me, but with the merge window open right now, I can't add it into linux-next yet, and it wouldn't qualify as a bugfix for 5.13. Please resend them to me after -rc1 is out so I can merge it for 5.14 through the asm-generic tree. Please add two small changes to the changelog texts: - for patch 3, please include a 'Link: tag' to the lore archive of the previous discussion, that should cover any questions that people may have - for the risc-v patch, I would suggest explaining that this fixes an existing runtime bug, not just a compiler error: | This is already broken, as accessing a fixed I/O port number of | an ISA device on NOMMU RISC-V would turn into a NULL pointer | dereference. Feel free to either copy this, or use your own explanation. Arnd
On Mon, 2021-05-03 at 18:07 +0200, Arnd Bergmann wrote: > On Fri, Apr 30, 2021 at 1:16 PM Niklas Schnelle <schnelle@linux.ibm.com> wrote: > > From: Niklas Schnelle <niklas@komani.de> > > > > This is version 4 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. > > > > This applies cleanly and was compile tested on top of v5.12 for the > > previously broken ARC, nds32, h8300 and risc-v architecture > > > > I did boot test this only on x86_64 and s390x the former implements > > inb() itself while the latter would emit a WARN_ONCE() but no drivers > > use inb(). > > This looks all fine to me, but with the merge window open right now, I > can't add it into linux-next yet, and it wouldn't qualify as a bugfix for 5.13. > > Please resend them to me after -rc1 is out so I can merge it for > 5.14 through the asm-generic tree. Thanks for the great feedback I appreciate it. Will do the resend of course. > > Please add two small changes to the changelog texts: > > - for patch 3, please include a 'Link: tag' to the lore archive of the > previous discussion, that should cover any questions that people > may have Done > > - for the risc-v patch, I would suggest explaining that this fixes > an existing runtime bug, not just a compiler error: > | This is already broken, as accessing a fixed I/O port number of > | an ISA device on NOMMU RISC-V would turn into a NULL pointer > | dereference. > Feel free to either copy this, or use your own explanation. I mixed the above in with the current commit message: Without MMU support PCI_IOBASE is left undefined because PCI_IO_END is VMEMMAP_START. Nevertheless the in*()/out*() helper macros are left defined with uses of PCI_IOBASE. At the moment this only compiles because asm-generic/io.h defines PCI_IOBASE as 0 if it is undefined and so at macro expansion PCI_IOBASE is defined. This leads to compilation errors when asm-generic/io.h is changed to leave PCI_IOBASE undefined. More importantly it is currently broken at runtime, as accessing a fixed I/O port number of an ISA device on NOMMU RISC-V would turn into a NULL pointer dereference. Instead only define the in*()/out*() helper macros with MMU support and fall back to the asm-generic/io.h helper stubs otherwise. > > Arnd
On Tue, May 4, 2021 at 9:40 AM Niklas Schnelle <schnelle@linux.ibm.com> wrote: > On Mon, 2021-05-03 at 18:07 +0200, Arnd Bergmann wrote: > > - for the risc-v patch, I would suggest explaining that this fixes > > an existing runtime bug, not just a compiler error: > > | This is already broken, as accessing a fixed I/O port number of > > | an ISA device on NOMMU RISC-V would turn into a NULL pointer > > | dereference. > > Feel free to either copy this, or use your own explanation. > > I mixed the above in with the current commit message: > > Without MMU support PCI_IOBASE is left undefined because PCI_IO_END is > VMEMMAP_START. Nevertheless the in*()/out*() helper macros are left > defined with uses of PCI_IOBASE. At the moment this only compiles > because asm-generic/io.h defines PCI_IOBASE as 0 if it is undefined and > so at macro expansion PCI_IOBASE is defined. This leads to compilation > errors when asm-generic/io.h is changed to leave PCI_IOBASE undefined. > More importantly it is currently broken at runtime, as accessing a fixed > I/O port number of an ISA device on NOMMU RISC-V would turn into a NULL > pointer dereference. Instead only define the in*()/out*() helper macros > with MMU support and fall back to the asm-generic/io.h helper stubs > otherwise. Looks good, thanks. Maybe split into two or three paragraphs for readability. Arnd
From: Niklas Schnelle <niklas@komani.de> Hi, This is version 4 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. This applies cleanly and was compile tested on top of v5.12 for the previously broken ARC, nds32, h8300 and risc-v architecture I did boot test this only on x86_64 and s390x the former implements inb() itself while the latter would emit a WARN_ONCE() but no drivers use inb(). Thanks, Niklas Changes since v3: - Changed the subject of the last patch to better reflect the actual change i.e. the addition of WARN_ONCE() to the helpers not the silencing of the clang warning - Added asm/bug.h to asm-generic/io.h so it doesn't have to be included previously by all arches to be available for the WARN_ONCE() - Added patch for risc-v which defines PCI_IOBASE except when compiled for nommu Changes since v2: - Improved comment for SPARC PCI_IOBASE definition as suggested by David Laight - Added a patch for ARC which is missing the asm/bug.h include for WARN_ONCE() (kernel test robot) - Added ifdefs to ioport_map() and __pci_ioport_map() since apparently at least test configs enable CONFIG_HAS_IOPORT_MAP even on architectures which leave PCI_IOBASE unset (kernel test robot for nds32 and ARC). 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 Bergmann) Niklas Schnelle (3): sparc: explicitly set PCI_IOBASE to 0 risc-v: Use generic io.h helpers for nommu asm-generic/io.h: warn in inb() and friends with undefined PCI_IOBASE arch/riscv/include/asm/io.h | 5 +-- arch/sparc/include/asm/io.h | 8 +++++ include/asm-generic/io.h | 65 ++++++++++++++++++++++++++++++++++--- 3 files changed, 72 insertions(+), 6 deletions(-)