Implement virtio-net Driver Support
cover Implement virtio-net Driver Support
Implement a virtio-net driver (using an in-built virtio-pci driver) to allow GRUB to have network support in virtual environments such as Qemu without a dependency on the BIOS, UEFI, etc. This provides a virtio-net driver implementation targetting the 1.x virtio specification (using just the minimal required features of the specification to get this working in GRUB).
Also add a net_http_transfer_test to provide an integration test of the new driver running under Qemu and also exercise some of the network stack code as well.
Right now this implementation has been tested on i386-pc and x86_64-efi, so the module is only built for those architectures. With additional architecture testing, this can likely be enabled on other configurations as well.
For the user perspective, this patch will provide GRUB network capability in a wider variety of virtualized configurations. It will also improve test coverage of the network code in GRUB. This driver should provide a basis for building upon this initial small test for the network code in the future.
Andrew Hamilton (3):
docs: Document Module virtionet
net: Implement virtio-net Driver for Qemu in GRUB
tests: Add net_http_transfer_test
.gitignore | 2 + Makefile.util.def | 12 + docs/grub.texi | 16 + grub-core/Makefile.core.def | 12 + grub-core/net/drivers/virtio/virtionet.c | 1000 ++++++++++++++++++++++ tests/net_http_transfer_test.in | 107 +++ tests/util/grub-shell.in | 3 + tests/util/qemu-linkup.in | 21 + 8 files changed, 1173 insertions(+) create mode 100644 grub-core/net/drivers/virtio/virtionet.c create mode 100755 tests/net_http_transfer_test.in create mode 100755 tests/util/qemu-linkup.in
Signature · 7 lines
2.39.5 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/3 docs: Document Module virtionet
Add documentation for new module virtionet which can be used to provide network driver support in GRUB in a virtual environment like Qemu.
--- docs/grub.texi | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
docs/grub.texi +16 -0
@@ -4167,6 +4167,7 @@ Modules can be loaded via the @command{insmod} (@pxref{insmod}) command. * videoinfo_module:: * videotest_module:: * videotest_checksum_module:: +* virtionet_module:: * wrmsr_module:: * xen_boot_module:: * xfs_module::
@@ -5861,6 +5862,21 @@ specified width and height. This module is intended for performing a functional test of the video functions in GRUB by displaying a test image and capturing a checksum. +@node virtionet_module +@section virtionet +This module provides network driver support in GRUB for a "virtio" device, such +as may be available in a virtual environment like Qemu. This driver uses the +virtio-pci interface, and provides support for PCI IDs: Vendor 1AF4 with +device ID 1000 (transitional virtio network device) and Vendor 1AF4 with +device ID 1041 (regular virtio network device). The following is an example of +parameters that can be passed to Qemu (in this case the "TAP" interface is used +which probably requires root permissions when launching Qemu: +@samp{-netdev tap,id=hostnet0,ifname=tap0,script=no,downscript=no -device +virtio-net-pci,netdev=hostnet0}. +This module may be useful in cases where the network driver support provided +by the BIOS / UEFI are not available (such as when BIOS PXE isn't used) or +when a specific configuration does not have a native network driver available. + @node wrmsr_module @section wrmsr This module provides support for the @command{wrmsr} command to write to CPU
Signature · 7 lines
2.39.5 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 3/3 tests: Add net_http_transfer_test
In reply to Andrew HamiltonAdd a new test to exercise the virtionet driver in GRUB as well as some elements of the network stack. This uses Python3 on the host to run a local HTTP server on the host / Qemu virtual interface and GRUB will download a GRUB file over HTTP and the host and GRUB calculated hashes are then compared.
--- .gitignore | 2 + Makefile.util.def | 12 ++++ tests/net_http_transfer_test.in | 107 ++++++++++++++++++++++++++++++++ tests/util/grub-shell.in | 3 + tests/util/qemu-linkup.in | 21 +++++++ 5 files changed, 145 insertions(+) create mode 100755 tests/net_http_transfer_test.in create mode 100755 tests/util/qemu-linkup.in
.gitignore +2 -0
@@ -237,6 +237,7 @@ widthspec.bin /m4/ /minixfs_test /missing +/net_http_transfer_test /netboot_test /nilfs2_test /ntfs_test
@@ -260,6 +261,7 @@ widthspec.bin /printf_test /priority_queue_unit_test /pseries_test +/qemu-linkup /reiserfs_test /romfs_test /squashfs_test
Makefile.util.def +12 -0
@@ -764,6 +764,18 @@ script = { dependencies = 'garbage-gen$(BUILD_EXEEXT)'; }; +script = { + name = qemu-linkup; + common = tests/util/qemu-linkup.in; + installdir = noinst; +}; + +script = { + testcase = nonnative; + name = net_http_transfer_test; + common = tests/net_http_transfer_test.in; +}; + script = { testcase = native; name = erofs_test;
tests/net_http_transfer_test.in new file +107 -0
107 lines not on this page · raw message
tests/util/grub-shell.in +3 -0
@@ -22,6 +22,7 @@ prefix="@prefix@" exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" builddir="@builddir@" +abs_top_builddir="@abs_top_builddir@" srcdir="@srcdir@" PACKAGE_NAME=@PACKAGE_NAME@ PACKAGE_TARNAME=@PACKAGE_TARNAME@
@@ -172,6 +173,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in i386-pc) boot=cd qemu=qemu-system-i386 + qemuopts="$qemuopts -netdev tap,id=hostnet0,ifname=tap0,script=${abs_top_builddir}/qemu-linkup,downscript=no -device virtio-net-pci,netdev=hostnet0" console=console netbootext=0 ;;
@@ -236,6 +238,7 @@ case "${grub_modinfo_target_cpu}-${grub_modinfo_platform}" in exit 1 fi fi + qemuopts="$qemuopts -netdev tap,id=hostnet0,ifname=tap0,script=${abs_top_builddir}/qemu-linkup,downscript=no -device virtio-net-pci,netdev=hostnet0" ;; arm64-efi) qemu=qemu-system-aarch64
tests/util/qemu-linkup.in new file +21 -0
@@ -0,0 +1,21 @@ +#! @BUILD_SHEBANG@ +set -e + +# Qemu network bringup script to assign an IP to an interface. +# Copyright (C) 2024 Free Software Foundation, Inc. +# +# GRUB is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GRUB is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GRUB. If not, see <http://www.gnu.org/licenses/>. + +ip link set "$1" up +ip address add 169.254.67.38/24 dev "$1"
Signature · 7 lines
2.39.5 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/3 net: Implement virtio-net Driver for Qemu in GRUB
In reply to Andrew HamiltonProvide virtio-net driver for network interface support in a virtual environment such as Qemu. This was written to comply with virtio version 1.x. This uses a virtio-pci interface.
--- grub-core/Makefile.core.def | 12 + grub-core/net/drivers/virtio/virtionet.c | 1000 ++++++++++++++++++++++ 2 files changed, 1012 insertions(+) create mode 100644 grub-core/net/drivers/virtio/virtionet.c
grub-core/Makefile.core.def +12 -0
@@ -1625,6 +1625,18 @@ module = { enable = i386_pc; }; +module = { + name = virtionet; + common = net/drivers/virtio/virtionet.c; + enable = i386_coreboot; + enable = i386_qemu; + enable = i386_multiboot; + enable = i386_ieee1275; + enable = i386_pc; + enable = i386_efi; + enable = x86_64_efi; +}; + module = { name = gettext; common = gettext/gettext.c;
grub-core/net/drivers/virtio/virtionet.c new file +1000 -0
1,000 lines not on this page · raw message
Signature · 7 lines
2.39.5 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Any interest in this patch set?
Thanks,
Andrew
Quoted 41 lines · Andrew Hamilton
Implement a virtio-net driver (using an in-built virtio-pci driver) to allow GRUB to have network support in virtual environments such as Qemu without a dependency on the BIOS, UEFI, etc. This provides a virtio-net driver implementation targetting the 1.x virtio specification (using just the minimal required features of the specification to get this working in GRUB).
Also add a
net_http_transfer_testto provide an integration test of the new driver running under Qemu and also exercise some of the network stack code as well.Right now this implementation has been tested on i386-pc and x86_64-efi, so the module is only built for those architectures. With additional architecture testing, this can likely be enabled on other configurations as well.
For the user perspective, this patch will provide GRUB network capability in a wider variety of virtualized configurations. It will also improve test coverage of the network code in GRUB. This driver should provide a basis for building upon this initial small test for the network code in the future.
Andrew Hamilton (3):
docs: Document Module virtionet
net: Implement virtio-net Driver for Qemu in GRUB
tests: Addnet_http_transfer_test.gitignore | 2 + Makefile.util.def | 12 + docs/grub.texi | 16 + grub-core/Makefile.core.def | 12 + grub-core/net/drivers/virtio/virtionet.c | 1000 ++++++++++++++++++++++ tests/net_http_transfer_test.in | 107 +++ tests/util/grub-shell.in | 3 + tests/util/qemu-linkup.in | 21 + 8 files changed, 1173 insertions(+) create mode 100644 grub-core/net/drivers/virtio/virtionet.c create mode 100755 tests/net_http_transfer_test.in create mode 100755 tests/util/qemu-linkup.in
Quoted 4 lines
--
2.39.5
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 1 line · Andrew Hamilton
Any interest in this patch set?
Yes, but due to holiday season and other things I will not be able to take a look at it for a few weeks. There is a chance I will have more time at turn of January and February. Sorry about that...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Sounds great, thank you and hope everyone has a happy holiday season.
- Andrew
Quoted 9 lines · Daniel Kiper
Quoted 1 line · Andrew Hamilton
Any interest in this patch set?
Yes, but due to holiday season and other things I will not be able to take a look at it for a few weeks. There is a chance I will have more time at turn of January and February. Sorry about that...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel