From patchwork Wed May 17 19:12:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13245569 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 B712FC77B7D for ; Wed, 17 May 2023 19:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbjEQTM2 (ORCPT ); Wed, 17 May 2023 15:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbjEQTMX (ORCPT ); Wed, 17 May 2023 15:12:23 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAFCEAD0A for ; Wed, 17 May 2023 12:12:12 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-76c6e795650so179939f.1 for ; Wed, 17 May 2023 12:12:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1684350731; x=1686942731; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SM0dEJvoZTNqWby0NsDJcypvoJnqRDOoMK+FyUUukzU=; b=NlE+DJBMpjyDexZMA7pqgO6hwPVCwf+/nLNMaUDQwW0ig3/dpS2TNDyQXX4e0tCHht MeSRPZpRi7s8iUGayu52Ta9eozJP0DPQhZ7xGSRRPUZZvbLzaCMSZDgfG7xxFI/rho2S Qp1eC1GsV/uuFJFHl5KpUaa957wYDM8MuS3JmlUb73+SAM1gtnm8Er4COHFavFzzdpDY xgRD46Pn0l1wbW4bggflUctLut7trJYohpuGdUkyocjtJdnUgXpZyLe9F2icOIW2GDNt D5MK25tBofFaefuqbs3stMInK/aEPDzirBILA+A5Sk9OR1r/4eN5uoOOP9ReaE1/QBqb mBLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684350731; x=1686942731; 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=SM0dEJvoZTNqWby0NsDJcypvoJnqRDOoMK+FyUUukzU=; b=hplL40smVzQlebbWf0c/1K8dgCSSbvEE/iGKzgIPfC1cEfLwi8whaAl1r92TkJMT2m YjsBRJRRxn3pKaiUDYTmXrWxVbxBTc99I1Ua35QB33R7Ap4H+yTz7ubWq3XZEBwSyPFL 7f4YyXoZ5/k0P0XQXmk1zKN/84NGtm2MAR6MQnXDiqdsalX0dIBakNXx5oXIc1Ck4Tqu D4VRjIaVWHY9+D3yO+bTY2uBfW+kshbMUrRqhYTlXlQGElfOYsgMITyWImWD3lC9j2Vn 55n4BjZbNIroyjeoM0CdbD1k1xm0/6di9ZAHDJ0r9rGxRMWa8VOop4eNXE77yWfQc5NF 8ukw== X-Gm-Message-State: AC+VfDxv2BFsK0AEE9KqxKg5qDZw9OshZ3PcRSxqA3KaTChJzKbhgRKb 9+baaQ1SIDZzt7r5oaU4kDySrIrmlV0Y7kivwho= X-Google-Smtp-Source: ACHHUZ75fFQ8k4IBs08/y8BiOp4MbSeRs9WfRWRZeZnEhfZAg6mqnBG1raC9s6MEdXXaGL17WbmDVQ== X-Received: by 2002:a92:60b:0:b0:338:4b36:5097 with SMTP id x11-20020a92060b000000b003384b365097mr610804ilg.1.1684350730951; Wed, 17 May 2023 12:12:10 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id b16-20020a92db10000000b0033827a77e24sm628996iln.50.2023.05.17.12.12.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 12:12:08 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/4] io_uring/net: initialize struct msghdr more sanely for io_recv() Date: Wed, 17 May 2023 13:12:00 -0600 Message-Id: <20230517191203.2077682-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517191203.2077682-1-axboe@kernel.dk> References: <20230517191203.2077682-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org We only need to clear the input fields on the first invocation, not when potentially doing a retry. Signed-off-by: Jens Axboe --- io_uring/net.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 89e839013837..08fe42673b75 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -860,6 +860,14 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(!sock)) return -ENOTSOCK; + msg.msg_name = NULL; + msg.msg_namelen = 0; + msg.msg_control = NULL; + msg.msg_get_inq = 1; + msg.msg_controllen = 0; + msg.msg_iocb = NULL; + msg.msg_ubuf = NULL; + retry_multishot: if (io_do_buffer_select(req)) { void __user *buf; @@ -874,14 +882,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(ret)) goto out_free; - msg.msg_name = NULL; - msg.msg_namelen = 0; - msg.msg_control = NULL; - msg.msg_get_inq = 1; msg.msg_flags = 0; - msg.msg_controllen = 0; - msg.msg_iocb = NULL; - msg.msg_ubuf = NULL; flags = sr->msg_flags; if (force_nonblock) From patchwork Wed May 17 19:12:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13245570 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 ED53FC77B7D for ; Wed, 17 May 2023 19:12:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbjEQTMb (ORCPT ); Wed, 17 May 2023 15:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbjEQTMa (ORCPT ); Wed, 17 May 2023 15:12:30 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6E57A5D1 for ; Wed, 17 May 2023 12:12:15 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-76c6ba5fafaso7279239f.1 for ; Wed, 17 May 2023 12:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1684350734; x=1686942734; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VSHgpsawUu5gp9G1ICYLSm0Yw+4JMWG54aNinBgLm1Q=; b=rPWTS/7OTVM0SsAcsZH9eMEwqU7lHxdsuePaEQG8lsKaxpInFtgXjC0Q4CSrYtTGWn CsIrBS4vfMw9Dxkl7pRQ9c4Uhd2yRMOKRZsoVX95Pb+fD97e4MiMWHyE+0QVc2tiqvL5 uCuS412P3yMtlLeRRvaaneaLe0n16dn8YfOwJtcmSDHum04GFTIFqlkUCwJZR2vWaHiU RTkHa7M419/KUd6jQQJGp6+WxYgBmtQsRalLK3/Yk+YDqMa3mlJv+vNArLnypWMR6RWr S95VSRvdCFhiprSpCiBzDWSfiCNbSbN1Hw9qvQgO+IMsM5B4goZ35Ye9TpdRY0ptPbJ9 q9IQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684350734; x=1686942734; 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=VSHgpsawUu5gp9G1ICYLSm0Yw+4JMWG54aNinBgLm1Q=; b=dk0GZzQhA8T30I0xCr/wMxUkyGnXISKmAf0acYIkC4wkMnENXTjQzH0GaH1LCmJjNk mVSu0x2euNXtZepfa/zoVsECVimCWxH6+/DYv2/d8pBPDuo5epeP5F/s/M/kIgr1zJRI UyFBVFqqVeb/WVe+fZ0piybXS2NY9f8p4h254KWBxS1+VmkQ7NECb0JDB8UXGZm6DseC cPd23ZNAROr4RCMHRQSqvpzrfD+plYQjyaweNx0V3N8e8Tl+Y1iScgoKEbmvlEji+beS pI7PV/U2Qt042tYTdoQOBCSFzIfv7nWoU2m3Cgy5UgLqhw4JzBBBm8UfLmNYymXkk6zq qaLw== X-Gm-Message-State: AC+VfDxYt3i6z/sM66gF9jQjCM5zwciYPn22XG/aFAV61ZC6qTAtdJ4W 8QtI2l+S2iP9vF+zRzckEEmuajy3bP6USbwTlHw= X-Google-Smtp-Source: ACHHUZ6sGEOVnBUSUVwUeh5hZmCalH2JBttwK5v5kRqvHgHzN7nmH4W6hvf/Le6KRS51iq/pqbq4Pg== X-Received: by 2002:a92:300b:0:b0:332:f7a:4347 with SMTP id x11-20020a92300b000000b003320f7a4347mr1828436ile.3.1684350734062; Wed, 17 May 2023 12:12:14 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id b16-20020a92db10000000b0033827a77e24sm628996iln.50.2023.05.17.12.12.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 12:12:12 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/4] io_uring/net: initalize msghdr->msg_inq to known value Date: Wed, 17 May 2023 13:12:01 -0600 Message-Id: <20230517191203.2077682-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517191203.2077682-1-axboe@kernel.dk> References: <20230517191203.2077682-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org We can't currently tell if ->msg_inq was set when we ask for msg_get_inq, initialize it to -1U so we can tell apart if it was set and there's no data left, or if it just wasn't set at all by the protocol. Signed-off-by: Jens Axboe --- io_uring/net.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 08fe42673b75..45f9c3046d67 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -785,6 +785,7 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) min_ret = iov_iter_count(&kmsg->msg.msg_iter); kmsg->msg.msg_get_inq = 1; + kmsg->msg.msg_inq = -1U; if (req->flags & REQ_F_APOLL_MULTISHOT) ret = io_recvmsg_multishot(sock, sr, kmsg, flags, &mshot_finished); @@ -821,7 +822,7 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) io_kbuf_recycle(req, issue_flags); cflags = io_put_kbuf(req, issue_flags); - if (kmsg->msg.msg_inq) + if (kmsg->msg.msg_inq && kmsg->msg.msg_inq != -1U) cflags |= IORING_CQE_F_SOCK_NONEMPTY; if (!io_recv_finish(req, &ret, cflags, mshot_finished, issue_flags)) @@ -882,6 +883,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) if (unlikely(ret)) goto out_free; + msg.msg_inq = -1U; msg.msg_flags = 0; flags = sr->msg_flags; @@ -923,7 +925,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) io_kbuf_recycle(req, issue_flags); cflags = io_put_kbuf(req, issue_flags); - if (msg.msg_inq) + if (msg.msg_inq && msg.msg_inq != -1U) cflags |= IORING_CQE_F_SOCK_NONEMPTY; if (!io_recv_finish(req, &ret, cflags, ret <= 0, issue_flags)) From patchwork Wed May 17 19:12:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13245571 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 3B48DC77B75 for ; Wed, 17 May 2023 19:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229955AbjEQTMm (ORCPT ); Wed, 17 May 2023 15:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbjEQTMg (ORCPT ); Wed, 17 May 2023 15:12:36 -0400 Received: from mail-il1-x12e.google.com (mail-il1-x12e.google.com [IPv6:2607:f8b0:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99B7CD056 for ; Wed, 17 May 2023 12:12:20 -0700 (PDT) Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-334d0f0d537so556665ab.0 for ; Wed, 17 May 2023 12:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1684350739; x=1686942739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Tg7+MaJ3NXxHlUMUvA6Q1ZlXCnsNrLvuDCIr3Vu4cXA=; b=VV4RAx1jp1Pa3CEtIa7z4N6VATlDcNggv45q3/FNLoc4qLN3gvfEkNaBi0KBhQCrQr nAjIFbaF4lwBtNGu/q70OJMCF2qB8+V8WqE4reYoWZobXS1ZX6fQkWTLW/Y05w5uL5JB +bbbnyER3n+LCl/5uQRqbUJA/cP4j3Td/URet4vlHNsAi0esNLWLXpsk283lJEJDDIdA GME0j4lmjmp6Gz+9kmEjM1gNP+cgypY+k0L2o1dJlsYl8ZzNy+tGDCj5sc659JHmsx8W OI81yboof2hEaGv/LVTL9Pi4uDZMdMJ/x3fPVVFbpuNLDGtjk8/v1E8jrfiR/uv0lGhc GFvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684350739; x=1686942739; 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=Tg7+MaJ3NXxHlUMUvA6Q1ZlXCnsNrLvuDCIr3Vu4cXA=; b=ZOJzUio4lc06FRPz1eSaM8rymWGjbhjp1QYUZZ8ekvLXd0/fKL+W5YKHLa1SdSXNaT gvF0qOBs3eERK9ZUPGdHcuD/NDn50A6uiba0tfkpTzQar/fwHy+agp2X0pClmbVDHca2 R0Mq4Z1VbYSARXWpT35FxmlfnL/XtuJ3FiGLrbZxGDBZMUrCf2o0sZhHk+H4Cf6b3qr7 Zwj5RAHrQrUoLMGRxwL2CFT16pO8e8gGj+ipCBx0YZZE65k2OBgBSdqKGi6uzJgJI4Hq mYXUpYqa5CYtGkvcV3L4kPnTj7miwVdL972DBe0HplNQYN56jcrXKPiSAw7pDwt6QcTI 8nEA== X-Gm-Message-State: AC+VfDy91sMwgl4uHt7Wo3KnwarsKuShxsc/NqQRn2jUwJVGj8w5TLuB SBbTrXOcR8dp6M14dfo859nzaaSdYYV8r9cd9Rk= X-Google-Smtp-Source: ACHHUZ7ryTY2lXLnU9SThKhbjdZK1fBzntGkDAnaqFJxJGvs6eNYZjgcHhyxJ6ngX19HI/apuW2Khg== X-Received: by 2002:a92:7604:0:b0:32a:8792:7248 with SMTP id r4-20020a927604000000b0032a87927248mr2171990ilc.2.1684350738813; Wed, 17 May 2023 12:12:18 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id b16-20020a92db10000000b0033827a77e24sm628996iln.50.2023.05.17.12.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 12:12:17 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/4] io_uring/net: push IORING_CQE_F_SOCK_NONEMPTY into io_recv_finish() Date: Wed, 17 May 2023 13:12:02 -0600 Message-Id: <20230517191203.2077682-4-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517191203.2077682-1-axboe@kernel.dk> References: <20230517191203.2077682-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Rather than have this logic in both io_recv() and io_recvmsg_multishot(), push it into the handler they both call when finishing a receive operation. Signed-off-by: Jens Axboe --- io_uring/net.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/io_uring/net.c b/io_uring/net.c index 45f9c3046d67..9e0034771dbb 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -616,9 +616,15 @@ static inline void io_recv_prep_retry(struct io_kiocb *req) * again (for multishot). */ static inline bool io_recv_finish(struct io_kiocb *req, int *ret, - unsigned int cflags, bool mshot_finished, + struct msghdr *msg, bool mshot_finished, unsigned issue_flags) { + unsigned int cflags; + + cflags = io_put_kbuf(req, issue_flags); + if (msg->msg_inq && msg->msg_inq != -1U) + cflags |= IORING_CQE_F_SOCK_NONEMPTY; + if (!(req->flags & REQ_F_APOLL_MULTISHOT)) { io_req_set_res(req, *ret, cflags); *ret = IOU_OK; @@ -732,7 +738,6 @@ 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); struct io_async_msghdr iomsg, *kmsg; struct socket *sock; - unsigned int cflags; unsigned flags; int ret, min_ret = 0; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; @@ -821,11 +826,7 @@ int io_recvmsg(struct io_kiocb *req, unsigned int issue_flags) else io_kbuf_recycle(req, issue_flags); - cflags = io_put_kbuf(req, issue_flags); - if (kmsg->msg.msg_inq && kmsg->msg.msg_inq != -1U) - cflags |= IORING_CQE_F_SOCK_NONEMPTY; - - if (!io_recv_finish(req, &ret, cflags, mshot_finished, issue_flags)) + if (!io_recv_finish(req, &ret, &kmsg->msg, mshot_finished, issue_flags)) goto retry_multishot; if (mshot_finished) { @@ -844,7 +845,6 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) struct io_sr_msg *sr = io_kiocb_to_cmd(req, struct io_sr_msg); struct msghdr msg; struct socket *sock; - unsigned int cflags; unsigned flags; int ret, min_ret = 0; bool force_nonblock = issue_flags & IO_URING_F_NONBLOCK; @@ -924,11 +924,7 @@ int io_recv(struct io_kiocb *req, unsigned int issue_flags) else io_kbuf_recycle(req, issue_flags); - cflags = io_put_kbuf(req, issue_flags); - if (msg.msg_inq && msg.msg_inq != -1U) - cflags |= IORING_CQE_F_SOCK_NONEMPTY; - - if (!io_recv_finish(req, &ret, cflags, ret <= 0, issue_flags)) + if (!io_recv_finish(req, &ret, &msg, ret <= 0, issue_flags)) goto retry_multishot; return ret; From patchwork Wed May 17 19:12:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13245572 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 C812DC7EE2A for ; Wed, 17 May 2023 19:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229977AbjEQTMp (ORCPT ); Wed, 17 May 2023 15:12:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229852AbjEQTMk (ORCPT ); Wed, 17 May 2023 15:12:40 -0400 Received: from mail-il1-x134.google.com (mail-il1-x134.google.com [IPv6:2607:f8b0:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E50183AAF for ; Wed, 17 May 2023 12:12:23 -0700 (PDT) Received: by mail-il1-x134.google.com with SMTP id e9e14a558f8ab-3357ea1681fso559795ab.1 for ; Wed, 17 May 2023 12:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1684350742; x=1686942742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TVbbeVhOmjwSyjTSnsPUaCjEOb0Ai/UlhSkz6YZfab8=; b=s5joX0Tut/zCLIhBhuwyRgELx61plpyi9YqTtuKrhVmLl5aSgwwSeu6FpcNO9i19Ub NVUSgSojFM2CeDypaY7D5x1o/0N6BcHL8nKBSB3plMUylRPiRnWeBQoXoL7F1ls5TTeO svO3WbFcIv44UJRz7SSn8qQIGxsKajTwtw8+wio8x6BRSDhIfO3LqpYCqkWE+a+uBGvW /lNz2VrQwGlwH1ljO0lNxStoJr1sB3Yri/u7WWfZzyiGsevfidUTKe7KX2K96dZgjpMh c9ar/Oc+qdXx64rKLXYcDePh606zdk4oF1FSo1Ky1B7bN7RTq4+/2HfYafCHlxTDkyvv xWTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684350742; x=1686942742; 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=TVbbeVhOmjwSyjTSnsPUaCjEOb0Ai/UlhSkz6YZfab8=; b=ZB0bz5EwxcSiEJO0VN4Sp/aOtU0JhrdhziI5e1vx8LzzZ23iy3V+w8gGT2TxLy07SG yIQlS/MssCqsDBze7X1mUDJtRKKftrzJ3Y+DmnmKDF/T88NsYVR/Q3IB0ESPJ45E6gbr /A/MQ6ucuCIDV4KmjDARZe1XTGPlX7fgOFky50n6ycnvtA/+HoW6RsmOC6GyKfPfZxiI +gJtZEUhjTws/YU8hDebNM+XjOtOG7ZzSrkJZBh/JoBNSK8g0OqGzyNc+GOYxfF3AdGX 6KJTZ6ppjbuUCKp38KcFxvxl9qwVo2bz/PpHoHCLzOxbVJUsrhKSz20hT1xLfguQ5vdl WY5Q== X-Gm-Message-State: AC+VfDzvQtHaaVnmx4+JAvWWfbRoD83+grt8EvAvmVy/kFLPwdlQLjSF EvhTWPDc0qcbhyUGDvVBSj9R7aNtGFoUawu1FM4= X-Google-Smtp-Source: ACHHUZ5gPFMgKDKedn1rJtBWG9n6L8d7xari5Ix/t0qoFyOJ/lxMVh8CK3iGO8MHApKP+3x/LBAOTw== X-Received: by 2002:a92:c569:0:b0:32a:eacb:c5d4 with SMTP id b9-20020a92c569000000b0032aeacbc5d4mr2551611ilj.0.1684350742239; Wed, 17 May 2023 12:12:22 -0700 (PDT) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id b16-20020a92db10000000b0033827a77e24sm628996iln.50.2023.05.17.12.12.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 May 2023 12:12:20 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 4/4] io_uring/net: don't retry recvmsg() unnecessarily Date: Wed, 17 May 2023 13:12:03 -0600 Message-Id: <20230517191203.2077682-5-axboe@kernel.dk> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230517191203.2077682-1-axboe@kernel.dk> References: <20230517191203.2077682-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org If we're doing multishot receives, then we always end up doing two trips through sock_recvmsg(). For protocols that sanely set msghdr->msg_inq, then we don't need to waste time picking a new buffer and attemtping a new receive if there's nothing there. Signed-off-by: Jens Axboe --- io_uring/net.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/io_uring/net.c b/io_uring/net.c index 9e0034771dbb..0795f3783013 100644 --- a/io_uring/net.c +++ b/io_uring/net.c @@ -635,7 +635,15 @@ static inline bool io_recv_finish(struct io_kiocb *req, int *ret, if (io_aux_cqe(req->ctx, issue_flags & IO_URING_F_COMPLETE_DEFER, req->cqe.user_data, *ret, cflags | IORING_CQE_F_MORE, true)) { io_recv_prep_retry(req); - return false; + /* Known not-empty or unknown state, retry */ + if (cflags & IORING_CQE_F_SOCK_NONEMPTY || + msg->msg_inq == -1U) + return false; + if (issue_flags & IO_URING_F_MULTISHOT) + *ret = IOU_ISSUE_SKIP_COMPLETE; + else + *ret = -EAGAIN; + return true; } /* Otherwise stop multishot but use the current result. */ }