[PATCH v1 07/12] iommu/arm-smmu-v3: Implement arm_smmu_get_viommu_size and arm_vsmmu_init

Tian, Kevin kevin.tian at intel.com
Thu Jun 12 01:20:30 PDT 2025


> From: Nicolin Chen <nicolinc at nvidia.com>
> Sent: Tuesday, June 10, 2025 1:14 AM
> 
> +int arm_smmu_get_viommu_size(enum iommu_viommu_type
> viommu_type,
> +			     struct device *dev, size_t *viommu_size)
> +{
> +	struct arm_smmu_master *master = dev_iommu_priv_get(dev);
> +	struct arm_smmu_device *smmu = master->smmu;
> +
> +	if (!(smmu->features & ARM_SMMU_FEAT_NESTING))
> +		return -EOPNOTSUPP;
> +
> +	/*
> +	 * FORCE_SYNC is not set with FEAT_NESTING. Some study of the
> exact HW
> +	 * defect is needed to determine if arm_vsmmu_cache_invalidate()
> needs
> +	 * any change to remove this.
> +	 */
> +	if (WARN_ON(smmu->options &
> ARM_SMMU_OPT_CMDQ_FORCE_SYNC))
> +		return -EOPNOTSUPP;
> +
> +	/*
> +	 * Must support some way to prevent the VM from bypassing the
> cache
> +	 * because VFIO currently does not do any cache maintenance.
> canwbs
> +	 * indicates the device is fully coherent and no cache maintenance is
> +	 * ever required, even for PCI No-Snoop. S2FWB means the S1 can't
> make
> +	 * things non-coherent using the memattr, but No-Snoop behavior is
> not
> +	 * effected.
> +	 */
> +	if (!arm_smmu_master_canwbs(master) &&
> +	    !(smmu->features & ARM_SMMU_FEAT_S2FWB))
> +		return -EOPNOTSUPP;
> +
> +	if (viommu_type != IOMMU_VIOMMU_TYPE_ARM_SMMUV3)
> +		return -EOPNOTSUPP;

it's more intuitive to check it first.

btw does it make sense to also add below here?
	if (s2_parent->smmu != master->smmu)
		return ERR_PTR(-EINVAL);



More information about the linux-arm-kernel mailing list