blktests: src/miniublk.c: fix unaligned mmap offset for 64K page size
PATCH 1/1 blktests: src/miniublk.c: fix unaligned mmap offset for 64K page size
The 'offset' passed to mmap() has to be PAGE_SIZE aligned, which is always true for 4K page size, but not true for 64K page size.
Fix it by adding helper of ublk_queue_max_cmd_buf_sz().
Signed-off-by Ming Lei <[email protected]>
--- src/miniublk.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
src/miniublk.c +13 -4
@@ -472,14 +472,24 @@ static struct ublk_dev *ublk_ctrl_init()return dev; } -static int ublk_queue_cmd_buf_sz (struct ublk_queue *q) +static int __ublk_queue_cmd_buf_sz (unsigned depth) { -int size = q->q_depth *sizeof (struct ublksrv_io_desc ); +int size = depth *sizeof (struct ublksrv_io_desc );unsigned int page_sz =getpagesize ();return round_up (size, page_sz); } +static int ublk_queue_max_cmd_buf_sz (void ) +{ +return __ublk_queue_cmd_buf_sz (UBLK_MAX_QUEUE_DEPTH ); +} + +static int ublk_queue_cmd_buf_sz (struct ublk_queue *q) +{ +return __ublk_queue_cmd_buf_sz (q->q_depth); +} +static void ublk_queue_deinit (struct ublk_queue *q) {int i;
@@ -516,8 +526,7 @@ static int ublk_queue_init(struct ublk_queue *q) q->tid =gettid (); cmd_buf_size =ublk_queue_cmd_buf_sz (q); - off =UBLKSRV_CMD_BUF_OFFSET + - q->q_id * (UBLK_MAX_QUEUE_DEPTH *sizeof (struct ublksrv_io_desc )); + off =UBLKSRV_CMD_BUF_OFFSET + q->q_id *ublk_queue_max_cmd_buf_sz (); q->io_cmd_buf = (char *)mmap (0 , cmd_buf_size,PROT_READ ,MAP_SHARED |MAP_POPULATE , dev->fds[0 ], off);if (q->io_cmd_buf ==MAP_FAILED ) {
Signature · 1 line
2.47.0
Verified with 6.13-rc1 64k kernel.
Tested-by Yi Zhang <[email protected]>
Quoted 56 lines · Ming Lei
The 'offset' passed to
mmap()has to bePAGE_SIZEaligned, which is always true for 4K page size, but not true for 64K page size.Fix it by adding helper of
ublk_queue_max_cmd_buf_sz().Signed-off-by Ming Lei <[email protected]>--- src/miniublk.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)src/miniublk.c +13
-5@@ -472,14 +472,24 @@ static struct ublk_dev *ublk_ctrl_init()return dev; } -static int ublk_queue_cmd_buf_sz (struct ublk_queue *q) +static int __ublk_queue_cmd_buf_sz (unsigned depth) { -int size = q->q_depth *sizeof (struct ublksrv_io_desc ); +int size = depth *sizeof (struct ublksrv_io_desc );unsigned int page_sz =getpagesize ();return round_up (size, page_sz); } +static int ublk_queue_max_cmd_buf_sz (void ) +{ +return __ublk_queue_cmd_buf_sz (UBLK_MAX_QUEUE_DEPTH ); +} + +static int ublk_queue_cmd_buf_sz (struct ublk_queue *q) +{ +return __ublk_queue_cmd_buf_sz (q->q_depth); +} +static void ublk_queue_deinit (struct ublk_queue *q) {int i;@@ -516,8 +526,7 @@ static int ublk_queue_init(struct ublk_queue *q) q->tid =gettid (); cmd_buf_size =ublk_queue_cmd_buf_sz (q); - off =UBLKSRV_CMD_BUF_OFFSET + - q->q_id * (UBLK_MAX_QUEUE_DEPTH *sizeof (struct ublksrv_io_desc )); + off =UBLKSRV_CMD_BUF_OFFSET + q->q_id *ublk_queue_max_cmd_buf_sz (); q->io_cmd_buf = (char *)mmap (0 , cmd_buf_size,PROT_READ ,MAP_SHARED |MAP_POPULATE , dev->fds[0 ], off);if (q->io_cmd_buf ==MAP_FAILED ) { --2.47.0
Signature · 2 lines
Best Regards, Yi Zhang
Shinichiro Kawasaki
AppliedQuoted 4 lines · Ming Lei
The 'offset' passed to
mmap()has to bePAGE_SIZEaligned, which is always true for 4K page size, but not true for 64K page size.Fix it by adding helper of
ublk_queue_max_cmd_buf_sz().
I applied it. Thanks!