Fix arm64 crash for accessing unmapped IO port regions (reboot)
Subsystems (5)
cover Fix arm64 crash for accessing unmapped IO port regions (reboot)
This is a reboot of my original series to address the problem of drivers for legacy ISA devices accessing unmapped IO port regions on arm64 systems and causing the system to crash.
There was another recent report of such an issue [0], and some old ones
[1] and [2] for reference.
The background is that many systems do not include PCI host controllers, or they do and controller probe may have failed. For these cases, no IO ports are mapped. However, loading drivers for legacy ISA devices can crash the system as there is nothing to stop them accessing those IO ports (which have not been io remap'ed).
My original solution tried to keep the kernel alive in these situations by rejecting logical PIO access to PCI IO regions until PCI IO port regions have been mapped.
This series goes one step further, by just reserving the complete legacy IO port range in 0x0--0xffff for arm64. The motivation for doing this is to make the request_region() calls for those drivers fail, like this:
root@ubuntu:/home/john# insmod mk712.ko [ 3415.575800] mk712: unable to get IO region insmod: ERROR: could not insert module mk712.ko: No such device
Otherwise, in theory, those drivers could initiate rogue accesses to mapped IO port regions for other devices and cause corruptions or side-effects. Indeed, those drivers should not be allowed to access IO ports at all in such a system.
As a secondary defence, for broken drivers who do not call request_region(), IO port accesses in range 0--0xffff will be ignored, again preserving the system.
I am sending as an RFC as I am not sure of any problem with reserving first 0x10000 of IO space like this. There is reserve= commandline argument, which does allow this already.
For reference, here's how /proc/ioports looks on my arm64 system with this change:
root@ubuntu:/home/john# more /proc/ioports
00010000-0001ffff : PCI Bus 0002:f8
00010000-00010fff : PCI Bus 0002:f9
00010000-00010007 : 0002:f9:00.0
00010000-00010007 : serial
00010008-0001000f : 0002:f9:00.1
00010008-0001000f : serial
00010010-00010017 : 0002:f9:00.2
00010018-0001001f : 0002:f9:00.2
00020000-0002ffff : PCI Bus 0004:88
00030000-0003ffff : PCI Bus 0005:78
00040000-0004ffff : PCI Bus 0006:c0
00050000-0005ffff : PCI Bus 0007:90
00060000-0006ffff : PCI Bus 000a:10
00070000-0007ffff : PCI Bus 000c:20
00080000-0008ffff : PCI Bus 000d:30[0] https://lore.kernel.org/linux-input/[email protected]/T/#mf86445470160c44ac110e9d200b09245169dc5b6
[1] https://lore.kernel.org/linux-pci/[email protected]
[2] https://lore.kernel.org/linux-arm-kernel/[email protected]/
Difference since v4:
https://lore.kernel.org/linux-pci/[email protected]/
- Reserve legacy ISA region
John Garry (4):
arm64: io: Introduce IO_SPACE_BASE asm-generic/io.h: Add IO_SPACE_BASE kernel/resource: Make ioport_resource.start configurable
logic_pio: Warn on and discard accesses to addresses below
IO_SPACE_BASE
arch/arm64/include/asm/io.h | 1 + include/asm-generic/io.h | 4 ++++ include/linux/logic_pio.h | 5 +++++ kernel/resource.c | 2 +- lib/logic_pio.c | 20 ++++++++++++++------ 5 files changed, 25 insertions(+), 7 deletions(-)
Signature · 1 line
2.26.2
RFC PATCH 1/4 arm64: io: Introduce IO_SPACE_BASE
Introduce IO_SPACE_BASE, which is the base address of the IO port region.
0x10000 is chosen intentionally to exclude legacy ISA IO port address range.
--- arch/arm64/include/asm/io.h | 1 + 1 file changed, 1 insertion(+)
arch/arm64/include/asm/io.h +1 -0
@@ -148,6 +148,7 @@ static inline u64 __raw_readq(const volatile void __iomem *addr)#define arch_has_dev_port () (1)#define IO_SPACE_LIMIT (PCI_IO_SIZE - 1)#define PCI_IOBASE ((void __iomem *)PCI_IO_START) +#define IO_SPACE_BASE (0x10000)/* * String version of I/O memory access operations.
Signature · 1 line
2.26.2
RFC PATCH 2/4 asm-generic/io.h: Add IO_SPACE_BASE
In reply to John GarryAdd a fallback default for IO_SPACE_BASE (at 0) for when an architecture does not define a value.
--- include/asm-generic/io.h | 4 ++++ 1 file changed, 4 insertions(+)
include/asm-generic/io.h +4 -0
@@ -448,6 +448,10 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer,#define IO_SPACE_LIMIT 0xffff#endif +#ifndef IO_SPACE_BASE +#define IO_SPACE_BASE 0x0 +#endif +/* * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be * implemented on hardware that needs an additional delay for I/O accesses to
Signature · 1 line
2.26.2
RFC PATCH 3/4 kernel/resource: Make ioport_resource.start configurable
In reply to John GarryMake IO space base address to be configurable through IO_SPACE_BASE.
This will allow architectures which do not natively support IO ports - like arm64 - to harden against legacy ISA-based drivers which use hardcoded addresses to access IO ports.
Any attempts for these drivers to request a resource region will now fail for architectures with set IO_SPACE_BASE above legacy ISA IO port region (0xffff).
--- kernel/resource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/resource.c +1 -1
@@ -29,7 +29,7 @@struct resource ioport_resource = { .name ="PCI IO" , - .start =0 , + .start =IO_SPACE_BASE , .end =IO_SPACE_LIMIT , .flags =IORESOURCE_IO , };
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH RFC 3/4] kernel/resource: Make ioport_resource.start configurable
[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]
Hi John,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on asm-generic/master soc/for-next linus/master v5.11-rc3 next-20210115] [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/John-Garry/Fix-arm64-crash-for-accessing-unmapped-IO-port-regions-reboot/20210116-010800 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: parisc-randconfig-r022-20210115 (attached as .config) compiler: hppa-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/48d619e4d6beb0d7a086cbe60a0b24355d3ddd52
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review John-Garry/Fix-arm64-crash-for-accessing-unmapped-IO-port-regions-reboot/20210116-010800 git checkout 48d619e4d6beb0d7a086cbe60a0b24355d3ddd52
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=parisc
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
>> kernel/resource.c:32:11: error: 'IO_SPACE_BASE' undeclared here (not in a function); did you mean 'QIF_SPACE_B'?
32 | .start = IO_SPACE_BASE,
| ^~~~~~~~~~~~~
| QIF_SPACE_Bvim +32 kernel/resource.c
28
29
30 struct resource ioport_resource = {
31 .name = "PCI IO",
> 32 .start = IO_SPACE_BASE,
33 .end = IO_SPACE_LIMIT,
34 .flags = IORESOURCE_IO,
35 };
36 EXPORT_SYMBOL(ioport_resource);
37 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH 4/4 logic_pio: Warn on and discard accesses to addresses below IO_SPACE_BASE
In reply to John GarryStart the PCI MMIO region at IO_SPACE_BASE, and warn on any accesses below that address. Those accesses are also discarded.
This is only for CONFIG_INDIRECT_PIO currently, and support can be added later for !CONFIG_INDIRECT_PIO.
--- include/linux/logic_pio.h | 5 +++++ lib/logic_pio.c | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-)
include/linux/logic_pio.h +5 -0
@@ -111,7 +111,12 @@ void logic_outsl(unsigned long addr, const void *buffer, unsigned int count);#else #define PIO_INDIRECT_SIZE 0#endif /* CONFIG_INDIRECT_PIO */ +#define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE) +#define MMIO_LOWER_LIMIT IO_SPACE_BASE +#if MMIO_LOWER_LIMIT >=MMIO_UPPER_LIMIT +#error MMIO_UPPPER_LIMIT should be above MMIO_LOWER_LIMIT +#endif struct logic_pio_hwaddr *find_io_range_by_fwnode (struct fwnode_handle *fwnode); unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode,
lib/logic_pio.c +14 -6
@@ -36,7 +36,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range)struct logic_pio_hwaddr *range;resource_size_t start;resource_size_t end; -resource_size_t mmio_end =0 ; +resource_size_t mmio_end =MMIO_LOWER_LIMIT ;resource_size_t iio_sz =MMIO_UPPER_LIMIT ;int ret =0 ;
@@ -234,7 +234,9 @@ type logic_in##bwl(unsigned long addr) \ { \type ret = (type )~0 ; \ \ -if (addr <MMIO_UPPER_LIMIT ) { \ +if (addr <MMIO_LOWER_LIMIT ) { \ +WARN_ON_ONCE (1 ); \ + }else if (addr <MMIO_UPPER_LIMIT ) { \ ret = _in##bwl(addr); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \
@@ -250,8 +252,10 @@ type logic_in##bwl(unsigned long addr) \ \ void logic_out##bwl(type value, unsigned long addr) \ { \ - if (addr < MMIO_UPPER_LIMIT) { \ - _out##bwl(value, addr); \ + if (addr < MMIO_LOWER_LIMIT) { \ + WARN_ON_ONCE(1); \ + } else if (addr < MMIO_UPPER_LIMIT) { \ + _out##bwl(value, addr); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \
@@ -266,7 +270,9 @@ void logic_out##bwl(type value, unsigned long addr) \ void logic_ins##bwl(unsigned long addr, void *buffer, \ unsigned int count) \ { \ - if (addr < MMIO_UPPER_LIMIT) { \ + if (addr < MMIO_LOWER_LIMIT) { \ + WARN_ON_ONCE(1); \ + } else if (addr < MMIO_UPPER_LIMIT) { \ reads##bwl(PCI_IOBASE + addr, buffer, count); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \
@@ -283,7 +289,9 @@ void logic_ins##bwl(unsigned long addr, void *buffer, \ void logic_outs##bwl(unsigned long addr, const void *buffer, \ unsigned int count) \ { \ - if (addr < MMIO_UPPER_LIMIT) { \ + if (addr < MMIO_LOWER_LIMIT) { \ + WARN_ON_ONCE(1); \ + } else if (addr < MMIO_UPPER_LIMIT) { \ writes##bwl(PCI_IOBASE + addr, buffer, count); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \
Signature · 1 line
2.26.2
kernel test robot
build botRe: [PATCH RFC 4/4] logic_pio: Warn on and discard accesses to addresses below IO_SPACE_BASE
[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]
Hi John,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on asm-generic/master soc/for-next linus/master v5.11-rc3 next-20210115] [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/John-Garry/Fix-arm64-crash-for-accessing-unmapped-IO-port-regions-reboot/20210116-010800 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: arm-randconfig-r014-20210115 (attached as .config) compiler: arm-linux-gnueabi-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/a75a79165fd5529fe38a5f05268cce3c1ee89b5e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review John-Garry/Fix-arm64-crash-for-accessing-unmapped-IO-port-regions-reboot/20210116-010800 git checkout a75a79165fd5529fe38a5f05268cce3c1ee89b5e
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm
If you fix the issue, kindly add following tag as appropriate
All error/warnings (new ones prefixed by >>):
In file included from include/linux/scatterlist.h:9,
from include/linux/dma-mapping.h:10, from arch/arm/kernel/asm-offsets.c:13:
>> arch/arm/include/asm/io.h:221:26: warning: "resource_size_t" is not defined, evaluates to 0 [-Wundef]
221 | #define IO_SPACE_LIMIT ((resource_size_t)0xffff)
| ^~~~~~~~~~~~~~~
include/linux/logic_pio.h:115:27: note: in expansion of macro 'IO_SPACE_LIMIT'
115 | #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
| ^~~~~~~~~~~~~~
include/linux/logic_pio.h:117:25: note: in expansion of macro 'MMIO_UPPER_LIMIT'
117 | #if MMIO_LOWER_LIMIT >= MMIO_UPPER_LIMIT
| ^~~~~~~~~~~~~~~~
>> arch/arm/include/asm/io.h:221:42: error: missing binary operator before token "0xffff"
221 | #define IO_SPACE_LIMIT ((resource_size_t)0xffff)
| ^~~~~~ include/linux/logic_pio.h:115:27: note: in expansion of macro 'IO_SPACE_LIMIT'
115 | #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
| ^~~~~~~~~~~~~~
include/linux/logic_pio.h:117:25: note: in expansion of macro 'MMIO_UPPER_LIMIT'
117 | #if MMIO_LOWER_LIMIT >= MMIO_UPPER_LIMIT
| ^~~~~~~~~~~~~~~~
--
In file included from include/linux/scatterlist.h:9,
from include/linux/dma-mapping.h:10,
from arch/arm/kernel/asm-offsets.c:13:
>> arch/arm/include/asm/io.h:221:26: warning: "resource_size_t" is not defined, evaluates to 0 [-Wundef]
221 | #define IO_SPACE_LIMIT ((resource_size_t)0xffff)
| ^~~~~~~~~~~~~~~
include/linux/logic_pio.h:115:27: note: in expansion of macro 'IO_SPACE_LIMIT'
115 | #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
| ^~~~~~~~~~~~~~
include/linux/logic_pio.h:117:25: note: in expansion of macro 'MMIO_UPPER_LIMIT'
117 | #if MMIO_LOWER_LIMIT >= MMIO_UPPER_LIMIT
| ^~~~~~~~~~~~~~~~
>> arch/arm/include/asm/io.h:221:42: error: missing binary operator before token "0xffff"
221 | #define IO_SPACE_LIMIT ((resource_size_t)0xffff)
| ^~~~~~ include/linux/logic_pio.h:115:27: note: in expansion of macro 'IO_SPACE_LIMIT'
115 | #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
| ^~~~~~~~~~~~~~
include/linux/logic_pio.h:117:25: note: in expansion of macro 'MMIO_UPPER_LIMIT'
117 | #if MMIO_LOWER_LIMIT >= MMIO_UPPER_LIMIT
| ^~~~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:117: arch/arm/kernel/asm-offsets.s] Error 1 make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1206: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:185: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +/resource_size_t +221 arch/arm/include/asm/io.h
^1da177e4c3f4152 include/asm-arm/io.h Linus Torvalds 2005-04-16 205 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 206 /* 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 207 * This is the limit of PC card/PCI/ISA IO space, which is by default 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 208 * 64K if we have PC card, PCI or ISA support. Otherwise, default to 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 209 * zero to prevent ISA/PCI drivers claiming IO space (and potentially 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 210 * oopsing.) 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 211 * 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 212 * Only set this larger if you really need inb() et.al. to operate over 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 213 * a larger address space. Note that SOC_COMMON ioremaps each sockets 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 214 * IO space area, and so inb() et.al. must be defined to operate as per 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 215 * readb() et.al. on such platforms. 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 216 */ 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 217 #ifndef IO_SPACE_LIMIT 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 218 #if defined(CONFIG_PCMCIA_SOC_COMMON) || defined(CONFIG_PCMCIA_SOC_COMMON_MODULE) 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 219 #define IO_SPACE_LIMIT ((resource_size_t)0xffffffff) 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 220 #elif defined(CONFIG_PCI) || defined(CONFIG_ISA) || defined(CONFIG_PCCARD) 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 @221 #define IO_SPACE_LIMIT ((resource_size_t)0xffff) 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 222 #else 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 223 #define IO_SPACE_LIMIT ((resource_size_t)0) 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 224 #endif 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 225 #endif 04e1c83806e30ae3 arch/arm/include/asm/io.h Russell King 2011-07-06 226
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botRe: [PATCH RFC 4/4] logic_pio: Warn on and discard accesses to addresses below IO_SPACE_BASE
In reply to John Garry[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]
Hi John,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on arm64/for-next/core]
[also build test ERROR on asm-generic/master soc/for-next linus/master v5.11-rc3 next-20210115] [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/John-Garry/Fix-arm64-crash-for-accessing-unmapped-IO-port-regions-reboot/20210116-010800 base: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core config: nios2-randconfig-r012-20210115 (attached as .config) compiler: nios2-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/a75a79165fd5529fe38a5f05268cce3c1ee89b5e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review John-Garry/Fix-arm64-crash-for-accessing-unmapped-IO-port-regions-reboot/20210116-010800 git checkout a75a79165fd5529fe38a5f05268cce3c1ee89b5e
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=nios2
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/asm-generic/io.h:530,
from arch/nios2/include/asm/io.h:41,
from include/linux/io.h:13,
from include/linux/irq.h:20,
from include/asm-generic/hardirq.h:17,
from ./arch/nios2/include/generated/asm/hardirq.h:1,
from include/linux/hardirq.h:10,
from include/linux/interrupt.h:11,
from include/linux/kernel_stat.h:9,
from arch/nios2/kernel/asm-offsets.c:8:
>> include/linux/logic_pio.h:118:2: error: #error MMIO_UPPPER_LIMIT should be above MMIO_LOWER_LIMIT 118 | #error MMIO_UPPPER_LIMIT should be above MMIO_LOWER_LIMIT
| ^~~~~
make[2]: *** [scripts/Makefile.build:117: arch/nios2/kernel/asm-offsets.s] Error 1 make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1206: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:185: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.
vim +118 include/linux/logic_pio.h
114
115 #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE)
116 #define MMIO_LOWER_LIMIT IO_SPACE_BASE
117 #if MMIO_LOWER_LIMIT >= MMIO_UPPER_LIMIT
> 118 #error MMIO_UPPPER_LIMIT should be above MMIO_LOWER_LIMIT
119 #endif
120
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Quoted 30 lines · John Garry
This is a reboot of my original series to address the problem of drivers for legacy ISA devices accessing unmapped IO port regions on arm64 systems and causing the system to crash.
There was another recent report of such an issue [0], and some old ones
[1] and [2] for reference.The background is that many systems do not include PCI host controllers, or they do and controller probe may have failed. For these cases, no IO ports are mapped. However, loading drivers for legacy ISA devices can crash the system as there is nothing to stop them accessing those IO ports (which have not been io remap'ed).
My original solution tried to keep the kernel alive in these situations by rejecting logical PIO access to PCI IO regions until PCI IO port regions have been mapped.
This series goes one step further, by just reserving the complete legacy IO port range in 0x0--0xffff for arm64. The motivation for doing this is to make the
request_region()calls for those drivers fail, like this:root@ubuntu:/home/john# insmod mk712.ko [ 3415.575800] mk712: unable to get IO region insmod: ERROR: could not insert module mk712.ko: No such deviceOtherwise, in theory, those drivers could initiate rogue accesses to mapped IO port regions for other devices and cause corruptions or side-effects. Indeed, those drivers should not be allowed to access IO ports at all in such a system.
Quoted 7 lines
As a secondary defence, for broken drivers who do not call
request_region(), IO port accesses in range 0--0xffff will be ignored, again preserving the system.I am sending as an RFC as I am not sure of any problem with reserving first
0x10000of IO space like this. There is reserve= commandline argument, which does allow this already.
Hi John,
Is it ok with ACPI? I'm not really familiar with ACPI on arm64 but my impression is ACPI would use legacy I/O ports to communicate with kbd controller, EC and power management facilities.
We'd better have a method to detect if ISA bus is not present on the system instead of reserve them unconditionally.
Thanks.
- Jiaxun
Quoted 43 lines
For reference, here's how
/proc/ioportslooks on my arm64 system with this change:root@ubuntu:/home/john# more /proc/ioports 00010000-0001ffff : PCI Bus 0002:f8 00010000-00010fff : PCI Bus 0002:f9 00010000-00010007 : 0002:f9:00.0 00010000-00010007 : serial 00010008-0001000f : 0002:f9:00.1 00010008-0001000f : serial 00010010-00010017 : 0002:f9:00.2 00010018-0001001f : 0002:f9:00.2 00020000-0002ffff : PCI Bus 0004:88 00030000-0003ffff : PCI Bus 0005:78 00040000-0004ffff : PCI Bus 0006:c0 00050000-0005ffff : PCI Bus 0007:90 00060000-0006ffff : PCI Bus 000a:10 00070000-0007ffff : PCI Bus 000c:20 00080000-0008ffff : PCI Bus 000d:30[0] https://lore.kernel.org/linux-input/[email protected]/T/#mf86445470160c44ac110e9d200b09245169dc5b6
[1] https://lore.kernel.org/linux-pci/[email protected]
[2] https://lore.kernel.org/linux-arm-kernel/[email protected]/Difference since v4:
https://lore.kernel.org/linux-pci/[email protected]/
- Reserve legacy ISA regionJohn Garry (4):
arm64: io: IntroduceIO_SPACE_BASEasm-generic/io.h: AddIO_SPACE_BASEkernel/resource: Make ioport_resource.start configurable
logic_pio: Warn on and discard accesses to addresses below
IO_SPACE_BASEarch/arm64/include/asm/io.h | 1 + include/asm-generic/io.h | 4 ++++ include/linux/logic_pio.h | 5 +++++ kernel/resource.c | 2 +- lib/logic_pio.c | 20 ++++++++++++++------ 5 files changed, 25 insertions(+), 7 deletions(-)
Quoted 31 lines · Jiaxun Yang
Quoted 30 lines · John Garry
This is a reboot of my original series to address the problem of drivers for legacy ISA devices accessing unmapped IO port regions on arm64 systems and causing the system to crash.
There was another recent report of such an issue [0], and some old ones
[1] and [2] for reference.The background is that many systems do not include PCI host controllers, or they do and controller probe may have failed. For these cases, no IO ports are mapped. However, loading drivers for legacy ISA devices can crash the system as there is nothing to stop them accessing those IO ports (which have not been io remap'ed).
My original solution tried to keep the kernel alive in these situations by rejecting logical PIO access to PCI IO regions until PCI IO port regions have been mapped.
This series goes one step further, by just reserving the complete legacy IO port range in 0x0--0xffff for arm64. The motivation for doing this is to make the
request_region()calls for those drivers fail, like this:root@ubuntu:/home/john# insmod mk712.ko [ 3415.575800] mk712: unable to get IO region insmod: ERROR: could not insert module mk712.ko: No such deviceOtherwise, in theory, those drivers could initiate rogue accesses to mapped IO port regions for other devices and cause corruptions or side-effects. Indeed, those drivers should not be allowed to access IO ports at all in such a system.
Quoted 8 lines
Quoted 7 lines
As a secondary defence, for broken drivers who do not call
request_region(), IO port accesses in range 0--0xffff will be ignored, again preserving the system.I am sending as an RFC as I am not sure of any problem with reserving first
0x10000of IO space like this. There is reserve= commandline argument, which does allow this already.
Hi Jiaxun,
Quoted 4 lines
Is it ok with ACPI? I'm not really familiar with ACPI on arm64 but my impression is ACPI would use legacy I/O ports to communicate with kbd controller, EC and power management facilities.
I tested for ACPI. As far as I'm concerned, fixed IO ports should not be used on arm64 systems.
Indeed, ACPI spec says IO port addresses should be CPU addressable, and it is the job of the kernel to io remap those correctly for systems which do not support IO ports natively, i.e. those that define PCI_IOBASE.
Quoted 4 lines
We'd better have a method to detect if ISA bus is not present on the system instead of reserve them unconditionally.
For ISA bus or any IO ports region, they would/should be behind PCI host bridge or modeled as INDIRECT IO host and we should allocate logic PIO region for them, and there should be no assumption on the IO port address in drivers, i.e. not fixed.
Thanks,
John
Quoted 48 lines
Quoted 40 lines
For reference, here's how
/proc/ioportslooks on my arm64 system with this change:root@ubuntu:/home/john# more /proc/ioports 00010000-0001ffff : PCI Bus 0002:f8 00010000-00010fff : PCI Bus 0002:f9 00010000-00010007 : 0002:f9:00.0 00010000-00010007 : serial 00010008-0001000f : 0002:f9:00.1 00010008-0001000f : serial 00010010-00010017 : 0002:f9:00.2 00010018-0001001f : 0002:f9:00.2 00020000-0002ffff : PCI Bus 0004:88 00030000-0003ffff : PCI Bus 0005:78 00040000-0004ffff : PCI Bus 0006:c0 00050000-0005ffff : PCI Bus 0007:90 00060000-0006ffff : PCI Bus 000a:10 00070000-0007ffff : PCI Bus 000c:20 00080000-0008ffff : PCI Bus 000d:30[0] https://lore.kernel.org/linux-input/[email protected]/T/#mf86445470160c44ac110e9d200b09245169dc5b6
[1] https://lore.kernel.org/linux-pci/[email protected]
[2] https://lore.kernel.org/linux-arm-kernel/[email protected]/Difference since v4:
https://lore.kernel.org/linux-pci/[email protected]/- Reserve legacy ISA region
John Garry (4):
arm64: io: IntroduceIO_SPACE_BASEasm-generic/io.h: AddIO_SPACE_BASEkernel/resource: Make ioport_resource.start configurable
logic_pio: Warn on and discard accesses to addresses belowIO_SPACE_BASEQuoted 7 lines
arch/arm64/include/asm/io.h| 1 + include/asm-generic/io.h | 4 ++++ include/linux/logic_pio.h | 5 +++++ kernel/resource.c | 2 +- lib/logic_pio.c | 20 ++++++++++++++------5 files changed, 25 insertions(+), 7 deletions(-)
Quoted 1 line
.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 42 lines · John Garry
This is a reboot of my original series to address the problem of drivers for legacy ISA devices accessing unmapped IO port regions on arm64 systems and causing the system to crash.
There was another recent report of such an issue [0], and some old ones
[1] and [2] for reference.The background is that many systems do not include PCI host controllers, or they do and controller probe may have failed. For these cases, no IO ports are mapped. However, loading drivers for legacy ISA devices can crash the system as there is nothing to stop them accessing those IO ports (which have not been io remap'ed).
My original solution tried to keep the kernel alive in these situations by rejecting logical PIO access to PCI IO regions until PCI IO port regions have been mapped.
This series goes one step further, by just reserving the complete legacy IO port range in 0x0--0xffff for arm64. The motivation for doing this is to make the
request_region()calls for those drivers fail, like this:root@ubuntu:/home/john# insmod mk712.ko [ 3415.575800] mk712: unable to get IO region insmod: ERROR: could not insert module mk712.ko: No such deviceOtherwise, in theory, those drivers could initiate rogue accesses to mapped IO port regions for other devices and cause corruptions or side-effects. Indeed, those drivers should not be allowed to access IO ports at all in such a system.
As a secondary defence, for broken drivers who do not call
request_region(), IO port accesses in range 0--0xffff will be ignored, again preserving the system.I am sending as an RFC as I am not sure of any problem with reserving first
0x10000of IO space like this. There is reserve= commandline argument, which does allow this already.For reference, here's how
/proc/ioportslooks on my arm64 system with this change:
Quoted 16 lines
root@ubuntu:/home/john# more /proc/ioports
00010000-0001ffff : PCI Bus 0002:f8
00010000-00010fff : PCI Bus 0002:f9
00010000-00010007 : 0002:f9:00.0
00010000-00010007 : serial
00010008-0001000f : 0002:f9:00.1
00010008-0001000f : serial
00010010-00010017 : 0002:f9:00.2
00010018-0001001f : 0002:f9:00.2
00020000-0002ffff : PCI Bus 0004:88
00030000-0003ffff : PCI Bus 0005:78
00040000-0004ffff : PCI Bus 0006:c0
00050000-0005ffff : PCI Bus 0007:90
00060000-0006ffff : PCI Bus 000a:10
00070000-0007ffff : PCI Bus 000c:20
00080000-0008ffff : PCI Bus 000d:30Doesn't this mean we lose the ability to access PCI devices with legacy ISA compatibility? Most importantly, any GPU today should in theory still support VGA frame buffer mode or text console, but both of these stop working if the low I/O ports are not mapped to the corresponding PCI bus. There is of course already a problem if you have multiple PCI host bridges, and each one gets its own PIO range, which means that only one of them can have an ISA bridge with working PIO behind it.
Another such case would be a BMC that has legacy ISA devices behind a (real or emulated) LPC bus, e.g. a 8250 UART, ps2 keyboard, RTC, or an ATA CDROM. Not sure if any of those are ever used on Arm machines.
Regarding the size of the reservation, does this actually need to cover the 0x0fff...0xffff range or just 0x0000...0x0fff? I don't think there are any drivers that hardcode I/O ports beyond 0x0fff because those would not work on ISA buses but require PCI assigned BARs.
One more thought: There are two common ways in which PCI host bridges map their PIO ports: either each host bridge has its own 0x0...0xffff BAR range but gets remapped to an arbitrary range of port numbers in the kernel, or each host bridge uses a distinct range of port numbers, and the kernel can use a 1:1 mapping between hardware and software port numbers, i.e. the number in the BAR is the same as in the kernel.
If all numbers are shifted by 0x10000, that second case no longer works, and there is always an offset.
Arnd
Quoted 4 lines
Quoted 4 lines
For reference, here's how
/proc/ioportslooks on my arm64 system with this change:
Quoted 16 lines
Quoted 8 lines
root@ubuntu:/home/john# more /proc/ioports 00010000-0001ffff : PCI Bus 0002:f8 00010000-00010fff : PCI Bus 0002:f9 00010000-00010007 : 0002:f9:00.0 00010000-00010007 : serial 00010008-0001000f : 0002:f9:00.1 00010008-0001000f : serial 00010010-00010017 : 0002:f9:00.2Quoted 8 lines
00010018-0001001f : 0002:f9:00.2 00020000-0002ffff : PCI Bus 0004:88 00030000-0003ffff : PCI Bus 0005:78 00040000-0004ffff : PCI Bus 0006:c0 00050000-0005ffff : PCI Bus 0007:90 00060000-0006ffff : PCI Bus 000a:10 00070000-0007ffff : PCI Bus 000c:20 00080000-0008ffff : PCI Bus 000d:30
Hi Arnd,
Quoted 5 lines
Doesn't this mean we lose the ability to access PCI devices with legacy ISA compatibility? Most importantly, any GPU today should in theory still support VGA frame buffer mode or text console, but both of these stop working if the low I/O ports are not mapped to the corresponding PCI bus.
Hmmm.. so are you saying that there is an expectation that the kernel PIO region assigned for these devices must start at 0x0? If so, I assume it's because fixed IO ports are used.
Quoted 4 lines
There is of course
already a problem if you have multiple PCI host bridges, and each one gets its own PIO range, which means that only one of them can have an ISA bridge with working PIO behind it.
The answer to my question, above, seems to be 'yes' now.
Quoted 11 lines
Another such case would be a BMC that has legacy ISA devices behind a (real or emulated) LPC bus, e.g. a 8250 UART, ps2 keyboard, RTC, or an ATA CDROM. Not sure if any of those are ever used on Arm machines.
Regarding the size of the reservation, does this actually need to cover the 0x0fff...0xffff range or just 0x0000...0x0fff? I don't think there are any drivers that hardcode I/O ports beyond
0x0fffbecause those would not work on ISA buses but require PCI assigned BARs.
I just chose the complete legacy IO port range, that being 0x0--0xffff. If there would be no hardcoded ports beyond 0x0fff, then reserving 0x0--0xfff would work.
Quoted 11 lines
One more thought: There are two common ways in which PCI host bridges map their PIO ports: either each host bridge has its own 0x0...0xffff BAR range but gets remapped to an arbitrary range of port numbers in the kernel, or each host bridge uses a distinct range of port numbers, and the kernel can use a 1:1 mapping between hardware and software port numbers, i.e. the number in the BAR is the same as in the kernel.
If all numbers are shifted by
0x10000, that second case no longer works, and there is always an offset.
Yes, this change would definitely break the second. But does - or could - anyone use it on arm64? I didn't think that it was possible.
Thanks,
John
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel