Re: [PATCH v2 4/4] vhost_net: Add self test with tun device
From: Jason Wang <hidden>
Date: 2021-06-23 04:02:44
在 2021/6/23 上午12:15, David Woodhouse 写道:
From: David Woodhouse <redacted> This creates a tun device and brings it up, then finds out the link-local address the kernel automatically assigns to it. It sends a ping to that address, from a fake LL address of its own, and then waits for a response. If the virtio_net_hdr stuff is all working correctly, it gets a response and manages to understand it.
I wonder whether it worth to bother the dependency like ipv6 or kernel networking stack. How about simply use packet socket that is bound to tun to receive and send packets?
Signed-off-by: David Woodhouse <redacted> --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/vhost/Makefile | 16 + tools/testing/selftests/vhost/config | 2 + .../testing/selftests/vhost/test_vhost_net.c | 522 ++++++++++++++++++ 4 files changed, 541 insertions(+) create mode 100644 tools/testing/selftests/vhost/Makefile create mode 100644 tools/testing/selftests/vhost/config create mode 100644 tools/testing/selftests/vhost/test_vhost_net.c
[...]
+ /* + * I just want to map the *whole* of userspace address space. But + * from userspace I don't know what that is. On x86_64 it would be: + * + * vmem->regions[0].guest_phys_addr = 4096; + * vmem->regions[0].memory_size = 0x7fffffffe000; + * vmem->regions[0].userspace_addr = 4096; + * + * For now, just ensure we put everything inside a single BSS region. + */ + vmem->regions[0].guest_phys_addr = (uint64_t)&rings; + vmem->regions[0].userspace_addr = (uint64_t)&rings; + vmem->regions[0].memory_size = sizeof(rings);
Instead of doing tricks like this, we can do it in another way: 1) enable device IOTLB 2) wait for the IOTLB miss request (iova, len) and update identity mapping accordingly This should work for all the archs (with some performance hit). Thanks