linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme-pci: add missing condition check for existence of mapped data
@ 2024-07-24 10:31 ` Leon Romanovsky
  2024-07-24 17:57   ` Nitesh Shetty
                     ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Leon Romanovsky @ 2024-07-24 10:31 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
  Cc: Leon Romanovsky, Chaitanya Kulkarni, linux-nvme, linux-kernel

From: Leon Romanovsky <leonro@nvidia.com>

nvme_map_data() is called when request has physical segments, hence
the nvme_unmap_data() should have same condition to avoid dereference.

Fixes: 4aedb705437f ("nvme-pci: split metadata handling from nvme_map_data / nvme_unmap_data")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 drivers/nvme/host/pci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 102a9fb0c65f..cdc0b25091e9 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -863,7 +863,8 @@ static blk_status_t nvme_prep_rq(struct nvme_dev *dev, struct request *req)
 	nvme_start_request(req);
 	return BLK_STS_OK;
 out_unmap_data:
-	nvme_unmap_data(dev, req);
+	if (blk_rq_nr_phys_segments(req))
+		nvme_unmap_data(dev, req);
 out_free_cmd:
 	nvme_cleanup_cmd(req);
 	return ret;
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-pci: add missing condition check for existence of mapped data
  2024-07-24 10:31 ` [PATCH] nvme-pci: add missing condition check for existence of mapped data Leon Romanovsky
@ 2024-07-24 17:57   ` Nitesh Shetty
  2024-07-25 14:06   ` Christoph Hellwig
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Nitesh Shetty @ 2024-07-24 17:57 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Leon Romanovsky, Chaitanya Kulkarni, linux-nvme, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 437 bytes --]

On 24/07/24 01:31PM, Leon Romanovsky wrote:
>From: Leon Romanovsky <leonro@nvidia.com>
>
>nvme_map_data() is called when request has physical segments, hence
>the nvme_unmap_data() should have same condition to avoid dereference.
>
>Fixes: 4aedb705437f ("nvme-pci: split metadata handling from nvme_map_data / nvme_unmap_data")
>Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
>---

Reviewed-by: Nitesh Shetty <nj.shetty@samsung.com>

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-pci: add missing condition check for existence of mapped data
  2024-07-24 10:31 ` [PATCH] nvme-pci: add missing condition check for existence of mapped data Leon Romanovsky
  2024-07-24 17:57   ` Nitesh Shetty
@ 2024-07-25 14:06   ` Christoph Hellwig
  2024-07-25 14:29   ` Keith Busch
  2024-07-30 17:09   ` Keith Busch
  3 siblings, 0 replies; 8+ messages in thread
From: Christoph Hellwig @ 2024-07-25 14:06 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Leon Romanovsky, Chaitanya Kulkarni, linux-nvme, linux-kernel

Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-pci: add missing condition check for existence of mapped data
  2024-07-24 10:31 ` [PATCH] nvme-pci: add missing condition check for existence of mapped data Leon Romanovsky
  2024-07-24 17:57   ` Nitesh Shetty
  2024-07-25 14:06   ` Christoph Hellwig
@ 2024-07-25 14:29   ` Keith Busch
  2024-07-30 17:09   ` Keith Busch
  3 siblings, 0 replies; 8+ messages in thread
From: Keith Busch @ 2024-07-25 14:29 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Leon Romanovsky,
	Chaitanya Kulkarni, linux-nvme, linux-kernel

On Wed, Jul 24, 2024 at 01:31:14PM +0300, Leon Romanovsky wrote:
> From: Leon Romanovsky <leonro@nvidia.com>
> 
> nvme_map_data() is called when request has physical segments, hence
> the nvme_unmap_data() should have same condition to avoid dereference.

Thanks, applied to nvme-6.11.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-pci: add missing condition check for existence of mapped data
  2024-07-24 10:31 ` [PATCH] nvme-pci: add missing condition check for existence of mapped data Leon Romanovsky
                     ` (2 preceding siblings ...)
  2024-07-25 14:29   ` Keith Busch
@ 2024-07-30 17:09   ` Keith Busch
  2024-07-30 17:21     ` Christoph Hellwig
  3 siblings, 1 reply; 8+ messages in thread
From: Keith Busch @ 2024-07-30 17:09 UTC (permalink / raw)
  To: Leon Romanovsky
  Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Leon Romanovsky,
	Chaitanya Kulkarni, linux-nvme, linux-kernel

On Wed, Jul 24, 2024 at 01:31:14PM +0300, Leon Romanovsky wrote:
> diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
> index 102a9fb0c65f..cdc0b25091e9 100644
> --- a/drivers/nvme/host/pci.c
> +++ b/drivers/nvme/host/pci.c
> @@ -863,7 +863,8 @@ static blk_status_t nvme_prep_rq(struct nvme_dev *dev, struct request *req)
>  	nvme_start_request(req);
>  	return BLK_STS_OK;
>  out_unmap_data:
> -	nvme_unmap_data(dev, req);
> +	if (blk_rq_nr_phys_segments(req))
> +		nvme_unmap_data(dev, req);

