linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order
@ 2020-12-03 21:35 Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback Toke Høiland-Jørgensen
                   ` (6 more replies)
  0 siblings, 7 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

This series restores the test_offload.py selftest to working order. It seems a
number of subtle behavioural changes have crept into various subsystems which
broke test_offload.py in a number of ways. Most of these are fairly benign
changes where small adjustments to the test script seems to be the best fix, but
one is an actual kernel bug that I've observed in the wild caused by a bad
interaction between xdp_attachment_flags_ok() and the rework of XDP program
handling in the core netdev code.

Patch 1 fixes the bug by removing xdp_attachment_flags_ok(), and the reminder of
the patches are adjustments to test_offload.py, including a new feature for
netdevsim to force a BPF verification fail. Please see the individual patches
for details.

---

Toke Høiland-Jørgensen (7):
      xdp: remove the xdp_attachment_flags_ok() callback
      selftests/bpf/test_offload.py: Remove check for program load flags match
      netdevsim: Add debugfs toggle to reject BPF programs in verifier
      selftests/bpf/test_offload.py: only check verifier log on verification fails
      selftests/bpf/test_offload.py: fix expected case of extack messages
      selftests/bpf/test_offload.py: reset ethtool features after failed setting
      selftests/bpf/test_offload.py: filter bpftool internal map when counting maps


 .../ethernet/netronome/nfp/nfp_net_common.c   |  6 ---
 drivers/net/ethernet/ti/cpsw_priv.c           |  3 --
 drivers/net/netdevsim/bpf.c                   | 15 ++++--
 drivers/net/netdevsim/netdevsim.h             |  1 +
 include/net/xdp.h                             |  2 -
 net/core/xdp.c                                | 12 -----
 tools/testing/selftests/bpf/test_offload.py   | 49 +++++++++----------
 7 files changed, 35 insertions(+), 53 deletions(-)


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback
  2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
@ 2020-12-03 21:35 ` Toke Høiland-Jørgensen
  2020-12-04  1:42   ` Jakub Kicinski
  2020-12-03 21:35 ` [PATCH bpf 2/7] selftests/bpf/test_offload.py: Remove check for program load flags match Toke Høiland-Jørgensen
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

From: Toke Høiland-Jørgensen <toke@redhat.com>

Since commit 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF
programs in net_device"), the XDP program attachment info is now maintained
in the core code. This interacts badly with the xdp_attachment_flags_ok()
check that prevents unloading an XDP program with different load flags than
it was loaded with. In practice, two kinds of failures are seen:

- An XDP program loaded without specifying a mode (and which then ends up
  in driver mode) cannot be unloaded if the program mode is specified on
  unload.

- The dev_xdp_uninstall() hook always calls the driver callback with the
  mode set to the type of the program but an empty flags argument, which
  means the flags_ok() check prevents the program from being removed,
  leading to bpf prog reference leaks.

Since we offloaded and non-offloaded programs can co-exist there doesn't
really seem to be any reason for the check anyway, and it's only used in
three drivers so let's just get rid of the callback entirely.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 .../net/ethernet/netronome/nfp/nfp_net_common.c    |    6 ------
 drivers/net/ethernet/ti/cpsw_priv.c                |    3 ---
 drivers/net/netdevsim/bpf.c                        |    3 ---
 include/net/xdp.h                                  |    2 --
 net/core/xdp.c                                     |   12 ------------
 5 files changed, 26 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
index b150da43adb2..437226866ce8 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_common.c
@@ -3562,9 +3562,6 @@ static int nfp_net_xdp_setup_drv(struct nfp_net *nn, struct netdev_bpf *bpf)
 	struct nfp_net_dp *dp;
 	int err;
 
