* [PATCH] nvmet: fix building bvec from sg list
@ 2019-03-27 9:07 ` Ming Lei
0 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2019-03-27 9:07 UTC (permalink / raw)
To: linux-nvme, Christoph Hellwig
Cc: Ming Lei, Yi Zhang, Sagi Grimberg, Chaitanya Kulkarni, stable
There are two mistakes for building bvec from sg list for file
backed ns:
- use request data length to compute number of io vector, this way
doesn't consider sg->offset, and the result may be smaller than required
io vectors
- bvec->bv_len isn't capped by sg->length
This patch fixes this issue by building bvec from sg directly, given
the whole IO stack is ready for multi-page bvec.
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Fixes: 3a85a5de29ea ("nvme-loop: add a NVMe loopback host driver")
Cc: Yi Zhang <yi.zhang@redhat.com>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
(Backporting depends on the stable-only patch of 'nvmet: set loop queue's
segment boundary mask as PAGE_SIZE - 1')
Cc: <stable@vger.kernel.org>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
drivers/nvme/target/io-cmd-file.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 3e43212d3c1c..bc6ebb51b0bf 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -75,11 +75,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
return ret;
}
-static void nvmet_file_init_bvec(struct bio_vec *bv, struct sg_page_iter *iter)
+static void nvmet_file_init_bvec(struct bio_vec *bv, struct scatterlist *sg)
{
- bv->bv_page = sg_page_iter_page(iter);
- bv->bv_offset = iter->sg->offset;
- bv->bv_len = PAGE_SIZE - iter->sg->offset;
+ bv->bv_page = sg_page(sg);
+ bv->bv_offset = sg->offset;
+ bv->bv_len = sg->length;
}
static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos,
@@ -128,14 +128,14 @@ static void nvmet_file_io_done(struct kiocb *iocb, long ret, long ret2)
static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags)
{
- ssize_t nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
- struct sg_page_iter sg_pg_iter;
+ ssize_t nr_bvec = req->sg_cnt;
unsigned long bv_cnt = 0;
bool is_sync = false;
size_t len = 0, total_len = 0;
ssize_t ret = 0;
loff_t pos;
-
+ int i;
+ struct scatterlist *sg;
if (req->f.mpool_alloc && nr_bvec > NVMET_MAX_MPOOL_BVEC)
is_sync = true;
@@ -147,8 +147,8 @@ static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags)
}
memset(&req->f.iocb, 0, sizeof(struct kiocb));
- for_each_sg_page(req->sg, &sg_pg_iter, req->sg_cnt, 0) {
- nvmet_file_init_bvec(&req->f.bvec[bv_cnt], &sg_pg_iter);
+ for_each_sg(req->sg, sg, req->sg_cnt, i) {
+ nvmet_file_init_bvec(&req->f.bvec[bv_cnt], sg);
len += req->f.bvec[bv_cnt].bv_len;
total_len += req->f.bvec[bv_cnt].bv_len;
bv_cnt++;
@@ -225,7 +225,7 @@ static void nvmet_file_submit_buffered_io(struct nvmet_req *req)
static void nvmet_file_execute_rw(struct nvmet_req *req)
{
- ssize_t nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
+ ssize_t nr_bvec = req->sg_cnt;
if (!req->sg_cnt || !nr_bvec) {
nvmet_req_complete(req, 0);
--
2.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] nvmet: fix building bvec from sg list
@ 2019-03-27 9:07 ` Ming Lei
0 siblings, 0 replies; 5+ messages in thread
From: Ming Lei @ 2019-03-27 9:07 UTC (permalink / raw)
There are two mistakes for building bvec from sg list for file
backed ns:
- use request data length to compute number of io vector, this way
doesn't consider sg->offset, and the result may be smaller than required
io vectors
- bvec->bv_len isn't capped by sg->length
This patch fixes this issue by building bvec from sg directly, given
the whole IO stack is ready for multi-page bvec.
Reported-by: Yi Zhang <yi.zhang at redhat.com>
Fixes: 3a85a5de29ea ("nvme-loop: add a NVMe loopback host driver")
Cc: Yi Zhang <yi.zhang at redhat.com>
Cc: Sagi Grimberg <sagi at grimberg.me>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni at wdc.com>
(Backporting depends on the stable-only patch of 'nvmet: set loop queue's
segment boundary mask as PAGE_SIZE - 1')
Cc: <stable at vger.kernel.org>
Signed-off-by: Ming Lei <ming.lei at redhat.com>
---
drivers/nvme/target/io-cmd-file.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/nvme/target/io-cmd-file.c b/drivers/nvme/target/io-cmd-file.c
index 3e43212d3c1c..bc6ebb51b0bf 100644
--- a/drivers/nvme/target/io-cmd-file.c
+++ b/drivers/nvme/target/io-cmd-file.c
@@ -75,11 +75,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
return ret;
}
-static void nvmet_file_init_bvec(struct bio_vec *bv, struct sg_page_iter *iter)
+static void nvmet_file_init_bvec(struct bio_vec *bv, struct scatterlist *sg)
{
- bv->bv_page = sg_page_iter_page(iter);
- bv->bv_offset = iter->sg->offset;
- bv->bv_len = PAGE_SIZE - iter->sg->offset;
+ bv->bv_page = sg_page(sg);
+ bv->bv_offset = sg->offset;
+ bv->bv_len = sg->length;
}
static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos,
@@ -128,14 +128,14 @@ static void nvmet_file_io_done(struct kiocb *iocb, long ret, long ret2)
static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags)
{
- ssize_t nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
- struct sg_page_iter sg_pg_iter;
+ ssize_t nr_bvec = req->sg_cnt;
unsigned long bv_cnt = 0;
bool is_sync = false;
size_t len = 0, total_len = 0;
ssize_t ret = 0;
loff_t pos;
-
+ int i;
+ struct scatterlist *sg;
if (req->f.mpool_alloc && nr_bvec > NVMET_MAX_MPOOL_BVEC)
is_sync = true;
@@ -147,8 +147,8 @@ static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags)
}
memset(&req->f.iocb, 0, sizeof(struct kiocb));
- for_each_sg_page(req->sg, &sg_pg_iter, req->sg_cnt, 0) {
- nvmet_file_init_bvec(&req->f.bvec[bv_cnt], &sg_pg_iter);
+ for_each_sg(req->sg, sg, req->sg_cnt, i) {
+ nvmet_file_init_bvec(&req->f.bvec[bv_cnt], sg);
len += req->f.bvec[bv_cnt].bv_len;
total_len += req->f.bvec[bv_cnt].bv_len;
bv_cnt++;
@@ -225,7 +225,7 @@ static void nvmet_file_submit_buffered_io(struct nvmet_req *req)
static void nvmet_file_execute_rw(struct nvmet_req *req)
{
- ssize_t nr_bvec = DIV_ROUND_UP(req->data_len, PAGE_SIZE);
+ ssize_t nr_bvec = req->sg_cnt;
if (!req->sg_cnt || !nr_bvec) {
nvmet_req_complete(req, 0);
--
2.9.5
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] nvmet: fix building bvec from sg list
2019-03-27 9:07 ` Ming Lei
@ 2019-03-27 13:50 ` Christoph Hellwig
-1 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2019-03-27 13:50 UTC (permalink / raw)
To: Ming Lei
Cc: linux-nvme, Christoph Hellwig, Yi Zhang, Sagi Grimberg,
Chaitanya Kulkarni, stable
Thanks,
applied to nvme-5.1.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] nvmet: fix building bvec from sg list
@ 2019-03-27 13:50 ` Christoph Hellwig
0 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2019-03-27 13:50 UTC (permalink / raw)
Thanks,
applied to nvme-5.1.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] nvmet: fix building bvec from sg list
2019-03-27 9:07 ` Ming Lei
(?)
(?)
@ 2019-03-29 14:17 ` Sasha Levin
-1 siblings, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2019-03-29 14:17 UTC (permalink / raw)
Hi,
[This is an automated email]
This commit has been processed because it contains a "Fixes:" tag,
fixing commit: 3a85a5de29ea nvme-loop: add a NVMe loopback host driver.
The bot has tested the following trees: v5.0.5, v4.19.32, v4.14.109, v4.9.166.
v5.0.5: Build OK!
v4.19.32: Failed to apply! Possible dependencies:
50a909db36f2 ("nvmet: use IOCB_NOWAIT for file-ns buffered I/O")
v4.14.109: Failed to apply! Possible dependencies:
1b72b71facce ("nvmet: fix file discard return status")
50a909db36f2 ("nvmet: use IOCB_NOWAIT for file-ns buffered I/O")
543c09c89fdc ("nvmet: Fix nvmet_execute_write_zeroes sector count")
55eb942eda2c ("nvmet: add buffered I/O support for file backed ns")
618cff4285dc ("nvmet: remove duplicate NULL initialization for req->ns")
7756f72ccd43 ("nvmet: Change return code of discard command if not supported")
9c891c139894 ("nvmet: check fileio lba range access boundaries")
d5eff33ee6f8 ("nvmet: add simple file backed ns support")
e454d122e228 ("nvmet: kill nvmet_inline_bio_init")
e929f06d9eaa ("nvmet: constify struct nvmet_fabrics_ops")
ea435e1b9392 ("block: add a poll_fn callback to struct request_queue")
v4.9.166: Failed to apply! Possible dependencies:
297e3d854784 ("blk-throttle: make throtl_slice tunable")
4151dd9a58c6 ("nvmet: Fixed avoided printing nvmet: twice in error logs.")
4e4cbee93d56 ("block: switch bios to blk_status_t")
778f067c185c ("nvme: add semicolon in nvme_command setting")
87760e5eef35 ("block: hook up writeback throttling")
986994a27587 ("nvme: Use CNS as 8-bit field and avoid endianness conversion")
9e234eeafbe1 ("blk-throttle: add a simple idle detection")
cf43e6be865a ("block: add scalable completion tracking of requests")
d5eff33ee6f8 ("nvmet: add simple file backed ns support")
e806402130c9 ("block: split out request-only flags into a new namespace")
fbbaf700e7b1 ("block: trace completion of all bios.")
How should we proceed with this patch?
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-03-29 14:17 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-27 9:07 [PATCH] nvmet: fix building bvec from sg list Ming Lei
2019-03-27 9:07 ` Ming Lei
2019-03-27 13:50 ` Christoph Hellwig
2019-03-27 13:50 ` Christoph Hellwig
2019-03-29 14:17 ` Sasha Levin
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.