-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement virtio-net device #34
Conversation
2448d1f
to
8ff17bb
Compare
I have pushed a newer version. Please take a look. For testing the function, you can use the command below: Host OS :
Guest OS :
|
24b160f
to
6ef8a65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rebase the latest master
branch because the commit "Bump linux version to 6.1.91" was accidentally checked in as a non-functional change. See #35
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent all files using clang-format
. That is, run find src -name '*.[ch]' | xargs clang-format-12 -i
. Do replace clang-format-12
with clang-format version 12 or later.
6ef8a65
to
e0a0284
Compare
e0a0284
to
7543e27
Compare
I have pushed the latest version with the following updates:
|
Warning: No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use git rebase -i
to rework the git commits.
The following commits can be squashed and refined:
- Define VIRTIO_NET_IRQ 14
- Define VIRTIO_PCI_DEVICE_ID_NET macro
- Define macro in virtio-net.h
- Define struct virtio_net_dev and functions in virtio-net.h
Git commits are snapshots around logical units of change. Over time, commits should tell a story of the history of your repository and how it came to be the way that it currently is.
See https://github.blog/2022-06-30-write-better-commits-build-better-projects/
You don't have to mention the file names in the subject of git commit messages. Instead, summarize the functional changes.
- Define `VIRTIO_NET_IRQ` macro for the `notify_used` virtq callback function to send IRQ - Define `VIRTIO_PCI_DEVICE_ID_NET` (0x1041) according to the Virtio 1.1 specification - Define `VIRTIO_NET_PCI_CLASS` macro according to the PCI specification with class code (0x020000) for Ethernet Controller - Define struct `virtio_net_dev` and operation functions for the virtio-net device
7543e27
to
7549229
Compare
@@ -93,6 +93,8 @@ int main(int argc, char *argv[]) | |||
return throw_err("Failed to load initrd"); | |||
if (diskimg_file && vm_load_diskimg(&vm, diskimg_file) < 0) | |||
return throw_err("Failed to load disk image"); | |||
if (vm_enable_net(&vm) < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If virtio-net is not enabled, it still makes sense to initialize and launch this virtual machine via KVM. Thus, instead of returning, we can proceed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed throw_err to fprintf. If vm_enable_net
failed to enable virtio-net device, it will now handle the situation by logging an error message.
if (vm_enable_net(&vm) < 0)
fprintf(stderr, "Failed to Enable Virtio-Net Device\n");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refine the message as following:
Failed to enable virtio-net device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok ! Already done
- Defined struct `virtio_net_dev` to represent the virtio-net device. - Implemented `virtio_net_init` to initialize the TAP device and prepare it for communication. - Added `virtio_net_init_pci` for registering the virtio-net device to PCI, setting up virtqueues. - Implemented functions to enable and handle available events for RX and TX virtqueues. - Added functions to notify the guest OS about used descriptors after packet processing.
This commit removes the initialization of vq->info.notify_off value in the virtio-net implementation. The reason for this change is that during the execution of RX and TX enable callback functions, the `vm_ioeventfd_register` function registers the ioeventfd at the same address repeatly. Therefore, the notify_off value is now initialized directly within the virtqueue enable callback functions.
This commit adds a struct `virtio_net_dev` entry within the struct `vm_t` structure to facilitate the implementation of the virtio-net device. This addition is necessary to integrate and manage the virtio-net device within the broader context of the virtual machine.
7549229
to
2ec4a21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unify the commit "Implement vm_enable_net API" and "Compile virtio-net.c into virtio-net.o during build process" into a single one since they are tended to the same purpose.
2ec4a21
to
a878518
Compare
The vm_enable_net function to facilitate the integration of additional I/O devices in the future. The function initializes the virtio-net device by setting up the tap device using virtio_net_init and subsequently registers the virtio-net device with the PCI bus. This function is invoked during the VM initialization session.
Enabled kernel configuration options required for networking functionality,including `CONFIG_NET`,`CONFIG_INET`,`CONFIG_VIRTIO`, `CONFIG_VIRTIO_NET`,`CONFIG_NETDEVICES` etc. Additionally, enabled specific networking commacands necessary for testing the virtio-net device.
a878518
to
f727c6e
Compare
Thank @jimmylu890303 for contributing! |
Implementation of Virtio-net Device
virtio_net_dev
to represent the virtio-net device.virtio_net_init
to initialize the TAP device for communication.virtio_net_init_pci
to register the virtio-net device on PCI, configure virtqueues.Makefile Modification
Kernel Networking Options Enabled
CONFIG_NET
,CONFIG_INET
,CONFIG_VIRTIO
,CONFIG_VIRTIO_NET
,CONFIG_NETDEVICES
) to support networking functionality.Structural Updates
virtio_net_dev
entry within structvm_t
to facilitate the integration and management of the virtio-net device.Additional Changes
virtio_net_init
andvirtio_net_init_pci
invm_arch_init_platform_device
andmain
respectively, ensuring initialization of the virtio-net device before the virtual machine starts.