-	if (!xdp_attachment_flags_ok(&nn->xdp, bpf))
-		return -EBUSY;
-
 	if (!prog == !nn->dp.xdp_prog) {
 		WRITE_ONCE(nn->dp.xdp_prog, prog);
 		xdp_attachment_setup(&nn->xdp, bpf);
@@ -3593,9 +3590,6 @@ static int nfp_net_xdp_setup_hw(struct nfp_net *nn, struct netdev_bpf *bpf)
 {
 	int err;
 
-	if (!xdp_attachment_flags_ok(&nn->xdp_hw, bpf))
-		return -EBUSY;
-
 	err = nfp_app_xdp_offload(nn->app, nn, bpf->prog, bpf->extack);
 	if (err)
 		return err;
diff --git a/drivers/net/ethernet/ti/cpsw_priv.c b/drivers/net/ethernet/ti/cpsw_priv.c
index 31c5e36ff706..424e644724e4 100644
--- a/drivers/net/ethernet/ti/cpsw_priv.c
+++ b/drivers/net/ethernet/ti/cpsw_priv.c
@@ -1265,9 +1265,6 @@ static int cpsw_xdp_prog_setup(struct cpsw_priv *priv, struct netdev_bpf *bpf)
 	if (!priv->xdpi.prog && !prog)
 		return 0;
 
-	if (!xdp_attachment_flags_ok(&priv->xdpi, bpf))
-		return -EBUSY;
-
 	WRITE_ONCE(priv->xdp_prog, prog);
 
 	xdp_attachment_setup(&priv->xdpi, bpf);
diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c
index 2e90512f3bbe..85546664bdd5 100644
--- a/drivers/net/netdevsim/bpf.c
+++ b/drivers/net/netdevsim/bpf.c
@@ -190,9 +190,6 @@ nsim_xdp_set_prog(struct netdevsim *ns, struct netdev_bpf *bpf,
 {
 	int err;
 
-	if (!xdp_attachment_flags_ok(xdp, bpf))
-		return -EBUSY;
-
 	if (bpf->command == XDP_SETUP_PROG && !ns->bpf_xdpdrv_accept) {
 		NSIM_EA(bpf->extack, "driver XDP disabled in DebugFS");
 		return -EOPNOTSUPP;
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 3814fb631d52..9dab2bc6f187 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -240,8 +240,6 @@ struct xdp_attachment_info {
 };
 
 struct netdev_bpf;
-bool xdp_attachment_flags_ok(struct xdp_attachment_info *info,
-			     struct netdev_bpf *bpf);
 void xdp_attachment_setup(struct xdp_attachment_info *info,
 			  struct netdev_bpf *bpf);
 
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 491ad569a79c..d900cebc0acd 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -403,18 +403,6 @@ void __xdp_release_frame(void *data, struct xdp_mem_info *mem)
 }
 EXPORT_SYMBOL_GPL(__xdp_release_frame);
 
-bool xdp_attachment_flags_ok(struct xdp_attachment_info *info,
-			     struct netdev_bpf *bpf)
-{
-	if (info->prog && (bpf->flags ^ info->flags) & XDP_FLAGS_MODES) {
-		NL_SET_ERR_MSG(bpf->extack,
-			       "program loaded with different flags");
-		return false;
-	}
-	return true;
-}
-EXPORT_SYMBOL_GPL(xdp_attachment_flags_ok);
-
 void xdp_attachment_setup(struct xdp_attachment_info *info,
 			  struct netdev_bpf *bpf)
 {


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH bpf 2/7] selftests/bpf/test_offload.py: Remove check for program load flags match
  2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback Toke Høiland-Jørgensen
@ 2020-12-03 21:35 ` Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier Toke Høiland-Jørgensen
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

From: Toke Høiland-Jørgensen <toke@redhat.com>

Since we just removed the xdp_attachment_flags_ok() callback, also remove
the check for it in test_offload.py

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/testing/selftests/bpf/test_offload.py |   18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 43c9cda199b8..7afe259c785f 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -716,14 +716,6 @@ def test_multi_prog(simdev, sim, obj, modename, modeid):
     fail(ret == 0, "Replaced one of programs without -force")
     check_extack(err, "XDP program already attached.", args)
 
-    if modename == "" or modename == "drv":
-        othermode = "" if modename == "drv" else "drv"
-        start_test("Test multi-attachment XDP - detach...")
-        ret, _, err = sim.unset_xdp(othermode, force=True,
-                                    fail=False, include_stderr=True)
-        fail(ret == 0, "Removed program with a bad mode")
-        check_extack(err, "program loaded with different flags.", args)
-
     sim.unset_xdp("offload")
     xdp = sim.ip_link_show(xdp=True)["xdp"]
     offloaded = sim.dfs_read("bpf_offloaded_id")
@@ -1001,16 +993,6 @@ try:
     check_extack(err,
                  "native and generic XDP can't be active at the same time.",
                  args)
-    ret, _, err = sim.set_xdp(obj, "", force=True,
-                              fail=False, include_stderr=True)
-    fail(ret == 0, "Replaced XDP program with a program in different mode")
-    check_extack(err, "program loaded with different flags.", args)
-
-    start_test("Test XDP prog remove with bad flags...")
-    ret, _, err = sim.unset_xdp("", force=True,
-                                fail=False, include_stderr=True)
-    fail(ret == 0, "Removed program with a bad mode")
-    check_extack(err, "program loaded with different flags.", args)
 
     start_test("Test MTU restrictions...")
     ret, _ = sim.set_mtu(9000, fail=False)


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH bpf 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier
  2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 2/7] selftests/bpf/test_offload.py: Remove check for program load flags match Toke Høiland-Jørgensen
@ 2020-12-03 21:35 ` Toke Høiland-Jørgensen
  2020-12-04  1:44   ` Jakub Kicinski
  2020-12-03 21:35 ` [PATCH bpf 4/7] selftests/bpf/test_offload.py: only check verifier log on verification fails Toke Høiland-Jørgensen
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

From: Toke Høiland-Jørgensen <toke@redhat.com>

This adds a new debugfs toggle ('bpf_bind_verifier_accept') that can be
used to make netdevsim reject BPF programs from being accepted by the
verifier. If this toggle (which defaults to true) is set to false,
nsim_bpf_verify_insn() will return EOPNOTSUPP on the last
instruction (after outputting the 'Hello from netdevsim' verifier message).

This makes it possible to check the verification callback in the driver
from test_offload.py in selftests, since the verifier now clears the
verifier log on a successful load, hiding the message from the driver.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 drivers/net/netdevsim/bpf.c       |   12 ++++++++++--
 drivers/net/netdevsim/netdevsim.h |    1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/netdevsim/bpf.c b/drivers/net/netdevsim/bpf.c
index 85546664bdd5..90aafb56f140 100644
--- a/drivers/net/netdevsim/bpf.c
+++ b/drivers/net/netdevsim/bpf.c
@@ -63,15 +63,20 @@ static int
 nsim_bpf_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn)
 {
 	struct nsim_bpf_bound_prog *state;
+	int ret = 0;
 
 	state = env->prog->aux->offload->dev_priv;
 	if (state->nsim_dev->bpf_bind_verifier_delay && !insn_idx)
 		msleep(state->nsim_dev->bpf_bind_verifier_delay);
 
-	if (insn_idx == env->prog->len - 1)
+	if (insn_idx == env->prog->len - 1) {
 		pr_vlog(env, "Hello from netdevsim!\n");
 
-	return 0;
+		if (!state->nsim_dev->bpf_bind_verifier_accept)
+			ret = -EOPNOTSUPP;
+	}
+
+	return ret;
 }
 
 static int nsim_bpf_finalize(struct bpf_verifier_env *env)
@@ -595,6 +600,9 @@ int nsim_bpf_dev_init(struct nsim_dev *nsim_dev)
 			    &nsim_dev->bpf_bind_accept);
 	debugfs_create_u32("bpf_bind_verifier_delay", 0600, nsim_dev->ddir,
 			   &nsim_dev->bpf_bind_verifier_delay);
+	nsim_dev->bpf_bind_verifier_accept = true;
+	debugfs_create_bool("bpf_bind_verifier_accept", 0600, nsim_dev->ddir,
+			    &nsim_dev->bpf_bind_verifier_accept);
 	return 0;
 }
 
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 827fc80f50a0..d1d329af3e61 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -190,6 +190,7 @@ struct nsim_dev {
 	struct bpf_offload_dev *bpf_dev;
 	bool bpf_bind_accept;
 	u32 bpf_bind_verifier_delay;
+	bool bpf_bind_verifier_accept;
 	struct dentry *ddir_bpf_bound_progs;
 	u32 prog_id_gen;
 	struct list_head bpf_bound_progs;


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH bpf 4/7] selftests/bpf/test_offload.py: only check verifier log on verification fails
  2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
                   ` (2 preceding siblings ...)
  2020-12-03 21:35 ` [PATCH bpf 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier Toke Høiland-Jørgensen
@ 2020-12-03 21:35 ` Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 5/7] selftests/bpf/test_offload.py: fix expected case of extack messages Toke Høiland-Jørgensen
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

From: Toke Høiland-Jørgensen <toke@redhat.com>

Since 6f8a57ccf85 ("bpf: Make verifier log more relevant by default"), the
verifier discards log messages for successfully-verified programs. This
broke test_offload.py which is looking for a verification message from the
driver callback. Change test_offload.py to use the toggle in netdevsim to
make the verification fail before looking for the verification message.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/testing/selftests/bpf/test_offload.py |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 7afe259c785f..6f8ff2f27027 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -905,11 +905,18 @@ try:
 
     sim.tc_flush_filters()
 
+    start_test("Test TC offloads failure...")
+    sim.dfs["dev/bpf_bind_verifier_accept"] = 0
+    ret, _, err = sim.cls_bpf_add_filter(obj, verbose=True, skip_sw=True,
+                                         fail=False, include_stderr=True)
+    fail(ret == 0, "TC filter did not reject with TC offloads enabled")
+    check_verifier_log(err, "[netdevsim] Hello from netdevsim!")
+    sim.dfs["dev/bpf_bind_verifier_accept"] = 1
+
     start_test("Test TC offloads work...")
     ret, _, err = sim.cls_bpf_add_filter(obj, verbose=True, skip_sw=True,
                                          fail=False, include_stderr=True)
     fail(ret != 0, "TC filter did not load with TC offloads enabled")
-    check_verifier_log(err, "[netdevsim] Hello from netdevsim!")
 
     start_test("Test TC offload basics...")
     dfs = simdev.dfs_get_bound_progs(expected=1)
@@ -1026,6 +1033,15 @@ try:
     rm("/sys/fs/bpf/offload")
     sim.wait_for_flush()
 
+    start_test("Test XDP load failure...")
+    sim.dfs["dev/bpf_bind_verifier_accept"] = 0
+    ret, _, err = bpftool_prog_load("sample_ret0.o", "/sys/fs/bpf/offload",
+                                 dev=sim['ifname'], fail=False, include_stderr=True)
+    fail(ret == 0, "verifier should fail on load")
+    check_verifier_log(err, "[netdevsim] Hello from netdevsim!")
+    sim.dfs["dev/bpf_bind_verifier_accept"] = 1
+    sim.wait_for_flush()
+
     start_test("Test XDP offload...")
     _, _, err = sim.set_xdp(obj, "offload", verbose=True, include_stderr=True)
     ipl = sim.ip_link_show(xdp=True)
@@ -1033,7 +1049,6 @@ try:
     progs = bpftool_prog_list(expected=1)
     prog = progs[0]
     fail(link_xdp["id"] != prog["id"], "Loaded program has wrong ID")
-    check_verifier_log(err, "[netdevsim] Hello from netdevsim!")
 
     start_test("Test XDP offload is device bound...")
     dfs = simdev.dfs_get_bound_progs(expected=1)


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH bpf 5/7] selftests/bpf/test_offload.py: fix expected case of extack messages
  2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
                   ` (3 preceding siblings ...)
  2020-12-03 21:35 ` [PATCH bpf 4/7] selftests/bpf/test_offload.py: only check verifier log on verification fails Toke Høiland-Jørgensen
@ 2020-12-03 21:35 ` Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 6/7] selftests/bpf/test_offload.py: reset ethtool features after failed setting Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 7/7] selftests/bpf/test_offload.py: filter bpftool internal map when counting maps Toke Høiland-Jørgensen
  6 siblings, 0 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

From: Toke Høiland-Jørgensen <toke@redhat.com>

Commit 7f0a838254bd ("bpf, xdp: Maintain info on attached XDP BPF programs
in net_device") changed the case of some of the extack messages being
returned when attaching of XDP programs failed. This broke test_offload.py,
so let's fix the test to reflect this.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/testing/selftests/bpf/test_offload.py |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 6f8ff2f27027..5b0fe8e0b2d2 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -998,7 +998,7 @@ try:
                               fail=False, include_stderr=True)
     fail(ret == 0, "Replaced XDP program with a program in different mode")
     check_extack(err,
-                 "native and generic XDP can't be active at the same time.",
+                 "Native and generic XDP can't be active at the same time.",
                  args)
 
     start_test("Test MTU restrictions...")
@@ -1029,7 +1029,7 @@ try:
     offload = bpf_pinned("/sys/fs/bpf/offload")
     ret, _, err = sim.set_xdp(offload, "drv", fail=False, include_stderr=True)
     fail(ret == 0, "attached offloaded XDP program to drv")
-    check_extack(err, "using device-bound program without HW_MODE flag is not supported.", args)
+    check_extack(err, "Using device-bound program without HW_MODE flag is not supported.", args)
     rm("/sys/fs/bpf/offload")
     sim.wait_for_flush()
 


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH bpf 6/7] selftests/bpf/test_offload.py: reset ethtool features after failed setting
  2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
                   ` (4 preceding siblings ...)
  2020-12-03 21:35 ` [PATCH bpf 5/7] selftests/bpf/test_offload.py: fix expected case of extack messages Toke Høiland-Jørgensen
