]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iommupt: Always add IOVA range to iotlb_gather in gather_range_pages()
authorYu Zhang <zhangyu1@linux.microsoft.com>
Tue, 3 Feb 2026 08:29:34 +0000 (16:29 +0800)
committerJoerg Roedel <joerg.roedel@amd.com>
Tue, 3 Feb 2026 13:36:21 +0000 (14:36 +0100)
Add current (iova, len) to the iotlb gather, regardless of the setting
of PT_FEAT_FLUSH_RANGE or PT_FEAT_FLUSH_RANGE_NO_GAPS.

In gather_range_pages(), the current IOVA range is only added to
iotlb_gather when PT_FEAT_FLUSH_RANGE is set. Yet a virtual IOMMU with
NpCache uses only PT_FEAT_FLUSH_RANGE_NO_GAPS. In that case, iotlb_gather
will stay empty (start=ULONG_MAX, end=0) after initialization, and the
current (iova, len) will not be added to the iotlb_gather, causing
subsequent iommu_iotlb_sync() to perform IOTLB invalidation with wrong
parameters (e.g., amd_iommu_iotlb_sync() computes size from
gather->end - gather->start + 1, leading to an invalid range).

The disjoint check and sync for PT_FEAT_FLUSH_RANGE_NO_GAPS remain
unchanged: when the new range is disjoint from the existing gather,
we still sync first and then add the new range, so semantics for
NO_GAPS are preserved.

Fixes: 7c53f4238aa8 ("iommupt: Add unmap_pages op")
Cc: stable@vger.kernel.org
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Yu Zhang <zhangyu1@linux.microsoft.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
drivers/iommu/generic_pt/iommu_pt.h

index 3327116a441cace111c34d34ae4f2c95c8c2df22..6de22fa6bb34f337b9b930d72e32e39709cfe941 100644 (file)
@@ -58,10 +58,9 @@ static void gather_range_pages(struct iommu_iotlb_gather *iotlb_gather,
                 * Note that the sync frees the gather's free list, so we must
                 * not have any pages on that list that are covered by iova/len
                 */
-       } else if (pt_feature(common, PT_FEAT_FLUSH_RANGE)) {
-               iommu_iotlb_gather_add_range(iotlb_gather, iova, len);
        }
 
+       iommu_iotlb_gather_add_range(iotlb_gather, iova, len);
        iommu_pages_list_splice(free_list, &iotlb_gather->freelist);
 }