From patchwork Fri Oct 20 13:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13430749 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 665D0C0032E for ; Fri, 20 Oct 2023 13:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377372AbjJTNjd (ORCPT ); Fri, 20 Oct 2023 09:39:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377074AbjJTNjc (ORCPT ); Fri, 20 Oct 2023 09:39:32 -0400 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B93F11A8 for ; Fri, 20 Oct 2023 06:39:30 -0700 (PDT) Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-9b95622c620so130188366b.0 for ; Fri, 20 Oct 2023 06:39:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697809169; x=1698413969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1EjyJ4uhP/CxBADjUG+qEfppqNSusPrKMcrU9qiJ+8I=; b=Acde6q/VFlEF3TC5vWgl+nIvLKfRExTYr763RmdqCH8E8KxjG+gK4HzFsxacaM1qt1 Q046bYUq95/Z0BFnAFqfo4/0lJXgqKK6InZa7LX3DSLhbof60Bq6J0w1t5MrSk8oM36R DJIXJ8We05Uec0VvwvsXmk3GMieVjeBnPVwFDNZEbqlDBJfLdr/NWsjIs1Y9AaR/IiIH V/qirLC8H6ymCJpILLVisKOOc2bRjRZiZgJMeYGHKMNzQmMdLMJ15NKFVxSkpqW6cWgD VcupR+C8GTJ4zNuNMQaKxg5SIwQGTrrtfoJvYSQqW3Q2xqRaRL5EhwX69KfeuR8nZTeL UKfg== X-Gm-Message-State: AOJu0YzZCDFEvPyFxjb+hZbzk8+4c1QLwWsHU717grOW3GwObBxlMoQN j5spFTr4rAs93kUmOUdVW/AzT65Yhp3tQA== X-Google-Smtp-Source: AGHT+IHsT3EZ9LFHtBBrOM6VyzzTRUCQZKJBcELJ+7FDE58c1Ips5sghV7tFhKl2Vc7p+mwVWwaiAg== X-Received: by 2002:a17:907:9306:b0:9b9:4509:d575 with SMTP id bu6-20020a170907930600b009b94509d575mr1653882ejc.2.1697809168775; Fri, 20 Oct 2023 06:39:28 -0700 (PDT) Received: from localhost (fwdproxy-cln-004.fbsv.net. [2a03:2880:31ff:4::face:b00c]) by smtp.gmail.com with ESMTPSA id ca9-20020a170906a3c900b009b8a4f9f20esm1512582ejb.102.2023.10.20.06.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:39:28 -0700 (PDT) From: Breno Leitao To: asml.silence@gmail.com, axboe@kernel.dk Cc: io-uring@vger.kernel.org Subject: [PATCH 1/5] io_uring: uapi: Sync the {g,s}etsockopt fields Date: Fri, 20 Oct 2023 06:39:13 -0700 Message-Id: <20231020133917.953642-2-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020133917.953642-1-leitao@debian.org> References: <20231020133917.953642-1-leitao@debian.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Copy the UAPI fields necessary to support the new SOCKET_URING_OP_GETSOCKOPT and SOCKET_URING_OP_SETSOCKOPT socket commands. Sync the necessary bits for io_uring_sqe struct from the kernel, and also adds the SOCKET_URING_OP_GETSOCKOPT and SOCKET_URING_OP_SETSOCKOPT to the enum that defines the commands. Signed-off-by: Breno Leitao --- src/include/liburing/io_uring.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/include/liburing/io_uring.h b/src/include/liburing/io_uring.h index 10a6ef0..a7a95a3 100644 --- a/src/include/liburing/io_uring.h +++ b/src/include/liburing/io_uring.h @@ -43,6 +43,10 @@ struct io_uring_sqe { union { __u64 addr; /* pointer to buffer or iovecs */ __u64 splice_off_in; + struct { + __u32 level; + __u32 optname; + }; }; __u32 len; /* buffer size or number of iovecs */ union { @@ -79,6 +83,7 @@ struct io_uring_sqe { union { __s32 splice_fd_in; __u32 file_index; + __u32 optlen; struct { __u16 addr_len; __u16 __pad3[1]; @@ -89,6 +94,7 @@ struct io_uring_sqe { __u64 addr3; __u64 __pad2[1]; }; + __u64 optval; /* * If the ring is initialized with IORING_SETUP_SQE128, then * this field is used for 80 bytes of arbitrary command data @@ -721,6 +727,8 @@ struct io_uring_recvmsg_out { enum { SOCKET_URING_OP_SIOCINQ = 0, SOCKET_URING_OP_SIOCOUTQ, + SOCKET_URING_OP_GETSOCKOPT, + SOCKET_URING_OP_SETSOCKOPT, }; #ifdef __cplusplus From patchwork Fri Oct 20 13:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13430750 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 13B09C001DF for ; Fri, 20 Oct 2023 13:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377360AbjJTNje (ORCPT ); Fri, 20 Oct 2023 09:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377074AbjJTNje (ORCPT ); Fri, 20 Oct 2023 09:39:34 -0400 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2509DD4C for ; Fri, 20 Oct 2023 06:39:32 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso129873766b.2 for ; Fri, 20 Oct 2023 06:39:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697809170; x=1698413970; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dPvWh+kMxMBw+crBdqTX68BCRqpRuCu5+S8tdbJ+E7k=; b=D5JfTCa9hAnkyn2fq5wiJowtypyfDLVsIpcBi1QkRWMz5AgSkZcvYmWymGSP28+yGd 2h1jGLdTf7HWyUST/dypXC3igxaVKWKQkHcuoKRG2Vcd1Kqzd0oeAM/BclqE/fXpGfA4 fxOql/FiqC7kQeprhLjvYP1wr5EspfBPU2FEHtpuF/VoI/UxVbEa+V/qLYx4OCC1gPrA eyI0vGcTiVBEGabdFpvg4nBz9L8pot9s7PqNpxTjpQI+fikhhJ3V9HP+dbog+yI2AIe+ /vItC0BH8nbOk0EKpjhaZOw0tv2CWZ5vWnQ44H72HuSxO7hEFmYce1vNL2/b8b7KsbJZ E6rw== X-Gm-Message-State: AOJu0Yyvxu4+p/N3lopDDoMKXZMnnoRzEhMfEv7OnFTL5foi6kCgEeGm 9QYnIkti9g36W77sDiupglQ= X-Google-Smtp-Source: AGHT+IHoEegdAPZwCSmjvl8uMk4AnbxESzhe35wzC+mgr6chX67iONUumG/LtGIM1Y+DTTK9YOBVdQ== X-Received: by 2002:a17:907:3fa2:b0:9ae:56da:6068 with SMTP id hr34-20020a1709073fa200b009ae56da6068mr1349387ejc.57.1697809170045; Fri, 20 Oct 2023 06:39:30 -0700 (PDT) Received: from localhost (fwdproxy-cln-011.fbsv.net. [2a03:2880:31ff:b::face:b00c]) by smtp.gmail.com with ESMTPSA id 29-20020a170906001d00b009875a6d28b0sm1512427eja.51.2023.10.20.06.39.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:39:29 -0700 (PDT) From: Breno Leitao To: asml.silence@gmail.com, axboe@kernel.dk Cc: io-uring@vger.kernel.org Subject: [PATCH 2/5] liburing.h: Populate SQE for {s,g} etsockopt Date: Fri, 20 Oct 2023 06:39:14 -0700 Message-Id: <20231020133917.953642-3-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020133917.953642-1-leitao@debian.org> References: <20231020133917.953642-1-leitao@debian.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org The current io_uring_prep_cmd_sock() liburing function is not populating the SQE will all the fields because the kernel implementation was not ready. With the integration of the kernel part[1], populate the SQE with the missing fields (optlen, optval, level and optname). This enables the usage of this function to prepare commands that executes setsockopt and getsockopt operations. [1] Link: https://lore.kernel.org/all/20231016134750.1381153-1-leitao@debian.org/ Signed-off-by: Breno Leitao --- CHANGELOG | 4 ++++ src/include/liburing.h | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 42a7fc1..61199e2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +liburing-2.5 release + +- Add getsockopt and setsockopt socket commands + liburing-2.4 release - Add io_uring_{major,minor,check}_version() functions. diff --git a/src/include/liburing.h b/src/include/liburing.h index 1008544..84400ea 100644 --- a/src/include/liburing.h +++ b/src/include/liburing.h @@ -1129,8 +1129,6 @@ IOURINGINLINE void io_uring_prep_socket_direct_alloc(struct io_uring_sqe *sqe, } -#define UNUSED(x) (void)(x) - /* * Prepare commands for sockets */ @@ -1142,13 +1140,12 @@ IOURINGINLINE void io_uring_prep_cmd_sock(struct io_uring_sqe *sqe, void *optval, int optlen) { - /* This will be removed once the get/setsockopt() patches land */ - UNUSED(optlen); - UNUSED(optval); - UNUSED(level); - UNUSED(optname); io_uring_prep_rw(IORING_OP_URING_CMD, sqe, fd, NULL, 0, 0); + sqe->optval = (long long unsigned int)optval; + sqe->optname = optname; + sqe->optlen = optlen; sqe->cmd_op = cmd_op; + sqe->level = level; } /* From patchwork Fri Oct 20 13:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13430752 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 1BE69C0032E for ; Fri, 20 Oct 2023 13:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377364AbjJTNjg (ORCPT ); Fri, 20 Oct 2023 09:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377074AbjJTNjg (ORCPT ); Fri, 20 Oct 2023 09:39:36 -0400 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 58F911A4 for ; Fri, 20 Oct 2023 06:39:33 -0700 (PDT) Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-9be02fcf268so126647266b.3 for ; Fri, 20 Oct 2023 06:39:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697809171; x=1698413971; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5aquoTQ7zTsA88/VEGHqLqBNmNNuVaBEFNaSIKTEsgw=; b=SdbZmcFAYdWuueT4uewqghwceYfHLy2xPbUoOSeban88qxulQF+jDBl6XUllSwNBLP WLQ97GBcDg4nLMJh6RbLFVLkUEVHhm7Hsihs1tvz7PnLnThrwzUqWY29L1IwFTciYT2m HkTFLLI6dQ3G4Ba0EoRFp+Vs7AbhMVhn20HUHubpBd8uorvlI7c2z//giTOZL8pnNu5P OWJeTHqkVwkmrctHNEUqyWeJieAnn+anB0iWvV0Z6b390SvWcQT51gKdMrYASHfdNiD7 2RwTgfJe/Oj5IB1kEpi54XLFO1oo5FL4P/R6UNhYRBTAMdUIMZyXyOO++EZyBk05s5R+ 19mw== X-Gm-Message-State: AOJu0YzpMQCksi/CCHMhOGvoLhrg8sEWbaa1Em7tpvgVlKc1sOvc5adW uaa4BO1Rl3DAMZ5EODLSTkE= X-Google-Smtp-Source: AGHT+IHD6Ij6BJ46lDs/HCJHYXWpU8riKZAzhLt5FRf/o0oK4MXASVL+fqfGjU7IUHl0Ac4NrXUjHA== X-Received: by 2002:a17:907:94c3:b0:9c3:bd63:4245 with SMTP id dn3-20020a17090794c300b009c3bd634245mr1288464ejc.47.1697809171201; Fri, 20 Oct 2023 06:39:31 -0700 (PDT) Received: from localhost (fwdproxy-cln-016.fbsv.net. [2a03:2880:31ff:10::face:b00c]) by smtp.gmail.com with ESMTPSA id p20-20020a170906a01400b009b655c43710sm1531946ejy.24.2023.10.20.06.39.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:39:30 -0700 (PDT) From: Breno Leitao To: asml.silence@gmail.com, axboe@kernel.dk Cc: io-uring@vger.kernel.org Subject: [PATCH 3/5] tests/socket-getsetsock-cmd: New test for {g,s}etsockopt Date: Fri, 20 Oct 2023 06:39:15 -0700 Message-Id: <20231020133917.953642-4-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020133917.953642-1-leitao@debian.org> References: <20231020133917.953642-1-leitao@debian.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Introduce a new test to exercise the io_uring getsockopt and setsockopt commands. On the liburing side, use the io_uring_prep_cmd_sock() function to prepare the SQE. The test executes the same operation using a regular systemcall, such as getsockopt(2), and the io_uring getsockopt command and compare the results. The same for the setsockopt counterpart. Signed-off-by: Breno Leitao --- test/Makefile | 1 + test/socket-getsetsock-cmd.c | 328 +++++++++++++++++++++++++++++++++++ 2 files changed, 329 insertions(+) create mode 100644 test/socket-getsetsock-cmd.c diff --git a/test/Makefile b/test/Makefile index c15b2a3..6b25e58 100644 --- a/test/Makefile +++ b/test/Makefile @@ -167,6 +167,7 @@ test_srcs := \ skip-cqe.c \ socket.c \ socket-io-cmd.c \ + socket-getsetsock-cmd.c \ socket-rw.c \ socket-rw-eagain.c \ socket-rw-offset.c \ diff --git a/test/socket-getsetsock-cmd.c b/test/socket-getsetsock-cmd.c new file mode 100644 index 0000000..5b6aa48 --- /dev/null +++ b/test/socket-getsetsock-cmd.c @@ -0,0 +1,328 @@ +/* SPDX-License-Identifier: MIT */ +/* + * Description: Check that {g,s}etsockopt CMD operations on sockets are + * consistent. + * + * The tests basically do the same socket operation using regular system calls + * and io_uring commands, and then compare the results. + */ + +#include +#include +#include +#include +#include + +#include "liburing.h" +#include "helpers.h" + +#define USERDATA 0xff42ff +#define MSG "foobarbaz" + +struct fds { + int tx; + int rx; +}; + +static struct fds create_sockets(void) +{ + struct fds retval; + int fd[2]; + + t_create_socket_pair(fd, true); + + retval.tx = fd[0]; + retval.rx = fd[1]; + + return retval; +} + +static struct io_uring create_ring(void) +{ + struct io_uring ring; + int ring_flags = 0; + int err; + + err = io_uring_queue_init(32, &ring, ring_flags); + assert(err == 0); + + return ring; +} + +static int submit_cmd_sqe(struct io_uring *ring, int32_t fd, + int op, int level, int optname, + void *optval, int optlen) +{ + struct io_uring_sqe *sqe; + int err; + + assert(fd > 0); + + sqe = io_uring_get_sqe(ring); + assert(sqe != NULL); + + io_uring_prep_cmd_sock(sqe, op, fd, level, optname, optval, optlen); + sqe->user_data = USERDATA; + + /* Submitting SQE */ + err = io_uring_submit_and_wait(ring, 1); + if (err != 1) + fprintf(stderr, "Failure: io_uring_submit_and_wait returned %d\n", err); + + return err; +} + +static int receive_cqe(struct io_uring *ring) +{ + struct io_uring_cqe *cqe; + int err; + + err = io_uring_wait_cqe(ring, &cqe); + assert(err == 0); + assert(cqe->user_data == USERDATA); + io_uring_cqe_seen(ring, cqe); + + /* Return the result of the operation */ + return cqe->res; +} + +/* + * Run getsock operation using SO_RCVBUF using io_uring cmd operation and + * getsockopt(2) and compare the results. + */ +static int run_get_rcvbuf(struct io_uring *ring, struct fds *sockfds) +{ + int sval, uval, ulen, err; + unsigned int slen; + + /* System call values */ + slen = sizeof(sval); + /* io_uring values */ + ulen = sizeof(uval); + + /* get through io_uring cmd */ + err = submit_cmd_sqe(ring, sockfds->rx, SOCKET_URING_OP_GETSOCKOPT, + SOL_SOCKET, SO_RCVBUF, &uval, ulen); + assert(err == 1); + + /* Wait for the CQE */ + err = receive_cqe(ring); + if (err == -EOPNOTSUPP) + return T_EXIT_SKIP; + if (err < 0) { + fprintf(stderr, "Error received. %d\n", err); + return T_EXIT_FAIL; + } + /* The output of CQE->res contains the length */ + ulen = err; + + /* Executes the same operation using system call */ + err = getsockopt(sockfds->rx, SOL_SOCKET, SO_RCVBUF, &sval, &slen); + assert(err == 0); + + /* Make sure that io_uring operation returns the same value as the systemcall */ + assert(ulen == slen); + assert(uval == sval); + + return T_EXIT_PASS; +} + +/* + * Run getsock operation using SO_PEERNAME using io_uring cmd operation + * and getsockopt(2) and compare the results. + */ +static int run_get_peername(struct io_uring *ring, struct fds *sockfds) +{ + struct sockaddr sval, uval = {}; + socklen_t slen = sizeof(sval); + socklen_t ulen = sizeof(uval); + int err; + + /* Get values from the systemcall */ + err = getsockopt(sockfds->tx, SOL_SOCKET, SO_PEERNAME, &sval, &slen); + assert(err == 0); + + /* Getting SO_PEERNAME */ + err = submit_cmd_sqe(ring, sockfds->rx, SOCKET_URING_OP_GETSOCKOPT, + SOL_SOCKET, SO_PEERNAME, &uval, ulen); + assert(err == 1); + + /* Wait for the CQE */ + err = receive_cqe(ring); + if (err == -EOPNOTSUPP) + return T_EXIT_SKIP; + + if (err < 0) { + fprintf(stderr, "%s: Error in the CQE: %d\n", __func__, err); + return T_EXIT_FAIL; + } + + /* The length comes from cqe->res, which is returned from receive_cqe() */ + ulen = err; + + /* Make sure that io_uring operation returns the same values as the systemcall */ + assert(sval.sa_family == uval.sa_family); + assert(slen == ulen); + + return T_EXIT_PASS; +} + +/* + * Run getsockopt tests. Basically comparing io_uring output and systemcall results + */ +static int run_getsockopt_test(struct io_uring *ring, struct fds *sockfds) +{ + int err; + + fprintf(stderr, "Testing getsockopt SO_PEERNAME\n"); + err = run_get_peername(ring, sockfds); + if (err) + return err; + + fprintf(stderr, "Testing getsockopt SO_RCVBUF\n"); + err = run_get_rcvbuf(ring, sockfds); + + return err; +} + +/* + * Given a `val` value, set it in SO_REUSEPORT using io_uring cmd, and read using + * getsockopt(2), and make sure they match. + */ +static int run_setsockopt_reuseport(struct io_uring *ring, struct fds *sockfds, int val) +{ + unsigned int slen, ulen; + int sval, uval = val; + int err; + + slen = sizeof(sval); + ulen = sizeof(uval); + + /* Setting SO_REUSEPORT */ + err = submit_cmd_sqe(ring, sockfds->rx, SOCKET_URING_OP_SETSOCKOPT, + SOL_SOCKET, SO_REUSEPORT, &uval, ulen); + assert(err == 1); + + err = receive_cqe(ring); + if (err == -EOPNOTSUPP) + return T_EXIT_SKIP; + + /* Get values from the systemcall */ + err = getsockopt(sockfds->rx, SOL_SOCKET, SO_REUSEPORT, &sval, &slen); + assert(err == 0); + + /* Make sure the set using io_uring cmd matches what systemcall returns */ + assert(uval == sval); + assert(ulen == slen); + + return T_EXIT_PASS; +} + +/* + * Given a `val` value, set the TCP_USER_TIMEOUT using io_uring and read using + * getsockopt(2). Make sure they match + */ +static int run_setsockopt_usertimeout(struct io_uring *ring, struct fds *sockfds, int val) +{ + int optname = TCP_USER_TIMEOUT; + int level = IPPROTO_TCP; + unsigned int slen, ulen; + int sval, uval, err; + + slen = sizeof(uval); + ulen = sizeof(uval); + + uval = val; + + /* Setting timeout */ + err = submit_cmd_sqe(ring, sockfds->rx, SOCKET_URING_OP_SETSOCKOPT, + level, optname, &uval, ulen); + assert(err == 1); + + err = receive_cqe(ring); + if (err == -EOPNOTSUPP) + return T_EXIT_SKIP; + if (err < 0) { + fprintf(stderr, "%s: Got an error: %d\n", __func__, err); + return T_EXIT_FAIL; + } + + /* Get the value from the systemcall, to make sure it was set */ + err = getsockopt(sockfds->rx, level, optname, &sval, &slen); + assert(err == 0); + assert(uval == sval); + + return T_EXIT_PASS; +} + +/* Test setsockopt() for SOL_SOCKET */ +static int run_setsockopt_test(struct io_uring *ring, struct fds *sockfds) +{ + int err, i; + + fprintf(stderr, "Testing setsockopt SOL_SOCKET/SO_REUSEPORT\n"); + for (i = 0; i <= 1; i++) { + err = run_setsockopt_reuseport(ring, sockfds, i); + if (err) + return err; + } + + fprintf(stderr, "Testing setsockopt IPPROTO_TCP/TCP_FASTOPEN\n"); + for (i = 1; i <= 10; i++) { + err = run_setsockopt_usertimeout(ring, sockfds, i); + if (err) + return err; + } + + return err; +} + +/* Send data throughts the sockets */ +void send_data(struct fds *s) +{ + int written_bytes; + /* Send data sing the sockstruct->send */ + written_bytes = write(s->tx, MSG, strlen(MSG)); + assert(written_bytes == strlen(MSG)); +} + +int main(int argc, char *argv[]) +{ + struct fds sockfds; + struct io_uring ring; + int err; + + if (argc > 1) + return 0; + + /* Simply io_uring ring creation */ + ring = create_ring(); + + /* Create sockets */ + sockfds = create_sockets(); + + send_data(&sockfds); + + err = run_getsockopt_test(&ring, &sockfds); + if (err) { + if (err == T_EXIT_SKIP) { + fprintf(stderr, "Skipping tests.\n"); + return T_EXIT_SKIP; + } + fprintf(stderr, "Failed to run test: %d\n", err); + return err; + } + + err = run_setsockopt_test(&ring, &sockfds); + if (err) { + if (err == T_EXIT_SKIP) { + fprintf(stderr, "Skipping tests.\n"); + return T_EXIT_SKIP; + } + fprintf(stderr, "Failed to run test: %d\n", err); + return err; + } + + io_uring_queue_exit(&ring); + return err; +} From patchwork Fri Oct 20 13:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13430751 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 8BCBCCDB474 for ; Fri, 20 Oct 2023 13:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377074AbjJTNjh (ORCPT ); Fri, 20 Oct 2023 09:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377376AbjJTNjg (ORCPT ); Fri, 20 Oct 2023 09:39:36 -0400 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4171C19E for ; Fri, 20 Oct 2023 06:39:34 -0700 (PDT) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-9be02fcf268so126649666b.3 for ; Fri, 20 Oct 2023 06:39:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697809172; x=1698413972; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ecBcTJo5sXfk5aiuigWKv420DY2jJfGo1LUDJOdUAbA=; b=bcIimGogtvu5SHxXIDVskA6gV/bsM5KkLnYgvaSO5FB+8X1we7Hqmu3GacEjm/Fm5t yD6CiAyCkPrxVNX1QjuMkhIUU5jzi27ySXHEmMQQIsfOsyU3EjgKD0sZ1yZH4zmS+HTV HMuHIF4+74Hs7iHTmEYxzHaY+v0xMcxCBpjYkbUB/PDZF9yq4q38EZ/qOzQlpg6FYtxB 0BuEXEiC5nwI3WXbN639gGaGWt4737kvWcy6nMEo/P5ZHp8wO64hlBgT/zOlLkj+jbHq PleUvBQk+UpdsxfP7ED7FbOWRYsMINatHBdopAjjIgXmzmrOsuRvqxYvgtkbmk/OlMTT fm7g== X-Gm-Message-State: AOJu0YydD6EQVc23XKziEJqLc82F3XMZdcR+xJeDKuSHUGHd3h4MMgpk iz+u6Zp1CWr0R4OJL0rwNew= X-Google-Smtp-Source: AGHT+IGihgOGShk/iOyHNBrAytCBKuluhTEmP7LF8xbrqtspszeVQc7m0M8SAe53i/yXQ+ZfLwbgFA== X-Received: by 2002:a17:907:25c4:b0:9c1:bee1:b7eb with SMTP id ae4-20020a17090725c400b009c1bee1b7ebmr1466368ejc.37.1697809172424; Fri, 20 Oct 2023 06:39:32 -0700 (PDT) Received: from localhost (fwdproxy-cln-020.fbsv.net. [2a03:2880:31ff:14::face:b00c]) by smtp.gmail.com with ESMTPSA id jp10-20020a170906f74a00b009adc81bb544sm1544531ejb.106.2023.10.20.06.39.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:39:31 -0700 (PDT) From: Breno Leitao To: asml.silence@gmail.com, axboe@kernel.dk Cc: io-uring@vger.kernel.org Subject: [PATCH 4/5] man/io_uring_prep_cmd: Fix argument name Date: Fri, 20 Oct 2023 06:39:16 -0700 Message-Id: <20231020133917.953642-5-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020133917.953642-1-leitao@debian.org> References: <20231020133917.953642-1-leitao@debian.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org io_uring_prep_cmd(3) documents that one of the argument is SIOCOUTQ, while, in fact, it is called `SOCKET_URING_OP_SIOCOUTQ`. Fix the argument name, by replacing SIOCOUTQ to SOCKET_URING_OP_SIOCOUTQ. Fixes: 2459fef09411 ("io_uring_prep_cmd: Create a new helper for command ops") Signed-off-by: Breno Leitao --- man/io_uring_prep_cmd.3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/io_uring_prep_cmd.3 b/man/io_uring_prep_cmd.3 index 01b48da..d6ec909 100644 --- a/man/io_uring_prep_cmd.3 +++ b/man/io_uring_prep_cmd.3 @@ -55,7 +55,7 @@ For more information about this command, please check .TP -.B SIOCOUTQ +.B SOCKET_URING_OP_SIOCOUTQ Returns the amount of unsent data in the socket send queue. The socket must not be in LISTEN state, otherwise an error .B -EINVAL From patchwork Fri Oct 20 13:39:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Breno Leitao X-Patchwork-Id: 13430753 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 32821C07480 for ; Fri, 20 Oct 2023 13:39:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377376AbjJTNjh (ORCPT ); Fri, 20 Oct 2023 09:39:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377401AbjJTNjh (ORCPT ); Fri, 20 Oct 2023 09:39:37 -0400 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EAFB1BF for ; Fri, 20 Oct 2023 06:39:35 -0700 (PDT) Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-9b6559cbd74so128083566b.1 for ; Fri, 20 Oct 2023 06:39:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697809173; x=1698413973; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KZmIgf8orud72D6ZziTFbUOmUuDgSQtB73Fv85A+5OI=; b=GAWIejMEZtXKVILn8QjswOTblP6aKvcTxI3SzTndbb2HAAvu0dWy0TLoGCvJMwZDoB lD4ugPH3CwpRryBh7+YKkE9mWR2T8xjq4Xz3vSkDIrMp1jq4lLom4RyjXZEY9+WmTq2p kUcsvbWF2G89o/TqPV94DWWNFtRLv/JS1MNpEJXSXKwsKuXJi/ZtwKRarykTXuqfmmqy mFVtAR7LPdV8qG0/zYVoph7RUax/4c9Y6xw+FkvuYOKXLbXxVRYEOi39yaZCLmrbRuqf YRBy/AIfNftzn7yhhYSqEv3TkDr/ya+oEfgxrecOhwC8/K98+YVjuo9er4blHFpeptPO 1czA== X-Gm-Message-State: AOJu0YwxHkYkHAFjAv+oLzs6J9UC2tfKgyEZARtl/hOVfGCPH9ALzWSu gaGv+Pef46FsS0ZuNbAcuUk= X-Google-Smtp-Source: AGHT+IHPiF3+57Qs5OJ5jbUiz7tWTOvwgz4t6dQqcFsuKroYbp0ZwngQFE4COj51iNIKa12RMvWO9Q== X-Received: by 2002:a17:907:25c3:b0:9bf:32c8:30ff with SMTP id ae3-20020a17090725c300b009bf32c830ffmr1418843ejc.25.1697809173413; Fri, 20 Oct 2023 06:39:33 -0700 (PDT) Received: from localhost (fwdproxy-cln-010.fbsv.net. [2a03:2880:31ff:a::face:b00c]) by smtp.gmail.com with ESMTPSA id 26-20020a170906011a00b009ae587ce128sm1498970eje.216.2023.10.20.06.39.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 06:39:32 -0700 (PDT) From: Breno Leitao To: asml.silence@gmail.com, axboe@kernel.dk Cc: io-uring@vger.kernel.org Subject: [PATCH 5/5] man/io_uring_prep_cmd: Add the new sockopt commands Date: Fri, 20 Oct 2023 06:39:17 -0700 Message-Id: <20231020133917.953642-6-leitao@debian.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231020133917.953642-1-leitao@debian.org> References: <20231020133917.953642-1-leitao@debian.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org io_uring now supports getsockopt and setsockopt socket commands. Document these two new commands in the io_uring_prep_cmd man page. Signed-off-by: Breno Leitao --- man/io_uring_prep_cmd.3 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/man/io_uring_prep_cmd.3 b/man/io_uring_prep_cmd.3 index d6ec909..12f607e 100644 --- a/man/io_uring_prep_cmd.3 +++ b/man/io_uring_prep_cmd.3 @@ -72,6 +72,38 @@ Negative return value means an error. For more information about this command, please check .BR unix(7). +.TP +.B SOCKET_URING_OP_GETSOCKOPT +Command to get options for the socket referred to by the socket file descriptor +.I fd. +The arguments are similar to the +.BR getsockopt(2) +system call. + +The +.BR SOCKET_URING_OP_GETSOCKOPT +command is limited to +.BR SOL_SOCKET +.I level. + +Differently from the +.BR getsockopt(2) +system call, the updated +.I optlen +value is returned in the CQE +.I res +field, on success. On failure, the CQE +.I res +contains a negative error number. + +.TP +.B SOCKET_URING_OP_SETSOCKOPT +Command to set options for the socket referred to by the socket file descriptor +.I fd. +The arguments are similar to the +.BR setsockopt(2) +system call. + .SH NOTES The memory block pointed by .I optval