Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iommufd/selftest: Add set_dev_pasid in mock iommu

The callback is needed to make pasid_attach/detach path complete for mock
device. A nop is enough for set_dev_pasid.

A MOCK_FLAGS_DEVICE_PASID is added to indicate a pasid-capable mock device
for the pasid test cases. Other test cases will still create a non-pasid
mock device. While the mock iommu always pretends to be pasid-capable.

Link: https://patch.msgid.link/r/20250321171940.7213-16-yi.l.liu@intel.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Yi Liu and committed by
Jason Gunthorpe
9eb59204 dbc5f37b

+36 -5
+4
drivers/iommu/iommufd/iommufd_test.h
··· 49 49 enum { 50 50 MOCK_FLAGS_DEVICE_NO_DIRTY = 1 << 0, 51 51 MOCK_FLAGS_DEVICE_HUGE_IOVA = 1 << 1, 52 + MOCK_FLAGS_DEVICE_PASID = 1 << 2, 52 53 }; 53 54 54 55 enum { ··· 154 153 __u32 last; 155 154 }; 156 155 #define IOMMU_TEST_CMD _IO(IOMMUFD_TYPE, IOMMUFD_CMD_BASE + 32) 156 + 157 + /* Mock device/iommu PASID width */ 158 + #define MOCK_PASID_WIDTH 20 157 159 158 160 /* Mock structs for IOMMU_DEVICE_GET_HW_INFO ioctl */ 159 161 #define IOMMU_HW_INFO_TYPE_SELFTEST 0xfeedbeef
+32 -5
drivers/iommu/iommufd/selftest.c
··· 223 223 return 0; 224 224 } 225 225 226 + static int mock_domain_set_dev_pasid_nop(struct iommu_domain *domain, 227 + struct device *dev, ioasid_t pasid, 228 + struct iommu_domain *old) 229 + { 230 + return 0; 231 + } 232 + 226 233 static const struct iommu_domain_ops mock_blocking_ops = { 227 234 .attach_dev = mock_domain_nop_attach, 235 + .set_dev_pasid = mock_domain_set_dev_pasid_nop 228 236 }; 229 237 230 238 static struct iommu_domain mock_blocking_domain = { ··· 374 366 struct mock_iommu_domain_nested *mock_nested; 375 367 struct mock_iommu_domain *mock_parent; 376 368 377 - if (flags) 369 + if (flags & ~IOMMU_HWPT_ALLOC_PASID) 378 370 return ERR_PTR(-EOPNOTSUPP); 379 371 if (!parent || parent->ops != mock_ops.default_domain_ops) 380 372 return ERR_PTR(-EINVAL); ··· 396 388 { 397 389 bool has_dirty_flag = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING; 398 390 const u32 PAGING_FLAGS = IOMMU_HWPT_ALLOC_DIRTY_TRACKING | 399 - IOMMU_HWPT_ALLOC_NEST_PARENT; 391 + IOMMU_HWPT_ALLOC_NEST_PARENT | 392 + IOMMU_HWPT_ALLOC_PASID; 400 393 struct mock_dev *mdev = to_mock_dev(dev); 401 394 bool no_dirty_ops = mdev->flags & MOCK_FLAGS_DEVICE_NO_DIRTY; 402 395 struct mock_iommu_domain *mock; ··· 617 608 struct mock_viommu *mock_viommu = to_mock_viommu(viommu); 618 609 struct mock_iommu_domain_nested *mock_nested; 619 610 620 - if (flags) 611 + if (flags & ~IOMMU_HWPT_ALLOC_PASID) 621 612 return ERR_PTR(-EOPNOTSUPP); 622 613 623 614 mock_nested = __mock_domain_alloc_nested(user_data); ··· 752 743 .map_pages = mock_domain_map_pages, 753 744 .unmap_pages = mock_domain_unmap_pages, 754 745 .iova_to_phys = mock_domain_iova_to_phys, 746 + .set_dev_pasid = mock_domain_set_dev_pasid_nop, 755 747 }, 756 748 }; 757 749 ··· 813 803 .free = mock_domain_free_nested, 814 804 .attach_dev = mock_domain_nop_attach, 815 805 .cache_invalidate_user = mock_domain_cache_invalidate_user, 806 + .set_dev_pasid = mock_domain_set_dev_pasid_nop, 816 807 }; 817 808 818 809 static inline struct iommufd_hw_pagetable * ··· 873 862 874 863 static struct mock_dev *mock_dev_create(unsigned long dev_flags) 875 864 { 865 + struct property_entry prop[] = { 866 + PROPERTY_ENTRY_U32("pasid-num-bits", 0), 867 + {}, 868 + }; 869 + const u32 valid_flags = MOCK_FLAGS_DEVICE_NO_DIRTY | 870 + MOCK_FLAGS_DEVICE_HUGE_IOVA | 871 + MOCK_FLAGS_DEVICE_PASID; 876 872 struct mock_dev *mdev; 877 873 int rc, i; 878 874 879 - if (dev_flags & 880 - ~(MOCK_FLAGS_DEVICE_NO_DIRTY | MOCK_FLAGS_DEVICE_HUGE_IOVA)) 875 + if (dev_flags & ~valid_flags) 881 876 return ERR_PTR(-EINVAL); 882 877 883 878 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); ··· 906 889 rc = dev_set_name(&mdev->dev, "iommufd_mock%u", mdev->id); 907 890 if (rc) 908 891 goto err_put; 892 + 893 + if (dev_flags & MOCK_FLAGS_DEVICE_PASID) 894 + prop[0] = PROPERTY_ENTRY_U32("pasid-num-bits", MOCK_PASID_WIDTH); 895 + 896 + rc = device_create_managed_software_node(&mdev->dev, prop, NULL); 897 + if (rc) { 898 + dev_err(&mdev->dev, "add pasid-num-bits property failed, rc: %d", rc); 899 + goto err_put; 900 + } 909 901 910 902 rc = device_add(&mdev->dev); 911 903 if (rc) ··· 1804 1778 init_completion(&mock_iommu.complete); 1805 1779 1806 1780 mock_iommu_iopf_queue = iopf_queue_alloc("mock-iopfq"); 1781 + mock_iommu.iommu_dev.max_pasids = (1 << MOCK_PASID_WIDTH); 1807 1782 1808 1783 return 0; 1809 1784