Add Multiple Atomicity Mode (MAM) emulation support. MAM is a superset
of Single Atomicity Mode (SAM): per the NVMe spec, a write command that
crosses a Namespace Atomic Boundary is divided into LBA subranges, each
written atomically. The emulation reuses the atomic write support from
commit ebd1568fc732 ("hw/nvme: add atomic write support"): when MAM is
enabled, the size and boundary limits that decide whether a write is
atomic no longer apply, so the whole command is serialized as one atomic
write.

A namespace enables it with atomic.map=on alongside
the existing per-namespace atomicity parameters. Example:

    -device nvme,serial=foo,id=nvme0 \
    -drive file=nvme0.qcow2,if=none,format=qcow2,id=nvme0-ns0 \
    -device nvme-ns,drive=nvme0-ns0,bus=nvme0,atomic.nawun=7,\
      atomic.nawupf=7,atomic.nabsn=7,atomic.nabspf=7,atomic.mam=on

Quering the result with nvme-cli:
nvme id-ns -H /dev/nvme0n1 | head
NVME Identify Namespace 1:
nsze    : 0x500000      Total size in logical blocks
ncap    : 0x500000      Maximum size in logical blocks
nuse    : 0x500000      Current size in logical blocks
nsfeat  : 0x76
  [7:7] : 0     NPRG, NPRA and NORS are Not Supported
  [6:6] : 0x1   Multiple Atomicity Mode applies to write operations

While at it, fix endianness issues on the atomic write command path
(first patch) and update hw/nvme docs with atomic writes section.

Baseline: nvme.next branch; tree: https://gitlab.com/birkelund/qemu

Signed-off-by: Daniel Gomez <[email protected]>
---
Daniel Gomez (5):
      hw/nvme: fix endianness handling in the atomic write path
      hw/nvme: add missing atomic.* fields in usage
      docs: add hw/nvme atomics section
      hw/nvme: add multiple atomicity mode support
      docs: update hw/nvme atomics with mam

 docs/system/devices/nvme.rst | 47 ++++++++++++++++++++++++++++++++++++++++++--
 hw/nvme/ctrl.c               | 40 +++++++++++++++++++++++--------------
 hw/nvme/ns.c                 | 27 ++++++++++++++++++++++++-
 hw/nvme/nvme.h               |  1 +
 4 files changed, 97 insertions(+), 18 deletions(-)
---
base-commit: 7a34f7b8794b29cd1bd4dfa45f7d8e8daba7cff5
change-id: 20260824-nvme-mam-3af8616d6e37

Best regards,
--  
Daniel Gomez <[email protected]>


Reply via email to