From: Keith Busch <kbusch@meta.com>
To: <linux-nvme@lists.infradead.org>
Cc: <hch@lst.de>, Keith Busch <kbusch@kernel.org>
Subject: [PATCHv2 2/2] nvme-pci: use sgls for all user requests if possible
Date: Tue, 12 Nov 2024 13:06:20 -0800 [thread overview]
Message-ID: <20241112210620.2650523-3-kbusch@meta.com> (raw)
In-Reply-To: <20241112210620.2650523-1-kbusch@meta.com>
From: Keith Busch <kbusch@kernel.org>
If the device supports SGLs, use these for all user requests. This
format encodes the expected transfer length so it can catch short buffer
errors in a user command, whether it occurred accidently or maliciously.
For controllers that support SGL data mode, this is a viable mitigation
to CVE-2023-6238.
Signed-off-by: Keith Busch <kbusch@kernel.org>
---
drivers/nvme/host/pci.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 919f173043d18..8f59ff3be8cea 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -515,7 +515,8 @@ static inline bool nvme_pci_metadata_use_sgls(struct nvme_dev *dev,
{
if (!nvme_ctrl_meta_sgl_supported(&dev->ctrl))
return false;
- return req->nr_integrity_segments > 1;
+ return req->nr_integrity_segments > 1 ||
+ nvme_req(req)->flags & NVME_REQ_USERCMD;
}
static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req,
@@ -533,7 +534,7 @@ static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req,
if (nvme_pci_metadata_use_sgls(dev, req))
return true;
if (!sgl_threshold || avg_seg_size < sgl_threshold)
- return false;
+ return nvme_req(req)->flags & NVME_REQ_USERCMD;
return true;
}
--
2.43.5
next prev parent reply other threads:[~2024-11-12 21:08 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-12 21:06 [PATCHv2 0/2] Using SGLs for userspace commands Keith Busch
2024-11-12 21:06 ` [PATCHv2 1/2] nvme-pci: add support for sgl metadata Keith Busch
2024-11-13 4:58 ` Christoph Hellwig
2024-11-13 15:48 ` Keith Busch
2024-11-12 21:06 ` Keith Busch [this message]
2024-11-13 4:58 ` [PATCHv2 2/2] nvme-pci: use sgls for all user requests if possible Christoph Hellwig
2024-11-13 15:48 ` Keith Busch
2024-11-14 5:56 ` Christoph Hellwig
2024-11-14 15:53 ` Keith Busch
2024-11-14 16:42 ` Christoph Hellwig
2024-11-14 17:29 ` Keith Busch
2024-11-13 4:50 ` [PATCHv2 0/2] Using SGLs for userspace commands Christoph Hellwig
2024-11-13 15:50 ` Keith Busch
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=20241112210620.2650523-3-kbusch@meta.com \
--to=kbusch@meta.com \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.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