Received: by 2002:a05:7412:8d11:b0:fa:4934:9f with SMTP id bj17csp546625rdb; Mon, 15 Jan 2024 06:00:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IH8gD0m2TsRPwbdznI6AG0xQxbWHQKZIZJ0jnwL9FCd+N75hJbHesYEBA8A+P1c1eD6Fmel X-Received: by 2002:a17:902:b682:b0:1d4:bd4a:df44 with SMTP id c2-20020a170902b68200b001d4bd4adf44mr2414493pls.14.1705327256527; Mon, 15 Jan 2024 06:00:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705327256; cv=none; d=google.com; s=arc-20160816; b=iBfr8apZYpFaQvmWQupTKtAWvVBJKb9OMUxlkP9NI2OtD7hL4lgtxGTZRVqzUMtbX8 QzebfG1TUuany0koMCu6ZTbLzpPPGUJYETXQMdprassloTCt84TUwRD3jSrDbQ/O+sx+ qD1Dw3cMGTWotQqatOFHE9B2YBE6/+zHIfF/eX7zO8tp2GGI5uc+lX7gF9mlAU4Xv0IL gJF34iT3TWg8sh4NDs81qMgmb3/EIVHDDl0jOQVdb9ChSjpbbGQ9lDgOTk7RaosgvzLo Wd1TXOt5VbI0eJ3fE/AHhpnUTjIp7aVaBnqR8rWUKJIXSYhGJgMOu+iniYevCckdnJwN UV6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-language:content-transfer-encoding:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=+c2TsUtCg7sEI9ivc6Wg4TMFT4g9T9eD53LQ00RhhUQ=; fh=yECD7NgnTI3gLd2JYWx196DBx1V8pQOlQZzWlb1vTy8=; b=llIfoxhJ5KCb8r/XsYSxhCMaqKappaz60o4fber1LSQ+i75WtNKfaOM8o7qzKHey+/ C2g6TtPx/j9mJv+G/JgPQng6t5Y1/+ZygGE+NxpIFPyrhR/ykFfZDHGiS7RkHEqsto9V yyFQ4cGHmDjGKyt8HKyOF51Y0kSju03uj9RQCzgnEM1bnEKtY6yxWwRyuY5NDg2iImu1 1PLpNBWCLlRKoEB/nV64c3l9mhNBv146vsVJZKZBSEb45pCLUjZ/4k8VBZtRk3xwPA8F 2KPP7BWsf4jSwdIdD6ILJsvY9MXqAW0Vhnci9eeHYCj8TstCTQZEOzS+evcetFkhXfup 7Yew== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26068-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26068-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h14-20020a170902ac8e00b001d3eaa80970si8989358plr.174.2024.01.15.06.00.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 06:00:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26068-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26068-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26068-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4217D28056E for ; Mon, 15 Jan 2024 14:00:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A0A5175BF; Mon, 15 Jan 2024 14:00:25 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D212C1757A; Mon, 15 Jan 2024 14:00:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TDDL969ZXz4f3jq2; Mon, 15 Jan 2024 22:00:17 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id EEC511A0BAE; Mon, 15 Jan 2024 22:00:19 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP2 (Coremail) with SMTP id Syh0CgBXeg1xOqVlBRm1Aw--.63466S2; Mon, 15 Jan 2024 22:00:19 +0800 (CST) Subject: Re: [PATCH bpf-next v3 2/2] selftests/bpf: Skip callback tests if jit is disabled in test_verifier To: Tiezhu Yang , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Eduard Zingerman , John Fastabend , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org References: <20240115070010.12338-1-yangtiezhu@loongson.cn> <20240115070010.12338-3-yangtiezhu@loongson.cn> From: Hou Tao Message-ID: <84e15d1c-c2a6-9af4-c123-beea01893a8f@huaweicloud.com> Date: Mon, 15 Jan 2024 22:00:17 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240115070010.12338-3-yangtiezhu@loongson.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-CM-TRANSID:Syh0CgBXeg1xOqVlBRm1Aw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/15/2024 3:00 PM, Tiezhu Yang wrote: > If CONFIG_BPF_JIT_ALWAYS_ON is not set and bpf_jit_enable is 0, there > exist 6 failed tests. > > [root@linux bpf]# echo 0 > /proc/sys/net/core/bpf_jit_enable > [root@linux bpf]# echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled > [root@linux bpf]# ./test_verifier | grep FAIL > #106/p inline simple bpf_loop call FAIL > #107/p don't inline bpf_loop call, flags non-zero FAIL > #108/p don't inline bpf_loop call, callback non-constant FAIL > #109/p bpf_loop_inline and a dead func FAIL > #110/p bpf_loop_inline stack locations for loop vars FAIL > #111/p inline bpf_loop call in a big program FAIL > Summary: 768 PASSED, 15 SKIPPED, 6 FAILED > > The test log shows that callbacks are not allowed in non-JITed programs, > interpreter doesn't support them yet, thus these tests should be skipped > if jit is disabled, copy some check functions from the other places under > tools directory, and then handle this case in do_test_single(). > > With this patch: > > [root@linux bpf]# echo 0 > /proc/sys/net/core/bpf_jit_enable > [root@linux bpf]# echo 0 > /proc/sys/kernel/unprivileged_bpf_disabled > [root@linux bpf]# ./test_verifier | grep FAIL > Summary: 768 PASSED, 21 SKIPPED, 0 FAILED > > Signed-off-by: Tiezhu Yang > --- > tools/testing/selftests/bpf/test_verifier.c | 23 +++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c > index 1a09fc34d093..70f903e869b7 100644 > --- a/tools/testing/selftests/bpf/test_verifier.c > +++ b/tools/testing/selftests/bpf/test_verifier.c > @@ -74,6 +74,7 @@ > 1ULL << CAP_BPF) > #define UNPRIV_SYSCTL "kernel/unprivileged_bpf_disabled" > static bool unpriv_disabled = false; > +static bool jit_disabled; > static int skips; > static bool verbose = false; > static int verif_log_level = 0; > @@ -1355,6 +1356,16 @@ static bool is_skip_insn(struct bpf_insn *insn) > return memcmp(insn, &skip_insn, sizeof(skip_insn)) == 0; > } > > +static bool is_ldimm64_insn(struct bpf_insn *insn) > +{ > + return insn->code == (BPF_LD | BPF_IMM | BPF_DW); > +} > + > +static bool insn_is_pseudo_func(struct bpf_insn *insn) > +{ > + return is_ldimm64_insn(insn) && insn->src_reg == BPF_PSEUDO_FUNC; > +} > + > static int null_terminated_insn_len(struct bpf_insn *seq, int max_len) > { > int i; > @@ -1619,6 +1630,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv, > goto close_fds; > } > > + if (fd_prog < 0 && saved_errno == EINVAL && jit_disabled) { > + for (i = 0; i < prog_len; i++, prog++) { > + if (insn_is_pseudo_func(prog)) { > + printf("SKIP (callbacks are not allowed in non-JITed programs)\n"); > + skips++; > + goto close_fds; > + } > + } > + } I ran test_verifier before applying the patch set, it seems all expected_ret for these failed programs are ACCEPT, so I think it would be better to move the not-allowed-checking into "if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT)" block. I should suggest such modification in v2, sorry about that. > + > alignment_prevented_execution = 0; > > if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) { > @@ -1844,6 +1865,8 @@ int main(int argc, char **argv) > return EXIT_FAILURE; > } > > + jit_disabled = !is_jit_enabled(); > + > /* Use libbpf 1.0 API mode */ > libbpf_set_strict_mode(LIBBPF_STRICT_ALL); >