linux-stable/arch/powerpc/platforms/powernv
Frederic Barrat 887084d0ad powerpc/powernv/ioda: Skip unallocated resources when mapping to PE
[ Upstream commit e64e71056f ]

pnv_ioda_setup_pe_res() calls opal to map a resource with a PE. However,
the code assumes the resource is allocated and it uses the resource
address to find out the segment(s) which need to be mapped to the
PE. In the unlikely case where the resource hasn't been allocated, the
computation for the segment number is garbage, which can lead to
invalid memory access and potentially a kernel crash, such as:

[ ] pci_bus 0002:02: Configuring PE for bus
[ ] pci 0002:02     : [PE# fc] Secondary bus 0x0000000000000002..0x0000000000000002 associated with PE#fc
[ ] BUG: Kernel NULL pointer dereference on write at 0x00000000
[ ] Faulting instruction address: 0xc00000000005eac4
[ ] Oops: Kernel access of bad area, sig: 7 [#1]
[ ] LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA PowerNV
[ ] Modules linked in:
[ ] CPU: 12 PID: 1 Comm: swapper/20 Not tainted 5.10.50-openpower1 #2
[ ] NIP:  c00000000005eac4 LR: c00000000005ea44 CTR: 0000000030061b9c
[ ] REGS: c000200007383650 TRAP: 0300   Not tainted  (5.10.50-openpower1)
[ ] MSR:  9000000000009033 <SF,HV,EE,ME,IR,DR,RI,LE>  CR: 44000224  XER: 20040000
[ ] CFAR: c00000000005eaa0 DAR: 0000000000000000 DSISR: 02080000 IRQMASK: 0
[ ] GPR00: c00000000005dd98 c0002000073838e0 c00000000185de00 c000200fff018960
[ ] GPR04: 00000000000000fc 0000000000000003 0000000000000000 0000000000000000
[ ] GPR08: 0000000000000000 0000000000000000 0000000000000000 9000000000001033
[ ] GPR12: 0000000031cb0000 c000000ffffe6a80 c000000000010a58 0000000000000000
[ ] GPR16: 0000000000000000 0000000000000000 0000000000000000 0000000000000000
[ ] GPR20: 0000000000000000 0000000000000000 0000000000000000 c00000000711e200
[ ] GPR24: 0000000000000100 c000200009501120 c00020000cee2800 00000000000003ff
[ ] GPR28: c000200fff018960 0000000000000000 c000200ffcb7fd00 0000000000000000
[ ] NIP [c00000000005eac4] pnv_ioda_setup_pe_res+0x94/0x1a0
[ ] LR [c00000000005ea44] pnv_ioda_setup_pe_res+0x14/0x1a0
[ ] Call Trace:
[ ] [c0002000073838e0] [c00000000005eb98] pnv_ioda_setup_pe_res+0x168/0x1a0 (unreliable)
[ ] [c000200007383970] [c00000000005dd98] pnv_pci_ioda_dma_dev_setup+0x43c/0x970
[ ] [c000200007383a60] [c000000000032cdc] pcibios_bus_add_device+0x78/0x18c
[ ] [c000200007383aa0] [c00000000028f2bc] pci_bus_add_device+0x28/0xbc
[ ] [c000200007383b10] [c00000000028f3a0] pci_bus_add_devices+0x50/0x7c
[ ] [c000200007383b50] [c00000000028f3c4] pci_bus_add_devices+0x74/0x7c
[ ] [c000200007383b90] [c00000000028f3c4] pci_bus_add_devices+0x74/0x7c
[ ] [c000200007383bd0] [c00000000069ad0c] pcibios_init+0xf0/0x104
[ ] [c000200007383c50] [c0000000000106d8] do_one_initcall+0x84/0x1c4
[ ] [c000200007383d20] [c0000000006910b8] kernel_init_freeable+0x264/0x268
[ ] [c000200007383dc0] [c000000000010a68] kernel_init+0x18/0x138
[ ] [c000200007383e20] [c00000000000cbfc] ret_from_kernel_thread+0x5c/0x80
[ ] Instruction dump:
[ ] 7f89e840 409d000c 7fbbf840 409c000c 38210090 4848f448 809c002c e95e0120
[ ] 7ba91764 38a00003 57a7043e 38c00000 <7c8a492e> 5484043e e87e0018 4bff23bd

Hitting the problem is not that easy. It was seen with a (semi-bogus)
PCI device with a class code of 0. The generic PCI framework doesn't
allocate resources in such a case.

The patch is simply skipping resources which are still flagged with
IORESOURCE_UNSET.

We don't have the problem with 64-bit mem resources, as the address of
the resource is checked to be within the range of the 64-bit mmio
window. See pnv_ioda_reserve_dev_m64_pe() and pnv_pci_is_m64().

Reported-by: Andrew Jeffery <andrew@aj.id.au>
Fixes: 23e79425fe ("powerpc/powernv: Simplify pnv_ioda_setup_pe_seg()")
Signed-off-by: Frederic Barrat <fbarrat@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230120093215.19496-1-fbarrat@linux.ibm.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-11 16:26:40 +01:00
..
Kconfig
Makefile
copy-paste.h powerpc/powernv: copy/paste - Mask SO bit in CR 2018-07-03 11:24:50 +02:00
eeh-powernv.c powerpc/powernv/eeh/npu: Fix uninitialized variables in opal_pci_eeh_freeze_status 2019-12-05 15:37:43 +01:00
idle.c powerpc/powernv/cpuidle: Init all present cpus for deep states 2018-07-03 11:24:51 +02:00
memtrace.c powerpc/powernv/memtrace: Don't leak kernel memory to user space 2020-12-29 13:47:08 +01:00
npu-dma.c powerpc/powernv: Fix concurrency issue with npu->mmio_atsd_usage 2018-09-19 22:43:38 +02:00
opal-async.c
opal-dump.c powerpc/powernv/opal-dump : Use IRQ_HANDLED instead of numbers in interrupt handler 2020-10-29 09:07:21 +01:00
opal-elog.c powerpc/powernv/elog: Fix race while processing OPAL error log event. 2020-11-05 11:07:02 +01:00
opal-flash.c
opal-hmi.c
opal-imc.c powerpc/perf: Fix IMC_MAX_PMU macro 2019-11-20 17:59:25 +01:00
opal-irqchip.c
opal-kmsg.c
opal-lpc.c powerpc/powernv: add missing of_node_put 2022-01-27 09:00:57 +01:00
opal-memory-errors.c
opal-msglog.c powerpc/powernv: Make opal log only readable by root 2019-03-23 14:35:26 +01:00
opal-nvram.c powerpc/powernv: Fix NVRAM sleep in invalid context when crashing 2018-05-22 18:53:58 +02:00
opal-power.c
opal-powercap.c
opal-prd.c
opal-psr.c
opal-rtc.c rtc: opal: Fix OPAL RTC driver OPAL_BUSY loops 2018-05-01 12:58:24 -07:00
opal-sensor-groups.c
opal-sensor.c
opal-sysparam.c
opal-tracepoints.c
opal-wrappers.S powerpc/xive: Fix bogus error code returned by OPAL 2019-10-05 12:47:32 +02:00
opal-xscom.c
opal.c powerpc/powernv: add missing of_node_put() in opal_export_attrs() 2022-10-26 13:17:07 +02:00
pci-cxl.c
pci-ioda.c powerpc/powernv/ioda: Skip unallocated resources when mapping to PE 2023-03-11 16:26:40 +01:00
pci.c powerpc/powernv/iov: Ensure the pdn for VFs always contains a valid PE number 2020-02-28 16:35:56 +01:00
pci.h
powernv.h powerpc/powernv: wire up rng during setup_arch 2022-07-02 16:18:10 +02:00
rng.c powerpc/powernv: Avoid crashing if rng is NULL 2022-08-25 11:11:13 +02:00
setup.c powerpc/powernv: wire up rng during setup_arch 2022-07-02 16:18:10 +02:00
smp.c powerpc/powernv/smp: Fix spurious DBG() warning 2020-11-05 11:06:53 +01:00
subcore-asm.S
subcore.c
subcore.h
vas-window.c
vas.c
vas.h