Linux block layer
 help / color / mirror / Atom feed
From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: Ming Lei <ming.lei@redhat.com>
Subject: [PATCH 2/3] ubd_drv: fix io command buffer mapping
Date: Fri,  6 Dec 2024 16:21:59 +0800	[thread overview]
Message-ID: <20241206082202.949142-6-ming.lei@redhat.com> (raw)
In-Reply-To: <20241206082202.949142-1-ming.lei@redhat.com>

Unit of vma->vm_pgoff is PAGE_SIZE, so have to compute physical offset
first.

Without this patch, io command buffer gets corrupted in case of MQ.

Fixes: 54f5156aa8d1 ("ubd_drv: prepare for supporting MQ")
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 drivers/block/ubd_drv.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/block/ubd_drv.c b/drivers/block/ubd_drv.c
index 3b3723d78084..bbcbb2f05840 100644
--- a/drivers/block/ubd_drv.c
+++ b/drivers/block/ubd_drv.c
@@ -558,14 +558,17 @@ static int ubd_ch_mmap(struct file *filp, struct vm_area_struct *vma)
 	struct ubd_device *ub = filp->private_data;
 	size_t sz = vma->vm_end - vma->vm_start;
 	unsigned max_sz = UBD_MAX_QUEUE_DEPTH * sizeof(struct ubdsrv_io_desc);
-	unsigned long pfn, end;
+	unsigned long pfn, end, phys_off = vma->vm_pgoff << PAGE_SHIFT;
 	int q_id;
 
 	end = UBDSRV_CMD_BUF_OFFSET + ub->dev_info.nr_hw_queues * max_sz;
-	if (vma->vm_pgoff < UBDSRV_CMD_BUF_OFFSET || vma->vm_pgoff >= end)
+	if (phys_off < UBDSRV_CMD_BUF_OFFSET || phys_off >= end)
 		return -EINVAL;
 
-	q_id = (vma->vm_pgoff - UBDSRV_CMD_BUF_OFFSET) / max_sz;
+	q_id = (phys_off - UBDSRV_CMD_BUF_OFFSET) / max_sz;
+	pr_devel("%s: qid %d, pid %d, addr %lx pg_off %lx sz %lu\n",
+			__func__, q_id, current->pid, vma->vm_start,
+			phys_off, sz);
 
 	if (sz != ubd_queue_cmd_buf_size(ub, q_id))
 		return -EINVAL;
-- 
2.31.1


  parent reply	other threads:[~2024-12-06  8:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-06  8:21 [PATCH 0/2] blk-mq: fix lockdep warning between sysfs_lock and cpuhotplug lock Ming Lei
2024-12-06  8:21 ` [PATCH 1/2] blk-mq: register cpuhp callback after hctx is added to xarray table Ming Lei
2024-12-06  8:21 ` [PATCH V2] null_blk: cleanup null_init_tag_set Ming Lei
2024-12-06  8:21 ` [PATCH 1/3] ubd_drv: fix return value for COMMIT* command Ming Lei
2024-12-06  8:21 ` [PATCH 2/2] blk-mq: move cpuhp callback registering out of q->sysfs_lock Ming Lei
2024-12-06  8:21 ` Ming Lei [this message]
2024-12-06  8:24 ` [PATCH 0/2] blk-mq: fix lockdep warning between sysfs_lock and cpuhotplug lock Ming Lei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241206082202.949142-6-ming.lei@redhat.com \
    --to=ming.lei@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox