From: Yunsheng Lin <linyunsheng@huawei.com>
To: Jason Wang <jasowang@redhat.com>
Cc: <davem@davemloft.net>, <kuba@kernel.org>, <pabeni@redhat.com>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
Xuan Zhuo <xuanzhuo@linux.alibaba.com>,
<virtualization@lists.linux.dev>
Subject: Re: [PATCH net-next 6/6] tools: virtio: introduce vhost_net_test
Date: Wed, 20 Dec 2023 20:44:49 +0800 [thread overview]
Message-ID: <c5b5d36c-d0ca-c943-5355-343214d92c26@huawei.com> (raw)
In-Reply-To: <CACGkMEsMdP1B-9RaqibJYfFsd_qJpB+Kta5BnyD_WXH=W2w_OQ@mail.gmail.com>
On 2023/12/12 12:35, Jason Wang wrote:>>>> +done:
>>>> + backend.fd = tun_alloc();
>>>> + assert(backend.fd >= 0);
>>>> + vdev_info_init(&dev, features);
>>>> + vq_info_add(&dev, 256);
>>>> + run_test(&dev, &dev.vqs[0], delayed, batch, reset, nbufs);
>>>
>>> I'd expect we are testing some basic traffic here. E.g can we use a
>>> packet socket then we can test both tx and rx?
>>
>> Yes, only rx for tun is tested.
>> Do you have an idea how to test the tx too? As I am not familar enough
>> with vhost_net and tun yet.
>
> Maybe you can have a packet socket to bind to the tun/tap. Then you can test:
>
> 1) TAP RX: by write a packet via virtqueue through vhost_net and read
> it from packet socket
> 2) TAP TX: by write via packet socket and read it from the virtqueue
> through vhost_net
When implementing the TAP TX by adding VHOST_NET_F_VIRTIO_NET_HDR,
I found one possible use of uninitialized data in vhost_net_build_xdp().
And vhost_hlen is set to sizeof(struct virtio_net_hdr_mrg_rxbuf) and
sock_hlen is set to zero in vhost_net_set_features() for both tx and rx
queue.
For vhost_net_build_xdp() called by handle_tx_copy():
The (gso->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) checking below may cause a
read of uninitialized data if sock_hlen is zero.
And it seems vhost_hdr is skipped in get_tx_bufs():
https://elixir.bootlin.com/linux/latest/source/drivers/vhost/net.c#L616
static int vhost_net_build_xdp(struct vhost_net_virtqueue *nvq,
struct iov_iter *from)
{
...
buflen += SKB_DATA_ALIGN(len + pad);
alloc_frag->offset = ALIGN((u64)alloc_frag->offset, SMP_CACHE_BYTES);
if (unlikely(!vhost_net_page_frag_refill(net, buflen,
alloc_frag, GFP_KERNEL)))
return -ENOMEM;
buf = (char *)page_address(alloc_frag->page) + alloc_frag->offset;
copied = copy_page_from_iter(alloc_frag->page,
alloc_frag->offset +
offsetof(struct tun_xdp_hdr, gso),
sock_hlen, from);
if (copied != sock_hlen)
return -EFAULT;
hdr = buf;
gso = &hdr->gso;
if ((gso->flags & VIRTIO_NET_HDR_F_NEEDS_CSUM) &&
vhost16_to_cpu(vq, gso->csum_start) +
vhost16_to_cpu(vq, gso->csum_offset) + 2 >
vhost16_to_cpu(vq, gso->hdr_len)) {
...
}
I seems the handle_tx_copy() does not handle the VHOST_NET_F_VIRTIO_NET_HDR
case correctly, Or do I miss something obvious here?
>
> Thanks
>
>>
>>>
>>> Thanks
>>
>
> .
>
next prev parent reply other threads:[~2023-12-20 12:44 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-05 11:34 [PATCH net-next 0/6] remove page frag implementation in vhost_net Yunsheng Lin
2023-12-05 11:34 ` [PATCH net-next 1/6] mm/page_alloc: modify page_frag_alloc_align() to accept align as an argument Yunsheng Lin
2023-12-05 11:34 ` [PATCH net-next 2/6] page_frag: unify gfp bit for order 3 page allocation Yunsheng Lin
2023-12-07 3:15 ` Jakub Kicinski
2023-12-07 11:27 ` Yunsheng Lin
2023-12-05 11:34 ` [PATCH net-next 3/6] mm/page_alloc: use initial zero offset for page_frag_alloc_align() Yunsheng Lin
2023-12-05 11:34 ` [PATCH net-next 4/6] vhost/net: remove vhost_net_page_frag_refill() Yunsheng Lin
2023-12-07 5:52 ` Jason Wang
2023-12-05 11:34 ` [PATCH net-next 5/6] net: introduce page_frag_cache_drain() Yunsheng Lin
2023-12-07 5:46 ` Jason Wang
2023-12-05 11:34 ` [PATCH net-next 6/6] tools: virtio: introduce vhost_net_test Yunsheng Lin
2023-12-07 6:00 ` Jason Wang
2023-12-07 11:28 ` Yunsheng Lin
2023-12-12 4:35 ` Jason Wang
2023-12-20 12:44 ` Yunsheng Lin [this message]
2023-12-21 2:33 ` Jason Wang
2023-12-21 2:47 ` Yunsheng Lin
2023-12-21 2:56 ` Jason Wang
2024-01-03 9:56 [PATCH net-next 0/6] remove page frag implementation in vhost_net Yunsheng Lin
2024-01-03 9:56 ` [PATCH net-next 6/6] tools: virtio: introduce vhost_net_test Yunsheng Lin
2024-01-04 16:17 ` Eugenio Perez Martin
2024-01-05 2:09 ` Yunsheng Lin
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=c5b5d36c-d0ca-c943-5355-343214d92c26@huawei.com \
--to=linyunsheng@huawei.com \
--cc=davem@davemloft.net \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
--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
all inboxes | Powered by JetHome®