From: Sasha Levin <sashal@kernel.org>
To: Ming Lei <tom.leiming@gmail.com>
Cc: Shuah Khan <shuah@kernel.org>,
linux-block@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH] selftests: ublk: fix the build and file offsets on 32-bit
Date: Tue, 3 Nov 2026 11:39:28 -0500 [thread overview]
Message-ID: <20261103163928.641519-1-sashal@kernel.org> (raw)
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
reply other threads:[~2026-11-03 16:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261103163928.641519-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=tom.leiming@gmail.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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®