Skip to content

Commit a5c57fd

Browse files
Gaurav Batrampe
Gaurav Batra
authored andcommitted
powerpc/pseries/iommu: DLPAR add doesn't completely initialize pci_controller
When a PCI device is dynamically added, the kernel oopses with a NULL pointer dereference: BUG: Kernel NULL pointer dereference on read at 0x00000030 Faulting instruction address: 0xc0000000006bbe5c Oops: Kernel access of bad area, sig: 11 [#1] LE PAGE_SIZE=64K MMU=Radix SMP NR_CPUS=2048 NUMA pSeries Modules linked in: rpadlpar_io rpaphp rpcsec_gss_krb5 auth_rpcgss nfsv4 dns_resolver nfs lockd grace fscache netfs xsk_diag bonding nft_compat nf_tables nfnetlink rfkill binfmt_misc dm_multipath rpcrdma sunrpc rdma_ucm ib_srpt ib_isert iscsi_target_mod target_core_mod ib_umad ib_iser libiscsi scsi_transport_iscsi ib_ipoib rdma_cm iw_cm ib_cm mlx5_ib ib_uverbs ib_core pseries_rng drm drm_panel_orientation_quirks xfs libcrc32c mlx5_core mlxfw sd_mod t10_pi sg tls ibmvscsi ibmveth scsi_transport_srp vmx_crypto pseries_wdt psample dm_mirror dm_region_hash dm_log dm_mod fuse CPU: 17 PID: 2685 Comm: drmgr Not tainted 6.7.0-203405+ #66 Hardware name: IBM,9080-HEX POWER10 (raw) 0x800200 0xf000006 of:IBM,FW1060.00 (NH1060_008) hv:phyp pSeries NIP: c0000000006bbe5c LR: c000000000a13e68 CTR: c0000000000579f8 REGS: c00000009924f240 TRAP: 0300 Not tainted (6.7.0-203405+) MSR: 8000000000009033 <SF,EE,ME,IR,DR,RI,LE> CR: 24002220 XER: 20040006 CFAR: c000000000a13e64 DAR: 0000000000000030 DSISR: 40000000 IRQMASK: 0 ... NIP sysfs_add_link_to_group+0x34/0x94 LR iommu_device_link+0x5c/0x118 Call Trace: iommu_init_device+0x26c/0x318 (unreliable) iommu_device_link+0x5c/0x118 iommu_init_device+0xa8/0x318 iommu_probe_device+0xc0/0x134 iommu_bus_notifier+0x44/0x104 notifier_call_chain+0xb8/0x19c blocking_notifier_call_chain+0x64/0x98 bus_notify+0x50/0x7c device_add+0x640/0x918 pci_device_add+0x23c/0x298 of_create_pci_dev+0x400/0x884 of_scan_pci_dev+0x124/0x1b0 __of_scan_bus+0x78/0x18c pcibios_scan_phb+0x2a4/0x3b0 init_phb_dynamic+0xb8/0x110 dlpar_add_slot+0x170/0x3b8 [rpadlpar_io] add_slot_store.part.0+0xb4/0x130 [rpadlpar_io] kobj_attr_store+0x2c/0x48 sysfs_kf_write+0x64/0x78 kernfs_fop_write_iter+0x1b0/0x290 vfs_write+0x350/0x4a0 ksys_write+0x84/0x140 system_call_exception+0x124/0x330 system_call_vectored_common+0x15c/0x2ec Commit a940904 ("powerpc/iommu: Add iommu_ops to report capabilities and allow blocking domains") broke DLPAR add of PCI devices. The above added iommu_device structure to pci_controller. During system boot, PCI devices are discovered and this newly added iommu_device structure is initialized by a call to iommu_device_register(). During DLPAR add of a PCI device, a new pci_controller structure is allocated but there are no calls made to iommu_device_register() interface. Fix is to register the iommu device during DLPAR add as well. Fixes: a940904 ("powerpc/iommu: Add iommu_ops to report capabilities and allow blocking domains") Signed-off-by: Gaurav Batra <[email protected]> Reviewed-by: Brian King <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent 0846dd7 commit a5c57fd

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

arch/powerpc/include/asm/ppc-pci.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ void *pci_traverse_device_nodes(struct device_node *start,
3030
void *data);
3131
extern void pci_devs_phb_init_dynamic(struct pci_controller *phb);
3232

33+
#if defined(CONFIG_IOMMU_API) && (defined(CONFIG_PPC_PSERIES) || \
34+
defined(CONFIG_PPC_POWERNV))
35+
extern void ppc_iommu_register_device(struct pci_controller *phb);
36+
extern void ppc_iommu_unregister_device(struct pci_controller *phb);
37+
#else
38+
static inline void ppc_iommu_register_device(struct pci_controller *phb) { }
39+
static inline void ppc_iommu_unregister_device(struct pci_controller *phb) { }
40+
#endif
41+
42+
3343
/* From rtas_pci.h */
3444
extern void init_pci_config_tokens (void);
3545
extern unsigned long get_phb_buid (struct device_node *);

