From patchwork Fri Sep 23 04:59:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 12986125 X-Patchwork-Delegate: kuba@kernel.org 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 26902ECAAD8 for ; Fri, 23 Sep 2022 04:59:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229788AbiIWE7Y (ORCPT ); Fri, 23 Sep 2022 00:59:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbiIWE7W (ORCPT ); Fri, 23 Sep 2022 00:59:22 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56BC6115BE4; Thu, 22 Sep 2022 21:59:21 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id ml1so8353750qvb.1; Thu, 22 Sep 2022 21:59:21 -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:subject:date; bh=w7WgXqDy6uF6D+cwyb3YICMekC6oPMZu16hQg76TAnA=; b=mCh0hQB87AyS+SvnmXQml6Ibr0omif9APXSh7t707zyN3sjQt2K2/Sx4adFGzQM/SH 4TLyvSNnrqdQeI89nPdnBU4X6yoOG/r0V3G4PvbCyf2is0izv2JG4Vm1ga6w8q5jgLvp BfDOYMRN5z9vL7ZHbgc1zg0jJj/CqK39G8dBD//GekYY8vdJbKzu2VDHtliv5YKS9W3F lAZwR+9TYG4BhMHLiqIop9Y6WdYGu5c5Ao/BmXpwDd1z+8eNLbu/iIFPIcEq3TVTa1an RngSul6mSsUV5rKYj+qtHYlRZaGxF/JpIhaaB7ZhhOcxphLu3ww2tCQQsRKZTrqf2dFD NELA== 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 :subject:date; bh=w7WgXqDy6uF6D+cwyb3YICMekC6oPMZu16hQg76TAnA=; b=JrnhLkohsHiRzmHUdV8Zv/iPGaCamCmxFeRhqTkvoQbW3K7FVCAbpeLa56TIVnuA/4 H/gvDJvbt0276uSf53EkeyOkllDdE7gJEsqwDFAjHh7zwG+xIMQs4AyqGRHgn3jRrp6S C0fTgynLsN5JVEb+yfIE2sANSB/fz3BWNreszMOP+TBpr1BhYmmCIKyReI8+2GlplMMG mX4oe7X7mwfWtYc1Qzlm1KIs7umDRK25Rwe8iY9bKbmbZom2beY5nO7lKBkFZ0aE06ci AvhlS+xRrK72vQE/NNEHUmF6VWjtGMPYTlwz5malkEaiHQJXmdot6PKB3f/wUhQrtWSt PxVw== X-Gm-Message-State: ACrzQf0TQomQLZidecY8043+CZNh6kMXHXyZ67RhlMD/xQ6YrkI4IaqU DpjTvj2fd6J/ftbTyuQ5v24BuU/3vA== X-Google-Smtp-Source: AMsMyM67b/wMw8cHGqon+6muFXWM74Sl4GqRVyNjNFY1g0kOQxvmpqa/nFFOoWnxPwqMzhdFILw2fA== X-Received: by 2002:a05:6214:2528:b0:4ad:6fa4:4170 with SMTP id gg8-20020a056214252800b004ad6fa44170mr5430291qvb.113.1663909160182; Thu, 22 Sep 2022 21:59:20 -0700 (PDT) Received: from bytedance.attlocal.net (ec2-3-231-65-244.compute-1.amazonaws.com. [3.231.65.244]) by smtp.gmail.com with ESMTPSA id x2-20020ac86b42000000b0034305a91aaesm4519573qts.83.2022.09.22.21.59.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 21:59:19 -0700 (PDT) From: Peilin Ye To: Eric Dumazet , "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Paolo Abeni Cc: Peilin Ye , Cong Wang , Kuniyuki Iwashima , Alexei Starovoitov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Peilin Ye Subject: [PATCH net-next RESEND 1/2] udp: Refactor udp_read_skb() Date: Thu, 22 Sep 2022 21:59:13 -0700 Message-Id: <343b5d8090a3eb764068e9f1d392939e2b423747.1663909008.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <03db9765fe1ef0f61bfc87fc68b5a95b4126aa4e.1663143016.git.peilin.ye@bytedance.com> References: <03db9765fe1ef0f61bfc87fc68b5a95b4126aa4e.1663143016.git.peilin.ye@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Peilin Ye Delete the unnecessary while loop in udp_read_skb() for readability. Additionally, since recv_actor() cannot return a value greater than skb->len (see sk_psock_verdict_recv()), remove the redundant check. Suggested-by: Cong Wang Signed-off-by: Peilin Ye --- net/ipv4/udp.c | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 560d9eadeaa5..d63118ce5900 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1801,41 +1801,29 @@ EXPORT_SYMBOL(__skb_recv_udp); int udp_read_skb(struct sock *sk, skb_read_actor_t recv_actor) { - int copied = 0; - - while (1) { - struct sk_buff *skb; - int err, used; - - skb = skb_recv_udp(sk, MSG_DONTWAIT, &err); - if (!skb) - return err; + struct sk_buff *skb; + int err, copied; - if (udp_lib_checksum_complete(skb)) { - __UDP_INC_STATS(sock_net(sk), UDP_MIB_CSUMERRORS, - IS_UDPLITE(sk)); - __UDP_INC_STATS(sock_net(sk), UDP_MIB_INERRORS, - IS_UDPLITE(sk)); - atomic_inc(&sk->sk_drops); - kfree_skb(skb); - continue; - } +try_again: + skb = skb_recv_udp(sk, MSG_DONTWAIT, &err); + if (!skb) + return err; - WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk)); - used = recv_actor(sk, skb); - if (used <= 0) { - if (!copied) - copied = used; - kfree_skb(skb); - break; - } else if (used <= skb->len) { - copied += used; - } + if (udp_lib_checksum_complete(skb)) { + int is_udplite = IS_UDPLITE(sk); + struct net *net = sock_net(sk); + __UDP_INC_STATS(net, UDP_MIB_CSUMERRORS, is_udplite); + __UDP_INC_STATS(net, UDP_MIB_INERRORS, is_udplite); + atomic_inc(&sk->sk_drops); kfree_skb(skb); - break; + goto try_again; } + WARN_ON_ONCE(!skb_set_owner_sk_safe(skb, sk)); + copied = recv_actor(sk, skb); + kfree_skb(skb); + return copied; } EXPORT_SYMBOL(udp_read_skb); From patchwork Fri Sep 23 04:59:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peilin Ye X-Patchwork-Id: 12986126 X-Patchwork-Delegate: kuba@kernel.org 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 89EF2C6FA82 for ; Fri, 23 Sep 2022 04:59:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229678AbiIWE7o (ORCPT ); Fri, 23 Sep 2022 00:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229865AbiIWE7j (ORCPT ); Fri, 23 Sep 2022 00:59:39 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B69262FD; Thu, 22 Sep 2022 21:59:35 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id ml1so8354010qvb.1; Thu, 22 Sep 2022 21:59:35 -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:subject:date; bh=E3uwB8CqWVlPJdmYFGu1eVYpx1JpXqpegdhCF2Dn9pA=; b=nZsnGlCKEzHd5dkQ0Y+CcZkE37s49utJ7EJjcXq+k9Xew12sdEX8ZXxoP6MT11iATd lVSFZjKCwWKTp77T6e35BiSz8cY2UJX++jtcHdDYwSiKi2CF2p3ZirJtNqoZRCo81+qn nbWX+HLIfTNp/1lBNasq9K9qgtuvM8qpjh+S6af5Pq02ap0uCnuCQxAxOW8xASajLw3i QEWtdD692EUISxJ91DrP/Z/n8Xu/FYDgY8WmZkqi/FwPOVKKANdd6LWK71JIjYoRJLcY Gga/YwSnTM5lBPvmjPS7Rr1d0oiHmgABjvrRH467LPt2f/Vm4pPLbbpgu4OVP8qcu0QJ A4Kg== 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 :subject:date; bh=E3uwB8CqWVlPJdmYFGu1eVYpx1JpXqpegdhCF2Dn9pA=; b=YyTy/7PhCu1Nl4g6sJPZ4EXJd3KZglaXe2ZcJHDkFg7nt8RK9qMFr4CliuJAC2yya0 CRmY4jmfyf9HiNNV6ey/RVj5RPPLE36doyVYQ30tOBHJ6iSO9L/rW/K9vJmDOANI9VBl WNIII+Tx6oosNBz6PX5iDJ/2c0tilJyfQTqMGPdjLpfTw+Bei2G1K8dsIvVbE9rXQtCc CWuMG6kwg16fLssNSMMBGTNDFYT+bc4JbksjtYuxozUfyd+YfCeZLhzkj1FNKdXagjOa 46Ez5EwMdEA+i7s31x5bNOZzXrW3EbMn8xNtBzNJdbF1a0ejkNW5qSfH3Bu36eD0CLw/ CYSg== X-Gm-Message-State: ACrzQf3XejoZzL4oF49GUr4ixAQZPiD9uMM/xSrmRz4FOSzIw5N2nc3w G2UxX7VMsSwcQ6GnjV65yQ== X-Google-Smtp-Source: AMsMyM7daWXjghU4BJEGxdJKD7rszzAz0+XrbF8n/FxFUIKac8PUSEcwk3rImT8JwBHpJCRZAkrBKQ== X-Received: by 2002:a05:6214:29e3:b0:4ad:5de4:accd with SMTP id jv3-20020a05621429e300b004ad5de4accdmr5377972qvb.60.1663909174781; Thu, 22 Sep 2022 21:59:34 -0700 (PDT) Received: from bytedance.attlocal.net (ec2-3-231-65-244.compute-1.amazonaws.com. [3.231.65.244]) by smtp.gmail.com with ESMTPSA id x17-20020a05620a449100b006b9264191b5sm5263168qkp.32.2022.09.22.21.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Sep 2022 21:59:34 -0700 (PDT) From: Peilin Ye To: Eric Dumazet , "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Paolo Abeni Cc: Peilin Ye , Cong Wang , Kuniyuki Iwashima , Alexei Starovoitov , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Peilin Ye Subject: [PATCH net-next RESEND 2/2] af_unix: Refactor unix_read_skb() Date: Thu, 22 Sep 2022 21:59:26 -0700 Message-Id: <7009141683ad6cd3785daced3e4a80ba0eb773b5.1663909008.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <343b5d8090a3eb764068e9f1d392939e2b423747.1663909008.git.peilin.ye@bytedance.com> References: <343b5d8090a3eb764068e9f1d392939e2b423747.1663909008.git.peilin.ye@bytedance.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Peilin Ye Similar to udp_read_skb(), delete the unnecessary while loop in unix_read_skb() for readability. Since recv_actor() cannot return a value greater than skb->len (see sk_psock_verdict_recv()), remove the redundant check. Suggested-by: Cong Wang Signed-off-by: Peilin Ye --- net/unix/af_unix.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c index dea2972c8178..c955c7253d4b 100644 --- a/net/unix/af_unix.c +++ b/net/unix/af_unix.c @@ -2536,32 +2536,18 @@ static int unix_dgram_recvmsg(struct socket *sock, struct msghdr *msg, size_t si static int unix_read_skb(struct sock *sk, skb_read_actor_t recv_actor) { - int copied = 0; - - while (1) { - struct unix_sock *u = unix_sk(sk); - struct sk_buff *skb; - int used, err; - - mutex_lock(&u->iolock); - skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err); - mutex_unlock(&u->iolock); - if (!skb) - return err; + struct unix_sock *u = unix_sk(sk); + struct sk_buff *skb; + int err, copied; - used = recv_actor(sk, skb); - if (used <= 0) { - if (!copied) - copied = used; - kfree_skb(skb); - break; - } else if (used <= skb->len) { - copied += used; - } + mutex_lock(&u->iolock); + skb = skb_recv_datagram(sk, MSG_DONTWAIT, &err); + mutex_unlock(&u->iolock); + if (!skb) + return err; - kfree_skb(skb); - break; - } + copied = recv_actor(sk, skb); + kfree_skb(skb); return copied; }