* [PATCH] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
@ 2026-08-27 17:24 Thomas Lamprecht
2026-09-03 3:10 ` Martin K. Petersen (Oracle)
0 siblings, 1 reply; 4+ messages in thread
From: Thomas Lamprecht @ 2026-08-27 17:24 UTC (permalink / raw)
To: Kashyap Desai, Sumit Saxena, Shivasharan S, Chandrakanth patil,
megaraidlinux.pdl, Martin K . Petersen
Cc: James E . J . Bottomley, linux-scsi, linux-kernel,
Damien Le Moal, Jens Axboe, Keith Busch, Ranjan Kumar,
Thorsten Leemhuis, regressions, Lukasz Magiera, Mira Limbeck,
Daniel Fernau, Mats Topstad, stable
megasas_make_prp_nvme() builds a command's PRP list in cmd->sg_frame, a
DMA pool buffer of instance->max_chain_frame_sz bytes, spending one entry
per NVMe page of the transfer plus one per page of the buffer for the
chain pointer. The loop runs until the transfer is described and never
checks the buffer bound.
max_hw_sectors comes straight from the MDTS the firmware reports for the
drive. On drives with a large MDTS the only thing keeping the list inside
the buffer was the block layer default of 1280 KiB, which needs 320
entries, which fit into a 4 KiB frame as that holds 512. But since commit
9b8b84879d4a ("block: Increase BLK_DEF_MAX_SECTORS_CAP") that default is
4 MiB, and such a transfer needs 1025 entries, so the list runs a full
page past the end of the frame:
sd 1:0:1:0: [sdb] tag#630 page boundary ptr_sgl: 0x00000000ba62d13f
BUG: unable to handle page fault for address: ff663bcb81e7c000
#PF: supervisor write access in kernel mode
#PF: error_code(0x0002) - not-present page
RIP: 0010:megasas_build_and_issue_cmd_fusion+0xeaa/0x1870 [megaraid_sas]
If the page after the frame happens to be mapped, the overrun does not
fault but silently corrupts the neighbouring pool entry, which is another
in-flight command's PRP list.
Cap max_hw_sectors at what the chain frame can describe, less one page
for transfers that do not start on a page boundary and so need one entry
more. This is the megaraid_sas counterpart of commit 04631f55afc5 ("scsi:
mpt3sas: Limit NVMe request size to 2 MiB"), but derives the limit from
max_chain_frame_sz rather than hardcoding it.
Cc: stable@vger.kernel.org
Fixes: 9b8b84879d4a ("block: Increase BLK_DEF_MAX_SECTORS_CAP")
Reported-by: Lukasz Magiera <me@magik.net>
Closes: https://lore.kernel.org/all/GPhsSM0vkgyIrs0DIZ62qeUZX7X4RxwQXVKiuvMx-lHQVSPDxpztUyQOGS0xikqvJ-Z94hMV-dW_5KN_0CX2hsfV7kTf_t0MTf6vdAAaSEc=@magik.net/
Reported-by: Mira Limbeck <m.limbeck@proxmox.com>
Closes: https://lore.kernel.org/all/d171cc76-bf25-48ce-b482-d344669dfc24@proxmox.com/
Suggested-by: Martin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/all/yq17bmzd5jr.fsf@ca-mkp.ca.oracle.com/
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
Based on current master, but mostly tested on our downstream 7.0-based
kernel.
The derived cap was checked against a replay of the pointer arithmetic in
megasas_make_prp_nvme(), for chain frames of 1024
(MEGASAS_CHAIN_FRAME_SZ_MIN) to 15872 bytes and NVMe page sizes of 4 and
8 KiB, at every 512 byte start offset, with both fully coalesced and
one-entry-per-page scatterlists.
drivers/scsi/megaraid/megaraid_sas_base.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index ecd365d78ae3c14f4682d61063b6f216974daa7d..d83abded2039ba9ffae23d0c78a79e155b32424f 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -1973,12 +1973,23 @@ megasas_set_nvme_device_properties(struct scsi_device *sdev,
{
struct megasas_instance *instance;
u32 mr_nvme_pg_size;
+ u64 max_prp_io;
instance = (struct megasas_instance *)sdev->host->hostdata;
mr_nvme_pg_size = max_t(u32, instance->nvme_page_size,
MR_DEFAULT_NVME_PAGE_SIZE);
- lim->max_hw_sectors = max_io_size / 512;
+ /*
+ * megasas_make_prp_nvme() builds the PRP list in cmd->sg_frame without
+ * bounding it against that buffer, and spends one entry per page of
+ * it on the chain pointer. Cap the transfer at what the buffer holds,
+ * less one page for lists that start off a page boundary.
+ */
+ max_prp_io = (u64)((instance->max_chain_frame_sz / sizeof(u64)) -
+ (instance->max_chain_frame_sz / mr_nvme_pg_size) - 1) *
+ mr_nvme_pg_size;
+
+ lim->max_hw_sectors = min_t(u64, max_io_size, max_prp_io) >> SECTOR_SHIFT;
lim->virt_boundary_mask = mr_nvme_pg_size - 1;
}
base-commit: 18fbf5151d2c0bfe433c7428eef03cabf5fdb2fa
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
2026-08-27 17:24 [PATCH] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame Thomas Lamprecht
@ 2026-09-03 3:10 ` Martin K. Petersen (Oracle)
2026-09-15 12:24 ` Daniel Fernau
0 siblings, 1 reply; 4+ messages in thread
From: Martin K. Petersen (Oracle) @ 2026-09-03 3:10 UTC (permalink / raw)
To: Kashyap Desai, Sumit Saxena, Shivasharan S, Chandrakanth patil,
megaraidlinux.pdl, Martin K. Petersen, Thomas Lamprecht
Cc: James E . J . Bottomley, linux-scsi, linux-kernel,
Damien Le Moal, Jens Axboe, Keith Busch, Ranjan Kumar,
Thorsten Leemhuis, regressions, Lukasz Magiera, Mira Limbeck,
Daniel Fernau, Mats Topstad, stable
On Thu, 27 Aug 2026 19:24:24 +0200, Thomas Lamprecht wrote:
> megasas_make_prp_nvme() builds a command's PRP list in cmd->sg_frame, a
> DMA pool buffer of instance->max_chain_frame_sz bytes, spending one entry
> per NVMe page of the transfer plus one per page of the buffer for the
> chain pointer. The loop runs until the transfer is described and never
> checks the buffer bound.
>
> max_hw_sectors comes straight from the MDTS the firmware reports for the
> drive. On drives with a large MDTS the only thing keeping the list inside
> the buffer was the block layer default of 1280 KiB, which needs 320
> entries, which fit into a 4 KiB frame as that holds 512. But since commit
> 9b8b84879d4a ("block: Increase BLK_DEF_MAX_SECTORS_CAP") that default is
> 4 MiB, and such a transfer needs 1025 entries, so the list runs a full
> page past the end of the frame:
>
> [...]
Applied to 7.3/scsi-fixes, thanks!
[1/1] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
https://git.kernel.org/mkp/scsi/c/af8c27375733
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
2026-09-03 3:10 ` Martin K. Petersen (Oracle)
@ 2026-09-15 12:24 ` Daniel Fernau
2026-09-16 2:01 ` Martin K. Petersen (Oracle)
0 siblings, 1 reply; 4+ messages in thread
From: Daniel Fernau @ 2026-09-15 12:24 UTC (permalink / raw)
To: Martin K. Petersen (Oracle)
Cc: Kashyap Desai, Sumit Saxena, Shivasharan S, Chandrakanth patil,
megaraidlinux.pdl, Thomas Lamprecht, James E . J . Bottomley,
linux-scsi, linux-kernel, Damien Le Moal, Jens Axboe,
Keith Busch, Ranjan Kumar, Thorsten Leemhuis, regressions,
Lukasz Magiera, Mira Limbeck, Mats Topstad, stable
Follow-up from our earlier note on pinning 6.8.12-4-pve.
We have now been running the HPE MR416i-o Gen11 cluster on Proxmox
kernel 7.0.14-15-pve without the previous megasas_make_prp_nvme
overflow.
Hardware / firmware
- HPE MR416i-o Gen11 (Broadcom PCI 0x1000:0x10e2)
- HPE FW package 52.32.3-6333 / controller FW 5.320.03-4207
- megaraid_sas 07.734.00.00-rc1
- KIOXIA NVMe behind the controller
7.0.14-15-pve includes
"scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame"
(pve-kernel 46a6f4f). That is the driver-side max_hw_sectors cap
Martin suggested and the megaraid equivalent of Damien's
04631f55afc5 ("scsi: mpt3sas: Limit NVMe request size to 2 MiB"),
not Lukasz's original bounds check in megasas_make_prp_nvme().
On this hardware the cap is enough. We no longer need the
max_sectors_kb udev workaround, and we do not see the page-boundary
ptr_sgl fault (RAX=0x200 / 512th PRP slot) under production load.
Thanks,
Daniel
On Thursday, September 3rd, 2026 at 5:10 AM, Martin K. Petersen (Oracle) <mkp@kernel.org> wrote:
> On Thu, 27 Aug 2026 19:24:24 +0200, Thomas Lamprecht wrote:
>
> > megasas_make_prp_nvme() builds a command's PRP list in cmd->sg_frame, a
> > DMA pool buffer of instance->max_chain_frame_sz bytes, spending one entry
> > per NVMe page of the transfer plus one per page of the buffer for the
> > chain pointer. The loop runs until the transfer is described and never
> > checks the buffer bound.
> >
> > max_hw_sectors comes straight from the MDTS the firmware reports for the
> > drive. On drives with a large MDTS the only thing keeping the list inside
> > the buffer was the block layer default of 1280 KiB, which needs 320
> > entries, which fit into a 4 KiB frame as that holds 512. But since commit
> > 9b8b84879d4a ("block: Increase BLK_DEF_MAX_SECTORS_CAP") that default is
> > 4 MiB, and such a transfer needs 1025 entries, so the list runs a full
> > page past the end of the frame:
> >
> > [...]
>
> Applied to 7.3/scsi-fixes, thanks!
>
> [1/1] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
> https://git.kernel.org/mkp/scsi/c/af8c27375733
>
> --
> Martin K. Petersen
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame
2026-09-15 12:24 ` Daniel Fernau
@ 2026-09-16 2:01 ` Martin K. Petersen (Oracle)
0 siblings, 0 replies; 4+ messages in thread
From: Martin K. Petersen (Oracle) @ 2026-09-16 2:01 UTC (permalink / raw)
To: Daniel Fernau
Cc: Kashyap Desai, Sumit Saxena, Shivasharan S, Chandrakanth patil,
megaraidlinux.pdl, Thomas Lamprecht, James E . J . Bottomley,
linux-scsi, linux-kernel, Damien Le Moal, Jens Axboe,
Keith Busch, Ranjan Kumar, Thorsten Leemhuis, regressions,
Lukasz Magiera, Mira Limbeck, Mats Topstad, stable
Daniel,
> On this hardware the cap is enough. We no longer need the
> max_sectors_kb udev workaround, and we do not see the page-boundary
> ptr_sgl fault (RAX=0x200 / 512th PRP slot) under production load.
Great, thanks for testing!
--
Martin K. Petersen
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-16 2:01 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-08-27 17:24 [PATCH] scsi: megaraid_sas: Limit NVMe request size to the PRP chain frame Thomas Lamprecht
2026-09-03 3:10 ` Martin K. Petersen (Oracle)
2026-09-15 12:24 ` Daniel Fernau
2026-09-16 2:01 ` Martin K. Petersen (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®