From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: Re: binding/unbinding devices to vfio-pci Date: Tue, 02 Jul 2013 08:46:05 -0600 Message-ID: <1372776365.30572.874.camel@ul30vt.home> References: <9F6FE96B71CF29479FF1CDC8046E1503632FA9@039-SN1MPN1-004.039d.mgd.msft.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: "a.motakis@virtualopensystems.com" , "virtualization@lists.linux-foundation.org" , "kvm@vger.kernel.org list" , Bhushan Bharat-R65777 To: Yoder Stuart-B08248 Return-path: In-Reply-To: <9F6FE96B71CF29479FF1CDC8046E1503632FA9@039-SN1MPN1-004.039d.mgd.msft.net> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: virtualization-bounces@lists.linux-foundation.org Errors-To: virtualization-bounces@lists.linux-foundation.org List-Id: kvm.vger.kernel.org On Tue, 2013-07-02 at 14:15 +0000, Yoder Stuart-B08248 wrote: > Alex, > > I'm trying to think through how binding/unbinding of devices will > work with VFIO for platform devices and have a couple of questions > about how vfio-pci works. > > When you bind a device to vfio-pci, e.g.: > # echo 1102 0002 > /sys/bus/pci/drivers/vfio-pci/new_id > > ...I understand that the echo into 'new_id' tells the > vfio pci driver that it now handles the specified PCI ID. > > But now there are 2 drivers that handle that PCI ID, > the original host driver and vfio-pci. Say that > you hotplug a PCI device that matches that ID. Which of > the 2 drivers are going to get bound to the device? > > Also, if you unbind a device from vfio-pci and want to > bind it again to the normal host driver you would just > echo the full device info into the 'bind' sysfs file > for the host driver, right? > > echo 0000:06:0d.0 > /sys/bus/pci/drivers/... Hi Stuart, The driver binding interface is far from perfect. In your scenario where you've added the ID for one device, then hotplug another device with the same ID, the results are indeterminate. Both vfio-pci and the host driver, assuming it's still loaded, can claim the device, it's just a matter of which gets probed first. Generally that window should be very short though. To bind a device, the user should do: 1) echo ssss:bb:dd.f > /sys/bus/pci/devices/ssss:bb:dd.f/driver/unbind 2) echo vvvv dddd > /sys/bus/pci/drivers/vfio-pci/new_id 3) echo ssss:bb:dd.f > /sys/bus/pci/drivers/vfio-pci/bind 4) echo vvvv dddd > /sys/bus/pci/drivers/vfio-pci/remove_id There are actually a number of ways you can do this and the default autoprobe behavior really makes step 3) unnecessary as the driver core will probe any unbound devices as soon as a new_id is added to vfio-pci. That can be changed by: # echo 0 > /sys/bus/pci/drivers_autoprobe But then we have to worry about races from any devices that might have been hotplugged in the interim. To unbind: 1) echo ssss:bb:dd.f > /sys/bus/pci/drivers/vfio-pci/unbind 2) echo ssss:bb:dd.f > /sys/bus/pci/drivers_probe So we don't have to manually remember or hunt down the host driver for the device. Thanks, Alex