All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kanchan Joshi <joshi.k@samsung.com>
To: Keith Busch <kbusch@meta.com>
Cc: linux-nvme@lists.infradead.org, hch@lst.de, sagi@grimberg.me,
	Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>
Subject: Re: [PATCH] nvme-pci: Fix mempool alloc size
Date: Wed, 21 Dec 2022 13:32:49 +0530	[thread overview]
Message-ID: <20221221080249.GA896@green> (raw)
In-Reply-To: <20221219185906.3595984-1-kbusch@meta.com>

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

On Mon, Dec 19, 2022 at 10:59:06AM -0800, Keith Busch wrote:
>From: Keith Busch <kbusch@kernel.org>
>
>Convert the max size to bytes to match the units of the divisor that
>calculates the worst-case number of PRP entries.
>
>The result is used to determine how many PRP Lists are required. The
>code was previously rounding this to 1 list, but we can require 2 in the
>worst case. In that scenario, the driver would corrupt memory beyond the
>size provided by the mempool.
>
>While unlikely to occur (you'd need a 4MB in exactly 127 phys segments
>on a queue that doesn't support SGLs), this memory corruption has been
>observed by kfence.
>
>Cc: Jens Axboe <axboe@kernel.dk>
>Fixes: 943e942e6266f ("nvme-pci: limit max IO size and segments to avoid high order allocations")
>Signed-off-by: Keith Busch <kbusch@kernel.org>
>---
> drivers/nvme/host/pci.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
>index f0f8027644bbf..fa182fcd4c3e8 100644
>--- a/drivers/nvme/host/pci.c
>+++ b/drivers/nvme/host/pci.c
>@@ -380,8 +380,8 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, u32 *dbbuf_db,
>  */
> static int nvme_pci_npages_prp(void)
> {
>-	unsigned nprps = DIV_ROUND_UP(NVME_MAX_KB_SZ + NVME_CTRL_PAGE_SIZE,
>-				      NVME_CTRL_PAGE_SIZE);

Similar calculation is present in apple.c too.
Regardless, this looks good.
Reviewed-by: Kanchan Joshi <joshi.k@samsung.com>


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



  parent reply	other threads:[~2022-12-21  8:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20221219195515epcas5p200e1e1f3430ac6f494a66740bfb6a3b3@epcas5p2.samsung.com>
2022-12-19 18:59 ` [PATCH] nvme-pci: Fix mempool alloc size Keith Busch
2022-12-19 19:07   ` Jens Axboe
2022-12-20  6:08   ` Chaitanya Kulkarni
2022-12-21  8:02   ` Kanchan Joshi [this message]
2022-12-21  8:04   ` Christoph Hellwig

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=20221221080249.GA896@green \
    --to=joshi.k@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=kbusch@meta.com \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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 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.