VirtualBox

Opened 16 months ago

Closed 16 months ago

Last modified 16 months ago

#21813 closed defect (duplicate)

iPXE ISO with virtio-net drivers fails to work in Virtualbox (nic not detected). Works in QEMU.

Reported by: jimm Owned by:
Component: network Version: VirtualBox-7.0.10
Keywords: virtio-net Cc:
Guest type: other Host type: Mac OS X

Description

Hi,

I am creating a custom iPXE ISO from latest github source, to contain only the virtio-net and also the Intel 82545EM drivers just as a sanity check.

Intel 8254EM works fine in VirtualBox. If I switch to VirtIO NIC then it is not detected. I initially thought it was a problem with the ISO, but it works fine in QEMU.

This is testing on i386 guest, but it's the same with x64 and EFI. If you use the official "all-drivers" ipxe.iso then EFI appears to work, however it is using SNP rather than the virtio driver.

Script to build the ISO:-

#!/bin/bash

# Build test script for ISO

cat <<EOF >/tmp/isoboot.ipxe
#!ipxe
ifstat || echo ifstat error
dhcp || echo dhcp error
prompt
reboot
EOF

cd ~/ipxe/src

# Build ISO with just Intel 82545EM and virtio-net drivers

rm -f bin/82545em--virtio-net.iso
make bin/82545em--virtio-net.iso EMBED=/tmp/isoboot.ipxe DEBUG=intel:3,virtio-net:3

I run it in QEMU using all 3 variants of the virtio driver and it detects the nic fine:-

qemu-system-i386 -boot d -cdrom 82545em--virtio-net.iso -m 64 -nic user,model=virtio-net-pci
qemu-system-i386 -boot d -cdrom 82545em--virtio-net.iso -m 64 -nic user,model=virtio-net-pci-non-transitional
qemu-system-i386 -boot d -cdrom 82545em--virtio-net.iso -m 64 -nic user,model=virtio-net-pci-transitional

Attached: Screenshot of failure. Thanks in advance.

Attachments (1)

vbox-virtio-fail.png (59.1 KB ) - added by jimm 16 months ago.

Download all attachments as: .zip

Change History (7)

by jimm, 16 months ago

Attachment: vbox-virtio-fail.png added

comment:1 by aeichner, 16 months ago

Resolution: invalid
Status: newclosed

This appears to be a bug in ipxe. Our virtio emulation is a bit more strict when it comes to register access widths and alignments. The following patch in ipxe fixes the issue for me:

diff --git a/src/drivers/bus/virtio-pci.c b/src/drivers/bus/virtio-pci.c
index 8b34c727..3fc93a90 100644
--- a/src/drivers/bus/virtio-pci.c
+++ b/src/drivers/bus/virtio-pci.c
@@ -230,10 +230,10 @@ u32 vpm_ioread32(struct virtio_pci_modern_device *vdev,
     uint32_t data;
     switch (region->flags & VIRTIO_PCI_REGION_TYPE_MASK) {
     case VIRTIO_PCI_REGION_MEMORY:
-        data = readw(region->base + offset);
+        data = readl(region->base + offset);
         break;
     case VIRTIO_PCI_REGION_PORT:
-        data = inw(region->base + offset);
+        data = inl(region->base + offset);
         break;
     case VIRTIO_PCI_REGION_PCI_CONFIG:
         prep_pci_cfg_cap(vdev, region, offset, 4);

A bit of technical background. VirtIO states that register accesses must be aligned and sized to the natural register width. vpm_ioread32() is supposed to read a 32-bit register but the code apparently tries to read 16-bit only which makes our emulation ignore it. qemu might be a bit more relaxed in that regard but it is clearly a bug in ipxe causing the device to not transition to the modern 1.0 Virtio standard but remaining in legacy mode. This should probably be reported to the ipxe maintainers (might do it myself).

Closing the bug as invalid, as the issue is not on our end.

comment:2 by aeichner, 16 months ago

Resolution: invalid
Status: closedreopened

Actually there might be more to it as you wrote that the device is not detected at all initially and your screenshot doesn't show the debug line I get here. This part might be a duplicate of #21516 which is fixed internally already. There PCI IDs were wrong causing the guest not to detect virtio-net devices at all. So there are multiple issues here. You could try the latest testbuild from here which should have the fix from #21516.

comment:3 by aeichner, 16 months ago

Resolution: duplicate
Status: reopenedclosed

comment:4 by jimm, 16 months ago

Hi,

I can happily confirm that by applying the iPXE patch you provided - using VirtualBox RELEASE 7.0.10 this works. Also iPXE patch does not break qemu.

I'll try and test later with/without this iPXE patch against the VirtualBox TESTBUILD, and will pass this patch onto the iPXE developers.

Thanks for your help, much appreciated.

P.S. apologies for screenshot, it was taken before I turned on debug flags and I forogt to update it.

Last edited 16 months ago by jimm (previous) (diff)

comment:5 by aeichner, 16 months ago

Ah okay, I already opened a pull request on github with the patch, see https://github.com/ipxe/ipxe/pull/1028 . No need to do anything on your end.

comment:6 by jimm, 16 months ago

Hi Alex,

With regards to i386 or x64 BIOS - virtio now detects and works fine, however there appears to be some sort of lock in VirtualBox. If I run my test ISO and then close the window it can take up to 2 minutes to close. If I do a "poweroff" command from iPXE console the same thing happens, ~2 minutes to power off. This only happens if my NIC is virtio-net, any other NIC results in instant power off as one would expect.

EFI ISOs don't work with virtio and surprisingly intel drivers, i386 or x64. But they do with PCnet32! Intel results in a freeze as iPXE loads, virtio no detection as with the BIOS issue you fixed. I am not sure if a different code path and a similar fix somwhere else?. I realise as this is EFI it might of already been fixed with your other #21516 ticket so will let you know. I've been testing everything with current release VirtualBox, and am about to now do it all again using the testbuild.

Essence of how I am building the ISOs (with your https://github.com/ipxe/ipxe/pull/1028 PR applied):-

DEBUG_PARAMS=virtio-net:3,intel:3
DRIVERS=virtio-net--82545em--pcnet32
make bin-i386-pcbios/${DRIVERS}.iso EMBED=/tmp/isoboot.ipxe DEBUG=${DEBUG_PARAMS}
make bin-x86_64-pcbios/${DRIVERS}.iso EMBED=/tmp/isoboot.ipxe DEBUG=${DEBUG_PARAMS}
make bin-i386-efi/${DRIVERS}.iso EMBED=/tmp/isoboot.ipxe DEBUG=${DEBUG_PARAMS}
make bin-x86_64-efi/${DRIVERS}.iso EMBED=/tmp/isoboot.ipxe DEBUG=${DEBUG_PARAMS}
Last edited 16 months ago by jimm (previous) (diff)
Note: See TracTickets for help on using tickets.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette