WSL2-Linux-Kernel/arch/powerpc/platforms/powernv
Frederic Barrat 83c043b92b 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>
2024-03-01 13:21:51 +01:00
..
Kconfig powerpc/vas: Move VAS API to book3s common platform 2021-06-20 21:58:55 +10:00
Makefile powerpc/vas: Move VAS API to book3s common platform 2021-06-20 21:58:55 +10:00
copy-paste.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
eeh-powernv.c powerpc/eeh: Clean up PE addressing 2020-10-06 23:22:25 +11:00
idle.c Merge branch 'topic/ppc-kvm' into next 2021-08-26 21:21:11 +10:00
memtrace.c powerpc: rename powerpc_debugfs_root to arch_debugfs_dir 2021-08-13 22:04:26 +10:00
ocxl.c ocxl: Initiate a TLB invalidate command 2020-12-04 01:01:30 +11:00
opal-async.c powerpc: Use fallthrough pseudo-keyword 2020-07-29 21:09:37 +10:00
opal-call.c powerpc/64s: avoid reloading (H)SRR registers if they are still valid 2021-06-25 00:06:55 +10:00
opal-core.c powerpc/powernv: make symbol 'mpipl_kobj' static 2021-04-14 23:04:17 +10:00
opal-dump.c powerpc/powernv/dump: Handle multiple writes to ack attribute 2020-10-19 22:58:52 +11:00
opal-elog.c powerpc/powernv: Rate limit opal-elog read failure message 2020-12-15 22:53:27 +11:00
opal-fadump.c powerpc/fadump: Fix fadump to work with a different endian capture kernel 2022-06-09 10:22:42 +02:00
opal-fadump.h powerpc/fadump: Fix fadump to work with a different endian capture kernel 2022-06-09 10:22:42 +02:00
opal-flash.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
opal-hmi.c powerpc/64s/powernv: Ratelimit harmless HMI error printing 2020-12-04 01:01:23 +11:00
opal-imc.c powerpc: rename powerpc_debugfs_root to arch_debugfs_dir 2021-08-13 22:04:26 +10:00
opal-irqchip.c powerpc/powernv: Add a null pointer check in opal_event_init() 2024-01-25 14:52:33 -08:00
opal-kmsg.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
opal-lpc.c powerpc/powernv: add missing of_node_put 2022-01-27 11:04:56 +01:00
opal-memory-errors.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
opal-msglog.c powerpc/powernv: Include asm/powernv.h from the local powernv.h 2020-08-25 01:31:33 +10:00
opal-nvram.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
opal-power.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
opal-powercap.c powerpc/powernv: Add a null pointer check in opal_powercap_init() 2024-01-25 14:52:33 -08:00
opal-prd.c powerpc/powernv: Fix fortify source warnings in opal-prd.c 2023-11-28 16:56:36 +00:00
opal-psr.c powerpc/powernv: Make some symbols static 2019-11-13 16:58:06 +11:00
opal-rtc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
opal-secvar.c powerpc/powernv: Add OPAL API interface to access secure variable 2019-11-13 00:33:22 +11:00
opal-sensor-groups.c powerpc/powernv: Make some symbols static 2019-11-13 16:58:06 +11:00
opal-sensor.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
opal-sysparam.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
opal-tracepoints.c jump_label: move 'asm goto' support test to Kconfig 2019-01-06 09:46:51 +09:00
opal-wrappers.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
opal-xscom.c powerpc/powernv: Add a null pointer check to scom_debug_init_one() 2024-01-25 14:52:32 -08:00
opal.c powerpc/powernv: add missing of_node_put() in opal_export_attrs() 2022-10-26 12:35:22 +02:00
pci-cxl.c powerpc/powernv: remove get_cxl_module 2021-02-08 12:20:17 +01:00
pci-ioda-tce.c powerpc/powernv/pci: fix a RCU-list lock 2021-01-31 22:35:49 +11:00
pci-ioda.c powerpc/powernv/ioda: Skip unallocated resources when mapping to PE 2024-03-01 13:21:51 +01:00
pci-sriov.c powerpc/powernv/sriov: perform null check on iov before dereferencing iov 2023-07-23 13:47:13 +02:00
pci.c powerpc/powernv/pci: Drop unused MSI code 2021-08-10 23:15:00 +10:00
pci.h powerpc/powernv/pci: Drop unused MSI code 2021-08-10 23:15:00 +10:00
powernv.h powerpc/powernv: wire up rng during setup_arch 2022-06-29 09:03:30 +02:00
rng.c powerpc/powernv/kvm: Use darn for H_RANDOM on Power9 2022-08-17 14:24:25 +02:00
setup.c powerpc/powernv: wire up rng during setup_arch 2022-06-29 09:03:30 +02:00
smp.c powerpc/64s: Trim offlined CPUs from mm_cpumasks 2020-11-27 00:10:39 +11:00
subcore-asm.S treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
subcore.c powerpc: Move update_power8_hid0() into its only user 2021-06-17 00:09:11 +10:00
subcore.h powerpc: remove unneeded semicolons 2021-02-09 00:10:50 +11:00
ultravisor.c powerpc/powernv: fix missing of_node_put in uv_init() 2022-06-09 10:22:43 +02:00
vas-debug.c powerpc/vas: Define and use common vas_window struct 2021-06-20 21:58:56 +10:00
vas-fault.c powerpc/powernv/vas: Assign real address to rx_fifo in vas_rx_win_attr 2022-06-09 10:22:43 +02:00
vas-trace.h powerpc/vas: Define and use common vas_window struct 2021-06-20 21:58:56 +10:00
vas-window.c powerpc/64s: Fix VAS mm use after free 2023-07-23 13:47:12 +02:00
vas.c powerpc/vas: Fix IRQ name allocation 2021-01-30 11:39:31 +11:00
vas.h powerpc/powernv/vas: Assign real address to rx_fifo in vas_rx_win_attr 2022-06-09 10:22:43 +02:00