Verified with 6.13-rc1 64k kernel. Tested-by: Yi Zhang <yi.zhang@xxxxxxxxxx> On Fri, Dec 6, 2024 at 7:04 PM Ming Lei <ming.lei@xxxxxxxxxx> wrote: > > 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 <ming.lei@xxxxxxxxxx> > --- > src/miniublk.c | 17 +++++++++++++---- > 1 file changed, 13 insertions(+), 4 deletions(-) > > diff --git a/src/miniublk.c b/src/miniublk.c > index 565aa60..73791fd 100644 > --- a/src/miniublk.c > +++ b/src/miniublk.c > @@ -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 > > -- Best Regards, Yi Zhang