From: Jiong Wang <jiong.wang@netronome.com>
To: alexei.starovoitov@gmail.com, daniel@iogearbox.net
Cc: bpf@vger.kernel.org, netdev@vger.kernel.org,
oss-drivers@netronome.com, Jiong Wang <jiong.wang@netronome.com>
Subject: [PATCH/RFC v2 bpf-next 11/19] libbpf: new global variable "libbpf_test_mode"
Date: Wed, 10 Apr 2019 20:50:25 +0100 [thread overview]
Message-ID: <1554925833-7333-12-git-send-email-jiong.wang@netronome.com> (raw)
In-Reply-To: <1554925833-7333-1-git-send-email-jiong.wang@netronome.com>
Enable BPF_F_TEST_RND_HI32 for all existing bpf selftests or other
independent tests could involve quite a few changes to make sure all bpf
prog load places has BPF_F_TEST_RND_HI32 set.
Given most of the tests are using libbpf, this patch introduces a new
global variable "libbpf_test_mode" into libbpf, once which is set, all bpf
prog load issued through libbpf will have BPF_F_TEST_RND_HI32 set
automatically, this could minimize changes required from testsuite.
The other way might be introducing new load function like
"bpf_prog_test_load", which will set BPF_F_TEST_RND_HI32. But there are
several prog load APIs, and we need minor changes on some parameters.
The global variable approach seems to be a proper first step for easy
testsuite porting.
Signed-off-by: Jiong Wang <jiong.wang@netronome.com>
---
tools/lib/bpf/bpf.c | 4 ++++
tools/lib/bpf/libbpf.c | 2 ++
tools/lib/bpf/libbpf.h | 2 ++
tools/lib/bpf/libbpf.map | 1 +
4 files changed, 9 insertions(+)
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index dababce..0795a85 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -254,6 +254,8 @@ int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
if (load_attr->name)
memcpy(attr.prog_name, load_attr->name,
min(strlen(load_attr->name), BPF_OBJ_NAME_LEN - 1));
+ if (libbpf_test_mode)
+ attr.prog_flags |= BPF_F_TEST_RND_HI32;
fd = sys_bpf_prog_load(&attr, sizeof(attr));
if (fd >= 0)
@@ -350,6 +352,8 @@ int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns,
log_buf[0] = 0;
attr.kern_version = kern_version;
attr.prog_flags = prog_flags;
+ if (libbpf_test_mode)
+ attr.prog_flags |= BPF_F_TEST_RND_HI32;
return sys_bpf_prog_load(&attr, sizeof(attr));
}
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e2a457e..606643f 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -45,6 +45,8 @@
#include "str_error.h"
#include "libbpf_util.h"
+bool libbpf_test_mode;
+
#ifndef EM_BPF
#define EM_BPF 247
#endif
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index c5ff005..b40de66 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -447,6 +447,8 @@ bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear);
LIBBPF_API void
bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear);
+LIBBPF_API extern bool libbpf_test_mode;
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map
index 6730017..5854e0b 100644
--- a/tools/lib/bpf/libbpf.map
+++ b/tools/lib/bpf/libbpf.map
@@ -156,6 +156,7 @@ LIBBPF_0.0.2 {
bpf_program__get_prog_info_linear;
bpf_program__bpil_addr_to_offs;
bpf_program__bpil_offs_to_addr;
+ libbpf_test_mode;
} LIBBPF_0.0.1;
LIBBPF_0.0.3 {
--
2.7.4
next prev parent reply other threads:[~2019-04-10 19:51 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-10 19:50 [PATCH/RFC v2 bpf-next 00/19] bpf: eliminate zero extensions for sub-register writes Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 01/19] bpf: refactor propagate_liveness to eliminate duplicated for loop Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 02/19] bpf: refactor propagate_liveness to eliminate code redundance Jiong Wang
2019-04-11 2:39 ` [oss-drivers] " Jakub Kicinski
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 03/19] bpf: factor out reg and stack slot propagation into "propagate_liveness_reg" Jiong Wang
2019-04-11 2:39 ` [oss-drivers] " Jakub Kicinski
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 04/19] bpf: refactor "check_reg_arg" to eliminate code redundancy Jiong Wang
2019-04-11 2:40 ` Jakub Kicinski
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 05/19] bpf: split read liveness into REG_LIVE_READ64 and REG_LIVE_READ32 Jiong Wang
2019-04-11 2:52 ` Jakub Kicinski
2019-04-11 6:13 ` Jiong Wang
2019-04-11 16:44 ` [oss-drivers] " Jakub Kicinski
2019-04-11 16:53 ` Jiong Wang
2019-04-12 16:14 ` Jiong Wang
2019-04-11 17:22 ` Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 06/19] bpf: mark lo32 writes that should be zero extended into hi32 Jiong Wang
2019-04-11 3:13 ` Jakub Kicinski
2019-04-11 6:02 ` Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 07/19] bpf: reduce false alarm by refining helper call arg types Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 08/19] bpf: insert explicit zero extension insn when hardware doesn't do it implicitly Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 09/19] bpf: introduce new bpf prog load flags "BPF_F_TEST_RND_HI32" Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 10/19] bpf: randomize high 32-bit when BPF_F_TEST_RND_HI32 is set Jiong Wang
2019-04-10 19:50 ` Jiong Wang [this message]
2019-04-11 3:19 ` [PATCH/RFC v2 bpf-next 11/19] libbpf: new global variable "libbpf_test_mode" Jakub Kicinski
2019-04-11 14:32 ` Jiong Wang
2019-04-11 21:49 ` Jiong Wang
2019-04-12 22:08 ` Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 12/19] selftests: enable hi32 randomization for "test_progs" and "test_verifier" Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 13/19] arm: bpf: eliminate zero extension code-gen Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 14/19] powerpc: " Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 15/19] s390: " Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 16/19] sparc: " Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 17/19] x32: " Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 18/19] riscv: " Jiong Wang
2019-04-10 19:50 ` [PATCH/RFC v2 bpf-next 19/19] nfp: " Jiong Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1554925833-7333-12-git-send-email-jiong.wang@netronome.com \
--to=jiong.wang@netronome.com \
--cc=alexei.starovoitov@gmail.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@netronome.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).