mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: ublk: fix the build and file offsets on 32-bit
@ 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: Ming Lei; +Cc: Shuah Khan, linux-block, linux-kselftest, linux-kernel

kublk puts pointers into 64-bit UAPI and SQE fields with a plain (__u64)
cast. ublk builds with -Werror, so it fails to build on 32-bit
architectures:

  batch.c:379:42: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]

Cast through uintptr_t. kublk also passes 64-bit user copy offsets,
which start at UBLKSRV_IO_BUF_OFFSET (2 GB), to pread() and pwrite(),
and with glibc those are truncated to a 32-bit off_t there. Build with
-D_FILE_OFFSET_BITS=64 as well.

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/ublk/Makefile | 1 +
 tools/testing/selftests/ublk/batch.c  | 6 +++---
 tools/testing/selftests/ublk/ctrl.c   | 2 +-
 tools/testing/selftests/ublk/kublk.c  | 2 +-
 4 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/ublk/Makefile b/tools/testing/selftests/ublk/Makefile
index fc64b8f028332..1a50d4695c9fa 100644
--- a/tools/testing/selftests/ublk/Makefile
+++ b/tools/testing/selftests/ublk/Makefile
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 
 CFLAGS += -O3 -Wl,-no-as-needed -Wall -I $(top_srcdir)/usr/include
+CFLAGS += -D_FILE_OFFSET_BITS=64
 ifneq ($(WERROR),0)
 	CFLAGS += -Werror
 endif
diff --git a/tools/testing/selftests/ublk/batch.c b/tools/testing/selftests/ublk/batch.c
index dfc81ee17d076..625a9c32a80b1 100644
--- a/tools/testing/selftests/ublk/batch.c
+++ b/tools/testing/selftests/ublk/batch.c
@@ -376,10 +376,10 @@ static int __ublk_batch_queue_prep_io_cmds(struct ublk_thread *t, struct ublk_qu
 		if (ublk_queue_use_auto_zc(q))
 			elem->buf_index = ublk_batch_io_buf_idx(t, q, i);
 		else if (!ublk_queue_no_buf(q))
-			elem->buf_addr = (__u64)io->buf_addr;
+			elem->buf_addr = (__u64)(uintptr_t)io->buf_addr;
 	}
 
-	sqe->addr = (__u64)buf;
+	sqe->addr = (__u64)(uintptr_t)buf;
 	sqe->len = t->commit_buf_elem_size * nr_elem;
 
 	ublk_init_batch_cmd(t, q->q_id, sqe, UBLK_U_IO_PREP_IO_CMDS,
@@ -473,7 +473,7 @@ static void __ublk_batch_commit_io_cmds(struct ublk_thread *t,
 
 	ublk_io_alloc_sqes(t, &sqe, 1);
 	buf_idx = cb->buf_idx;
-	sqe->addr = (__u64)cb->elem;
+	sqe->addr = (__u64)(uintptr_t)cb->elem;
 	sqe->len = nr_elem * t->commit_buf_elem_size;
 
 	/* commit isn't per-queue command */
diff --git a/tools/testing/selftests/ublk/ctrl.c b/tools/testing/selftests/ublk/ctrl.c
index 53d54799f9097..5e0762cfc4eae 100644
--- a/tools/testing/selftests/ublk/ctrl.c
+++ b/tools/testing/selftests/ublk/ctrl.c
@@ -204,7 +204,7 @@ int ublk_ctrl_get_params(struct ublk_dev *dev,
 	struct ublk_ctrl_cmd_data data = {
 		.cmd_op	= UBLK_U_CMD_GET_PARAMS,
 		.flags	= CTRL_CMD_HAS_BUF,
-		.addr = (__u64)params,
+		.addr = (__u64)(uintptr_t)params,
 		.len = sizeof(*params),
 	};
 
diff --git a/tools/testing/selftests/ublk/kublk.c b/tools/testing/selftests/ublk/kublk.c
index 5a4ff689c1f7a..115f25351d309 100644
--- a/tools/testing/selftests/ublk/kublk.c
+++ b/tools/testing/selftests/ublk/kublk.c
@@ -148,7 +148,7 @@ static int ublk_ctrl_get_affinity(struct ublk_dev *ctrl_dev, cpu_set_t **ptr_buf
 	for (i = 0; i < ctrl_dev->dev_info.nr_hw_queues; i++) {
 		data.data[0] = i;
 		data.len = sizeof(cpu_set_t);
-		data.addr = (__u64)&buf[i];
+		data.addr = (__u64)(uintptr_t)&buf[i];
 
 		ret = __ublk_ctrl_cmd(ctrl_dev, &data);
 		if (ret < 0) {
-- 
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] selftests: ublk: fix the build and file offsets on 32-bit 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®