@ 2020-12-03 21:35 ` Toke Høiland-Jørgensen
  2020-12-03 21:35 ` [PATCH bpf 7/7] selftests/bpf/test_offload.py: filter bpftool internal map when counting maps Toke Høiland-Jørgensen
  6 siblings, 0 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

From: Toke Høiland-Jørgensen <toke@redhat.com>

When setting the ethtool feature flag fails (as expected for the test), the
kernel now tracks that the feature was requested to be 'off' and refuses to
subsequently disable it again. So reset it back to 'on' so a subsequent
disable (that's not supposed to fail) can succeed.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/testing/selftests/bpf/test_offload.py |    1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 5b0fe8e0b2d2..f861503433c9 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -940,6 +940,7 @@ try:
     start_test("Test disabling TC offloads is rejected while filters installed...")
     ret, _ = sim.set_ethtool_tc_offloads(False, fail=False)
     fail(ret == 0, "Driver should refuse to disable TC offloads with filters installed...")
+    sim.set_ethtool_tc_offloads(True)
 
     start_test("Test qdisc removal frees things...")
     sim.tc_flush_filters()


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH bpf 7/7] selftests/bpf/test_offload.py: filter bpftool internal map when counting maps
  2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
                   ` (5 preceding siblings ...)
  2020-12-03 21:35 ` [PATCH bpf 6/7] selftests/bpf/test_offload.py: reset ethtool features after failed setting Toke Høiland-Jørgensen
