[Intel-gfx] [PATCH v4 6/9] iommufd: Reserved -1 in the iommufd xarray

Tian, Kevin kevin.tian at intel.com
Thu Apr 27 06:41:54 UTC 2023


> From: Liu, Yi L <yi.l.liu at intel.com>
> Sent: Wednesday, April 26, 2023 10:54 PM
> 
> VFIO needs two reserved values. 0 is already reserved by initializing
> xarray with XA_FLAGS_ALLOC1. This reserves -1 by limiting the xa alloc
> range.
> 
> Signed-off-by: Yi Liu <yi.l.liu at intel.com>
> ---
>  drivers/iommu/iommufd/main.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iommu/iommufd/main.c
> b/drivers/iommu/iommufd/main.c
> index 3fbe636c3d8a..51b27c96c52f 100644
> --- a/drivers/iommu/iommufd/main.c
> +++ b/drivers/iommu/iommufd/main.c
> @@ -28,6 +28,9 @@ struct iommufd_object_ops {
>  static const struct iommufd_object_ops iommufd_object_ops[];
>  static struct miscdevice vfio_misc_dev;
> 
> +/* -1 is reserved */
> +#define iommufd_xa_limit_32b XA_LIMIT(0, (-2U))
> +
>  struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx,
>  					     size_t size,
>  					     enum iommufd_object_type type)
> @@ -50,7 +53,7 @@ struct iommufd_object *_iommufd_object_alloc(struct
> iommufd_ctx *ictx,
>  	 * before calling iommufd_object_finalize().
>  	 */
>  	rc = xa_alloc(&ictx->objects, &obj->id, XA_ZERO_ENTRY,
> -		      xa_limit_32b, GFP_KERNEL_ACCOUNT);
> +		      iommufd_xa_limit_32b, GFP_KERNEL_ACCOUNT);

Just direct use XA_LIMIT() here.

btw do we need a contract so vfio can learn 0 and -1 are reserved or
fine to have a fixed assumption in later patches?


More information about the Intel-gfx mailing list