Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp177360rdb; Sun, 21 Jan 2024 23:58:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGv6OnnS8k0PvbVXN/bTJcFLYKLNtp5BRoQN5epoteG/CwRnEeLkLKTpWmn8lmy5TpP1ZUa X-Received: by 2002:a25:4147:0:b0:dbe:3257:f23b with SMTP id o68-20020a254147000000b00dbe3257f23bmr1597449yba.108.1705910293429; Sun, 21 Jan 2024 23:58:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705910293; cv=pass; d=google.com; s=arc-20160816; b=Z5XomV0DaLOTfMyeC3zwXvOmMRj9+3O1ISCr4n84wPydH9kNeQh5UlWqSuwn5dUAFk BUCM/0b2nYpFBkv8zZ2ZaKyj/d89aq2r+InKTMHeiKZMfOH3qxgIYA4PELV6Vj6s3ojX otSE4Cog/bQAwMZMK4vBIk2t41gch2gckfz9KPtg6VWQZByDPwJqXhVyHMJuy/K6Mn8I 4twndkWCAlb2uNWvRtWoFpV7lFGNUnG/kBtfIEk6iZmr8Vb6Xn0e7uHJMfS3702+2ex+ ntHCAMkkii7+NX8oggo3dqXCghzs2xedSZZS85jh67bwDidb/iDincBmP3yg1EQWmTC1 8uQA== ARC-Message-Signature: i=2; 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:references:in-reply-to:message-id :date:subject:cc:to:from; bh=1QGJHcZZpcuu3lEJoo7fBNSlaX/z96T6ERNQ4y4DoCI=; fh=EvR41b01nAjTv94pCV1QdzfpeHL6jIcxejUnN6KALZM=; b=ZNIMAMKv2ZfRxkV0LqRzy8BVCaGL05XyHs9aOhXXOGvDj9CAYryIAOdEJGDPKoUcgD fefm4tC2hCVIQTq21+iYFt9+Y38jTre4kMURSi+oznRa+L8Xgb5in8+6D3Iqc3x/XlX7 vLihhLzuh2oPvjdV+2u9L4ErsXsuOTYhvwMseQmXVnGo98lmgfGdxx5+wjPFJAtNjLJH Zz/uVvphCazZEFyQP4D7ScJsEY5177XilBg5Z5Hg5nuZW9DQ+6KeIXqrAxDcx671odTx ZB3rtw2svtP8UlgNyTRf6TXzCrwFNjM9RSVo6ly8W/RSxhV8LDvws8rK4wemPeZS2F3t CUOw== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-32478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32478-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s10-20020ac85cca000000b0042a334dde02si4008661qta.361.2024.01.21.23.58.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 Jan 2024 23:58:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-32478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32478-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 321441C21CF2 for ; Mon, 22 Jan 2024 07:58:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D33C03612F; Mon, 22 Jan 2024 07:57:16 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DA2F18C3D; Mon, 22 Jan 2024 07:57:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705910236; cv=none; b=CR6P6gcPJYyEbDgKjiahGlHarW8h5Rj5OredbHG+gNl9vLmstNiZelBpAcUPM2QnQ7mDZAZLoS77lA3Gck8o5C0yy6rl9jDEJpQrqbfxZsAA+VCShpOhAg4clJ2YUfNSUfrE1vlJrL6BUnGl8ewS3LjER9oGE7Tcb/FEUXZiDAE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705910236; c=relaxed/simple; bh=l6MfQQw55J1lyN8m43DBpKixXCKLSr/+URZH8IUBdPw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KRQEVhzQpeM4iRuKICzwx4W/xjAPW/PmfUd29qQ7Uq4TseCqqq8FBaMyPqbc45m09rZ8KNxvUtX6LHRMhBbge+XhzIusXJTiUgcY9NtEeT8X1AlSZ0/5g5Ky46mooCimoZMufmSY70Umhl6b7amWiTRiZucwedMEh+d2kw9p7OI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 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 _____8AxPOnSH65ll20DAA--.3871S3; Mon, 22 Jan 2024 15:57:06 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxf8_NH65lKSIRAA--.13989S5; Mon, 22 Jan 2024 15:57:04 +0800 (CST) From: Tiezhu Yang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: Eduard Zingerman , John Fastabend , Jiri Olsa , Hou Tao , Song Liu , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next v6 3/3] selftests/bpf: Skip callback tests if jit is disabled in test_verifier Date: Mon, 22 Jan 2024 15:57:00 +0800 Message-ID: <20240122075700.7120-4-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240122075700.7120-1-yangtiezhu@loongson.cn> References: <20240122075700.7120-1-yangtiezhu@loongson.cn> 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:AQAAf8Cxf8_NH65lKSIRAA--.13989S5 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoWxGFW3tr1UtrW5ur1xGF1fKrX_yoW5Gw45pa y8JF1qkF10qa4I9ry7A393GFWY9w4vqw48JFy5uw48Z3Z5Aw47Xr1fKFyYvasxGrWFqasa vanrurWUWw1UJFXCm3ZEXasCq-sJn29KB7ZKAUJUUUUr529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBab4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAF wI0_Gr1j6F4UJwAaw2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2 xF0cIa020Ex4CE44I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_ Jw0_WrylYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x 0EwIxGrwCY1x0262kKe7AKxVWUAVWUtwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkE bVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s026c02F40E14v26r1j6r18MI8I3I0E74 80Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jw0_GFylIxkGc2Ij64vIr41lIxAIcVC0 I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04 k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7Cj xVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j2MKZUUUUU= 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, just 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 Acked-by: Hou Tao Acked-by: Song Liu --- tools/testing/selftests/bpf/test_verifier.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/testing/selftests/bpf/test_verifier.c b/tools/testing/selftests/bpf/test_verifier.c index 1a09fc34d093..cf05448cfe13 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; @@ -1622,6 +1623,16 @@ static void do_test_single(struct bpf_test *test, bool unpriv, alignment_prevented_execution = 0; if (expected_ret == ACCEPT || expected_ret == VERBOSE_ACCEPT) { + if (fd_prog < 0 && saved_errno == EINVAL && jit_disabled) { + for (i = 0; i < prog_len; i++, prog++) { + if (!insn_is_pseudo_func(prog)) + continue; + printf("SKIP (callbacks are not allowed in non-JITed programs)\n"); + skips++; + goto close_fds; + } + } + if (fd_prog < 0) { printf("FAIL\nFailed to load prog '%s'!\n", strerror(saved_errno)); @@ -1844,6 +1855,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); -- 2.42.0