RE: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-04-04 Thread Liu, Yi L
Hi Alex,

> From: Alex Williamson 
> Sent: Saturday, April 4, 2020 1:28 AM
> To: Liu, Yi L 
> Cc: eric.au...@redhat.com; Tian, Kevin ;
> jacob.jun@linux.intel.com; j...@8bytes.org; Raj, Ashok 
> ;
> Tian, Jun J ; Sun, Yi Y ; jean-
> phili...@linaro.org; pet...@redhat.com; iommu@lists.linux-foundation.org;
> k...@vger.kernel.org; linux-ker...@vger.kernel.org; Wu, Hao 
> Subject: Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to
> userspace
> 
> On Fri, 3 Apr 2020 08:17:44 +
> "Liu, Yi L"  wrote:
> 
> > > From: Alex Williamson < alex.william...@redhat.com >
> > > Sent: Friday, April 3, 2020 2:01 AM
> > > To: Liu, Yi L 
> > > Subject: Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free
> > > support to userspace
> > >
> > > On Sun, 22 Mar 2020 05:32:00 -0700
> > > "Liu, Yi L"  wrote:
> > >
> > > > From: Liu Yi L 
> > > >
> > > > This patch reports PASID alloc/free availability to userspace (e.g.
> > > > QEMU) thus userspace could do a pre-check before utilizing this feature.
> > > >
> > > > Cc: Kevin Tian 
> > > > CC: Jacob Pan 
> > > > Cc: Alex Williamson 
> > > > Cc: Eric Auger 
> > > > Cc: Jean-Philippe Brucker 
> > > > Signed-off-by: Liu Yi L 
> > > > ---
> > > >  drivers/vfio/vfio_iommu_type1.c | 28 
> > > >  include/uapi/linux/vfio.h   |  8 
> > > >  2 files changed, 36 insertions(+)
> > > >
> > > > diff --git a/drivers/vfio/vfio_iommu_type1.c
> > > > b/drivers/vfio/vfio_iommu_type1.c index e40afc0..ddd1ffe 100644
> > > > --- a/drivers/vfio/vfio_iommu_type1.c
> > > > +++ b/drivers/vfio/vfio_iommu_type1.c
> > > > @@ -2234,6 +2234,30 @@ static int
> > > > vfio_iommu_type1_pasid_free(struct
> > > vfio_iommu *iommu,
> > > > return ret;
> > > >  }
> > > >
> > > > +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> > > > +struct vfio_info_cap *caps) {
> > > > +   struct vfio_info_cap_header *header;
> > > > +   struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> > > > +
> > > > +   header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> > > > +  VFIO_IOMMU_TYPE1_INFO_CAP_NESTING, 
> > > > 1);
> > > > +   if (IS_ERR(header))
> > > > +   return PTR_ERR(header);
> > > > +
> > > > +   nesting_cap = container_of(header,
> > > > +   struct 
> > > > vfio_iommu_type1_info_cap_nesting,
> > > > +   header);
> > > > +
> > > > +   nesting_cap->nesting_capabilities = 0;
> > > > +   if (iommu->nesting) {
> > > > +   /* nesting iommu type supports PASID requests 
> > > > (alloc/free) */
> > > > +   nesting_cap->nesting_capabilities |= 
> > > > VFIO_IOMMU_PASID_REQS;
> > > > +   }
> > > > +
> > > > +   return 0;
> > > > +}
> > > > +
> > > >  static long vfio_iommu_type1_ioctl(void *iommu_data,
> > > >unsigned int cmd, unsigned long arg) 
> > > >  { @@ -
> > > 2283,6 +2307,10 @@
> > > > static long vfio_iommu_type1_ioctl(void *iommu_data,
> > > > if (ret)
> > > > return ret;
> > > >
> > > > +   ret = vfio_iommu_info_add_nesting_cap(iommu, );
> > > > +   if (ret)
> > > > +   return ret;
> > > > +
> > > > if (caps.size) {
> > > > info.flags |= VFIO_IOMMU_INFO_CAPS;
> > > >
> > > > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> > > > index 298ac80..8837219 100644
> > > > --- a/include/uapi/linux/vfio.h
> > > > +++ b/include/uapi/linux/vfio.h
> > > > @@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
> > > > struct  vfio_iova_range iova_ranges[];
> > > >  };
> > > >
> > > > +#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
> > > > +
> > > > +struct vfio_iommu_type1_info_cap_nesting {
> > > > +   struct  vfio_info_cap_header header;
> > > > +#define VFIO_IOMMU_PASID_REQS  (1 << 0)
> > > > +   __u32   nesting_capabilities;
> > > > +};
> > > > +
> > > >  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
> > > >
> > > >  /**
> > >
> > > I think this answers my PROBE question on patch 1/.
> > yep.
> > > Should the quota/usage be exposed to the user here?  Thanks,
> >
> > Do you mean report the quota available for this user in this cap info as 
> > well?
> 
> Yes.  Would it be useful?

I think so.

> > For usage, do you mean the alloc and free or others?
> 
> I mean how many of the quota are currently in allocated, or alternatively, how
> many remain.  Thanks,

ok, got it, maybe report the remain. thanks.

Regards,
Yi Liu
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-04-03 Thread Alex Williamson
On Fri, 3 Apr 2020 08:17:44 +
"Liu, Yi L"  wrote:

> > From: Alex Williamson < alex.william...@redhat.com >
> > Sent: Friday, April 3, 2020 2:01 AM
> > To: Liu, Yi L 
> > Subject: Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to
> > userspace
> > 
> > On Sun, 22 Mar 2020 05:32:00 -0700
> > "Liu, Yi L"  wrote:
> >   
> > > From: Liu Yi L 
> > >
> > > This patch reports PASID alloc/free availability to userspace (e.g.
> > > QEMU) thus userspace could do a pre-check before utilizing this feature.
> > >
> > > Cc: Kevin Tian 
> > > CC: Jacob Pan 
> > > Cc: Alex Williamson 
> > > Cc: Eric Auger 
> > > Cc: Jean-Philippe Brucker 
> > > Signed-off-by: Liu Yi L 
> > > ---
> > >  drivers/vfio/vfio_iommu_type1.c | 28 
> > >  include/uapi/linux/vfio.h   |  8 
> > >  2 files changed, 36 insertions(+)
> > >
> > > diff --git a/drivers/vfio/vfio_iommu_type1.c
> > > b/drivers/vfio/vfio_iommu_type1.c index e40afc0..ddd1ffe 100644
> > > --- a/drivers/vfio/vfio_iommu_type1.c
> > > +++ b/drivers/vfio/vfio_iommu_type1.c
> > > @@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct  
> > vfio_iommu *iommu,  
> > >   return ret;
> > >  }
> > >
> > > +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> > > +  struct vfio_info_cap *caps)
> > > +{
> > > + struct vfio_info_cap_header *header;
> > > + struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> > > +
> > > + header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> > > +VFIO_IOMMU_TYPE1_INFO_CAP_NESTING, 1);
> > > + if (IS_ERR(header))
> > > + return PTR_ERR(header);
> > > +
> > > + nesting_cap = container_of(header,
> > > + struct vfio_iommu_type1_info_cap_nesting,
> > > + header);
> > > +
> > > + nesting_cap->nesting_capabilities = 0;
> > > + if (iommu->nesting) {
> > > + /* nesting iommu type supports PASID requests (alloc/free) */
> > > + nesting_cap->nesting_capabilities |= VFIO_IOMMU_PASID_REQS;
> > > + }
> > > +
> > > + return 0;
> > > +}
> > > +
> > >  static long vfio_iommu_type1_ioctl(void *iommu_data,
> > >  unsigned int cmd, unsigned long arg)  { @@ - 
> > >  
> > 2283,6 +2307,10 @@  
> > > static long vfio_iommu_type1_ioctl(void *iommu_data,
> > >   if (ret)
> > >   return ret;
> > >
> > > + ret = vfio_iommu_info_add_nesting_cap(iommu, );
> > > + if (ret)
> > > + return ret;
> > > +
> > >   if (caps.size) {
> > >   info.flags |= VFIO_IOMMU_INFO_CAPS;
> > >
> > > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> > > index 298ac80..8837219 100644
> > > --- a/include/uapi/linux/vfio.h
> > > +++ b/include/uapi/linux/vfio.h
> > > @@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
> > >   struct  vfio_iova_range iova_ranges[];
> > >  };
> > >
> > > +#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
> > > +
> > > +struct vfio_iommu_type1_info_cap_nesting {
> > > + struct  vfio_info_cap_header header;
> > > +#define VFIO_IOMMU_PASID_REQS(1 << 0)
> > > + __u32   nesting_capabilities;
> > > +};
> > > +
> > >  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
> > >
> > >  /**  
> > 
> > I think this answers my PROBE question on patch 1/.   
> yep.
> > Should the quota/usage be exposed to the user here?  Thanks,  
> 
> Do you mean report the quota available for this user in this cap info as well?

Yes.  Would it be useful?

> For usage, do you mean the alloc and free or others?

I mean how many of the quota are currently in allocated, or
alternatively, how many remain.  Thanks,

Alex

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


RE: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-04-03 Thread Liu, Yi L
> From: Alex Williamson < alex.william...@redhat.com >
> Sent: Friday, April 3, 2020 2:01 AM
> To: Liu, Yi L 
> Subject: Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to
> userspace
> 
> On Sun, 22 Mar 2020 05:32:00 -0700
> "Liu, Yi L"  wrote:
> 
> > From: Liu Yi L 
> >
> > This patch reports PASID alloc/free availability to userspace (e.g.
> > QEMU) thus userspace could do a pre-check before utilizing this feature.
> >
> > Cc: Kevin Tian 
> > CC: Jacob Pan 
> > Cc: Alex Williamson 
> > Cc: Eric Auger 
> > Cc: Jean-Philippe Brucker 
> > Signed-off-by: Liu Yi L 
> > ---
> >  drivers/vfio/vfio_iommu_type1.c | 28 
> >  include/uapi/linux/vfio.h   |  8 
> >  2 files changed, 36 insertions(+)
> >
> > diff --git a/drivers/vfio/vfio_iommu_type1.c
> > b/drivers/vfio/vfio_iommu_type1.c index e40afc0..ddd1ffe 100644
> > --- a/drivers/vfio/vfio_iommu_type1.c
> > +++ b/drivers/vfio/vfio_iommu_type1.c
> > @@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct
> vfio_iommu *iommu,
> > return ret;
> >  }
> >
> > +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> > +struct vfio_info_cap *caps)
> > +{
> > +   struct vfio_info_cap_header *header;
> > +   struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> > +
> > +   header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> > +  VFIO_IOMMU_TYPE1_INFO_CAP_NESTING, 1);
> > +   if (IS_ERR(header))
> > +   return PTR_ERR(header);
> > +
> > +   nesting_cap = container_of(header,
> > +   struct vfio_iommu_type1_info_cap_nesting,
> > +   header);
> > +
> > +   nesting_cap->nesting_capabilities = 0;
> > +   if (iommu->nesting) {
> > +   /* nesting iommu type supports PASID requests (alloc/free) */
> > +   nesting_cap->nesting_capabilities |= VFIO_IOMMU_PASID_REQS;
> > +   }
> > +
> > +   return 0;
> > +}
> > +
> >  static long vfio_iommu_type1_ioctl(void *iommu_data,
> >unsigned int cmd, unsigned long arg)  { @@ -
> 2283,6 +2307,10 @@
> > static long vfio_iommu_type1_ioctl(void *iommu_data,
> > if (ret)
> > return ret;
> >
> > +   ret = vfio_iommu_info_add_nesting_cap(iommu, );
> > +   if (ret)
> > +   return ret;
> > +
> > if (caps.size) {
> > info.flags |= VFIO_IOMMU_INFO_CAPS;
> >
> > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> > index 298ac80..8837219 100644
> > --- a/include/uapi/linux/vfio.h
> > +++ b/include/uapi/linux/vfio.h
> > @@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
> > struct  vfio_iova_range iova_ranges[];
> >  };
> >
> > +#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
> > +
> > +struct vfio_iommu_type1_info_cap_nesting {
> > +   struct  vfio_info_cap_header header;
> > +#define VFIO_IOMMU_PASID_REQS  (1 << 0)
> > +   __u32   nesting_capabilities;
> > +};
> > +
> >  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
> >
> >  /**
> 
> I think this answers my PROBE question on patch 1/. 
yep.
> Should the quota/usage be exposed to the user here?  Thanks,

Do you mean report the quota available for this user in this cap info as well?
For usage, do you mean the alloc and free or others?

Regards,
Yi Liu
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-04-02 Thread Alex Williamson
On Sun, 22 Mar 2020 05:32:00 -0700
"Liu, Yi L"  wrote:

> From: Liu Yi L 
> 
> This patch reports PASID alloc/free availability to userspace (e.g. QEMU)
> thus userspace could do a pre-check before utilizing this feature.
> 
> Cc: Kevin Tian 
> CC: Jacob Pan 
> Cc: Alex Williamson 
> Cc: Eric Auger 
> Cc: Jean-Philippe Brucker 
> Signed-off-by: Liu Yi L 
> ---
>  drivers/vfio/vfio_iommu_type1.c | 28 
>  include/uapi/linux/vfio.h   |  8 
>  2 files changed, 36 insertions(+)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index e40afc0..ddd1ffe 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct 
> vfio_iommu *iommu,
>   return ret;
>  }
>  
> +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> +  struct vfio_info_cap *caps)
> +{
> + struct vfio_info_cap_header *header;
> + struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> +
> + header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> +VFIO_IOMMU_TYPE1_INFO_CAP_NESTING, 1);
> + if (IS_ERR(header))
> + return PTR_ERR(header);
> +
> + nesting_cap = container_of(header,
> + struct vfio_iommu_type1_info_cap_nesting,
> + header);
> +
> + nesting_cap->nesting_capabilities = 0;
> + if (iommu->nesting) {
> + /* nesting iommu type supports PASID requests (alloc/free) */
> + nesting_cap->nesting_capabilities |= VFIO_IOMMU_PASID_REQS;
> + }
> +
> + return 0;
> +}
> +
>  static long vfio_iommu_type1_ioctl(void *iommu_data,
>  unsigned int cmd, unsigned long arg)
>  {
> @@ -2283,6 +2307,10 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
>   if (ret)
>   return ret;
>  
> + ret = vfio_iommu_info_add_nesting_cap(iommu, );
> + if (ret)
> + return ret;
> +
>   if (caps.size) {
>   info.flags |= VFIO_IOMMU_INFO_CAPS;
>  
> diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> index 298ac80..8837219 100644
> --- a/include/uapi/linux/vfio.h
> +++ b/include/uapi/linux/vfio.h
> @@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
>   struct  vfio_iova_range iova_ranges[];
>  };
>  
> +#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
> +
> +struct vfio_iommu_type1_info_cap_nesting {
> + struct  vfio_info_cap_header header;
> +#define VFIO_IOMMU_PASID_REQS(1 << 0)
> + __u32   nesting_capabilities;
> +};
> +
>  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
>  
>  /**

I think this answers my PROBE question on patch 1/.  Should the
quota/usage be exposed to the user here?  Thanks,

Alex

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


RE: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-04-01 Thread Liu, Yi L
Hi Eric,

> From: Auger Eric 
> Sent: Wednesday, April 1, 2020 5:41 PM
> To: Liu, Yi L ; alex.william...@redhat.com
> Subject: Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to
> userspace
> 
> Yi,
> On 3/22/20 1:32 PM, Liu, Yi L wrote:
> > From: Liu Yi L 
> >
> > This patch reports PASID alloc/free availability to userspace (e.g.
> > QEMU) thus userspace could do a pre-check before utilizing this feature.
> >
> > Cc: Kevin Tian 
> > CC: Jacob Pan 
> > Cc: Alex Williamson 
> > Cc: Eric Auger 
> > Cc: Jean-Philippe Brucker 
> > Signed-off-by: Liu Yi L 
> > ---
> >  drivers/vfio/vfio_iommu_type1.c | 28 
> >  include/uapi/linux/vfio.h   |  8 
> >  2 files changed, 36 insertions(+)
> >
> > diff --git a/drivers/vfio/vfio_iommu_type1.c
> > b/drivers/vfio/vfio_iommu_type1.c index e40afc0..ddd1ffe 100644
> > --- a/drivers/vfio/vfio_iommu_type1.c
> > +++ b/drivers/vfio/vfio_iommu_type1.c
> > @@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct
> vfio_iommu *iommu,
> > return ret;
> >  }
> >
> > +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> > +struct vfio_info_cap *caps)
> > +{
> > +   struct vfio_info_cap_header *header;
> > +   struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> > +
> > +   header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> > +  VFIO_IOMMU_TYPE1_INFO_CAP_NESTING, 1);
> > +   if (IS_ERR(header))
> > +   return PTR_ERR(header);
> > +
> > +   nesting_cap = container_of(header,
> > +   struct vfio_iommu_type1_info_cap_nesting,
> > +   header);
> > +
> > +   nesting_cap->nesting_capabilities = 0;
> > +   if (iommu->nesting) {
> > +   /* nesting iommu type supports PASID requests (alloc/free) */
> > +   nesting_cap->nesting_capabilities |= VFIO_IOMMU_PASID_REQS;
> Supporting nesting does not necessarily mean supporting PASID.

here I think the PASID is somehow IDs in kernel which can be used to
tag various address spaces provided by guest software. I think this
is why we introduced the ioasid. :-) Current implementation is doing
PASID alloc/free in vfio.

> > +   }
> > +
> > +   return 0;
> > +}
> > +
> >  static long vfio_iommu_type1_ioctl(void *iommu_data,
> >unsigned int cmd, unsigned long arg)  { @@ -
> 2283,6 +2307,10 @@
> > static long vfio_iommu_type1_ioctl(void *iommu_data,
> > if (ret)
> > return ret;
> >
> > +   ret = vfio_iommu_info_add_nesting_cap(iommu, );
> > +   if (ret)
> > +   return ret;
> > +
> > if (caps.size) {
> > info.flags |= VFIO_IOMMU_INFO_CAPS;
> >
> > diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> > index 298ac80..8837219 100644
> > --- a/include/uapi/linux/vfio.h
> > +++ b/include/uapi/linux/vfio.h
> > @@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
> > struct  vfio_iova_range iova_ranges[];
> >  };
> >
> > +#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
> > +
> > +struct vfio_iommu_type1_info_cap_nesting {
> > +   struct  vfio_info_cap_header header;
> > +#define VFIO_IOMMU_PASID_REQS  (1 << 0)
> PASID_REQS sounds a bit far from the claimed host managed alloc/free
> capability.
> VFIO_IOMMU_SYSTEM_WIDE_PASID?

Oh, yep. I can rename it.

Regards,
Yi Liu
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-04-01 Thread Auger Eric
Yi,
On 3/22/20 1:32 PM, Liu, Yi L wrote:
> From: Liu Yi L 
> 
> This patch reports PASID alloc/free availability to userspace (e.g. QEMU)
> thus userspace could do a pre-check before utilizing this feature.
> 
> Cc: Kevin Tian 
> CC: Jacob Pan 
> Cc: Alex Williamson 
> Cc: Eric Auger 
> Cc: Jean-Philippe Brucker 
> Signed-off-by: Liu Yi L 
> ---
>  drivers/vfio/vfio_iommu_type1.c | 28 
>  include/uapi/linux/vfio.h   |  8 
>  2 files changed, 36 insertions(+)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
> index e40afc0..ddd1ffe 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct 
> vfio_iommu *iommu,
>   return ret;
>  }
>  
> +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> +  struct vfio_info_cap *caps)
> +{
> + struct vfio_info_cap_header *header;
> + struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> +
> + header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> +VFIO_IOMMU_TYPE1_INFO_CAP_NESTING, 1);
> + if (IS_ERR(header))
> + return PTR_ERR(header);
> +
> + nesting_cap = container_of(header,
> + struct vfio_iommu_type1_info_cap_nesting,
> + header);
> +
> + nesting_cap->nesting_capabilities = 0;
> + if (iommu->nesting) {
> + /* nesting iommu type supports PASID requests (alloc/free) */
> + nesting_cap->nesting_capabilities |= VFIO_IOMMU_PASID_REQS;
Supporting nesting does not necessarily mean supporting PASID.
> + }
> +
> + return 0;
> +}
> +
>  static long vfio_iommu_type1_ioctl(void *iommu_data,
>  unsigned int cmd, unsigned long arg)
>  {
> @@ -2283,6 +2307,10 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
>   if (ret)
>   return ret;
>  
> + ret = vfio_iommu_info_add_nesting_cap(iommu, );
> + if (ret)
> + return ret;
> +
>   if (caps.size) {
>   info.flags |= VFIO_IOMMU_INFO_CAPS;
>  
> diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> index 298ac80..8837219 100644
> --- a/include/uapi/linux/vfio.h
> +++ b/include/uapi/linux/vfio.h
> @@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
>   struct  vfio_iova_range iova_ranges[];
>  };
>  
> +#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
> +
> +struct vfio_iommu_type1_info_cap_nesting {
> + struct  vfio_info_cap_header header;
> +#define VFIO_IOMMU_PASID_REQS(1 << 0)
PASID_REQS sounds a bit far from the claimed host managed alloc/free
capability.
VFIO_IOMMU_SYSTEM_WIDE_PASID?
> + __u32   nesting_capabilities;
> +};
> +
>  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
>  
>  /**
> 
Thanks

Eric

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


RE: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-04-01 Thread Liu, Yi L
> From: Tian, Kevin 
> Sent: Monday, March 30, 2020 5:44 PM
> To: Liu, Yi L ; alex.william...@redhat.com;
> Subject: RE: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to
> userspace
> 
> > From: Liu, Yi L 
> > Sent: Sunday, March 22, 2020 8:32 PM
> >
> > From: Liu Yi L 
> >
> > This patch reports PASID alloc/free availability to userspace (e.g.
> > QEMU) thus userspace could do a pre-check before utilizing this feature.
> >
> > Cc: Kevin Tian 
> > CC: Jacob Pan 
> > Cc: Alex Williamson 
> > Cc: Eric Auger 
> > Cc: Jean-Philippe Brucker 
> > Signed-off-by: Liu Yi L 
> > ---
> >  drivers/vfio/vfio_iommu_type1.c | 28 
> >  include/uapi/linux/vfio.h   |  8 
> >  2 files changed, 36 insertions(+)
> >
> > diff --git a/drivers/vfio/vfio_iommu_type1.c
> > b/drivers/vfio/vfio_iommu_type1.c index e40afc0..ddd1ffe 100644
> > --- a/drivers/vfio/vfio_iommu_type1.c
> > +++ b/drivers/vfio/vfio_iommu_type1.c
> > @@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct
> > vfio_iommu *iommu,
> > return ret;
> >  }
> >
> > +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> > +struct vfio_info_cap *caps)
> > +{
> > +   struct vfio_info_cap_header *header;
> > +   struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> > +
> > +   header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> > +  VFIO_IOMMU_TYPE1_INFO_CAP_NESTING,
> > 1);
> > +   if (IS_ERR(header))
> > +   return PTR_ERR(header);
> > +
> > +   nesting_cap = container_of(header,
> > +   struct vfio_iommu_type1_info_cap_nesting,
> > +   header);
> > +
> > +   nesting_cap->nesting_capabilities = 0;
> > +   if (iommu->nesting) {
> 
> Is it good to report a nesting cap when iommu->nesting is disabled? I suppose 
> the
> check should move before vfio_info_cap_add...

oops, yes it.

> 
> > +   /* nesting iommu type supports PASID requests (alloc/free)
> > */
> > +   nesting_cap->nesting_capabilities |=
> > VFIO_IOMMU_PASID_REQS;
> 
> VFIO_IOMMU_CAP_PASID_REQ? to avoid confusion with ioctl cmd
> VFIO_IOMMU_PASID_REQUEST...

got it.

Thanks,
Yi Liu

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


RE: [PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-03-30 Thread Tian, Kevin
> From: Liu, Yi L 
> Sent: Sunday, March 22, 2020 8:32 PM
> 
> From: Liu Yi L 
> 
> This patch reports PASID alloc/free availability to userspace (e.g. QEMU)
> thus userspace could do a pre-check before utilizing this feature.
> 
> Cc: Kevin Tian 
> CC: Jacob Pan 
> Cc: Alex Williamson 
> Cc: Eric Auger 
> Cc: Jean-Philippe Brucker 
> Signed-off-by: Liu Yi L 
> ---
>  drivers/vfio/vfio_iommu_type1.c | 28 
>  include/uapi/linux/vfio.h   |  8 
>  2 files changed, 36 insertions(+)
> 
> diff --git a/drivers/vfio/vfio_iommu_type1.c
> b/drivers/vfio/vfio_iommu_type1.c
> index e40afc0..ddd1ffe 100644
> --- a/drivers/vfio/vfio_iommu_type1.c
> +++ b/drivers/vfio/vfio_iommu_type1.c
> @@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct
> vfio_iommu *iommu,
>   return ret;
>  }
> 
> +static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
> +  struct vfio_info_cap *caps)
> +{
> + struct vfio_info_cap_header *header;
> + struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
> +
> + header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
> +VFIO_IOMMU_TYPE1_INFO_CAP_NESTING,
> 1);
> + if (IS_ERR(header))
> + return PTR_ERR(header);
> +
> + nesting_cap = container_of(header,
> + struct vfio_iommu_type1_info_cap_nesting,
> + header);
> +
> + nesting_cap->nesting_capabilities = 0;
> + if (iommu->nesting) {

Is it good to report a nesting cap when iommu->nesting is disabled? I suppose
the check should move before vfio_info_cap_add...

> + /* nesting iommu type supports PASID requests (alloc/free)
> */
> + nesting_cap->nesting_capabilities |=
> VFIO_IOMMU_PASID_REQS;

VFIO_IOMMU_CAP_PASID_REQ? to avoid confusion with ioctl cmd
VFIO_IOMMU_PASID_REQUEST...

> + }
> +
> + return 0;
> +}
> +
>  static long vfio_iommu_type1_ioctl(void *iommu_data,
>  unsigned int cmd, unsigned long arg)
>  {
> @@ -2283,6 +2307,10 @@ static long vfio_iommu_type1_ioctl(void
> *iommu_data,
>   if (ret)
>   return ret;
> 
> + ret = vfio_iommu_info_add_nesting_cap(iommu, );
> + if (ret)
> + return ret;
> +
>   if (caps.size) {
>   info.flags |= VFIO_IOMMU_INFO_CAPS;
> 
> diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
> index 298ac80..8837219 100644
> --- a/include/uapi/linux/vfio.h
> +++ b/include/uapi/linux/vfio.h
> @@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
>   struct  vfio_iova_range iova_ranges[];
>  };
> 
> +#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
> +
> +struct vfio_iommu_type1_info_cap_nesting {
> + struct  vfio_info_cap_header header;
> +#define VFIO_IOMMU_PASID_REQS(1 << 0)
> + __u32   nesting_capabilities;
> +};
> +
>  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
> 
>  /**
> --
> 2.7.4

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH v1 3/8] vfio/type1: Report PASID alloc/free support to userspace

2020-03-22 Thread Liu, Yi L
From: Liu Yi L 

This patch reports PASID alloc/free availability to userspace (e.g. QEMU)
thus userspace could do a pre-check before utilizing this feature.

Cc: Kevin Tian 
CC: Jacob Pan 
Cc: Alex Williamson 
Cc: Eric Auger 
Cc: Jean-Philippe Brucker 
Signed-off-by: Liu Yi L 
---
 drivers/vfio/vfio_iommu_type1.c | 28 
 include/uapi/linux/vfio.h   |  8 
 2 files changed, 36 insertions(+)

diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c
index e40afc0..ddd1ffe 100644
--- a/drivers/vfio/vfio_iommu_type1.c
+++ b/drivers/vfio/vfio_iommu_type1.c
@@ -2234,6 +2234,30 @@ static int vfio_iommu_type1_pasid_free(struct vfio_iommu 
*iommu,
return ret;
 }
 
+static int vfio_iommu_info_add_nesting_cap(struct vfio_iommu *iommu,
+struct vfio_info_cap *caps)
+{
+   struct vfio_info_cap_header *header;
+   struct vfio_iommu_type1_info_cap_nesting *nesting_cap;
+
+   header = vfio_info_cap_add(caps, sizeof(*nesting_cap),
+  VFIO_IOMMU_TYPE1_INFO_CAP_NESTING, 1);
+   if (IS_ERR(header))
+   return PTR_ERR(header);
+
+   nesting_cap = container_of(header,
+   struct vfio_iommu_type1_info_cap_nesting,
+   header);
+
+   nesting_cap->nesting_capabilities = 0;
+   if (iommu->nesting) {
+   /* nesting iommu type supports PASID requests (alloc/free) */
+   nesting_cap->nesting_capabilities |= VFIO_IOMMU_PASID_REQS;
+   }
+
+   return 0;
+}
+
 static long vfio_iommu_type1_ioctl(void *iommu_data,
   unsigned int cmd, unsigned long arg)
 {
@@ -2283,6 +2307,10 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
if (ret)
return ret;
 
+   ret = vfio_iommu_info_add_nesting_cap(iommu, );
+   if (ret)
+   return ret;
+
if (caps.size) {
info.flags |= VFIO_IOMMU_INFO_CAPS;
 
diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h
index 298ac80..8837219 100644
--- a/include/uapi/linux/vfio.h
+++ b/include/uapi/linux/vfio.h
@@ -748,6 +748,14 @@ struct vfio_iommu_type1_info_cap_iova_range {
struct  vfio_iova_range iova_ranges[];
 };
 
+#define VFIO_IOMMU_TYPE1_INFO_CAP_NESTING  2
+
+struct vfio_iommu_type1_info_cap_nesting {
+   struct  vfio_info_cap_header header;
+#define VFIO_IOMMU_PASID_REQS  (1 << 0)
+   __u32   nesting_capabilities;
+};
+
 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
 
 /**
-- 
2.7.4

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu