lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aGzYHR0+/mjufmUQ@yilunxu-OptiPlex-7050>
Date: Tue, 8 Jul 2025 16:34:37 +0800
From: Xu Yilun <yilun.xu@...ux.intel.com>
To: Baolu Lu <baolu.lu@...ux.intel.com>
Cc: jgg@...dia.com, jgg@...pe.ca, kevin.tian@...el.com, will@...nel.org,
	aneesh.kumar@...nel.org, iommu@...ts.linux.dev,
	linux-kernel@...r.kernel.org, joro@...tes.org, robin.murphy@....com,
	shuah@...nel.org, nicolinc@...dia.com, aik@....com,
	dan.j.williams@...el.com, yilun.xu@...el.com
Subject: Re: [PATCH v3 2/5] iommufd: Destroy vdevice on idevice destroy

> > -void iommufd_vdevice_destroy(struct iommufd_object *obj)
> > +void iommufd_vdevice_abort(struct iommufd_object *obj)
> >   {
> >   	struct iommufd_vdevice *vdev =
> >   		container_of(obj, struct iommufd_vdevice, obj);
> >   	struct iommufd_viommu *viommu = vdev->viommu;
> > +	struct iommufd_device *idev = vdev->idev;
> > +
> > +	lockdep_assert_held(&idev->igroup->lock);
> > +
> > +	/*
> > +	 * iommufd_vdevice_abort() could be reentrant, by
> > +	 * iommufd_device_unbind() or by iommufd_destroy(). Cleanup only once.
> > +	 */
> > +	if (!viommu)
> > +		return;
> >   	/* xa_cmpxchg is okay to fail if alloc failed xa_cmpxchg previously */
> >   	xa_cmpxchg(&viommu->vdevs, vdev->id, vdev, NULL, GFP_KERNEL);
> >   	refcount_dec(&viommu->obj.users);
> >   	put_device(vdev->dev);
> > +	vdev->viommu = NULL;
> > +	idev->vdev = NULL;
> 
> I feel it makes more sense to reorder the operations like this:
> 
> 	vdev->viommu = NULL;
> 	vdev->idev = NULL;
> 	idev->vdev = NULL;
> 	put_device(vdev->dev);
> 
> put_device(vdev->dev) could potentially trigger other code paths that
> might attempt to reference vdev or its associated pointers. Therefore,
> it's safer to null all the relevant reference pointers before calling
> put_device().

Yep. due to other changes, now I keep:

        xa_cmpxchg(&viommu->vdevs, vdev->id, vdev, NULL, GFP_KERNEL);
        refcount_dec(&viommu->obj.users);
+       idev->vdev = NULL;
        put_device(vdev->dev);

Anyway, vdev->dev would be completely dropped in next patch, so it
doesn't matter much.

Thanks,
Yilun

> 
> Others look good to me,
> 
> Reviewed-by: Lu Baolu <baolu.lu@...ux.intel.com>
> 
> Thanks,
> baolu

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