From patchwork Mon Oct 31 13:41:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 13025939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71D97FA3745 for ; Mon, 31 Oct 2022 13:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbiJaNl5 (ORCPT ); Mon, 31 Oct 2022 09:41:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231267AbiJaNl4 (ORCPT ); Mon, 31 Oct 2022 09:41:56 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B52EF101F8 for ; Mon, 31 Oct 2022 06:41:55 -0700 (PDT) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29VDFP6L005880 for ; Mon, 31 Oct 2022 06:41:55 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=5UAK8/r+oYf2G6j07qTXSAPgzd10hopmcm9ZNkR5gs8=; b=XgljDSJMesW1btodXNg+MMO7dCwfJjRJMfTcRCcfN0tnQrTEOoI2E6BHGgK+UkEBK0wp sKNNG6t62mD7DG9jvfqDsYEBxZynive/fEliiSlxXvB8VtQCi3KYVOYTF1vDCvznFxHs +f4PQkQIqNE9pGRYUhFZp7f5lswOA4gbI6oSCqSfz3wMB/c14iz/LeXgj4JDHD6sKSdD KY6SZMGfPANnDZws7jU7vgPqWplbKevp9ymPfTtnWUbfoDqP8/f8Tetv9Uu2O5JNqPRa PVFLWvx/ruwYvAxsfyAHI967ioIYs+XqBFHDvVkUy3YbtplNbxc4uUag7h+KCwCCYBA0 qw== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3kh1x1xcb1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 31 Oct 2022 06:41:54 -0700 Received: from twshared2001.03.ash8.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 31 Oct 2022 06:41:52 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id D8A3B8A1965A; Mon, 31 Oct 2022 06:41:35 -0700 (PDT) From: Dylan Yudaken To: Jens Axboe , Pavel Begunkov CC: , , Dylan Yudaken Subject: [PATCH for-next 08/12] io_uring: recv/recvmsg retarget_rsrc support Date: Mon, 31 Oct 2022 06:41:22 -0700 Message-ID: <20221031134126.82928-9-dylany@meta.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221031134126.82928-1-dylany@meta.com> References: <20221031134126.82928-1-dylany@meta.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: 7UN_yBR63euU9i9LNSM2PX7sV_lFVpZV X-Proofpoint-GUID: 7UN_yBR63euU9i9LNSM2PX7sV_lFVpZV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-31_15,2022-10-31_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Add can_retarget_rsrc handler for recv/recvmsg Signed-off-by: Dylan Yudaken --- io_uring/net.c | 22 +++++++++++++++++++++- io_uring/net.h | 1 + io_uring/opdef.c | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/io_uring/net.c b/io_uring/net.c index f4638e79a022..0fa05ef52dd3 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -70,6 +70,11 @@ struct io_send_zc_msg { struct io_kiocb *notif; }; +struct io_recv_msg { + struct io_sr_msg sr; + int retarget_fd; +}; + #define IO_APOLL_MULTI_POLLED (REQ_F_APOLL_MULTISHOT | REQ_F_POLLED) @@ -547,7 +552,8 @@ int io_recvmsg_prep_async(struct io_kiocb *req) int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) { - struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); + struct io_recv_msg *rcv = io_kiocb_to_cmd(req, struct io_recv_msg); + struct io_sr_msg *sr = &rcv->sr; if (unlikely(sqe->file_index || sqe->addr2)) return -EINVAL; @@ -572,6 +578,11 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) req->flags |= REQ_F_APOLL_MULTISHOT; } + if (req->flags & REQ_F_FIXED_FILE) + rcv->retarget_fd = req->cqe.fd; + else + rcv->retarget_fd = -1; + #ifdef CONFIG_COMPAT if (req->ctx->compat) sr->msg_flags |= MSG_CMSG_COMPAT; @@ -709,6 +720,15 @@ static int io_recvmsg_multishot(struct socket *sock, struct io_sr_msg *io, kmsg->controllen + err; } +bool io_recv_can_retarget_rsrc(struct io_kiocb *req) +{ + struct io_recv_msg *rcv = io_kiocb_to_cmd(req, struct io_recv_msg); + + if (rcv->retarget_fd < 0) + return false; + return io_file_peek_fixed(req, rcv->retarget_fd) == req->file; +} + int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) { struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); diff --git a/io_uring/net.h b/io_uring/net.h index 5ffa11bf5d2e..6b5719084494 100644 --- a/io_uring/net.h +++ b/io_uring/net.h @@ -43,6 +43,7 @@ int io_recvmsg_prep_async(struct io_kiocb *req); int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags); int io_recv(struct io_kiocb *req, unsigned int issue_flags); +bool io_recv_can_retarget_rsrc(struct io_kiocb *req); void io_sendrecv_fail(struct io_kiocb *req); diff --git a/io_uring/opdef.c b/io_uring/opdef.c index 83dc0f9ad3b2..1a0be5681c7b 100644 --- a/io_uring/opdef.c +++ b/io_uring/opdef.c @@ -178,6 +178,7 @@ const struct io_op_def io_op_defs[] = { .prep_async = io_recvmsg_prep_async, .cleanup = io_sendmsg_recvmsg_cleanup, .fail = io_sendrecv_fail, + .can_retarget_rsrc = io_recv_can_retarget_rsrc, #else .prep = io_eopnotsupp_prep, #endif @@ -340,6 +341,7 @@ const struct io_op_def io_op_defs[] = { .prep = io_recvmsg_prep, .issue = io_recv, .fail = io_sendrecv_fail, + .can_retarget_rsrc = io_recv_can_retarget_rsrc, #else .prep = io_eopnotsupp_prep, #endif