linux/arch/powerpc/include/asm
Mauricio Faria de Oliveira 2dd9c11b9d powerpc/pseries: use pci_host_bridge.release_fn() to kfree(phb)
This patch leverages 'struct pci_host_bridge' from the PCI subsystem
in order to free the pci_controller only after the last reference to
its devices is dropped (avoiding an oops in pcibios_release_device()
if the last reference is dropped after pcibios_free_controller()).

The patch relies on pci_host_bridge.release_fn() (and .release_data),
which is called automatically by the PCI subsystem when the root bus
is released (i.e., the last reference is dropped).  Those fields are
set via pci_set_host_bridge_release() (e.g. in the platform-specific
implementation of pcibios_root_bridge_prepare()).

It introduces the 'pcibios_free_controller_deferred()' .release_fn()
and it expects .release_data to hold a pointer to the pci_controller.

The function implictly calls 'pcibios_free_controller()', so an user
must *NOT* explicitly call it if using the new _deferred() callback.

The functionality is enabled for pseries (although it isn't platform
specific, and may be used by cxl).

Details on not-so-elegant design choices:

 - Use 'pci_host_bridge.release_data' field as pointer to associated
   'struct pci_controller' so *not* to 'pci_bus_to_host(bridge->bus)'
   in pcibios_free_controller_deferred().

   That's because pci_remove_root_bus() sets 'host_bridge->bus = NULL'
   (so, if the last reference is released after pci_remove_root_bus()
   runs, which eventually reaches pcibios_free_controller_deferred(),
   that would hit a null pointer dereference).

   The cxl/vphb.c code calls pci_remove_root_bus(), and the cxl folks
   are interested in this fix.

Test-case #1 (hold references)

  # ls -ld /sys/block/sd* | grep -m1 0021:01:00.0
  <...> /sys/block/sdaa -> ../devices/pci0021:01/0021:01:00.0/<...>

  # ls -ld /sys/block/sd* | grep -m1 0021:01:00.1
  <...> /sys/block/sdab -> ../devices/pci0021:01/0021:01:00.1/<...>

  # cat >/dev/sdaa & pid1=$!
  # cat >/dev/sdab & pid2=$!

  # drmgr -w 5 -d 1 -c phb -s 'PHB 33' -r
  Validating PHB DLPAR capability...yes.
  [  594.306719] pci_hp_remove_devices: PCI: Removing devices on bus 0021:01
  [  594.306738] pci_hp_remove_devices:    Removing 0021:01:00.0...
  ...
  [  598.236381] pci_hp_remove_devices:    Removing 0021:01:00.1...
  ...
  [  611.972077] pci_bus 0021:01: busn_res: [bus 01-ff] is released
  [  611.972140] rpadlpar_io: slot PHB 33 removed

  # kill -9 $pid1
  # kill -9 $pid2
  [  632.918088] pcibios_free_controller_deferred: domain 33, dynamic 1

Test-case #2 (don't hold references)

  # drmgr -w 5 -d 1 -c phb -s 'PHB 33' -r
  Validating PHB DLPAR capability...yes.
  [  916.357363] pci_hp_remove_devices: PCI: Removing devices on bus 0021:01
  [  916.357386] pci_hp_remove_devices:    Removing 0021:01:00.0...
  ...
  [  920.566527] pci_hp_remove_devices:    Removing 0021:01:00.1...
  ...
  [  933.955873] pci_bus 0021:01: busn_res: [bus 01-ff] is released
  [  933.955977] pcibios_free_controller_deferred: domain 33, dynamic 1
  [  933.955999] rpadlpar_io: slot PHB 33 removed

