android_kernel_samsung_msm8976/arch/powerpc/sysdev
Paul Mackerras 892e053cd7 powerpc/MSI: Fix race condition in tearing down MSI interrupts
commit e297c939b745e420ef0b9dc989cb87bda617b399 upstream.

This fixes a race which can result in the same virtual IRQ number
being assigned to two different MSI interrupts.  The most visible
consequence of that is usually a warning and stack trace from the
sysfs code about an attempt to create a duplicate entry in sysfs.

The race happens when one CPU (say CPU 0) is disposing of an MSI
while another CPU (say CPU 1) is setting up an MSI.  CPU 0 calls
(for example) pnv_teardown_msi_irqs(), which calls
msi_bitmap_free_hwirqs() to indicate that the MSI (i.e. its
hardware IRQ number) is no longer in use.  Then, before CPU 0 gets
to calling irq_dispose_mapping() to free up the virtal IRQ number,
CPU 1 comes in and calls msi_bitmap_alloc_hwirqs() to allocate an
MSI, and gets the same hardware IRQ number that CPU 0 just freed.
CPU 1 then calls irq_create_mapping() to get a virtual IRQ number,
which sees that there is currently a mapping for that hardware IRQ
number and returns the corresponding virtual IRQ number (which is
the same virtual IRQ number that CPU 0 was using).  CPU 0 then
calls irq_dispose_mapping() and frees that virtual IRQ number.
Now, if another CPU comes along and calls irq_create_mapping(), it
is likely to get the virtual IRQ number that was just freed,
resulting in the same virtual IRQ number apparently being used for
two different hardware interrupts.

To fix this race, we just move the call to msi_bitmap_free_hwirqs()
to after the call to irq_dispose_mapping().  Since virq_to_hw()
doesn't work for the virtual IRQ number after irq_dispose_mapping()
has been called, we need to call it before irq_dispose_mapping() and
remember the result for the msi_bitmap_free_hwirqs() call.

The pattern of calling msi_bitmap_free_hwirqs() before
irq_dispose_mapping() appears in 5 places under arch/powerpc, and
appears to have originated in commit 05af7bd2d7 ("[POWERPC] MPIC
U3/U4 MSI backend") from 2007.

Fixes: 05af7bd2d7 ("[POWERPC] MPIC U3/U4 MSI backend")
Reported-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2015-10-22 14:37:52 -07:00
..
ge
qe_lib powerpc/qe: Fix Kconfig enablement of QE_USB support 2013-03-15 11:14:15 -05:00
xics powerpc: Fix irq_set_affinity() return values 2013-05-14 16:00:18 +10:00
6xx-suspend.S
axonram.c axonram: Fix bug in direct_access 2015-03-06 14:40:50 -08:00
cpm1.c
cpm2.c
cpm2_pic.c
cpm2_pic.h
cpm_common.c
dart.h
dart_iommu.c
dcr-low.S
dcr.c
ehv_pic.c powerpc: Fix irq_set_affinity() return values 2013-05-14 16:00:18 +10:00
fsl_85xx_cache_ctlr.h
fsl_85xx_cache_sram.c
fsl_85xx_l2ctlr.c powerpc/85xx: l2sram - Add compatible string for BSC9131 platform 2013-02-19 11:01:54 -06:00
fsl_gtm.c
fsl_ifc.c
fsl_lbc.c
fsl_mpic_err.c
fsl_msi.c powerpc/MSI: Fix race condition in tearing down MSI interrupts 2015-10-22 14:37:52 -07:00
fsl_msi.h
fsl_pci.c powerpc/pci: Fix boot panic on mpc83xx (regression) 2013-06-24 16:54:09 -05:00
fsl_pci.h powerpc/85xx: Add platform_device declaration to fsl_pci.h 2013-03-15 11:12:46 -05:00
fsl_pmc.c
fsl_rio.c
fsl_rio.h
fsl_rmu.c
fsl_soc.c
fsl_soc.h
grackle.c
i8259.c
indirect_pci.c powerpc/fsl-pci Make PCIe hotplug work with Freescale PCIe controllers 2013-04-10 10:15:28 -05:00
ipic.c
ipic.h
Kconfig powerpc/powernv: Add option CONFIG_POWERNV_MSI 2013-04-26 16:09:58 +10:00
Makefile powerpc: Add an in memory udbg console 2013-05-08 06:36:49 +10:00
micropatch.c
mmio_nvram.c
mpc5xxx_clocks.c
mpc8xx_pic.c
mpc8xx_pic.h
mpic.c powerpc/mpic: Fix irq distribution problem when MPIC_SINGLE_DEST_CPU 2013-06-01 08:29:24 +10:00
mpic.h
mpic_msgr.c
mpic_msi.c
mpic_pasemi_msi.c powerpc/MSI: Fix race condition in tearing down MSI interrupts 2015-10-22 14:37:52 -07:00
mpic_u3msi.c powerpc/MSI: Fix race condition in tearing down MSI interrupts 2015-10-22 14:37:52 -07:00
msi_bitmap.c
mv64x60.h
mv64x60_dev.c mv643xx_eth: convert to use the Marvell Orion MDIO driver 2013-03-22 10:25:15 -04:00
mv64x60_pci.c
mv64x60_pic.c
mv64x60_udbg.c
of_rtc.c
pmi.c
ppc4xx_cpm.c
ppc4xx_gpio.c
ppc4xx_msi.c powerpc/MSI: Fix race condition in tearing down MSI interrupts 2015-10-22 14:37:52 -07:00
ppc4xx_ocm.c
ppc4xx_pci.c powerpc/pci: Support per-aperture memory offset 2013-05-06 13:40:40 +10:00
ppc4xx_pci.h
ppc4xx_soc.c
rtc_cmos_setup.c powerpc: Use PTR_RET instead of IS_ERR/PTR_ERR 2013-04-18 13:03:48 +10:00
scom.c
simple_gpio.c
simple_gpio.h
tsi108_dev.c
tsi108_pci.c
udbg_memcons.c powerpc: Add an in memory udbg console 2013-05-08 06:36:49 +10:00
uic.c
xilinx_intc.c
xilinx_pci.c