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.

iommupt: Add a mock pagetable format for iommufd selftest to use

The iommufd self test uses an xarray to store the pfns and their orders to
emulate a page table. Slightly modify the amdv1 page table to create a
real page table that has similar properties:

- 2k base granule to simulate something like a 4k page table on a 64K
PAGE_SIZE ARM system
- Contiguous page support for every PFN order
- Dirty tracking

AMDv1 is the closest format, as it is the only one that already supports
every page size. Tweak it to have only 5 levels and an 11 bit base granule
and compile it separately as a format variant.

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Samiullah Khawaja <skhawaja@google.com>
Tested-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
Tested-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>

authored by

Jason Gunthorpe and committed by
Joerg Roedel
e5359dcc 1dd4187f

+33 -2
+1
drivers/iommu/generic_pt/fmt/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 3 iommu_pt_fmt-$(CONFIG_IOMMU_PT_AMDV1) += amdv1 4 + iommu_pt_fmt-$(CONFIG_IOMMUFD_TEST) += mock 4 5 5 6 IOMMU_PT_KUNIT_TEST := 6 7 define create_format
+16 -2
drivers/iommu/generic_pt/fmt/amdv1.h
··· 26 26 #include <linux/string.h> 27 27 28 28 enum { 29 - PT_MAX_OUTPUT_ADDRESS_LG2 = 52, 30 - PT_MAX_VA_ADDRESS_LG2 = 64, 31 29 PT_ITEM_WORD_SIZE = sizeof(u64), 30 + /* 31 + * The IOMMUFD selftest uses the AMDv1 format with some alterations It 32 + * uses a 2k page size to test cases where the CPU page size is not the 33 + * same. 34 + */ 35 + #ifdef AMDV1_IOMMUFD_SELFTEST 36 + PT_MAX_VA_ADDRESS_LG2 = 56, 37 + PT_MAX_OUTPUT_ADDRESS_LG2 = 51, 38 + PT_MAX_TOP_LEVEL = 4, 39 + PT_GRANULE_LG2SZ = 11, 40 + #else 41 + PT_MAX_VA_ADDRESS_LG2 = 64, 42 + PT_MAX_OUTPUT_ADDRESS_LG2 = 52, 32 43 PT_MAX_TOP_LEVEL = 5, 33 44 PT_GRANULE_LG2SZ = 12, 45 + #endif 34 46 PT_TABLEMEM_LG2SZ = 12, 35 47 36 48 /* The DTE only has these bits for the top phyiscal address */ ··· 386 374 } 387 375 #define pt_iommu_fmt_init amdv1pt_iommu_fmt_init 388 376 377 + #ifndef PT_FMT_VARIANT 389 378 static inline void 390 379 amdv1pt_iommu_fmt_hw_info(struct pt_iommu_amdv1 *table, 391 380 const struct pt_range *top_range, ··· 397 384 info->mode = top_range->top_level + 1; 398 385 } 399 386 #define pt_iommu_fmt_hw_info amdv1pt_iommu_fmt_hw_info 387 + #endif 400 388 401 389 #if defined(GENERIC_PT_KUNIT) 402 390 static const struct pt_iommu_amdv1_cfg amdv1_kunit_fmt_cfgs[] = {
+10
drivers/iommu/generic_pt/fmt/iommu_mock.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (c) 2024-2025, NVIDIA CORPORATION & AFFILIATES 4 + */ 5 + #define AMDV1_IOMMUFD_SELFTEST 1 6 + #define PT_FMT amdv1 7 + #define PT_FMT_VARIANT mock 8 + #define PT_SUPPORTED_FEATURES 0 9 + 10 + #include "iommu_template.h"
+6
include/linux/generic_pt/iommu.h
··· 237 237 238 238 IOMMU_FORMAT(amdv1, amdpt); 239 239 240 + /* amdv1_mock is used by the iommufd selftest */ 241 + #define pt_iommu_amdv1_mock pt_iommu_amdv1 242 + #define pt_iommu_amdv1_mock_cfg pt_iommu_amdv1_cfg 243 + struct pt_iommu_amdv1_mock_hw_info; 244 + IOMMU_PROTOTYPES(amdv1_mock); 245 + 240 246 #undef IOMMU_PROTOTYPES 241 247 #undef IOMMU_FORMAT 242 248 #endif