From: Jason Wang <jasowang@redhat.com>
To: Paolo Abeni <pabeni@redhat.com>
Cc: "Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
netdev@vger.kernel.org,
"Willem de Bruijn" <willemdebruijn.kernel@gmail.com>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Jiri Pirko" <jiri@resnulli.us>,
"Alvaro Karsz" <alvaro.karsz@solid-run.com>,
virtualization@lists.linux.dev
Subject: Re: [PATCH net v10 1/2] virtio-net: correct hdr_len handling for VIRTIO_NET_F_GUEST_HDRLEN
Date: Fri, 20 Mar 2026 08:38:35 +0800 [thread overview]
Message-ID: <CACGkMEvTXpQ8pxL5DQjWeaJPMLP9X3=c5=hc-Geoj1PSZ+_sJQ@mail.gmail.com> (raw)
In-Reply-To: <6be7d6f0-08ce-466c-87cc-bc2ad3f26aab@redhat.com>
On Thu, Mar 19, 2026 at 4:15 PM Paolo Abeni <pabeni@redhat.com> wrote:
>
> Hi,
>
> On 3/18/26 5:11 AM, Jason Wang wrote:
> > On Wed, Mar 18, 2026 at 12:07 PM Jason Wang <jasowang@redhat.com> wrote:
> >> On Fri, Mar 13, 2026 at 3:59 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >>> diff --git a/include/linux/virtio_net.h b/include/linux/virtio_net.h
> >>> index 75dabb763c65..48de4a16a96a 100644
> >>> --- a/include/linux/virtio_net.h
> >>> +++ b/include/linux/virtio_net.h
> >>> @@ -207,6 +207,22 @@ static inline int virtio_net_hdr_to_skb(struct sk_buff *skb,
> >>> return __virtio_net_hdr_to_skb(skb, hdr, little_endian, hdr->gso_type);
> >>> }
> >>>
> >>> +static inline void virtio_net_set_hdrlen(const struct sk_buff *skb,
> >>> + struct virtio_net_hdr *hdr,
> >>> + bool little_endian)
> >>> +{
> >>> + u16 hdr_len;
> >>> +
> >>> + hdr_len = skb_transport_offset(skb);
> >>> +
> >>> + if (hdr->gso_type == VIRTIO_NET_HDR_GSO_UDP_L4)
> >>> + hdr_len += sizeof(struct udphdr);
> >>> + else
> >>> + hdr_len += tcp_hdrlen(skb);
> >>
> >> Ok, I think this depends on the logic inside virtio_net_hdr_from_skb()
> >>
> >> if (sinfo->gso_type & SKB_GSO_TCPV4)
> >> hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
> >> 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->gso_type = VIRTIO_NET_HDR_GSO_UDP_L4;
> >> else
> >> return -EINVAL;
> >>
> >> To be more robust, I'd suggest moving it there.
> >>
> >> But I have another question, the logic above depends on the headlen is
> >> correctly set:
> >>
> >> /* This is a hint as to how much should be linear. */
> >> hdr->hdr_len = __cpu_to_virtio16(little_endian,
> >> skb_headlen(skb));
> >>
> >> Is the headlen guaranteed to be correct in all cases (e.g for nested
> >> setups or dodgy packets?)
> >
> > Speak too fast, I miss
> >
> > hdr_len = skb_transport_offset(skb);
> >
> > This is probably another call to
> >
> > 1) Move virtio_net_set_hdrlen() inside virtio_net_hdr_from_skb() or
> > 2) call virtio_net_set_hdrlen() inside virtio_net_hdr_from_skb().
>
> It looks like that the above leads to more complex code with a bunch of
> additional conditionals, which possibly the compiler can't optimize out,
> and IMHO not nice layering violation, see the already mentioned previous
> iteration:
>
> https://lore.kernel.org/all/cf62a942-e1e8-4b37-837a-b0bd76297656@redhat.com/
>
> What about instead simply rename virtio_net_set_hdrlen() to
> __virtio_net_set_hdrlen(), virtio_net_set_tnl_hdrlen() to
> __virtio_net_set_tnl_hdrlen(), and add explicitly mention in a comment
> that such functions must be invoked only after virtio_net_hdr_from_skb()
> validation?
Works for me.
Thanks
>
> /P
>
next prev parent reply other threads:[~2026-03-20 0:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 7:59 [PATCH net v10 0/2] virtio-net: fix for VIRTIO_NET_F_GUEST_HDRLEN Xuan Zhuo
2026-03-13 7:59 ` [PATCH net v10 1/2] virtio-net: correct hdr_len handling " Xuan Zhuo
2026-03-17 11:29 ` Paolo Abeni
2026-03-20 1:47 ` Xuan Zhuo
2026-03-18 4:07 ` Jason Wang
2026-03-18 4:11 ` Jason Wang
2026-03-18 5:52 ` Xuan Zhuo
2026-03-19 8:15 ` Paolo Abeni
2026-03-20 0:38 ` Jason Wang [this message]
2026-03-13 7:59 ` [PATCH net v10 2/2] virtio-net: correct hdr_len handling for tunnel gso Xuan Zhuo
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='CACGkMEvTXpQ8pxL5DQjWeaJPMLP9X3=c5=hc-Geoj1PSZ+_sJQ@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=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=willemdebruijn.kernel@gmail.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