From: Wei Liu <wei.liu@kernel.org>
To: Praveen Kumar <kumarpraveen@linux.microsoft.com>
Cc: Wei Liu <wei.liu@kernel.org>,
Linux on Hyper-V List <linux-hyperv@vger.kernel.org>,
virtualization@lists.linux-foundation.org,
Linux Kernel List <linux-kernel@vger.kernel.org>,
Michael Kelley <mikelley@microsoft.com>,
Vineeth Pillai <viremana@linux.microsoft.com>,
Sunil Muthuswamy <sunilmut@microsoft.com>,
Nuno Das Neves <nunodasneves@linux.microsoft.com>,
pasha.tatashin@soleen.com, "K. Y. Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Stephen Hemminger <sthemmin@microsoft.com>,
Dexuan Cui <decui@microsoft.com>
Subject: Re: [RFC v1 8/8] mshv: add vfio bridge device
Date: Tue, 10 Aug 2021 10:52:11 +0000 [thread overview]
Message-ID: <20210810105211.zzaamjqmcq3jecmn@liuwe-devbox-debian-v2> (raw)
In-Reply-To: <b400d536-632e-9212-a06d-6e41af8a6fe5@linux.microsoft.com>
On Wed, Aug 04, 2021 at 12:57:03AM +0530, Praveen Kumar wrote:
> On 09-07-2021 17:13, Wei Liu wrote:
> > +
> > +static int mshv_vfio_set_group(struct mshv_device *dev, long attr, u64 arg)
> > +{
> > + struct mshv_vfio *mv = dev->private;
> > + struct vfio_group *vfio_group;
> > + struct mshv_vfio_group *mvg;
> > + int32_t __user *argp = (int32_t __user *)(unsigned long)arg;
> > + struct fd f;
> > + int32_t fd;
> > + int ret;
> > +
> > + switch (attr) {
> > + case MSHV_DEV_VFIO_GROUP_ADD:
> > + if (get_user(fd, argp))
> > + return -EFAULT;
> > +
> > + f = fdget(fd);
> > + if (!f.file)
> > + return -EBADF;
> > +
> > + vfio_group = mshv_vfio_group_get_external_user(f.file);
> > + fdput(f);
> > +
> > + if (IS_ERR(vfio_group))
> > + return PTR_ERR(vfio_group);
> > +
> > + mutex_lock(&mv->lock);
> > +
> > + list_for_each_entry(mvg, &mv->group_list, node) {
> > + if (mvg->vfio_group == vfio_group) {
> > + mutex_unlock(&mv->lock);
> > + mshv_vfio_group_put_external_user(vfio_group);
> > + return -EEXIST;
> > + }
> > + }
> > +
> > + mvg = kzalloc(sizeof(*mvg), GFP_KERNEL_ACCOUNT);
> > + if (!mvg) {
> > + mutex_unlock(&mv->lock);
> > + mshv_vfio_group_put_external_user(vfio_group);
> > + return -ENOMEM;
> > + }
> > +
> > + list_add_tail(&mvg->node, &mv->group_list);
> > + mvg->vfio_group = vfio_group;
> > +
> > + mutex_unlock(&mv->lock);
> > +
> > + return 0;
> > +
> > + case MSHV_DEV_VFIO_GROUP_DEL:
> > + if (get_user(fd, argp))
> > + return -EFAULT;
> > +
> > + f = fdget(fd);
> > + if (!f.file)
> > + return -EBADF;
>
> Can we move these both checks above switch statement and do fdput
> accordingly under both case statement accordingly?
Fair point. This can be done, albeit at the cost of having a rather
different code structure.
I was waiting to see if we should somehow merge this with KVM's
implementation so the code was deliberately kept close. If there is no
further comment I can of course make the change you suggested.
>
> > +
> > + ret = -ENOENT;
> > +
> > + mutex_lock(&mv->lock);
> > +
> > + list_for_each_entry(mvg, &mv->group_list, node) {
> > + if (!mshv_vfio_external_group_match_file(mvg->vfio_group,
> > + f.file))
> > + continue;
> > +
> > + list_del(&mvg->node);
> > + mshv_vfio_group_put_external_user(mvg->vfio_group);
> > + kfree(mvg);
> > + ret = 0;
> > + break;
> > + }
> > +
> > + mutex_unlock(&mv->lock);
> > +
> > + fdput(f);
> > +
> > + return ret;
> > + }
> > +
> > + return -ENXIO;
> > +}
> > +
> > +static int mshv_vfio_set_attr(struct mshv_device *dev,
> > + struct mshv_device_attr *attr)
> > +{
> > + switch (attr->group) {
> > + case MSHV_DEV_VFIO_GROUP:
> > + return mshv_vfio_set_group(dev, attr->attr, attr->addr);
> > + }
> > +
> > + return -ENXIO;
> > +}
> > +
> > +static int mshv_vfio_has_attr(struct mshv_device *dev,
> > + struct mshv_device_attr *attr)
> > +{
> > + switch (attr->group) {
> > + case MSHV_DEV_VFIO_GROUP:
> > + switch (attr->attr) {
> > + case MSHV_DEV_VFIO_GROUP_ADD:
> > + case MSHV_DEV_VFIO_GROUP_DEL:
> > + return 0;
> > + }
> > +
> > + break;
>
> do we need this break statement ? If not, lets remove it.
Will do.
Wei.
prev parent reply other threads:[~2021-08-10 10:52 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-09 11:43 [RFC v1 0/8] MSHV: add PV-IOMMU driver Wei Liu
2021-07-09 11:43 ` [RFC v1 1/8] x86/hyperv: export hv_build_pci_dev_id Wei Liu
2021-07-09 11:43 ` [RFC v1 2/8] asm-generic/hyperv: add device domain definitions Wei Liu
2021-07-09 11:43 ` [RFC v1 3/8] intel/vt-d: make DMAR table parsing code more flexible Wei Liu
2021-07-09 12:56 ` Robin Murphy
2021-07-09 13:42 ` Wei Liu
2021-07-09 11:43 ` [RFC v1 4/8] intel/vt-d: export intel_iommu_get_resv_regions Wei Liu
2021-07-09 14:17 ` Lu Baolu
2021-07-09 14:21 ` Wei Liu
2021-07-09 11:43 ` [RFC v1 5/8] mshv: add paravirtualized IOMMU support Wei Liu
2021-08-03 18:40 ` Praveen Kumar
2021-08-03 21:47 ` Wei Liu
2021-08-04 6:43 ` Praveen Kumar
2021-08-10 10:46 ` Wei Liu
2021-07-09 11:43 ` [RFC v1 6/8] mshv: command line option to skip devices in PV-IOMMU Wei Liu
2021-07-09 12:46 ` Robin Murphy
2021-07-09 13:34 ` Wei Liu
2021-08-03 18:50 ` Praveen Kumar
2021-08-03 21:56 ` Wei Liu
2021-08-04 7:03 ` Praveen Kumar
2021-08-10 10:04 ` Wei Liu
2021-07-09 11:43 ` [RFC v1 7/8] mshv: implement in-kernel device framework Wei Liu
2021-07-09 13:02 ` Matthew Wilcox
2021-07-09 13:50 ` Wei Liu
2021-07-09 15:32 ` Matthew Wilcox
2021-07-09 16:27 ` Wei Liu
2021-07-09 16:38 ` Matthew Wilcox
2021-07-09 19:14 ` Wei Liu
2021-07-09 19:48 ` Matthew Wilcox
2021-07-09 20:11 ` Wei Liu
2021-08-03 19:12 ` Praveen Kumar
2021-08-03 22:04 ` Wei Liu
2021-07-09 11:43 ` [RFC v1 8/8] mshv: add vfio bridge device Wei Liu
2021-08-03 19:27 ` Praveen Kumar
2021-08-10 10:52 ` Wei Liu [this message]
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=20210810105211.zzaamjqmcq3jecmn@liuwe-devbox-debian-v2 \
--to=wei.liu@kernel.org \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=kumarpraveen@linux.microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mikelley@microsoft.com \
--cc=nunodasneves@linux.microsoft.com \
--cc=pasha.tatashin@soleen.com \
--cc=sthemmin@microsoft.com \
--cc=sunilmut@microsoft.com \
--cc=viremana@linux.microsoft.com \
--cc=virtualization@lists.linux-foundation.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).