linux/drivers
David Vrabel 3d63d1e0fe xen/evtchn: avoid a deadlock when unbinding an event channel
commit 179fbd5a45 upstream.

Unbinding an event channel (either with the ioctl or when the evtchn
device is closed) may deadlock because disable_irq() is called with
port_user_lock held which is also locked by the interrupt handler.

Think of the IOCTL_EVTCHN_UNBIND is being serviced, the routine has
just taken the lock, and an interrupt happens. The evtchn_interrupt
is invoked, tries to take the lock and spins forever.

A quick glance at the code shows that the spinlock is a local IRQ
variant. Unfortunately that does not help as "disable_irq() waits for
the interrupt handler on all CPUs to stop running.  If the irq occurs
on another VCPU, it tries to take port_user_lock and can't because
the unbind ioctl is holding it." (from David). Hence we cannot
depend on the said spinlock to protect us. We could make it a system
wide IRQ disable spinlock but there is a better way.

We can piggyback on the fact that the existence of the spinlock is
to make get_port_user() checks be up-to-date. And we can alter those
checks to not depend on the spin lock (as it's protected by u->bind_mutex
in the ioctl) and can remove the unnecessary locking (this is
IOCTL_EVTCHN_UNBIND) path.

In the interrupt handler we cannot use the mutex, but we do not
need it.

"The unbind disables the irq before making the port user stale, so when
you clear it you are guaranteed that the interrupt handler that might
use that port cannot be running." (from David).

Hence this patch removes the spinlock usage on the teardown path
and piggybacks on disable_irq happening before we muck with the
get_port_user() data. This ensures that the interrupt handler will
never run on stale data.

Signed-off-by: David Vrabel <david.vrabel@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
[v1: Expanded the commit description a bit]
Signed-off-by: Jonghwan Choi <jhbird.choi@samsung.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-08-04 16:51:15 +08:00
..
accessibility
acpi ACPI / video: ignore BIOS initial backlight value for Fujitsu E753 2013-08-04 16:51:02 +08:00
amba
ata libata: make it clear that sata_inic162x is experimental 2013-08-04 16:50:55 +08:00
atm
auxdisplay
base regmap: cache: bail in regmap_async_complete() for bus-less maps 2013-08-04 16:50:58 +08:00
bcma bcma: add more core IDs 2013-05-17 14:31:05 -04:00
block xen/blkback: Check device permissions before allowing OP_DISCARD 2013-08-04 16:50:53 +08:00
bluetooth Bluetooth: btmrvl: fix thread stopping race 2013-06-13 13:05:40 -04:00
bus
cdrom drivers/cdrom/cdrom.c: use kzalloc() for failing hardware 2013-07-13 11:42:26 -07:00
char random: fix accounting race condition with lockless irq entropy_count update 2013-05-24 16:22:52 -07:00
clk ARM: tegra30: clocks: Fix pciex clock registration 2013-06-16 11:25:45 -07:00
clocksource clocksource: dw_apb: Fix error check 2013-07-25 14:07:29 -07:00
connector
cpufreq cpufreq / intel_pstate: Change to scale off of max P-state 2013-08-04 16:50:51 +08:00
cpuidle
crypto crypto: caam - Fixed the memory out of bound overwrite issue 2013-08-04 16:50:57 +08:00
dca
devfreq
dio
dma drivers/dma/pl330.c: fix locking in pl330_free_chan_resources() 2013-07-21 18:21:35 -07:00
edac EDAC: Fix lockdep splat 2013-07-28 16:30:11 -07:00
eisa
extcon
firewire firewire: fix libdc1394/FlyCap2 iso event regression 2013-08-04 16:50:38 +08:00
firmware
gpio gpio/omap: don't use linear domain mapping for OMAP1 2013-06-25 23:13:40 -07:00
gpu drm/radeon/atom: initialize more atom interpretor elements to 0 2013-08-04 16:51:14 +08:00
hid HID: apple: Add support for the 2013 Macbook Air 2013-07-21 18:21:29 -07:00
hsi
hv Drivers: hv: balloon: Do not post pressure status if interrupted 2013-08-04 16:50:58 +08:00
hwmon hwmon: (nct6775) Drop unsupported fan alarm attributes for NCT6775 2013-07-25 14:07:27 -07:00
hwspinlock
i2c i2c-piix4: Add AMD CZ SMBus device ID 2013-07-25 14:07:28 -07:00
ide
idle
iio iio: inkern: fix iio_convert_raw_to_processed_unlocked 2013-07-25 14:07:23 -07:00
infiniband iscsi-target: Fix ISCSI_OP_SCSI_TMFUNC handling for iser 2013-08-04 16:50:34 +08:00
input Input: bcm5974 - add support for the 2013 MacBook Air 2013-07-21 18:21:29 -07:00
iommu iommu/amd: Only unmap large pages from the first pte 2013-07-25 14:07:42 -07:00
ipack
irqchip ARM: SoC fixes for 3.10-rc 2013-06-22 09:44:45 -10:00
isdn isdn/kcapi: fix a small underflow 2013-05-20 13:38:14 -07:00
leds drivers/leds/leds-ot200.c: fix error caused by shifted mask 2013-05-24 16:22:51 -07:00
lguest
macintosh
mailbox
md dm verity: fix inability to use a few specific devices sizes 2013-08-04 16:51:02 +08:00
media media: dmxdev: remove dvb_ringbuffer_flush() on writer side 2013-07-28 16:30:21 -07:00
memory drivers/memory: don't check resource with devm_ioremap_resource 2013-05-18 11:55:52 +02:00
memstick
message
mfd mfd: tps6586x: correct device name of the regulator cell 2013-06-24 12:37:47 +01:00
misc Char / Misc fixes for 3.10-rc6 2013-06-14 19:15:36 -10:00
mmc mmc: omap_hsmmc: Skip platform_get_resource_byname() for dt case 2013-05-26 14:23:11 -04:00
mtd drivers/mtd/nand: don't check resource with devm_ioremap_resource 2013-05-18 11:55:55 +02:00
net rtlwifi: Initialize power-setting callback for USB devices 2013-08-04 16:51:14 +08:00
nfc NFC: mei: Do not disable MEI devices from their remove routine 2013-05-21 10:48:41 +02:00
ntb
nubus
of of: Fix address decoding on Bimini and js2x machines 2013-07-25 14:07:32 -07:00
oprofile
parisc parisc: fix LMMIO mismatch between PAT length and MASK register 2013-07-21 18:21:26 -07:00
parport parisc: parport0: fix this legacy no-device port driver! 2013-06-01 14:46:42 +02:00
pci ahci: Add AMD CZ SATA device ID 2013-07-21 18:21:30 -07:00
pcmcia pcmcia: at91_cf: fix gpio_get_value in at91_cf_get_status 2013-07-21 18:21:25 -07:00
pinctrl Renesas ARM based SoC fixes for v3.10 2013-06-07 18:11:02 -07:00
platform x86 / platform / hp_wmi: Fix bluetooth_rfkill misuse in hp_wmi_rfkill_setup() 2013-06-01 23:51:48 +02:00
pnp
power charger-manager: Ensure event is not used as format string 2013-07-13 11:42:26 -07:00
pps
ps3
ptp ptp_pch: fix error handling in pch_probe() 2013-05-25 21:24:15 -07:00
pwm drivers/pwm: don't check resource with devm_ioremap_resource 2013-05-18 11:55:58 +02:00
rapidio RAPIDIO: IDT_GEN2: Fix build error. 2013-07-28 16:30:07 -07:00
regulator mfd: tps6586x: correct device name of the regulator cell 2013-06-24 12:37:47 +01:00
remoteproc
reset
rpmsg
rtc drivers/rtc/rtc-rv3029c2.c: fix disabling AIE irq 2013-07-21 18:21:28 -07:00
s390 SCSI: zfcp: status read buffers on first adapter open with link down 2013-07-25 14:07:30 -07:00
sbus
scsi SCSI: qla2xxx: Properly set the tagging for commands. 2013-08-04 16:50:41 +08:00
sfi
sh
sn
spi Merge remote-tracking branch 'spi/fix/s3c64xx' into spi-linus 2013-06-24 12:28:29 +01:00
ssb
ssbi
staging staging: android: logger: Correct write offset reset on error 2013-08-04 16:50:51 +08:00
target iscsi-target: Fix ISCSI_OP_SCSI_TMFUNC handling for iser 2013-08-04 16:50:34 +08:00
tc
thermal drivers/thermal: don't check resource with devm_ioremap_resource 2013-05-18 11:57:30 +02:00
tty tty_port: Fix refcounting leak in tty_port_tty_hangup() 2013-08-04 16:51:14 +08:00
uio uio: UIO_DMEM_GENIRQ should depend on HAS_DMA 2013-05-21 10:13:23 -07:00
usb usb: gadget: udc-core: fix the typo of udc state attribute 2013-08-04 16:51:14 +08:00
uwb
vfio vfio: fix crash on rmmod 2013-06-05 08:54:16 -06:00
vhost vhost-net: fix use-after-free in vhost_net_flush 2013-07-28 16:29:57 -07:00
video atmel_lcdfb: blank the backlight on remove 2013-06-01 03:18:55 +08:00
virt
virtio virtio: support unlocked queue poll 2013-07-28 16:29:55 -07:00
vlynq
vme
w1 drivers/w1/masters: don't check resource with devm_ioremap_resource 2013-05-18 11:58:03 +02:00
watchdog drivers/watchdog: don't check resource with devm_ioremap_resource 2013-05-18 11:58:04 +02:00
xen xen/evtchn: avoid a deadlock when unbinding an event channel 2013-08-04 16:51:15 +08:00
zorro
Kconfig
Makefile