BPF Archive on lore.kernel.org
 help / color / Atom feed
From: Yonghong Song <yhs@fb.com>
To: Stanislav Fomichev <sdf@fomichev.me>
Cc: "bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Kernel Team <Kernel-team@fb.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH bpf-next v2 3/3] tools/bpf: add a selftest for bpf_send_signal() helper
Date: Wed, 22 May 2019 19:44:31 +0000
Message-ID: <72d75786-1cbd-e6d0-89e7-192f39d436f5@fb.com> (raw)
In-Reply-To: <20190522191006.GN10244@mini-arch>



On 5/22/19 12:10 PM, Stanislav Fomichev wrote:
> On 05/21, Yonghong Song wrote:
>> The test covered both nmi and tracepoint perf events.
>>    $ ./test_send_signal_user
>>    test_send_signal (tracepoint): OK
>>    test_send_signal (perf_event): OK
>>
>> Signed-off-by: Yonghong Song <yhs@fb.com>
>> ---
>>   tools/testing/selftests/bpf/Makefile          |   3 +-
>>   tools/testing/selftests/bpf/bpf_helpers.h     |   1 +
>>   .../bpf/progs/test_send_signal_kern.c         |  51 +++++
>>   .../selftests/bpf/test_send_signal_user.c     | 212 ++++++++++++++++++
>>   4 files changed, 266 insertions(+), 1 deletion(-)
>>   create mode 100644 tools/testing/selftests/bpf/progs/test_send_signal_kern.c
>>   create mode 100644 tools/testing/selftests/bpf/test_send_signal_user.c
>>
>> diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
>> index 66f2dca1dee1..5eb6368a96a2 100644
>> --- a/tools/testing/selftests/bpf/Makefile
>> +++ b/tools/testing/selftests/bpf/Makefile
>> @@ -23,7 +23,8 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
>>   	test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
>>   	test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user \
>>   	test_socket_cookie test_cgroup_storage test_select_reuseport test_section_names \
>> -	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl
>> +	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl \
>> +	test_send_signal_user
>>   
>>   BPF_OBJ_FILES = $(patsubst %.c,%.o, $(notdir $(wildcard progs/*.c)))
>>   TEST_GEN_FILES = $(BPF_OBJ_FILES)
>> diff --git a/tools/testing/selftests/bpf/bpf_helpers.h b/tools/testing/selftests/bpf/bpf_helpers.h
>> index 5f6f9e7aba2a..cb02521b8e58 100644
>> --- a/tools/testing/selftests/bpf/bpf_helpers.h
>> +++ b/tools/testing/selftests/bpf/bpf_helpers.h
>> @@ -216,6 +216,7 @@ static void *(*bpf_sk_storage_get)(void *map, struct bpf_sock *sk,
>>   	(void *) BPF_FUNC_sk_storage_get;
>>   static int (*bpf_sk_storage_delete)(void *map, struct bpf_sock *sk) =
>>   	(void *)BPF_FUNC_sk_storage_delete;
>> +static int (*bpf_send_signal)(unsigned sig) = (void *)BPF_FUNC_send_signal;
>>   
>>   /* llvm builtin functions that eBPF C program may use to
>>    * emit BPF_LD_ABS and BPF_LD_IND instructions
>> diff --git a/tools/testing/selftests/bpf/progs/test_send_signal_kern.c b/tools/testing/selftests/bpf/progs/test_send_signal_kern.c
>> new file mode 100644
>> index 000000000000..45a1a1a2c345
>> --- /dev/null
>> +++ b/tools/testing/selftests/bpf/progs/test_send_signal_kern.c
>> @@ -0,0 +1,51 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +// Copyright (c) 2019 Facebook
>> +#include <linux/bpf.h>
>> +#include <linux/version.h>
>> +#include "bpf_helpers.h"
>> +
>> +struct bpf_map_def SEC("maps") info_map = {
>> +	.type = BPF_MAP_TYPE_ARRAY,
>> +	.key_size = sizeof(__u32),
>> +	.value_size = sizeof(__u64),
>> +	.max_entries = 1,
>> +};
>> +
>> +BPF_ANNOTATE_KV_PAIR(info_map, __u32, __u64);
>> +
>> +struct bpf_map_def SEC("maps") status_map = {
>> +	.type = BPF_MAP_TYPE_ARRAY,
>> +	.key_size = sizeof(__u32),
>> +	.value_size = sizeof(__u64),
>> +	.max_entries = 1,
>> +};
>> +
>> +BPF_ANNOTATE_KV_PAIR(status_map, __u32, __u64);
>> +
>> +SEC("send_signal_demo")
>> +int bpf_send_signal_test(void *ctx)
>> +{
>> +	__u64 *info_val, *status_val;
>> +	__u32 key = 0, pid, sig;
>> +	int ret;
>> +
>> +	status_val = bpf_map_lookup_elem(&status_map, &key);
>> +	if (!status_val || *status_val != 0)
>> +		return 0;
>> +
>> +	info_val = bpf_map_lookup_elem(&info_map, &key);
>> +	if (!info_val || *info_val == 0)
>> +		return 0;
>> +
>> +	sig = *info_val >> 32;
>> +	pid = *info_val & 0xffffFFFF;
>> +
>> +	if ((bpf_get_current_pid_tgid() >> 32) == pid) {
>> +		ret = bpf_send_signal(sig);
>> +		if (ret == 0)
>> +			*status_val = 1;
>> +	}
>> +
>> +	return 0;
>> +}
>> +char __license[] SEC("license") = "GPL";
>> diff --git a/tools/testing/selftests/bpf/test_send_signal_user.c b/tools/testing/selftests/bpf/test_send_signal_user.c
>> new file mode 100644
>> index 000000000000..0bd0f7674860
>> --- /dev/null
> [..]
>> +++ b/tools/testing/selftests/bpf/test_send_signal_user.c
> Any reason you didn't put it under bpf/prog_tests?

The only reason I put it as a standalone test is
that the program receives signals and tries to
minimize potential impact on other tests.

But it might be okay as the signal is sent to
child process.

> That way you don't need to define your own CHECK macro and
> care about the includes.

Right. I will try to use bpf/prog_tests infrastructure
in the next revision.

  reply index

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22  5:39 [PATCH bpf-next v2 0/3] bpf: implement " Yonghong Song
2019-05-22  5:39 ` [PATCH bpf-next v2 1/3] " Yonghong Song
2019-05-23 15:41   ` Daniel Borkmann
2019-05-23 15:58     ` Yonghong Song
2019-05-23 16:28       ` Daniel Borkmann
2019-05-23 21:07         ` Yonghong Song
2019-05-23 21:30           ` Yonghong Song
2019-05-23 23:08             ` Daniel Borkmann
2019-05-23 23:54               ` Yonghong Song
2019-05-24 21:32                 ` Daniel Borkmann
2019-05-22  5:39 ` [PATCH bpf-next v2 2/3] tools/bpf: sync bpf uapi header bpf.h to tools directory Yonghong Song
2019-05-22  5:39 ` [PATCH bpf-next v2 3/3] tools/bpf: add a selftest for bpf_send_signal() helper Yonghong Song
2019-05-22 18:48   ` Andrii Nakryiko
2019-05-22 19:38     ` Yonghong Song
2019-05-22 19:10   ` Stanislav Fomichev
2019-05-22 19:44     ` Yonghong Song [this message]
2019-05-22 16:38 ` [PATCH bpf-next v2 0/3] bpf: implement " Stanislav Fomichev
2019-05-22 16:43   ` Alexei Starovoitov
2019-05-22 17:11     ` Stanislav Fomichev

Reply instructions:

You may reply publically 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=72d75786-1cbd-e6d0-89e7-192f39d436f5@fb.com \
    --to=yhs@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=netdev@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=sdf@fomichev.me \
    /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

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org bpf@archiver.kernel.org
	public-inbox-index bpf


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/ public-inbox