From patchwork Tue Aug 16 07:42:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12944498 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 97202C32771 for ; Tue, 16 Aug 2022 09:27:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230162AbiHPJ1G (ORCPT ); Tue, 16 Aug 2022 05:27:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230285AbiHPJ0h (ORCPT ); Tue, 16 Aug 2022 05:26:37 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D08289C218 for ; Tue, 16 Aug 2022 00:43:22 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id dc19so17376200ejb.12 for ; Tue, 16 Aug 2022 00:43:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=wli84RS/gEgVUPbgbSmPokmw5HWw7zXztjijpxFndag=; b=YGc6AtrlSXXfQQ3R53DijGTNZGi9D2+ne+e+V42k/w9tAz5nZGnkJ2e4FLX8rVOysN 3svtZKya01pRivZ8HQKtDAF4dVSXyasEwQGDT4S4vbc1IMtco3kyghcSD7VgQLiyuR5c KbWZa5K4Aplb2WFquyTN7nt12IelZqVFFbbwFRlKCPtSQ+ijqTdZRguDNwrUIeDNkumR SDLNp3+mFyBIq6P5NrQrC11jec/2Q0JACYuMksAVNsAxjmRlh5JqkxJ1fcjqXOhEJDYb XPKdv0oVGK5ydqQ62Q7dkC5XwKQY9PdkMcI7sEl6OBGDNRsuXmeBpWo7FbOSw4v4804H uA6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=wli84RS/gEgVUPbgbSmPokmw5HWw7zXztjijpxFndag=; b=65r/65qpBc8WElUM37zvTah+Xek9lHSXlpzFxik0Q+9L5AQQvmNXbYpXrZxv9onYO7 7BYd9YyFUupZ5pSRvnUMveoVp+PM8IMtEof76YR7RXn04jzQVc7nkqmGNnJxtBR23Nw+ +VBhdqlXM7L9+JO61NBG2/fhOdD5YJCWCARkpWZ+Tveq8rMh7h+u0Sw4zJHsWR7IT8Nd Tv7jrffKIwG55hwbYjTRqLA69HHO26ZuqLlTWBH9AXw1gN6uVCGiotZHzWSX6hGbwdLE +9jjvXSc5hGhnl5L5kiDkeic4z0VyAZeOiWt4/3e2/E/Me/PLFop/2Ks3xhVxcsIqpmN P7GQ== X-Gm-Message-State: ACgBeo1I7hJqIs9tP4tQzMcCS18dZ+V8ZPJJmytemfS3mSIkCZdZ2jck VZ61rw+qau+zLvFMxTNXvaBNq8jQN9s= X-Google-Smtp-Source: AA6agR7ByRrm3crsxgIaMIJzCBi1yRyQhH4CSXanvTWpx+DBgPNZ6EcJYjzGpYXJpYwJ8Opmi6cg3A== X-Received: by 2002:a17:906:4598:b0:738:4282:995f with SMTP id qs24-20020a170906459800b007384282995fmr6133609ejc.592.1660635801132; Tue, 16 Aug 2022 00:43:21 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.126.24.threembb.co.uk. [188.28.126.24]) by smtp.gmail.com with ESMTPSA id e1-20020a1709062c0100b00730799724c3sm5057363ejh.149.2022.08.16.00.43.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 00:43:20 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Dylan Yudaken , Stefan Metzmacher Subject: [RFC 1/2] io_uring/notif: change notif CQE uapi format Date: Tue, 16 Aug 2022 08:42:00 +0100 Message-Id: <1ef0d539e1eb74d9aa0456d07198ecaadaf1b6a4.1660635140.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Change the notification CQE layout while we can, put the seq number into cqe->res so we can cqe->flags to mark notification CQEs with IORING_CQE_F_NOTIF and add other flags in the future if needed. This will be needed to distinguish notifications from send completions when they use the same user_data. Also, limit the sequence number to u16 and reserve upper 16 bits for the future. We also want it to mask out the sign bit for userspace convenience as it's easier to test for (cqe->res < 0). Signed-off-by: Pavel Begunkov --- include/uapi/linux/io_uring.h | 6 ++++++ io_uring/notif.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 1463cfecb56b..20368394870e 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -286,6 +286,9 @@ enum io_uring_op { #define IORING_RECVSEND_FIXED_BUF (1U << 2) #define IORING_RECVSEND_NOTIF_FLUSH (1U << 3) +/* cqe->res mask for extracting the notification sequence number */ +#define IORING_NOTIF_SEQ_MASK 0xFFFFU + /* * accept flags stored in sqe->ioprio */ @@ -337,10 +340,13 @@ struct io_uring_cqe { * IORING_CQE_F_BUFFER If set, the upper 16 bits are the buffer ID * IORING_CQE_F_MORE If set, parent SQE will generate more CQE entries * IORING_CQE_F_SOCK_NONEMPTY If set, more data to read after socket recv + * IORING_CQE_F_NOTIF Set for notification CQEs. Can be used to distinct + * them from sends. */ #define IORING_CQE_F_BUFFER (1U << 0) #define IORING_CQE_F_MORE (1U << 1) #define IORING_CQE_F_SOCK_NONEMPTY (1U << 2) +#define IORING_CQE_F_NOTIF (1U << 3) enum { IORING_CQE_BUFFER_SHIFT = 16, diff --git a/io_uring/notif.c b/io_uring/notif.c index 714715678817..6e17d1ae5a0d 100644 --- a/io_uring/notif.c +++ b/io_uring/notif.c @@ -60,8 +60,8 @@ struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx, notif->rsrc_node = NULL; io_req_set_rsrc_node(notif, ctx, 0); notif->cqe.user_data = slot->tag; - notif->cqe.flags = slot->seq++; - notif->cqe.res = 0; + notif->cqe.flags = IORING_CQE_F_NOTIF; + notif->cqe.res = slot->seq++ & IORING_NOTIF_SEQ_MASK; nd = io_notif_to_data(notif); nd->account_pages = 0; From patchwork Tue Aug 16 07:42:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12944499 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 311A4C32772 for ; Tue, 16 Aug 2022 09:27:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230285AbiHPJ1H (ORCPT ); Tue, 16 Aug 2022 05:27:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230481AbiHPJ0i (ORCPT ); Tue, 16 Aug 2022 05:26:38 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E633CAC88 for ; Tue, 16 Aug 2022 00:43:24 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id x21so12417590edd.3 for ; Tue, 16 Aug 2022 00:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=yVzqRhsA8UgsVSoAOBpYJgpjwlxlDe/nBeUWWw8GQ1U=; b=Lad4ZptyJtJSoMxQI2Un7L81eQnwRD2kH5hx4JIcZ4IBbTgoB5Xss2pSIeJD5w7uOW z03eou0pQIQafSw/ADFYhc5DqJofx0QOjxlVFhB1i87tvnyKUFLqMWG2nm/awhxrIaSQ NCSBovETHCvVeu0swOxhE8HMZOFHe/0N/M8j2LSWQLwtuIghNnGzpFzPSFa9fsGNt6qp 3jqmwdjWAwjQNA6XqXKfZY3Xe4Hx7h3R8ssVVpC4qqp3RXfa4G9PDD6REWlZX1PlLnPf 4lGmG95qlBkX87oTp5jlQVf7HrJF/B+rmv28CX0/5pajmAp2dNR6MtLYuQ+Gy5ebru2d 8sWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=yVzqRhsA8UgsVSoAOBpYJgpjwlxlDe/nBeUWWw8GQ1U=; b=ycV8+6F9+jBumgNaUSNE/iqmjv+8DSBlQf8ALISX/2hE5XrN5XK+LDrrk4srygzC1h nIc2WH9r2M/biz/CUenQQgGMWBuejn3z4Z8wITwztgV7qFiDm3gR2F+NzjIYRzPHf7fi DNO0yflhU6mtQro00BX6OqX9WJpUZikQQ/mGFst5SJgLyrzJPvlT9CEgsXZ5npWnBHlG +7OREXm780ePsPTQyytSBDp3pK3/UVZZhZApceJ4Q5mkt0IPed9KoekniVQ0XypwjHuD xniMiAzZFrBqte5OiaAgMk6MY+2X9O8USCDawngWW+Pud4xwzX3ykTcugXIeS9w51uOd KCUw== X-Gm-Message-State: ACgBeo3bAD/wOKSMMi0GVT5qpdY0U7eBQYktANtkvVEg6CTi9IWdh4B7 mcarv/gtrcplu1BBWpW7FRKRkU4M7NU= X-Google-Smtp-Source: AA6agR6LCG41lq+LAzNh2WuG7qvVYWG7aFP6Q5xciCKd1zpzeSfdDaJP2eG1R5Cocy1ZSvaYQHQa9Q== X-Received: by 2002:a05:6402:2753:b0:43a:d6f2:9839 with SMTP id z19-20020a056402275300b0043ad6f29839mr17257050edd.73.1660635802255; Tue, 16 Aug 2022 00:43:22 -0700 (PDT) Received: from 127.0.0.1localhost (188.28.126.24.threembb.co.uk. [188.28.126.24]) by smtp.gmail.com with ESMTPSA id e1-20020a1709062c0100b00730799724c3sm5057363ejh.149.2022.08.16.00.43.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 00:43:21 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, Dylan Yudaken , Stefan Metzmacher Subject: [RFC 2/2] io_uring/net: allow to override notification tag Date: Tue, 16 Aug 2022 08:42:01 +0100 Message-Id: <6aa0c662a3fec17a1ade512e7bbb519aa49e6e4d.1660635140.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Considering limited amount of slots some users struggle with registration time notification tag assignment as it's hard to manage notifications using sequence numbers. Add a simple feature that copies sqe->user_data of a send(+flush) request into the notification CQE it flushes (and only when it's flushes). Signed-off-by: Pavel Begunkov --- include/uapi/linux/io_uring.h | 4 ++++ io_uring/net.c | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index 20368394870e..91e7944c9c78 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -280,11 +280,15 @@ enum io_uring_op { * * IORING_RECVSEND_NOTIF_FLUSH Flush a notification after a successful * successful. Only for zerocopy sends. + * + * IORING_RECVSEND_NOTIF_COPY_TAG Copy request's user_data into the notification + * completion even if it's flushed. */ #define IORING_RECVSEND_POLL_FIRST (1U << 0) #define IORING_RECV_MULTISHOT (1U << 1) #define IORING_RECVSEND_FIXED_BUF (1U << 2) #define IORING_RECVSEND_NOTIF_FLUSH (1U << 3) +#define IORING_RECVSEND_NOTIF_COPY_TAG (1U << 4) /* cqe->res mask for extracting the notification sequence number */ #define IORING_NOTIF_SEQ_MASK 0xFFFFU diff --git a/io_uring/net.c b/io_uring/net.c index bd3fad9536ef..4d271a269979 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -858,7 +858,9 @@ int io_sendzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) zc->flags = READ_ONCE(sqe->ioprio); if (zc->flags & ~(IORING_RECVSEND_POLL_FIRST | - IORING_RECVSEND_FIXED_BUF | IORING_RECVSEND_NOTIF_FLUSH)) + IORING_RECVSEND_FIXED_BUF | + IORING_RECVSEND_NOTIF_FLUSH | + IORING_RECVSEND_NOTIF_COPY_TAG)) return -EINVAL; if (zc->flags & IORING_RECVSEND_FIXED_BUF) { unsigned idx = READ_ONCE(sqe->buf_index); @@ -1024,6 +1026,8 @@ int io_sendzc(struct io_kiocb *req, unsigned int issue_flags) if (ret == -ERESTARTSYS) ret = -EINTR; } else if (zc->flags & IORING_RECVSEND_NOTIF_FLUSH) { + if (zc->flags & IORING_RECVSEND_NOTIF_COPY_TAG) + notif->cqe.user_data = req->cqe.user_data; io_notif_slot_flush_submit(notif_slot, 0); }