All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Cornelia Huck <cohuck@redhat.com>,
	kvm@vger.kernel.org, Max Gurtovoy <mgurtovoy@nvidia.com>,
	Yishai Hadas <yishaih@nvidia.com>
Subject: Re: [PATCH v2] vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used
Date: Tue, 12 Apr 2022 16:52:44 -0300	[thread overview]
Message-ID: <20220412195244.GK2120790@nvidia.com> (raw)
In-Reply-To: <20220412122544.4a56f20a.alex.williamson@redhat.com>

On Tue, Apr 12, 2022 at 12:25:44PM -0600, Alex Williamson wrote:
> On Mon, 11 Apr 2022 10:56:31 -0300
> Jason Gunthorpe <jgg@nvidia.com> wrote:
> 
> > @@ -1732,10 +1705,28 @@ static int vfio_pci_bus_notifier(struct notifier_block *nb,
> >  static int vfio_pci_vf_init(struct vfio_pci_core_device *vdev)
> >  {
> >  	struct pci_dev *pdev = vdev->pdev;
> > +	struct vfio_pci_core_device *cur;
> > +	struct pci_dev *physfn;
> >  	int ret;
> >  
> > -	if (!pdev->is_physfn)
> > +	if (!pdev->is_physfn) {
> > +		/*
> > +		 * If this VF was created by our vfio_pci_core_sriov_configure()
> > +		 * then we can find the PF vfio_pci_core_device now, and due to
> > +		 * the locking in pci_disable_sriov() it cannot change until
> > +		 * this VF device driver is removed.
> > +		 */
> > +		physfn = pci_physfn(vdev->pdev);
> > +		mutex_lock(&vfio_pci_sriov_pfs_mutex);
> > +		list_for_each_entry (cur, &vfio_pci_sriov_pfs, sriov_pfs_item) {
> > +			if (cur->pdev == physfn) {
> > +				vdev->sriov_pf_core_dev = cur;
> > +				break;
> > +			}
> > +		}
> > +		mutex_unlock(&vfio_pci_sriov_pfs_mutex);
> >  		return 0;
> > +	}
> >  
> >  	vdev->vf_token = kzalloc(sizeof(*vdev->vf_token), GFP_KERNEL);
> >  	if (!vdev->vf_token)
> 
> One more comment on final review; are we equating !is_physfn to
> is_virtfn above?  This branch was originally meant to kick out both VFs
> and non-SRIOV PFs.  Calling pci_physfn() on a !is_virtfn device will
> return itself, so we should never find a list match, but we also don't
> need to look for a match for !is_virtfn, so it's a bit confusing and
> slightly inefficient.  Should the new code be added in a separate
> is_virtfn branch above the existing !is_physfn test?  Thanks,

I started at it for a while and came the same conclusion, I
misunderstood that is_physfn is really trying to be
is_sriov_physfn.. So not a bug, but not really clear code.

I added this, I'll repost it.

diff --git a/drivers/vfio/pci/vfio_pci_core.c b/drivers/vfio/pci/vfio_pci_core.c
index 8bf0f18e668a32..3c6493957abe19 100644
--- a/drivers/vfio/pci/vfio_pci_core.c
+++ b/drivers/vfio/pci/vfio_pci_core.c
@@ -1709,7 +1709,7 @@ static int vfio_pci_vf_init(struct vfio_pci_core_device *vdev)
 	struct pci_dev *physfn;
 	int ret;
 
-	if (!pdev->is_physfn) {
+	if (pdev->is_virtfn) {
 		/*
 		 * If this VF was created by our vfio_pci_core_sriov_configure()
 		 * then we can find the PF vfio_pci_core_device now, and due to
@@ -1728,6 +1728,10 @@ static int vfio_pci_vf_init(struct vfio_pci_core_device *vdev)
 		return 0;
 	}
 
+	/* Not a SRIOV PF */
+	if (!pdev->is_physfn)
+		return 0;
+
 	vdev->vf_token = kzalloc(sizeof(*vdev->vf_token), GFP_KERNEL);
 	if (!vdev->vf_token)
 		return -ENOMEM;


Thanks,
Jason

  reply	other threads:[~2022-04-12 19:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 13:56 [PATCH v2] vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used Jason Gunthorpe
2022-04-12 18:25 ` Alex Williamson
2022-04-12 19:52   ` Jason Gunthorpe [this message]
2022-04-12 20:13     ` 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=20220412195244.GK2120790@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mgurtovoy@nvidia.com \
    --cc=yishaih@nvidia.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.