From: Heng Qi <hengqi@linux.alibaba.com>
To: "Michael S. Tsirkin" <mst@redhat.com>
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
Jason Wang <jasowang@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>
Subject: Re: [PATCH net-next 2/4] virtio-net: reprobe csum related fields for skb passed by XDP
Date: Mon, 19 Jun 2023 20:29:35 +0800 [thread overview]
Message-ID: <20230619122935.GA74977@h68b04307.sqa.eu95> (raw)
In-Reply-To: <20230619072651-mutt-send-email-mst@kernel.org>
On Mon, Jun 19, 2023 at 07:27:26AM -0400, Michael S. Tsirkin wrote:
> On Mon, Jun 19, 2023 at 06:57:36PM +0800, Heng Qi wrote:
> > Currently, the VIRTIO_NET_F_GUEST_CSUM (corresponds to NETIF_F_RXCSUM
> > for netdev) feature of the virtio-net driver conflicts with the loading
> > of XDP, which is caused by the problem described in [1][2], that is,
> > XDP may cause errors in partial csumed-related fields which can lead
> > to packet dropping.
> >
> > In addition, when communicating between vm and vm on the same host, the
> > receiving side vm will receive packets marked as
> > VIRTIO_NET_HDR_F_NEEDS_CSUM, but after these packets are processed by
> > XDP, the VIRTIO_NET_HDR_F_NEEDS_CSUM and skb CHECKSUM_PARTIAL flags will
> > be cleared, causing the packet dropping.
> >
> > This patch introduces a helper function, which will try to solve the
> > above problems in the subsequent patch.
> >
> > [1] commit 18ba58e1c234 ("virtio-net: fail XDP set if guest csum is negotiated")
> > [2] commit e59ff2c49ae1 ("virtio-net: disable guest csum during XDP set")
> >
> > Signed-off-by: Heng Qi <hengqi@linux.alibaba.com>
> > Reviewed-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
>
>
> squash this and patch 1 into where the helpers are used.
>
> in particular so we don't get warnings with bisect.
Ok. Will modify.
Thanks.
>
> > ---
> > drivers/net/virtio_net.c | 38 ++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 38 insertions(+)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 36cae78f6311..07b4801d689c 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -1663,6 +1663,44 @@ static int virtnet_flow_dissect_udp_tcp(struct virtnet_info *vi, struct sk_buff
> > return 0;
> > }
> >
> > +static int virtnet_set_csum_after_xdp(struct virtnet_info *vi,
> > + struct sk_buff *skb,
> > + __u8 flags)
> > +{
> > + int err;
> > +
> > + /* When XDP program is loaded, for example, the vm-vm scenario
> > + * on the same host, packets marked as VIRTIO_NET_HDR_F_NEEDS_CSUM
> > + * will travel. Although these packets are safe from the point of
> > + * view of the vm, to avoid modification by XDP and successful
> > + * forwarding in the upper layer, we re-probe the necessary checksum
> > + * related information: skb->csum_{start, offset}, pseudo-header csum.
> > + *
> > + * This benefits us:
> > + * 1. XDP can be loaded when there's _F_GUEST_CSUM.
> > + * 2. The device verifies the checksum of packets , especially
> > + * benefiting for large packets.
> > + * 3. In the same-host vm-vm scenario, packets marked as
> > + * VIRTIO_NET_HDR_F_NEEDS_CSUM are no longer dropped after being
> > + * processed by XDP.
> > + */
> > + if (flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) {
> > + err = virtnet_flow_dissect_udp_tcp(vi, skb);
> > + if (err < 0)
> > + return -EINVAL;
> > +
> > + skb->ip_summed = CHECKSUM_PARTIAL;
> > + } else if (flags && VIRTIO_NET_HDR_F_DATA_VALID) {
> > + /* We want to benefit from this: XDP guarantees that packets marked
> > + * as VIRTIO_NET_HDR_F_DATA_VALID still have correct csum after they
> > + * are processed.
> > + */
> > + skb->ip_summed = CHECKSUM_UNNECESSARY;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > static void receive_buf(struct virtnet_info *vi, struct receive_queue *rq,
> > void *buf, unsigned int len, void **ctx,
> > unsigned int *xdp_xmit,
> > --
> > 2.19.1.6.gb485710b
next prev parent reply other threads:[~2023-06-19 12:29 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-19 10:57 [PATCH net-next 0/4] virtio-net: avoid XDP and _F_GUEST_CSUM Heng Qi
2023-06-19 10:57 ` [PATCH net-next 1/4] virtio-net: a helper for probing the pseudo-header checksum Heng Qi
2023-06-19 12:30 ` kernel test robot
2023-06-19 12:30 ` kernel test robot
2023-06-19 10:57 ` [PATCH net-next 2/4] virtio-net: reprobe csum related fields for skb passed by XDP Heng Qi
2023-06-19 11:27 ` Michael S. Tsirkin
2023-06-19 12:29 ` Heng Qi [this message]
2023-06-19 13:32 ` kernel test robot
2023-06-19 10:57 ` [PATCH net-next 3/4] virtio-net: support coexistence of XDP and _F_GUEST_CSUM Heng Qi
2023-06-19 11:26 ` Michael S. Tsirkin
2023-06-19 12:31 ` Heng Qi
2023-06-20 3:24 ` Heng Qi
2023-06-20 10:50 ` Michael S. Tsirkin
2023-06-20 11:01 ` Heng Qi
2023-06-20 12:10 ` Michael S. Tsirkin
2023-06-20 14:15 ` Heng Qi
2023-06-19 10:57 ` [PATCH net-next 4/4] virtio-net: remove F_GUEST_CSUM check for XDP loading Heng Qi
2023-06-19 11:16 ` Michael S. Tsirkin
2023-06-19 12:41 ` Heng Qi
2023-06-19 14:33 ` Michael S. Tsirkin
2023-06-19 15:43 ` Heng Qi
2023-06-19 18:36 ` Michael S. Tsirkin
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=20230619122935.GA74977@h68b04307.sqa.eu95 \
--to=hengqi@linux.alibaba.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hawk@kernel.org \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=mst@redhat.com \
--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).