From: Martin KaFai Lau <kafai@fb.com>
To: Andrii Nakryiko <andriin@fb.com>
Cc: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
<daniel@iogearbox.net>, <andrii.nakryiko@gmail.com>,
<kernel-team@fb.com>
Subject: Re: [Potential Spoof] [PATCH bpf-next 3/3] selftests/bpf: reset process and thread affinity after each test/sub-test
Date: Mon, 16 Mar 2020 22:35:50 -0700 [thread overview]
Message-ID: <20200317053550.uk2lzcqfrrmgsdq7@kafai-mbp> (raw)
In-Reply-To: <20200314013932.4035712-3-andriin@fb.com>
On Fri, Mar 13, 2020 at 06:39:32PM -0700, Andrii Nakryiko wrote:
> Some tests and sub-tests are setting "custom" thread/process affinity and
> don't reset it back. Instead of requiring each test to undo all this, ensure
> that thread affinity is restored by test_progs test runner itself.
>
> Signed-off-by: Andrii Nakryiko <andriin@fb.com>
> ---
> tools/testing/selftests/bpf/test_progs.c | 42 +++++++++++++++++++++++-
> tools/testing/selftests/bpf/test_progs.h | 1 +
> 2 files changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c
> index c8cb407482c6..b521e0a512b6 100644
> --- a/tools/testing/selftests/bpf/test_progs.c
> +++ b/tools/testing/selftests/bpf/test_progs.c
> @@ -1,12 +1,15 @@
> // SPDX-License-Identifier: GPL-2.0-only
> /* Copyright (c) 2017 Facebook
> */
> +#define _GNU_SOURCE
> #include "test_progs.h"
> #include "cgroup_helpers.h"
> #include "bpf_rlimit.h"
> #include <argp.h>
> -#include <string.h>
> +#include <pthread.h>
> +#include <sched.h>
> #include <signal.h>
> +#include <string.h>
> #include <execinfo.h> /* backtrace */
>
> /* defined in test_progs.h */
> @@ -90,6 +93,34 @@ static void skip_account(void)
> }
> }
>
> +static void stdio_restore(void);
> +
> +/* A bunch of tests set custom affinity per-thread and/or per-process. Reset
> + * it after each test/sub-test.
> + */
> +static void reset_affinity() {
> +
> + cpu_set_t cpuset;
> + int i, err;
> +
> + CPU_ZERO(&cpuset);
> + for (i = 0; i < env.nr_cpus; i++)
> + CPU_SET(i, &cpuset);
In case the user may run "taskset somemask test_progs",
is it better to store the inital_cpuset at the beginning
of main and then restore to inital_cpuset after each run?
> +
> + err = sched_setaffinity(0, sizeof(cpuset), &cpuset);
> + if (err < 0) {
> + stdio_restore();
> + fprintf(stderr, "Failed to reset process affinity: %d!\n", err);
> + exit(-1);
> + }
> + err = pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
> + if (err < 0) {
> + stdio_restore();
> + fprintf(stderr, "Failed to reset thread affinity: %d!\n", err);
> + exit(-1);
> + }
> +}
next prev parent reply other threads:[~2020-03-17 5:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-14 1:39 [PATCH bpf-next 1/3] selftests/bpf: fix race in tcp_rtt test Andrii Nakryiko
2020-03-14 1:39 ` [PATCH bpf-next 2/3] selftests/bpf: fix test_progs's parsing of test numbers Andrii Nakryiko
2020-03-17 5:28 ` Martin KaFai Lau
2020-03-14 1:39 ` [PATCH bpf-next 3/3] selftests/bpf: reset process and thread affinity after each test/sub-test Andrii Nakryiko
2020-03-17 5:35 ` Martin KaFai Lau [this message]
2020-03-17 5:39 ` [Potential Spoof] " Andrii Nakryiko
2020-03-17 5:27 ` [Potential Spoof] [PATCH bpf-next 1/3] selftests/bpf: fix race in tcp_rtt test Martin KaFai Lau
2020-03-17 18:58 ` Daniel Borkmann
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=20200317053550.uk2lzcqfrrmgsdq7@kafai-mbp \
--to=kafai@fb.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=netdev@vger.kernel.org \
/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).