kvm-host icon indicating copy to clipboard operation
kvm-host copied to clipboard

Implement virtio-net device

Open jimmylu890303 opened this issue 1 year ago • 1 comments

Implementation of Virtio-net Device

  • Defined struct virtio_net_dev to represent the virtio-net device.
  • Implemented virtio_net_init to initialize the TAP device for communication.
  • Introduced virtio_net_init_pci to register the virtio-net device on PCI, configure virtqueues.
  • Implemented functions to handle available events for RX and TX virtqueues.
  • Added functions to notify the guest OS about used descriptors after packet processing.

Makefile Modification

  • Added rules to compile virtio-net.c into virtio-net.o, ensuring correct compilation and linkage of virtio-net functionality within the project.

Kernel Networking Options Enabled

  • Enabled necessary kernel configuration options (CONFIG_NET, CONFIG_INET, CONFIG_VIRTIO, CONFIG_VIRTIO_NET, CONFIG_NETDEVICES) to support networking functionality.
  • Enabled specific networking commands required for testing the virtio-net device.

Structural Updates

  • Added struct virtio_net_dev entry within struct vm_t to facilitate the integration and management of the virtio-net device.

Additional Changes

  • Called virtio_net_init and virtio_net_init_pci in vm_arch_init_platform_device and main respectively, ensuring initialization of the virtio-net device before the virtual machine starts.

jimmylu890303 avatar Jun 27 '24 18:06 jimmylu890303

I have pushed a newer version. Please take a look.

For testing the function, you can use the command below:

Host OS :

sudo ip link delete br0
sudo brctl addbr br0
sudo ip addr add 10.0.0.1/24 dev br0
sudo ip route add default via 10.0.0.1 dev br0
sudo ip link set br0 up
sudo ip link set tap0 master br0
sudo ip link set tap0 up

Guest OS :

ip addr add 10.0.0.2/24 dev eth0
ip link set eth0 up
ip route add default via 10.0.0.1

jimmylu890303 avatar Jul 06 '24 14:07 jimmylu890303

I'm good with the changes now. Thanks for all the kindly reply.

Let' see if @jserv has any extra comment.

Thanks for your review !

jimmylu890303 avatar Jul 10 '24 12:07 jimmylu890303

I have pushed the latest version with the following updates:

  • I rebased the latest master branch to remove the non-functional commit "Bump linux version to 6.1.91" as discussed in issue #35.
  • I have reformatted all relevant files using clang-format. Specifically, I ran the command find src -name '*.[ch]' | xargs clang-format-12 -i with clang-format version 12.

jimmylu890303 avatar Jul 20 '24 05:07 jimmylu890303

  1. I have reformatted all relevant files using clang-format. Specifically, I ran the command find src -name '*.[ch]' | xargs clang-format-12 -i with clang-format version 12.

Warning: No newline at end of file src/virtio-net.c See https://medium.com/@alexey.inkin/how-to-force-newline-at-end-of-files-and-why-you-should-do-it-fdf76d1d090e

jserv avatar Jul 21 '24 07:07 jserv

Thank @jimmylu890303 for contributing!

jserv avatar Jul 21 '24 18:07 jserv