public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: Jason Wang <jasowang@redhat.com>, Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: 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: Thu, 19 Mar 2026 09:15:05 +0100	[thread overview]
Message-ID: <6be7d6f0-08ce-466c-87cc-bc2ad3f26aab@redhat.com> (raw)
In-Reply-To: <CACGkMEutuueTx_QhEa9gV72NYTqaGD=69YvMKG=RcmEfdrJKhQ@mail.gmail.com>

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?

/P


  parent reply	other threads:[~2026-03-19  8:15 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 [this message]
2026-03-20  0:38         ` Jason Wang
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=6be7d6f0-08ce-466c-87cc-bc2ad3f26aab@redhat.com \
    --to=pabeni@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=jasowang@redhat.com \
    --cc=jiri@resnulli.us \
    --cc=kuba@kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --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