This is already applied, but it is kind of strange. We get here only if
metadata mapping fails. Is there actually a command that has metadata
without data?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-pci: add missing condition check for existence of mapped data
  2024-07-30 17:09   ` Keith Busch
@ 2024-07-30 17:21     ` Christoph Hellwig
  2024-07-30 17:33       ` Keith Busch
  2024-07-30 17:39       ` Leon Romanovsky
  0 siblings, 2 replies; 8+ messages in thread
From: Christoph Hellwig @ 2024-07-30 17:21 UTC (permalink / raw)
  To: Keith Busch
  Cc: Leon Romanovsky, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
	Leon Romanovsky, Chaitanya Kulkarni, linux-nvme, linux-kernel

On Tue, Jul 30, 2024 at 11:09:04AM -0600, Keith Busch wrote:
> > +	if (blk_rq_nr_phys_segments(req))
> > +		nvme_unmap_data(dev, req);
> 
> This is already applied, but it is kind of strange. We get here only if
> metadata mapping fails. Is there actually a command that has metadata
> without data?

Well, passthrough can always set metadata to map without data even
if there is no NVMe defined command that works that way, so we should
handle the error.

But I suspect this is due to Leon's dma-mapping work, and it probably
points to a bug in that :)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-pci: add missing condition check for existence of mapped data
  2024-07-30 17:21     ` Christoph Hellwig
@ 2024-07-30 17:33       ` Keith Busch
  2024-07-30 17:39       ` Leon Romanovsky
  1 sibling, 0 replies; 8+ messages in thread
From: Keith Busch @ 2024-07-30 17:33 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Leon Romanovsky, Jens Axboe, Sagi Grimberg, Leon Romanovsky,
	Chaitanya Kulkarni, linux-nvme, linux-kernel

On Tue, Jul 30, 2024 at 07:21:11PM +0200, Christoph Hellwig wrote:
> On Tue, Jul 30, 2024 at 11:09:04AM -0600, Keith Busch wrote:
> > > +	if (blk_rq_nr_phys_segments(req))
> > > +		nvme_unmap_data(dev, req);
> > 
> > This is already applied, but it is kind of strange. We get here only if
> > metadata mapping fails. Is there actually a command that has metadata
> > without data?
> 
> Well, passthrough can always set metadata to map without data even
> if there is no NVMe defined command that works that way, so we should
> handle the error.

That's what I initially thought too, but nvme passthrough maps metadata
only if there's also user data. It doesn't look like you can even build
a request to have metadata if it doesn't have user data: where does the
bio come from in that case?

And generic block stack maps it only for READ or WRITE commands, which
must have payloads too, so I didn't find a path to reach this condition.

Not a big deal, the patch is fine, but I was wondering if we need to
change something else to allow the conditions it proposes to fix.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] nvme-pci: add missing condition check for existence of mapped data
  2024-07-30 17:21     ` Christoph Hellwig
  2024-07-30 17:33       ` Keith Busch
@ 2024-07-30 17:39       ` Leon Romanovsky
  1 sibling, 0 replies; 8+ messages in thread
From: Leon Romanovsky @ 2024-07-30 17:39 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Keith Busch, Jens Axboe, Sagi Grimberg, Chaitanya Kulkarni,
	linux-nvme, linux-kernel

On Tue, Jul 30, 2024 at 07:21:11PM +0200, Christoph Hellwig wrote:
> On Tue, Jul 30, 2024 at 11:09:04AM -0600, Keith Busch wrote:
> > > +	if (blk_rq_nr_phys_segments(req))
> > > +		nvme_unmap_data(dev, req);
> > 
> > This is already applied, but it is kind of strange. We get here only if
> > metadata mapping fails. Is there actually a command that has metadata
> > without data?
> 
> Well, passthrough can always set metadata to map without data even
> if there is no NVMe defined command that works that way, so we should
> handle the error.
> 
> But I suspect this is due to Leon's dma-mapping work, and it probably
> points to a bug in that :)

Yeah, something like that. I had a bug in my code and saw this
asymmetry while reviewed all paths which lead to nvme_unmap_data().

Thanks


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-07-30 17:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20240724180451epcas5p3cffc89fcc59156ca49078a60851f1e29@epcas5p3.samsung.com>
2024-07-24 10:31 ` [PATCH] nvme-pci: add missing condition check for existence of mapped data Leon Romanovsky
2024-07-24 17:57   ` Nitesh Shetty
2024-07-25 14:06   ` Christoph Hellwig
2024-07-25 14:29   ` Keith Busch
2024-07-30 17:09   ` Keith Busch
2024-07-30 17:21     ` Christoph Hellwig
2024-07-30 17:33       ` Keith Busch
2024-07-30 17:39       ` Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).