Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp1594537rdd; Thu, 11 Jan 2024 04:06:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdKPzCmpxlUiWhsH1eUEu3JE/i/AOdCL1DNRX+iEKtIKz1WUDt4Iz2mORcvdesY0IWO9yU X-Received: by 2002:a17:906:37cb:b0:a2a:a4c4:5229 with SMTP id o11-20020a17090637cb00b00a2aa4c45229mr368462ejc.90.1704974789017; Thu, 11 Jan 2024 04:06:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704974789; cv=none; d=google.com; s=arc-20160816; b=GO6wu7w64tFIi3tJwYxLdIJM4sKM6feOwK/eK+9dnvVJIAPo6eInyqtmBQ0TYvFW0F kt3cTGVNIfvbbPQ35Z6TEq+XCgpcKF/kz+a5XIANL4GzkpSl4mcc8PG07AeIbj2KyJa6 lGOjtzN91xrjqyvJUAXEUdesmPipokGIRS3hqU36puP2S8TBDXa41jPGG0O8IAN+hQqx MSVefYdTWWtl7TTlcNiPcn3HZ7nw7SgU0W1WF8o3HI7GWjGmn2aAPSwGJnC9dNe6Yx+S QAkdWLvAFmXlfIIpYMyUAT8VD6BVHpicch5LFXNi/mXQuWXqO7XD0GB5C1omLQfTy42Z h03g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=DYgfHel0NGbYCySNezQrq7sthLlXWNJrgqiDosqqseU=; fh=f6IS13o5n0Cpbs3W/7GmwDBt6Anbk36/+WoWq6j8Je8=; b=XUHEx2UAxtOMEo4lbQKFtsDnP+8wA+WX0T1yXqZkd3qq/je14qX/M/YC7Hu/31Aran R9Q3X/ZJUXf8TpjAwZYPtTod0P8qCajS6hK1CuAKFwLmoVP/HlJK41yCIPn72uyt8voz x5BdyJUVkwcY51eqEVM/BoXUK+p6U63UHw68MuQ/vk3BEJKbxykGFlRNRI4YUPMZgNUd WOB1v9H1u6jyxYIfDiBkgb7ZIUvTnoeO707sX8v6ILO8R6wfW4DLE/vzRVbJIYY1Cmrm kg6xMRMdfyd+oNb/YN6+1kFSAwwQ6IakrXz/MaNgwS/6hhvyUQbCT20KcZ1sHnA451t3 WHxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23550-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23550-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z18-20020a170906075200b00a2b2bdb8d7esi426205ejb.75.2024.01.11.04.06.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jan 2024 04:06:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-23550-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-23550-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-23550-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 am.mirrors.kernel.org (Postfix) with ESMTPS id BDC181F24285 for ; Thu, 11 Jan 2024 12:06:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8976D3D38C; Thu, 11 Jan 2024 12:01:44 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 92A6432C89; Thu, 11 Jan 2024 12:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8CxLOui2J9lh0EEAA--.12675S3; Thu, 11 Jan 2024 20:01:38 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxO9yg2J9llQsQAA--.41850S2; Thu, 11 Jan 2024 20:01:37 +0800 (CST) From: Tiezhu Yang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Eduard Zingerman , John Fastabend , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v1] selftests/bpf: Skip callback tests if jit is disabled in test_verifier Date: Thu, 11 Jan 2024 20:01:36 +0800 Message-ID: <20240111120136.16013-1-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8CxO9yg2J9llQsQAA--.41850S2 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxGFW3tr1UtrW5ur1xGr1kCrX_yoW5ury3pF WkCr1qkF1UJFySgr17Arn3JFWFvw4vqw18Gr98G3yUZa1DA343Jrn7KFyjvF9xGrW5ua4S vFWI9FW5uw4UXFXCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Jr0_Gr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AK xVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx 1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv 67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2 Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s02 6x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0x vE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6x kF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07j0FALUUUUU= 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 --- 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..7c74e65ee25c 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 inline 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); + 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()) { + 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; + } + } + } + alignment_prevented_execution = 0; if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) { -- 2.42.0