Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7617150rwn; Wed, 14 Sep 2022 01:22:46 -0700 (PDT) X-Google-Smtp-Source: AA6agR5Cq3PsQjAJRCoxRWipX/Y4jWMbg3ZaOzBuSrPCcZJzpuC7RgMSSaEHwr5ImQdUKJzPO9d0 X-Received: by 2002:aa7:c556:0:b0:44e:9c95:a9a4 with SMTP id s22-20020aa7c556000000b0044e9c95a9a4mr29396747edr.301.1663143766444; Wed, 14 Sep 2022 01:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663143766; cv=none; d=google.com; s=arc-20160816; b=Qs3eOPve5nSw20yGHmBpoCYUcvB6yZzcQVrWhjQ0137YETNFaHA1ULs0iSVAntv4gm JfTEec4vOkUNDzDyTEyc4U1kvXx7GLEpxpr9r9MB5gnhWnrasgi8cba3pOhY+N6V2f1z HWPf37jmQnOwsNJckzcjR5z8XRk56uV+DeBr0dBge6birGBBSNT/iWPt0hGilfMzBF9I /+HflwFIe1VtZorSGMeqza6vyiZXAR71QtZkWPyopCZy/uwOkrN3DDh7AvesN1Jtnh3e zElffBgpPxMyO87j+SU/wMkeZLbGEIR8nLRsP0m+mUFSGrMr5xtXOMiTB1wxBzGEwwkf VoVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+wbG6fgMQYUO57P7KRa54jq5kT0uHMNGp+ISOp5Std4=; b=Gp//7RQHUm+NHqpOPEByB6JRjIdDQrD2JizBojG3kUrTmLCMmw3/VPT9HdThYgcfi0 kuJU1oLiscH9XvCM/WEiM31IQM1qhyrAH5bpl1FYp69tgnGomMKPmpm+op+F60BXW+6y l3IrJMWq+hHhhuPGxPA4HLn60nvRMnUQYwOyd3H8BiztULH+qPw/o4iUZNwILEyyqicX U0CJ56RuKrr+cdmKZvSZSqnNxMNrx76gKpOp/nhKH8+q9IeTs4a0gDNMSK4aTXqqhLRM 0pr2jt+LqbhP9PQIuSfU1Tee60y9I9FKaupXsSYj3TMEf8BzY4eTrxRkTX2Jtqmqqscd 7LXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="BVdW/9lv"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a170906784c00b00741a0720a2dsi1725520ejm.776.2022.09.14.01.22.21; Wed, 14 Sep 2022 01:22:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="BVdW/9lv"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230124AbiINIP7 (ORCPT + 99 others); Wed, 14 Sep 2022 04:15:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230250AbiINIPj (ORCPT ); Wed, 14 Sep 2022 04:15:39 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9D6D422E9; Wed, 14 Sep 2022 01:15:38 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id 3so9893496qka.5; Wed, 14 Sep 2022 01:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=+wbG6fgMQYUO57P7KRa54jq5kT0uHMNGp+ISOp5Std4=; b=BVdW/9lvb4MCtpvq2YiPmv3poClN+V/2D1tsWD0FOgTQf33mx3xSsfh+lrefRHXfgY 6ynJesxowPfHFkXWEnaF4obCfX6oa24cAKlw89geXK9vj/7+Etrq2RvXVJ6EwQF2Pv5P kH3tZ/r0qDSMgN2tU32xCoylwQ2y3rl4fe+w+87xxMR1CDRdN8/2b8swrtvmjWIiB2t/ 1b/BbNxCiD4nnBZygOstkCRifYVDSWgjgyMljUjBbXTGFM69q/eoN0TxZEecrbyLrwSE 7Quagg2MHpCS6RAHNqpaM00uBbAQqLxi+gTGl6LZjcpHRdhXVMK8k4B3s6SKJhgfnpqD ygWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=+wbG6fgMQYUO57P7KRa54jq5kT0uHMNGp+ISOp5Std4=; b=vrbh48nZfOxkRePA5/DZUqG39F4ubj+SsMZQPLQyLigFQHNia7bL4OYa+ruTc5Dgxj W6dqNJ6Npi6yYT6Wt7b+VlCkfD+xpSp8D6mgd0POkjscOJagLitXBpjFE86Twg+pe1hj 39flg9JteBkPx5D60CCY7TpOqGjSnn1ooRnOpx0Smxaoej8wZLykpcm+UGfAzm7Ak79P jdO9nPydcjoiFan7De7PGPcW/xnIfxtsfacpDg3xVDcAdOYTY3vJZ7CImV5FgbC6r7k/ jkLGZSvv39Z48q9+xwHjf7HtO6IYHH5lehBZrYs313ubjvMOrgrsXgKd8kprN74IcK3/ 3kPw== X-Gm-Message-State: ACgBeo0fzaCcEF1we1SeBCJs04bJZ21H64ngYqaEWTCabjTZkzfWc25a HcEbSbC7Crtk2JEDrEMAaA== X-Received: by 2002:a05:620a:284c:b0:6b8:6e70:cd95 with SMTP id h12-20020a05620a284c00b006b86e70cd95mr25052613qkp.247.1663143337943; Wed, 14 Sep 2022 01:15:37 -0700 (PDT) Received: from bytedance.attlocal.net (ec2-52-52-7-82.us-west-1.compute.amazonaws.com. [52.52.7.82]) by smtp.gmail.com with ESMTPSA id g26-20020ac842da000000b0035bb4805309sm1191561qtm.42.2022.09.14.01.15.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Sep 2022 01:15:36 -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 1/2] udp: Refactor udp_read_skb() Date: Wed, 14 Sep 2022 01:15:30 -0700 Message-Id: <03db9765fe1ef0f61bfc87fc68b5a95b4126aa4e.1663143016.git.peilin.ye@bytedance.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.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 --- Depends on: "[PATCH net v2] net: Use WARN_ON_ONCE() in {tcp,udp}_read_skb()" https://lore.kernel.org/all/20220913184016.16095-1-yepeilin.cs@gmail.com/ Thanks, 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); -- 2.20.1