linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Liu, Yi L" <yi.l.liu@intel.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: "kwankhede@nvidia.com" <kwankhede@nvidia.com>,
	"Tian, Kevin" <kevin.tian@intel.com>,
	"baolu.lu@linux.intel.com" <baolu.lu@linux.intel.com>,
	"Sun, Yi Y" <yi.y.sun@intel.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Zhao, Yan Y" <yan.y.zhao@intel.com>,
	"He, Shaopeng" <shaopeng.he@intel.com>,
	"Xia, Chenbo" <chenbo.xia@intel.com>,
	"Tian, Jun J" <jun.j.tian@intel.com>
Subject: RE: [PATCH v2 10/13] samples: refine vfio-mdev-pci driver
Date: Mon, 30 Sep 2019 12:39:11 +0000	[thread overview]
Message-ID: <A2975661238FB949B60364EF0F2C25743A0B55CE@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <20190925203644.7273028f@x1.home>

Hi Alex,

> From: Alex Williamson [mailto:alex.williamson@redhat.com]
> Sent: Thursday, September 26, 2019 10:37 AM
> To: Liu, Yi L <yi.l.liu@intel.com>
>
> Subject: Re: [PATCH v2 10/13] samples: refine vfio-mdev-pci driver
> 
> On Thu,  5 Sep 2019 15:59:27 +0800
> Liu Yi L <yi.l.liu@intel.com> wrote:
> 
> > From: Alex Williamson <alex.williamson@redhat.com>
> >
> > This patch refines the implementation of original vfio-mdev-pci driver.
> >
> > And the vfio-mdev-pci-type_name will be named per the following rule:
> >
> > 	vmdev->attr.name = kasprintf(GFP_KERNEL,
> > 				     "%04x:%04x:%04x:%04x:%06x:%02x",
> > 				     pdev->vendor, pdev->device,
> > 				     pdev->subsystem_vendor,
> > 				     pdev->subsystem_device, pdev->class,
> > 				     pdev->revision);
> >
> > Before usage, check the
> > /sys/bus/pci/devices/$bdf/mdev_supported_types/
> > to ensure the final mdev_supported_types.
> >
> > Cc: Kevin Tian <kevin.tian@intel.com>
> > Cc: Lu Baolu <baolu.lu@linux.intel.com>
> > Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> > Signed-off-by: Liu Yi L <yi.l.liu@intel.com>
> > ---
> >  drivers/vfio/pci/vfio_mdev_pci.c | 123
> > +++++++++++++++++++++++----------------
> >  1 file changed, 72 insertions(+), 51 deletions(-)
> >
> > diff --git a/drivers/vfio/pci/vfio_mdev_pci.c
> > b/drivers/vfio/pci/vfio_mdev_pci.c
> > index 07c8067..09143d3 100644
> > --- a/drivers/vfio/pci/vfio_mdev_pci.c
> > +++ b/drivers/vfio/pci/vfio_mdev_pci.c
> > @@ -65,18 +65,22 @@ MODULE_PARM_DESC(disable_idle_d3,
> >
> >  static struct pci_driver vfio_mdev_pci_driver;
> >
> > -static ssize_t
> > -name_show(struct kobject *kobj, struct device *dev, char *buf) -{
> > -	return sprintf(buf, "%s-type1\n", dev_name(dev));
> > -}
> > -
> > -MDEV_TYPE_ATTR_RO(name);
> > +struct vfio_mdev_pci_device {
> > +	struct vfio_pci_device vdev;
> > +	struct mdev_parent_ops ops;
> > +	struct attribute_group *groups[2];
> > +	struct attribute_group attr;
> > +	atomic_t avail;
> > +};
> >
> >  static ssize_t
> >  available_instances_show(struct kobject *kobj, struct device *dev,
> > char *buf)  {
> > -	return sprintf(buf, "%d\n", 1);
> > +	struct vfio_mdev_pci_device *vmdev;
> > +
> > +	vmdev = pci_get_drvdata(to_pci_dev(dev));
> > +
> > +	return sprintf(buf, "%d\n", atomic_read(&vmdev->avail));
> >  }
> >
> >  MDEV_TYPE_ATTR_RO(available_instances);
> > @@ -90,62 +94,57 @@ static ssize_t device_api_show(struct kobject
> > *kobj, struct device *dev,  MDEV_TYPE_ATTR_RO(device_api);
> >
> >  static struct attribute *vfio_mdev_pci_types_attrs[] = {
> > -	&mdev_type_attr_name.attr,
> >  	&mdev_type_attr_device_api.attr,
> >  	&mdev_type_attr_available_instances.attr,
> >  	NULL,
> >  };
> >
> > -static struct attribute_group vfio_mdev_pci_type_group1 = {
> > -	.name  = "type1",
> > -	.attrs = vfio_mdev_pci_types_attrs,
> > -};
> > -
> > -struct attribute_group *vfio_mdev_pci_type_groups[] = {
> > -	&vfio_mdev_pci_type_group1,
> > -	NULL,
> > -};
> > -
> >  struct vfio_mdev_pci {
> >  	struct vfio_pci_device *vdev;
> >  	struct mdev_device *mdev;
> > -	unsigned long handle;
> >  };
> >
> >  static int vfio_mdev_pci_create(struct kobject *kobj, struct
> > mdev_device *mdev)  {
> >  	struct device *pdev;
> > -	struct vfio_pci_device *vdev;
> > +	struct vfio_mdev_pci_device *vmdev;
> >  	struct vfio_mdev_pci *pmdev;
> >  	int ret;
> >
> >  	pdev = mdev_parent_dev(mdev);
> > -	vdev = dev_get_drvdata(pdev);
> > +	vmdev = dev_get_drvdata(pdev);
> > +
> > +	if (atomic_dec_if_positive(&vmdev->avail) < 0)
> > +		return -ENOSPC;
> > +
> >  	pmdev = kzalloc(sizeof(struct vfio_mdev_pci), GFP_KERNEL);
> > -	if (pmdev == NULL) {
> > -		ret = -EBUSY;
> > -		goto out;
> > -	}
> > +	if (!pmdev)
> > +		return -ENOMEM;
> 
> Needs an atomic_inc(&vmdev->avail) in this error path.  Thanks,

Oops, yes it is.

> 
> Alex

Thanks,
Yi Liu

  reply	other threads:[~2019-09-30 12:39 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-05  7:59 [PATCH v2 00/13] vfio_pci: wrap pci device as a mediated device Liu Yi L
2019-09-05  7:59 ` [PATCH v2 01/13] vfio_pci: move vfio_pci_is_vga/vfio_vga_disabled to header Liu Yi L
2019-09-05  7:59 ` [PATCH v2 02/13] vfio_pci: refine user config reference in vfio-pci module Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:38     ` Liu, Yi L
2019-09-05  7:59 ` [PATCH v2 03/13] vfio_pci: refine vfio_pci_driver reference in vfio_pci.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 04/13] vfio_pci: make common functions be extern Liu Yi L
2019-09-05  7:59 ` [PATCH v2 05/13] vfio_pci: duplicate vfio_pci.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 06/13] vfio_pci: shrink vfio_pci_common.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 07/13] vfio_pci: shrink vfio_pci.c Liu Yi L
2019-09-05  7:59 ` [PATCH v2 08/13] vfio/pci: protect cap/ecap_perm bits alloc/free with atomic op Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:38     ` Liu, Yi L
2019-09-05  7:59 ` [PATCH v2 09/13] samples: add vfio-mdev-pci driver Liu Yi L
2019-09-05  7:59 ` [PATCH v2 10/13] samples: refine " Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:39     ` Liu, Yi L [this message]
2019-09-05  7:59 ` [PATCH v2 11/13] samples/vfio-mdev-pci: call vfio_add_group_dev() Liu Yi L
2019-09-26  2:36   ` Alex Williamson
2019-09-30 12:40     ` Liu, Yi L
2019-09-05  7:59 ` [PATCH v2 12/13] vfio/type1: use iommu_attach_group() for wrapping PF/VF as mdev Liu Yi L
2019-09-26  2:37   ` Alex Williamson
2019-09-05  7:59 ` [PATCH v2 13/13] vfio/type1: track iommu backed group attach Liu Yi L
2019-09-25  9:13 ` [PATCH v2 00/13] vfio_pci: wrap pci device as a mediated device 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=A2975661238FB949B60364EF0F2C25743A0B55CE@SHSMSX104.ccr.corp.intel.com \
    --to=yi.l.liu@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=baolu.lu@linux.intel.com \
    --cc=chenbo.xia@intel.com \
    --cc=joro@8bytes.org \
    --cc=jun.j.tian@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shaopeng.he@intel.com \
    --cc=yan.y.zhao@intel.com \
    --cc=yi.y.sun@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).