mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iommufd/selftest: fix the unmap-all length on 32-bit architectures
@ 2026-11-03 16:39 Sasha Levin
  0 siblings, 0 replies; only message in thread
From: Sasha Levin @ 2026-11-03 16:39 UTC (permalink / raw)
  To: Jason Gunthorpe, Kevin Tian
  Cc: Shuah Khan, iommu, linux-kselftest, linux-kernel

_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.

Signed-off-by: Sasha Levin <sashal@kernel.org>
---
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(-)

diff --git a/tools/testing/selftests/iommu/iommufd.c b/tools/testing/selftests/iommu/iommufd.c
index ca2b35e9d443a..f96c262c6a245 100644
--- a/tools/testing/selftests/iommu/iommufd.c
+++ b/tools/testing/selftests/iommu/iommufd.c
@@ -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;
diff --git a/tools/testing/selftests/iommu/iommufd_utils.h b/tools/testing/selftests/iommu/iommufd_utils.h
index b4928cbd4d9c8..38339dc9f943b 100644
--- a/tools/testing/selftests/iommu/iommufd_utils.h
+++ b/tools/testing/selftests/iommu/iommufd_utils.h
@@ -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;
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-03 16:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 16:39 [PATCH] iommufd/selftest: fix the unmap-all length on 32-bit architectures Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®