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: Thu, 7 Dec 2023 19:28:16 +0800 [thread overview]
Message-ID: <424670ab-23d8-663b-10cb-d88906767956@huawei.com> (raw)
In-Reply-To: <CACGkMEvVezZnHK-gRWY+MUd_6awnprb024scqPNmMQ05P8rWTQ@mail.gmail.com>
On 2023/12/7 14:00, Jason Wang wrote:
> On Tue, Dec 5, 2023 at 7:35 PM Yunsheng Lin <linyunsheng@huawei.com> wrote:
...
>> +
>> +static int tun_alloc(void)
>> +{
>> + struct ifreq ifr;
>> + int fd, e;
>> +
>> + fd = open("/dev/net/tun", O_RDWR);
>> + if (fd < 0) {
>> + perror("Cannot open /dev/net/tun");
>> + return fd;
>> + }
>> +
>> + memset(&ifr, 0, sizeof(ifr));
>> +
>> + ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
>
> Why did you use IFF_TUN but not IFF_TAP here?
To be honest, no particular reason, I just picked IFF_TUN and it happened
to work for me to test changing in vhost_net_build_xdp().
Is there a particular reason you perfer the IFF_TAP over IFF_TUN?
>
>> + strncpy(ifr.ifr_name, "tun0", IFNAMSIZ);
>
> tun0 is pretty common if there's a VPN. Do we need some randomized name here?
How about something like below?
snprintf(ifr.ifr_name, IFNAMSIZ, "tun_%d", getpid());
>
>
>> +
>> + e = ioctl(fd, TUNSETIFF, (void *) &ifr);
>> + if (e < 0) {
>> + perror("ioctl[TUNSETIFF]");
>> + close(fd);
>> + return e;
>> + }
>> +
>> + return fd;
>> +}
>> +
>> +/* Unused */
>> +void *__kmalloc_fake, *__kfree_ignore_start, *__kfree_ignore_end;
>
> Why do we need trick like these here?
That is because of the below error:
tools/virtio/./linux/kernel.h:58: undefined reference to `__kmalloc_fake'
when virtio_ring.c is compiled in the userspace, the kmalloc raleted function
is implemented in tools/virtio/./linux/kernel.h, which requires those varibles
to be defined.
>
>> +
>> +struct vq_info {
>> + int kick;
>> + int call;
>> + int num;
>> + int idx;
>> + void *ring;
>> + /* copy used for control */
>> + struct vring vring;
>> + struct virtqueue *vq;
>> +};
>> +
>> +struct vdev_info {
>> + struct virtio_device vdev;
>> + int control;
>> + struct pollfd fds[1];
>> + struct vq_info vqs[1];
>> + int nvqs;
>> + void *buf;
>> + size_t buf_size;
>> + struct vhost_memory *mem;
>> +};
>> +
>> +static struct vhost_vring_file no_backend = { .index = 1, .fd = -1 },
>> + backend = { .index = 1, .fd = 1 };
>
> A magic number like fd = 1 is pretty confusing.
>
> And I don't see why we need global variables here.
I was using the virtio_test.c as reference, will try to remove it
if it is possible.
>
>> +static const struct vhost_vring_state null_state = {};
>> +
..
>> +
>> +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.
>
> Thanks
next prev parent reply other threads:[~2023-12-07 11:28 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 [this message]
2023-12-12 4:35 ` Jason Wang
2023-12-20 12:44 ` Yunsheng Lin
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=424670ab-23d8-663b-10cb-d88906767956@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®