Re: [PATCH v2 11/22] iommufd: Add for-driver helpers iommufd_vcmdq_depend/undepend()

Nicolin Chen
2025-04-28T18:21:41Z

On Mon, Apr 28, 2025 at 10:22:09AM +0800, Baolu Lu wrote:
> On 4/26/25 13:58, Nicolin Chen wrote:
> > NVIDIA Virtual Command Queue is one of the iommufd users exposing vIOMMU
> > features to user space VMs. Its hardware has a strict rule when mapping
> > and unmapping multiple global CMDQVs to/from a VM-owned VINTF, requiring
> > mappings in ascending order and unmappings in descending order.
> >
> > The tegra241-cmdqv driver can apply the rule for a mapping in the LVCMDQ
> > allocation handler, however it can't do the same for an unmapping since
> > the destroy op returns void.
>
> The key point is that unmapping happens during object destroy. These
> depend/undepend helpers ensure a vCMDQ is not destroyed (and therefore
> unmapped) before any vCMDQs that depend on it. Do I get it right?

Yea, I should add some additional words:
"
The tegra241-cmdqv driver can apply the rule for a mapping in the LVCMDQ
allocation handler. However, it can't do the same for an unmapping since
user space could start random destroy calls breaking the rule, while the
destroy op in the driver level can't reject a destroy call as it returns
void.

Add iommufd_vcmdq_depend/undepend() for-driver helpers, allowing LVCMDQ
allocator to refcount_inc() a sibling LVCMDQ object and LVCMDQ destroyer
to refcount_dec(), so that iommufd core will help block a random destroy
call that breaks the rule.
"

Thanks
Nicolin