From: Gabriel Krisman Bertazi <krisman@suse.de>
To: axboe@kernel.dk
Cc: io-uring@vger.kernel.org,
Gabriel Krisman Bertazi <krisman@suse.de>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Vlastimil Babka <vbabka@suse.cz>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
linux-mm@kvack.org
Subject: [PATCH 1/2] io_uring: Support commands with optional file descriptors
Date: Thu, 29 Jan 2026 17:11:37 -0500 [thread overview]
Message-ID: <20260129221138.897715-2-krisman@suse.de> (raw)
In-Reply-To: <20260129221138.897715-1-krisman@suse.de>
mmap can be called either for file-backed memory or for anonymous memory
in which case no fd is provided. This patch allows an io_uring command
to request optional files for io_uring. If a fd is provided, io_uring
loads it in the regular paths. Otherwise, req->file stays NULL.
At the SQE level, Use the ancient mmap semantics of fd == -1 to indicate
no fd. This feels more useful than a flag or using 0. The later because
I'd expect 0 to be commonly used for direct FDs. We can abstract this
details in liburing. It is a bit ugly and it could be a flag elsewhere,
but we don't need to waste a flag on that.
Signed-off-by: Gabriel Krisman Bertazi <krisman@suse.de>
---
io_uring/io_uring.c | 15 ++++++++++-----
io_uring/opdef.h | 2 ++
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c
index 87a87396e940..158e9823a72a 100644
--- a/io_uring/io_uring.c
+++ b/io_uring/io_uring.c
@@ -1756,10 +1756,17 @@ static __cold void io_drain_req(struct io_kiocb *req)
ctx->drain_active = false;
}
+static inline bool op_wants_file(const struct io_issue_def *def,
+ struct io_kiocb *req)
+{
+ return (def->needs_file ||
+ (def->opt_file && req->cqe.fd != -1));
+}
+
static bool io_assign_file(struct io_kiocb *req, const struct io_issue_def *def,
unsigned int issue_flags)
{
- if (req->file || !def->needs_file)
+ if (req->file || !op_wants_file(def, req))
return true;
if (req->flags & REQ_F_FIXED_FILE)
@@ -2200,11 +2207,9 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
if (!def->iopoll && (ctx->flags & IORING_SETUP_IOPOLL))
return io_init_fail_req(req, -EINVAL);
- if (def->needs_file) {
+ req->cqe.fd = READ_ONCE(sqe->fd);
+ if (op_wants_file(def, req)) {
struct io_submit_state *state = &ctx->submit_state;
-
- req->cqe.fd = READ_ONCE(sqe->fd);
-
/*
* Plug now if we have more than 2 IO left after this, and the
* target is potentially a read/write to block based storage.
diff --git a/io_uring/opdef.h b/io_uring/opdef.h
index aa37846880ff..5b81f82c2359 100644
--- a/io_uring/opdef.h
+++ b/io_uring/opdef.h
@@ -5,6 +5,8 @@
struct io_issue_def {
/* needs req->file assigned */
unsigned needs_file : 1;
+ /* Optional req->file assigned, if available. */
+ unsigned opt_file : 1;
/* should block plug */
unsigned plug : 1;
/* supports ioprio */
--
2.52.0
next prev parent reply other threads:[~2026-01-29 22:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-29 22:11 [PATCH 0/2] Introduce IORING_OP_MMAP Gabriel Krisman Bertazi
2026-01-29 22:11 ` Gabriel Krisman Bertazi [this message]
2026-01-29 22:11 ` [PATCH 2/2] io_uring: introduce IORING_OP_MMAP Gabriel Krisman Bertazi
2026-01-30 6:03 ` kernel test robot
2026-01-30 15:47 ` Gabriel Krisman Bertazi
2026-01-30 15:55 ` Jens Axboe
2026-02-01 17:46 ` [PATCH 0/2] Introduce IORING_OP_MMAP David Hildenbrand (arm)
2026-02-01 18:16 ` Jens Axboe
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=20260129221138.897715-2-krisman@suse.de \
--to=krisman@suse.de \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=david@kernel.org \
--cc=io-uring@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
/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