Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp1249729rwb; Wed, 26 Jul 2023 09:35:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlFNpjmOKcimSyzmZ84PuwRQ0G9hNHLw6v2/6x7URT9iuzkijBfcEUPFEWC1iexHPxfvnEUh X-Received: by 2002:a05:6a00:4a06:b0:682:5e8f:d8ba with SMTP id do6-20020a056a004a0600b006825e8fd8bamr18294pfb.11.1690389316886; Wed, 26 Jul 2023 09:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690389316; cv=none; d=google.com; s=arc-20160816; b=D5zinmYH0HkBdQ8huw4NpohQmvu6RfH+t2bY2Rcp+IqoVkwLxKziIRV781SWQI77iO kVTf0JAgAUO2NwFsrhRGV4HZaNJz+GUSztxF6g/RvpCplei28TyHdACOSKIpPC6hQE3N UYT+JO/mbskYIALSVzanZGJ7p7V25Aen4+HLrdVi33QdCAiyHH3CU1uX7VPM+HVHmeAF 4TUgGEUBK+AJvfDjMTERQYkiudCZ2DIFyKDB1NkndcY0Ao5y7Lburpd/u4S+qzao/j09 c8Xs6c4ZhIi6UKCF0IopPK8SvB4TSRwoP9R/CAsjXh4CXydHylRVlZZsrF9ctdJCff9a iecg== 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=kWApWdvVXHNiMFGGzJvmxw82QwhtiYRXTqYUjlHOECI=; fh=NzFlDLg/UqCULsBTxoJw7JnDEtQvO5wAq+tvkS36bwM=; b=JNj74eYT94YDIQxB5tqKxBvvew5gFeL2FmSukZRiKv3PyN4NnSf8EExdTs9zbvSI7E q6CxNd+f0NHbU8Cc/jSqxMZCu5R+ZZkASSm8V+2rLBjvPqp1xKmx76gqbwLRAoPrqsh0 qFvuImZW6bLQmrQz1QwINYazAldUSCT+35l8oQLzu6Il96z3pPTszC0aG0TpwgM5GPwu oJCEGR/Vo/yysmgek/9k4xljCPzfLD6wzev2WPXnlP4QTbZu86yWDO2nvY40o/1Kq9lO SXqmIY7sIMAFdblT4vGvzAvqNx3YJ0YhaNAPyObmF3U1vT6q7ZXMD/qE6AW0Ke6zRELe Ck1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=dMRzsTH8; 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 s21-20020a056a0008d500b006817ac73c65si13497209pfu.156.2023.07.26.09.35.04; Wed, 26 Jul 2023 09:35:16 -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=20221208 header.b=dMRzsTH8; 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 S233941AbjGZPy0 (ORCPT + 99 others); Wed, 26 Jul 2023 11:54:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230261AbjGZPyZ (ORCPT ); Wed, 26 Jul 2023 11:54:25 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9656B100; Wed, 26 Jul 2023 08:54:24 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id 98e67ed59e1d1-26824c32cfbso795147a91.1; Wed, 26 Jul 2023 08:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690386864; x=1690991664; 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=kWApWdvVXHNiMFGGzJvmxw82QwhtiYRXTqYUjlHOECI=; b=dMRzsTH8qjyHfSTdW1IMt5u9fvauGMxWUVkXC+Kz4vCaIh32zzfJgAueG7ExSe8rP/ sGhcyp/X5nT5aYHXOQHUARE33rRFM+vR5wS6RYRD6/6zTfr1eJe37auAIvreLclqpDdK 9n+HqN3r4gdBoDZn5cuUmYReOjRLUvEV40MC8J2UkE30tDE1Z4CvysAIPncTy4N4XyVf HYfFRwE7mcVda2crEBbW4W9CByANlB8GU1gjsstr4LH2RfDXwlRryx6wMz7XacAMyOwL LNCzVvQ3I/sQiZZj7+nyxLIt46s/NS1gR0fDrqdkTPcvcie9sWEjyfTsMLRwFIsMzPU6 8+HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690386864; x=1690991664; 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=kWApWdvVXHNiMFGGzJvmxw82QwhtiYRXTqYUjlHOECI=; b=QxpMUZmexyaOSb980FRENJZduXLRJH4Auypb97wo+Z2QHfkEqguKJDAyW3q/qzCa++ lFjCLwIJhqH2MVdrWlEFVQmtUD7cV2vPY0zqWdfS8MWAK/X4G1+KiZlsB/uHvFEOnqXy O+oVmiqO5Fnq7l2whoYctfy3AVs4aYR+ukgoOh6WW4Aq7N3o/olS6LPCZx8K+ACjp2fH fYkShyKO1kONY1IhiavhRLi5OxNlXWEjW+9qeeUjU1BdJNzyrs0Q6xcMqCDjZ/OTSZ21 PtDo+Qg7/QWEko3uYqAqSAY7naGZaOZ/CNG8U1LOLZTvCehtEzklmHDmDv6igMDPD8Td mKwQ== X-Gm-Message-State: ABy/qLb+Rz1CFJeru0K2zqa6Vp4v+o7ww3aecffG1cskNHUb+8vCV3Pf h1VmmkCzvDEAOBV5KHvTqtsApP66kH6AgIfQJ9aFH/2a X-Received: by 2002:a17:90a:fd85:b0:268:42da:25e1 with SMTP id cx5-20020a17090afd8500b0026842da25e1mr3102133pjb.8.1690386863941; Wed, 26 Jul 2023 08:54:23 -0700 (PDT) MIME-Version: 1.0 References: <20230725074148.2936402-1-wei.fang@nxp.com> <70b71e7bb8a7dff2dacab99b0746e7bf2bee9344.camel@gmail.com> In-Reply-To: From: Alexander Duyck Date: Wed, 26 Jul 2023 08:53:47 -0700 Message-ID: Subject: Re: [PATCH net] net: fec: tx processing does not call XDP APIs if budget is 0 To: Wei Fang Cc: dl-linux-imx , "linux-kernel@vger.kernel.org" , "davem@davemloft.net" , "edumazet@google.com" , "kuba@kernel.org" , Shenwei Wang , Clark Wang , "pabeni@redhat.com" , "netdev@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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_BLOCKED,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 On Tue, Jul 25, 2023 at 8:40=E2=80=AFPM Wei Fang wrote: > > Hi Alexander, > > > > @@ -1416,6 +1416,14 @@ fec_enet_tx_queue(struct net_device *ndev, > > u16 queue_id) > > > if (!skb) > > > goto tx_buf_done; > > > } else { > > > + /* Tx processing cannot call any XDP (or page poo= l) APIs if > > > + * the "budget" is 0. Because NAPI is called with= budget of > > > + * 0 (such as netpoll) indicates we may be in an = IRQ context, > > > + * however, we can't use the page pool from IRQ c= ontext. > > > + */ > > > + if (unlikely(!budget)) > > > + break; > > > + > > > xdpf =3D txq->tx_buf[index].xdp; > > > if (bdp->cbd_bufaddr) > > > dma_unmap_single(&fep->pdev->dev, > > > > This statement isn't correct. There are napi enabled and non-napi > > versions of these calls. This is the reason for things like the > > "allow_direct" parameter in page_pool_put_full_page and the > > "napi_direct" parameter in __xdp_return. > > > > By blocking on these cases you can end up hanging the Tx queue which is > > going to break netpoll as you are going to stall the ring on XDP > > packets if they are already in the queue. > > > > From what I can tell your driver is using xdp_return_frame in the case > > of an XDP frame which doesn't make use of the NAPI optimizations in > > freeing from what I can tell. The NAPI optimized version is > > xdp_return_frame_rx. > > > So you mean it is safe to use xdp_return_frame no matter in NAPI context > or non-NAPI context? And xdp_return_frame_rx_napi must be used in NAPI > context? If so, I think I must have misunderstood, then this patch is not= necessary. Actually after talking with Jakub a bit more there is an issue here, but not freeing the frames isn't the solution. We likely need to just fix the page pool code so that it doesn't attempt to recycle the frames if operating in IRQ context. The way this is dealt with for skbs is that we queue skbs if we are in IRQ context so that it can be deferred to be freed by the net_tx_action. We likely need to look at doing something similar for page_pool pages or XDP frames. > > > @@ -1508,14 +1516,14 @@ fec_enet_tx_queue(struct net_device *ndev, > > u16 queue_id) > > > writel(0, txq->bd.reg_desc_active); > > > } > > > > > > -static void fec_enet_tx(struct net_device *ndev) > > > +static void fec_enet_tx(struct net_device *ndev, int budget) > > > { > > > struct fec_enet_private *fep =3D netdev_priv(ndev); > > > int i; > > > > > > /* Make sure that AVB queues are processed first. */ > > > for (i =3D fep->num_tx_queues - 1; i >=3D 0; i--) > > > - fec_enet_tx_queue(ndev, i); > > > + fec_enet_tx_queue(ndev, i, budget); > > > } > > > > > > static void fec_enet_update_cbd(struct fec_enet_priv_rx_q *rxq, > > > @@ -1858,7 +1866,7 @@ static int fec_enet_rx_napi(struct napi_struct > > *napi, int budget) > > > > > > do { > > > done +=3D fec_enet_rx(ndev, budget - done); > > > - fec_enet_tx(ndev); > > > + fec_enet_tx(ndev, budget); > > > } while ((done < budget) && fec_enet_collect_events(fep)); > > > > > > if (done < budget) { > > > > Since you are passing budget, one optimization you could make use of > > would be napi_consume_skb in your Tx path instead of dev_kfree_skb_any. > That's good suggestion, I think I can add this optimization in my XDP_TX = support > patch. Thanks!