From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: Re: [PATCH] vfio: Limit group opens
Date: Sat, 22 Jun 2013 11:16:36 +1000 [thread overview]
Message-ID: <51C4FAF4.5090509@ozlabs.ru> (raw)
In-Reply-To: <20130621211144.8237.7370.stgit@bling.home>
Cool, thanks!
So we will need only this (to be called from KVM), and that will be it, right?
int vfio_group_iommu_id_from_file(struct file *filep)
...
On 06/22/2013 07:12 AM, Alex Williamson wrote:
> vfio_group_fops_open attempts to limit concurrent sessions by
> disallowing opens once group->container is set. This really doesn't
> do what we want and allow for inconsistent behavior, for instance a
> group can be opened twice, then a container set giving the user two
> file descriptors to the group. But then it won't allow more to be
> opened. There's not much reason to have the group opened multiple
> times since most access is through devices or the container, so
> complete what the original code intended and only allow a single
> instance.
>
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
> drivers/vfio/vfio.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index 6d78736..d30f44d 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -76,6 +76,7 @@ struct vfio_group {
> struct notifier_block nb;
> struct list_head vfio_next;
> struct list_head container_next;
> + atomic_t opened;
> };
>
> struct vfio_device {
> @@ -206,6 +207,7 @@ static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group)
> INIT_LIST_HEAD(&group->device_list);
> mutex_init(&group->device_lock);
> atomic_set(&group->container_users, 0);
> + atomic_set(&group->opened, 0);
> group->iommu_group = iommu_group;
>
> group->nb.notifier_call = vfio_iommu_group_notifier;
> @@ -1236,12 +1238,22 @@ static long vfio_group_fops_compat_ioctl(struct file *filep,
> static int vfio_group_fops_open(struct inode *inode, struct file *filep)
> {
> struct vfio_group *group;
> + int opened;
>
> group = vfio_group_get_from_minor(iminor(inode));
> if (!group)
> return -ENODEV;
>
> + /* Do we need multiple instances of the group open? Seems not. */
> + opened = atomic_cmpxchg(&group->opened, 0, 1);
> + if (opened) {
> + vfio_group_put(group);
> + return -EBUSY;
> + }
> +
> + /* Is something still in use from a previous open? */
> if (group->container) {
> + atomic_dec(&group->opened);
> vfio_group_put(group);
> return -EBUSY;
> }
> @@ -1259,6 +1271,8 @@ static int vfio_group_fops_release(struct inode *inode, struct file *filep)
>
> vfio_group_try_dissolve_container(group);
>
> + atomic_dec(&group->opened);
> +
> vfio_group_put(group);
>
> return 0;
>
--
Alexey
next prev parent reply other threads:[~2013-06-22 1:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-21 21:12 [PATCH] vfio: Limit group opens Alex Williamson
2013-06-22 1:16 ` Alexey Kardashevskiy [this message]
2013-06-22 1:26 ` Alex Williamson
2013-06-22 2:44 ` Alexey Kardashevskiy
2013-06-22 2:57 ` Alex Williamson
2013-06-22 3:16 ` Alexey Kardashevskiy
2013-06-22 3:45 ` 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=51C4FAF4.5090509@ozlabs.ru \
--to=aik@ozlabs.ru \
--cc=alex.williamson@redhat.com \
--cc=benh@kernel.crashing.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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