Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp1039439rwi; Mon, 31 Oct 2022 10:25:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4i5ToH+R5bjd4JiYBOD2AJQNRfmulGaFUyVSO/2naVdymZ4EjRTRHTRESTi7INg2GDW8Ew X-Received: by 2002:a05:6402:1710:b0:463:69ac:a679 with SMTP id y16-20020a056402171000b0046369aca679mr5072608edu.184.1667237127049; Mon, 31 Oct 2022 10:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667237127; cv=none; d=google.com; s=arc-20160816; b=I5UHOfoiaXGQbSMrddGzUj7rqhIUzEghetqMZJP9f7T15F3A0hsVAVXOUoIXeRIApt tU3rYFzyVYI2qxtNf06jbSoN5VNoKBNb6+71+4QCjpPxwL1qeuyWZ27iof8Aps+yPWEB +XThBkG8CHIv4OFoL3GAE1neQN3NOZKP6z3BT/RbkQMkpem5kGvVvrEtW0wNWGiI7GAU GTP1/L2in3rPlTTHxTO+NvNJa3VqFF2THAeUxeTOnY9nZ/1oWfDZfwumf3O9cO8u4OBa OcAFgM5eyigAcnQiBPao54aFIwVwmAQuAVdZMjIdsXS2zZ6Vzfe1OY3spQY8QSRNggSi IYJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6vzHxEAPqVfIR65YIpx9t4I4izpmXEj2rkIyxRK348E=; b=jwkb2Ip8qqWjxD3D9opu8cIcJpt/cewSa2CBzEbv+nPbOD16+IXJX/3KQ+BH45tAwS Pk9g01GsnoUCCvceBzcnn/Jd9FRDHqanSPOr/veYGmLa8Z4Y8I3D1OaYiVk/9YpsfgJj hu82p4QtmnT9YM/jcn0cn5Lyc/qI3p0Dp+ibgs9QIeMZRSUdvFvOR2vOnZU6UIVYVaph 0PYR8ctSBQDAU0Ei0V33bsYbTWwGi77WgYnY+DXPmos4XlNwvrOARgMmZBr9QEout7Lu 4UFNccMywp8FCFz9SNtfdGhOCayrjR0GzPd/BoFrqdXGyW2jzckC+K2kzBvALbsUpXF9 Fi1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=3dHLv00P; 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=NONE dis=NONE) header.from=lunn.ch Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg2-20020a1709072cc200b007adc8d6b77esi6337668ejc.308.2022.10.31.10.25.01; Mon, 31 Oct 2022 10:25:27 -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=@lunn.ch header.s=20171124 header.b=3dHLv00P; 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=NONE dis=NONE) header.from=lunn.ch Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232017AbiJaRKy (ORCPT + 99 others); Mon, 31 Oct 2022 13:10:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbiJaRKw (ORCPT ); Mon, 31 Oct 2022 13:10:52 -0400 Received: from vps0.lunn.ch (vps0.lunn.ch [156.67.10.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B6CD12D28; Mon, 31 Oct 2022 10:10:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=6vzHxEAPqVfIR65YIpx9t4I4izpmXEj2rkIyxRK348E=; b=3dHLv00PYewsTy8LuMrCq/Bk6/ Erh0z8QowWmrxBI7wEcl+Hh5gljmTEw0el8eqthgQS3irtAAFOqwG+ehcaldnWBiRLhvMEU/jQM+d 2sREW0EMdntpV7QWs1rfFPG70A3rBg2XIw4AbiPwDYcI/4F0g6d4R1g3sTdFYMEIP7FI=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1opYIZ-0012Yw-Ce; Mon, 31 Oct 2022 18:10:07 +0100 Date: Mon, 31 Oct 2022 18:10:07 +0100 From: Andrew Lunn To: Shenwei Wang Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, kernel test robot Subject: Re: [PATCH v2 1/1] net: fec: add initial XDP support Message-ID: References: <20221031162200.1997788-1-shenwei.wang@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221031162200.1997788-1-shenwei.wang@nxp.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS 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 > +static int fec_enet_bpf(struct net_device *dev, struct netdev_bpf *bpf) > +{ > + struct fec_enet_private *fep = netdev_priv(dev); > + bool is_run = netif_running(dev); > + struct bpf_prog *old_prog; > + unsigned int dsize; > + int i; > + > + switch (bpf->command) { > + case XDP_SETUP_PROG: > + if (is_run) { > + napi_disable(&fep->napi); > + netif_tx_disable(dev); > + } > + > + old_prog = xchg(&fep->xdp_prog, bpf->prog); > + > + /* Update RX ring size */ > + dsize = fep->bufdesc_ex ? sizeof(struct bufdesc_ex) : > + sizeof(struct bufdesc); > + for (i = 0; i < fep->num_rx_queues; i++) { > + struct fec_enet_priv_rx_q *rxq = fep->rx_queue[i]; > + struct bufdesc *cbd_base; > + unsigned int size; > + > + cbd_base = rxq->bd.base; > + if (bpf->prog) > + rxq->bd.ring_size = XDP_RX_RING_SIZE; > + else > + rxq->bd.ring_size = RX_RING_SIZE; > + size = dsize * rxq->bd.ring_size; > + cbd_base = (struct bufdesc *)(((void *)cbd_base) + size); > + rxq->bd.last = (struct bufdesc *)(((void *)cbd_base) - dsize); This does not look safe. netif_tx_disable(dev) will stop new transmissions, but the hardware can be busy receiving, DMAing frames, using the descriptors, etc. Modifying rxq->bd.last in particular seems risky. I think you need to disable the receiver, wait for it to indicate it really has stopped, and only then make these modifications. Andrew