Skip to content

Commit

Permalink
libublksrv: align max command buffer size with page_size
Browse files Browse the repository at this point in the history
For 4k page size, max command buffer size is always aligned
with page size. But for 64K page size, it isn't true.

Fix it by aligning it with page_size.

Signed-off-by: Ming Lei <[email protected]>
  • Loading branch information
ming1 committed Nov 13, 2024
1 parent bcfde42 commit 4ba6a89
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/ublksrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ static int ublksrv_queue_cmd_buf_sz(struct _ublksrv_queue *q)
return round_up(size, page_sz);
}

static int queue_max_cmd_buf_sz(void)
{
unsigned int page_sz = getpagesize();

return round_up(UBLK_MAX_QUEUE_DEPTH * sizeof(struct ublksrv_io_desc),
page_sz);
}

int ublksrv_queue_unconsumed_cqes(const struct ublksrv_queue *tq)
{
if (tq->ring_ptr)
Expand Down Expand Up @@ -549,8 +557,7 @@ const struct ublksrv_queue *ublksrv_queue_init(const struct ublksrv_dev *tdev,
q->tid = ublksrv_gettid();

cmd_buf_size = ublksrv_queue_cmd_buf_sz(q);
off = UBLKSRV_CMD_BUF_OFFSET +
q_id * (UBLK_MAX_QUEUE_DEPTH * sizeof(struct ublksrv_io_desc));
off = UBLKSRV_CMD_BUF_OFFSET + q_id * queue_max_cmd_buf_sz();
q->io_cmd_buf = (char *)mmap(0, cmd_buf_size, PROT_READ,
MAP_SHARED | MAP_POPULATE, dev->cdev_fd, off);
if (q->io_cmd_buf == MAP_FAILED) {
Expand Down

0 comments on commit 4ba6a89

Please sign in to comment.