Skip to content

Commit 4c5fee0

Browse files
keithbuschgregkh
authored andcommitted
nvme-pci: fix page size checks
[ Upstream commit 8417342 ] The size allocated out of the dma pool is at most NVME_CTRL_PAGE_SIZE, which may be smaller than the PAGE_SIZE. Fixes: c61b82c ("nvme-pci: fix PRP pool size") Signed-off-by: Keith Busch <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 9141144 commit 4c5fee0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/nvme/host/pci.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#define SQ_SIZE(q) ((q)->q_depth << (q)->sqes)
3434
#define CQ_SIZE(q) ((q)->q_depth * sizeof(struct nvme_completion))
3535

36-
#define SGES_PER_PAGE (PAGE_SIZE / sizeof(struct nvme_sgl_desc))
36+
#define SGES_PER_PAGE (NVME_CTRL_PAGE_SIZE / sizeof(struct nvme_sgl_desc))
3737

3838
/*
3939
* These can be higher, but we need to ensure that any command doesn't
@@ -372,7 +372,7 @@ static int nvme_pci_npages_prp(void)
372372
{
373373
unsigned max_bytes = (NVME_MAX_KB_SZ * 1024) + NVME_CTRL_PAGE_SIZE;
374374
unsigned nprps = DIV_ROUND_UP(max_bytes, NVME_CTRL_PAGE_SIZE);
375-
return DIV_ROUND_UP(8 * nprps, PAGE_SIZE - 8);
375+
return DIV_ROUND_UP(8 * nprps, NVME_CTRL_PAGE_SIZE - 8);
376376
}
377377

378378
/*
@@ -382,7 +382,7 @@ static int nvme_pci_npages_prp(void)
382382
static int nvme_pci_npages_sgl(void)
383383
{
384384
return DIV_ROUND_UP(NVME_MAX_SEGS * sizeof(struct nvme_sgl_desc),
385-
PAGE_SIZE);
385+
NVME_CTRL_PAGE_SIZE);
386386
}
387387

388388
static size_t nvme_pci_iod_alloc_size(void)
@@ -732,7 +732,7 @@ static void nvme_pci_sgl_set_seg(struct nvme_sgl_desc *sge,
732732
sge->length = cpu_to_le32(entries * sizeof(*sge));
733733
sge->type = NVME_SGL_FMT_LAST_SEG_DESC << 4;
734734
} else {
735-
sge->length = cpu_to_le32(PAGE_SIZE);
735+
sge->length = cpu_to_le32(NVME_CTRL_PAGE_SIZE);
736736
sge->type = NVME_SGL_FMT_SEG_DESC << 4;
737737
}
738738
}

0 commit comments

Comments
 (0)