diff mbox series

ublk: fix ublk_ch_mmap() for 64K page size

Message ID 20241111110718.1394001-1-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series ublk: fix ublk_ch_mmap() for 64K page size | expand

Commit Message

Ming Lei Nov. 11, 2024, 11:07 a.m. UTC
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.

Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/ublk_drv.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

Comments

Jens Axboe Nov. 11, 2024, 3:17 p.m. UTC | #1
On Mon, 11 Nov 2024 19:07:18 +0800, Ming Lei wrote:
> 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)`
> 
> [...]

Applied, thanks!

[1/1] ublk: fix ublk_ch_mmap() for 64K page size
      commit: d369735e02ef122d19d4c3d093028da0eb400636

Best regards,
diff mbox series

Patch

diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index 59951e7c2593..4ae4fdb8bb7f 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -669,12 +669,21 @@  static inline char *ublk_queue_cmd_buf(struct ublk_device *ub, int q_id)
 	return ublk_get_queue(ub, q_id)->io_cmd_buf;
 }
 
+static inline int __ublk_queue_cmd_buf_size(int depth)
+{
+	return round_up(depth * sizeof(struct ublksrv_io_desc), PAGE_SIZE);
+}
+
 static inline int ublk_queue_cmd_buf_size(struct ublk_device *ub, int q_id)
 {
 	struct ublk_queue *ubq = ublk_get_queue(ub, q_id);
 
-	return round_up(ubq->q_depth * sizeof(struct ublksrv_io_desc),
-			PAGE_SIZE);
+	return __ublk_queue_cmd_buf_size(ubq->q_depth);
+}
+
+static int ublk_max_cmd_buf_size(void)
+{
+	return __ublk_queue_cmd_buf_size(UBLK_MAX_QUEUE_DEPTH);
 }
 
 /*
@@ -1358,7 +1367,7 @@  static int ublk_ch_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	struct ublk_device *ub = filp->private_data;
 	size_t sz = vma->vm_end - vma->vm_start;
-	unsigned max_sz = UBLK_MAX_QUEUE_DEPTH * sizeof(struct ublksrv_io_desc);
+	unsigned max_sz = ublk_max_cmd_buf_size();
 	unsigned long pfn, end, phys_off = vma->vm_pgoff << PAGE_SHIFT;
 	int q_id, ret = 0;