arch/powerpc/kernel/iommu.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ static struct iommu_device *spapr_tce_iommu_probe_device(struct device *dev)
13411341
struct pci_controller *hose;
13421342

13431343
if (!dev_is_pci(dev))
1344-
return ERR_PTR(-EPERM);
1344+
return ERR_PTR(-ENODEV);
13451345

13461346
pdev = to_pci_dev(dev);
13471347
hose = pdev->bus->sysdata;
@@ -1390,6 +1390,21 @@ static const struct attribute_group *spapr_tce_iommu_groups[] = {
13901390
NULL,
13911391
};
13921392

1393+
void ppc_iommu_register_device(struct pci_controller *phb)
1394+
{
1395+
iommu_device_sysfs_add(&phb->iommu, phb->parent,
1396+
spapr_tce_iommu_groups, "iommu-phb%04x",
1397+
phb->global_number);
1398+
iommu_device_register(&phb->iommu, &spapr_tce_iommu_ops,
1399+
phb->parent);
1400+
}
1401+
1402+
void ppc_iommu_unregister_device(struct pci_controller *phb)
1403+
{
1404+
iommu_device_unregister(&phb->iommu);
1405+
iommu_device_sysfs_remove(&phb->iommu);
1406+
}
1407+
13931408
/*
13941409
* This registers IOMMU devices of PHBs. This needs to happen
13951410
* after core_initcall(iommu_init) + postcore_initcall(pci_driver_init) and
@@ -1400,11 +1415,7 @@ static int __init spapr_tce_setup_phb_iommus_initcall(void)
14001415
struct pci_controller *hose;
14011416

14021417
list_for_each_entry(hose, &hose_list, list_node) {
1403-
iommu_device_sysfs_add(&hose->iommu, hose->parent,
1404-
spapr_tce_iommu_groups, "iommu-phb%04x",
1405-
hose->global_number);
1406-
iommu_device_register(&hose->iommu, &spapr_tce_iommu_ops,
1407-
hose->parent);
1418+
ppc_iommu_register_device(hose);
14081419
}
14091420
return 0;
14101421
}

arch/powerpc/platforms/pseries/pci_dlpar.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ struct pci_controller *init_phb_dynamic(struct device_node *dn)
3535

3636
pseries_msi_allocate_domains(phb);
3737

38+
ppc_iommu_register_device(phb);
39+
3840
/* Create EEH devices for the PHB */
3941
eeh_phb_pe_create(phb);
4042

@@ -76,6 +78,8 @@ int remove_phb_dynamic(struct pci_controller *phb)
7678
}
7779
}
7880

81+
ppc_iommu_unregister_device(phb);
82+
7983
pseries_msi_free_domains(phb);
8084

8185
/* Keep a reference so phb isn't freed yet */

0 commit comments

Comments
 (0)