Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2074360rdd; Thu, 11 Jan 2024 20:21:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHca+mYP8UFJ+sEzt/t00Zh9F+TJcfFq3ps8VEsW641V/xGjdXRg64/eIm5Z8l1rEyXX1Ot X-Received: by 2002:a17:902:e78a:b0:1d4:42c0:a4da with SMTP id cp10-20020a170902e78a00b001d442c0a4damr198978plb.91.1705033317166; Thu, 11 Jan 2024 20:21:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705033317; cv=none; d=google.com; s=arc-20160816; b=cAr9HYX1+QbZsZv3KPF7PFPNLvu/LSOR6cPWyYUsAs+C4WmYkQ9kp0hOU6WAp7Vjrp 9ky3COp6Ru3PQ7BEWnRWqvWz77C7YoxljAySPiXEqtbbxRti5MpCCEAcjh9ewIwuVSZc Sg/sRXYgVRTGffw7Ys/uVgaA7wIM6+8SVvo5QIUTSJqGKCf7q5GsgSPi0wVs3MphDC8j 9dfFoGeN0PdasKigWSaRhntD7h7cntVIONnxX2a4ljx+teA/GM+MBeIYI+8ajmpBpPSr DK4xUk+xoyQ+JrYtka5RqPls+gn+vTahO9ZO2dFkQ6VcvKtS0ACE8riBIWV3E8SLBRRN NCuQ== 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=hlCagvD4RtHGbWxSnaQj2wUHst+49ZQgQBS71rVz4zQ=; fh=yECD7NgnTI3gLd2JYWx196DBx1V8pQOlQZzWlb1vTy8=; b=wMderHvMk0IRCPxZeRG5v2dz90v7Yv9jSpnV2ClZ9vU7xkq7coq7tvN1eYlERQ/TAQ T10A1Lx/FWaFgUidm/mklmrXWaJ8mdedtw5sk/nT8yEOyaRdmEO8luLk8O8VpPE6OnJX gf9j4WVOA4/Jm36cKUBHSw9yfwU2KGTyvmlQ4lGScSnbKzP+kmy6aZ7u6uRNWgY2kXg/ 0GIJquFbrM6LiNbhUx3AbF1HlQ/WJ+B7o2EAwlg0JkmVMaQ4Vlk+byHH8ff4JLW+lZ7o Tvlw6ed67O9DZ1Q+jYF+ESbI+ACH13Q/h+0CFDagnzRZryhMGSe8XBYEIUEY8knNBTci Vtlg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24284-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24284-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ky15-20020a170902f98f00b001d58bce3241si2296499plb.589.2024.01.11.20.21.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 20:21:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-24284-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-24284-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-24284-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 502D5B22314 for ; Fri, 12 Jan 2024 04:21:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E7AF1B29D; Fri, 12 Jan 2024 04:21:45 +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 A2AAF1B28E; Fri, 12 Jan 2024 04:21:41 +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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TB7dk48gFz4f3kkN; Fri, 12 Jan 2024 12:21:30 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 9073D1A01A9; Fri, 12 Jan 2024 12:21:32 +0800 (CST) Received: from [10.174.176.117] (unknown [10.174.176.117]) by APP1 (Coremail) with SMTP id cCh0CgB3lQ5IvqBlaHlSAg--.3495S2; Fri, 12 Jan 2024 12:21:32 +0800 (CST) Subject: Re: [PATCH bpf-next v2] 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: <20240112015700.19974-1-yangtiezhu@loongson.cn> From: Hou Tao Message-ID: <1e919c98-2fc4-bd03-df19-97c4e8a24649@huaweicloud.com> Date: Fri, 12 Jan 2024 12:21:28 +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: <20240112015700.19974-1-yangtiezhu@loongson.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-CM-TRANSID:cCh0CgB3lQ5IvqBlaHlSAg--.3495S2 X-Co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hi, On 1/12/2024 9:57 AM, 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 > --- > v2: Remove inline keyword in C files, sorry for that. > > Thanks very much for the feedbacks from Eduard, John, Jiri and Daniel. > I do not move loop inlining tests to test_progs, just copy some check > functions and do the minimal changes in test_verifier. > > tools/testing/selftests/bpf/test_verifier.c | 39 +++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c > index f36e41435be7..d4e600e3caec 100644 > --- a/tools/testing/selftests/bpf/test_verifier.c > +++ b/tools/testing/selftests/bpf/test_verifier.c > @@ -21,6 +21,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -1397,6 +1398,34 @@ 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 bool is_jit_enabled(void) > +{ > + const char *jit_sysctl = "/proc/sys/net/core/bpf_jit_enable"; > + bool enabled = false; > + int sysctl_fd; > + > + sysctl_fd = open(jit_sysctl, 0, O_RDONLY); It should be open(jit_sysctl, O_RDONLY). > + if (sysctl_fd != -1) { > + char tmpc; > + > + if (read(sysctl_fd, &tmpc, sizeof(tmpc)) == 1) > + enabled = (tmpc != '0'); > + close(sysctl_fd); > + } > + > + return enabled; > +} > + > static int null_terminated_insn_len(struct bpf_insn *seq, int max_len) > { > int i; > @@ -1662,6 +1691,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv, > goto close_fds; > } > > + if (!is_jit_enabled()) { Is it necessary to check whether jit is enabled or not each time ? Could we just check it only once just like unpriv_disabled does ? > + for (i = 0; i < prog_len; i++, prog++) { Is it better to only check pseudo_func only when both fd_prog < 0 and saved_errno == EINVAL are true, so unnecessary check can be skipped ? > + if (insn_is_pseudo_func(prog)) { > + printf("SKIP (callbacks are not allowed in non-JITed programs)\n"); > + skips++; > + goto close_fds; > + } > + } > + } > + > alignment_prevented_execution = 0; > > if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) {