From: Jason Gunthorpe <jgg@nvidia.com>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: Lu Baolu <baolu.lu@linux.intel.com>,
Cornelia Huck <cohuck@redhat.com>,
Eric Auger <eric.auger@redhat.com>,
Kevin Tian <kevin.tian@intel.com>,
kvm@vger.kernel.org, Lixiao Yang <lixiao.yang@intel.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Nicolin Chen <nicolinc@nvidia.com>, Yi Liu <yi.l.liu@intel.com>,
Yu He <yu.he@intel.com>
Subject: Re: [PATCH v3 06/11] vfio-iommufd: Allow iommufd to be used in place of a container fd
Date: Wed, 16 Nov 2022 20:20:39 -0400 [thread overview]
Message-ID: <Y3V+V9vxqhabkNcC@nvidia.com> (raw)
In-Reply-To: <20221116163133.7303b0ed.alex.williamson@redhat.com>
On Wed, Nov 16, 2022 at 04:31:33PM -0700, Alex Williamson wrote:
> > diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c
> > index 5c0e810f8b4d08..8c124290ce9f0d 100644
> > --- a/drivers/vfio/vfio_main.c
> > +++ b/drivers/vfio/vfio_main.c
> > @@ -35,6 +35,7 @@
> > #include <linux/pm_runtime.h>
> > #include <linux/interval_tree.h>
> > #include <linux/iova_bitmap.h>
> > +#include <linux/iommufd.h>
> > #include "vfio.h"
> >
> > #define DRIVER_VERSION "0.3"
> > @@ -665,6 +666,16 @@ EXPORT_SYMBOL_GPL(vfio_unregister_group_dev);
> > /*
> > * VFIO Group fd, /dev/vfio/$GROUP
> > */
> > +static bool vfio_group_has_iommu(struct vfio_group *group)
> > +{
> > + lockdep_assert_held(&group->group_lock);
> > + if (!group->container)
> > + WARN_ON(group->container_users);
> > + else
> > + WARN_ON(!group->container_users);
>
> I think this is just carrying forward the WARN_ON that gets replaced in
> set_container,
Yes, I've carried this invariant forward through a few series now
> but I don't really see how this bit of paranoia is ever a
> possibility.
Right, it is an invariant assertion, it should never trigger and we've
never seen it trigger. I think at one point it was harder to see that
this is impossible so an assertion must have been added
> WARN_ON(group->container ^ group->container_users);
Ah, this needs a "logical xor" which is a bit obscure. In C I guess
this is the common way to do it:
/*
* There can only be users if there is a container, and if there is a
* container there must be users.
*/
WARN_ON(!group->container != !group->container_users);
I'm also happy to delete it, not sure it is a valuable invariant.
> > @@ -900,7 +945,14 @@ static int vfio_group_ioctl_get_status(struct vfio_group *group,
> > return -ENODEV;
> > }
> >
> > - if (group->container)
> > + /*
> > + * With the container FD the iommu_group_claim_dma_owner() is done
> > + * during SET_CONTAINER but for IOMMFD this is done during
> > + * VFIO_GROUP_GET_DEVICE_FD. Meaning that with iommufd
> > + * VFIO_GROUP_FLAGS_VIABLE could be set but GET_DEVICE_FD will fail due
> > + * to viability.
> > + */
> > + if (group->container || group->iommufd)
>
> Why didn't this use the vfio_group_has_iommu() helper? This is only
> skipping the paranoia checks, which aren't currently obvious to me
> anyway.
Yes, it was missed, I fixed it
Thanks,
Jason
next prev parent reply other threads:[~2022-11-17 0:21 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-16 21:05 [PATCH v3 00/11] Connect VFIO to IOMMUFD Jason Gunthorpe
2022-11-16 21:05 ` [PATCH v3 01/11] vfio: Move vfio_device driver open/close code to a function Jason Gunthorpe
2022-11-16 21:05 ` [PATCH v3 02/11] vfio: Move vfio_device_assign_container() into vfio_device_first_open() Jason Gunthorpe
2022-11-16 21:05 ` [PATCH v3 03/11] vfio: Rename vfio_device_assign/unassign_container() Jason Gunthorpe
2022-11-16 21:05 ` [PATCH v3 04/11] vfio: Move storage of allow_unsafe_interrupts to vfio_main.c Jason Gunthorpe
2022-11-17 20:14 ` Alex Williamson
2022-11-18 15:36 ` Jason Gunthorpe
2022-11-18 20:36 ` Alex Williamson
2022-11-22 1:59 ` Jason Gunthorpe
2022-11-22 17:34 ` Alex Williamson
2022-11-22 17:41 ` Jason Gunthorpe
2022-11-23 1:21 ` Tian, Kevin
2022-11-23 16:38 ` Jason Gunthorpe
2022-11-24 5:30 ` Tian, Kevin
2022-11-24 13:24 ` Jason Gunthorpe
2022-11-23 19:47 ` Jason Gunthorpe
2022-11-24 5:26 ` Tian, Kevin
2022-11-16 21:05 ` [PATCH v3 05/11] vfio: Use IOMMU_CAP_ENFORCE_CACHE_COHERENCY for vfio_file_enforced_coherent() Jason Gunthorpe
2022-11-16 21:05 ` [PATCH v3 06/11] vfio-iommufd: Allow iommufd to be used in place of a container fd Jason Gunthorpe
2022-11-16 23:31 ` Alex Williamson
2022-11-17 0:20 ` Jason Gunthorpe [this message]
2022-11-16 21:05 ` [PATCH v3 07/11] vfio-iommufd: Support iommufd for physical VFIO devices Jason Gunthorpe
2022-11-18 1:30 ` Tian, Kevin
2022-11-16 21:05 ` [PATCH v3 08/11] vfio-iommufd: Support iommufd for emulated " Jason Gunthorpe
2022-11-18 2:03 ` Tian, Kevin
2022-11-16 21:05 ` [PATCH v3 09/11] vfio: Move container related MODULE_ALIAS statements into container.c Jason Gunthorpe
2022-11-16 21:05 ` [PATCH v3 10/11] vfio: Make vfio_container optionally compiled Jason Gunthorpe
2022-11-18 2:05 ` Tian, Kevin
2022-11-16 21:05 ` [PATCH v3 11/11] iommufd: Allow iommufd to supply /dev/vfio/vfio Jason Gunthorpe
2022-11-17 20:34 ` Alex Williamson
2022-11-18 13:07 ` Jason Gunthorpe
2022-11-23 2:44 ` [PATCH v3 00/11] Connect VFIO to IOMMUFD Yi Liu
2022-11-23 12:59 ` Jason Gunthorpe
2022-11-23 13:04 ` Yi Liu
2022-11-29 12:41 ` Yi Liu
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=Y3V+V9vxqhabkNcC@nvidia.com \
--to=jgg@nvidia.com \
--cc=alex.williamson@redhat.com \
--cc=baolu.lu@linux.intel.com \
--cc=cohuck@redhat.com \
--cc=eric.auger@redhat.com \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=lixiao.yang@intel.com \
--cc=mjrosato@linux.ibm.com \
--cc=nicolinc@nvidia.com \
--cc=yi.l.liu@intel.com \
--cc=yu.he@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 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.