提交 70af8836 编写于 作者: A Alexei Starovoitov 提交者: Zheng Zengkai

selftests/bpf: Convert test printk to use rodata.

mainline inclusion
from mainline-5.14-rc1
commit eb0f1e0c
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I5EUVD
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=eb0f1e0c7f103e262308d3f12a27a8331af3011a

-------------------------------------------------

Convert test trace_printk to more aggressively validate and use rodata.
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Acked-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210514003623.28033-21-alexei.starovoitov@gmail.com
(cherry picked from commit eb0f1e0c)
Signed-off-by: NWang Yufen <wangyufen@huawei.com>
上级 c7c9aa2b
...@@ -21,6 +21,9 @@ void test_trace_printk(void) ...@@ -21,6 +21,9 @@ void test_trace_printk(void)
if (CHECK(!skel, "skel_open", "failed to open skeleton\n")) if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
return; return;
ASSERT_EQ(skel->rodata->fmt[0], 'T', "invalid printk fmt string");
skel->rodata->fmt[0] = 't';
err = trace_printk__load(skel); err = trace_printk__load(skel);
if (CHECK(err, "skel_load", "failed to load skeleton: %d\n", err)) if (CHECK(err, "skel_load", "failed to load skeleton: %d\n", err))
goto cleanup; goto cleanup;
......
...@@ -10,11 +10,11 @@ char _license[] SEC("license") = "GPL"; ...@@ -10,11 +10,11 @@ char _license[] SEC("license") = "GPL";
int trace_printk_ret = 0; int trace_printk_ret = 0;
int trace_printk_ran = 0; int trace_printk_ran = 0;
SEC("tp/raw_syscalls/sys_enter") const char fmt[] = "Testing,testing %d\n";
SEC("fentry/__x64_sys_nanosleep")
int sys_enter(void *ctx) int sys_enter(void *ctx)
{ {
static const char fmt[] = "testing,testing %d\n";
trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt), trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt),
++trace_printk_ran); ++trace_printk_ran);
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册