[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <C196C9BC-7D51-4FE4-8E68-3C9958C5A858@infradead.org>
Date: Tue, 22 Jun 2021 09:10:03 +0100
From: David Woodhouse <dwmw2@...radead.org>
To: Jason Wang <jasowang@...hat.com>, netdev <netdev@...r.kernel.org>
CC: Eugenio Pérez <eperezma@...hat.com>
Subject: Re: [PATCH] net: tun: fix tun_xdp_one() for IFF_TUN mode
On 22 June 2021 08:51:43 BST, Jason Wang <jasowang@...hat.com> wrote:
>
>在 2021/6/22 下午3:24, David Woodhouse 写道:
>> On Tue, 2021-06-22 at 12:52 +0800, Jason Wang wrote:
>>>
>>> I cook two patches. Please see and check if they fix the problem.
>>> (compile test only for me).
>> I did the second one slightly differently (below) but those are what
>I
>> came up with too, which seems to be working.
>>
>> @@ -2331,7 +2344,7 @@ static int tun_xdp_one(struct tun_struct *tun,
>> {
>> unsigned int datasize = xdp->data_end - xdp->data;
>> struct tun_xdp_hdr *hdr = xdp->data_hard_start;
>> - struct virtio_net_hdr *gso = &hdr->gso;
>> + struct virtio_net_hdr *gso = NULL;
>> struct bpf_prog *xdp_prog;
>> struct sk_buff *skb = NULL;
>> u32 rxhash = 0, act;
>> @@ -2340,9 +2353,12 @@ static int tun_xdp_one(struct tun_struct *tun,
>> bool skb_xdp = false;
>> struct page *page;
>>
>> + if (tun->flags & IFF_VNET_HDR)
>> + gso = &hdr->gso;
>> +
>> xdp_prog = rcu_dereference(tun->xdp_prog);
>> if (xdp_prog) {
>> - if (gso->gso_type) {
>> + if (gso && gso->gso_type) {
>> skb_xdp = true;
>> goto build;
>> }
>> @@ -2388,14 +2406,18 @@ static int tun_xdp_one(struct tun_struct
>*tun,
>> skb_reserve(skb, xdp->data - xdp->data_hard_start);
>> skb_put(skb, xdp->data_end - xdp->data);
>>
>> - if (virtio_net_hdr_to_skb(skb, gso,
>tun_is_little_endian(tun))) {
>> + if (!gso)
>> + skb_reset_mac_header(skb);
>> + else if (virtio_net_hdr_to_skb(skb, gso,
>tun_is_little_endian(tun))) {
>> atomic_long_inc(&tun->rx_frame_errors);
>> kfree_skb(skb);
>
>
>This should work as well.
I'll rip out the rest of my debugging hacks and check that these two are sufficient, and that I hadn't accidentally papered over something else as I debugged it.
Then I'll look at the case of having no virtio_net_hdr on either side, and also different sized headers on the tun device (why does it even support that?).
And the test case, of course.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Powered by blists - more mailing lists