Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6161493rdb; Mon, 18 Sep 2023 06:08:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+6gO2hnVktv9E/o1KqGCb4RKqqGcztP5Q7qT8xBkAhxFZ6KQWOW/GReNHcv1YXxXISP9d X-Received: by 2002:a05:6a20:7faa:b0:140:324c:124c with SMTP id d42-20020a056a207faa00b00140324c124cmr8413485pzj.62.1695042486858; Mon, 18 Sep 2023 06:08:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695042486; cv=none; d=google.com; s=arc-20160816; b=N4FaxLsLbJsTWVJKLL/IJS1c4JUzVcndWSDZAQO3tMJwtN0wLxCwk028QRlC/8nqMT B0mXXtHadU+/90lUU7pxMjXUl9Hso4eE+yqHhsQFgV0bgt1PYZ9q0YXW5n/xs1jzr+tc dej5d5pW9hB20xR/VdLw/OZ3ofSnTvwogqAv7GbMdNzGBS9mIOgs4/9Qu/fnyOifovpc XETjKUus62TRHw58ImVmokghAQnnuCtAikZdYA1/6A7nIqi/oH9Y7tXXXLDrDpNu+5tf FvZh0GTvZT4VDMMYIi1lDnyEW+R7KwrRqEdiBikdj3z5VJtZRWvK6LxWvTOIX6bJRKlV H8yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JMGyAzpf8lWJYYzHbLt9+b5ipto9IJqdYCL10HebZHQ=; fh=a6e7EelKLeyTrSgW+dLvb4GCe03/psbdI4fBon68z08=; b=QDPzYF5kHupJNYLNBgy7Px4qsxcdQuO3eZwV609q1VNJUdpDBxNF14ruX1OYv3Kx+q JTNNUCLVPrUNyuaDOAj1YLddG4mcVViihcBsHCRU+S4ssRFjtJpUxDEqwvGIR0wxNp6g iYYqEgTvtxgnTWco4oy1ZnVbdMbPtZ7Tdx7Ad73dXvadsMQ4MLlar1I0T7UTxPUTqixF +/0Yv3XzlUdWTuHjNGJM+mGAML0JFPmsMf/4zl8uKiu4PQxwdDXpkBUAqhD71KGi17M7 Y5kfe801ra6dRJpRSCHaYgOARD824gR4SbeT+rJ+8KNpnQ+Kot9cic579axibC41l7jC T1iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=g4ieQu7J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id br15-20020a056a00440f00b0068e3baee27esi8001088pfb.266.2023.09.18.06.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 06:08:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=g4ieQu7J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 5F8BF8070790; Mon, 18 Sep 2023 00:58:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235889AbjIRH5q (ORCPT + 99 others); Mon, 18 Sep 2023 03:57:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240624AbjIRH5c (ORCPT ); Mon, 18 Sep 2023 03:57:32 -0400 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A376C3A8E for ; Mon, 18 Sep 2023 00:54:48 -0700 (PDT) Received: by mail-qt1-x82e.google.com with SMTP id d75a77b69052e-41513d2cca7so417641cf.0 for ; Mon, 18 Sep 2023 00:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695023687; x=1695628487; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JMGyAzpf8lWJYYzHbLt9+b5ipto9IJqdYCL10HebZHQ=; b=g4ieQu7J41A4zlrCCV76NG7lEtF2KIDdobCcY2Oo1SMuKtw2zO0PhlBb1cFjLRpptZ xXH6eGJgnPHdZxYfwZC1ZSRp9MrHWL9ZgR+UHEIq7uxtxoo3CMVq+N2hSWSL7GAfREro 9TipP18D36WdQ1Jpj3f644Kvil1Qa//DpFTGVTXgssMHC9pxKKUVruK1YuZyQUuvCwKK 1CfVqeRd5w75JwuqoiyqGsOUyms+w0Raipw/JNv/wTVQh6I1Pq9GQGecZx1qn24fJnUD AGGMq+cK/Fil4/CsECbqR1SvMiyfG1nEWJ8328IrJws5Fu2NvvB7gH43KSwNuiZAlU0D uZxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695023687; x=1695628487; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JMGyAzpf8lWJYYzHbLt9+b5ipto9IJqdYCL10HebZHQ=; b=OH+MV2SClUxzkczKdOsugb3bUZI2znO88mQEWKiC0yvJTCMtdf9KqlhrPlRWZJNfEw f0Ou/3+zJgHxHKBuBPE6aBSfimH9gxnjG6s5ahCIlNJtpFeD5dX55F0xXlwRLSmBUWQ1 duKEpb4kQeLQzYPN9XbeAlJ4/pfWNEQLfCCpUDQsxf0nrcS6BOtKKGkAqd35GDE3qNSt Z2JrabpySmXTLIJAXeP9JVPY4uTMW3ZimVh1SQNFWALo6pY3K2XnkbG3LNxj+Sp9c3Z/ M4glcPNuyrKP8yPjO9WHVz6ySO+BRuB5ikviDR6XeeqZMDkLyoIuP4lWWnN9p91/HQm6 ymlQ== X-Gm-Message-State: AOJu0YzFMrc2B5o4+r4oXL2zSRa5lAlD+QqLjA6tGYw+BabH+VQJbn0B F+mEI9wltr8lF11hNY6jDPLZXYBY4F6hFgUMXp40j9tke+JtyRpmaaA= X-Received: by 2002:a05:622a:1446:b0:410:8ba3:21c7 with SMTP id v6-20020a05622a144600b004108ba321c7mr410408qtx.18.1695023687484; Mon, 18 Sep 2023 00:54:47 -0700 (PDT) MIME-Version: 1.0 References: <20230918074202.2461-426-nic_swsd@realtek.com> <20230918074202.2461-427-nic_swsd@realtek.com> In-Reply-To: <20230918074202.2461-427-nic_swsd@realtek.com> From: Eric Dumazet Date: Mon, 18 Sep 2023 09:54:36 +0200 Message-ID: Subject: Re: [PATCH net-next resend 1/2] r8152: remove queuing rx packets in driver To: Hayes Wang Cc: kuba@kernel.org, davem@davemloft.net, netdev@vger.kernel.org, nic_swsd@realtek.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, bjorn@mork.no, pabeni@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Mon, 18 Sep 2023 00:58:26 -0700 (PDT) On Mon, Sep 18, 2023 at 9:42=E2=80=AFAM Hayes Wang = wrote: > > The original way would process all rx and queue the rx packets in the > driver. Now, the process would be broken if the budget is exhausted. And > the remained list would be queue back to rx_done for next schedule. > > Signed-off-by: Hayes Wang This deserves a Fixes: tag > --- > drivers/net/usb/r8152.c | 52 ++++++++++++----------------------------- > 1 file changed, 15 insertions(+), 37 deletions(-) > > diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c > index 0c13d9950cd8..ae46e7e46e39 100644 > --- a/drivers/net/usb/r8152.c > +++ b/drivers/net/usb/r8152.c > @@ -871,7 +871,7 @@ struct r8152 { > struct tx_agg tx_info[RTL8152_MAX_TX]; > struct list_head rx_info, rx_used; > struct list_head rx_done, tx_free; > - struct sk_buff_head tx_queue, rx_queue; > + struct sk_buff_head tx_queue; > spinlock_t rx_lock, tx_lock; > struct delayed_work schedule, hw_phy_work; > struct mii_if_info mii; > @@ -2031,7 +2031,6 @@ static int alloc_all_mem(struct r8152 *tp) > INIT_LIST_HEAD(&tp->tx_free); > INIT_LIST_HEAD(&tp->rx_done); > skb_queue_head_init(&tp->tx_queue); > - skb_queue_head_init(&tp->rx_queue); > atomic_set(&tp->rx_count, 0); > > for (i =3D 0; i < RTL8152_MAX_RX; i++) { > @@ -2431,24 +2430,6 @@ static int rx_bottom(struct r8152 *tp, int budget) > int ret =3D 0, work_done =3D 0; > struct napi_struct *napi =3D &tp->napi; > > - if (!skb_queue_empty(&tp->rx_queue)) { > - while (work_done < budget) { > - struct sk_buff *skb =3D __skb_dequeue(&tp->rx_que= ue); > - struct net_device *netdev =3D tp->netdev; > - struct net_device_stats *stats =3D &netdev->stats= ; > - unsigned int pkt_len; > - > - if (!skb) > - break; > - > - pkt_len =3D skb->len; > - napi_gro_receive(napi, skb); > - work_done++; > - stats->rx_packets++; > - stats->rx_bytes +=3D pkt_len; > - } > - } > - > if (list_empty(&tp->rx_done)) > goto out1; > > @@ -2484,10 +2465,6 @@ static int rx_bottom(struct r8152 *tp, int budget) > unsigned int pkt_len, rx_frag_head_sz; > struct sk_buff *skb; > > - /* limit the skb numbers for rx_queue */ > - if (unlikely(skb_queue_len(&tp->rx_queue) >=3D 10= 00)) > - break; > - > pkt_len =3D le32_to_cpu(rx_desc->opts1) & RX_LEN_= MASK; > if (pkt_len < ETH_ZLEN) > break; > @@ -2525,14 +2502,10 @@ static int rx_bottom(struct r8152 *tp, int budget= ) > > skb->protocol =3D eth_type_trans(skb, netdev); > rtl_rx_vlan_tag(rx_desc, skb); > - if (work_done < budget) { > - work_done++; > - stats->rx_packets++; > - stats->rx_bytes +=3D skb->len; > - napi_gro_receive(napi, skb); > - } else { > - __skb_queue_tail(&tp->rx_queue, skb); > - } > + work_done++; > + stats->rx_packets++; > + stats->rx_bytes +=3D skb->len; > + napi_gro_receive(napi, skb); > > find_next_rx: > rx_data =3D rx_agg_align(rx_data + pkt_len + ETH_= FCS_LEN); > @@ -2562,16 +2535,24 @@ static int rx_bottom(struct r8152 *tp, int budget= ) > urb->actual_length =3D 0; > list_add_tail(&agg->list, next); > } > + > + /* Break if budget is exhausted. */ [1] More conventional way to to put this condition at the beginning of the while () loop, because the budget could be zero. > + if (work_done >=3D budget) > + break; > } > > + /* Splice the remained list back to rx_done */ > if (!list_empty(&rx_queue)) { > spin_lock_irqsave(&tp->rx_lock, flags); > - list_splice_tail(&rx_queue, &tp->rx_done); > + list_splice(&rx_queue, &tp->rx_done); > spin_unlock_irqrestore(&tp->rx_lock, flags); > } > > out1: > - return work_done; > + if (work_done > budget) This (work_done >budget) condition would never be true if point [1] is addressed. > + return budget; > + else > + return work_done; > } > > static void tx_bottom(struct r8152 *tp) > @@ -2992,9 +2973,6 @@ static int rtl_stop_rx(struct r8152 *tp) > list_splice(&tmp_list, &tp->rx_info); > spin_unlock_irqrestore(&tp->rx_lock, flags); > > - while (!skb_queue_empty(&tp->rx_queue)) > - dev_kfree_skb(__skb_dequeue(&tp->rx_queue)); > - > return 0; > } > > -- > 2.41.0 >