From: Nicolin Chen <nicolinc@nvidia.com> To: <will@kernel.org>, <robin.murphy@arm.com>, <jgg@nvidia.com>, <kevin.tian@intel.com>, <suravee.suthikulpanit@amd.com> Cc: <joro@8bytes.org>, <linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>, <linux-arm-kernel@lists.infradead.org>, <linux-tegra@vger.kernel.org>, <yi.l.liu@intel.com>, <eric.auger@redhat.com>, <vasant.hegde@amd.com>, <jon.grimm@amd.com>, <santosh.shukla@amd.com>, <Dhaval.Giani@amd.com>, <shameerali.kolothum.thodi@huawei.com> Subject: [PATCH RFCv1 09/14] iommufd/selftest: Add IOMMU_VIOMMU_SET_DEV_ID test coverage Date: Fri, 12 Apr 2024 20:47:06 -0700 [thread overview] Message-ID: <80bd0cdd1108ff9247098b82a5b6bb0ea43c5ad1.1712978213.git.nicolinc@nvidia.com> (raw) In-Reply-To: <cover.1712978212.git.nicolinc@nvidia.com> Add an xarray to store the array of virtual ids to mock_devs, to cover the new IOMMU_VIOMMU_SET_DEV_ID ioctl. Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> --- drivers/iommu/iommufd/selftest.c | 50 +++++++++++++++++++ tools/testing/selftests/iommu/iommufd.c | 14 ++++++ tools/testing/selftests/iommu/iommufd_utils.h | 21 ++++++++ 3 files changed, 85 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index e2fc2ec23093..4caed9304065 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -139,6 +139,7 @@ struct mock_dev { struct device dev; unsigned long flags; int id; + unsigned int id_user; }; struct selftest_obj { @@ -516,6 +517,53 @@ static struct iommu_device *mock_probe_device(struct device *dev) struct mock_viommu { struct iommufd_viommu core; + struct xarray ids; +}; + +static void mock_viommu_free(struct iommufd_viommu *viommu) +{ + struct mock_viommu *mv = container_of(viommu, struct mock_viommu, core); + struct device *dev; + unsigned long index; + + xa_for_each(&mv->ids, index, dev) + xa_erase(&mv->ids, index); + xa_destroy(&mv->ids); +} + +static int mock_viommu_set_dev_id(struct iommufd_viommu *viommu, + struct device *dev, u64 dev_id) +{ + struct mock_viommu *mv = container_of(viommu, struct mock_viommu, core); + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + u32 id = (u32)dev_id; + int rc; + + if (dev_id > UINT_MAX) + return -EINVAL; + if (mdev->id_user > 0) + return -EBUSY; + rc = xa_alloc(&mv->ids, &id, dev, XA_LIMIT(id, id), GFP_KERNEL); + if (rc) + return rc; + mdev->id_user = (unsigned int)dev_id; + return 0; +} + +static void mock_viommu_unset_dev_id(struct iommufd_viommu *viommu, + struct device *dev) +{ + struct mock_viommu *mv = container_of(viommu, struct mock_viommu, core); + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + + WARN_ON(dev != xa_erase(&mv->ids, mdev->id_user)); + mdev->id_user = 0; +} + +static const struct iommufd_viommu_ops mock_viommu_ops = { + .free = mock_viommu_free, + .set_dev_id = mock_viommu_set_dev_id, + .unset_dev_id = mock_viommu_unset_dev_id, }; static struct iommufd_viommu *mock_viommu_alloc(struct device *dev, @@ -527,6 +575,8 @@ static struct iommufd_viommu *mock_viommu_alloc(struct device *dev, mv = iommufd_viommu_alloc(mock_viommu, core); if (!mv) return ERR_PTR(-ENOMEM); + mv->core.ops = &mock_viommu_ops; + xa_init_flags(&mv->ids, XA_FLAGS_ALLOC1); return &mv->core; } diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index dd7b7c7a06c6..378fbf00730e 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -271,6 +271,9 @@ TEST_F(iommufd_ioas, viommu) uint32_t dev_id = self->device_id; uint32_t viommu_id = 0; uint32_t hwpt_id = 0; + uint32_t device2; + uint32_t stdev2; + uint32_t hwpt2; if (dev_id) { test_err_viommu_alloc(ENOENT, dev_id, hwpt_id, &viommu_id); @@ -282,10 +285,21 @@ TEST_F(iommufd_ioas, viommu) IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id); test_cmd_viommu_alloc(dev_id, hwpt_id, &viommu_id); + test_err_viommu_set_dev_id(EINVAL, dev_id, viommu_id, 1ULL << 32); + test_cmd_viommu_set_dev_id(dev_id, viommu_id, 0x99); + test_err_viommu_set_dev_id(EBUSY, dev_id, viommu_id, 0x99); + + test_cmd_mock_domain(self->ioas_id, &stdev2, &hwpt2, &device2); + test_err_viommu_set_dev_id(EBUSY, device2, viommu_id, 0x99); + test_cmd_viommu_set_dev_id(device2, viommu_id, 0xaa); + test_err_viommu_set_dev_id(EBUSY, device2, viommu_id, 0xaa); + test_ioctl_destroy(stdev2); + test_ioctl_destroy(viommu_id); test_ioctl_destroy(hwpt_id); } else { test_err_viommu_alloc(ENOENT, dev_id, hwpt_id, &viommu_id); + test_err_viommu_set_dev_id(ENOENT, dev_id, viommu_id, 99); } } diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 037c84189d50..81e9184fd1d5 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -710,3 +710,24 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id, #define test_err_viommu_alloc(_errno, device_id, hwpt_id, viommu_id) \ EXPECT_ERRNO(_errno, _test_cmd_viommu_alloc(self->fd, device_id, \ hwpt_id, 0, viommu_id)) + +static int _test_cmd_viommu_set_dev_id(int fd, __u32 device_id, + __u32 viommu_id, __u64 virtual_id) +{ + struct iommu_viommu_set_dev_id cmd = { + .size = sizeof(cmd), + .dev_id = device_id, + .viommu_id = viommu_id, + .id = virtual_id, + }; + + return ioctl(fd, IOMMU_VIOMMU_SET_DEV_ID, &cmd); +} + +#define test_cmd_viommu_set_dev_id(device_id, viommu_id, virtual_id) \ + ASSERT_EQ(0, _test_cmd_viommu_set_dev_id(self->fd, device_id, \ + viommu_id, virtual_id)) +#define test_err_viommu_set_dev_id(_errno, device_id, viommu_id, virtual_id) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_viommu_set_dev_id(self->fd, device_id, \ + viommu_id, virtual_id)) -- 2.43.0
WARNING: multiple messages have this Message-ID (diff)
From: Nicolin Chen <nicolinc@nvidia.com> To: <will@kernel.org>, <robin.murphy@arm.com>, <jgg@nvidia.com>, <kevin.tian@intel.com>, <suravee.suthikulpanit@amd.com> Cc: <joro@8bytes.org>, <linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>, <linux-arm-kernel@lists.infradead.org>, <linux-tegra@vger.kernel.org>, <yi.l.liu@intel.com>, <eric.auger@redhat.com>, <vasant.hegde@amd.com>, <jon.grimm@amd.com>, <santosh.shukla@amd.com>, <Dhaval.Giani@amd.com>, <shameerali.kolothum.thodi@huawei.com> Subject: [PATCH RFCv1 09/14] iommufd/selftest: Add IOMMU_VIOMMU_SET_DEV_ID test coverage Date: Fri, 12 Apr 2024 20:47:06 -0700 [thread overview] Message-ID: <80bd0cdd1108ff9247098b82a5b6bb0ea43c5ad1.1712978213.git.nicolinc@nvidia.com> (raw) In-Reply-To: <cover.1712978212.git.nicolinc@nvidia.com> Add an xarray to store the array of virtual ids to mock_devs, to cover the new IOMMU_VIOMMU_SET_DEV_ID ioctl. Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> --- drivers/iommu/iommufd/selftest.c | 50 +++++++++++++++++++ tools/testing/selftests/iommu/iommufd.c | 14 ++++++ tools/testing/selftests/iommu/iommufd_utils.h | 21 ++++++++ 3 files changed, 85 insertions(+) diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c index e2fc2ec23093..4caed9304065 100644 --- a/drivers/iommu/iommufd/selftest.c +++ b/drivers/iommu/iommufd/selftest.c @@ -139,6 +139,7 @@ struct mock_dev { struct device dev; unsigned long flags; int id; + unsigned int id_user; }; struct selftest_obj { @@ -516,6 +517,53 @@ static struct iommu_device *mock_probe_device(struct device *dev) struct mock_viommu { struct iommufd_viommu core; + struct xarray ids; +}; + +static void mock_viommu_free(struct iommufd_viommu *viommu) +{ + struct mock_viommu *mv = container_of(viommu, struct mock_viommu, core); + struct device *dev; + unsigned long index; + + xa_for_each(&mv->ids, index, dev) + xa_erase(&mv->ids, index); + xa_destroy(&mv->ids); +} + +static int mock_viommu_set_dev_id(struct iommufd_viommu *viommu, + struct device *dev, u64 dev_id) +{ + struct mock_viommu *mv = container_of(viommu, struct mock_viommu, core); + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + u32 id = (u32)dev_id; + int rc; + + if (dev_id > UINT_MAX) + return -EINVAL; + if (mdev->id_user > 0) + return -EBUSY; + rc = xa_alloc(&mv->ids, &id, dev, XA_LIMIT(id, id), GFP_KERNEL); + if (rc) + return rc; + mdev->id_user = (unsigned int)dev_id; + return 0; +} + +static void mock_viommu_unset_dev_id(struct iommufd_viommu *viommu, + struct device *dev) +{ + struct mock_viommu *mv = container_of(viommu, struct mock_viommu, core); + struct mock_dev *mdev = container_of(dev, struct mock_dev, dev); + + WARN_ON(dev != xa_erase(&mv->ids, mdev->id_user)); + mdev->id_user = 0; +} + +static const struct iommufd_viommu_ops mock_viommu_ops = { + .free = mock_viommu_free, + .set_dev_id = mock_viommu_set_dev_id, + .unset_dev_id = mock_viommu_unset_dev_id, }; static struct iommufd_viommu *mock_viommu_alloc(struct device *dev, @@ -527,6 +575,8 @@ static struct iommufd_viommu *mock_viommu_alloc(struct device *dev, mv = iommufd_viommu_alloc(mock_viommu, core); if (!mv) return ERR_PTR(-ENOMEM); + mv->core.ops = &mock_viommu_ops; + xa_init_flags(&mv->ids, XA_FLAGS_ALLOC1); return &mv->core; } diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c index dd7b7c7a06c6..378fbf00730e 100644 --- a/tools/testing/selftests/iommu/iommufd.c +++ b/tools/testing/selftests/iommu/iommufd.c @@ -271,6 +271,9 @@ TEST_F(iommufd_ioas, viommu) uint32_t dev_id = self->device_id; uint32_t viommu_id = 0; uint32_t hwpt_id = 0; + uint32_t device2; + uint32_t stdev2; + uint32_t hwpt2; if (dev_id) { test_err_viommu_alloc(ENOENT, dev_id, hwpt_id, &viommu_id); @@ -282,10 +285,21 @@ TEST_F(iommufd_ioas, viommu) IOMMU_HWPT_ALLOC_NEST_PARENT, &hwpt_id); test_cmd_viommu_alloc(dev_id, hwpt_id, &viommu_id); + test_err_viommu_set_dev_id(EINVAL, dev_id, viommu_id, 1ULL << 32); + test_cmd_viommu_set_dev_id(dev_id, viommu_id, 0x99); + test_err_viommu_set_dev_id(EBUSY, dev_id, viommu_id, 0x99); + + test_cmd_mock_domain(self->ioas_id, &stdev2, &hwpt2, &device2); + test_err_viommu_set_dev_id(EBUSY, device2, viommu_id, 0x99); + test_cmd_viommu_set_dev_id(device2, viommu_id, 0xaa); + test_err_viommu_set_dev_id(EBUSY, device2, viommu_id, 0xaa); + test_ioctl_destroy(stdev2); + test_ioctl_destroy(viommu_id); test_ioctl_destroy(hwpt_id); } else { test_err_viommu_alloc(ENOENT, dev_id, hwpt_id, &viommu_id); + test_err_viommu_set_dev_id(ENOENT, dev_id, viommu_id, 99); } } diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h index 037c84189d50..81e9184fd1d5 100644 --- a/tools/testing/selftests/iommu/iommufd_utils.h +++ b/tools/testing/selftests/iommu/iommufd_utils.h @@ -710,3 +710,24 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id, #define test_err_viommu_alloc(_errno, device_id, hwpt_id, viommu_id) \ EXPECT_ERRNO(_errno, _test_cmd_viommu_alloc(self->fd, device_id, \ hwpt_id, 0, viommu_id)) + +static int _test_cmd_viommu_set_dev_id(int fd, __u32 device_id, + __u32 viommu_id, __u64 virtual_id) +{ + struct iommu_viommu_set_dev_id cmd = { + .size = sizeof(cmd), + .dev_id = device_id, + .viommu_id = viommu_id, + .id = virtual_id, + }; + + return ioctl(fd, IOMMU_VIOMMU_SET_DEV_ID, &cmd); +} + +#define test_cmd_viommu_set_dev_id(device_id, viommu_id, virtual_id) \ + ASSERT_EQ(0, _test_cmd_viommu_set_dev_id(self->fd, device_id, \ + viommu_id, virtual_id)) +#define test_err_viommu_set_dev_id(_errno, device_id, viommu_id, virtual_id) \ + EXPECT_ERRNO(_errno, \ + _test_cmd_viommu_set_dev_id(self->fd, device_id, \ + viommu_id, virtual_id)) -- 2.43.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2024-04-13 3:48 UTC|newest] Thread overview: 88+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-04-13 3:46 [PATCH RFCv1 00/14] Add Tegra241 (Grace) CMDQV Support (part 2/2) Nicolin Chen 2024-04-13 3:46 ` Nicolin Chen 2024-04-13 3:46 ` [PATCH RFCv1 01/14] iommufd: Move iommufd_object to public iommufd header Nicolin Chen 2024-04-13 3:46 ` Nicolin Chen 2024-05-12 13:21 ` Jason Gunthorpe 2024-05-12 13:21 ` Jason Gunthorpe 2024-05-12 22:40 ` Nicolin Chen 2024-05-12 22:40 ` Nicolin Chen 2024-05-13 22:30 ` Jason Gunthorpe 2024-05-13 22:30 ` Jason Gunthorpe 2024-04-13 3:46 ` [PATCH RFCv1 02/14] iommufd: Swap _iommufd_object_alloc and __iommufd_object_alloc Nicolin Chen 2024-04-13 3:46 ` Nicolin Chen 2024-05-12 13:26 ` Jason Gunthorpe 2024-05-12 13:26 ` Jason Gunthorpe 2024-05-13 2:29 ` Nicolin Chen 2024-05-13 2:29 ` Nicolin Chen 2024-05-13 3:44 ` Nicolin Chen 2024-05-13 3:44 ` Nicolin Chen 2024-05-13 22:30 ` Jason Gunthorpe 2024-05-13 22:30 ` Jason Gunthorpe 2024-04-13 3:47 ` [PATCH RFCv1 03/14] iommufd: Prepare for viommu structures and functions Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-05-12 13:42 ` Jason Gunthorpe 2024-05-12 13:42 ` Jason Gunthorpe 2024-05-13 2:35 ` Nicolin Chen 2024-05-13 2:35 ` Nicolin Chen 2024-04-13 3:47 ` [PATCH RFCv1 04/14] iommufd: Add struct iommufd_viommu and iommufd_viommu_ops Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-05-12 14:03 ` Jason Gunthorpe 2024-05-12 14:03 ` Jason Gunthorpe 2024-05-13 3:34 ` Nicolin Chen 2024-05-13 3:34 ` Nicolin Chen 2024-05-14 15:55 ` Jason Gunthorpe 2024-05-14 15:55 ` Jason Gunthorpe 2024-04-13 3:47 ` [PATCH RFCv1 05/14] iommufd: Add IOMMUFD_OBJ_VIOMMU and IOMMUFD_CMD_VIOMMU_ALLOC Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-05-12 14:27 ` Jason Gunthorpe 2024-05-12 14:27 ` Jason Gunthorpe 2024-05-13 4:33 ` Nicolin Chen 2024-05-13 4:33 ` Nicolin Chen 2024-05-14 15:38 ` Jason Gunthorpe 2024-05-14 15:38 ` Jason Gunthorpe 2024-05-15 1:20 ` Nicolin Chen 2024-05-15 1:20 ` Nicolin Chen 2024-04-13 3:47 ` [PATCH RFCv1 06/14] iommufd/selftest: Add IOMMU_VIOMMU_ALLOC test coverage Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-04-13 3:47 ` [PATCH RFCv1 07/14] iommufd: Add viommu set/unset_dev_id ops Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-05-12 14:46 ` Jason Gunthorpe 2024-05-12 14:46 ` Jason Gunthorpe 2024-05-13 4:39 ` Nicolin Chen 2024-05-13 4:39 ` Nicolin Chen 2024-05-14 15:53 ` Jason Gunthorpe 2024-05-14 15:53 ` Jason Gunthorpe 2024-05-15 1:59 ` Nicolin Chen 2024-05-15 1:59 ` Nicolin Chen 2024-05-12 14:51 ` Jason Gunthorpe 2024-05-12 14:51 ` Jason Gunthorpe 2024-04-13 3:47 ` [PATCH RFCv1 08/14] iommufd: Add IOMMU_VIOMMU_SET_DEV_ID ioctl Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-05-12 14:58 ` Jason Gunthorpe 2024-05-12 14:58 ` Jason Gunthorpe 2024-05-13 5:24 ` Nicolin Chen 2024-05-13 5:24 ` Nicolin Chen 2024-05-17 5:14 ` Nicolin Chen 2024-05-17 5:14 ` Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen [this message] 2024-04-13 3:47 ` [PATCH RFCv1 09/14] iommufd/selftest: Add IOMMU_VIOMMU_SET_DEV_ID test coverage Nicolin Chen 2024-04-13 3:47 ` [PATCH RFCv1 10/14] iommufd/selftest: Add IOMMU_TEST_OP_MV_CHECK_DEV_ID Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-04-13 3:47 ` [PATCH RFCv1 11/14] iommufd: Add struct iommufd_vqueue and its related viommu ops Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-04-13 3:47 ` [PATCH RFCv1 12/14] iommufd: Add IOMMUFD_OBJ_VQUEUE and IOMMUFD_CMD_VQUEUE_ALLOC Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-05-12 15:02 ` Jason Gunthorpe 2024-05-12 15:02 ` Jason Gunthorpe 2024-05-13 4:41 ` Nicolin Chen 2024-05-13 4:41 ` Nicolin Chen 2024-05-13 22:36 ` Jason Gunthorpe 2024-05-13 22:36 ` Jason Gunthorpe 2024-04-13 3:47 ` [PATCH RFCv1 13/14] iommufd: Add mmap infrastructure Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen 2024-05-12 15:19 ` Jason Gunthorpe 2024-05-12 15:19 ` Jason Gunthorpe 2024-05-13 4:43 ` Nicolin Chen 2024-05-13 4:43 ` Nicolin Chen 2024-04-13 3:47 ` [PATCH RFCv1 14/14] iommu/tegra241-cmdqv: Add user-space use support Nicolin Chen 2024-04-13 3:47 ` Nicolin Chen
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=80bd0cdd1108ff9247098b82a5b6bb0ea43c5ad1.1712978213.git.nicolinc@nvidia.com \ --to=nicolinc@nvidia.com \ --cc=Dhaval.Giani@amd.com \ --cc=eric.auger@redhat.com \ --cc=iommu@lists.linux.dev \ --cc=jgg@nvidia.com \ --cc=jon.grimm@amd.com \ --cc=joro@8bytes.org \ --cc=kevin.tian@intel.com \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-tegra@vger.kernel.org \ --cc=robin.murphy@arm.com \ --cc=santosh.shukla@amd.com \ --cc=shameerali.kolothum.thodi@huawei.com \ --cc=suravee.suthikulpanit@amd.com \ --cc=vasant.hegde@amd.com \ --cc=will@kernel.org \ --cc=yi.l.liu@intel.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.