mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suho Son <suho.son@samsung.com>
To: "axboe@kernel.dk" <axboe@kernel.dk>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>
Cc: "tj@kernel.org" <tj@kernel.org>,
	"hannes@cmpxchg.org" <hannes@cmpxchg.org>,
	"mkoutny@suse.com" <mkoutny@suse.com>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"skhan@linuxfoundation.org" <skhan@linuxfoundation.org>,
	"rdunlap@infradead.org" <rdunlap@infradead.org>,
	"viro@zeniv.linux.org.uk" <viro@zeniv.linux.org.uk>,
	"brauner@kernel.org" <brauner@kernel.org>,
	"jack@suse.cz" <jack@suse.cz>,
	"io-uring@vger.kernel.org" <io-uring@vger.kernel.org>,
	"cgroups@vger.kernel.org" <cgroups@vger.kernel.org>,
	"linux-fsdevel@vger.kernel.org" <linux-fsdevel@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"ngeol564@gmail.com" <ngeol564@gmail.com>,
	KiYoung Lee <kiyoung77.lee@samsung.com>,
	JinHeon Kim <jinheon09.kim@samsung.com>,
	Suho Son <suho.son@samsung.com>
Subject: [RFC PATCH RESEND 2/3] io_uring: add IORING_WRITE_STREAM_DEFAULT for explicit device-default placement
Date: Mon, 23 Nov 2026 14:17:19 +0900	[thread overview]
Message-ID: <20261123051719epcms2p2273654d46ba1890e9ebc86e5a28a434f@epcms2p2> (raw)
In-Reply-To: <20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p2>

From: Suho Son <suho.son@samsung.com>

Add a reserved sqe->write_stream value, IORING_WRITE_STREAM_DEFAULT
((__u8)-1), that explicitly requests the device-default stream for a
write.  Unlike an omitted (zero) stream, which lets the kernel derive
one from the inode write hint or, with the cgroup policy added later
in this series, a per-cgroup io.stream value, the reserved value pins
the write to the device default and suppresses both.

The value is translated once in __io_prep_rw() into a request flag
(REQ_F_STREAM_DEFAULT); io_rw_init_file() then converts it into a
concrete stream 0 plus IOCB_WRITE_STREAM_EXPLICIT.  Deciding at prep
time is required for re-issues, where ki_write_stream has already
been rewritten to zero, so the selection survives kiocb
reinitialization and IOSQE_ASYNC deferral.

The reservation is visible in the UAPI: 255 previously failed
validation with -EINVAL on any real device, so no working application
regresses, but a hypothetical device advertising more than 254
streams can no longer have its stream 255 selected through this
interface.

Signed-off-by: Suho Son <suho.son@samsung.com>
---
 include/linux/io_uring_types.h |  4 ++++
 include/uapi/linux/io_uring.h  | 26 ++++++++++++++++++++++++++
 io_uring/rw.c                  | 16 ++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_types.h
