Message ID | 20230426145419.450922-7-yi.l.liu@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Enhance vfio PCI hot reset for vfio cdev device | expand |
> From: Liu, Yi L <yi.l.liu@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@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?
> From: Tian, Kevin <kevin.tian@intel.com> > Sent: Thursday, April 27, 2023 2:42 PM > > > From: Liu, Yi L <yi.l.liu@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@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. Ok. > 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? I doubt how to do it. ☹ @Jason? What about your opinion? Regards, Yi Liu
On Thu, Apr 27, 2023 at 07:09:38AM +0000, Liu, Yi L wrote: > > > @@ -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. > > Ok. > > > 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? > > I doubt how to do it. ☹ @Jason? What about your opinion? It is probably fine to use xa_limit_31b and just say that -ve values are reserved in a comment near the define for 0 Jason
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); if (rc) goto out_free; return obj;
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@intel.com> --- drivers/iommu/iommufd/main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)