From patchwork Mon Oct 9 16:14:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vernet X-Patchwork-Id: 150193 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1976535vqo; Mon, 9 Oct 2023 09:14:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJ4QIKRcWZRrUMv3LHl43Kva+eXnLccDXExjLjed4J60iVpdxAInk2Z0YY7XVBQ4QXZ/Wu X-Received: by 2002:a05:6808:a1c:b0:3af:985b:365c with SMTP id n28-20020a0568080a1c00b003af985b365cmr1920540oij.42.1696868071956; Mon, 09 Oct 2023 09:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696868071; cv=none; d=google.com; s=arc-20160816; b=O72ofzr9DZqZyMLrKEYVkw5GrTh4RJHmkXQTOMnfqMOrtMOTRJESBp88919pln+1I8 I5Y+8DCsGSR6cgI6TuEsdN71d2fghPseps6JHsyit2ctG8aM6uyk7PHmLMkXv3KiK/YJ 69fFfLkjOfWq++I878oTGwRSzXzQZ1VVkb1dUVBO9VvaSjERT2HuMzPeyQOZYfbyaryP fFe6qJpWEQ25bx8i0BEBEOJFJWwYgVgR1l0ETJAj1qWj1M1mfS+q81m3rJ/rSqClxP9B FeVJdU2h1EA8f1wz0ehk6aTj1zejbXaWCnU/7b3UqiISphOrnJxGJX7Tsb3veByGtNnC HIqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Nn/6KVXbliEOh9rFCg0BPlbCxwqo18KGwCNTlkH9z2s=; fh=fRduVGGcbGNLOU4DUo/BPZE9kW2AdZyQZjfnRZNvspU=; b=XTMHVu9W9kNS1dcvjvmbMqPOYuEfDw03prEvJ0CB40eugaoRnUI2J2DCDjx91VHTOd czBZfcvEnGTefAXpm3i++QJZHU8LB+wVbtApH3n1W9UA0qU4EFwpoBklgimY/lHmgLhF 9ZtXM8e/9RrUWnYZ1+FG19Mbxvcg1IGoMKMM0OXZHFAwMt5Q4xz0AnwjykTkmf815rpj zZ7M5/QW43PEZWCVNrk3hlIdNjvGa6JLwajjC13GDGvJ7y0xe/1H7ZNNChtFeJCgriVa Vl/cveJQ/qJoU/kpjXQZAJGWCfCSGDM8oyIpoCfjKOjh8CxKr3YjSQoyh72FUaKCYkfp CTpw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id 76-20020a63004f000000b005859aa3da1esi10281768pga.492.2023.10.09.09.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 09:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id ED89080212B9; Mon, 9 Oct 2023 09:14:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377146AbjJIQO1 (ORCPT + 18 others); Mon, 9 Oct 2023 12:14:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377152AbjJIQOZ (ORCPT ); Mon, 9 Oct 2023 12:14:25 -0400 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2112CDB; Mon, 9 Oct 2023 09:14:23 -0700 (PDT) Received: by mail-il1-f180.google.com with SMTP id e9e14a558f8ab-352a3a95271so18231295ab.0; Mon, 09 Oct 2023 09:14:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696868062; x=1697472862; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nn/6KVXbliEOh9rFCg0BPlbCxwqo18KGwCNTlkH9z2s=; b=ayXOAaNREBHp/zziISJHyEOiUq944jCcZYLXpCblWqKsEyUwScwxcL3XizWB85YfxQ HduAgQV1IzaIe/o73NHwWnPELg5lU46glo7yYqXlzK6Xf0PxsuLdrxPai9NtFdVhehPb VMCpCtGlKRZSAIIrhNn48F57lE8BIrGrBOGZWa/a2GHyUmRHoQQBUpxoh8iTFcKff/in bYP4+9a4muWwCbU9Ufm3v7ZxbEmwyLoyicFUWfI93Brvkx/Ar7Ye8JEGtguxb/NKTc73 Qqz/b8D5etdi0qMwwF3IzvjOF6OHnMmbt/c3qyBlzW35FWJHCrc4YUpFyDnKORzJxbZf 0HJw== X-Gm-Message-State: AOJu0YxA+M+Fq/zNqkCnRChYw9ess8h/6NeOG2axpV1bldrdo1xb9Ih0 Lk1mWpNSzZsuz4lhs/uG1AI5m41qZ4r6LD0G X-Received: by 2002:a92:c262:0:b0:34c:cf1f:2a4a with SMTP id h2-20020a92c262000000b0034ccf1f2a4amr19831982ild.4.1696868062029; Mon, 09 Oct 2023 09:14:22 -0700 (PDT) Received: from localhost (c-24-1-27-177.hsd1.il.comcast.net. [24.1.27.177]) by smtp.gmail.com with ESMTPSA id q2-20020a056e02078200b0035163fb9f9fsm2999771ils.43.2023.10.09.09.14.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 09:14:21 -0700 (PDT) From: David Vernet To: bpf@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH bpf-next 2/2] bpf/selftests: Add testcase for async callback return value failure Date: Mon, 9 Oct 2023 11:14:14 -0500 Message-ID: <20231009161414.235829-2-void@manifault.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231009161414.235829-1-void@manifault.com> References: <20231009161414.235829-1-void@manifault.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 09 Oct 2023 09:14:31 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779295135305720495 X-GMAIL-MSGID: 1779295135305720495 A previous commit updated the verifier to print an accurate failure message for when someone specifies a nonzero return value from an async callback. This adds a testcase for validating that the verifier emits the correct message in such a case. Signed-off-by: David Vernet --- .../testing/selftests/bpf/prog_tests/timer.c | 6 ++- .../selftests/bpf/progs/timer_failure.c | 47 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/progs/timer_failure.c diff --git a/tools/testing/selftests/bpf/prog_tests/timer.c b/tools/testing/selftests/bpf/prog_tests/timer.c index d8bc838445ec..760ad96b4be0 100644 --- a/tools/testing/selftests/bpf/prog_tests/timer.c +++ b/tools/testing/selftests/bpf/prog_tests/timer.c @@ -2,6 +2,7 @@ /* Copyright (c) 2021 Facebook */ #include #include "timer.skel.h" +#include "timer_failure.skel.h" static int timer(struct timer *timer_skel) { @@ -53,10 +54,11 @@ void serial_test_timer(void) timer_skel = timer__open_and_load(); if (!ASSERT_OK_PTR(timer_skel, "timer_skel_load")) - goto cleanup; + return; err = timer(timer_skel); ASSERT_OK(err, "timer"); -cleanup: timer__destroy(timer_skel); + + RUN_TESTS(timer_failure); } diff --git a/tools/testing/selftests/bpf/progs/timer_failure.c b/tools/testing/selftests/bpf/progs/timer_failure.c new file mode 100644 index 000000000000..226d33b5a05c --- /dev/null +++ b/tools/testing/selftests/bpf/progs/timer_failure.c @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023 Meta Platforms, Inc. and affiliates. */ + +#include +#include +#include +#include +#include "bpf_misc.h" +#include "bpf_tcp_helpers.h" + +char _license[] SEC("license") = "GPL"; + +struct elem { + struct bpf_timer t; +}; + +struct { + __uint(type, BPF_MAP_TYPE_ARRAY); + __uint(max_entries, 1); + __type(key, int); + __type(value, struct elem); +} timer_map SEC(".maps"); + +static int timer_cb_ret1(void *map, int *key, struct bpf_timer *timer) +{ + if (bpf_get_smp_processor_id() % 2) + return 1; + else + return 0; +} + +SEC("fentry/bpf_fentry_test1") +__failure __msg("should have been in (0x0; 0x0)") +int BPF_PROG2(test_ret_1, int, a) +{ + int key = 0; + struct bpf_timer *timer; + + timer = bpf_map_lookup_elem(&timer_map, &key); + if (timer) { + bpf_timer_init(timer, &timer_map, CLOCK_BOOTTIME); + bpf_timer_set_callback(timer, timer_cb_ret1); + bpf_timer_start(timer, 1000, 0); + } + + return 0; +}