Skip to contentSkip to conversation

iommufd/selftest: fix the unmap-all length on 32-bit architectures

PATCH Applied Sasha Levin 2 participants 2 messages Nov 3 – Nov 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommufd/selftest: fix the unmap-all length on 32-bit architectures

_test_ioctl_ioas_unmap() takes the length as a size_t, so on 32-bit architectures test_ioctl_ioas_unmap(0, UINT64_MAX), which asks to unmap everything, passes SIZE_MAX instead and doesn't test the unmap-all case:

iommufd.c:861:9: warning: conversion from 'long long unsigned int' to 'size_t' {aka 'unsigned int'} changes value from '18446744073709551615' to '4294967295' [-Woverflow]

Take the length as uint64_t, like the length field of struct iommu_ioas_unmap. While at it, cast the pointers that go into 64-bit UAPI fields through uintptr_t, as casting them straight to uint64_t warns on 32-bit.

---
Found with 32-bit builds of the selftests (gcc 16 and clang 21 with -m32, with and without -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64); KernelCI's 32-bit arm builds show the same warnings. The changed files build without them now, and the x86_64 builds don't change.

 tools/testing/selftests/iommu/iommufd.c       |  2 +-
 tools/testing/selftests/iommu/iommufd_utils.h | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
tools/testing/selftests/iommu/iommufd.c +1 -1
index ca2b35e9d443a..f96c262c6a245 100644
@@ -2454,7 +2454,7 @@ TEST_F(iommufd, map_cmd)
 	struct vfio_iommu_type1_dma_map map_cmd = {
 		.iova = MOCK_APERTURE_START,
 		.size = PAGE_SIZE,
-		.vaddr = (__u64)buffer,
+		.vaddr = (__u64)(uintptr_t)buffer,
 	};
 
 	map_cmd.argsz = 1;
tools/testing/selftests/iommu/iommufd_utils.h +6 -6
index b4928cbd4d9c8..38339dc9f943b 100644
@@ -198,7 +198,7 @@ static int _test_cmd_hwpt_alloc(int fd, __u32 device_id, __u32 pt_id, __u32 ft_i
 		.pt_id = pt_id,
 		.data_type = data_type,
 		.data_len = data_len,
-		.data_uptr = (uint64_t)data,
+		.data_uptr = (uint64_t)(uintptr_t)data,
 		.fault_id = ft_id,
 	};
 	int ret;
@@ -310,7 +310,7 @@ static int _test_cmd_hwpt_invalidate(int fd, __u32 hwpt_id, void *reqs,
 		.size = sizeof(cmd),
 		.hwpt_id = hwpt_id,
 		.data_type = data_type,
-		.data_uptr = (uint64_t)reqs,
+		.data_uptr = (uint64_t)(uintptr_t)reqs,
 		.entry_len = lreq,
 		.entry_num = *nreqs,
 	};
@@ -341,7 +341,7 @@ static int _test_cmd_viommu_invalidate(int fd, __u32 viommu_id, void *reqs,
 		.size = sizeof(cmd),
 		.hwpt_id = viommu_id,
 		.data_type = data_type,
-		.data_uptr = (uint64_t)reqs,
+		.data_uptr = (uint64_t)(uintptr_t)reqs,
 		.entry_len = lreq,
 		.entry_num = *nreqs,
 	};
@@ -695,7 +695,7 @@ static int _test_ioctl_ioas_map(int fd, unsigned int ioas_id, void *buffer,
 	})
 
 static int _test_ioctl_ioas_unmap(int fd, unsigned int ioas_id, uint64_t iova,
-				  size_t length, uint64_t *out_len)
+				  uint64_t length, uint64_t *out_len)
 {
 	struct iommu_ioas_unmap cmd = {
 		.size = sizeof(cmd),
@@ -832,7 +832,7 @@ static int _test_cmd_get_hw_info(int fd, __u32 device_id, __u32 data_type,
 		.dev_id = device_id,
 		.data_len = data_len,
 		.in_data_type = data_type,
-		.data_uptr = (uint64_t)data,
+		.data_uptr = (uint64_t)(uintptr_t)data,
 		.out_capabilities = 0,
 	};
 	int ret;
@@ -978,7 +978,7 @@ static int _test_cmd_viommu_alloc(int fd, __u32 device_id, __u32 hwpt_id,
 		.type = type,
 		.dev_id = device_id,
 		.hwpt_id = hwpt_id,
-		.data_uptr = (uint64_t)data,
+		.data_uptr = (uint64_t)(uintptr_t)data,
 		.data_len = data_len,
 	};
 	int ret;
Signature · 1 line
2.53.0