From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 022CE204689 for ; Mon, 3 Feb 2025 15:45:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738597543; cv=none; b=aAkuzi5MYx4w4aLvBLMVApRRB6HPwUQbkCjo3U/YBOk1KFAPC4Ac1Sa1X5RtOHwviLK7NE4lM8y3MEwpK9OWjNm/sxUPYxYjPL7po2QGvB6in4vvNpocZwDzVArAWzlhn9IvbklMde9/rd+MQ4Yxvq7Q4eFJcntq0Ku5Kas3pgo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738597543; c=relaxed/simple; bh=UZwQu613tVNiidXf2pqDQqHnh35Leg2oX2D3CL9yOMg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=R5F30Z7k/g4vtdOvntcrl/yD4CewY+h5iE3wWQsozC1xtjLVsUZvyM16dAlGdAwpfHKKcy2ijLzW6vqke3HBSzAnk3P3zqROg0ZUa3+BPyKydTeQxJmYh8XKXCqwtYOfA8I9Z3SmmmLxWRg1RmOdlYVMYkXfcbCSQtTkEpknUuc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=G30sXIMA; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="G30sXIMA" Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 513Eh4pH020444 for ; Mon, 3 Feb 2025 07:45:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=s2048-2021-q4; bh=7ADqltAtWaV7JMAEEXiic/I4cGUqkxVKinmi63Va6/I=; b=G30sXIMAnl4F QQRSyFo6OOSe+7x7QYd9cGY/ao62KFZaU2S2zPSja6y0ta1R/RRSHqq/S4IFD1Ov u6AcQqclacvFf7Slw3mS7oq3zhhXVCHnEaY9KEhen5rHkn+MJ2YrEBzoViZw7Mx2 7LJQeqodIogeWtAKZwtrGUWoFl51VDJXOAMz1nF9tP8b26ZKuBqC8QHFq+MBeQS1 3h/kunFt6Pl5q4WrtA9G+KFuZwNxm5KFkjKDGBlhgwrEfSpnUHRPO6yXLO+qqEz+ s6FIaJl6IGYzMhLfEnIBRInS9XplJkk0Ue9lnCw55/6fp51NeVWfKFWsJZmi3N07 ZAn9/qYsNw== Received: from mail.thefacebook.com ([163.114.134.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 44juxphr4d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 03 Feb 2025 07:45:41 -0800 (PST) Received: from twshared18153.09.ash9.facebook.com (2620:10d:c085:208::7cb7) by mail.thefacebook.com (2620:10d:c08b:78::c78f) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1544.14; Mon, 3 Feb 2025 15:45:34 +0000 Received: by devbig638.nha1.facebook.com (Postfix, from userid 544533) id AF3E5179A9852; Mon, 3 Feb 2025 07:45:22 -0800 (PST) From: Keith Busch To: , , , , CC: Keith Busch Subject: [PATCH 5/6] io_uring: add abstraction for buf_table rsrc data Date: Mon, 3 Feb 2025 07:45:16 -0800 Message-ID: <20250203154517.937623-6-kbusch@meta.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20250203154517.937623-1-kbusch@meta.com> References: <20250203154517.937623-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: LkNHIN0r0eUIE_QOwdCybnL04MXm_EKX X-Proofpoint-GUID: LkNHIN0r0eUIE_QOwdCybnL04MXm_EKX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-03_06,2025-01-31_02,2024-11-22_01 From: Keith Busch We'll need to add more fields specific to the registered buffers, so make a layer for it now. No functional change in this patch. Signed-off-by: Keith Busch --- include/linux/io_uring_types.h | 6 +++- io_uring/fdinfo.c | 8 +++--- io_uring/net.c | 2 +- io_uring/nop.c | 2 +- io_uring/register.c | 2 +- io_uring/rsrc.c | 51 +++++++++++++++++----------------- io_uring/rw.c | 2 +- io_uring/uring_cmd.c | 2 +- 8 files changed, 39 insertions(+), 36 deletions(-) diff --git a/include/linux/io_uring_types.h b/include/linux/io_uring_type= s.h index 7e5a5a70c35f2..aa661ebfd6568 100644 --- a/include/linux/io_uring_types.h +++ b/include/linux/io_uring_types.h @@ -67,6 +67,10 @@ struct io_file_table { unsigned int alloc_hint; }; =20 +struct io_buf_table { + struct io_rsrc_data data; +}; + struct io_hash_bucket { struct hlist_head list; } ____cacheline_aligned_in_smp; @@ -290,7 +294,7 @@ struct io_ring_ctx { struct io_wq_work_list iopoll_list; =20 struct io_file_table file_table; - struct io_rsrc_data buf_table; + struct io_buf_table buf_table; =20 struct io_submit_state submit_state; =20 diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c index f60d0a9d505e2..d389c06cbce10 100644 --- a/io_uring/fdinfo.c +++ b/io_uring/fdinfo.c @@ -217,12 +217,12 @@ __cold void io_uring_show_fdinfo(struct seq_file *m= , struct file *file) seq_puts(m, "\n"); } } - seq_printf(m, "UserBufs:\t%u\n", ctx->buf_table.nr); - for (i =3D 0; has_lock && i < ctx->buf_table.nr; i++) { + seq_printf(m, "UserBufs:\t%u\n", ctx->buf_table.data.nr); + for (i =3D 0; has_lock && i < ctx->buf_table.data.nr; i++) { struct io_mapped_ubuf *buf =3D NULL; =20 - if (ctx->buf_table.nodes[i]) - buf =3D ctx->buf_table.nodes[i]->buf; + if (ctx->buf_table.data.nodes[i]) + buf =3D ctx->buf_table.data.nodes[i]->buf; if (buf) seq_printf(m, "%5u: 0x%llx/%u\n", i, buf->ubuf, buf->len); else diff --git a/io_uring/net.c b/io_uring/net.c index 4e9d0f04b902d..4917786456cf8 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -1348,7 +1348,7 @@ static int io_send_zc_import(struct io_kiocb *req, = unsigned int issue_flags) =20 ret =3D -EFAULT; io_ring_submit_lock(ctx, issue_flags); - node =3D io_rsrc_node_lookup(&ctx->buf_table, sr->buf_index); + node =3D io_rsrc_node_lookup(&ctx->buf_table.data, sr->buf_index); if (node) { io_req_assign_buf_node(sr->notif, node); ret =3D 0; diff --git a/io_uring/nop.c b/io_uring/nop.c index 5e5196df650a1..e3ebe5f019076 100644 --- a/io_uring/nop.c +++ b/io_uring/nop.c @@ -69,7 +69,7 @@ int io_nop(struct io_kiocb *req, unsigned int issue_fla= gs) =20 ret =3D -EFAULT; io_ring_submit_lock(ctx, issue_flags); - node =3D io_rsrc_node_lookup(&ctx->buf_table, nop->buffer); + node =3D io_rsrc_node_lookup(&ctx->buf_table.data, nop->buffer); if (node) { io_req_assign_buf_node(req, node); ret =3D 0; diff --git a/io_uring/register.c b/io_uring/register.c index 0db181437ae33..e8f00b19e75f6 100644 --- a/io_uring/register.c +++ b/io_uring/register.c @@ -919,7 +919,7 @@ SYSCALL_DEFINE4(io_uring_register, unsigned int, fd, = unsigned int, opcode, ret =3D __io_uring_register(ctx, opcode, arg, nr_args); =20 trace_io_uring_register(ctx, opcode, ctx->file_table.data.nr, - ctx->buf_table.nr, ret); + ctx->buf_table.data.nr, ret); mutex_unlock(&ctx->uring_lock); =20 fput(file); diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index 8c4c374abcc10..864c2eabf8efd 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -234,17 +234,17 @@ static int __io_sqe_buffers_update(struct io_ring_c= tx *ctx, __u32 done; int i, err; =20 - if (!ctx->buf_table.nr) + if (!ctx->buf_table.data.nr) return -ENXIO; - if (up->offset + nr_args > ctx->buf_table.nr) + if (up->offset + nr_args > ctx->buf_table.data.nr) return -EINVAL; =20 for (done =3D 0; done < nr_args; done++) { struct io_rsrc_node *node; u64 tag =3D 0; =20 - i =3D array_index_nospec(up->offset + done, ctx->buf_table.nr); - node =3D io_rsrc_node_lookup(&ctx->buf_table, i); + i =3D array_index_nospec(up->offset + done, ctx->buf_table.data.nr); + node =3D io_rsrc_node_lookup(&ctx->buf_table.data, i); if (node && node->type !=3D IORING_RSRC_BUFFER) { err =3D -EBUSY; break; @@ -276,8 +276,8 @@ static int __io_sqe_buffers_update(struct io_ring_ctx= *ctx, } node->tag =3D tag; } - io_reset_rsrc_node(ctx, &ctx->buf_table, i); - ctx->buf_table.nodes[i] =3D node; + io_reset_rsrc_node(ctx, &ctx->buf_table.data, i); + ctx->buf_table.data.nodes[i] =3D node; if (ctx->compat) user_data +=3D sizeof(struct compat_iovec); else @@ -556,9 +556,9 @@ int io_sqe_files_register(struct io_ring_ctx *ctx, vo= id __user *arg, =20 int io_sqe_buffers_unregister(struct io_ring_ctx *ctx) { - if (!ctx->buf_table.nr) + if (!ctx->buf_table.data.nr) return -ENXIO; - io_rsrc_data_free(ctx, &ctx->buf_table); + io_rsrc_data_free(ctx, &ctx->buf_table.data); return 0; } =20 @@ -585,8 +585,8 @@ static bool headpage_already_acct(struct io_ring_ctx = *ctx, struct page **pages, } =20 /* check previously registered pages */ - for (i =3D 0; i < ctx->buf_table.nr; i++) { - struct io_rsrc_node *node =3D ctx->buf_table.nodes[i]; + for (i =3D 0; i < ctx->buf_table.data.nr; i++) { + struct io_rsrc_node *node =3D ctx->buf_table.data.nodes[i]; struct io_mapped_ubuf *imu; =20 if (!node) @@ -812,7 +812,7 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, = void __user *arg, =20 BUILD_BUG_ON(IORING_MAX_REG_BUFFERS >=3D (1u << 16)); =20 - if (ctx->buf_table.nr) + if (ctx->buf_table.data.nr) return -EBUSY; if (!nr_args || nr_args > IORING_MAX_REG_BUFFERS) return -EINVAL; @@ -865,7 +865,7 @@ int io_sqe_buffers_register(struct io_ring_ctx *ctx, = void __user *arg, data.nodes[i] =3D node; } =20 - ctx->buf_table =3D data; + ctx->buf_table.data =3D data; if (ret) io_sqe_buffers_unregister(ctx); return ret; @@ -901,7 +901,7 @@ static struct io_rsrc_node *io_buffer_alloc_node(stru= ct io_ring_ctx *ctx, int io_buffer_register_bvec(struct io_ring_ctx *ctx, const struct reques= t *rq, unsigned int index) { - struct io_rsrc_data *data =3D &ctx->buf_table; + struct io_rsrc_data *data =3D &ctx->buf_table.data; u16 nr_bvecs =3D blk_rq_nr_phys_segments(rq); struct req_iterator rq_iter; struct io_rsrc_node *node; @@ -938,7 +938,7 @@ EXPORT_SYMBOL_GPL(io_buffer_register_bvec); =20 void io_buffer_unregister_bvec(struct io_ring_ctx *ctx, unsigned int ind= ex) { - struct io_rsrc_data *data =3D &ctx->buf_table; + struct io_rsrc_data *data =3D &ctx->buf_table.data; struct io_rsrc_node *node; =20 lockdep_assert_held(&ctx->uring_lock); @@ -1054,10 +1054,10 @@ static int io_clone_buffers(struct io_ring_ctx *c= tx, struct io_ring_ctx *src_ctx if (!arg->nr && (arg->dst_off || arg->src_off)) return -EINVAL; /* not allowed unless REPLACE is set */ - if (ctx->buf_table.nr && !(arg->flags & IORING_REGISTER_DST_REPLACE)) + if (ctx->buf_table.data.nr && !(arg->flags & IORING_REGISTER_DST_REPLAC= E)) return -EBUSY; =20 - nbufs =3D src_ctx->buf_table.nr; + nbufs =3D src_ctx->buf_table.data.nr; if (!arg->nr) arg->nr =3D nbufs; else if (arg->nr > nbufs) @@ -1067,13 +1067,13 @@ static int io_clone_buffers(struct io_ring_ctx *c= tx, struct io_ring_ctx *src_ctx if (check_add_overflow(arg->nr, arg->dst_off, &nbufs)) return -EOVERFLOW; =20 - ret =3D io_rsrc_data_alloc(&data, max(nbufs, ctx->buf_table.nr)); + ret =3D io_rsrc_data_alloc(&data, max(nbufs, ctx->buf_table.data.nr)); if (ret) return ret; =20 /* Fill entries in data from dst that won't overlap with src */ - for (i =3D 0; i < min(arg->dst_off, ctx->buf_table.nr); i++) { - struct io_rsrc_node *src_node =3D ctx->buf_table.nodes[i]; + for (i =3D 0; i < min(arg->dst_off, ctx->buf_table.data.nr); i++) { + struct io_rsrc_node *src_node =3D ctx->buf_table.data.nodes[i]; =20 if (src_node) { data.nodes[i] =3D src_node; @@ -1082,7 +1082,7 @@ static int io_clone_buffers(struct io_ring_ctx *ctx= , struct io_ring_ctx *src_ctx } =20 ret =3D -ENXIO; - nbufs =3D src_ctx->buf_table.nr; + nbufs =3D src_ctx->buf_table.data.nr; if (!nbufs) goto out_free; ret =3D -EINVAL; @@ -1102,7 +1102,7 @@ static int io_clone_buffers(struct io_ring_ctx *ctx= , struct io_ring_ctx *src_ctx while (nr--) { struct io_rsrc_node *dst_node, *src_node; =20 - src_node =3D io_rsrc_node_lookup(&src_ctx->buf_table, i); + src_node =3D io_rsrc_node_lookup(&src_ctx->buf_table.data, i); if (!src_node) { dst_node =3D NULL; } else { @@ -1124,7 +1124,7 @@ static int io_clone_buffers(struct io_ring_ctx *ctx= , struct io_ring_ctx *src_ctx * old and new nodes at this point. */ if (arg->flags & IORING_REGISTER_DST_REPLACE) - io_rsrc_data_free(ctx, &ctx->buf_table); + io_sqe_buffers_unregister(ctx); =20 /* * ctx->buf_table must be empty now - either the contents are being @@ -1132,10 +1132,9 @@ static int io_clone_buffers(struct io_ring_ctx *ct= x, struct io_ring_ctx *src_ctx * copied to a ring that does not have buffers yet (checked at function * entry). */ - WARN_ON_ONCE(ctx->buf_table.nr); - ctx->buf_table =3D data; + WARN_ON_ONCE(ctx->buf_table.data.nr); + ctx->buf_table.data =3D data; return 0; - out_free: io_rsrc_data_free(ctx, &data); return ret; @@ -1160,7 +1159,7 @@ int io_register_clone_buffers(struct io_ring_ctx *c= tx, void __user *arg) return -EFAULT; if (buf.flags & ~(IORING_REGISTER_SRC_REGISTERED|IORING_REGISTER_DST_RE= PLACE)) return -EINVAL; - if (!(buf.flags & IORING_REGISTER_DST_REPLACE) && ctx->buf_table.nr) + if (!(buf.flags & IORING_REGISTER_DST_REPLACE) && ctx->buf_table.data.n= r) return -EBUSY; if (memchr_inv(buf.pad, 0, sizeof(buf.pad))) return -EINVAL; diff --git a/io_uring/rw.c b/io_uring/rw.c index d6332d019dd56..f49ae3de94317 100644 --- a/io_uring/rw.c +++ b/io_uring/rw.c @@ -387,7 +387,7 @@ static int io_prep_rw_fixed(struct io_kiocb *req, con= st struct io_uring_sqe *sqe if (unlikely(ret)) return ret; =20 - node =3D io_rsrc_node_lookup(&ctx->buf_table, req->buf_index); + node =3D io_rsrc_node_lookup(&ctx->buf_table.data, req->buf_index); if (!node) return -EFAULT; io_req_assign_buf_node(req, node); diff --git a/io_uring/uring_cmd.c b/io_uring/uring_cmd.c index b7b9baf30d728..5c9f14d700373 100644 --- a/io_uring/uring_cmd.c +++ b/io_uring/uring_cmd.c @@ -213,7 +213,7 @@ int io_uring_cmd_prep(struct io_kiocb *req, const str= uct io_uring_sqe *sqe) struct io_rsrc_node *node; u16 index =3D READ_ONCE(sqe->buf_index); =20 - node =3D io_rsrc_node_lookup(&ctx->buf_table, index); + node =3D io_rsrc_node_lookup(&ctx->buf_table.data, index); if (unlikely(!node)) return -EFAULT; /* --=20 2.43.5