@ 2020-12-03 21:35 ` Toke Høiland-Jørgensen
  6 siblings, 0 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-03 21:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

From: Toke Høiland-Jørgensen <toke@redhat.com>

A few of the tests in test_offload.py expects to see a certain number of
maps created, and checks this by counting the number of maps returned by
bpftool. There is already a filter that will remove any maps already there
at the beginning of the test, but bpftool now creates a map for the PID
iterator rodata on each invocation, which makes the map count wrong. Fix
this by also filtering the pid_iter.rodata map by name when counting.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/testing/selftests/bpf/test_offload.py |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index f861503433c9..be2c7e3f57c4 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -184,9 +184,7 @@ def bpftool_prog_list(expected=None, ns=""):
 def bpftool_map_list(expected=None, ns=""):
     _, maps = bpftool("map show", JSON=True, ns=ns, fail=True)
     # Remove the base maps
-    for m in base_maps:
-        if m in maps:
-            maps.remove(m)
+    maps = [m for m in maps if m not in base_maps and m.get('name') not in base_map_names]
     if expected is not None:
         if len(maps) != expected:
             fail(True, "%d BPF maps loaded, expected %d" %
@@ -764,6 +762,9 @@ ret, progs = bpftool("prog", fail=False)
 skip(ret != 0, "bpftool not installed")
 base_progs = progs
 _, base_maps = bpftool("map")
+base_map_names = [
+    'pid_iter.rodata' # created on each bpftool invocation
+]
 
 # Check netdevsim
 ret, out = cmd("modprobe netdevsim", fail=False)


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback
  2020-12-03 21:35 ` [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback Toke Høiland-Jørgensen
@ 2020-12-04  1:42   ` Jakub Kicinski
  2020-12-04  9:38     ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 14+ messages in thread
From: Jakub Kicinski @ 2020-12-04  1:42 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

On Thu, 03 Dec 2020 22:35:18 +0100 Toke Høiland-Jørgensen wrote:
> Since we offloaded and non-offloaded programs can co-exist there doesn't
> really seem to be any reason for the check anyway, and it's only used in
> three drivers so let's just get rid of the callback entirely.

I don't remember exactly now, but I think the concern was that using 
the unspecified mode is pretty ambiguous when interface has multiple
programs attached.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH bpf 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier
  2020-12-03 21:35 ` [PATCH bpf 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier Toke Høiland-Jørgensen
@ 2020-12-04  1:44   ` Jakub Kicinski
  2020-12-04  9:39     ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 14+ messages in thread
From: Jakub Kicinski @ 2020-12-04  1:44 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

On Thu, 03 Dec 2020 22:35:20 +0100 Toke Høiland-Jørgensen wrote:
> diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
> index 827fc80f50a0..d1d329af3e61 100644
> --- a/drivers/net/netdevsim/netdevsim.h
> +++ b/drivers/net/netdevsim/netdevsim.h
> @@ -190,6 +190,7 @@ struct nsim_dev {
>  	struct bpf_offload_dev *bpf_dev;
>  	bool bpf_bind_accept;
>  	u32 bpf_bind_verifier_delay;
> +	bool bpf_bind_verifier_accept;
>  	struct dentry *ddir_bpf_bound_progs;

nit: if you respin please reorder the bpf_bind_verifier_* fields so
that the structure packs better.

Acked-by: Jakub Kicinski <kuba@kernel.org>

Thanks for fixing this test!

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback
  2020-12-04  1:42   ` Jakub Kicinski
@ 2020-12-04  9:38     ` Toke Høiland-Jørgensen
  2020-12-04 16:48       ` Jakub Kicinski
  0 siblings, 1 reply; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-04  9:38 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

Jakub Kicinski <kuba@kernel.org> writes:

> On Thu, 03 Dec 2020 22:35:18 +0100 Toke Høiland-Jørgensen wrote:
>> Since we offloaded and non-offloaded programs can co-exist there doesn't
>> really seem to be any reason for the check anyway, and it's only used in
>> three drivers so let's just get rid of the callback entirely.
>
> I don't remember exactly now, but I think the concern was that using 
> the unspecified mode is pretty ambiguous when interface has multiple
> programs attached.

Right. I did scratch my head a bit for why the check was there in the
first place, but that makes sense, actually :)

So how about we disallow unload without specifying a mode, but only if
more than one program is loaded? Since the core code tracks all the
programs now, this could just be enforced there and we would avoid all
the weird interactions with the drivers trying to enforce it...

-Toke


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH bpf 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier
  2020-12-04  1:44   ` Jakub Kicinski
@ 2020-12-04  9:39     ` Toke Høiland-Jørgensen
  0 siblings, 0 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-04  9:39 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

Jakub Kicinski <kuba@kernel.org> writes:

> On Thu, 03 Dec 2020 22:35:20 +0100 Toke Høiland-Jørgensen wrote:
>> diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
>> index 827fc80f50a0..d1d329af3e61 100644
>> --- a/drivers/net/netdevsim/netdevsim.h
>> +++ b/drivers/net/netdevsim/netdevsim.h
>> @@ -190,6 +190,7 @@ struct nsim_dev {
>>  	struct bpf_offload_dev *bpf_dev;
>>  	bool bpf_bind_accept;
>>  	u32 bpf_bind_verifier_delay;
>> +	bool bpf_bind_verifier_accept;
>>  	struct dentry *ddir_bpf_bound_progs;
>
> nit: if you respin please reorder the bpf_bind_verifier_* fields so
> that the structure packs better.

Ah, good point, will do!

> Acked-by: Jakub Kicinski <kuba@kernel.org>
>
> Thanks for fixing this test!

You're welcome :)

I'll see if I can't get our CI people to also run it regularly so we can
avoid it regressing again...

-Toke


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback
  2020-12-04  9:38     ` Toke Høiland-Jørgensen
@ 2020-12-04 16:48       ` Jakub Kicinski
  2020-12-04 17:12         ` Toke Høiland-Jørgensen
  0 siblings, 1 reply; 14+ messages in thread
From: Jakub Kicinski @ 2020-12-04 16:48 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

On Fri, 04 Dec 2020 10:38:06 +0100 Toke Høiland-Jørgensen wrote:
> Jakub Kicinski <kuba@kernel.org> writes:
> > On Thu, 03 Dec 2020 22:35:18 +0100 Toke Høiland-Jørgensen wrote:  
> >> Since we offloaded and non-offloaded programs can co-exist there doesn't
> >> really seem to be any reason for the check anyway, and it's only used in
> >> three drivers so let's just get rid of the callback entirely.  
> >
> > I don't remember exactly now, but I think the concern was that using 
> > the unspecified mode is pretty ambiguous when interface has multiple
> > programs attached.  
> 
> Right. I did scratch my head a bit for why the check was there in the
> first place, but that makes sense, actually :)
> 
> So how about we disallow unload without specifying a mode, but only if
> more than one program is loaded?

Are you including replacing as a form of unload? :)

IMHO the simpler the definition of the API / constraint the better.
"You must specify the same flags" is pretty simple, as is copying 
the old behavior rather than trying to come up with new rules.

But up to you, I don't mind either way, really..

> Since the core code tracks all the programs now, this could just be
> enforced there and we would avoid all the weird interactions with the
> drivers trying to enforce it...

Yup, enforcing in the core now would make perfect sense.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback
  2020-12-04 16:48       ` Jakub Kicinski
@ 2020-12-04 17:12         ` Toke Høiland-Jørgensen
  0 siblings, 0 replies; 14+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-12-04 17:12 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Daniel Borkmann, Alexei Starovoitov,
	Andrii Nakryiko, Martin KaFai Lau, Song Liu, Yonghong Song,
	John Fastabend, KP Singh, Jesper Dangaard Brouer,
	Michael S. Tsirkin, Romain Perier, Allen Pais, Grygorii Strashko,
	Simon Horman, Gustavo A. R. Silva, Lorenzo Bianconi, Wei Yongjun,
	Jiri Benc, oss-drivers, linux-omap, netdev, bpf

Jakub Kicinski <kuba@kernel.org> writes:

> On Fri, 04 Dec 2020 10:38:06 +0100 Toke Høiland-Jørgensen wrote:
>> Jakub Kicinski <kuba@kernel.org> writes:
>> > On Thu, 03 Dec 2020 22:35:18 +0100 Toke Høiland-Jørgensen wrote:  
>> >> Since we offloaded and non-offloaded programs can co-exist there doesn't
>> >> really seem to be any reason for the check anyway, and it's only used in
>> >> three drivers so let's just get rid of the callback entirely.  
>> >
>> > I don't remember exactly now, but I think the concern was that using 
>> > the unspecified mode is pretty ambiguous when interface has multiple
>> > programs attached.  
>> 
>> Right. I did scratch my head a bit for why the check was there in the
>> first place, but that makes sense, actually :)
>> 
>> So how about we disallow unload without specifying a mode, but only if
>> more than one program is loaded?
>
> Are you including replacing as a form of unload? :)

Yeah, that's what I ended up with (in v2): Any time there are multiple
programs loaded, callers have to specify a mode flag to avoid ambiguity.

> IMHO the simpler the definition of the API / constraint the better.
> "You must specify the same flags" is pretty simple, as is copying the
> old behavior rather than trying to come up with new rules.
>
> But up to you, I don't mind either way, really..

Well that old behaviour was what led me to investigate this in the first
place: If you just look at a program that's loaded, see it's in driver
mode, and then try to unload it with flags set to XDP_MODE_DRV, it will
sometimes work and sometimes not depending on what flags that program
happened to have been loaded with. In libxdp this is exactly what we do
(look at the loaded program and set the corresponding mode flag), so I
ended up getting some really odd bug reports...

So I really don't want to keep the current behaviour; if what I propose
in v2 is OK with you I think we should just go with that :)

-Toke


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-12-04 17:13 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 21:35 [PATCH bpf 0/7] selftests/bpf: Restore test_offload.py to working order Toke Høiland-Jørgensen
2020-12-03 21:35 ` [PATCH bpf 1/7] xdp: remove the xdp_attachment_flags_ok() callback Toke Høiland-Jørgensen
2020-12-04  1:42   ` Jakub Kicinski
2020-12-04  9:38     ` Toke Høiland-Jørgensen
2020-12-04 16:48       ` Jakub Kicinski
2020-12-04 17:12         ` Toke Høiland-Jørgensen
2020-12-03 21:35 ` [PATCH bpf 2/7] selftests/bpf/test_offload.py: Remove check for program load flags match Toke Høiland-Jørgensen
2020-12-03 21:35 ` [PATCH bpf 3/7] netdevsim: Add debugfs toggle to reject BPF programs in verifier Toke Høiland-Jørgensen
2020-12-04  1:44   ` Jakub Kicinski
2020-12-04  9:39     ` Toke Høiland-Jørgensen
2020-12-03 21:35 ` [PATCH bpf 4/7] selftests/bpf/test_offload.py: only check verifier log on verification fails Toke Høiland-Jørgensen
2020-12-03 21:35 ` [PATCH bpf 5/7] selftests/bpf/test_offload.py: fix expected case of extack messages Toke Høiland-Jørgensen
2020-12-03 21:35 ` [PATCH bpf 6/7] selftests/bpf/test_offload.py: reset ethtool features after failed setting Toke Høiland-Jørgensen
2020-12-03 21:35 ` [PATCH bpf 7/7] selftests/bpf/test_offload.py: filter bpftool internal map when counting maps Toke Høiland-Jørgensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).