Suggested-By: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Tested-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com> # cxl
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2016-08-22 11:09:33 +10:00
..
book3s powerpc/mm: Move register_process_table() out of ppc_md 2016-08-04 20:22:34 +10:00
nohash powerpc updates for 4.8 # 1 2016-07-30 21:01:36 -07:00
8xx_immap.h
Kbuild word-at-a-time.h: fix some Kbuild files 2015-10-06 14:52:48 -04:00
accounting.h powerpc32: provide VIRT_CPU_ACCOUNTING 2016-07-09 01:43:50 -05:00
agp.h
archrandom.h powerpc: Use hardware RNG for arch_get_random_seed_* not arch_get_random_* 2015-07-23 19:52:03 +10:00
asm-compat.h powerpc/ebpf/jit: Implement JIT compiler for extended BPF 2016-06-24 15:17:57 +10:00
asm-offsets.h
asm-prototypes.h powerpc: Introduce asm-prototypes.h 2016-06-16 22:39:54 +10:00
async_tx.h
atomic.h locking/atomic, arch/powerpc: Implement atomic{,64}_fetch_{add,sub,and,or,xor}{,_relaxed,_acquire,_release}() 2016-06-16 10:48:28 +02:00
backlight.h
barrier.h powerpc: define __smp_xxx 2016-01-12 20:46:53 +02:00
bitops.h powerpc: Fix comment typos in arch/powerpc/include/asm/bitops.h 2014-11-12 16:31:46 +11:00
bootx.h
btext.h
bug.h powerpc: Remove stale function prototypes 2014-09-25 23:14:43 +10:00
bugs.h
cache.h powerpc: add inline functions for cache related instructions 2016-03-11 17:20:11 -06:00
cacheflush.h powerpc: Move cpu_has_feature() to a separate file 2016-08-01 11:15:03 +10:00
cell-pmu.h
cell-regs.h
checksum.h powerpc: optimise csum_partial() call when len is constant 2016-03-09 10:44:18 -06:00
cmpxchg.h powerpc: Use BUILD_BUG_ON_MSG() for unsupported {cmp}xchg sizes 2016-02-24 20:08:48 +11:00
code-patching.h powerpc: Define and use PPC64_ELF_ABI_v2/v1 2016-06-14 13:58:27 +10:00
compat.h powerpc/kernel: Add SIG_SYS support for compat tasks 2015-07-29 11:56:13 +10:00
context_tracking.h
copro.h powerpc/cell: Make spu_flush_all_slbs() generic 2014-10-08 20:15:37 +11:00
cpm.h QE: Move QE from arch/powerpc to drivers/soc 2015-12-22 17:12:56 -06:00
cpm1.h
cpm2.h
cpu_has_feature.h powerpc/mm: Catch usage of cpu/mmu_has_feature() before jump label init 2016-08-01 11:15:06 +10:00
cpufeature.h powerpc: Add module autoloading based on CPU features 2016-07-21 20:33:57 +10:00
cpuidle.h powerpc/powernv: Move IDLE_STATE_ENTER_SEQ macro to cpuidle.h 2016-08-09 14:50:20 +10:00
cputable.h powerpc: Add option to use jump label for cpu_has_feature() 2016-08-01 11:15:05 +10:00
cputhreads.h powerpc: cputhreads: Add missing include file 2016-08-22 11:09:33 +10:00
cputime.h powerpc: Move cpu_has_feature() to a separate file 2016-08-01 11:15:03 +10:00
current.h
dbdma.h powerpc: Move Power Macintosh drivers to generic byteswappers 2015-03-23 14:29:40 +11:00
dbell.h powerpc: Move cpu_has_feature() to a separate file 2016-08-01 11:15:03 +10:00
dcr-generic.h
dcr-mmio.h
dcr-native.h powerpc: Move cpu_has_feature() to a separate file 2016-08-01 11:15:03 +10:00
dcr-regs.h
dcr.h
debug.h
delay.h
device.h powerpc/iommu: Remove dma_data union 2015-07-13 10:10:54 +10:00
disassemble.h KVM: PPC: e500: Emulate TMCFG0 TMRN register 2015-10-15 15:58:16 +11:00
dma-mapping.h dma-mapping: use unsigned long for dma_attrs 2016-08-04 08:50:07 -04:00
dma.h
edac.h EDAC: Cleanup atomic_scrub mess 2015-05-28 15:31:53 +02:00
eeh.h powerpc/pci: Delay populating pdn 2016-06-21 15:30:56 +10:00
eeh_event.h
ehv_pic.h
elf.h mm: fold arch_randomize_brk into ARCH_HAS_ELF_RANDOMIZE 2015-04-14 16:49:05 -07:00
emergency-restart.h
emulated_ops.h
epapr_hcalls.h
exception-64e.h powerpc/e6500: hw tablewalk: make sure we invalidate and write to the same tlb entry 2015-10-27 18:14:40 -05:00
exception-64s.h Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/scottwood/linux into next 2016-07-30 13:43:19 +10:00
exec.h
fadump.h powerpc/fadump: rename cpu_online_mask member of struct fadump_crash_info_header 2016-01-20 17:09:18 -08:00
fb.h
feature-fixups.h powerpc/32: Fix crash during static key init 2016-08-10 19:41:58 +10:00
firmware.h powerpc: Move FW feature probing out of pseries probe() 2016-07-21 18:56:13 +10:00
fixmap.h powerpc/8xx: Fix vaddr for IMMR early remap 2016-07-09 02:02:48 -05:00
floppy.h
fs_pd.h
fsl_85xx_cache_sram.h
fsl_gtm.h
fsl_hcalls.h
fsl_lbc.h uio: uio_fsl_elbc_gpcm: new driver 2015-01-12 05:04:13 -08:00
fsl_pamu_stash.h iommu/fsl: Various cleanups 2015-02-03 18:47:18 +01:00
fsl_pm.h powerpc/rcpm: add RCPM driver 2016-03-04 23:50:27 -06:00
ftrace.h powerpc: Define and use PPC64_ELF_ABI_v2/v1 2016-06-14 13:58:27 +10:00
futex.h
grackle.h
hardirq.h powerpc: Replace __get_cpu_var uses 2014-11-03 12:12:32 +11:00
heathrow.h
highmem.h kmap_atomic_to_page() has no users, remove it 2015-11-09 15:11:24 -08:00
hmi.h KVM: PPC: Book3S HV: Fix TB corruption in guest exit path on HMI interrupt 2016-06-20 14:11:25 +10:00
hugetlb.h powerpc/mm: Use hugetlb flush functions 2016-08-01 11:15:09 +10:00
hvcall.h powerpc: Put exception configuration in a common place 2016-07-21 18:56:31 +10:00
hvconsole.h
hvcserver.h
hvsi.h
hw_breakpoint.h
hw_irq.h powerpc/irq: Add mechanism to force a replay of interrupts 2016-07-17 16:42:44 +10:00
hydra.h powerpc: Fix misspellings in comments. 2016-03-01 19:27:20 +11:00
i8259.h
ibmebus.h
icswx.h crypto: nx-842 - Mask XERS0 bit in return value 2015-12-17 16:42:12 +08:00
ide.h
immap_cpm2.h
io-defs.h
io-workarounds.h
io.h powerpc: Fix misspellings in comments. 2016-03-01 19:27:20 +11:00
io_event_irq.h
iommu.h dma-mapping: use unsigned long for dma_attrs 2016-08-04 08:50:07 -04:00
ipic.h
irq.h powerpc: Remove stale function prototypes 2014-09-25 23:14:43 +10:00
irq_work.h powerpc: Re-enable dynticks 2015-02-23 14:52:04 +11:00
irqflags.h
jump_label.h powerpc updates for 4.8 #2 2016-08-05 09:00:54 -04:00
kdebug.h
kdump.h
kexec.h powerpc/kdump: Ignore failure in enabling big endian exception during crash 2014-12-29 15:44:53 +11:00
keylargo.h
kgdb.h
kmap_types.h
kprobes.h powerpc: Define and use PPC64_ELF_ABI_v2/v1 2016-06-14 13:58:27 +10:00
kvm_asm.h KVM: PPC: Remove shared defines for SPE and AltiVec interrupts 2014-09-22 10:11:34 +02:00
kvm_book3s.h kvm: rename pfn_t to kvm_pfn_t 2016-01-15 17:56:32 -08:00
kvm_book3s_32.h
kvm_book3s_64.h powerpc/mm/hash: Add helper for finding SLBE LLP encoding 2016-08-01 11:15:08 +10:00
kvm_book3s_asm.h powerpc/powernv: Add platform support for stop instruction 2016-07-15 20:18:41 +10:00
kvm_booke.h KVM: PPC: Book3S: correct width in XER handling 2015-08-22 11:16:19 +02:00
kvm_booke_hv_asm.h
kvm_fpu.h
kvm_host.h KVM: halt_polling: provide a way to qualify wakeups during poll 2016-05-13 17:29:23 +02:00
kvm_para.h
kvm_ppc.h KVM: PPC: Add support for 64bit TCE windows 2016-03-02 09:56:50 +11:00
libata-portmap.h
linkage.h powerpc: Define and use PPC64_ELF_ABI_v2/v1 2016-06-14 13:58:27 +10:00
livepatch.h powerpc/livepatch: Add livepatch stack to struct thread_info 2016-04-14 15:47:06 +10:00
local.h
lppaca.h
lv1call.h
machdep.h powerpc/mm: Move register_process_table() out of ppc_md 2016-08-04 20:22:34 +10:00
macio.h
mc146818rtc.h
mce.h
mediabay.h
mm-arch-hooks.h powerpc/mm: tracking vDSO remap 2015-06-24 17:49:41 -07:00
mman.h powerpc updates for 4.8 #2 2016-08-05 09:00:54 -04:00
mmu-8xx.h powerpc/8xx: Fix vaddr for IMMR early remap 2016-07-09 02:02:48 -05:00
mmu-40x.h
mmu-44x.h
mmu-book3e.h
mmu.h powerpc/mm: Catch usage of cpu/mmu_has_feature() before jump label init 2016-08-01 11:15:06 +10:00
mmu_context.h powerpc/mm/radix: Add mmu context handling callback for radix 2016-05-01 18:33:05 +10:00
mmzone.h
module.h Merge branch 'topic/mprofile-kernel' into next 2016-03-11 11:20:15 +11:00
mpc5xxx.h
mpc6xx.h
mpc52xx.h powerpc: Make ppc_md.{halt, restart} __noreturn 2016-07-14 21:12:06 +10:00
mpc52xx_psc.h powerpc: mpc512x: drop bogus and unused psc register bit definitions 2015-10-22 16:06:08 +02:00
mpc85xx.h powerpc/fsl-booke: Add T4080 SVR value 2015-03-31 22:23:17 -05:00
mpc5121.h powerpc/512x: add LocalPlus Bus FIFO device driver 2015-10-22 15:19:40 +02:00
mpc8260.h
mpic.h powerpc/mpic: Add get_version API both for internal and external use 2015-03-23 19:51:17 -05:00
mpic_msgr.h
mpic_timer.h
msi_bitmap.h powerpc/msi: Free the bitmap if it was slab allocated 2015-10-05 21:32:50 +11:00
mutex.h locking/mutex: Optimize mutex_trylock() fast-path 2016-06-08 15:17:01 +02:00
nmi.h powerpc: Add ppc64 hard lockup detector support 2015-04-11 20:49:27 +10:00
nvram.h powerpc/nvram: Move generic code for nvram and pstore 2015-03-23 14:05:49 +11:00
ohare.h
opal-api.h powerpc/opal: Add real mode call wrappers 2016-07-17 16:42:46 +10:00
opal.h powerpc: Put exception configuration in a common place 2016-07-21 18:56:31 +10:00
oprofile_impl.h
paca.h - ARM: GICv3 ITS emulation and various fixes. Removal of the old 2016-08-02 16:11:27 -04:00
page.h powerpc/32: Remove RELOCATABLE_PPC32 2016-07-19 20:17:07 +10:00
page_32.h powerpc32: Remove clear_pages() and define clear_page() inline 2016-03-11 17:20:11 -06:00
page_64.h powerpc/mm/slice: Remove slice_mm_new_context() 2016-05-11 21:54:00 +10:00
parport.h
pasemi_dma.h
pci-bridge.h powerpc/pseries: use pci_host_bridge.release_fn() to kfree(phb) 2016-08-22 11:09:33 +10:00
pci.h PCI: Unify pci_resource_to_user() declarations 2016-06-17 14:43:34 -05:00
percpu.h
perf_event.h powerpc: Rename __get_SP() to current_stack_pointer() 2014-10-15 11:23:20 +11:00
perf_event_fsl_emb.h
perf_event_server.h powerpc/perf: Export Power8 generic and cache events to sysfs 2016-03-10 22:56:05 +11:00
pgalloc.h powerpc/mm: Copy pgalloc (part 2) 2016-05-11 21:53:49 +10:00
pgtable-be-types.h powerpc/mm: use _raw variant of page table accessors 2016-07-17 16:42:51 +10:00
pgtable-types.h powerpc/mm: Add pte_xchg() helper 2016-05-01 18:32:16 +10:00
pgtable.h powerpc/mm: check for irq disabled() only if DEBUG_VM is enabled 2016-07-26 16:19:19 -07:00
plpar_wrappers.h powerpc/mm: Use H_READ with H_READ_4 2015-12-14 15:19:17 +11:00
pmac_feature.h powerpc: Various typo fixes 2016-06-14 13:58:26 +10:00
pmac_low_i2c.h
pmac_pfunc.h
pmc.h
pmi.h
pnv-pci.h PCI/hotplug: pnv_php: export symbols and move struct types needed by cxl 2016-07-14 20:28:08 +10:00
ppc-opcode.h powerpc updates for 4.8 # 1 2016-07-30 21:01:36 -07:00
ppc-pci.h powerpc/pci: Delay populating pdn 2016-06-21 15:30:56 +10:00
ppc4xx.h powerpc: Make ppc_md.{halt, restart} __noreturn 2016-07-14 21:12:06 +10:00
ppc4xx_ocm.h
ppc_asm.h powerpc updates for 4.8 # 1 2016-07-30 21:01:36 -07:00
probes.h
processor.h powerpc/powernv: Add platform support for stop instruction 2016-07-15 20:18:41 +10:00
prom.h powerpc: Remove stale function prototypes 2014-09-25 23:14:43 +10:00
ps3.h powerpc/64: Move MMU backend selection out of platform code 2016-07-21 18:56:38 +10:00
ps3av.h powerpc: Various typo fixes 2016-06-14 13:58:26 +10:00
ps3gpu.h
ps3stor.h
pte-common.h powerpc: Various typo fixes 2016-06-14 13:58:26 +10:00
ptrace.h powerpc: Define and use PPC64_ELF_ABI_v2/v1 2016-06-14 13:58:27 +10:00
reg.h powerpc: Remove mfvtb() 2016-08-01 11:15:03 +10:00
reg_8xx.h powerpc/8xx: Fix do_mtspr_cpu6() build on older compilers 2016-03-16 15:22:40 +11:00
reg_a2.h
reg_booke.h powerpc: Fix misspellings in comments. 2016-03-01 19:27:20 +11:00
reg_fsl_emb.h
rheap.h
rio.h powerpc: Remove stale function prototypes 2014-09-25 23:14:43 +10:00
rtas.h powerpc: Merge 32-bit and 64-bit setup_arch() 2016-07-21 19:17:46 +10:00
runlatch.h
scom.h
seccomp.h powerpc: switch to using asm-generic for seccomp.h 2015-04-17 09:04:10 -04:00
sections.h powerpc: Define and use PPC64_ELF_ABI_v2/v1 2016-06-14 13:58:27 +10:00
serial.h
setjmp.h
setup.h powerpc: Put exception configuration in a common place 2016-07-21 18:56:31 +10:00
sfp-machine.h
shmparam.h
signal.h
smp.h powerpc: Merge 32-bit and 64-bit setup_arch() 2016-07-21 19:17:46 +10:00
smu.h powerpc/pmac: Remove early allocation of the SMU command buffer 2016-07-21 18:56:38 +10:00
sparsemem.h
spinlock.h powerpc/spinlock: Fix spin_unlock_wait() 2016-06-14 16:05:44 +10:00
spinlock_types.h
spu.h powerpc/cell: Move spu_handle_mm_fault() out of cell platform 2014-10-08 20:14:54 +11:00
spu_csa.h powerpc/cell: Drop support for 64K local store on 4K kernels 2015-08-18 19:29:49 +10:00
spu_info.h
spu_priv1.h
sstep.h powerpc: Emulate icbi, mcrf and conditional-trap instructions 2014-09-25 23:14:51 +10:00
string.h powerpc: Remove assembly versions of strcpy, strcat, strlen and strcmp 2016-06-14 13:58:25 +10:00
swab.h powerpc: Remove unused st_le*() and ld_le* functions 2015-03-24 13:33:52 +11:00
swiotlb.h
switch_to.h powerpc/ptrace: Fix coredump since ptrace TM changes 2016-08-10 16:34:20 +10:00
synch.h powerpc: Factor do_feature_fixup calls 2016-07-21 18:51:42 +10:00
syscall.h powerpc: Change syscall_get_nr() to return int 2015-07-29 11:56:13 +10:00
syscalls.h
systbl.h powerpc: wire up preadv2 and pwritev2 syscalls 2016-04-27 16:47:55 +10:00
tce.h powerpc/powernv/pci: Remove SWINV constants and obsolete TCE code 2016-07-17 16:42:47 +10:00
termios.h
thread_info.h signal: consolidate {TS,TLF}_RESTORE_SIGMASK code 2016-08-02 19:35:23 -04:00
time.h powerpc: Move cpu_has_feature() to a separate file 2016-08-01 11:15:03 +10:00
timex.h
tlb.h powerpc/mm: Drop multiple definition of mm_is_core_local 2016-08-01 11:15:10 +10:00
tlbflush.h powerpc/mm: remove flush_tlb_page_nohash 2016-08-01 11:15:13 +10:00
tm.h
topology.h sched/topology: Rename topology_thread_cpumask() to topology_sibling_cpumask() 2015-05-27 15:22:15 +02:00
trace.h powerpc/pseries: Don't trace hcalls on offline CPUs 2016-02-15 21:10:03 +11:00
trace_clock.h powerpc/ftrace: add powerpc timebase as a trace clock source 2015-08-06 16:36:23 +10:00
tsi108.h powerpc: Various typo fixes 2016-06-14 13:58:26 +10:00
tsi108_irq.h
tsi108_pci.h genirq: Remove irq argument from irq flow handlers 2015-09-16 15:47:51 +02:00
types.h powerpc: Define and use PPC64_ELF_ABI_v2/v1 2016-06-14 13:58:27 +10:00
uaccess.h powerpc/uaccess: Enable hardened usercopy 2016-07-26 14:41:51 -07:00
udbg.h powerpc: Remove stale function prototypes 2014-09-25 23:14:43 +10:00
uic.h
unaligned.h
uninorth.h powerpc: Fix misspellings in comments. 2016-03-01 19:27:20 +11:00
unistd.h powerpc: wire up preadv2 and pwritev2 syscalls 2016-04-27 16:47:55 +10:00
uprobes.h
user.h
vdso.h
vdso_datapage.h powerpc: Standardise on NR_syscalls rather than __NR_syscalls. 2015-11-26 22:11:17 +11:00
vga.h powerpc: Move Power Macintosh drivers to generic byteswappers 2015-03-23 14:29:40 +11:00
vio.h remove <asm/scatterlist.h> 2015-05-05 13:35:39 -06:00
word-at-a-time.h powerpc: Fix bad inline asm constraint in create_zero_mask() 2016-05-02 11:10:25 +10:00
xics.h powerpc/xics: Properly set Edge/Level type and enable resend 2016-08-09 14:50:18 +10:00
xilinx_intc.h
xilinx_pci.h
xmon.h
xor.h powerpc: Move cpu_has_feature() to a separate file 2016-08-01 11:15:03 +10:00