Re: [PATCH v1 1/8] vfio: Add VFIO_IOMMU_PASID_REQUEST(alloc/free)

Jean-Philippe Brucker
2020-04-03T12:40:05Z

On Fri, Apr 03, 2020 at 11:56:09AM +0000, Liu, Yi L wrote:
> > > /**
> > > + * VFIO_MM objects - create, release, get, put, search
> > > + * Caller of the function should have held vfio.vfio_mm_lock.
> > > + */
> > > +static struct vfio_mm *vfio_create_mm(struct mm_struct *mm)
> > > +{
> > > + struct vfio_mm *vmm;
> > > + struct vfio_mm_token *token;
> > > + int ret = 0;
> > > +
> > > + vmm = kzalloc(sizeof(*vmm), GFP_KERNEL);
> > > + if (!vmm)
> > > + return ERR_PTR(-ENOMEM);
> > > +
> > > + /* Per mm IOASID set used for quota control and group operations */
> > > + ret = ioasid_alloc_set((struct ioasid_set *) mm,
> >
> > Hmm, either we need to change the token of ioasid_alloc_set() to "void *",
> > or pass an actual ioasid_set struct, but this cast doesn't look good :)
> >
> > As I commented on the IOASID series, I think we could embed a struct
> > ioasid_set into vfio_mm, pass that struct to all other ioasid_* functions,
> > and get rid of ioasid_sid.
>
> I think change to "void *" is better as we needs the token to ensure all
> threads within a single VM share the same ioasid_set.

Don't they share the same vfio_mm?

Thanks,
Jean
>
> > > + VFIO_DEFAULT_PASID_QUOTA, &vmm->ioasid_sid);
> > > + if (ret) {
> > > + kfree(vmm);
> > > + return ERR_PTR(ret);
> > > + }
> > > +
> > > + kref_init(&vmm->kref);
> > > + token = &vmm->token;
> > > + token->val = mm;
> >
> > Why the intermediate token struct? Could we just store the mm_struct
> > pointer within vfio_mm?
>
> Hmm, here we only want to use the pointer as a token, instead of using
> the structure behind the pointer. If store the mm_struct directly, may
> leave a space to further use its content, this is not good.
>
> Regards,
> Yi Liu
>