netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Wang <jasowang@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: netdev@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Pérez" <eperezma@redhat.com>,
	"Andrew Lunn" <andrew+netdev@lunn.ch>,
	"David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Willem de Bruijn" <willemb@google.com>,
	"Jiri Pirko" <jiri@resnulli.us>,
	"Alvaro Karsz" <alvaro.karsz@solid-run.com>,
	"Heng Qi" <hengqi@linux.alibaba.com>,
	virtualization@lists.linux.dev
Subject: Re: [PATCH net 2/2] virtio-net: correct hdr_len handling for VIRTIO_NET_F_GUEST_HDRLEN
Date: Fri, 10 Oct 2025 08:36:33 +0800	[thread overview]
Message-ID: <CACGkMEuYTgK2CVGPTJrAdcJ=GxuhFTSfAc0KGU9=yRHX-7f8-Q@mail.gmail.com> (raw)
In-Reply-To: <1760008083.6644826-2-xuanzhuo@linux.alibaba.com>

On Thu, Oct 9, 2025 at 7:10 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
>
> On Fri, 26 Sep 2025 12:52:53 +0800, Jason Wang <jasowang@redhat.com> wrote:
> > On Thu, Sep 25, 2025 at 10:25 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> > >
> > > The commit be50da3e9d4a ("net: virtio_net: implement exact header length
> > > guest feature") introduces support for the VIRTIO_NET_F_GUEST_HDRLEN
> > > feature in virtio-net.
> > >
> > > This feature requires virtio-net to set hdr_len to the actual header
> > > length of the packet when transmitting, the number of
> > > bytes from the start of the packet to the beginning of the
> > > transport-layer payload.
> > >
> > > However, in practice, hdr_len was being set using skb_headlen(skb),
> > > which is clearly incorrect. This commit fixes that issue.
> > >
> > > Fixes: be50da3e9d4a ("net: virtio_net: implement exact header length guest feature")
> > > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > > ---
> > >  include/linux/virtio_net.h | 19 ++++++++++++-------
> > >  1 file changed, 12 insertions(+), 7 deletions(-)
> > >
> > > diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> > > index 20e0584db1dd..4273420a9ff9 100644
> > > --- a/include/linux/virtio_net.h
> > > +++ b/include/linux/virtio_net.h
> > > @@ -217,20 +217,25 @@ static inline int virtio_net_hdr_from_skb(const struct sk_buff *skb,
> > >
> > >         if (skb_is_gso(skb)) {
> > >                 struct skb_shared_info *sinfo = skb_shinfo(skb);
> > > +               u16 hdr_len;
> > >
> > > -               /* This is a hint as to how much should be linear. */
> > > -               hdr->hdr_len = __cpu_to_virtio16(little_endian,
> > > -                                                skb_headlen(skb));
> > > +               hdr_len = skb_transport_offset(skb);
> > >                 hdr->gso_size = __cpu_to_virtio16(little_endian,
> > >                                                   sinfo->gso_size);
> > > -               if (sinfo->gso_type & SKB_GSO_TCPV4)
> > > +               if (sinfo->gso_type & SKB_GSO_TCPV4) {
> > >                         hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
> > > -               else if (sinfo->gso_type & SKB_GSO_TCPV6)
> > > +                       hdr_len += tcp_hdrlen(skb);
> > > +               } else if (sinfo->gso_type & SKB_GSO_TCPV6) {
> > >                         hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
> > > -               else if (sinfo->gso_type & SKB_GSO_UDP_L4)
> > > +                       hdr_len += tcp_hdrlen(skb);
> > > +               } else if (sinfo->gso_type & SKB_GSO_UDP_L4) {
> > >                         hdr->gso_type = VIRTIO_NET_HDR_GSO_UDP_L4;
> > > -               else
> >
> > I think we need to deal with the GSO tunnel as well?
> >
> > """
> >     If the \field{gso_type} has the VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4 bit or
> >     VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6 bit set, \field{hdr_len} accounts for
> >     all the headers up to and including the inner transport.
> > """
>
> I checked the new code, VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6
> and VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4 are not supported, so the next version
> will not include these feature.
>
> Thanks.

I may miss something but we had:

        if (skb->protocol == htons(ETH_P_IPV6))
                hdr->gso_type |= VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV6;
        else
                hdr->gso_type |= VIRTIO_NET_HDR_GSO_UDP_TUNNEL_IPV4;

in virtio_net_hdr_tnl_from_skb() now.

Thanks

>
>
> >
> > > +                       hdr_len += sizeof(struct udphdr);
> > > +               } else {
> > >                         return -EINVAL;
> > > +               }
> > > +
> > > +               hdr->hdr_len = __cpu_to_virtio16(little_endian, hdr_len);
> >
> > Should we at least check against the feature of VIRTIO_NET_F_GUEST_HDRLEN?
> >
> > >                 if (sinfo->gso_type & SKB_GSO_TCP_ECN)
> > >                         hdr->gso_type |= VIRTIO_NET_HDR_GSO_ECN;
> > >         } else
> > > --
> > > 2.32.0.3.g01195cf9f
> > >
> >
>


  reply	other threads:[~2025-10-10  0:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-25  2:25 [PATCH net 0/2] fixes two virtio-net related bugs Xuan Zhuo
2025-09-25  2:25 ` [PATCH net 1/2] virtio-net: fix incorrect flags recording in big mode Xuan Zhuo
2025-09-26  4:49   ` Jason Wang
2025-09-25  2:25 ` [PATCH net 2/2] virtio-net: correct hdr_len handling for VIRTIO_NET_F_GUEST_HDRLEN Xuan Zhuo
2025-09-26  4:52   ` Jason Wang
2025-10-09 11:00     ` Xuan Zhuo
2025-10-09 11:08     ` Xuan Zhuo
2025-10-10  0:36       ` Jason Wang [this message]
2025-10-10  3:01         ` Xuan Zhuo
2025-09-25  7:13 ` [syzbot ci] Re: fixes two virtio-net related bugs syzbot ci
2025-09-25  7:16   ` Marco Elver
2025-09-25  7:19     ` syzbot ci

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='CACGkMEuYTgK2CVGPTJrAdcJ=GxuhFTSfAc0KGU9=yRHX-7f8-Q@mail.gmail.com' \
    --to=jasowang@redhat.com \
    --cc=alvaro.karsz@solid-run.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=eperezma@redhat.com \
    --cc=hengqi@linux.alibaba.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=willemb@google.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).