Skip to content

eBPF-based security platform

xdp: tell a driver that refuses XDP from one without it

John Fastabendb963ec543a1b
diff --git a/Documentation/operate/troubleshoot/troubleshooting.rst b/Documentation/operate/troubleshoot/troubleshooting.rst
index b34c2dfd..a360ecfe 100644
--- a/Documentation/operate/troubleshoot/troubleshooting.rst
+++ b/Documentation/operate/troubleshoot/troubleshooting.rst
@@ -519,7 +519,8 @@ Causes
category. For an XDP upatch, a line ``XDP: attach <device>`` before
it names a device whose driver refused the program: a NIC added since
the load, or a setting that survived the reboot, in the NIC's firmware
- or the hypervisor, such as LRO or a device without multi-buffer XDP.
+ or the hypervisor, such as LRO, header-data split or a device without
+ multi-buffer XDP.
Action
A reboot restores the same archive and fails the same way. For an XDP
diff --git a/Documentation/reference/cli/upatch-load.rst b/Documentation/reference/cli/upatch-load.rst
index 00e62d38..0069b92d 100644
--- a/Documentation/reference/cli/upatch-load.rst
+++ b/Documentation/reference/cli/upatch-load.rst
@@ -89,7 +89,8 @@ package.
For XDP, the signed device-class mask selects interfaces present in the
initial network namespace at load time, with one endpoint per veth pair.
Each program can produce several ``link_<n>`` pins. Native XDP is
-required: unsupported devices are logged and skipped. An upatch with no
+required: a device without it is logged and skipped. A device that has
+native XDP but refuses it in its current settings is an error. An upatch with no
attachable device yet still loads, and
:doc:`/reference/cli/upatch-reconcile` attaches it when one appears. A
device that is occupied or does not report multi-buffer XDP, and any other
@@ -197,8 +198,8 @@ Exit status and failure categories
``eventlog_full``, ``already_loaded``, ``parser_rejected``,
``signature_rejected``, ``signature_unsupported``, ``lsm_denied``,
``verifier_rejected``, ``attach_target_missing``, ``binary_mismatch``,
-``attach_scope_mismatch``, ``xdp_multibuf_unsupported``, ``tpm_error`` and
-``unknown``.
+``attach_scope_mismatch``, ``xdp_multibuf_unsupported``,
+``xdp_driver_refused``, ``tpm_error`` and ``unknown``.
:doc:`/reference/failure-categories` gives the cause and the action for
each. Handle ``tampered`` as an incident
(:doc:`/operate/troubleshoot/incident-tampered`).
diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rst
index 0ad3f8ff..fa2401b0 100644
--- a/Documentation/reference/failure-categories.rst
+++ b/Documentation/reference/failure-categories.rst
@@ -150,6 +150,17 @@ Categories
- Narrow the signed device-class mask, or configure or change the
device so that it reports multi-buffer XDP. See
:doc:`/upatches/write/attach-kinds`.
+ * - ``xdp_driver_refused``
+ - ``link_create``
+ - ``ENOPROTOOPT``
+ - A selected device reports native XDP, but its driver refused the
+ program with ``EOPNOTSUPP``, which it does when its current
+ settings rule XDP out: ``virtio_net`` while the host does GRO_HW
+ or checksum offload, ``bnxt`` with header-data split or with rx
+ and tx channels not combined. The load was undone.
+ - Change the setting that rules XDP out, which ``bnxt`` names in the
+ kernel log, or narrow the signed device-class mask. See
+ :doc:`/upatches/write/attach-kinds`.
* - ``binary_mismatch``
- ``target_verify``, ``link_create``
- ``ESTALE``
diff --git a/Documentation/upatches/write/attach-kinds.rst b/Documentation/upatches/write/attach-kinds.rst
index 07fc6abb..e394b003 100644
--- a/Documentation/upatches/write/attach-kinds.rst
+++ b/Documentation/upatches/write/attach-kinds.rst
@@ -299,8 +299,13 @@ as interrupted is retried, and an interface renamed or removed during
the snapshot, or a veth whose peer is not in it, is left out rather than
failing the load.
-Links use ``XDP_FLAGS_DRV_MODE``. Devices that refuse native XDP with
-``EOPNOTSUPP``, such as a bridge, are logged and skipped. A device that
+Links use ``XDP_FLAGS_DRV_MODE``. A device without native XDP, which
+refuses with ``EOPNOTSUPP`` and reports no XDP features, such as a
+bridge, is logged and skipped. A device that reports native XDP and refuses
+with ``EOPNOTSUPP`` is refusing in its current settings, as
+``virtio_net`` does while the host does GRO_HW or checksum offload and
+``bnxt`` with header-data split, and fails like any other driver
+refusal, with the load category ``xdp_driver_refused``. A device that
changes or goes away during attachment is skipped too. An XDP program
with no device to attach to still loads: a pin of its own, ``xdp_prog_<i>``,
keeps it, and ``status`` shows it as ``xdp (waiting for a device)``. Other
diff --git a/builtin-upatch.c b/builtin-upatch.c
index 99129a7e..df2064d7 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -1372,8 +1372,11 @@ static int xdp_attach_one(int prog_fd, const struct prog_spec *spec,
if (xdp_multibuf_refused(features))
return XDP_ERR_NO_MULTIBUF;
fd = bpf_link_create(prog_fd, (int)dev->ifindex, BPF_XDP, &opts);
- if (fd == -EOPNOTSUPP)
+ if (xdp_attach_unsupported(fd, features))
return XDP_ATTACH_UNSUPPORTED;
+ /* Not a kernel without the link type: EOPNOTSUPP would read as one. */
+ if (fd == -EOPNOTSUPP)
+ return XDP_ERR_DRIVER_SETTINGS;
if (fd < 0)
return fd;
ret = link_matches_spec(fd, spec, dev->ifindex);
@@ -2313,6 +2316,8 @@ static int __upatch_apply(const char *path, bool verify_only,
cat = "binary_mismatch";
else if (e == EMEDIUMTYPE)
cat = "xdp_multibuf_unsupported";
+ else if (e == ENOPROTOOPT)
+ cat = "xdp_driver_refused";
else if (e == EXDEV)
cat = "attach_scope_mismatch";
else if (e == EOPNOTSUPP)
diff --git a/testing/unit/xdp.c b/testing/unit/xdp.c
index 2b1f588e..9f59f35d 100644
--- a/testing/unit/xdp.c
+++ b/testing/unit/xdp.c
@@ -125,6 +125,7 @@ static void restore_fails_on_a_driver_refusal(void)
static const int skipped[] = { -EBUSY, -EEXIST, -EXDEV, -ENODEV };
static const int refused[] = {
-EINVAL, -ENOSPC, -ERANGE, XDP_ERR_NO_MULTIBUF,
+ XDP_ERR_DRIVER_SETTINGS,
};
/* No device has this index, so the kernel answers ENODEV. */
struct xdp_device *devices = NULL, gone = { .ifindex = 0x7ffffff0 };
@@ -179,6 +180,18 @@ static void multibuf_is_required_of_native_xdp_alone(void)
EXPECT_STREQ(xdp_attach_strerror(-EINVAL), strerror(EINVAL));
}
+static void only_a_device_without_xdp_lacks_it(void)
+{
+ const __u64 basic = NETDEV_XDP_ACT_BASIC;
+
+ EXPECT_TRUE(xdp_attach_unsupported(-EOPNOTSUPP, 0));
+ EXPECT_FALSE(xdp_attach_unsupported(-EOPNOTSUPP, basic));
+ EXPECT_FALSE(xdp_attach_unsupported(-EINVAL, 0));
+ EXPECT_FALSE(xdp_attach_unsupported(0, 0));
+ EXPECT_STREQ(xdp_attach_strerror(XDP_ERR_DRIVER_SETTINGS),
+ "the driver refuses XDP in its current settings");
+}
+
static size_t add_attr(__u8 *buf, size_t len, __u16 type,
const void *value, size_t size)
{
@@ -286,6 +299,7 @@ static const struct unit_case cases[] = {
UNIT_CASE(load_stops_on_an_occupied_device),
UNIT_CASE(multibuf_is_required_of_native_xdp_alone),
UNIT_CASE(uncovered_devices_say_why),
+ UNIT_CASE(only_a_device_without_xdp_lacks_it),
UNIT_CASE(device_features_are_checked),
UNIT_CASE(link_messages_are_checked),
UNIT_CASE(kernel_discovery_revalidates_devices),
diff --git a/util/report.h b/util/report.h
index eae1c9e5..031c8d18 100644
--- a/util/report.h
+++ b/util/report.h
@@ -22,7 +22,8 @@
* Category strings: ok, tampered, keyring_missing, lsm_denied,
* signature_rejected, verifier_rejected, parser_rejected,
* payload_mismatch, already_loaded, already_unloaded, detach_failed,
- * tpm_error, not_initialized, xdp_multibuf_unsupported, unknown.
+ * tpm_error, not_initialized, xdp_multibuf_unsupported,
+ * xdp_driver_refused, unknown.
*/
struct op_report {
bool ok;
diff --git a/util/xdp.c b/util/xdp.c
index e157e219..8205ecc1 100644
--- a/util/xdp.c
+++ b/util/xdp.c
@@ -530,10 +530,17 @@ bool xdp_multibuf_refused(__u64 features)
!(features & NETDEV_XDP_ACT_RX_SG);
}
+bool xdp_attach_unsupported(int err, __u64 features)
+{
+ return err == -EOPNOTSUPP && !(features & NETDEV_XDP_ACT_BASIC);
+}
+
const char *xdp_attach_strerror(int err)
{
if (err == XDP_ERR_NO_MULTIBUF)
return "the device does not report multi-buffer XDP support";
+ if (err == XDP_ERR_DRIVER_SETTINGS)
+ return "the driver refuses XDP in its current settings";
return strerror(-err);
}
diff --git a/util/xdp.h b/util/xdp.h
index 47510672..7d801859 100644
--- a/util/xdp.h
+++ b/util/xdp.h
@@ -15,6 +15,9 @@
/* Every XDP program is loaded with frags, so the device must report them. */
#define XDP_ERR_NO_MULTIBUF (-EMEDIUMTYPE)
+/* A driver with native XDP that rules it out in its current settings. */
+#define XDP_ERR_DRIVER_SETTINGS (-ENOPROTOOPT)
+
struct xdp_device {
char devlink_device[128];
char devlink_bus[128];
@@ -58,6 +61,13 @@ int xdp_device_features(__u32 ifindex, __u64 *features);
/* Native XDP without multi-buffer; a device with neither fails on its own. */
bool xdp_multibuf_refused(__u64 features);
+
+/*
+ * Whether a failed link create says the device has no native XDP. A driver
+ * that has it refuses with the same EOPNOTSUPP in some settings, such as
+ * virtio_net under host GRO_HW or bnxt with header-data split.
+ */
+bool xdp_attach_unsupported(int err, __u64 features);
const char *xdp_attach_strerror(int err);
/*