All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Jason Gunthorpe <jgg@nvidia.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 12:25:44 -0600	[thread overview]
Message-ID: <20220412122544.4a56f20a.alex.williamson@redhat.com> (raw)
In-Reply-To: <0-v2-fe53fe3adce2+265-vfio_vf_token_jgg@nvidia.com>

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,

Alex


  reply	other threads:[~2022-04-12 18:25 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 [this message]
2022-04-12 19:52   ` Jason Gunthorpe
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=20220412122544.4a56f20a.alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=jgg@nvidia.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.