From: Lorenzo Bianconi <lorenzo.bianconi@redhat.com>
To: Shay Agroskin <shayagr@amazon.com>
Cc: Lorenzo Bianconi <lorenzo@kernel.org>,
bpf@vger.kernel.org, netdev@vger.kernel.org, davem@davemloft.net,
kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net,
brouer@redhat.com, toke@redhat.com, freysteinn.alfredsson@kau.se,
john.fastabend@gmail.com, jasowang@redhat.com, mst@redhat.com,
thomas.petazzoni@bootlin.com, mw@semihalf.com,
linux@armlinux.org.uk, ilias.apalodimas@linaro.org,
netanel@amazon.com, akiyano@amazon.com,
michael.chan@broadcom.com, madalin.bucur@nxp.com,
ioana.ciornei@nxp.com, jesse.brandeburg@intel.com,
anthony.l.nguyen@intel.com, saeedm@nvidia.com,
grygorii.strashko@ti.com, ecree.xilinx@gmail.com
Subject: Re: [PATCH v2 bpf-next] bpf: devmap: move drop error path to devmap for XDP_REDIRECT
Date: Sun, 28 Feb 2021 23:27:25 +0100 [thread overview]
Message-ID: <YDwYzYVIDQABINyy@lore-laptop-rh> (raw)
In-Reply-To: <pj41zly2f8wfq6.fsf@u68c7b5b1d2d758.ant.amazon.com>
[-- Attachment #1: Type: text/plain, Size: 3358 bytes --]
>
> Lorenzo Bianconi <lorenzo@kernel.org> writes:
>
> > ...
> > diff --git a/drivers/net/ethernet/amazon/ena/ena_netdev.c
> > b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> > index 102f2c91fdb8..7ad0557dedbd 100644
> > --- a/drivers/net/ethernet/amazon/ena/ena_netdev.c
> > +++ b/drivers/net/ethernet/amazon/ena/ena_netdev.c
> > ...
> >
> > @@ -339,8 +337,8 @@ static int ena_xdp_xmit(struct net_device *dev, int
> > n,
> > struct xdp_frame **frames, u32 flags)
> > {
> > struct ena_adapter *adapter = netdev_priv(dev);
> > - int qid, i, err, drops = 0;
> > struct ena_ring *xdp_ring;
> > + int qid, i, nxmit = 0;
> > if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
> > return -EINVAL;
> > @@ -360,12 +358,12 @@ static int ena_xdp_xmit(struct net_device *dev,
> > int n,
> > spin_lock(&xdp_ring->xdp_tx_lock);
> > for (i = 0; i < n; i++) {
> > - err = ena_xdp_xmit_frame(xdp_ring, dev, frames[i], 0);
> > /* The descriptor is freed by ena_xdp_xmit_frame in case
> > * of an error.
> > */
>
> Thanks a lot for the patch. It's a good idea. Do you mind removing the
> comment here as well ? ena_xdp_xmit_frame() no longer frees the frame in
> case of an error after this patch.
ack, will do in v3
>
> > - if (err)
> > - drops++;
> > + if (ena_xdp_xmit_frame(xdp_ring, dev, frames[i], 0))
> > + break;
> > + nxmit++;
> > }
> > /* Ring doorbell to make device aware of the packets */
> > @@ -378,7 +376,7 @@ static int ena_xdp_xmit(struct net_device *dev, int
> > n,
> > spin_unlock(&xdp_ring->xdp_tx_lock);
> > /* Return number of packets sent */
> > - return n - drops;
> > + return nxmit;
> > }
> > ...
> > diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
> > index 85d9d1b72a33..9f158b3862df 100644
> > --- a/kernel/bpf/devmap.c
> > +++ b/kernel/bpf/devmap.c
> > @@ -344,29 +344,26 @@ static void bq_xmit_all(struct xdp_dev_bulk_queue
> > *bq, u32 flags)
> > sent = dev->netdev_ops->ndo_xdp_xmit(dev, bq->count, bq->q, flags);
> > if (sent < 0) {
> > + /* If ndo_xdp_xmit fails with an errno, no frames have
> > + * been xmit'ed.
> > + */
> > err = sent;
> > sent = 0;
> > - goto error;
> > }
> > +
> > drops = bq->count - sent;
> > -out:
> > - bq->count = 0;
> > + if (unlikely(drops > 0)) {
> > + /* If not all frames have been transmitted, it is our
> > + * responsibility to free them
> > + */
> > + for (i = sent; i < bq->count; i++)
> > + xdp_return_frame_rx_napi(bq->q[i]);
> > + }
>
> Wouldn't the logic above be the same even w/o the 'if' condition ?
it is just an optimization to avoid the for loop instruction if sent = bq->count
Regards,
Lorenzo
>
> > + bq->count = 0;
> > trace_xdp_devmap_xmit(bq->dev_rx, dev, sent, drops, err);
> > bq->dev_rx = NULL;
> > __list_del_clearprev(&bq->flush_node);
> > - return;
> > -error:
> > - /* If ndo_xdp_xmit fails with an errno, no frames have been
> > - * xmit'ed and it's our responsibility to them free all.
> > - */
> > - for (i = 0; i < bq->count; i++) {
> > - struct xdp_frame *xdpf = bq->q[i];
> > -
> > - xdp_return_frame_rx_napi(xdpf);
> > - drops++;
> > - }
> > - goto out;
> > }
> > /* __dev_flush is called from xdp_do_flush() which _must_ be
> > signaled
>
> Thanks, Shay
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2021-02-28 22:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-27 11:04 [PATCH v2 bpf-next] bpf: devmap: move drop error path to devmap for XDP_REDIRECT Lorenzo Bianconi
2021-02-28 12:15 ` Shay Agroskin
2021-02-28 22:27 ` Lorenzo Bianconi [this message]
2021-03-01 7:48 ` Jesper Dangaard Brouer
2021-03-01 11:23 ` Shay Agroskin
2021-03-01 20:18 ` Jesper Dangaard Brouer
2021-03-02 15:28 ` Lorenzo Bianconi
2021-03-03 11:29 ` Shay Agroskin
2021-03-01 11:59 ` Ioana Ciornei
2021-03-01 12:26 ` Ilias Apalodimas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YDwYzYVIDQABINyy@lore-laptop-rh \
--to=lorenzo.bianconi@redhat.com \
--cc=akiyano@amazon.com \
--cc=anthony.l.nguyen@intel.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=ecree.xilinx@gmail.com \
--cc=freysteinn.alfredsson@kau.se \
--cc=grygorii.strashko@ti.com \
--cc=ilias.apalodimas@linaro.org \
--cc=ioana.ciornei@nxp.com \
--cc=jasowang@redhat.com \
--cc=jesse.brandeburg@intel.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=lorenzo@kernel.org \
--cc=madalin.bucur@nxp.com \
--cc=michael.chan@broadcom.com \
--cc=mst@redhat.com \
--cc=mw@semihalf.com \
--cc=netanel@amazon.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.com \
--cc=shayagr@amazon.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=toke@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox