From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Heng Qi <hengqi@linux.alibaba.com>, netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Subject: Re: [PATCH net] veth: Avoid drop packets when xdp_redirect performs
Date: Tue, 27 Sep 2022 14:20:25 +0200 [thread overview]
Message-ID: <87wn9proty.fsf@toke.dk> (raw)
In-Reply-To: <1664267413-75518-1-git-send-email-hengqi@linux.alibaba.com>
Heng Qi <hengqi@linux.alibaba.com> writes:
> In the current processing logic, when xdp_redirect occurs, it transmits
> the xdp frame based on napi.
>
> If napi of the peer veth is not ready, the veth will drop the packets.
> This doesn't meet our expectations.
Erm, why don't you just enable NAPI? Loading an XDP program is not
needed these days, you can just enable GRO on both peers...
> In this context, if napi is not ready, we convert the xdp frame to a skb,
> and then use veth_xmit() to deliver it to the peer veth.
>
> Like the following case:
> Even if veth1's napi cannot be used, the packet redirected from the NIC
> will be transmitted to veth1 successfully:
>
> NIC -> veth0----veth1
> | |
> (XDP) (no XDP)
>
> Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> ---
> drivers/net/veth.c | 36 +++++++++++++++++++++++++++++++++++-
> 1 file changed, 35 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/veth.c b/drivers/net/veth.c
> index 466da01..e1f5561 100644
> --- a/drivers/net/veth.c
> +++ b/drivers/net/veth.c
> @@ -469,8 +469,42 @@ static int veth_xdp_xmit(struct net_device *dev, int n,
> /* The napi pointer is set if NAPI is enabled, which ensures that
> * xdp_ring is initialized on receive side and the peer device is up.
> */
> - if (!rcu_access_pointer(rq->napi))
> + if (!rcu_access_pointer(rq->napi)) {
> + for (i = 0; i < n; i++) {
> + struct xdp_frame *xdpf = frames[i];
> + struct netdev_queue *txq = NULL;
> + struct sk_buff *skb;
> + int queue_mapping;
> + u16 mac_len;
> +
> + skb = xdp_build_skb_from_frame(xdpf, dev);
> + if (unlikely(!skb)) {
> + ret = nxmit;
> + goto out;
> + }
> +
> + /* We need to restore ETH header, because it is pulled
> + * in eth_type_trans.
> + */
> + mac_len = skb->data - skb_mac_header(skb);
> + skb_push(skb, mac_len);
> +
> + nxmit++;
> +
> + queue_mapping = skb_get_queue_mapping(skb);
> + txq = netdev_get_tx_queue(dev, netdev_cap_txqueue(dev, queue_mapping));
> + __netif_tx_lock(txq, smp_processor_id());
> + if (unlikely(veth_xmit(skb, dev) != NETDEV_TX_OK)) {
> + __netif_tx_unlock(txq);
> + ret = nxmit;
> + goto out;
> + }
> + __netif_tx_unlock(txq);
Locking and unlocking the txq repeatedly for each packet? Yikes! Did you
measure the performance overhead of this?
-Toke
next prev parent reply other threads:[~2022-09-27 12:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 8:30 [PATCH net] veth: Avoid drop packets when xdp_redirect performs Heng Qi
2022-09-27 12:20 ` Toke Høiland-Jørgensen [this message]
2022-09-28 11:57 ` Heng Qi
2022-09-28 14:58 ` Toke Høiland-Jørgensen
2022-09-29 2:50 ` Heng Qi
2022-09-29 6:57 ` Paolo Abeni
2022-09-29 7:33 ` Heng Qi
2022-09-29 12:08 ` Toke Høiland-Jørgensen
2022-10-20 2:23 ` Heng Qi
2022-10-20 16:34 ` Toke Høiland-Jørgensen
2022-10-21 6:31 ` Heng Qi
2022-10-24 11:20 ` Heng Qi
2022-10-24 13:34 ` Toke Høiland-Jørgensen
2022-10-24 13:39 ` Heng Qi
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=87wn9proty.fsf@toke.dk \
--to=toke@redhat.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hengqi@linux.alibaba.com \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=xuanzhuo@linux.alibaba.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;
as well as URLs for NNTP newsgroup(s).