netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool
@ 2018-11-08 11:52 Quentin Monnet
  2018-11-08 11:52 ` [PATCH bpf 1/4] tools: bpftool: prevent infinite loop in get_fdinfo() Quentin Monnet
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Quentin Monnet @ 2018-11-08 11:52 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, oss-drivers, Quentin Monnet

Hi,
This set contains minor fixes for bpftool code and documentation.
Please refer to individual patches for details.

Quentin Monnet (4):
  tools: bpftool: prevent infinite loop in get_fdinfo()
  tools: bpftool: fix plain output and doc for --bpffs option
  tools: bpftool: pass an argument to silence open_obj_pinned()
  tools: bpftool: update references to other man pages in documentation

 tools/bpf/bpftool/Documentation/bpftool-cgroup.rst |  8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-map.rst    |  8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-net.rst    |  8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-perf.rst   |  8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst   | 11 +++++++++--
 tools/bpf/bpftool/Documentation/bpftool.rst        |  9 +++++++--
 tools/bpf/bpftool/common.c                         | 17 +++++++++--------
 tools/bpf/bpftool/main.h                           |  2 +-
 tools/bpf/bpftool/prog.c                           |  3 +--
 9 files changed, 55 insertions(+), 19 deletions(-)

-- 
2.7.4

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

* [PATCH bpf 1/4] tools: bpftool: prevent infinite loop in get_fdinfo()
  2018-11-08 11:52 [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Quentin Monnet
@ 2018-11-08 11:52 ` Quentin Monnet
  2018-11-08 11:52 ` [PATCH bpf 2/4] tools: bpftool: fix plain output and doc for --bpffs option Quentin Monnet
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Quentin Monnet @ 2018-11-08 11:52 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, oss-drivers, Quentin Monnet

Function getline() returns -1 on failure to read a line, thus creating
an infinite loop in get_fdinfo() if the key is not found. Fix it by
calling the function only as long as we get a strictly positive return
value.

Found by copying the code for a key which is not always present...

Fixes: 71bb428fe2c1 ("tools: bpf: add bpftool")
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 tools/bpf/bpftool/common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 1149565be4b1..acd839e0e801 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -312,7 +312,7 @@ char *get_fdinfo(int fd, const char *key)
 		return NULL;
 	}
 
-	while ((n = getline(&line, &line_n, fdi))) {
+	while ((n = getline(&line, &line_n, fdi)) > 0) {
 		char *value;
 		int len;
 
-- 
2.7.4

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

* [PATCH bpf 2/4] tools: bpftool: fix plain output and doc for --bpffs option
  2018-11-08 11:52 [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Quentin Monnet
  2018-11-08 11:52 ` [PATCH bpf 1/4] tools: bpftool: prevent infinite loop in get_fdinfo() Quentin Monnet
@ 2018-11-08 11:52 ` Quentin Monnet
  2018-11-08 11:52 ` [PATCH bpf 3/4] tools: bpftool: pass an argument to silence open_obj_pinned() Quentin Monnet
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Quentin Monnet @ 2018-11-08 11:52 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, oss-drivers, Quentin Monnet

Edit the documentation of the -f|--bpffs option to make it explicit that
it dumps paths of pinned programs when bpftool is used to list the
programs only, so that users do not believe they will see the name of
the newly pinned program with "bpftool prog pin" or "bpftool prog load".

Also fix the plain output: do not add a blank line after each program
block, in order to remain consistent with what bpftool does when the
option is not passed.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 tools/bpf/bpftool/Documentation/bpftool-prog.rst | 3 ++-
 tools/bpf/bpftool/prog.c                         | 3 +--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
index ac4e904b10fb..81fb97acfaeb 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
@@ -124,7 +124,8 @@ OPTIONS
 		  Generate human-readable JSON output. Implies **-j**.
 
 	-f, --bpffs
-		  Show file names of pinned programs.
+		  When showing BPF programs, show file names of pinned
+		  programs.
 
 EXAMPLES
 ========
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index b9b84553bec4..763ddfa29045 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -357,10 +357,9 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd)
 	if (!hash_empty(prog_table.table)) {
 		struct pinned_obj *obj;
 
-		printf("\n");
 		hash_for_each_possible(prog_table.table, obj, hash, info->id) {
 			if (obj->id == info->id)
-				printf("\tpinned %s\n", obj->path);
+				printf("\n\tpinned %s", obj->path);
 		}
 	}
 
-- 
2.7.4

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

* [PATCH bpf 3/4] tools: bpftool: pass an argument to silence open_obj_pinned()
  2018-11-08 11:52 [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Quentin Monnet
  2018-11-08 11:52 ` [PATCH bpf 1/4] tools: bpftool: prevent infinite loop in get_fdinfo() Quentin Monnet
  2018-11-08 11:52 ` [PATCH bpf 2/4] tools: bpftool: fix plain output and doc for --bpffs option Quentin Monnet
@ 2018-11-08 11:52 ` Quentin Monnet
  2018-11-08 11:52 ` [PATCH bpf 4/4] tools: bpftool: update references to other man pages in documentation Quentin Monnet
  2018-11-09  7:38 ` [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Daniel Borkmann
  4 siblings, 0 replies; 6+ messages in thread
From: Quentin Monnet @ 2018-11-08 11:52 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, oss-drivers, Quentin Monnet

Function open_obj_pinned() prints error messages when it fails to open a
link in the BPF virtual file system. However, in some occasions it is
not desirable to print an error, for example when we parse all links
under the bpffs root, and the error is due to some paths actually being
symbolic links.

Example output:

    # ls -l /sys/fs/bpf/
    lrwxrwxrwx 1 root root 0 Oct 18 19:00 ip -> /sys/fs/bpf/tc/
    drwx------ 3 root root 0 Oct 18 19:00 tc
    lrwxrwxrwx 1 root root 0 Oct 18 19:00 xdp -> /sys/fs/bpf/tc/

    # bpftool --bpffs prog show
    Error: bpf obj get (/sys/fs/bpf): Permission denied
    Error: bpf obj get (/sys/fs/bpf): Permission denied

    # strace -e bpf bpftool --bpffs prog show
    bpf(BPF_OBJ_GET, {pathname="/sys/fs/bpf/ip", bpf_fd=0}, 72) = -1 EACCES (Permission denied)
    Error: bpf obj get (/sys/fs/bpf): Permission denied
    bpf(BPF_OBJ_GET, {pathname="/sys/fs/bpf/xdp", bpf_fd=0}, 72) = -1 EACCES (Permission denied)
    Error: bpf obj get (/sys/fs/bpf): Permission denied
    ...

To fix it, pass a bool as a second argument to the function, and prevent
it from printing an error when the argument is set to true.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 tools/bpf/bpftool/common.c | 15 ++++++++-------
 tools/bpf/bpftool/main.h   |  2 +-
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index acd839e0e801..7b2388bec4a9 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -138,16 +138,17 @@ static int mnt_bpffs(const char *target, char *buff, size_t bufflen)
 	return 0;
 }
 
-int open_obj_pinned(char *path)
+int open_obj_pinned(char *path, bool quiet)
 {
 	int fd;
 
 	fd = bpf_obj_get(path);
 	if (fd < 0) {
-		p_err("bpf obj get (%s): %s", path,
-		      errno == EACCES && !is_bpffs(dirname(path)) ?
-		    "directory not in bpf file system (bpffs)" :
-		    strerror(errno));
+		if (!quiet)
+			p_err("bpf obj get (%s): %s", path,
+			      errno == EACCES && !is_bpffs(dirname(path)) ?
+			    "directory not in bpf file system (bpffs)" :
+			    strerror(errno));
 		return -1;
 	}
 
@@ -159,7 +160,7 @@ int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type)
 	enum bpf_obj_type type;
 	int fd;
 
-	fd = open_obj_pinned(path);
+	fd = open_obj_pinned(path, false);
 	if (fd < 0)
 		return -1;
 
@@ -392,7 +393,7 @@ int build_pinned_obj_table(struct pinned_obj_table *tab,
 		while ((ftse = fts_read(fts))) {
 			if (!(ftse->fts_info & FTS_F))
 				continue;
-			fd = open_obj_pinned(ftse->fts_path);
+			fd = open_obj_pinned(ftse->fts_path, true);
 			if (fd < 0)
 				continue;
 
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 14857c273bf6..6d33baa51273 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -129,7 +129,7 @@ int cmd_select(const struct cmd *cmds, int argc, char **argv,
 int get_fd_type(int fd);
 const char *get_fd_type_name(enum bpf_obj_type type);
 char *get_fdinfo(int fd, const char *key);
-int open_obj_pinned(char *path);
+int open_obj_pinned(char *path, bool quiet);
 int open_obj_pinned_any(char *path, enum bpf_obj_type exp_type);
 int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(__u32));
 int do_pin_fd(int fd, const char *name);
-- 
2.7.4

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

* [PATCH bpf 4/4] tools: bpftool: update references to other man pages in documentation
  2018-11-08 11:52 [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Quentin Monnet
                   ` (2 preceding siblings ...)
  2018-11-08 11:52 ` [PATCH bpf 3/4] tools: bpftool: pass an argument to silence open_obj_pinned() Quentin Monnet
@ 2018-11-08 11:52 ` Quentin Monnet
  2018-11-09  7:38 ` [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Daniel Borkmann
  4 siblings, 0 replies; 6+ messages in thread
From: Quentin Monnet @ 2018-11-08 11:52 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann; +Cc: netdev, oss-drivers, Quentin Monnet

Update references to other bpftool man pages at the bottom of each
manual page. Also reference the "bpf(2)" and "bpf-helpers(7)" man pages.

References are sorted by number of man section, then by
"prog-and-map-go-first", the other pages in alphabetical order.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
---
 tools/bpf/bpftool/Documentation/bpftool-cgroup.rst | 8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-map.rst    | 8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-net.rst    | 8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-perf.rst   | 8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool-prog.rst   | 8 +++++++-
 tools/bpf/bpftool/Documentation/bpftool.rst        | 9 +++++++--
 6 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/tools/bpf/bpftool/Documentation/bpftool-cgroup.rst b/tools/bpf/bpftool/Documentation/bpftool-cgroup.rst
index edbe81534c6d..d07ccf8a23f7 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-cgroup.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-cgroup.rst
@@ -137,4 +137,10 @@ EXAMPLES
 
 SEE ALSO
 ========
-	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-map**\ (8)
+	**bpf**\ (2),
+	**bpf-helpers**\ (7),
+	**bpftool**\ (8),
+	**bpftool-prog**\ (8),
+	**bpftool-map**\ (8),
+	**bpftool-net**\ (8),
+	**bpftool-perf**\ (8)
diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst b/tools/bpf/bpftool/Documentation/bpftool-map.rst
index f55a2daed59b..7bb787cfa971 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-map.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst
@@ -171,4 +171,10 @@ The following three commands are equivalent:
 
 SEE ALSO
 ========
-	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)
+	**bpf**\ (2),
+	**bpf-helpers**\ (7),
+	**bpftool**\ (8),
+	**bpftool-prog**\ (8),
+	**bpftool-cgroup**\ (8),
+	**bpftool-net**\ (8),
+	**bpftool-perf**\ (8)
diff --git a/tools/bpf/bpftool/Documentation/bpftool-net.rst b/tools/bpf/bpftool/Documentation/bpftool-net.rst
index 408ec30d8872..ed87c9b619ad 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-net.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-net.rst
@@ -136,4 +136,10 @@ EXAMPLES
 
 SEE ALSO
 ========
-	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-map**\ (8)
+	**bpf**\ (2),
+	**bpf-helpers**\ (7),
+	**bpftool**\ (8),
+	**bpftool-prog**\ (8),
+	**bpftool-map**\ (8),
+	**bpftool-cgroup**\ (8),
+	**bpftool-perf**\ (8)
diff --git a/tools/bpf/bpftool/Documentation/bpftool-perf.rst b/tools/bpf/bpftool/Documentation/bpftool-perf.rst
index e3eb0eab7641..f4c5e5538bb8 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-perf.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-perf.rst
@@ -78,4 +78,10 @@ EXAMPLES
 
 SEE ALSO
 ========
-	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-map**\ (8)
+	**bpf**\ (2),
+	**bpf-helpers**\ (7),
+	**bpftool**\ (8),
+	**bpftool-prog**\ (8),
+	**bpftool-map**\ (8),
+	**bpftool-cgroup**\ (8),
+	**bpftool-net**\ (8)
diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
index 81fb97acfaeb..ecf618807125 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
@@ -207,4 +207,10 @@ EXAMPLES
 
 SEE ALSO
 ========
-	**bpftool**\ (8), **bpftool-map**\ (8), **bpftool-cgroup**\ (8)
+	**bpf**\ (2),
+	**bpf-helpers**\ (7),
+	**bpftool**\ (8),
+	**bpftool-map**\ (8),
+	**bpftool-cgroup**\ (8),
+	**bpftool-net**\ (8),
+	**bpftool-perf**\ (8)
diff --git a/tools/bpf/bpftool/Documentation/bpftool.rst b/tools/bpf/bpftool/Documentation/bpftool.rst
index 04cd4f92ab89..129b7a9c0f9b 100644
--- a/tools/bpf/bpftool/Documentation/bpftool.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool.rst
@@ -63,5 +63,10 @@ OPTIONS
 
 SEE ALSO
 ========
-	**bpftool-map**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)
-        **bpftool-perf**\ (8), **bpftool-net**\ (8)
+	**bpf**\ (2),
+	**bpf-helpers**\ (7),
+	**bpftool-prog**\ (8),
+	**bpftool-map**\ (8),
+	**bpftool-cgroup**\ (8),
+	**bpftool-net**\ (8),
+	**bpftool-perf**\ (8)
-- 
2.7.4

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

* Re: [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool
  2018-11-08 11:52 [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Quentin Monnet
                   ` (3 preceding siblings ...)
  2018-11-08 11:52 ` [PATCH bpf 4/4] tools: bpftool: update references to other man pages in documentation Quentin Monnet
@ 2018-11-09  7:38 ` Daniel Borkmann
  4 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2018-11-09  7:38 UTC (permalink / raw)
  To: Quentin Monnet, Alexei Starovoitov; +Cc: netdev, oss-drivers

On 11/08/2018 12:52 PM, Quentin Monnet wrote:
> Hi,
> This set contains minor fixes for bpftool code and documentation.
> Please refer to individual patches for details.
> 
> Quentin Monnet (4):
>   tools: bpftool: prevent infinite loop in get_fdinfo()
>   tools: bpftool: fix plain output and doc for --bpffs option
>   tools: bpftool: pass an argument to silence open_obj_pinned()
>   tools: bpftool: update references to other man pages in documentation
> 
>  tools/bpf/bpftool/Documentation/bpftool-cgroup.rst |  8 +++++++-
>  tools/bpf/bpftool/Documentation/bpftool-map.rst    |  8 +++++++-
>  tools/bpf/bpftool/Documentation/bpftool-net.rst    |  8 +++++++-
>  tools/bpf/bpftool/Documentation/bpftool-perf.rst   |  8 +++++++-
>  tools/bpf/bpftool/Documentation/bpftool-prog.rst   | 11 +++++++++--
>  tools/bpf/bpftool/Documentation/bpftool.rst        |  9 +++++++--
>  tools/bpf/bpftool/common.c                         | 17 +++++++++--------
>  tools/bpf/bpftool/main.h                           |  2 +-
>  tools/bpf/bpftool/prog.c                           |  3 +--
>  9 files changed, 55 insertions(+), 19 deletions(-)
> 

Applied to bpf, thanks Quentin!

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

end of thread, other threads:[~2018-11-09 17:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-08 11:52 [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Quentin Monnet
2018-11-08 11:52 ` [PATCH bpf 1/4] tools: bpftool: prevent infinite loop in get_fdinfo() Quentin Monnet
2018-11-08 11:52 ` [PATCH bpf 2/4] tools: bpftool: fix plain output and doc for --bpffs option Quentin Monnet
2018-11-08 11:52 ` [PATCH bpf 3/4] tools: bpftool: pass an argument to silence open_obj_pinned() Quentin Monnet
2018-11-08 11:52 ` [PATCH bpf 4/4] tools: bpftool: update references to other man pages in documentation Quentin Monnet
2018-11-09  7:38 ` [PATCH bpf 0/4] tools: bpftool: bring several minor fixes to bpftool Daniel Borkmann

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).