index 1468bcb028930..550928cd4ad95 100644
--- a/include/linux/io_uring_types.h
+++ b/include/linux/io_uring_types.h
@@ -622,6 +622,8 @@ enum {
 	REQ_F_SQE_COPIED_BIT,
 	REQ_F_IOPOLL_BIT,
 	REQ_F_DMABUF_BIT,
+	/* sqe->write_stream is IORING_WRITE_STREAM_DEFAULT */
+	REQ_F_STREAM_DEFAULT_BIT,
 
 	/* not a real bit, just to check we're not overflowing the space */
 	__REQ_F_LAST_BIT,
@@ -719,6 +721,8 @@ enum {
 	REQ_F_IOPOLL		= IO_REQ_FLAG(REQ_F_IOPOLL_BIT),
 	/* there is a dma map attached to request that needs to be dropped */
 	REQ_F_DMABUF		= IO_REQ_FLAG(REQ_F_DMABUF_BIT),
+	/* sqe->write_stream was IORING_WRITE_STREAM_DEFAULT (see io_rw_init_file()) */
+	REQ_F_STREAM_DEFAULT	= IO_REQ_FLAG(REQ_F_STREAM_DEFAULT_BIT),
 };
 
 struct io_tw_req {
diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h
index cf1afd11bb871..3ae504d9ec1a0 100644
--- a/include/uapi/linux/io_uring.h
+++ b/include/uapi/linux/io_uring.h
@@ -122,6 +122,32 @@ struct io_uring_sqe {
 /* sqe->attr_type_mask flags */
 #define IORING_RW_ATTR_FLAG_PI	(1U << 0)
 
+/*
+ * sqe->write_stream reserved value for explicitly requesting the
+ * device-default write stream.
+ *
+ * sqe->write_stream carries a per-I/O write stream identifier for write
+ * requests to block devices that support write streams (e.g. NVMe FDP):
+ *
+ *   0			the issuer does not express a stream; the kernel may
+ *			then derive one from the file's write lifetime hint
+ *			or, if configured, from the cgroup's io.stream
+ *			policy.
+ *   1..max		an explicit stream identifier, validated against the
+ *			device's max_write_streams.
+ *   255 (below)	an explicit request for the device-default stream.
+ *			This overrides both the inode write hint and any
+ *			cgroup io.stream value: the I/O is placed as if no
+ *			stream had been requested by anyone.
+ *
+ * Any other value above the device's max_write_streams is rejected with
+ * -EINVAL, as before. Note that a value of 255 can therefore no longer
+ * select stream 255 on a hypothetical device offering that many streams;
+ * the bio-level write stream field uses 255 as its "unset" sentinel, so
+ * stream identifiers are effectively limited to 1..254 through this
+ * interface.
+ */
+#define IORING_WRITE_STREAM_DEFAULT	((__u8)-1)
 /* PI attribute information in sqe->attr_ptr for IORING_RW_ATTR_FLAG_PI: */
 struct io_uring_attr_pi {
 	__u16	flags;
diff --git a/io_uring/rw.c b/io_uring/rw.c
index 3ecb842147a4d..d1d154533bf14 100644
--- a/io_uring/rw.c
+++ b/io_uring/rw.c
@@ -273,6 +273,8 @@ static int __io_prep_rw(struct io_kiocb *req, const struct io_uring_sqe *sqe,
 	}
 	rw->kiocb.ki_flags = 0;
 	rw->kiocb.ki_write_stream = READ_ONCE(sqe->write_stream);
+	if (rw->kiocb.ki_write_stream == IORING_WRITE_STREAM_DEFAULT)
+		io_req_set_flags(req, REQ_F_STREAM_DEFAULT);
 
 	if (req->ctx->flags & IORING_SETUP_IOPOLL)
 		rw->kiocb.ki_complete = io_complete_rw_iopoll;
@@ -851,6 +853,20 @@ static int io_rw_init_file(struct io_kiocb *req, fmode_t mode, int rw_type)
 	if (unlikely(ret))
 		return ret;
 
+	/*
+	 * IORING_WRITE_STREAM_DEFAULT is an explicit request for the
+	 * device-default stream: carry it as a concrete stream 0 plus a
+	 * marker, so neither the inode write hint nor a cgroup io.stream
+	 * value can override the issuer's choice. The request flag is set
+	 * once at prep time and survives the ki_flags reinitialization
+	 * above as well as async re-issues, where ki_write_stream has
+	 * already been rewritten to 0.
+	 */
+	if (req->flags & REQ_F_STREAM_DEFAULT) {
+		kiocb->ki_write_stream = 0;
+		kiocb->ki_flags |= IOCB_WRITE_STREAM_EXPLICIT;
+	}
+
 	/*
 	 * If the file is marked O_NONBLOCK, still allow retry for it if it
 	 * supports async. Otherwise it's impossible to use O_NONBLOCK files
-- 
2.43.0


      parent reply	other threads:[~2026-11-23  5:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p2>
2026-11-23  5:15 ` [RFC PATCH RESEND 0/3] block: cgroup-based and explicit write stream placement for NVMe FDP Suho Son
     [not found]   ` <CGME20261123051521epcms2p2445107f926f3acaa2d51c5e12abea90e@epcms2p7>
2026-11-23  5:16     ` [RFC PATCH RESEND 1/3] block: distinguish unspecified and explicit device-default write streams Suho Son
2026-11-23  5:27     ` [RFC PATCH RESEND 3/3] blk-cgroup: add cgroup-based write stream placement Suho Son
2026-11-23  5:17 ` Suho Son [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=20261123051719epcms2p2273654d46ba1890e9ebc86e5a28a434f@epcms2p2 \
    --to=suho.son@samsung.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=corbet@lwn.net \
    --cc=hannes@cmpxchg.org \
    --cc=io-uring@vger.kernel.org \
    --cc=jack@suse.cz \
    --cc=jinheon09.kim@samsung.com \
    --cc=kiyoung77.lee@samsung.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mkoutny@suse.com \
    --cc=ngeol564@gmail.com \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tj@kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®