Re: [PATCH v5 13/14] iommu/arm-smmu-v3: Introduce struct arm_smmu_vmaster

Nicolin Chen
2025-01-13T19:53:14Z

On Mon, Jan 13, 2025 at 03:29:27PM -0400, Jason Gunthorpe wrote:
> On Tue, Jan 07, 2025 at 09:10:16AM -0800, Nicolin Chen wrote:
>
> > +int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state,
> > + struct iommu_domain *domain)
> > +{
> > + struct arm_smmu_nested_domain *nested_domain;
> > + struct arm_smmu_vmaster *vmaster;
> > + unsigned long vsid;
> > + unsigned int cfg;
> > +
> > + iommu_group_mutex_assert(state->master->dev);
> > +
> > + if (domain->type != IOMMU_DOMAIN_NESTED)
> > + return 0;
> > + nested_domain = to_smmu_nested_domain(domain);
> > +
> > + /* Skip ABORT/BYPASS or invalid vSTE */
> > + cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(nested_domain->ste[0]));
> > + if (cfg == STRTAB_STE_0_CFG_ABORT || cfg == STRTAB_STE_0_CFG_BYPASS)
> > + return 0;
>
> Why? If the VM sets an ABORT vSTE then I would expect that any
> protection violation events the VM triggers are captured and forwarded
> as well?
>
> Basically any time a vSTE is in place we should capture events that
> are affiliated with the SID?

I see. I will drop this.

> > + if (!(nested_domain->ste[0] & cpu_to_le64(STRTAB_STE_0_V)))
> > + return 0;
> > +
> > + vsid = iommufd_viommu_get_vdev_id(&nested_domain->vsmmu->core,
> > + state->master->dev);
> > + /* Fail the attach if vSID is not correct set by the user space */
> > + if (!vsid)
> > + return -ENOENT;
>
> Is it really OK that 0 is being used as invalid here?

Hmm, perhaps better to do an int function for -ENOENT. Will fix
this.

Thanks
Nicolin