Skip to content

Commit

Permalink
nvmet: limit passthru MTDS by BIO_MAX_PAGES
Browse files Browse the repository at this point in the history
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: c1fef73 ("nvmet: add passthru code to process commands")
Suggested-by: Christoph Hellwig <[email protected]>
Signed-off-by: Logan Gunthorpe <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Sagi Grimberg <[email protected]>
Cc: Chaitanya Kulkarni <[email protected]>
Signed-off-by: Christoph Hellwig <[email protected]>
  • Loading branch information
lsgunth authored and Christoph Hellwig committed Oct 22, 2020
1 parent 85bd23f commit df06047
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion drivers/nvme/target/passthru.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req)
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);
Expand All @@ -48,6 +48,13 @@ static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req)
max_hw_sectors = min_not_zero(pctrl->max_segments << (PAGE_SHIFT - 9),
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 << (PAGE_SHIFT - 9),
max_hw_sectors);

page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12;

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

0 comments on commit df06047

Please sign in to comment.