linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] nvmet-passthru: Limit mdts by BIO_MAX_PAGES
@ 2020-10-19 22:04 Logan Gunthorpe
  2020-10-19 22:04 ` [PATCH v3 2/2] nvmet-passthru: Cleanup nvmet_passthru_map_sg() Logan Gunthorpe
  2020-10-20  8:18 ` [PATCH v3 1/2] nvmet-passthru: Limit mdts by BIO_MAX_PAGES Sagi Grimberg
  0 siblings, 2 replies; 3+ messages in thread
From: Logan Gunthorpe @ 2020-10-19 22:04 UTC (permalink / raw)
  To: linux-nvme
  Cc: Max Gurtovoy, Logan Gunthorpe, Christoph Hellwig,
	Chaitanya Kulkarni, Sagi Grimberg

nvmet_passthru_map_sg() only supports mapping a single BIO, not a chain
so the effective maximum transfer should also be limitted by BIO_MAX_PAGES
(presently this works out to 1MB).

For PCI passthru devices the max_sectors would typically be more limitting
than BIO_MAX_PAGES, but this may not be true for all passthru devices.

Fixes: c1fef73f793b ("nvmet: add passthru code to process commands")
Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Logan Gunthorpe <logang@deltatee.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Cc: Max Gurtovoy <mgurtovoy@nvidia.com>
---

v3: Added PG_TO_SECTOR constant which uses SECTOR_SHIFT (per Max)

 drivers/nvme/target/passthru.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index dacfa7435d0b..ed6b0586173e 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -22,11 +22,12 @@ static DEFINE_XARRAY(passthru_subsystems);

 static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req)
 {
+	const int PG_TO_SECTOR = PAGE_SHIFT - SECTOR_SHIFT;
 	struct nvmet_ctrl *ctrl = req->sq->ctrl;
 	struct nvme_ctrl *pctrl = ctrl->subsys->passthru_ctrl;
 	u16 status = NVME_SC_SUCCESS;
 	struct nvme_id_ctrl *id;
-	u32 max_hw_sectors;
+	int max_hw_sectors;
 	int page_shift;

 	id = kzalloc(sizeof(*id), GFP_KERNEL);
@@ -45,9 +46,16 @@ static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req)
 	 * which depends on the host's memory fragementation. To solve this,
 	 * ensure mdts is limited to the pages equal to the number of segments.
 	 */
-	max_hw_sectors = min_not_zero(pctrl->max_segments << (PAGE_SHIFT - 9),
+	max_hw_sectors = min_not_zero(pctrl->max_segments << PG_TO_SECTOR,
 				      pctrl->max_hw_sectors);

+	/*
+	 * nvmet_passthru_map_sg is limitted to using a single bio so limit
+	 * the mdts based on BIO_MAX_PAGES as well
+	 */
+	max_hw_sectors = min_not_zero(BIO_MAX_PAGES << PG_TO_SECTOR,
+				      max_hw_sectors);
+
 	page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12;

 	id->mdts = ilog2(max_hw_sectors) + 9 - page_shift;

base-commit: bbf5c979011a099af5dc76498918ed7df445635b
--
2.20.1

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

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

end of thread, other threads:[~2020-10-20  8:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-19 22:04 [PATCH v3 1/2] nvmet-passthru: Limit mdts by BIO_MAX_PAGES Logan Gunthorpe
2020-10-19 22:04 ` [PATCH v3 2/2] nvmet-passthru: Cleanup nvmet_passthru_map_sg() Logan Gunthorpe
2020-10-20  8:18 ` [PATCH v3 1/2] nvmet-passthru: Limit mdts by BIO_MAX_PAGES Sagi Grimberg

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).