Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1677409pxb; Wed, 9 Feb 2022 01:57:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJwoo8pgQRcidDYr8RXWMwV+k9pbg+VcHVLUoRcNUSFFCgBhBVccF7Pzodjfi1x2PJe+HejZ X-Received: by 2002:a62:5248:: with SMTP id g69mr1465459pfb.40.1644400668717; Wed, 09 Feb 2022 01:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644400668; cv=none; d=google.com; s=arc-20160816; b=RR1YNTejdiEFMYQG9gJeMeCzH9/WgAvYYwl/aD5y85FLF9ecVo2tFGMKJjg2x/jJAN M7Dw5o+Ts6xr7NYMntdmIz6LaFbogk73x10g1R7oUJL32/uleRa+Mi8nzfz8Kv7EUXNq oaHkNfansCyjCPBfvv9plNJdPoxTSzqCrC8+pHpcSt1quzTCbZXSHtbMbS+FdS5E2TMD b/DGfBHtNzUL86FwiPnDaxVp76wTGQ3tRLNK5gVOxa/hzgEpl/x8i8rIbDjeYsiEjvQE g488LsXsyvmJPcSKKYiqlVs3VQdRYWWhUtF9QfIgEizo03SlHl3upR183uwrmpxCu3pV uArA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vWTeTtK7QuygKDGNGhC3/zMgZotQ2ldpExYYNODBF4o=; b=HcTgBDNxCyFvuL80Y0By/SBp/WlRaT36juGWmgcWqAk4lBU7jwRBsz8O8qavfQojL0 dnJDxZoYvfvPHm68vV7Q58YoV3Q1Tx6b+UA+9icYWVX6NdtIL15NGTLrkFHxjBJCR/xC U8QV7RFWP0BqjWdy9EvP9T2eNKOYESKY3CPoG4RHSwmQ3fk0p7hXbLOVBGImDq5JaR1i hlmP417wLQcDXw0b5sfC2Q5O5B1AqljTsy2U3+Q+TrIGXJDiFOiAWB+Qrhxxy52951ko cyenlN0fCt11NyWUKHm86LQB4XERAEIqLZkmZ0kf6FV3oZgudmIXy6PhqMNJjcqDCohR uuOA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QOigSa2u; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id v12si4570076pjs.165.2022.02.09.01.57.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 01:57:48 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QOigSa2u; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B005DDF28ADD; Wed, 9 Feb 2022 01:11:19 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353418AbiBHJQE (ORCPT + 99 others); Tue, 8 Feb 2022 04:16:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353379AbiBHJQD (ORCPT ); Tue, 8 Feb 2022 04:16:03 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B7AB2C0401F0 for ; Tue, 8 Feb 2022 01:16:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644311761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vWTeTtK7QuygKDGNGhC3/zMgZotQ2ldpExYYNODBF4o=; b=QOigSa2uIUIC/0ykjaVnbD/d364QDOazpWy1cSTwmKjQeQCEdWkVqSiWRixE9A9fvA8EuG eR9qhOZ3UuCN7v200VFdV7w8fx4HQlrvSNzGCt6JNLYBNCUyZJNemEwSjIgFaWVtIy34A3 sj82scfrxazI+hu7OmHTx2qYFvmUm/Q= Received: from mail-ej1-f71.google.com (mail-ej1-f71.google.com [209.85.218.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-3nhrpAfIPayu3v3wGSzHDA-1; Tue, 08 Feb 2022 04:16:00 -0500 X-MC-Unique: 3nhrpAfIPayu3v3wGSzHDA-1 Received: by mail-ej1-f71.google.com with SMTP id v2-20020a170906292200b006a94a27f903so5479827ejd.8 for ; Tue, 08 Feb 2022 01:15:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=vWTeTtK7QuygKDGNGhC3/zMgZotQ2ldpExYYNODBF4o=; b=EEjxgSYvZX2OyVNCD4ncOdH01u3ZX6Dy82WmGrDN+xMJp2uDb/xG+yT7DNiiwV1SwW OGTIbVmz0zzaoKR3aJbl7h0cMINLyyluoFa5+mWTzIBQwgQjC7ag6hCaUCmSaEJlwfqh jGT5lgAHMiRI4oT5ls9fve54yCwNAMUiAmsQAyHKndA7nofvYWS+ScWTkYrUynONMoft muqCZNw0Nzt9lhWzv+ZM+TJb0CxZY/7+BTKkpZeuGF9uHn5kv6UyM8990U8SNu9XLHOH 6L5a5lUqCQuuuZz/TrirBV/vfR6T6mAxN8DC474s5U7DeCNk6o37u+/bs6oMjYEb9AXJ C9Pg== X-Gm-Message-State: AOAM5319kLN6YUT1w709Fpvj1IW5XxkYnrZ5HbbBUycm/JLtgrBN2ioD R9gmsTJGpwjhr9KhT5WkUK/5ElbMb2nrpEMM+u+i5WFF7NrclXV1i0WXmk6LtPRbbwPxqk7nuaX FeSrsaAVplG2zBrdQn4ZRF1rY X-Received: by 2002:aa7:cb87:: with SMTP id r7mr3496505edt.284.1644311758859; Tue, 08 Feb 2022 01:15:58 -0800 (PST) X-Received: by 2002:aa7:cb87:: with SMTP id r7mr3496479edt.284.1644311758630; Tue, 08 Feb 2022 01:15:58 -0800 (PST) Received: from krava (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id r6sm4025782ejd.100.2022.02.08.01.15.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 01:15:58 -0800 (PST) Date: Tue, 8 Feb 2022 10:15:56 +0100 From: Jiri Olsa To: Andrii Nakryiko 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 Subject: Re: [PATCH 8/8] selftest/bpf: Add fprobe test for bpf_cookie values Message-ID: References: <20220202135333.190761-1-jolsa@kernel.org> <20220202135333.190761-9-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 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 > > > + 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