From ae778091cac3e6324d0f4876bcc12869679c26e4 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Wed, 16 Jul 2014 15:27:16 +0100 Subject: [PATCH] [ioapi] Fail ioremap() when attempting to map a zero bus address When a 32-bit iPXE binary is running on a system which allocates PCI memory BARs above 4GB, our PCI subsystem will return the base address for any such BARs as zero (with a warning message if DEBUG=pci is enabled). Currently, ioremap() will happily map an address pointing to the start of physical memory, providing no sensible indication of failure. Fix by always returning NULL if we are asked to ioremap() a zero bus address. With a totally flat memory model (e.g. under EFI), this provides an accurate failure indication since no PCI peripheral will be mapped to the zero bus address. With the librm memory model, there is the possibility of a spurious NULL return from ioremap() if the bus address happens to be equal to virt_offset. Under the current virtual memory map, the NULL virtual address will always be the start of .textdata, and so this problem cannot occur; a NULL return from ioremap() will always be an accurate failure indication. Debugged-by: Anton D. Kachalov Signed-off-by: Michael Brown --- src/arch/x86/include/ipxe/x86_io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arch/x86/include/ipxe/x86_io.h b/src/arch/x86/include/ipxe/x86_io.h index adb00a686..1fc7f6608 100644 --- a/src/arch/x86/include/ipxe/x86_io.h +++ b/src/arch/x86/include/ipxe/x86_io.h @@ -45,7 +45,7 @@ IOAPI_INLINE ( x86, bus_to_phys ) ( unsigned long bus_addr ) { static inline __always_inline void * IOAPI_INLINE ( x86, ioremap ) ( unsigned long bus_addr, size_t len __unused ) { - return phys_to_virt ( bus_addr ); + return ( bus_addr ? phys_to_virt ( bus_addr ) : NULL ); } static inline __always_inline void