* [PATCH 01/18] nvme: add missing unmaps in nvme_queue_rq
[not found] <1444975128-8768-1-git-send-email-hch@lst.de>
@ 2015-10-16 5:58 ` Christoph Hellwig
2015-10-20 10:04 ` Sagi Grimberg
0 siblings, 1 reply; 3+ messages in thread
From: Christoph Hellwig @ 2015-10-16 5:58 UTC (permalink / raw)
To: axboe
Cc: keith.busch, james_p_freyensee, jay.e.sternberg, phil.cayton,
mlin, linux-nvme, stable
When we fail various metadata related operations in nvme_queue_rq we
need to unmap the data SGL.
Cc: stable@vger.kernel.org
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/pci.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 22d8375..2f05292 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -906,19 +906,28 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
goto retry_cmd;
}
if (blk_integrity_rq(req)) {
- if (blk_rq_count_integrity_sg(req->q, req->bio) != 1)
+ if (blk_rq_count_integrity_sg(req->q, req->bio) != 1) {
+ dma_unmap_sg(dev->dev, iod->sg, iod->nents,
+ dma_dir);
goto error_cmd;
+ }
sg_init_table(iod->meta_sg, 1);
if (blk_rq_map_integrity_sg(
- req->q, req->bio, iod->meta_sg) != 1)
+ req->q, req->bio, iod->meta_sg) != 1) {
+ dma_unmap_sg(dev->dev, iod->sg, iod->nents,
+ dma_dir);
goto error_cmd;
+ }
if (rq_data_dir(req))
nvme_dif_remap(req, nvme_dif_prep);
- if (!dma_map_sg(nvmeq->q_dmadev, iod->meta_sg, 1, dma_dir))
+ if (!dma_map_sg(nvmeq->q_dmadev, iod->meta_sg, 1, dma_dir)) {
+ dma_unmap_sg(dev->dev, iod->sg, iod->nents,
+ dma_dir);
goto error_cmd;
+ }
}
}
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 01/18] nvme: add missing unmaps in nvme_queue_rq
2015-10-16 5:58 ` [PATCH 01/18] nvme: add missing unmaps in nvme_queue_rq Christoph Hellwig
@ 2015-10-20 10:04 ` Sagi Grimberg
2015-10-20 14:07 ` Busch, Keith
0 siblings, 1 reply; 3+ messages in thread
From: Sagi Grimberg @ 2015-10-20 10:04 UTC (permalink / raw)
To: Christoph Hellwig, axboe
Cc: jay.e.sternberg, linux-nvme, keith.busch, phil.cayton, stable,
james_p_freyensee, mlin
On 10/16/2015 8:58 AM, Christoph Hellwig wrote:
> When we fail various metadata related operations in nvme_queue_rq we
> need to unmap the data SGL.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> drivers/nvme/host/pci.c | 15 ++++++++++++---
> 1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 22d8375..2f05292 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -906,19 +906,28 @@ static int nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
> goto retry_cmd;
> }
> if (blk_integrity_rq(req)) {
> - if (blk_rq_count_integrity_sg(req->q, req->bio) != 1)
> + if (blk_rq_count_integrity_sg(req->q, req->bio) != 1) {
> + dma_unmap_sg(dev->dev, iod->sg, iod->nents,
> + dma_dir);
> goto error_cmd;
> + }
>
> sg_init_table(iod->meta_sg, 1);
> if (blk_rq_map_integrity_sg(
> - req->q, req->bio, iod->meta_sg) != 1)
> + req->q, req->bio, iod->meta_sg) != 1) {
> + dma_unmap_sg(dev->dev, iod->sg, iod->nents,
> + dma_dir);
> goto error_cmd;
> + }
This is not related to the patch itself. But this condition seems bogus
to me. We passed meta_sg that consists of a single entry. If we
happened to map more than a single entry we're already in trouble as we
overrun meta_sg (modified the iod->sg pointer).
I think a WARN_ON_ONCE statement is more suitable here (which should
probably come as a separate patch).
Other than that, looks good to me:
Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 01/18] nvme: add missing unmaps in nvme_queue_rq
2015-10-20 10:04 ` Sagi Grimberg
@ 2015-10-20 14:07 ` Busch, Keith
0 siblings, 0 replies; 3+ messages in thread
From: Busch, Keith @ 2015-10-20 14:07 UTC (permalink / raw)
To: Sagi Grimberg
Cc: Christoph Hellwig, axboe, jay.e.sternberg, linux-nvme,
phil.cayton, stable, james_p_freyensee, mlin
On Tue, Oct 20, 2015 at 01:04:24PM +0300, Sagi Grimberg wrote:
> On 10/16/2015 8:58 AM, Christoph Hellwig wrote:
> > sg_init_table(iod->meta_sg, 1);
> > if (blk_rq_map_integrity_sg(
> >- req->q, req->bio, iod->meta_sg) != 1)
> >+ req->q, req->bio, iod->meta_sg) != 1) {
> >+ dma_unmap_sg(dev->dev, iod->sg, iod->nents,
> >+ dma_dir);
> > goto error_cmd;
> >+ }
>
> This is not related to the patch itself. But this condition seems bogus
> to me. We passed meta_sg that consists of a single entry. If we
> happened to map more than a single entry we're already in trouble as we
> overrun meta_sg (modified the iod->sg pointer).
>
> I think a WARN_ON_ONCE statement is more suitable here (which should
> probably come as a separate patch).
We are in trouble if it maps more than 1, but I think the condition
here is intended to guard against 0 rather than > 1. We should already
be ensured it won't be > 1 from a previous check.
Based on the implementation of blk_rq_map_integrity_sg and the functions
earlier setup, I don't think we can ever see 0 here either.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-20 14:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1444975128-8768-1-git-send-email-hch@lst.de>
2015-10-16 5:58 ` [PATCH 01/18] nvme: add missing unmaps in nvme_queue_rq Christoph Hellwig
2015-10-20 10:04 ` Sagi Grimberg
2015-10-20 14:07 ` Busch, Keith
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox