* [PATCH v3] iommu: Clarify uAPI errno for unsupported data types
@ 2026-11-19 19:23 Pranjal Shrivastava
2026-11-19 19:54 ` Nicolin Chen
0 siblings, 1 reply; 2+ messages in thread
From: Pranjal Shrivastava @ 2026-11-19 19:23 UTC (permalink / raw)
To: Jason Gunthorpe, Nicolin Chen
Cc: Kevin Tian, Will Deacon, Robin Murphy, Joerg Roedel, Peter Shier,
iommu, Pranjal Shrivastava
The IOMMU_HWPT_INVALIDATE uAPI says that an empty request array "can be
used to check if the given @data_type is supported or not by kernel",
but not what to look for. And the iommu_copy_struct_*() helpers and the
Intel VT-d, ARM SMMUv3 and selftest invalidation ops reject unsupported
data types with -EINVAL, which means that the request was understood but
a field is not correct.
Return -EOPNOTSUPP for an unsupported data type instead and document it
as what the probe looks for. Since arm_vsmmu_alloc_domain_nested() uses
the copy helper, it now returns -EOPNOTSUPP, like the other nested
domain allocators. Update and extend the selftests accordingly.
Signed-off-by: Pranjal Shrivastava <praan@google.com>
---
.../arm/arm-smmu-v3/arm-smmu-v3-iommufd.c | 2 +-
drivers/iommu/intel/nested.c | 2 +-
drivers/iommu/iommufd/selftest.c | 4 ++--
include/linux/iommu.h | 6 +++---
include/uapi/linux/iommufd.h | 3 ++-
tools/testing/selftests/iommu/iommufd.c | 18 ++++++++++++++++--
6 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
index e68b46485095..51c2b13cf280 100644
--- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
+++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3-iommufd.c
@@ -493,7 +493,7 @@ int arm_vsmmu_cache_invalidate(struct iommufd_viommu *viommu,
static_assert(sizeof(*cmds) == 2 * sizeof(u64));
if (array->type != IOMMU_VIOMMU_INVALIDATE_DATA_ARM_SMMUV3) {
- ret = -EINVAL;
+ ret = -EOPNOTSUPP;
goto out;
}
diff --git a/drivers/iommu/intel/nested.c b/drivers/iommu/intel/nested.c
index df72724242bf..b024688b0bb5 100644
--- a/drivers/iommu/intel/nested.c
+++ b/drivers/iommu/intel/nested.c
@@ -99,7 +99,7 @@ static int intel_nested_cache_invalidate_user(struct iommu_domain *domain,
int ret = 0;
if (array->type != IOMMU_HWPT_INVALIDATE_DATA_VTD_S1) {
- ret = -EINVAL;
+ ret = -EOPNOTSUPP;
goto out;
}
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index 037e54f3d2ba..dfe7cdb1b12f 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -642,7 +642,7 @@ static int mock_viommu_cache_invalidate(struct iommufd_viommu *viommu,
int i;
if (array->type != IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST) {
- rc = -EINVAL;
+ rc = -EOPNOTSUPP;
goto out;
}
@@ -876,7 +876,7 @@ mock_domain_cache_invalidate_user(struct iommu_domain *domain,
int i;
if (array->type != IOMMU_HWPT_INVALIDATE_DATA_SELFTEST) {
- rc = -EINVAL;
+ rc = -EOPNOTSUPP;
goto out;
}
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index ef5043752a36..253ac566aaf7 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -470,7 +470,7 @@ static inline int __iommu_copy_struct_from_user(
if (WARN_ON(!dst_data || !src_data))
return -EINVAL;
if (src_data->type != data_type)
- return -EINVAL;
+ return -EOPNOTSUPP;
if (src_data->len < min_len || data_len < src_data->len)
return -EINVAL;
return copy_struct_from_user(dst_data, data_len, src_data->uptr,
@@ -567,7 +567,7 @@ iommu_copy_struct_from_full_user_array(void *kdst, size_t kdst_entry_size,
int ret;
if (user_array->type != data_type)
- return -EINVAL;
+ return -EOPNOTSUPP;
if (!user_array->entry_num)
return -EINVAL;
if (likely(user_array->entry_len == kdst_entry_size)) {
@@ -609,7 +609,7 @@ __iommu_copy_struct_to_user(const struct iommu_user_data *dst_data,
if (WARN_ON(!dst_data || !src_data))
return -EINVAL;
if (dst_data->type != data_type)
- return -EINVAL;
+ return -EOPNOTSUPP;
if (dst_data->len < min_len || data_len < dst_data->len)
return -EINVAL;
return copy_struct_to_user(dst_data->uptr, dst_data->len, src_data,
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h
index 010f47f7d3d2..79424a8c1b5a 100644
--- a/include/uapi/linux/iommufd.h
+++ b/include/uapi/linux/iommufd.h
@@ -986,7 +986,8 @@ struct iommu_viommu_arm_smmuv3_invalidate {
*
* An empty invalidation request array by setting @entry_num==0 is allowed, and
* @entry_len and @data_uptr would be ignored in this case. This can be used to
- * check if the given @data_type is supported or not by kernel.
+ * check if the given @data_type is supported or not by kernel: the ioctl fails
+ * with -EOPNOTSUPP for an unsupported @data_type.
*/
struct iommu_hwpt_invalidate {
__u32 size;
diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index 964df8f73610..1e58ab4c292e 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -536,9 +536,16 @@ TEST_F(iommufd_ioas, alloc_hwpt_nested)
sizeof(*inv_reqs), &num_inv);
assert(!num_inv);
+ /* Negative test: Invalid data_type with zero-length array */
+ num_inv = 0;
+ test_err_hwpt_invalidate(EOPNOTSUPP, nested_hwpt_id[0], inv_reqs,
+ IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID,
+ sizeof(*inv_reqs), &num_inv);
+ assert(!num_inv);
+
/* Negative test: Invalid data_type */
num_inv = 1;
- test_err_hwpt_invalidate(EINVAL, nested_hwpt_id[0], inv_reqs,
+ test_err_hwpt_invalidate(EOPNOTSUPP, nested_hwpt_id[0], inv_reqs,
IOMMU_HWPT_INVALIDATE_DATA_SELFTEST_INVALID,
sizeof(*inv_reqs), &num_inv);
assert(!num_inv);
@@ -3090,9 +3097,16 @@ TEST_F(iommufd_viommu, vdevice_cache)
&num_inv);
assert(!num_inv);
+ /* Negative test: Invalid data_type with zero-length array */
+ num_inv = 0;
+ test_err_viommu_invalidate(EOPNOTSUPP, viommu_id, inv_reqs,
+ IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST_INVALID,
+ sizeof(*inv_reqs), &num_inv);
+ assert(!num_inv);
+
/* Negative test: Invalid data_type */
num_inv = 1;
- test_err_viommu_invalidate(EINVAL, viommu_id, inv_reqs,
+ test_err_viommu_invalidate(EOPNOTSUPP, viommu_id, inv_reqs,
IOMMU_VIOMMU_INVALIDATE_DATA_SELFTEST_INVALID,
sizeof(*inv_reqs), &num_inv);
assert(!num_inv);
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH v3] iommu: Clarify uAPI errno for unsupported data types
2026-11-19 19:23 [PATCH v3] iommu: Clarify uAPI errno for unsupported data types Pranjal Shrivastava
@ 2026-11-19 19:54 ` Nicolin Chen
0 siblings, 0 replies; 2+ messages in thread
From: Nicolin Chen @ 2026-11-19 19:54 UTC (permalink / raw)
To: Pranjal Shrivastava
Cc: Jason Gunthorpe, Kevin Tian, Will Deacon, Robin Murphy,
Joerg Roedel, Peter Shier, iommu
On Thu, Nov 19, 2026 at 07:23:55PM +0000, Pranjal Shrivastava wrote:
> The IOMMU_HWPT_INVALIDATE uAPI says that an empty request array "can be
> used to check if the given @data_type is supported or not by kernel",
> but not what to look for. And the iommu_copy_struct_*() helpers and the
> Intel VT-d, ARM SMMUv3 and selftest invalidation ops reject unsupported
> data types with -EINVAL, which means that the request was understood but
> a field is not correct.
>
> Return -EOPNOTSUPP for an unsupported data type instead and document it
> as what the probe looks for. Since arm_vsmmu_alloc_domain_nested() uses
> the copy helper, it now returns -EOPNOTSUPP, like the other nested
> domain allocators. Update and extend the selftests accordingly.
>
> Signed-off-by: Pranjal Shrivastava <praan@google.com>
Acked-by: Nicolin Chen <nicolinc@nvidia.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 19:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 19:23 [PATCH v3] iommu: Clarify uAPI errno for unsupported data types Pranjal Shrivastava
2026-11-19 19:54 ` Nicolin Chen
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.