On Wed, Jan 17, 2024 at 04:24:24PM +0800, Yi Liu wrote: > Above indeed makes more sense if there can be concurrent attach/replace/detach > on a single pasid. Just have one doubt should we add lock to protect the > whole attach/replace/detach paths. In the attach/replace path[1] [2], the > xarray entry is verified firstly, and then updated after returning from > iommu attach/replace API. It is uneasy to protect the xarray operations only > with xa_lock as a detach path can acquire xa_lock right after attach/replace > path checks the xarray. To avoid it, may need a mutex to protect the whole > attach/replace/detach path to avoid race. Or maybe the attach/replace path > should mark the corresponding entry as a special state that can block the > other path like detach until the attach/replace path update the final hwpt to > the xarray. Is there such state in xarray? If the caller is not allowed to make concurrent attaches/detaches to the same pasid then you can document that in a comment, but it is still better to use xarray in a self-consistent way. Jason