Page MenuHomeFreeBSD

bhyve/net_backends: Source file descriptors from nvlists
Needs ReviewPublic

Authored by bnovkov on Jan 11 2026, 1:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Feb 21, 8:56 PM
Unknown Object (File)
Sat, Feb 21, 8:56 PM
Unknown Object (File)
Sat, Feb 21, 5:40 AM
Unknown Object (File)
Sat, Feb 21, 5:27 AM
Unknown Object (File)
Fri, Feb 20, 7:50 PM
Unknown Object (File)
Fri, Feb 20, 4:45 PM
Unknown Object (File)
Tue, Feb 17, 8:26 AM
Unknown Object (File)
Mon, Feb 16, 1:22 AM

Details

Reviewers
None
Group Reviewers
bhyve
Summary

This change converts all existing network backends to use the
new, hotplug-friendly file descriptor initialization scheme.
Parts of the backend initialization routines that deal with files
have been factored out and moved to libbhyve and made available
to other hotpluggable device using the pci_init_fds routines.
The backend initialization routines now expect their required file
descriptors to be present in the nvlist object.
The configuration parsing routines were also moved and made available
via libbhyve's pci_parse_config routine.

This is a prerequisite for making the e1000 and virtio-net devices
hotpluggable.

While we're here, add additional failure messages in the backend
initialization routines.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

novel added inline comments.
lib/libbhyve/net_backends.c
54

jemalloc on my system does not like this:

bhyve -c 2 -m 4096 -S -A -I -u -H -P -s 0:0,hostbridge -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd -s 1:0,lpc -s 2:0,e1000,slirp,mac=52:54:00:77:e7:eb,open -s 7:0,virtio-blk,/data/img/ubuntu2510.img -s 5:0,fbuf,tcp=127.0.0.1:5957 ubuntu2510
<jemalloc>: jemalloc_rtree.c:146: Failed assertion: "!dependent || leaf != NULL"

The following workaround fixes that for me:

--- a/lib/libbhyve/net_backends.c
+++ b/lib/libbhyve/net_backends.c
@@ -40,18 +40,22 @@ static int
 slirp_init_fds(nvlist_t *nvl)
 {
        int error;
-       int sockpair_fds[2];
+       int *sockpair_fds = calloc(2, sizeof(int));
+       if (sockpair_fds == NULL) {
+               nvlist_add_stringf(nvl, "error", "Unable to allocate sockpair_fds");
+               return (-1);
+       }
 
        error = socketpair(PF_LOCAL, SOCK_SEQPACKET | SOCK_NONBLOCK, 0,
            sockpair_fds);
        if (error != 0) {
                nvlist_add_stringf(nvl, "error", "Unable to create pipe: %s",
                    strerror(errno));
+               free(sockpair_fds);
                return (error);
        }
 
-       nvlist_move_descriptor_array(nvl, "sockpair", sockpair_fds,
-           sizeof(sockpair_fds));
+       nvlist_move_descriptor_array(nvl, "sockpair", sockpair_fds, 2);
 
        return (0);
 }

Use procdesc(4) to enable slirp backend hotplugging.