netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Bruce Allan <bruce.w.allan@intel.com>
Cc: kvm@vger.kernel.org, netdev@vger.kernel.org,
	intel-wired-lan@lists.osuosl.org
Subject: Re: [PATCH] vfio-pci: PCI_DEV_FLAGS_ASSIGNED flag not set when PCI device is assigned
Date: Tue, 12 May 2015 20:41:48 -0600	[thread overview]
Message-ID: <1431484908.3625.10.camel@redhat.com> (raw)
In-Reply-To: <20150513013550.10328.1416.stgit@bwallan-smackover2.jf.intel.com>

On Tue, 2015-05-12 at 18:35 -0700, Bruce Allan wrote:
> A number of PCI device drivers supporting SR-IOV use pci_vfs_assigned() to
> check if there are any VF devices assigned by a VMM prior to disabling
> SR-IOV (i.e. bnx2x, be2net, fm10k, i40e, igb, ixgbe, qlcnic).  This check
> works fine with the legacy device assignment (pci-stub enables the device)
> which calls pci_set_dev_assigned().  The newer VFIO-based assignment
> (vfio-pci enables device) doesn't call pci_set_dev_assigned() potentially
> leading to issues in those drivers when disabling SR-IOV with VFs assigned.
> 
> Add calls to pci_[set|clear]_dev_assigned() to set the flag as expected.
> 
> Signed-off-by: Bruce Allan <bruce.w.allan@intel.com>
> ---
>  drivers/vfio/pci/vfio_pci.c |    4 ++++
>  1 file changed, 4 insertions(+)


Why should a device exposed to the user be handled differently than a
device used by a host driver?  The reason the assigned flag exists is
because legacy KVM device assignment doesn't actually claim the device
using the driver model, it relies on pci-stub to act as a placeholder to
prevent other drivers from binding to the device, but pci-stub has no
visibility to the device usage and will immediately release it
regardless of it being in use.  vfio-pci participates in the driver
model, signals the user for the device to be released and blocks until
it is released.  Beyond that, the assigned flag is a racy hack.  There's
no locking whatsoever to imply that the flag as any meaning beyond the
instant that it's tested.  I'd like to see the assigned flag deprecated
along with legacy KVM device assignment, not perpetuated in newer
drivers.  The patch is also wrong because we can tell when the device is
actually opened by the user, not just bound to the vfio-pci driver.
Thanks,

Alex

> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 69fab0f..3f368ce 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -956,6 +956,8 @@ static int vfio_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
>  		return ret;
>  	}
>  
> +	pci_set_dev_assigned(pdev);
> +
>  	if (vfio_pci_is_vga(pdev)) {
>  		vga_client_register(pdev, vdev, NULL, vfio_pci_set_vga_decode);
>  		vga_set_legacy_decoding(pdev,
> @@ -990,6 +992,8 @@ static void vfio_pci_remove(struct pci_dev *pdev)
>  	iommu_group_put(pdev->dev.iommu_group);
>  	kfree(vdev);
>  
> +	pci_clear_dev_assigned(pdev);
> +
>  	if (vfio_pci_is_vga(pdev)) {
>  		vga_client_register(pdev, NULL, NULL, NULL);
>  		vga_set_legacy_decoding(pdev,
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2015-05-13  2:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-13  1:35 [PATCH] vfio-pci: PCI_DEV_FLAGS_ASSIGNED flag not set when PCI device is assigned Bruce Allan
2015-05-13  2:41 ` Alex Williamson [this message]
2015-05-13 17:50   ` Allan, Bruce W
2015-05-13 18:39     ` Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431484908.3625.10.camel@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=bruce.w.allan@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=kvm@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).