PV network interfaces on NetBSD-99.77 domu guests fail to operate

From: Brian Buhrow <buhrow_at_nfbcal.org>
Date: Fri, 03 Jun 2022 21:51:50 UTC
	hello. As part of my update to xen-4.16 and FreeBSD-13.1 as dom0, I'm trying to get some
guests running NetBSD-99.77 working.  These guests have been working fine with xen-4.14 and
FreeBSD-12.2, with the patch shown below applied.

What happens when these guests boot is that the network interface attaches, but then netback.c
decides something is wrong and it shuts the xnb interface down for that domain, detaching it
from the domu's perspective.  I can reproduce this behavior over and over again by using the xl
network-detach and network-attach commands to reinitialize the xnb and xennet interfaces on
host and guest respectively to show the behavior.
	I downloaded the the latest FreeBSD-13-stable sources to see if the patch shown below was
applied.  It is.  I'm not sure if it made it into the 13.1 binary release, but it seems like it
should be there.  
As a data point, FreeBSD guests seem to work fine, as do NetBSD-5.2 guests.
Is this a casewhere the patch is in the current code, but not the binary release or is this a
diferent problem with a similar symptom?

-thanks
-Brian

(Output on the dom0 side when I attach a network interface to the relevant guest.)
root@xen-lothlorien:/var/xen/nfbcal/loth_9 # xl network-attach 6 'mac=00:4e:46:42:42:cc'
ifconfig: interface xenbr0 does not exist
ifconfig: 'mtu' requires argument
libxl: error: libxl_exec.c:118:libxl_report_child_exitstatus:
/usr/local/etc/xen/scripts/vif-bridge
/local/domain/0/backend/vif/6/4 [5085] exited with error status 1
libxl: error: libxl_device.c:1412:device_addrm_aocomplete: Domain 6:Unable to add vif with id 4
libxl_device_nic_add failed.

(Output from dom0/FreeBSD-13.1  kernel when above command is issued.)
Jun  3 14:24:48 xen-lothlorien kernel: xnb(xnb_probe:1123): Claiming device 5, xnb
Jun  3 14:24:48 xen-lothlorien kernel: xnb(xnb_attach:1267): Attaching to backend/vif/6/4
Jun  3 14:24:48 xen-lothlorien kernel: xnb(xnb_frontend_changed:1391): frontend_state=Initialising, xnb_state=InitWait
Jun  3 14:24:48 xen-lothlorien kernel: xnb(xnb_frontend_changed:1391): frontend_state=Initialised, xnb_state=InitWait
Jun  3 14:24:48 xen-lothlorien kernel: xnb5: Error 2 Unable to retrieve ring information from frontend /local/domain/6/device/vif/4.  Unable to connect.
Jun  3 14:24:48 xen-lothlorien kernel: xnb5: Fatal error. Transitioning to Closing State
Jun  3 14:24:48 xen-lothlorien kernel: xnb(xnb_frontend_changed:1391): frontend_state=Closed, xnb_state=Closing

(Output from domu host when network interface is attached.)

Script started on Fri Jun  3 14:22:00 2022
[ 6810.3600640] xenbus0: can't get state for device/suspend/event-channel (2)
[ 6810.3600640] xennet0 at xenbus0 id 4: Xen Virtual Network Interface
[ 6810.3700593] xennet0: backend features 0x6<SG,RX-COPY>
[ 6810.3700593] xennet0: MAC address 00:4e:46:42:42:cc
[ 6810.3800626] xenbus0: can't get state for device/suspend/event-channel (2)
[ 6810.3900596] xenbus0: can't get state for device/suspend/event-channel (2)
[ 6810.3900596] xennet0: detached


<Cut here for patch I referenced earlier.)
diff --git a/sys/dev/xen/netback/netback.c b/sys/dev/xen/netback/netback.c
index 44159f60d996..29efd76430c7 100644
--- a/sys/dev/xen/netback/netback.c
+++ b/sys/dev/xen/netback/netback.c
@@ -1392,8 +1392,8 @@ xnb_frontend_changed(device_t dev, XenbusState frontend_state)
 
 	switch (frontend_state) {
 	case XenbusStateInitialising:
-		break;
 	case XenbusStateInitialised:
+		break;
 	case XenbusStateConnected:
 		xnb_connect(xnb);
 		break;