OSDN Git Service

PCI: Block on access to temporarily unavailable pci device
authorMatthew Wilcox <matthew@wil.cx>
Thu, 19 Oct 2006 15:41:28 +0000 (09:41 -0600)
committerGreg Kroah-Hartman <gregkh@suse.de>
Fri, 1 Dec 2006 22:36:58 +0000 (14:36 -0800)
commit7ea7e98fd8d02351c43ef4ab35d70f3aaa26c31d
treecb37b18402c2b82cc227ad6bd1ab3d57cf677ff3
parent50bf14b3ff05fb6e10688021b96f95d30a300f8d
PCI: Block on access to temporarily unavailable pci device

The existing implementation of pci_block_user_cfg_access() was recently
criticised for providing out of date information and for returning errors
on write, which applications won't be expecting.

This reimplementation uses a global wait queue and a bit per device.
I've open-coded prepare_to_wait() / finish_wait() as I could optimise
it significantly by knowing that the pci_lock protected us at all points.

It looked a bit funny to be doing a spin_unlock_irqsave(); schedule(),
so I used spin_lock_irq() for the _user versions of pci_read_config and
pci_write_config.  Not carrying a flags pointer around made the code
much less nasty.

Attempts to block an already blocked device hit a BUG() and attempts to
unblock an already unblocked device hit a WARN().  If we need to block
access to a device from userspace, it's because it's unsafe for even
another bit of the kernel to access the device.  An attempt to block
a device for a second time means we're about to access the device to
perform some other operation, which could provoke undefined behaviour
from the device.

Signed-off-by: Matthew Wilcox <matthew@wil.cx>
Acked-by: Adam Belay <abelay@novell.com>
Acked-by: Alan Cox <alan@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/pci/access.c