From: Amit Shah Subject: Re: [PATCH 2/4] KVM: pci device assignment Date: Mon, 28 Jul 2008 14:03:24 +0530 Message-ID: <200807281403.25093.amit.shah@qumranet.com> References: <1216728835-19721-1-git-send-email-benami@il.ibm.com> <1216728835-19721-2-git-send-email-benami@il.ibm.com> <1216728835-19721-3-git-send-email-benami@il.ibm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Cc: avi@qumranet.com, kvm@vger.kernel.org, muli@il.ibm.com, weidong.han@intel.com, anthony@codemonkey.ws To: Ben-Ami Yassour Return-path: Received: from mis011-1.exch011.intermedia.net ([64.78.21.128]:58578 "EHLO mis011-1.exch011.intermedia.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750736AbYG1IeK (ORCPT ); Mon, 28 Jul 2008 04:34:10 -0400 In-Reply-To: <1216728835-19721-3-git-send-email-benami@il.ibm.com> Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: * On Tuesday 22 Jul 2008 17:43:53 Ben-Ami Yassour wrote: > Based on a patch from: Amit Shah > > This patch adds support for handling PCI devices that are assigned to > the guest. > > The device to be assigned to the guest is registered in the host kernel > and interrupt delivery is handled. If a device is already assigned, or > the device driver for it is still loaded on the host, the device > assignment > is failed by conveying a -EBUSY reply to the userspace. > > Devices that share their interrupt line are not supported at the moment. > > By itself, this patch will not make devices work within the guest. > The VT-d extension is required to enable the device to perform DMA. > Another alternative is PVDMA. > > Signed-off-by: Amit Shah > Signed-off-by: Ben-Ami Yassour > Signed-off-by: Weidong Han > + if (pci_enable_device(dev)) { > + printk(KERN_INFO "%s: Could not enable PCI device\n", __func__); > + r = -EBUSY; > + goto out_put; > + } > + r = pci_request_regions(dev, "kvm_assigned_device"); > + if (r) { > + printk(KERN_INFO "%s: Could not get access to device regions\n", > + __func__); > + goto out_disable; > + } A driver might already be loaded for this device. If we fail to get the regions, it might mean the device was enabled and in use. That's the reason I didn't originally have a pci_disable_device() when pci_request_regions fails. > +out: > + mutex_unlock(&kvm->lock); > + return r; > +out_list_del: > + list_del(&match->list); > + pci_release_regions(dev); > +out_disable: > + pci_disable_device(dev); > +out_put: > + pci_dev_put(dev); > +out_free: > + kfree(match); > + mutex_unlock(&kvm->lock); > + return r;