eBPF-based security platform
xdp: class Xen netback interfaces in dom0 as virtual
John Fastabend6a99337e9f64
diff --git a/Documentation/upatches/write/attach-kinds.rst b/Documentation/upatches/write/attach-kinds.rstindex 2c5cf546..bcc200ed 100644--- a/Documentation/upatches/write/attach-kinds.rst+++ b/Documentation/upatches/write/attach-kinds.rst@@ -275,7 +275,8 @@ it.- Hardware-backed NICs and physical devlink ports.* - 2- Virtual- - Software interfaces, host tap devices and devlink representors.+ - Software interfaces, host tap devices, devlink representors and+ Xen netback interfaces in dom0.* - 8- VM- Guest adapters using virtio-net, vmxnet3, Hyper-V netvsc or Xen@@ -288,7 +289,10 @@ it.Bit 4 is not a class, and a mask with it is refused. Loopback has nonative XDP, so it has no class and no mask selects it. Every other-interface has exactly one class. shirudo checks the driver names ``virtio_net``, ``vmxnet3``, ``hv_netvsc``,+interface has exactly one class. A device on the ``xen-backend`` bus,+Xen's netback in dom0, is virtual: it is the host end of a guest's link,+though its driver is named ``vif`` as netfront's is. shirudo then checks+the driver names ``virtio_net``, ``vmxnet3``, ``hv_netvsc``,``xen-netfront`` and ``vif`` for VM adapters, then ``netdevsim``, whichis virtual whatever its devlink port says. Next it uses devlink portflavour: physical ports are network-facing; CPU, DSA, PCI PF, VF, SFdiff --git a/testing/unit/xdp.c b/testing/unit/xdp.cindex a26c03ae..82d3b6b0 100644--- a/testing/unit/xdp.c+++ b/testing/unit/xdp.c@@ -49,6 +49,17 @@ static void netdevsim_is_virtual_whatever_its_port_says(void)EXPECT_UEQ(xdp_device_class(&dev), UPATCH_XDP_VIRTUAL);}+static void xen_netback_is_virtual_though_named_vif(void)+{+ struct xdp_device dev = {};++ memcpy(dev.driver, "vif", sizeof("vif"));+ memcpy(dev.parent_bus, "xen", sizeof("xen"));+ EXPECT_UEQ(xdp_device_class(&dev), UPATCH_XDP_VM);+ memcpy(dev.parent_bus, "xen-backend", sizeof("xen-backend"));+ EXPECT_UEQ(xdp_device_class(&dev), UPATCH_XDP_VIRTUAL);+}+static void veth_peers_are_namespace_aware(void){struct xdp_device devs[4] = {};@@ -321,6 +332,7 @@ static void kernel_discovery_revalidates_devices(void)static const struct unit_case cases[] = {UNIT_CASE(classes_are_exclusive),UNIT_CASE(netdevsim_is_virtual_whatever_its_port_says),+ UNIT_CASE(xen_netback_is_virtual_though_named_vif),UNIT_CASE(veth_peers_are_namespace_aware),UNIT_CASE(veth_without_a_peer_is_not_selected),UNIT_CASE(unresolved_devices_sit_out),diff --git a/util/xdp.c b/util/xdp.cindex aafb0e98..757ebc8c 100644--- a/util/xdp.c+++ b/util/xdp.c@@ -288,6 +288,9 @@ __u32 xdp_device_class(const struct xdp_device *dev)if (dev->flags & IFF_LOOPBACK)return 0;+ /* netback is "vif" too: in dom0 it is the host end of a guest's link. */+ if (!strcmp(dev->parent_bus, "xen-backend"))+ return UPATCH_XDP_VIRTUAL;for (i = 0; i < ARRAY_SIZE(vm_drivers); i++)if (!strcmp(dev->driver, vm_drivers[i]))return UPATCH_XDP_VM;