Skip to content

Commit d369735

Browse files
Ming Leiaxboe
authored andcommitted
ublk: fix ublk_ch_mmap() for 64K page size
In ublk_ch_mmap(), queue id is calculated in the following way: (vma->vm_pgoff << PAGE_SHIFT) / `max_cmd_buf_size` 'max_cmd_buf_size' is equal to `UBLK_MAX_QUEUE_DEPTH * sizeof(struct ublksrv_io_desc)` and UBLK_MAX_QUEUE_DEPTH is 4096 and part of UAPI, so 'max_cmd_buf_size' is always page aligned in 4K page size kernel. However, it isn't true in 64K page size kernel. Fixes the issue by always rounding up 'max_cmd_buf_size' with PAGE_SIZE. Cc: [email protected] Fixes: 71f28f3 ("ublk_drv: add io_uring based userspace block driver") Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent b2113ed commit d369735

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/block/ublk_drv.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,12 +669,21 @@ static inline char *ublk_queue_cmd_buf(struct ublk_device *ub, int q_id)
669669
return ublk_get_queue(ub, q_id)->io_cmd_buf;
670670
}
671671

672+
static inline int __ublk_queue_cmd_buf_size(int depth)
673+
{
674+
return round_up(depth * sizeof(struct ublksrv_io_desc), PAGE_SIZE);
675+
}
676+
672677
static inline int ublk_queue_cmd_buf_size(struct ublk_device *ub, int q_id)
673678
{
674679
struct ublk_queue *ubq = ublk_get_queue(ub, q_id);
675680

676-
return round_up(ubq->q_depth * sizeof(struct ublksrv_io_desc),
677-
PAGE_SIZE);
681+
return __ublk_queue_cmd_buf_size(ubq->q_depth);
682+
}
683+
684+
static int ublk_max_cmd_buf_size(void)
685+
{
686+
return __ublk_queue_cmd_buf_size(UBLK_MAX_QUEUE_DEPTH);
678687
}
679688

680689
/*
@@ -1358,7 +1367,7 @@ static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)
13581367
{
13591368
struct ublk_device *ub = filp->private_data;
13601369
size_t sz = vma->vm_end - vma->vm_start;
1361-
unsigned max_sz = UBLK_MAX_QUEUE_DEPTH * sizeof(struct ublksrv_io_desc);
1370+
unsigned max_sz = ublk_max_cmd_buf_size();
13621371
unsigned long pfn, end, phys_off = vma->vm_pgoff << PAGE_SHIFT;
13631372
int q_id, ret = 0;
13641373

0 commit comments

Comments
 (0)