]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iommu/arm-smmu-v3-iommufd: Allow attaching nested domain for GBPA cases
authorNicolin Chen <nicolinc@nvidia.com>
Mon, 3 Nov 2025 17:27:55 +0000 (09:27 -0800)
committerJason Gunthorpe <jgg@nvidia.com>
Wed, 26 Nov 2025 18:04:04 +0000 (14:04 -0400)
A vDEVICE has been a hard requirement for attaching a nested domain to the
device. This makes sense when installing a guest STE, since a vSID must be
present and given to the kernel during the vDEVICE allocation.

But, when CR0.SMMUEN is disabled, VM doesn't really need a vSID to program
the vSMMU behavior as GBPA will take effect, in which case the vSTE in the
nested domain could have carried the bypass or abort configuration in GBPA
register. Thus, having such a hard requirement doesn't work well for GBPA.

Skip vmaster allocation in arm_smmu_attach_prepare_vmaster() for an abort
or bypass vSTE. Note that device on this attachment won't report vevents.

Update the uAPI doc accordingly.

Link: https://patch.msgid.link/r/20251103172755.2026145-1-nicolinc@nvidia.com
Tested-by: Shameer Kolothum <skolothumtho@nvidia.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Pranjal Shrivastava <praan@google.com>
Tested-by: Shuai Xue <xueshuai@linux.alibaba.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
include/uapi/linux/iommufd.h

index 8cd8929bbfdf8102bd17c5a23942d7b054ebe2cc..e5fbbdbdea242dadd25e7b14c454cab38f45b07a 100644 (file)
@@ -99,6 +99,8 @@ static void arm_smmu_make_nested_domain_ste(
 int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state,
                                    struct arm_smmu_nested_domain *nested_domain)
 {
+       unsigned int cfg =
+               FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(nested_domain->ste[0]));
        struct arm_smmu_vmaster *vmaster;
        unsigned long vsid;
        int ret;
@@ -107,8 +109,17 @@ int arm_smmu_attach_prepare_vmaster(struct arm_smmu_attach_state *state,
 
        ret = iommufd_viommu_get_vdev_id(&nested_domain->vsmmu->core,
                                         state->master->dev, &vsid);
-       if (ret)
+       /*
+        * Attaching to a translate nested domain must allocate a vDEVICE prior,
+        * as CD/ATS invalidations and vevents require a vSID to work properly.
+        * A abort/bypass domain is allowed to attach w/o vmaster for GBPA case.
+        */
+       if (ret) {
+               if (cfg == STRTAB_STE_0_CFG_ABORT ||
+                   cfg == STRTAB_STE_0_CFG_BYPASS)
+                       return 0;
                return ret;
+       }
 
        vmaster = kzalloc(sizeof(*vmaster), GFP_KERNEL);
        if (!vmaster)
index c218c89e0e2ebd4ede6e1b5e8f3b8504ee6f26e2..2c41920b641dc13fa68effe66b4663f424262a5b 100644 (file)
@@ -450,6 +450,16 @@ struct iommu_hwpt_vtd_s1 {
  * nested domain will translate the same as the nesting parent. The S1 will
  * install a Context Descriptor Table pointing at userspace memory translated
  * by the nesting parent.
+ *
+ * It's suggested to allocate a vDEVICE object carrying vSID and then re-attach
+ * the nested domain, as soon as the vSID is available in the VMM level:
+ *
+ * - when Cfg=translate, a vDEVICE must be allocated prior to attaching to the
+ *   allocated nested domain, as CD/ATS invalidations and vevents need a vSID.
+ * - when Cfg=bypass/abort, a vDEVICE is not enforced during the nested domain
+ *   attachment, to support a GBPA case where VM sets CR0.SMMUEN=0. However, if
+ *   VM sets CR0.SMMUEN=1 while missing a vDEVICE object, kernel would fail to
+ *   report events to the VM. E.g. F_TRANSLATION when guest STE.Cfg=abort.
  */
 struct iommu_hwpt_arm_smmuv3 {
        __aligned_le64 ste[2];