Raise the QEMU NVMe controller's MDTS beyond the 2 MiB cap.
Commit 53493c1f83 ("hw/nvme: cap MDTS value for internal limitation")
needed the 2 MiB cap because dma_blk_io() submitted the full sglist
in one preadv()/pwritev() call, which the host kernel rejects when the
iovec count exceeds IOV_MAX. This series moves the IOV_MAX bound down to
dma_blk_cb(), where we batch in IOV_MAX chunks when necessary.
dma_blk_cb() now breaks its accumulation at IOV_MAX and submits the
next chunk via the existing re-entry path. With that the DMA-path
nvme_map_addr() guard and the MDTS cap are removed. The cap stays only
for CMB/PMR, whose transfers go through a different path and are still
bounded by IOV_MAX.
This series builds cleanly under ubsan with large mdts and passes the
following fio tests on a 4k LBA QEMU NVMe device:
fio \
--name=mdts-stress \
--filename=/mnt/mdts/stress.fio \
--rw=randwrite \
--bs=8M \
--ioengine=psync \
--direct=0 \
--numjobs=8 \
--time_based \
--runtime=600 \
--fsync=8 \
--end_fsync=1 \
--group_reporting \
--refill_buffers \
--norandommap \
--offset_align=32k
fio --name=demo --filename=/dev/nvme0n1 \
--rw=write --bs=8M --size=8M --direct=1 \
--iomem_align=4 --verify=crc32c --do_verify=0
fio --name=demo --filename=/dev/nvme0n1 \
--rw=write --bs=8M --size=8M --direct=1 \
--verify=crc32c --verify_only
---
Changes in v2:
- Update cover letter.
- Rebase on top of nvme.next branch, tree:
https://gitlab.com/birkelund/qemu
- Keep the 2 MiB mdts cap for CMB/PMR configurations (Klaus)
- Fix the `mem` leak reported by Keith
- Drop NVME_MDTS_MAX, ie. unlimited mdts as long as Linux host supports
it.
Allowing larger mdts, also meant we needed to:
- Clamp the mdts and zasl shifts to stay within uint64_t
- Cap qemu_iovec_init() to IOV_MAX when the sg list is large
- Keep IO chunks aligned when chunking at IOV_MAX
- Fix the wrong bytes being discarded in the discard path
- Link to v1:
https://lore.kernel.org/qemu-devel/20260529-align-nvme-mdts-with-linux-v1-0-221d4d21a...@samsung.com
To: [email protected]
Cc: Paolo Bonzini <[email protected]>
Cc: Peter Xu <[email protected]>
Cc: Philippe Mathieu-Daudé <[email protected]>
Cc: Keith Busch <[email protected]>
Cc: Klaus Jensen <[email protected]>
Cc: Klaus Jensen <[email protected]>
Cc: Jesper Devantier <[email protected]>
Cc: [email protected]
Cc: Daniel Gomez <[email protected]>
Cc: Daniel Gomez <[email protected]>
Cc: GOST <[email protected]>
Signed-off-by: Daniel Gomez <[email protected]>
---
Daniel Gomez (7):
dma-helpers: fix unaligned discard_back
dma-helpers: ensure IOV_MAX chunks end aligned
dma-helpers: cap iovec allocation at IOV_MAX
dma-helpers: chunk dma_blk_cb at IOV_MAX
hw/nvme: clamp mdts and zasl shifts
hw/nvme: drop DMA-path IOV_MAX guard
hw/nvme: cap mdts for CMB/PMR-only
hw/nvme/ctrl.c | 21 +++++++++++++--------
system/dma-helpers.c | 19 ++++++++++++++++---
2 files changed, 29 insertions(+), 11 deletions(-)
---
base-commit: 7a34f7b8794b29cd1bd4dfa45f7d8e8daba7cff5
change-id: 20260528-align-nvme-mdts-with-linux-67d618f6730b
Best regards,
--
Daniel Gomez <[email protected]>