From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Williamson Subject: Re: [PATCH 2/3] vfio: vfio-pci device assignment driver Date: Tue, 14 Aug 2012 07:51:39 -0600 Message-ID: <1344952299.4683.239.camel@ul30vt.home> References: <20120801050241.22163.78549.stgit@bling.home> <20120801051814.22163.66621.stgit@bling.home> <20120814071207.GA14056@stefanha-thinkpad.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Cc: aik@ozlabs.ru, aliguori@us.ibm.com, qemu-devel@nongnu.org, kvm@vger.kernel.org To: Stefan Hajnoczi Return-path: In-Reply-To: <20120814071207.GA14056@stefanha-thinkpad.localdomain> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org Sender: qemu-devel-bounces+gceq-qemu-devel=gmane.org@nongnu.org List-Id: kvm.vger.kernel.org On Tue, 2012-08-14 at 08:12 +0100, Stefan Hajnoczi wrote: > On Tue, Jul 31, 2012 at 11:18:15PM -0600, Alex Williamson wrote: > > This adds the core of the QEMU VFIO-based PCI device assignment driver. > > To make use of this driver, enable CONFIG_VFIO, CONFIG_VFIO_IOMMU_TYPE1, > > and CONFIG_VFIO_PCI in your host Linux kernel config. Load the vfio-pci > > module. To assign device 0000:05:00.0 to a guest, do the following: > > > > for dev in $(ls /sys/bus/pci/devices/0000:05:00.0/iommu_group/devices); do > > vendor=$(cat /sys/bus/pci/devices/$dev/vendor) > > device=$(cat /sys/bus/pci/devices/$dev/device) > > if [ -e /sys/bus/pci/devices/$dev/driver ]; then > > echo $dev > /sys/bus/pci/devices/$dev/driver/unbind > > fi > > echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id > > done > > Both vfio-pci and the old driver successfully match the $vendor:$device. > What happens when another $vendor:$device PCI adapter is hotplugged into > the host? > > Is there a way to bind vfio-pci on a per-adapter basis instead of a > per-$vendor:$device? There's also a remove_id sysfs entry so we can be a little more strategic, this was just an example. We can also re-order new_id vs unbind so that we need to manually unbind->bind the device. There's still an opportunity to race with a hotplug during this interaction though. I think this is the best Linux currently offers for dynamic driver binding though. Thanks, Alex From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:50080) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1HX8-0007Tw-JL for qemu-devel@nongnu.org; Tue, 14 Aug 2012 09:51:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T1HX6-0006SR-Dd for qemu-devel@nongnu.org; Tue, 14 Aug 2012 09:51:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T1HX6-0006SK-5Q for qemu-devel@nongnu.org; Tue, 14 Aug 2012 09:51:44 -0400 Message-ID: <1344952299.4683.239.camel@ul30vt.home> From: Alex Williamson Date: Tue, 14 Aug 2012 07:51:39 -0600 In-Reply-To: <20120814071207.GA14056@stefanha-thinkpad.localdomain> References: <20120801050241.22163.78549.stgit@bling.home> <20120801051814.22163.66621.stgit@bling.home> <20120814071207.GA14056@stefanha-thinkpad.localdomain> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/3] vfio: vfio-pci device assignment driver List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: aik@ozlabs.ru, aliguori@us.ibm.com, qemu-devel@nongnu.org, kvm@vger.kernel.org On Tue, 2012-08-14 at 08:12 +0100, Stefan Hajnoczi wrote: > On Tue, Jul 31, 2012 at 11:18:15PM -0600, Alex Williamson wrote: > > This adds the core of the QEMU VFIO-based PCI device assignment driver. > > To make use of this driver, enable CONFIG_VFIO, CONFIG_VFIO_IOMMU_TYPE1, > > and CONFIG_VFIO_PCI in your host Linux kernel config. Load the vfio-pci > > module. To assign device 0000:05:00.0 to a guest, do the following: > > > > for dev in $(ls /sys/bus/pci/devices/0000:05:00.0/iommu_group/devices); do > > vendor=$(cat /sys/bus/pci/devices/$dev/vendor) > > device=$(cat /sys/bus/pci/devices/$dev/device) > > if [ -e /sys/bus/pci/devices/$dev/driver ]; then > > echo $dev > /sys/bus/pci/devices/$dev/driver/unbind > > fi > > echo $vendor $device > /sys/bus/pci/drivers/vfio-pci/new_id > > done > > Both vfio-pci and the old driver successfully match the $vendor:$device. > What happens when another $vendor:$device PCI adapter is hotplugged into > the host? > > Is there a way to bind vfio-pci on a per-adapter basis instead of a > per-$vendor:$device? There's also a remove_id sysfs entry so we can be a little more strategic, this was just an example. We can also re-order new_id vs unbind so that we need to manually unbind->bind the device. There's still an opportunity to race with a hotplug during this interaction though. I think this is the best Linux currently offers for dynamic driver binding though. Thanks, Alex