Skip to content

Commit df06047

Browse files
lsgunthChristoph Hellwig
authored andcommitted
nvmet: limit passthru MTDS by BIO_MAX_PAGES
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 <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> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 85bd23f commit df06047

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

drivers/nvme/target/passthru.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req)
2626
struct nvme_ctrl *pctrl = ctrl->subsys->passthru_ctrl;
2727
u16 status = NVME_SC_SUCCESS;
2828
struct nvme_id_ctrl *id;
29-
u32 max_hw_sectors;
29+
int max_hw_sectors;
3030
int page_shift;
3131

3232
id = kzalloc(sizeof(*id), GFP_KERNEL);
@@ -48,6 +48,13 @@ static u16 nvmet_passthru_override_id_ctrl(struct nvmet_req *req)
4848
max_hw_sectors = min_not_zero(pctrl->max_segments << (PAGE_SHIFT - 9),
4949
pctrl->max_hw_sectors);
5050

51+
/*
52+
* nvmet_passthru_map_sg is limitted to using a single bio so limit
53+
* the mdts based on BIO_MAX_PAGES as well
54+
*/
55+
max_hw_sectors = min_not_zero(BIO_MAX_PAGES << (PAGE_SHIFT - 9),
56+
max_hw_sectors);
57+
5158
page_shift = NVME_CAP_MPSMIN(ctrl->cap) + 12;
5259

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

0 commit comments

Comments
 (0)