kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Liu Yi L <yi.l.liu@intel.com>
Cc: kwankhede@nvidia.com, linux-kernel@vger.kernel.org,
	kvm@vger.kernel.org, kevin.tian@intel.com, joro@8bytes.org,
	peterx@redhat.com, baolu.lu@linux.intel.com
Subject: Re: [PATCH v4 03/12] vfio_pci: refine vfio_pci_driver reference in vfio_pci.c
Date: Thu, 9 Jan 2020 15:48:19 -0700	[thread overview]
Message-ID: <20200109154819.455f11d3@w520.home> (raw)
In-Reply-To: <1578398509-26453-4-git-send-email-yi.l.liu@intel.com>

On Tue,  7 Jan 2020 20:01:40 +0800
Liu Yi L <yi.l.liu@intel.com> wrote:

> This patch replaces the vfio_pci_driver reference in vfio_pci.c with
> pci_dev_driver(vdev->pdev) which is more helpful to make the functions
> be generic to module types.
> 
> Cc: Kevin Tian <kevin.tian@intel.com>
> Cc: Lu Baolu <baolu.lu@linux.intel.com>
> Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
> ---
>  drivers/vfio/pci/vfio_pci.c | 34 ++++++++++++++++++----------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index 009d2df..9140f5e5 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -1463,24 +1463,25 @@ static void vfio_pci_reflck_get(struct vfio_pci_reflck *reflck)
>  
>  static int vfio_pci_reflck_find(struct pci_dev *pdev, void *data)
>  {
> -	struct vfio_pci_reflck **preflck = data;
> +	struct vfio_pci_device *vdev = data;
> +	struct vfio_pci_reflck **preflck = &vdev->reflck;
>  	struct vfio_device *device;
> -	struct vfio_pci_device *vdev;
> +	struct vfio_pci_device *tmp;
>  
>  	device = vfio_device_get_from_dev(&pdev->dev);
>  	if (!device)
>  		return 0;
>  
> -	if (pci_dev_driver(pdev) != &vfio_pci_driver) {
> +	if (pci_dev_driver(pdev) != pci_dev_driver(vdev->pdev)) {
>  		vfio_device_put(device);
>  		return 0;
>  	}
>  
> -	vdev = vfio_device_data(device);
> +	tmp = vfio_device_data(device);
>  
> -	if (vdev->reflck) {
> -		vfio_pci_reflck_get(vdev->reflck);
> -		*preflck = vdev->reflck;
> +	if (tmp->reflck) {
> +		vfio_pci_reflck_get(tmp->reflck);
> +		*preflck = tmp->reflck;

Seems we can do away with preflck entirely with this refactor, this
simply becomes vdev->reflck = tmp->reflck.  Thanks,

Alex

>  		vfio_device_put(device);
>  		return 1;
>  	}
> @@ -1497,7 +1498,7 @@ static int vfio_pci_reflck_attach(struct vfio_pci_device *vdev)
>  
>  	if (pci_is_root_bus(vdev->pdev->bus) ||
>  	    vfio_pci_for_each_slot_or_bus(vdev->pdev, vfio_pci_reflck_find,
> -					  &vdev->reflck, slot) <= 0)
> +					  vdev, slot) <= 0)
>  		vdev->reflck = vfio_pci_reflck_alloc();
>  
>  	mutex_unlock(&reflck_lock);
> @@ -1522,6 +1523,7 @@ static void vfio_pci_reflck_put(struct vfio_pci_reflck *reflck)
>  
>  struct vfio_devices {
>  	struct vfio_device **devices;
> +	struct vfio_pci_device *vdev;
>  	int cur_index;
>  	int max_index;
>  };
> @@ -1530,7 +1532,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data)
>  {
>  	struct vfio_devices *devs = data;
>  	struct vfio_device *device;
> -	struct vfio_pci_device *vdev;
> +	struct vfio_pci_device *tmp;
>  
>  	if (devs->cur_index == devs->max_index)
>  		return -ENOSPC;
> @@ -1539,15 +1541,15 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data)
>  	if (!device)
>  		return -EINVAL;
>  
> -	if (pci_dev_driver(pdev) != &vfio_pci_driver) {
> +	if (pci_dev_driver(pdev) != pci_dev_driver(devs->vdev->pdev)) {
>  		vfio_device_put(device);
>  		return -EBUSY;
>  	}
>  
> -	vdev = vfio_device_data(device);
> +	tmp = vfio_device_data(device);
>  
>  	/* Fault if the device is not unused */
> -	if (vdev->refcnt) {
> +	if (tmp->refcnt) {
>  		vfio_device_put(device);
>  		return -EBUSY;
>  	}
> @@ -1574,7 +1576,7 @@ static int vfio_pci_get_unused_devs(struct pci_dev *pdev, void *data)
>   */
>  static void vfio_pci_try_bus_reset(struct vfio_pci_device *vdev)
>  {
> -	struct vfio_devices devs = { .cur_index = 0 };
> +	struct vfio_devices devs = { .vdev = vdev, .cur_index = 0 };
>  	int i = 0, ret = -EINVAL;
>  	bool slot = false;
>  	struct vfio_pci_device *tmp;
> @@ -1637,7 +1639,7 @@ static void __exit vfio_pci_cleanup(void)
>  	vfio_pci_uninit_perm_bits();
>  }
>  
> -static void __init vfio_pci_fill_ids(char *ids)
> +static void __init vfio_pci_fill_ids(char *ids, struct pci_driver *driver)
>  {
>  	char *p, *id;
>  	int rc;
> @@ -1665,7 +1667,7 @@ static void __init vfio_pci_fill_ids(char *ids)
>  			continue;
>  		}
>  
> -		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
> +		rc = pci_add_dynid(driver, vendor, device,
>  				   subvendor, subdevice, class, class_mask, 0);
>  		if (rc)
>  			pr_warn("failed to add dynamic id [%04x:%04x[%04x:%04x]] class %#08x/%08x (%d)\n",
> @@ -1692,7 +1694,7 @@ static int __init vfio_pci_init(void)
>  	if (ret)
>  		goto out_driver;
>  
> -	vfio_pci_fill_ids(ids);
> +	vfio_pci_fill_ids(ids, &vfio_pci_driver);
>  
>  	return 0;
>  


  reply	other threads:[~2020-01-09 22:48 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-07 12:01 [PATCH v4 00/12] vfio_pci: wrap pci device as a mediated device Liu Yi L
2020-01-07 12:01 ` [PATCH v4 01/12] vfio_pci: refine user config reference in vfio-pci module Liu Yi L
2020-01-09 22:48   ` Alex Williamson
2020-01-16 12:19     ` Liu, Yi L
2020-01-07 12:01 ` [PATCH v4 02/12] vfio_pci: move vfio_pci_is_vga/vfio_vga_disabled to header file Liu Yi L
2020-01-15 10:43   ` Cornelia Huck
2020-01-16 12:46     ` Liu, Yi L
2020-01-07 12:01 ` [PATCH v4 03/12] vfio_pci: refine vfio_pci_driver reference in vfio_pci.c Liu Yi L
2020-01-09 22:48   ` Alex Williamson [this message]
2020-01-10  7:35     ` Liu, Yi L
2020-01-07 12:01 ` [PATCH v4 04/12] vfio_pci: make common functions be extern Liu Yi L
2020-01-15 10:56   ` Cornelia Huck
2020-01-16 12:48     ` Liu, Yi L
2020-01-07 12:01 ` [PATCH v4 05/12] vfio_pci: duplicate vfio_pci.c Liu Yi L
2020-01-15 11:03   ` Cornelia Huck
2020-01-15 15:12     ` Alex Williamson
2020-01-07 12:01 ` [PATCH v4 06/12] vfio_pci: shrink vfio_pci_common.c Liu Yi L
2020-01-07 12:01 ` [PATCH v4 07/12] vfio_pci: shrink vfio_pci.c Liu Yi L
2020-01-08 11:24   ` kbuild test robot
2020-01-09 22:48   ` Alex Williamson
2020-01-16 12:42     ` Liu, Yi L
2020-01-07 12:01 ` [PATCH v4 08/12] vfio_pci: duplicate vfio_pci_private.h to include/linux Liu Yi L
2020-01-07 12:01 ` [PATCH v4 09/12] vfio: split vfio_pci_private.h into two files Liu Yi L
2020-01-09 22:48   ` Alex Williamson
2020-01-16 11:59     ` Liu, Yi L
2020-01-07 12:01 ` [PATCH v4 10/12] vfio: build vfio_pci_common.c into a kernel module Liu Yi L
2020-01-07 12:01 ` [PATCH v4 11/12] samples: add vfio-mdev-pci driver Liu Yi L
2020-01-09 22:48   ` Alex Williamson
2020-01-16 12:33     ` Liu, Yi L
2020-01-16 21:24       ` Alex Williamson
2020-01-18 14:25         ` Liu, Yi L
2020-01-20 21:07           ` Alex Williamson
2020-01-21  7:43             ` Tian, Kevin
2020-01-21  8:43               ` Yan Zhao
2020-01-21 20:04                 ` Alex Williamson
2020-01-21 21:54                   ` Yan Zhao
2020-01-23 23:33                     ` Alex Williamson
2020-01-31  2:26                       ` Yan Zhao
2020-01-15 12:30   ` Cornelia Huck
2020-01-16 13:23     ` Liu, Yi L
2020-01-16 17:40       ` Cornelia Huck
2020-01-18 14:23         ` Liu, Yi L
2020-01-20  8:55           ` Cornelia Huck
2020-01-07 12:01 ` [PATCH v4 12/12] samples: refine " Liu Yi L

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=20200109154819.455f11d3@w520.home \
    --to=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterx@redhat.com \
    --cc=yi.l.liu@intel.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 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).