mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-05 16:37:50 +00:00
iommufd/selftest: Add domain_alloc_user() support in iommu mock
Add mock_domain_alloc_user() and a new test case for IOMMU_HWPT_ALLOC_NEST_PARENT. Link: https://lore.kernel.org/r/20230928071528.26258-6-yi.l.liu@intel.com Co-developed-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Signed-off-by: Yi Liu <yi.l.liu@intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
This commit is contained in:
parent
4ff5421633
commit
408663619f
4 changed files with 48 additions and 8 deletions
|
@ -146,6 +146,8 @@ static void *mock_domain_hw_info(struct device *dev, u32 *length, u32 *type)
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const struct iommu_ops mock_ops;
|
||||||
|
|
||||||
static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
|
static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
|
||||||
{
|
{
|
||||||
struct mock_iommu_domain *mock;
|
struct mock_iommu_domain *mock;
|
||||||
|
@ -162,10 +164,26 @@ static struct iommu_domain *mock_domain_alloc(unsigned int iommu_domain_type)
|
||||||
mock->domain.geometry.aperture_start = MOCK_APERTURE_START;
|
mock->domain.geometry.aperture_start = MOCK_APERTURE_START;
|
||||||
mock->domain.geometry.aperture_end = MOCK_APERTURE_LAST;
|
mock->domain.geometry.aperture_end = MOCK_APERTURE_LAST;
|
||||||
mock->domain.pgsize_bitmap = MOCK_IO_PAGE_SIZE;
|
mock->domain.pgsize_bitmap = MOCK_IO_PAGE_SIZE;
|
||||||
|
mock->domain.ops = mock_ops.default_domain_ops;
|
||||||
|
mock->domain.type = iommu_domain_type;
|
||||||
xa_init(&mock->pfns);
|
xa_init(&mock->pfns);
|
||||||
return &mock->domain;
|
return &mock->domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct iommu_domain *
|
||||||
|
mock_domain_alloc_user(struct device *dev, u32 flags)
|
||||||
|
{
|
||||||
|
struct iommu_domain *domain;
|
||||||
|
|
||||||
|
if (flags & (~IOMMU_HWPT_ALLOC_NEST_PARENT))
|
||||||
|
return ERR_PTR(-EOPNOTSUPP);
|
||||||
|
|
||||||
|
domain = mock_domain_alloc(IOMMU_DOMAIN_UNMANAGED);
|
||||||
|
if (!domain)
|
||||||
|
domain = ERR_PTR(-ENOMEM);
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
static void mock_domain_free(struct iommu_domain *domain)
|
static void mock_domain_free(struct iommu_domain *domain)
|
||||||
{
|
{
|
||||||
struct mock_iommu_domain *mock =
|
struct mock_iommu_domain *mock =
|
||||||
|
@ -307,6 +325,7 @@ static const struct iommu_ops mock_ops = {
|
||||||
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
|
.pgsize_bitmap = MOCK_IO_PAGE_SIZE,
|
||||||
.hw_info = mock_domain_hw_info,
|
.hw_info = mock_domain_hw_info,
|
||||||
.domain_alloc = mock_domain_alloc,
|
.domain_alloc = mock_domain_alloc,
|
||||||
|
.domain_alloc_user = mock_domain_alloc_user,
|
||||||
.capable = mock_domain_capable,
|
.capable = mock_domain_capable,
|
||||||
.set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
|
.set_platform_dma_ops = mock_domain_set_plaform_dma_ops,
|
||||||
.device_group = generic_device_group,
|
.device_group = generic_device_group,
|
||||||
|
|
|
@ -114,6 +114,7 @@ TEST_F(iommufd, cmd_length)
|
||||||
|
|
||||||
TEST_LENGTH(iommu_destroy, IOMMU_DESTROY);
|
TEST_LENGTH(iommu_destroy, IOMMU_DESTROY);
|
||||||
TEST_LENGTH(iommu_hw_info, IOMMU_GET_HW_INFO);
|
TEST_LENGTH(iommu_hw_info, IOMMU_GET_HW_INFO);
|
||||||
|
TEST_LENGTH(iommu_hwpt_alloc, IOMMU_HWPT_ALLOC);
|
||||||
TEST_LENGTH(iommu_ioas_alloc, IOMMU_IOAS_ALLOC);
|
TEST_LENGTH(iommu_ioas_alloc, IOMMU_IOAS_ALLOC);
|
||||||
TEST_LENGTH(iommu_ioas_iova_ranges, IOMMU_IOAS_IOVA_RANGES);
|
TEST_LENGTH(iommu_ioas_iova_ranges, IOMMU_IOAS_IOVA_RANGES);
|
||||||
TEST_LENGTH(iommu_ioas_allow_iovas, IOMMU_IOAS_ALLOW_IOVAS);
|
TEST_LENGTH(iommu_ioas_allow_iovas, IOMMU_IOAS_ALLOW_IOVAS);
|
||||||
|
@ -1404,13 +1405,28 @@ TEST_F(iommufd_mock_domain, alloc_hwpt)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i != variant->mock_domains; i++) {
|
for (i = 0; i != variant->mock_domains; i++) {
|
||||||
|
uint32_t hwpt_id[2];
|
||||||
uint32_t stddev_id;
|
uint32_t stddev_id;
|
||||||
uint32_t hwpt_id;
|
|
||||||
|
|
||||||
test_cmd_hwpt_alloc(self->idev_ids[i], self->ioas_id, &hwpt_id);
|
test_err_hwpt_alloc(EOPNOTSUPP,
|
||||||
test_cmd_mock_domain(hwpt_id, &stddev_id, NULL, NULL);
|
self->idev_ids[i], self->ioas_id,
|
||||||
|
~IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id[0]);
|
||||||
|
test_cmd_hwpt_alloc(self->idev_ids[i], self->ioas_id,
|
||||||
|
0, &hwpt_id[0]);
|
||||||
|
test_cmd_hwpt_alloc(self->idev_ids[i], self->ioas_id,
|
||||||
|
IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id[1]);
|
||||||
|
|
||||||
|
/* Do a hw_pagetable rotation test */
|
||||||
|
test_cmd_mock_domain_replace(self->stdev_ids[i], hwpt_id[0]);
|
||||||
|
EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, hwpt_id[0]));
|
||||||
|
test_cmd_mock_domain_replace(self->stdev_ids[i], hwpt_id[1]);
|
||||||
|
EXPECT_ERRNO(EBUSY, _test_ioctl_destroy(self->fd, hwpt_id[1]));
|
||||||
|
test_cmd_mock_domain_replace(self->stdev_ids[i], self->ioas_id);
|
||||||
|
test_ioctl_destroy(hwpt_id[1]);
|
||||||
|
|
||||||
|
test_cmd_mock_domain(hwpt_id[0], &stddev_id, NULL, NULL);
|
||||||
test_ioctl_destroy(stddev_id);
|
test_ioctl_destroy(stddev_id);
|
||||||
test_ioctl_destroy(hwpt_id);
|
test_ioctl_destroy(hwpt_id[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -615,7 +615,7 @@ TEST_FAIL_NTH(basic_fail_nth, device)
|
||||||
if (_test_cmd_get_hw_info(self->fd, idev_id, &info, sizeof(info)))
|
if (_test_cmd_get_hw_info(self->fd, idev_id, &info, sizeof(info)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, &hwpt_id))
|
if (_test_cmd_hwpt_alloc(self->fd, idev_id, ioas_id, 0, &hwpt_id))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (_test_cmd_mock_domain_replace(self->fd, stdev_id, ioas_id2, NULL))
|
if (_test_cmd_mock_domain_replace(self->fd, stdev_id, ioas_id2, NULL))
|
||||||
|
|
|
@ -103,10 +103,11 @@ static int _test_cmd_mock_domain_replace(int fd, __u32 stdev_id, __u32 pt_id,
|
||||||
pt_id, NULL))
|
pt_id, NULL))
|
||||||
|
|
||||||
static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id,
|
static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id,
|
||||||
__u32 *hwpt_id)
|
__u32 flags, __u32 *hwpt_id)
|
||||||
{
|
{
|
||||||
struct iommu_hwpt_alloc cmd = {
|
struct iommu_hwpt_alloc cmd = {
|
||||||
.size = sizeof(cmd),
|
.size = sizeof(cmd),
|
||||||
|
.flags = flags,
|
||||||
.dev_id = device_id,
|
.dev_id = device_id,
|
||||||
.pt_id = pt_id,
|
.pt_id = pt_id,
|
||||||
};
|
};
|
||||||
|
@ -120,8 +121,12 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define test_cmd_hwpt_alloc(device_id, pt_id, hwpt_id) \
|
#define test_cmd_hwpt_alloc(device_id, pt_id, flags, hwpt_id) \
|
||||||
ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, pt_id, hwpt_id))
|
ASSERT_EQ(0, _test_cmd_hwpt_alloc(self->fd, device_id, \
|
||||||
|
pt_id, flags, hwpt_id))
|
||||||
|
#define test_err_hwpt_alloc(_errno, device_id, pt_id, flags, hwpt_id) \
|
||||||
|
EXPECT_ERRNO(_errno, _test_cmd_hwpt_alloc(self->fd, device_id, \
|
||||||
|
pt_id, flags, hwpt_id))
|
||||||
|
|
||||||
static int _test_cmd_access_replace_ioas(int fd, __u32 access_id,
|
static int _test_cmd_access_replace_ioas(int fd, __u32 access_id,
|
||||||
unsigned int ioas_id)
|
unsigned int ioas_id)
|
||||||
|
|
Loading…
Reference in a new issue