Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1706834pxb; Wed, 9 Feb 2022 02:44:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzMLmIf8wvCiD0STnspKkYV5/B+NlcPeEkvwKxJkQOmXHe5YGaqoXQRPWavppiwdvjZkHPX X-Received: by 2002:a63:8a4c:: with SMTP id y73mr1380112pgd.303.1644403470123; Wed, 09 Feb 2022 02:44:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644403470; cv=none; d=google.com; s=arc-20160816; b=uaAJ0yiX51NBuQlY9ElMwYQ9B7DTQUOfp6NF0Ys4Pa1Q5xfW7rdVZfRbrD2fo1t6WK PP8qFBp2wM7u8IRGS2D+jPmcoytMDV9Jy8ociyOuMjEfQKhPZPDeBsyj1uLuTlZb/ISw LvDPISqnvZ9272o57O0UW8+zui86vmrxsiFczU6oZqFpBjlR5FYH2TB+5bYxlMbsfktr 6be7NndSJBwfZKF8eU7dtAjK5dy0FI9UdmzKEs1OMjw6dYmNhk/stocmQpHcouCIZQWJ G0HvbGzsw94OEfN8ZVEuafDYpCnz8L49AHPwNS5E+qLaU4JFFzYRev9i3bT0xZh+7PBK WObQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=icW1CmJt7V7nnYt5AEHzW1LfQUR9u0/06jxrbW0ydIE=; b=rFXMJ3M1/7inidjSmy4uLlrnNiVJ8Z92fhpocXhMP34YTwE9DfnXvqd5u5NWy6lkiH SdwoFZ0wiiyUq+JcfP2DP9/e4SIvEsnz8kaggL37zXYcoaSWoHUcZkBwgDUnFeNQsIiO VRoMtzkeG04IX3vpUfQVWorrX1bNTcAC/2hPSyvIhcmvINvBgikyJ0VapUSON+YGbJvb 3RUPhXTHjOP3LMzwVVe0GhGmItWbiuUK6Vkedrbyj+p74mS7Q2fp8wxUYsl/zEDM3N8v /aI4Q9kRuUCvce9JP2KOH32lJbH1wXQsBPys0Z7TPGtLOGMwZRx57K5bUncAFw2oEMwY y7GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jWTvazfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id k8si2263405plg.110.2022.02.09.02.44.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 02:44:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=jWTvazfU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id ECD81C1DF835; Wed, 9 Feb 2022 01:25:32 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236428AbiBHXYX (ORCPT + 99 others); Tue, 8 Feb 2022 18:24:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234907AbiBHXYV (ORCPT ); Tue, 8 Feb 2022 18:24:21 -0500 Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80B83C061576; Tue, 8 Feb 2022 15:24:19 -0800 (PST) Received: by mail-il1-x135.google.com with SMTP id b5so291358ile.11; Tue, 08 Feb 2022 15:24:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=icW1CmJt7V7nnYt5AEHzW1LfQUR9u0/06jxrbW0ydIE=; b=jWTvazfUXIGZM4J993OHGxm2ZT3pV/4rQPbUpZfltxws6BXlwBQBM2zYTSjY4Rm/Jt pmCf2lp0vaijmggY0iiIvc0is4diW9zh72iCOlZHinv7lbxSSZU962g9QzsHC55DN7t/ 6Ov6Op+kTCxBjT94pLbDXuyQ71l7it10AJouojfJCWSDGCeBLdHSGFLdrmAYVN1LXAgf NTgdRwvZendUKApqUXOKwNFdEN1AseLeyEHkBHAbrAUGgiWSbSKwOK2W40bPf08L5kq5 sAbq7euYFesaYWWTcr5jmpyMk+xTcwyRDHWb+IkpT4CUbkuVSiy0BMjFawXX3HAdTAOu wwyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=icW1CmJt7V7nnYt5AEHzW1LfQUR9u0/06jxrbW0ydIE=; b=JprkbFj/ZYZocFmqI0GwfA+8R5RPw8oNl46UospMctLu3ki+q09Luk/11zh9TJYh7q XWpqYf6QXTza07EaIfTcnENxNmK2ty3zZUnpnjL3WAc4/cAS0CofgpGDwSg/88as/Puq Ppsntdq/vL0KB3bK0NM+wtqIaEF4topYU5ptTuLf/CsgDGwJvk6RY9mic8rJBo5fSSNf UFi0+0VkJAcgbvCj2d/3ZDl/0ni1MIyuEVn21yKFG5mgVY2ngDbbzRuCUzQDFQWGhnUP vzqU1JBK3EkdyEu0iq75o6SGiNqh+RAlOc3cOR4jiU3XJTXnqoY2qg4chIjEXDz/6238 eJnA== X-Gm-Message-State: AOAM531x1dok55d1nnrOf1O2EpWl7L2y/ZelcBVZZlc9XsJbjfoArQlZ hNX+Y0hZCKEy2gMPELMzUTUvQJKdetd9uGWtqrA= X-Received: by 2002:a05:6e02:1bcd:: with SMTP id x13mr3347247ilv.98.1644362658855; Tue, 08 Feb 2022 15:24:18 -0800 (PST) MIME-Version: 1.0 References: <20220202135333.190761-1-jolsa@kernel.org> <20220202135333.190761-9-jolsa@kernel.org> In-Reply-To: From: Andrii Nakryiko Date: Tue, 8 Feb 2022 15:24:07 -0800 Message-ID: Subject: Re: [PATCH 8/8] selftest/bpf: Add fprobe test for bpf_cookie values To: Jiri Olsa Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt , Jiri Olsa Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE 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 On Tue, Feb 8, 2022 at 1:16 AM Jiri Olsa wrote: > > On Mon, Feb 07, 2022 at 10:59:32AM -0800, Andrii Nakryiko wrote: > > On Wed, Feb 2, 2022 at 5:54 AM Jiri Olsa wrote: > > > > > > Adding bpf_cookie test for kprobe attached by fprobe link. > > > > > > Signed-off-by: Jiri Olsa > > > --- > > > .../selftests/bpf/prog_tests/bpf_cookie.c | 73 +++++++++++++++++++ > > > .../selftests/bpf/progs/fprobe_bpf_cookie.c | 62 ++++++++++++++++ > > > 2 files changed, 135 insertions(+) > > > create mode 100644 tools/testing/selftests/bpf/progs/fprobe_bpf_cookie.c > > > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c > > > index cd10df6cd0fc..bf70d859c598 100644 > > > --- a/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c > > > +++ b/tools/testing/selftests/bpf/prog_tests/bpf_cookie.c > > > @@ -7,6 +7,7 @@ > > > #include > > > #include > > > #include "test_bpf_cookie.skel.h" > > > +#include "fprobe_bpf_cookie.skel.h" > > > > > > /* uprobe attach point */ > > > static void trigger_func(void) > > > @@ -63,6 +64,76 @@ static void kprobe_subtest(struct test_bpf_cookie *skel) > > > bpf_link__destroy(retlink2); > > > } > > > > > > +static void fprobe_subtest(void) > > > +{ > > > + DECLARE_LIBBPF_OPTS(bpf_link_create_opts, opts); > > > + int err, prog_fd, link1_fd = -1, link2_fd = -1; > > > + struct fprobe_bpf_cookie *skel = NULL; > > > + __u32 duration = 0, retval; > > > + __u64 addrs[8], cookies[8]; > > > + > > > + skel = fprobe_bpf_cookie__open_and_load(); > > > + if (!ASSERT_OK_PTR(skel, "fentry_raw_skel_load")) > > > + goto cleanup; > > > + > > > + kallsyms_find("bpf_fentry_test1", &addrs[0]); > > > + kallsyms_find("bpf_fentry_test2", &addrs[1]); > > > + kallsyms_find("bpf_fentry_test3", &addrs[2]); > > > + kallsyms_find("bpf_fentry_test4", &addrs[3]); > > > + kallsyms_find("bpf_fentry_test5", &addrs[4]); > > > + kallsyms_find("bpf_fentry_test6", &addrs[5]); > > > + kallsyms_find("bpf_fentry_test7", &addrs[6]); > > > + kallsyms_find("bpf_fentry_test8", &addrs[7]); > > > + > > > + cookies[0] = 1; > > > + cookies[1] = 2; > > > + cookies[2] = 3; > > > + cookies[3] = 4; > > > + cookies[4] = 5; > > > + cookies[5] = 6; > > > + cookies[6] = 7; > > > + cookies[7] = 8; > > > + > > > + opts.fprobe.addrs = (__u64) &addrs; > > > > we should have ptr_to_u64() for test_progs, but if not, let's either > > add it or it should be (__u64)(uintptr_t)&addrs. Otherwise we'll be > > getting compilation warnings on some architectures. > > there's one in btf.c, bpf.c and libbpf.c ;-) so I guess it could go to bpf.h No, it shouldn't, bpf.h is a public API header. Let's keep internal helpers internal. Just copy/paste. > > > > > > + opts.fprobe.cnt = 8; > > > + opts.fprobe.bpf_cookies = (__u64) &cookies; > > > + prog_fd = bpf_program__fd(skel->progs.test2); > > > + > > > + link1_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FPROBE, &opts); > > > + if (!ASSERT_GE(link1_fd, 0, "link1_fd")) > > > + return; > > > + > > > + cookies[0] = 8; > > > + cookies[1] = 7; > > > + cookies[2] = 6; > > > + cookies[3] = 5; > > > + cookies[4] = 4; > > > + cookies[5] = 3; > > > + cookies[6] = 2; > > > + cookies[7] = 1; > > > + > > > + opts.flags = BPF_F_FPROBE_RETURN; > > > + prog_fd = bpf_program__fd(skel->progs.test3); > > > + > > > + link2_fd = bpf_link_create(prog_fd, 0, BPF_TRACE_FPROBE, &opts); > > > + if (!ASSERT_GE(link2_fd, 0, "link2_fd")) > > > + goto cleanup; > > > + > > > + prog_fd = bpf_program__fd(skel->progs.test1); > > > + err = bpf_prog_test_run(prog_fd, 1, NULL, 0, > > > + NULL, NULL, &retval, &duration); > > > + ASSERT_OK(err, "test_run"); > > > + ASSERT_EQ(retval, 0, "test_run"); > > > + > > > + ASSERT_EQ(skel->bss->test2_result, 8, "test2_result"); > > > + ASSERT_EQ(skel->bss->test3_result, 8, "test3_result"); > > > + > > > +cleanup: > > > + close(link1_fd); > > > + close(link2_fd); > > > + fprobe_bpf_cookie__destroy(skel); > > > +} > > > + > > > static void uprobe_subtest(struct test_bpf_cookie *skel) > > > { > > > DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, opts); > > > @@ -249,6 +320,8 @@ void test_bpf_cookie(void) > > > > > > if (test__start_subtest("kprobe")) > > > kprobe_subtest(skel); > > > + if (test__start_subtest("rawkprobe")) > > > > kprobe.multi? > > yes > > thanks, > jirka >