From patchwork Tue Jul 26 12:14:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12929223 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 41B52C43334 for ; Tue, 26 Jul 2022 12:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233235AbiGZMPS (ORCPT ); Tue, 26 Jul 2022 08:15:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233224AbiGZMPR (ORCPT ); Tue, 26 Jul 2022 08:15:17 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFD1FAE70 for ; Tue, 26 Jul 2022 05:15:15 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26Q0rR8e010368 for ; Tue, 26 Jul 2022 05:15:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=fvuLvGOXfPpDawfY17s+47uVGXBsXbTXyOIpofQR6Tc=; b=PdgXfs48EWXKZUg78cReGEbgL3D+7i23C1FkGa9TH0IOWTPkvgTSR4EDrSOQfrJN31e7 oTiLkOmqD9siiFlZBsOlX25WkB9CLHDC51IHFyAHUrUOSVri+SLf3P/e+6+uWKhTRc64 sDRSoad7AHrFz9KDIytgQBTIfNlld84E5ck= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hhxbwny4s-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Jul 2022 05:15:15 -0700 Received: from twshared25107.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 26 Jul 2022 05:15:12 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 0C97B397A78C; Tue, 26 Jul 2022 05:15:08 -0700 (PDT) From: Dylan Yudaken To: , CC: , , Dylan Yudaken Subject: [PATCH liburing 1/5] more consistent multishot recvmsg API parameter names Date: Tue, 26 Jul 2022 05:14:58 -0700 Message-ID: <20220726121502.1958288-2-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220726121502.1958288-1-dylany@fb.com> References: <20220726121502.1958288-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: lTpCwPUyisxLPMV0ruqqj7_zy-z0MLWk X-Proofpoint-ORIG-GUID: lTpCwPUyisxLPMV0ruqqj7_zy-z0MLWk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_04,2022-07-26_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Make the parameters more consistent with for example cmsg(3), and with itself (in the form of buf_len). Signed-off-by: Dylan Yudaken --- src/include/liburing.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/include/liburing.h b/src/include/liburing.h index cffdabd71144..d3cbdb037b32 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -734,9 +734,9 @@ static inline void io_uring_prep_recv_multishot(struct io_uring_sqe *sqe, } static inline struct io_uring_recvmsg_out * -io_uring_recvmsg_validate(void *buf, int buf_len, struct msghdr *m) +io_uring_recvmsg_validate(void *buf, int buf_len, struct msghdr *msgh) { - int header = m->msg_controllen + m->msg_namelen + + int header = msgh->msg_controllen + msgh->msg_namelen + sizeof(struct io_uring_recvmsg_out); if (buf_len < header) @@ -751,42 +751,42 @@ static inline void *io_uring_recvmsg_name(struct io_uring_recvmsg_out *o) static inline struct cmsghdr * io_uring_recvmsg_cmsg_firsthdr(struct io_uring_recvmsg_out *o, - struct msghdr *m) + struct msghdr *msgh) { if (o->controllen < sizeof(struct cmsghdr)) return NULL; return (struct cmsghdr *)((unsigned char *) io_uring_recvmsg_name(o) + - m->msg_namelen); + msgh->msg_namelen); } static inline void *io_uring_recvmsg_payload(struct io_uring_recvmsg_out *o, - struct msghdr *m) + struct msghdr *msgh) { return (void *)((unsigned char *)io_uring_recvmsg_name(o) + - m->msg_namelen + m->msg_controllen); + msgh->msg_namelen + msgh->msg_controllen); } static inline size_t io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *o, - int buf_length, struct msghdr *m) + int buf_len, struct msghdr *msgh) { unsigned long payload_start, payload_end; - payload_start = (unsigned long) io_uring_recvmsg_payload(o, m); - payload_end = (unsigned long) o + buf_length; + payload_start = (unsigned long) io_uring_recvmsg_payload(o, msgh); + payload_end = (unsigned long) o + buf_len; return payload_end - payload_start; } static inline struct cmsghdr * -io_uring_recvmsg_cmsg_nexthdr(struct io_uring_recvmsg_out *o, struct msghdr *m, +io_uring_recvmsg_cmsg_nexthdr(struct io_uring_recvmsg_out *o, struct msghdr *msgh, struct cmsghdr *cmsg) { unsigned char *end; if (cmsg->cmsg_len < sizeof(struct cmsghdr)) return NULL; - end = (unsigned char *) io_uring_recvmsg_cmsg_firsthdr(o, m) + + end = (unsigned char *) io_uring_recvmsg_cmsg_firsthdr(o, msgh) + o->controllen; cmsg = (struct cmsghdr *)((unsigned char *) cmsg + CMSG_ALIGN(cmsg->cmsg_len)); From patchwork Tue Jul 26 12:14:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12929227 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 9B832C43334 for ; Tue, 26 Jul 2022 12:16:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233449AbiGZMQM (ORCPT ); Tue, 26 Jul 2022 08:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232573AbiGZMQM (ORCPT ); Tue, 26 Jul 2022 08:16:12 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78B1BAE5F for ; Tue, 26 Jul 2022 05:16:11 -0700 (PDT) Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26Q9hIfC031451 for ; Tue, 26 Jul 2022 05:16:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=QDCicKDcqOyhCxEsYTCiARD4bjpHFaEKweJNPtet+Rg=; b=EeNJskIXme9v9YjP8LptCngXl3QlV84QzIH5dgejjlwoki992Hkp/QOQFR6mie72/Jaz 7NYBJEYDSRnWWmk4Z1XqYtpzcq0kT93U6SUE3T8Wn/UE17NJsflXFdb88r5ndL7sAKV0 MBC6SM0N3XRTmahO8URKO9424uQWZ0Ihkd8= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hjdvtgng8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Jul 2022 05:16:11 -0700 Received: from twshared1866.09.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 26 Jul 2022 05:15:28 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 0F7CE397A78E; Tue, 26 Jul 2022 05:15:08 -0700 (PDT) From: Dylan Yudaken To: , CC: , , Dylan Yudaken Subject: [PATCH liburing 2/5] order like functions together in liburing.h Date: Tue, 26 Jul 2022 05:14:59 -0700 Message-ID: <20220726121502.1958288-3-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220726121502.1958288-1-dylany@fb.com> References: <20220726121502.1958288-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: dfpg8TNK4QT7WAqfuxNsAi__X7Cfm-2R X-Proofpoint-ORIG-GUID: dfpg8TNK4QT7WAqfuxNsAi__X7Cfm-2R X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_04,2022-07-26_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org the cmsg related functions were not together - which was confusing Signed-off-by: Dylan Yudaken --- src/include/liburing.h | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/include/liburing.h b/src/include/liburing.h index d3cbdb037b32..9e7f06f390be 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -760,24 +760,6 @@ io_uring_recvmsg_cmsg_firsthdr(struct io_uring_recvmsg_out *o, msgh->msg_namelen); } -static inline void *io_uring_recvmsg_payload(struct io_uring_recvmsg_out *o, - struct msghdr *msgh) -{ - return (void *)((unsigned char *)io_uring_recvmsg_name(o) + - msgh->msg_namelen + msgh->msg_controllen); -} - -static inline size_t -io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *o, - int buf_len, struct msghdr *msgh) -{ - unsigned long payload_start, payload_end; - - payload_start = (unsigned long) io_uring_recvmsg_payload(o, msgh); - payload_end = (unsigned long) o + buf_len; - return payload_end - payload_start; -} - static inline struct cmsghdr * io_uring_recvmsg_cmsg_nexthdr(struct io_uring_recvmsg_out *o, struct msghdr *msgh, struct cmsghdr *cmsg) @@ -799,6 +781,24 @@ io_uring_recvmsg_cmsg_nexthdr(struct io_uring_recvmsg_out *o, struct msghdr *msg return cmsg; } +static inline void *io_uring_recvmsg_payload(struct io_uring_recvmsg_out *o, + struct msghdr *msgh) +{ + return (void *)((unsigned char *)io_uring_recvmsg_name(o) + + msgh->msg_namelen + msgh->msg_controllen); +} + +static inline size_t +io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *o, + int buf_len, struct msghdr *msgh) +{ + unsigned long payload_start, payload_end; + + payload_start = (unsigned long) io_uring_recvmsg_payload(o, msgh); + payload_end = (unsigned long) o + buf_len; + return payload_end - payload_start; +} + static inline void io_uring_prep_openat2(struct io_uring_sqe *sqe, int dfd, const char *path, struct open_how *how) { From patchwork Tue Jul 26 12:15:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12929224 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 AB057C43334 for ; Tue, 26 Jul 2022 12:15:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238632AbiGZMP2 (ORCPT ); Tue, 26 Jul 2022 08:15:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233224AbiGZMP2 (ORCPT ); Tue, 26 Jul 2022 08:15:28 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E86D2AC53 for ; Tue, 26 Jul 2022 05:15:27 -0700 (PDT) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26Q0osRx003807 for ; Tue, 26 Jul 2022 05:15:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=IvHtzsYmeoD7dYs/XROGai/v/J8+kLFHqiY2yDVoe6A=; b=knpD8wyBBrS6ISboCRbQ33seCSxkQj+HsTyFISSD6HkAQLX2i8YziKa3ilAmvAZq4e0s mGgzmTYPA1d5HhJOIdllkXh8yUy+1bohE2HSXg3RCUYVwoO3rJTx5KJi30Q4jS9ayq40 Nrb+lj12vdLsceipF2P8IDiC/d5ZDC1dC4U= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hj1usm8y9-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Jul 2022 05:15:26 -0700 Received: from twshared33626.07.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 26 Jul 2022 05:15:24 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 175F1397A790; Tue, 26 Jul 2022 05:15:08 -0700 (PDT) From: Dylan Yudaken To: , CC: , , Dylan Yudaken Subject: [PATCH liburing 3/5] change io_uring_recvmsg_payload_length return type Date: Tue, 26 Jul 2022 05:15:00 -0700 Message-ID: <20220726121502.1958288-4-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220726121502.1958288-1-dylany@fb.com> References: <20220726121502.1958288-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: fAhIhW7pVBFrpz4txVGupiTj5RbvK6ul X-Proofpoint-ORIG-GUID: fAhIhW7pVBFrpz4txVGupiTj5RbvK6ul X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_04,2022-07-26_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Payloads can not be bigger than UINT_MAX, so no need to force a bigger type on the caller. Signed-off-by: Dylan Yudaken --- src/include/liburing.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/liburing.h b/src/include/liburing.h index 9e7f06f390be..06f4a50bacb1 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -788,7 +788,7 @@ static inline void *io_uring_recvmsg_payload(struct io_uring_recvmsg_out *o, msgh->msg_namelen + msgh->msg_controllen); } -static inline size_t +static inline unsigned int io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *o, int buf_len, struct msghdr *msgh) { @@ -796,7 +796,7 @@ io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *o, payload_start = (unsigned long) io_uring_recvmsg_payload(o, msgh); payload_end = (unsigned long) o + buf_len; - return payload_end - payload_start; + return (unsigned int) (payload_end - payload_start); } static inline void io_uring_prep_openat2(struct io_uring_sqe *sqe, int dfd, From patchwork Tue Jul 26 12:15:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12929225 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 8FDAFC43334 for ; Tue, 26 Jul 2022 12:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232784AbiGZMPf (ORCPT ); Tue, 26 Jul 2022 08:15:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238875AbiGZMPe (ORCPT ); Tue, 26 Jul 2022 08:15:34 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 429562E9F2 for ; Tue, 26 Jul 2022 05:15:31 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26Q0rSab010441 for ; Tue, 26 Jul 2022 05:15:31 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=821pu2G9kGNqXC97bqubOwgp5SaO+E5RJACeXsN0nqE=; b=E8Touh3rP4DWL6DGIJaIvnQmbrvSe04aK6C+QZPj8FdWLfU2Tl1rApRMQwFpX0fmbiv9 W4l5udUbNgUwdlimBACPwphFXXx3Go5mACw80FAChN+bW+XlP4FPr2wSrrAxMnsTpyEQ UndfuTMG13+5lDoMKLXWWa6skqle85TklIQ= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hhxbwny67-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Jul 2022 05:15:30 -0700 Received: from twshared1866.09.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 26 Jul 2022 05:15:28 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 249AE397A792; Tue, 26 Jul 2022 05:15:08 -0700 (PDT) From: Dylan Yudaken To: , CC: , , Dylan Yudaken Subject: [PATCH liburing 4/5] add documentation for multishot recvmsg Date: Tue, 26 Jul 2022 05:15:01 -0700 Message-ID: <20220726121502.1958288-5-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220726121502.1958288-1-dylany@fb.com> References: <20220726121502.1958288-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: a37C6OhJs51ZBoBJIBTWeozqxFoT2_c7 X-Proofpoint-ORIG-GUID: a37C6OhJs51ZBoBJIBTWeozqxFoT2_c7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_04,2022-07-26_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Add missing documentation for new multishot recvmsg API Signed-off-by: Dylan Yudaken --- man/io_uring_prep_recvmsg.3 | 30 +++++++++++ man/io_uring_prep_recvmsg_multishot.3 | 1 + man/io_uring_recvmsg_cmsg_firsthdr.3 | 1 + man/io_uring_recvmsg_cmsg_nexthdr.3 | 1 + man/io_uring_recvmsg_name.3 | 1 + man/io_uring_recvmsg_out.3 | 78 +++++++++++++++++++++++++++ man/io_uring_recvmsg_payload.3 | 1 + man/io_uring_recvmsg_payload_length.3 | 1 + man/io_uring_recvmsg_validate.3 | 1 + 9 files changed, 115 insertions(+) create mode 120000 man/io_uring_prep_recvmsg_multishot.3 create mode 120000 man/io_uring_recvmsg_cmsg_firsthdr.3 create mode 120000 man/io_uring_recvmsg_cmsg_nexthdr.3 create mode 120000 man/io_uring_recvmsg_name.3 create mode 100644 man/io_uring_recvmsg_out.3 create mode 120000 man/io_uring_recvmsg_payload.3 create mode 120000 man/io_uring_recvmsg_payload_length.3 create mode 120000 man/io_uring_recvmsg_validate.3 diff --git a/man/io_uring_prep_recvmsg.3 b/man/io_uring_prep_recvmsg.3 index f64326be0a99..07096ee4826c 100644 --- a/man/io_uring_prep_recvmsg.3 +++ b/man/io_uring_prep_recvmsg.3 @@ -15,6 +15,11 @@ io_uring_prep_recvmsg \- prepare a recvmsg request .BI " int " fd "," .BI " struct msghdr *" msg "," .BI " unsigned " flags ");" +.PP +.BI "void io_uring_prep_recvmsg_multishot(struct io_uring_sqe *" sqe "," +.BI " int " fd "," +.BI " struct msghdr *" msg "," +.BI " unsigned " flags ");" .fi .SH DESCRIPTION .PP @@ -37,6 +42,31 @@ This function prepares an async request. See that man page for details on the arguments specified to this prep helper. +The multishot version allows the application to issue a single receive request, +which repeatedly posts a CQE when data is available. It requires the +.B IOSQE_BUFFER_SELECT +flag to be set and no +.B MSG_WAITALL +flag to be set. +Therefore each CQE will take a buffer out of a provided buffer pool for receiving. +The application should check the flags of each CQE, regardless of it's result. +If a posted CQE does not have the +.B IORING_CQE_F_MORE +flag set then the multishot receive will be done and the application should issue a +new request. + +Unlike +.BR recvmsg (2) +, multishot recvmsg will prepend a +.I struct io_uring_recvmsg_out +which describes the layout of the rest of the buffer in combination with the initial +.I struct msghdr +submitted with the request. See +.B io_uring_recvmsg_out (3) +for more information on accessing the data. + +Multishot variants are available since kernel 5.20. + After calling this function, additional io_uring internal modifier flags may be set in the SQE .I ioprio diff --git a/man/io_uring_prep_recvmsg_multishot.3 b/man/io_uring_prep_recvmsg_multishot.3 new file mode 120000 index 000000000000..cd9566f2c2be --- /dev/null +++ b/man/io_uring_prep_recvmsg_multishot.3 @@ -0,0 +1 @@ +io_uring_prep_recvmsg.3 \ No newline at end of file diff --git a/man/io_uring_recvmsg_cmsg_firsthdr.3 b/man/io_uring_recvmsg_cmsg_firsthdr.3 new file mode 120000 index 000000000000..8eb17436288d --- /dev/null +++ b/man/io_uring_recvmsg_cmsg_firsthdr.3 @@ -0,0 +1 @@ +io_uring_recvmsg_out.3 \ No newline at end of file diff --git a/man/io_uring_recvmsg_cmsg_nexthdr.3 b/man/io_uring_recvmsg_cmsg_nexthdr.3 new file mode 120000 index 000000000000..8eb17436288d --- /dev/null +++ b/man/io_uring_recvmsg_cmsg_nexthdr.3 @@ -0,0 +1 @@ +io_uring_recvmsg_out.3 \ No newline at end of file diff --git a/man/io_uring_recvmsg_name.3 b/man/io_uring_recvmsg_name.3 new file mode 120000 index 000000000000..8eb17436288d --- /dev/null +++ b/man/io_uring_recvmsg_name.3 @@ -0,0 +1 @@ +io_uring_recvmsg_out.3 \ No newline at end of file diff --git a/man/io_uring_recvmsg_out.3 b/man/io_uring_recvmsg_out.3 new file mode 100644 index 000000000000..60f92619d566 --- /dev/null +++ b/man/io_uring_recvmsg_out.3 @@ -0,0 +1,78 @@ +.\" Copyright (C), 2022 Dylan Yudaken +.\" +.\" SPDX-License-Identifier: LGPL-2.0-or-later +.\" +.TH io_uring_recvmsg_out 3 "Julyu 26, 2022" "liburing-2.2" "liburing Manual" +.SH NAME +io_uring_recvmsg_out - access data from multishot recvmsg +.SH SYNOPSIS +.nf +.B #include +.PP +.BI "struct io_uring_recvmsg_out *io_uring_recvmsg_validate(void *" buf "," +.BI " int " buf_len "," +.BI " struct msghdr *" msgh ");" +.PP +.BI "void *io_uring_recvmsg_name(struct io_uring_recvmsg_out *" o ");" +.PP +.BI "struct cmsghdr *io_uring_recvmsg_cmsg_firsthdr(struct io_uring_recvmsg_out * " o "," +.BI " struct msghdr *" msgh ");" +.BI "struct cmsghdr *io_uring_recvmsg_cmsg_nexthdr(struct io_uring_recvmsg_out * " o "," +.BI " struct msghdr *" msgh "," +.BI " struct cmsghdr *" cmsg ");" +.PP +.BI "void *io_uring_recvmsg_payload(struct io_uring_recvmsg_out * " o "," +.BI " struct msghdr *" msgh ");" +.BI "unsigned int io_uring_recvmsg_payload_length(struct io_uring_recvmsg_out *" o "," +.BI " int " buf_len "," +.BI " struct msghdr *" msgh ");" +.PP +.fi + +.SH DESCRIPTION + +These functions are used to access data in the payload delivered by +.BR io_uring_prep_recv_multishot (3) +. +.PP +.BR io_uring_recvmsg_validate (3) +will validate a buffer delivered by +.BR io_uring_prep_recv_multishot (3) +and extract the +.I io_uring_recvmsg_out +if it is valid, returning a pointer to it or else NULL. +.PP +The structure is defined as follows: +.PP +.in +4n +.EX + +struct io_uring_recvmsg_out { + __u32 namelen; /* Name byte count as would have been populated + * by recvmsg(2) */ + __u32 controllen; /* Control byte count */ + __u32 payloadlen; /* Payload byte count as would have been returned + * by recvmsg(2) */ + __u32 flags; /* Flags result as would have been populated + * by recvmsg(2) */ +}; + +.IP * 3 +.BR io_uring_recvmsg_name (3) +returns a pointer to the name in the buffer. +.IP * +.BR io_uring_recvmsg_cmsg_firsthdr (3) +returns a pointer to the first cmsg in the buffer, or NULL. +.IP * +.BR io_uring_recvmsg_cmsg_nexthdr (3) +returns a pointer to the next cmsg in the buffer, or NULL. +.IP * +.BR io_uring_recvmsg_payload (3) +returns a pointer to the payload in the buffer. +.IP * +.BR io_uring_recvmsg_payload_length (3) +Calculates the usable payload length in bytes. + + +.SH "SEE ALSO" +.BR io_uring_prep_recv_multishot (3) diff --git a/man/io_uring_recvmsg_payload.3 b/man/io_uring_recvmsg_payload.3 new file mode 120000 index 000000000000..8eb17436288d --- /dev/null +++ b/man/io_uring_recvmsg_payload.3 @@ -0,0 +1 @@ +io_uring_recvmsg_out.3 \ No newline at end of file diff --git a/man/io_uring_recvmsg_payload_length.3 b/man/io_uring_recvmsg_payload_length.3 new file mode 120000 index 000000000000..8eb17436288d --- /dev/null +++ b/man/io_uring_recvmsg_payload_length.3 @@ -0,0 +1 @@ +io_uring_recvmsg_out.3 \ No newline at end of file diff --git a/man/io_uring_recvmsg_validate.3 b/man/io_uring_recvmsg_validate.3 new file mode 120000 index 000000000000..8eb17436288d --- /dev/null +++ b/man/io_uring_recvmsg_validate.3 @@ -0,0 +1 @@ +io_uring_recvmsg_out.3 \ No newline at end of file From patchwork Tue Jul 26 12:15:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dylan Yudaken X-Patchwork-Id: 12929226 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 A8347C433EF for ; Tue, 26 Jul 2022 12:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233224AbiGZMPg (ORCPT ); Tue, 26 Jul 2022 08:15:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232573AbiGZMPf (ORCPT ); Tue, 26 Jul 2022 08:15:35 -0400 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C7CB2ED79 for ; Tue, 26 Jul 2022 05:15:33 -0700 (PDT) Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26Q0rSae010441 for ; Tue, 26 Jul 2022 05:15:33 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=KWO59xWjmoMjIP0ziR38WUBHz1/YaIRPfNVrsyBGP5I=; b=NT6fOEvx65S4D2dHbepJwFZ9Tstg7qGlhazsY1XYC2NkeMinTahMjhaOo4vYGpb+jl13 /SK3PYil12n/rzAfEQkymoMjxenmz2Q7PSx16fwDpGhKaMrHQS1xKyfLnXS6lNYcnnOq wlH/e4SrYCHE6j7mcyrSzL2X7xm87uttqEg= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hhxbwny67-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Jul 2022 05:15:32 -0700 Received: from twshared1866.09.ash9.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 26 Jul 2022 05:15:28 -0700 Received: by devbig038.lla2.facebook.com (Postfix, from userid 572232) id 2AA78397A794; Tue, 26 Jul 2022 05:15:08 -0700 (PDT) From: Dylan Yudaken To: , CC: , , Dylan Yudaken Subject: [PATCH liburing 5/5] add an example for a UDP server Date: Tue, 26 Jul 2022 05:15:02 -0700 Message-ID: <20220726121502.1958288-6-dylany@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220726121502.1958288-1-dylany@fb.com> References: <20220726121502.1958288-1-dylany@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: 1O7wJvfi9Cxft5KXygYuVqZNLUamF3nq X-Proofpoint-ORIG-GUID: 1O7wJvfi9Cxft5KXygYuVqZNLUamF3nq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-26_04,2022-07-26_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Add an example showing off multishot recvmsg and provided buffer rings. The application is a UDP echo server that responds to all packets with the same packet. Signed-off-by: Dylan Yudaken --- .gitignore | 1 + examples/Makefile | 1 + examples/io_uring-udp.c | 388 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 390 insertions(+) create mode 100644 examples/io_uring-udp.c diff --git a/.gitignore b/.gitignore index b5acffd68c95..7853dbdf1a97 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ /examples/io_uring-cp /examples/io_uring-test +/examples/io_uring-udp /examples/link-cp /examples/ucontext-cp diff --git a/examples/Makefile b/examples/Makefile index 1997a31dcc08..e561e05c1785 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -13,6 +13,7 @@ endif example_srcs := \ io_uring-cp.c \ io_uring-test.c \ + io_uring-udp.c \ link-cp.c \ poll-bench.c \ send-zerocopy.c diff --git a/examples/io_uring-udp.c b/examples/io_uring-udp.c new file mode 100644 index 000000000000..77472df3d224 --- /dev/null +++ b/examples/io_uring-udp.c @@ -0,0 +1,388 @@ +/* SPDX-License-Identifier: MIT */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "liburing.h" + +#define QD 64 +#define BUF_SHIFT 12 /* 4k */ +#define CQES (QD * 16) +#define BUFFERS CQES +#define CONTROLLEN 0 + +struct sendmsg_ctx { + struct msghdr msg; + struct iovec iov; +}; + +struct ctx { + struct io_uring ring; + struct io_uring_buf_ring *buf_ring; + unsigned char *buffer_base; + struct msghdr msg; + int buf_shift; + int af; + bool verbose; + struct sendmsg_ctx send[BUFFERS]; + size_t buf_ring_size; +}; + +static size_t buffer_size(struct ctx *ctx) +{ + return 1U << ctx->buf_shift; +} + +static unsigned char *get_buffer(struct ctx *ctx, int idx) +{ + return ctx->buffer_base + (idx << ctx->buf_shift); +} + +static int setup_buffer_pool(struct ctx *ctx) +{ + int ret, i; + void *mapped; + struct io_uring_buf_reg reg = { .ring_addr = 0, + .ring_entries = BUFFERS, + .bgid = 0 }; + + ctx->buf_ring_size = (sizeof(struct io_uring_buf) + buffer_size(ctx)) * BUFFERS; + mapped = mmap(NULL, ctx->buf_ring_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, 0, 0); + if (mapped == MAP_FAILED) { + fprintf(stderr, "buf_ring mmap: %s\n", strerror(errno)); + return -1; + } + ctx->buf_ring = (struct io_uring_buf_ring *)mapped; + + io_uring_buf_ring_init(ctx->buf_ring); + + reg = (struct io_uring_buf_reg) { + .ring_addr = (unsigned long)ctx->buf_ring, + .ring_entries = BUFFERS, + .bgid = 0 + }; + ctx->buffer_base = (unsigned char *)ctx->buf_ring + + sizeof(struct io_uring_buf) * BUFFERS; + + ret = io_uring_register_buf_ring(&ctx->ring, ®, 0); + if (ret) { + fprintf(stderr, "buf_ring init: %s\n", strerror(-ret)); + return ret; + } + + for (i = 0; i < BUFFERS; i++) { + io_uring_buf_ring_add(ctx->buf_ring, get_buffer(ctx, i), buffer_size(ctx), i, + io_uring_buf_ring_mask(BUFFERS), i); + } + io_uring_buf_ring_advance(ctx->buf_ring, BUFFERS); + + return 0; +} + +static int setup_context(struct ctx *ctx) +{ + struct io_uring_params params; + int ret; + + memset(¶ms, 0, sizeof(params)); + params.cq_entries = QD * 8; + params.flags = IORING_SETUP_SUBMIT_ALL | IORING_SETUP_COOP_TASKRUN | + IORING_SETUP_CQSIZE; + + ret = io_uring_queue_init_params(QD, &ctx->ring, ¶ms); + if (ret < 0) { + fprintf(stderr, "queue_init: %s\n", strerror(-ret)); + return ret; + } + + ret = setup_buffer_pool(ctx); + if (ret) + io_uring_queue_exit(&ctx->ring); + + memset(&ctx->msg, 0, sizeof(ctx->msg)); + ctx->msg.msg_namelen = sizeof(struct sockaddr_storage); + ctx->msg.msg_controllen = CONTROLLEN; + return ret; +} + +static int setup_sock(int af, int port) +{ + int ret; + int fd; + uint16_t nport = port <= 0 ? 0 : htons(port); + + fd = socket(af, SOCK_DGRAM, 0); + if (fd < 0) { + fprintf(stderr, "sock_init: %s\n", strerror(errno)); + return -1; + } + + if (af == AF_INET6) { + struct sockaddr_in6 addr6 = { + .sin6_family = af, + .sin6_port = nport, + .sin6_addr = IN6ADDR_ANY_INIT + }; + + ret = bind(fd, &addr6, sizeof(addr6)); + } else { + struct sockaddr_in addr = { + .sin_family = af, + .sin_port = nport, + .sin_addr = { INADDR_ANY } + }; + + ret = bind(fd, &addr, sizeof(addr)); + } + + if (ret) { + fprintf(stderr, "sock_bind: %s\n", strerror(errno)); + close(fd); + return -1; + } + + if (port <= 0) { + int port; + struct sockaddr_storage s; + socklen_t sz = sizeof(s); + + if (getsockname(fd, (struct sockaddr *)&s, &sz)) { + fprintf(stderr, "getsockname failed\n"); + close(fd); + return -1; + } + + port = ntohs(((struct sockaddr_in *)&s)->sin_port); + fprintf(stderr, "port bound to %d\n", port); + } + + return fd; +} + +static void cleanup_context(struct ctx *ctx) +{ + munmap(ctx->buf_ring, ctx->buf_ring_size); + io_uring_queue_exit(&ctx->ring); +} + +static bool get_sqe(struct ctx *ctx, struct io_uring_sqe **sqe) +{ + *sqe = io_uring_get_sqe(&ctx->ring); + + if (!*sqe) { + io_uring_submit(&ctx->ring); + *sqe = io_uring_get_sqe(&ctx->ring); + } + if (!*sqe) { + fprintf(stderr, "cannot get sqe\n"); + return true; + } + return false; +} + +static int add_recv(struct ctx *ctx, int idx) +{ + struct io_uring_sqe *sqe; + + if (get_sqe(ctx, &sqe)) + return -1; + + io_uring_prep_recvmsg_multishot(sqe, idx, &ctx->msg, MSG_TRUNC); + sqe->flags |= IOSQE_FIXED_FILE; + + sqe->flags |= IOSQE_BUFFER_SELECT; + sqe->buf_group = 0; + io_uring_sqe_set_data64(sqe, BUFFERS + 1); + return 0; +} + +static void recycle_buffer(struct ctx *ctx, int idx) +{ + io_uring_buf_ring_add(ctx->buf_ring, get_buffer(ctx, idx), buffer_size(ctx), idx, + io_uring_buf_ring_mask(BUFFERS), 0); + io_uring_buf_ring_advance(ctx->buf_ring, 1); +} + +static int process_cqe_send(struct ctx *ctx, struct io_uring_cqe *cqe) +{ + int idx = cqe->user_data; + + if (cqe->res < 0) + fprintf(stderr, "bad send %s\n", strerror(-cqe->res)); + recycle_buffer(ctx, idx); + return 0; +} + +static int process_cqe_recv(struct ctx *ctx, struct io_uring_cqe *cqe, + int fdidx) +{ + int ret, idx; + struct io_uring_recvmsg_out *o; + struct io_uring_sqe *sqe; + + if (!(cqe->flags & IORING_CQE_F_MORE)) { + ret = add_recv(ctx, fdidx); + if (ret) + return ret; + } + + if (cqe->res == -ENOBUFS) + return 0; + + if (!(cqe->flags & IORING_CQE_F_BUFFER) || cqe->res < 0) { + fprintf(stderr, "bad res %d\n", cqe->res); + return -1; + } + idx = cqe->flags >> 16; + + o = io_uring_recvmsg_validate(get_buffer(ctx, cqe->flags >> 16), + cqe->res, &ctx->msg); + if (!o) { + fprintf(stderr, "bad recvmsg\n"); + return -1; + } + if (o->namelen > ctx->msg.msg_namelen) { + fprintf(stderr, "truncated name\n"); + recycle_buffer(ctx, idx); + return 0; + } + if (o->flags & MSG_TRUNC) { + unsigned int r; + + r = io_uring_recvmsg_payload_length(o, cqe->res, &ctx->msg); + fprintf(stderr, "truncated msg need %u received %u\n", + o->payloadlen, r); + recycle_buffer(ctx, idx); + return 0; + } + + if (ctx->verbose) { + char buff[INET6_ADDRSTRLEN + 1]; + const char *name; + struct sockaddr_in *addr = io_uring_recvmsg_name(o); + + name = inet_ntop(ctx->af, addr, buff, sizeof(buff)); + if (!name) + name = ""; + fprintf(stderr, "received %u bytes %d from %s:%d\n", + io_uring_recvmsg_payload_length(o, cqe->res, &ctx->msg), + o->namelen, name, (int)ntohs(addr->sin_port)); + } + + if (get_sqe(ctx, &sqe)) + return -1; + + ctx->send[idx].iov = (struct iovec) { + .iov_base = io_uring_recvmsg_payload(o, &ctx->msg), + .iov_len = + io_uring_recvmsg_payload_length(o, cqe->res, &ctx->msg) + }; + ctx->send[idx].msg = (struct msghdr) { + .msg_namelen = o->namelen, + .msg_name = io_uring_recvmsg_name(o), + .msg_control = NULL, + .msg_controllen = 0, + .msg_iov = &ctx->send[idx].iov, + .msg_iovlen = 1 + }; + + io_uring_prep_sendmsg(sqe, fdidx, &ctx->send[idx].msg, 0); + io_uring_sqe_set_data64(sqe, idx); + sqe->flags |= IOSQE_FIXED_FILE; + + return 0; +} +static int process_cqe(struct ctx *ctx, struct io_uring_cqe *cqe, int fdidx) +{ + if (cqe->user_data < BUFFERS) + return process_cqe_send(ctx, cqe); + else + return process_cqe_recv(ctx, cqe, fdidx); +} + +int main(int argc, char *argv[]) +{ + struct ctx ctx; + int ret; + int port = -1; + int sockfd; + int opt; + struct io_uring_cqe *cqes[CQES]; + unsigned int count, i; + + memset(&ctx, 0, sizeof(ctx)); + ctx.verbose = false; + ctx.af = AF_INET; + ctx.buf_shift = BUF_SHIFT; + + while ((opt = getopt(argc, argv, "6vp:b:")) != -1) { + switch (opt) { + case '6': + ctx.af = AF_INET6; + break; + case 'p': + port = atoi(optarg); + break; + case 'b': + ctx.buf_shift = atoi(optarg); + break; + case 'v': + ctx.verbose = true; + break; + default: + fprintf(stderr, "Usage: %s [-p port] " + "[-b log2(BufferSize)] [-6] [-v]\n", + argv[0]); + exit(-1); + } + } + + sockfd = setup_sock(ctx.af, port); + if (sockfd < 0) + return 1; + + if (setup_context(&ctx)) { + close(sockfd); + return 1; + } + + ret = io_uring_register_files(&ctx.ring, &sockfd, 1); + if (ret) { + fprintf(stderr, "register files: %s\n", strerror(-ret)); + return -1; + } + + ret = add_recv(&ctx, 0); + if (ret) + return 1; + + while (true) { + ret = io_uring_submit_and_wait(&ctx.ring, 1); + if (ret == -EINTR) + continue; + if (ret < 0) { + fprintf(stderr, "submit and wait failed %d\n", ret); + break; + } + + count = io_uring_peek_batch_cqe(&ctx.ring, &cqes[0], CQES); + for (i = 0; i < count; i++) { + ret = process_cqe(&ctx, cqes[i], 0); + if (ret) + goto cleanup; + } + io_uring_cq_advance(&ctx.ring, count); + } + +cleanup: + cleanup_context(&ctx); + close(sockfd); + return ret; +}