Skip to content

eBPF-based security platform

xdp: report every driver refusal as xdp_driver_refused

John Fastabend16446b07c90c
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index af31d9e1..9cd764b8 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -205,7 +205,9 @@ signed config image.
and alternate-attachment lockdown; a repeated init adopts the
archived XDP without another event. A veth with a peer MTU of 9000
and the ``virtio_net`` guest adapter at MTU 9000 attach, which only a
- multi-buffer program can. Each case cleans up its state
+ multi-buffer program can. A veth with too few rx queues, which its
+ driver refuses with ``ENOSPC``, fails the load as
+ ``xdp_driver_refused`` and leaves nothing. Each case cleans up its state
so a failed assertion does not contaminate later cases.
* - ``t3112-xdp-reconcile``
- ``upatch reconcile`` attaches a device added after load, adds no
diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rst
index 740bca36..9273d9aa 100644
--- a/Documentation/reference/failure-categories.rst
+++ b/Documentation/reference/failure-categories.rst
@@ -153,11 +153,14 @@ Categories
* - ``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.
+ - The driver of a selected device refused the program in its
+ current settings: ``EOPNOTSUPP`` while it reports native XDP, from
+ ``virtio_net`` while the host does GRO_HW or checksum offload or
+ from ``bnxt`` with header-data split or with rx and tx channels not
+ combined; ``EINVAL`` from ``mlx5`` with LRO or hardware GRO on;
+ ``ENOSPC`` from a veth with fewer rx queues than its peer has tx
+ queues; ``ERANGE`` for an MTU the driver cannot take. The journal
+ names the driver's errno. 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`.
diff --git a/Documentation/upatches/write/attach-kinds.rst b/Documentation/upatches/write/attach-kinds.rst
index dd0ca937..6e747bae 100644
--- a/Documentation/upatches/write/attach-kinds.rst
+++ b/Documentation/upatches/write/attach-kinds.rst
@@ -313,11 +313,14 @@ failing the load. A kernel that does not answer a netlink request within
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
+bridge, is logged and skipped. Any other refusal is the driver ruling XDP
+out in its current settings, and fails with the load category
+``xdp_driver_refused``: ``EOPNOTSUPP`` from a device that reports native
+XDP, as ``virtio_net`` gives while the host does GRO_HW or checksum
+offload and ``bnxt`` with header-data split, ``EINVAL`` from ``mlx5``
+with LRO or hardware GRO on, ``ENOSPC`` from a veth with fewer rx queues
+than its peer has tx queues, and ``ERANGE`` from a driver whose MTU is
+too large. The journal names the driver's own errno. 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 7c186666..8fb08a60 100644
--- a/builtin-upatch.c
+++ b/builtin-upatch.c
@@ -1371,11 +1371,14 @@ static int xdp_attach_one(int prog_fd, const struct prog_spec *spec,
fd = bpf_link_create(prog_fd, (int)dev->ifindex, BPF_XDP, &opts);
if (xdp_attach_unsupported(fd, features))
return XDP_ERR_NO_NATIVE;
- /* Not a kernel without the link type: EOPNOTSUPP would read as one. */
- if (fd == -EOPNOTSUPP)
- return XDP_ERR_DRIVER_SETTINGS;
if (fd == -EBUSY || fd == -EEXIST)
return XDP_ERR_OCCUPIED;
+ /* Not a kernel without the link type: EOPNOTSUPP would read as one. */
+ if (xdp_driver_refused(fd)) {
+ pr_info("XDP: the driver of %s refused the program: %s",
+ dev->name, strerror(-fd));
+ return XDP_ERR_DRIVER_SETTINGS;
+ }
if (fd < 0)
return fd;
ret = link_matches_spec(fd, spec, dev->ifindex);
diff --git a/testing/functional/upatch/t3111-xdp.sh b/testing/functional/upatch/t3111-xdp.sh
index 9045eeb3..02d76b1c 100644
--- a/testing/functional/upatch/t3111-xdp.sh
+++ b/testing/functional/upatch/t3111-xdp.sh
@@ -124,6 +124,17 @@ test_xdp_success 'veth attaches above the single-buffer MTU' '
unload "$NAME"
'
+test_xdp_success 'a driver refusing the program fails the load as xdp_driver_refused' '
+ ip link add xdpa index 30000 numrxqueues 1 type veth \
+ peer name xdpc index 30001 numtxqueues 2 &&
+ ip link set xdpa up && ip link set xdpc up &&
+ category=$("$SHIRUDO_BIN" upatch load "$FIXTURES/$NAME.upatch" \
+ --no-precheck --report=- 2>/dev/null | report_field category) &&
+ [ "$category" = xdp_driver_refused ] &&
+ [ ! -e "$B/$NAME" ] &&
+ [ "$("$H" query xdpa)" = 0 ]
+'
+
test_xdp_success 'both host endpoints of separate cross-namespace pairs attach' '
ip netns add xdp-test-a && ip netns add xdp-test-b &&
ip link add xdpa type veth peer name xdpa-peer netns xdp-test-a &&
diff --git a/testing/unit/xdp.c b/testing/unit/xdp.c
index 919c0e2f..a88965e3 100644
--- a/testing/unit/xdp.c
+++ b/testing/unit/xdp.c
@@ -197,6 +197,18 @@ static void only_a_device_without_xdp_lacks_it(void)
"the link is not on the device and namespace it was made for");
}
+static void a_driver_refusal_is_told_from_other_errors(void)
+{
+ EXPECT_TRUE(xdp_driver_refused(-EOPNOTSUPP));
+ EXPECT_TRUE(xdp_driver_refused(-EINVAL));
+ EXPECT_TRUE(xdp_driver_refused(-ENOSPC));
+ EXPECT_TRUE(xdp_driver_refused(-ERANGE));
+ EXPECT_FALSE(xdp_driver_refused(-EBUSY));
+ EXPECT_FALSE(xdp_driver_refused(-ENOMEM));
+ EXPECT_FALSE(xdp_driver_refused(-EPERM));
+ EXPECT_FALSE(xdp_driver_refused(0));
+}
+
static void attach_errors_never_alias_an_errno(void)
{
EXPECT_EQ(xdp_attach_errno(XDP_ERR_NO_MULTIBUF), -EMEDIUMTYPE);
@@ -318,6 +330,7 @@ static const struct unit_case cases[] = {
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(a_driver_refusal_is_told_from_other_errors),
UNIT_CASE(attach_errors_never_alias_an_errno),
UNIT_CASE(device_features_are_checked),
UNIT_CASE(link_messages_are_checked),
diff --git a/util/xdp.c b/util/xdp.c
index c4b9fede..0be7dc0b 100644
--- a/util/xdp.c
+++ b/util/xdp.c
@@ -536,6 +536,12 @@ bool xdp_attach_unsupported(int err, __u64 features)
return err == -EOPNOTSUPP && !(features & NETDEV_XDP_ACT_BASIC);
}
+bool xdp_driver_refused(int err)
+{
+ return err == -EOPNOTSUPP || err == -EINVAL || err == -ENOSPC ||
+ err == -ERANGE;
+}
+
const char *xdp_attach_strerror(int err)
{
switch (err) {
diff --git a/util/xdp.h b/util/xdp.h
index 1f3af186..f61b376d 100644
--- a/util/xdp.h
+++ b/util/xdp.h
@@ -79,6 +79,13 @@ bool xdp_multibuf_refused(__u64 features);
*/
bool xdp_attach_unsupported(int err, __u64 features);
+/*
+ * Whether a failed link create is the driver refusing in its current
+ * settings: mlx5 with LRO says EINVAL, veth with too few rx queues ENOSPC,
+ * a driver whose MTU is too large ERANGE.
+ */
+bool xdp_driver_refused(int err);
+
/* err is an enum xdp_attach_err or a negative errno. */
const char *xdp_attach_strerror(int err);