BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show
@ 2023-11-22 22:23 Stanislav Fomichev
  2023-11-22 22:23 ` [PATCH bpf-next v2 2/2] selftests/bpf: update test_offload to use new orphaned property Stanislav Fomichev
  2023-11-23 13:36 ` [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show Quentin Monnet
  0 siblings, 2 replies; 4+ messages in thread
From: Stanislav Fomichev @ 2023-11-22 22:23 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa

Commit ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD
and PERF_BPF_EVENT_PROG_UNLOAD") stopped removing program's id from
idr when the offloaded/bound netdev goes away. I was supposed to
take a look and check in [0], but apparently I did not.

Martin points out it might be useful to keep it that way for
observability sake, but we at least need to mark those programs as
unusable.

Mark those programs as 'orphaned' and keep printing the list when
we encounter ENODEV.

0: unspec  tag 0000000000000000
        xlated 0B  not jited  memlock 4096B orphaned

[0]: https://lore.kernel.org/all/CAKH8qBtyR20ZWAc11z1-6pGb3Hd47AQUTbE_cfoktG59TqaJ7Q@mail.gmail.com/

Fixes: ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/bpf/bpftool/prog.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 7ec4f5671e7a..a4f23692c187 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -442,7 +442,7 @@ static void print_prog_header_json(struct bpf_prog_info *info, int fd)
 		jsonw_uint_field(json_wtr, "recursion_misses", info->recursion_misses);
 }
 
-static void print_prog_json(struct bpf_prog_info *info, int fd)
+static void print_prog_json(struct bpf_prog_info *info, int fd, bool orphaned)
 {
 	char *memlock;
 
@@ -461,6 +461,7 @@ static void print_prog_json(struct bpf_prog_info *info, int fd)
 		jsonw_uint_field(json_wtr, "uid", info->created_by_uid);
 	}
 
+	jsonw_bool_field(json_wtr, "orphaned", orphaned);
 	jsonw_uint_field(json_wtr, "bytes_xlated", info->xlated_prog_len);
 
 	if (info->jited_prog_len) {
@@ -527,7 +528,7 @@ static void print_prog_header_plain(struct bpf_prog_info *info, int fd)
 	printf("\n");
 }
 
-static void print_prog_plain(struct bpf_prog_info *info, int fd)
+static void print_prog_plain(struct bpf_prog_info *info, int fd, bool orphaned)
 {
 	char *memlock;
 
@@ -554,6 +555,9 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
 		printf("  memlock %sB", memlock);
 	free(memlock);
 
+	if (orphaned)
+		printf(" orphaned");
+
 	if (info->nr_map_ids)
 		show_prog_maps(fd, info->nr_map_ids);
 
@@ -581,15 +585,15 @@ static int show_prog(int fd)
 	int err;
 
 	err = bpf_prog_get_info_by_fd(fd, &info, &len);
-	if (err) {
+	if (err && err != -ENODEV) {
 		p_err("can't get prog info: %s", strerror(errno));
 		return -1;
 	}
 
 	if (json_output)
-		print_prog_json(&info, fd);
+		print_prog_json(&info, fd, err == -ENODEV);
 	else
-		print_prog_plain(&info, fd);
+		print_prog_plain(&info, fd, err == -ENODEV);
 
 	return 0;
 }
-- 
2.43.0.rc1.413.gea7ed67945-goog


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

* [PATCH bpf-next v2 2/2] selftests/bpf: update test_offload to use new orphaned property
  2023-11-22 22:23 [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show Stanislav Fomichev
@ 2023-11-22 22:23 ` Stanislav Fomichev
  2023-11-23 13:36 ` [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show Quentin Monnet
  1 sibling, 0 replies; 4+ messages in thread
From: Stanislav Fomichev @ 2023-11-22 22:23 UTC (permalink / raw)
  To: bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, sdf, haoluo, jolsa

- filter orphaned programs by default
- when trying to query orphaned program, don't expect bpftool failure

Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/testing/selftests/bpf/test_offload.py | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index 40cba8d368d9..6157f884d091 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -169,12 +169,14 @@ netns = [] # net namespaces to be removed
     return tool("bpftool", args, {"json":"-p"}, JSON=JSON, ns=ns,
                 fail=fail, include_stderr=include_stderr)
 
-def bpftool_prog_list(expected=None, ns=""):
+def bpftool_prog_list(expected=None, ns="", exclude_orphaned=True):
     _, progs = bpftool("prog show", JSON=True, ns=ns, fail=True)
     # Remove the base progs
     for p in base_progs:
         if p in progs:
             progs.remove(p)
+    if exclude_orphaned:
+        progs = [ p for p in progs if not p['orphaned'] ]
     if expected is not None:
         if len(progs) != expected:
             fail(True, "%d BPF programs loaded, expected %d" %
@@ -612,11 +614,9 @@ def bpftool_prog_load(sample, file_name, maps=[], prog_type="xdp", dev=None,
 
 def check_dev_info_removed(prog_file=None, map_file=None):
     bpftool_prog_list(expected=0)
+    bpftool_prog_list(expected=1, exclude_orphaned=False)
     ret, err = bpftool("prog show pin %s" % (prog_file), fail=False)
-    fail(ret == 0, "Showing prog with removed device did not fail")
-    fail(err["error"].find("No such device") == -1,
-         "Showing prog with removed device expected ENODEV, error is %s" %
-         (err["error"]))
+    fail(ret != 0, "failed to show prog with removed device")
 
     bpftool_map_list(expected=0)
     ret, err = bpftool("map show pin %s" % (map_file), fail=False)
@@ -1395,10 +1395,7 @@ netns = []
 
     start_test("Test multi-dev ASIC cross-dev destruction - orphaned...")
     ret, out = bpftool("prog show %s" % (progB), fail=False)
-    fail(ret == 0, "got information about orphaned program")
-    fail("error" not in out, "no error reported for get info on orphaned")
-    fail(out["error"] != "can't get prog info: No such device",
-         "wrong error for get info on orphaned")
+    fail(ret != 0, "couldn't get information about orphaned program")
 
     print("%s: OK" % (os.path.basename(__file__)))
 
-- 
2.43.0.rc1.413.gea7ed67945-goog


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

* Re: [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show
  2023-11-22 22:23 [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show Stanislav Fomichev
  2023-11-22 22:23 ` [PATCH bpf-next v2 2/2] selftests/bpf: update test_offload to use new orphaned property Stanislav Fomichev
@ 2023-11-23 13:36 ` Quentin Monnet
  2023-11-27 18:02   ` Stanislav Fomichev
  1 sibling, 1 reply; 4+ messages in thread
From: Quentin Monnet @ 2023-11-23 13:36 UTC (permalink / raw)
  To: Stanislav Fomichev, bpf
  Cc: ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, haoluo, jolsa

2023-11-22 22:23 UTC+0000 ~ Stanislav Fomichev <sdf@google.com>
> Commit ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD
> and PERF_BPF_EVENT_PROG_UNLOAD") stopped removing program's id from
> idr when the offloaded/bound netdev goes away. I was supposed to
> take a look and check in [0], but apparently I did not.
> 
> Martin points out it might be useful to keep it that way for
> observability sake, but we at least need to mark those programs as
> unusable.
> 
> Mark those programs as 'orphaned' and keep printing the list when
> we encounter ENODEV.
> 
> 0: unspec  tag 0000000000000000
>         xlated 0B  not jited  memlock 4096B orphaned
> 
> [0]: https://lore.kernel.org/all/CAKH8qBtyR20ZWAc11z1-6pGb3Hd47AQUTbE_cfoktG59TqaJ7Q@mail.gmail.com/
> 
> Fixes: ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD")
> Signed-off-by: Stanislav Fomichev <sdf@google.com>
> ---
>  tools/bpf/bpftool/prog.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> index 7ec4f5671e7a..a4f23692c187 100644
> --- a/tools/bpf/bpftool/prog.c
> +++ b/tools/bpf/bpftool/prog.c

> @@ -554,6 +555,9 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
>  		printf("  memlock %sB", memlock);
>  	free(memlock);
>  
> +	if (orphaned)
> +		printf(" orphaned");

Please use a double space at the beginning of "  orphaned" here, this is
what we do elsewhere in bpftool to make the different fields easier to
dissociate visually (given that some contain multiple words).

Looks good otherwise. Thanks!

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

* Re: [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show
  2023-11-23 13:36 ` [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show Quentin Monnet
@ 2023-11-27 18:02   ` Stanislav Fomichev
  0 siblings, 0 replies; 4+ messages in thread
From: Stanislav Fomichev @ 2023-11-27 18:02 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: bpf, ast, daniel, andrii, martin.lau, song, yhs, john.fastabend,
	kpsingh, haoluo, jolsa

On 11/23, Quentin Monnet wrote:
> 2023-11-22 22:23 UTC+0000 ~ Stanislav Fomichev <sdf@google.com>
> > Commit ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD
> > and PERF_BPF_EVENT_PROG_UNLOAD") stopped removing program's id from
> > idr when the offloaded/bound netdev goes away. I was supposed to
> > take a look and check in [0], but apparently I did not.
> > 
> > Martin points out it might be useful to keep it that way for
> > observability sake, but we at least need to mark those programs as
> > unusable.
> > 
> > Mark those programs as 'orphaned' and keep printing the list when
> > we encounter ENODEV.
> > 
> > 0: unspec  tag 0000000000000000
> >         xlated 0B  not jited  memlock 4096B orphaned
> > 
> > [0]: https://lore.kernel.org/all/CAKH8qBtyR20ZWAc11z1-6pGb3Hd47AQUTbE_cfoktG59TqaJ7Q@mail.gmail.com/
> > 
> > Fixes: ef01f4e25c17 ("bpf: restore the ebpf program ID for BPF_AUDIT_UNLOAD and PERF_BPF_EVENT_PROG_UNLOAD")
> > Signed-off-by: Stanislav Fomichev <sdf@google.com>
> > ---
> >  tools/bpf/bpftool/prog.c | 14 +++++++++-----
> >  1 file changed, 9 insertions(+), 5 deletions(-)
> > 
> > diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> > index 7ec4f5671e7a..a4f23692c187 100644
> > --- a/tools/bpf/bpftool/prog.c
> > +++ b/tools/bpf/bpftool/prog.c
> 
> > @@ -554,6 +555,9 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
> >  		printf("  memlock %sB", memlock);
> >  	free(memlock);
> >  
> > +	if (orphaned)
> > +		printf(" orphaned");
> 
> Please use a double space at the beginning of "  orphaned" here, this is
> what we do elsewhere in bpftool to make the different fields easier to
> dissociate visually (given that some contain multiple words).
> 
> Looks good otherwise. Thanks!

Sure, will do, thanks!

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

end of thread, other threads:[~2023-11-27 18:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 22:23 [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show Stanislav Fomichev
2023-11-22 22:23 ` [PATCH bpf-next v2 2/2] selftests/bpf: update test_offload to use new orphaned property Stanislav Fomichev
2023-11-23 13:36 ` [PATCH bpf-next v2 1/2] bpftool: mark orphaned programs during prog show Quentin Monnet
2023-11-27 18:02   ` Stanislav Fomichev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox