All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient
@ 2018-06-14 18:06 Jakub Kicinski
  2018-06-14 18:06 ` [PATCH bpf 1/2] tools: bpftool: improve accuracy of load time Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jakub Kicinski @ 2018-06-14 18:06 UTC (permalink / raw)
  To: alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Jakub Kicinski

Hi!

This small series allows test_offload.py selftest to run on modern
distributions which may create BPF programs for cgroups at boot,
like Ubuntu 18.04.  We still expect the program list to not be
altered by any other agent while the test is running, but no longer
depend on there being no BPF programs at all at the start.

Fixing the test revealed a small problem with bpftool, which doesn't
report the program load time very accurately.  Because nanoseconds
were not taken into account reported load time would fluctuate by
1 second.  First patch of the series takes care of fixing that.

Jakub Kicinski (2):
  tools: bpftool: improve accuracy of load time
  selftests/bpf: test offloads even with BPF programs present

 tools/bpf/bpftool/prog.c                    |  4 +++-
 tools/testing/selftests/bpf/test_offload.py | 12 ++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)

-- 
2.17.1

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

* [PATCH bpf 1/2] tools: bpftool: improve accuracy of load time
  2018-06-14 18:06 [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient Jakub Kicinski
@ 2018-06-14 18:06 ` Jakub Kicinski
  2018-06-14 18:06 ` [PATCH bpf 2/2] selftests/bpf: test offloads even with BPF programs present Jakub Kicinski
  2018-06-15  1:15 ` [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2018-06-14 18:06 UTC (permalink / raw)
  To: alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Jakub Kicinski

BPF program load time is reported from the kernel relative to boot time.
If conversion to wall clock does not take nanosecond parts into account,
the load time reported by bpftool may differ by one second from run to
run.  This means JSON object reported by bpftool for a program will
randomly change.

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

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index a4f435203fef..05f42a46d6ed 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -90,7 +90,9 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
 	}
 
 	wallclock_secs = (real_time_ts.tv_sec - boot_time_ts.tv_sec) +
-		nsecs / 1000000000;
+		(real_time_ts.tv_nsec - boot_time_ts.tv_nsec + nsecs) /
+		1000000000;
+
 
 	if (!localtime_r(&wallclock_secs, &load_tm)) {
 		snprintf(buf, size, "%llu", nsecs / 1000000000);
-- 
2.17.1

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

* [PATCH bpf 2/2] selftests/bpf: test offloads even with BPF programs present
  2018-06-14 18:06 [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient Jakub Kicinski
  2018-06-14 18:06 ` [PATCH bpf 1/2] tools: bpftool: improve accuracy of load time Jakub Kicinski
@ 2018-06-14 18:06 ` Jakub Kicinski
  2018-06-15  1:15 ` [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2018-06-14 18:06 UTC (permalink / raw)
  To: alexei.starovoitov, daniel; +Cc: netdev, oss-drivers, Jakub Kicinski

Modern distroes increasingly make use of BPF programs.  Default
Ubuntu 18.04 installation boots with a number of cgroup_skb
programs loaded.

test_offloads.py tries to check if programs and maps are not
leaked on error paths by confirming the list of programs on the
system is empty between tests.

Since we can no longer expect the system to have no BPF objects
at boot try to remember the programs and maps present at the start,
and skip those when scanning the system.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
---
 tools/testing/selftests/bpf/test_offload.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py
index e78aad0a68bb..be800d0e7a84 100755
--- a/tools/testing/selftests/bpf/test_offload.py
+++ b/tools/testing/selftests/bpf/test_offload.py
@@ -163,6 +163,10 @@ netns = [] # net namespaces to be removed
 
 def bpftool_prog_list(expected=None, ns=""):
     _, 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 expected is not None:
         if len(progs) != expected:
             fail(True, "%d BPF programs loaded, expected %d" %
@@ -171,6 +175,10 @@ netns = [] # net namespaces to be removed
 
 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)
     if expected is not None:
         if len(maps) != expected:
             fail(True, "%d BPF maps loaded, expected %d" %
@@ -585,8 +593,8 @@ skip(os.getuid() != 0, "test must be run as root")
 # Check tools
 ret, progs = bpftool("prog", fail=False)
 skip(ret != 0, "bpftool not installed")
-# Check no BPF programs are loaded
-skip(len(progs) != 0, "BPF programs already loaded on the system")
+base_progs = progs
+_, base_maps = bpftool("map")
 
 # Check netdevsim
 ret, out = cmd("modprobe netdevsim", fail=False)
-- 
2.17.1

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

* Re: [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient
  2018-06-14 18:06 [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient Jakub Kicinski
  2018-06-14 18:06 ` [PATCH bpf 1/2] tools: bpftool: improve accuracy of load time Jakub Kicinski
  2018-06-14 18:06 ` [PATCH bpf 2/2] selftests/bpf: test offloads even with BPF programs present Jakub Kicinski
@ 2018-06-15  1:15 ` Daniel Borkmann
  2 siblings, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2018-06-15  1:15 UTC (permalink / raw)
  To: Jakub Kicinski, alexei.starovoitov; +Cc: netdev, oss-drivers

On 06/14/2018 08:06 PM, Jakub Kicinski wrote:
> Hi!
> 
> This small series allows test_offload.py selftest to run on modern
> distributions which may create BPF programs for cgroups at boot,
> like Ubuntu 18.04.  We still expect the program list to not be
> altered by any other agent while the test is running, but no longer
> depend on there being no BPF programs at all at the start.
> 
> Fixing the test revealed a small problem with bpftool, which doesn't
> report the program load time very accurately.  Because nanoseconds
> were not taken into account reported load time would fluctuate by
> 1 second.  First patch of the series takes care of fixing that.
> 
> Jakub Kicinski (2):
>   tools: bpftool: improve accuracy of load time
>   selftests/bpf: test offloads even with BPF programs present
> 
>  tools/bpf/bpftool/prog.c                    |  4 +++-
>  tools/testing/selftests/bpf/test_offload.py | 12 ++++++++++--
>  2 files changed, 13 insertions(+), 3 deletions(-)
> 

Applied to bpf, thanks Jakub!

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

end of thread, other threads:[~2018-06-15  1:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-14 18:06 [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient Jakub Kicinski
2018-06-14 18:06 ` [PATCH bpf 1/2] tools: bpftool: improve accuracy of load time Jakub Kicinski
2018-06-14 18:06 ` [PATCH bpf 2/2] selftests/bpf: test offloads even with BPF programs present Jakub Kicinski
2018-06-15  1:15 ` [PATCH bpf 0/2] bpf: fix the load time reporting and make offload test more resilient Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.