selftests: ublk: fix the build and file offsets on 32-bit
Subsystems (3)
PATCH 1/1 selftests: ublk: fix the build and file offsets on 32-bit
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.
---
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(-)
tools/testing/selftests/ublk/Makefile +1 -0
@@ -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
tools/testing/selftests/ublk/batch.c +3 -3
@@ -376,10 +376,10 @@ static int __ublk_batch_queue_prep_io_cmds(struct ublk_thread *t, struct ublk_quif (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 */
tools/testing/selftests/ublk/ctrl.c +1 -1
@@ -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), };
tools/testing/selftests/ublk/kublk.c +1 -1
@@ -148,7 +148,7 @@ static int ublk_ctrl_get_affinity(struct ublk_dev *ctrl_dev, cpu_set_t **ptr_buffor (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 ) {
Signature · 1 line
2.53.0
Quoted 12 lines · Sasha Levin
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 atUBLKSRV_IO_BUF_OFFSET(2 GB), topread()andpwrite(), and with glibc those are truncated to a 32-bitoff_tthere. Build with -D_FILE_OFFSET_BITS=64 as well.
Quoted 7 lines
Signed-off-by Sasha Levin <[email protected]>---
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 thex86_64builds don't change.
Thanks,
Quoted 4 lines · Sasha Levin
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:
Quoted 8 lines
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 atUBLKSRV_IO_BUF_OFFSET(2 GB), topread()andpwrite(), and with glibc those are truncated to a 32-bitoff_tthere. Build with -D_FILE_OFFSET_BITS=64 as well.[...]
Applied, thanks!
[1/1] selftests: ublk: fix the build and file offsets on 32-bit
commit: 3197517875fdcfae1e9b5a4dcaf35cbbd66c413c
Best regards,
Signature · 1 line
Jens Axboe