Linux block layer
 help / color / mirror / Atom feed
From: Daniel Gomez <da.gomez@kernel.org>
To: Jens Axboe <axboe@kernel.dk>, Keith Busch <kbusch@kernel.org>,
	 Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-nvme@lists.infradead.org,
	Andres Freund <andres@anarazel.de>,
	 Pankaj Raghav <pankaj.raghav@linux.dev>,
	Daniel Gomez <da.gomez@kernel.org>,  GOST <gost.dev@samsung.com>,
	Daniel Gomez <da.gomez@samsung.com>
Subject: [PATCH RFC 2/2] nvme: enable multiple atomicity mode
Date: Tue, 29 Sep 2026 13:17:12 +0200	[thread overview]
Message-ID: <20260929-nvme-mam-v1-2-48dcbe79cece@samsung.com> (raw)
In-Reply-To: <20260929-nvme-mam-v1-0-48dcbe79cece@samsung.com>

From: Daniel Gomez <da.gomez@samsung.com>

Add support for Multiple Atomicity Mode (MAM), a superset of Single
Atomicity Mode (SAM) where the controller divides a write command that
crosses the atomic boundaries into per-window atomic writes. Honoring
the mode lets contiguous atomic writes merge past the atomic unit
limits.

Set BLK_FEAT_ATOMIC_WRITE_MULTI when the namespace reports MAM and its
atomic parameters are compliant; otherwise fall back to SAM. Re-derive
the flag on every rescan, and skip the single-write unit_max and
boundary checks because a merged atomic carrier can exceed both.

Assisted-by: LLM
Signed-off-by: Daniel Gomez <da.gomez@samsung.com>
---
 drivers/nvme/host/core.c | 23 +++++++++++++++++++++++
 include/linux/nvme.h     |  1 +
 2 files changed, 24 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 9bcab3dc4c118..69a565ac0da97 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -993,6 +993,9 @@ static bool nvme_valid_atomic_write(struct request *req)
 	struct request_queue *q = req->q;
 	u32 boundary_bytes = queue_atomic_write_boundary_bytes(q);
 
+	if (q->limits.features & BLK_FEAT_ATOMIC_WRITE_MULTI)
+		return true;
+
 	if (blk_rq_bytes(req) > queue_atomic_write_unit_max_bytes(q))
 		return false;
 
@@ -2038,12 +2041,24 @@ static void nvme_configure_metadata(struct nvme_ctrl *ctrl,
 	}
 }
 
+static bool nvme_mam_compliant(struct nvme_id_ns *id)
+{
+	if (id->nabspf != id->nawupf)
+		return false;
+	if (id->nabsn && id->nabsn != id->nabspf)
+		return false;
+	if (id->nawun && id->nawun != id->nawupf)
+		return false;
+	return true;
+}
 
 static u32 nvme_configure_atomic_write(struct nvme_ns *ns,
 		struct nvme_id_ns *id, struct queue_limits *lim, u32 bs)
 {
 	u32 atomic_bs, boundary = 0;
 
+	lim->features &= ~BLK_FEAT_ATOMIC_WRITE_MULTI;
+
 	/*
 	 * We do not support an offset for the atomic boundaries.
 	 */
@@ -2057,6 +2072,14 @@ static u32 nvme_configure_atomic_write(struct nvme_ns *ns,
 		atomic_bs = (1 + le16_to_cpu(id->nawupf)) * bs;
 		if (id->nabspf)
 			boundary = (le16_to_cpu(id->nabspf) + 1) * bs;
+
+		if (id->nsfeat & NVME_NS_FEAT_MAM) {
+			if (nvme_mam_compliant(id))
+				lim->features |= BLK_FEAT_ATOMIC_WRITE_MULTI;
+			else
+				dev_warn_once(ns->ctrl->device,
+					"Inconsistent MAM parameters, ignoring\n");
+		}
 	} else {
 		if (ns->ctrl->awupf)
 			dev_info_once(ns->ctrl->device,
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 91ce434a7e8d9..8fdc4b91cf906 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -602,6 +602,7 @@ enum {
 	NVME_NS_FEAT_OPTPERF_MASK = 0x1,
 	/* Since version 2.1, OPTPERF is bits 4 and 5 of NSFEAT */
 	NVME_NS_FEAT_OPTPERF_MASK_2_1 = 0x3,
+	NVME_NS_FEAT_MAM	= 1 << 6,
 	NVME_NS_ATTR_RO		= 1 << 0,
 	NVME_NS_FLBAS_LBA_MASK	= 0xf,
 	NVME_NS_FLBAS_LBA_UMASK	= 0x60,

-- 
2.55.0


      parent reply	other threads:[~2026-09-29 11:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-29 11:17 [PATCH RFC 0/2] Support for Multiple Atomicity Mode Daniel Gomez
2026-09-29 11:17 ` [PATCH RFC 1/2] block: add BLK_FEAT_ATOMIC_WRITE_MULTI Daniel Gomez
2026-09-29 11:17 ` Daniel Gomez [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260929-nvme-mam-v1-2-48dcbe79cece@samsung.com \
    --to=da.gomez@kernel.org \
    --cc=andres@anarazel.de \
    --cc=axboe@kernel.dk \
    --cc=da.gomez@samsung.com \
    --cc=gost.dev@samsung.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=pankaj.raghav@linux.dev \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox