Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1256153pxp; Sun, 6 Mar 2022 09:47:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwIJfl7CDz8h4Z2UB4sOHbaQjDZhAvgKQ60Cp1ARgr6oyIlJhUlA1G6K3jLbLxfwKvkJqD0 X-Received: by 2002:aa7:d147:0:b0:415:c68c:f8d6 with SMTP id r7-20020aa7d147000000b00415c68cf8d6mr7714051edo.67.1646588849905; Sun, 06 Mar 2022 09:47:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646588849; cv=none; d=google.com; s=arc-20160816; b=R+j/ozFgTjEJl0c1QzwpyegLPDl1ULToqAfiHhZ4S+LnYa9ANl/rfo00WjQsJphZam EBgIltVY+PzyvnKQyFbG7DEKjfSPdkqIXtV+rbZ/RPM6vNVT9OuaAQkRZQQ4x6//stKn Y6UuTuiZjxXAPFwGplUDH5b5mGDdNVefpJR/kvcOmBogmrpTOeiSX9f6ugMgdOUXLN3D Tb7qUTM9jsyBo+NIvKURBejINF55dSvjtDrXmhEY9+a/P11Z4QpOYQTJ7dp7aRezYKkK Tl8954G+BXmyJbzWBM8Is4qNXbmIDNUEhiOls2/WcfLYLnl4WpgYbzUIBTjPBdjRJCka wMYg== 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=1zzNgf433hyjGkgzGz6Qpkm1fu9BPDmLsvmtuyA914E=; b=xpr79maXjeAJjYyi+MH/y5+gPWCdfhzBR4npRHSCrKSsoHB50B7WSVFtTfkeM5DBvQ oAg/Lp179GBX2+HyQUf1W4S2VledkapsoGC0Ko0bucnlt4d3MtiG3jm2FPc7LHeCbLjW dS3B9YrZ6NdIQ9Cdw4c+sWaFizDyv1oCk75CbOqBhF2UvSMupXogfO/m4s1F0D7DHMf+ gY18gVKLPixnjq+nRM/f2ZW7s+dPI79n/tn7Dbn8eIBROQNSy0F83Wn7RI3fX5DXC+yX I1saBvQah/sPVm6S8vUBrhP92/PG+keWE8909izsPMBpCKpFl+x9RoRDY7V6aGpYE8sI gPeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=husxF0wg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp15-20020a1709073e0f00b006d717120dc4si8233955ejc.450.2022.03.06.09.47.06; Sun, 06 Mar 2022 09:47:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=husxF0wg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233925AbiCFRak (ORCPT + 99 others); Sun, 6 Mar 2022 12:30:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233937AbiCFRaj (ORCPT ); Sun, 6 Mar 2022 12:30:39 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8508A4B1E4; Sun, 6 Mar 2022 09:29:46 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id q20so5546247wmq.1; Sun, 06 Mar 2022 09:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=1zzNgf433hyjGkgzGz6Qpkm1fu9BPDmLsvmtuyA914E=; b=husxF0wgW3KVw8HHmc98ry3UwO3cSwMAsqHJyO4MgtxAxeufK+7y2BeH03igmgNIYy YGKXxafZ+HCiiOYn5iWnL45ZiK5P5qmQhfvzQUdMv8XnbxVw4NmicfE/ckFegBlVPzHP +HecN91dxbexme3px6k8x6X4D9Fy1+KNBeJ9HxUW8BG9ycrXWdHwVI8FpToThfKf5bA4 iyTqnw0M9zo/Ug+iJK3B7ekNl03in/sdcd9d9kSrS/WFKXugBW8LAE3p7KEcFCG0dIDl pjbADMkd1pBc2co/tVujHq/UxhozjyE28LAoa3VPoHFwkNDCeV3icBhx/Zwxs3NIT3XN Grfw== 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=1zzNgf433hyjGkgzGz6Qpkm1fu9BPDmLsvmtuyA914E=; b=vgANla/2WVET3B1MrwZ3PqGs+9k8ADJWUIrpykaL2UfvweuZxE3qAGoMqlXQspyCDC sv/MZCKikYYHrhLc/hQZjq3dZ1blJ64BIEtdDu2+NV1KG+eLmDiSL14Z4O3XRknOSqby N71Fu2rsoBMPd9hzPr4kv+m2cXduz1/b8o/7Cu1XUat51biE3bAEZvWXNe7/4aV9EqL4 ZOyoN9z6Krbw26xCZI5+pAqeevSorxnVDpkKhffyjI6ox8/lJC30YynrKGeO27nWMwqH rZ/jWuu5J25Z/u3S80j+QLnEdwzbPDRJazeoCOkzddBWnEUE20lJbPpaPIc+Fj3qLvyU FLsg== X-Gm-Message-State: AOAM533tJwgfUEt6552uMqMWg6AoucUJP1Tfp9ePauJnI4ghYz9Dn3q1 lPFplYM8u3OiciMlGygeZBU= X-Received: by 2002:a05:600c:4e0a:b0:37b:c548:622a with SMTP id b10-20020a05600c4e0a00b0037bc548622amr15944416wmq.55.1646587785100; Sun, 06 Mar 2022 09:29:45 -0800 (PST) Received: from krava ([193.85.244.190]) by smtp.gmail.com with ESMTPSA id v5-20020adfe4c5000000b001edc1e5053esm9332016wrm.82.2022.03.06.09.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Mar 2022 09:29:44 -0800 (PST) Date: Sun, 6 Mar 2022 18:29:42 +0100 From: Jiri Olsa To: Andrii Nakryiko Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt Subject: Re: [PATCH 10/10] selftest/bpf: Add kprobe_multi test for bpf_cookie values Message-ID: References: <20220222170600.611515-1-jolsa@kernel.org> <20220222170600.611515-11-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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Fri, Mar 04, 2022 at 03:11:26PM -0800, Andrii Nakryiko wrote: > On Tue, Feb 22, 2022 at 9:08 AM Jiri Olsa wrote: > > > > Adding bpf_cookie test for programs attached by kprobe_multi links. > > > > Signed-off-by: Jiri Olsa > > --- > > .../selftests/bpf/prog_tests/bpf_cookie.c | 72 +++++++++++++++++++ > > .../bpf/progs/kprobe_multi_bpf_cookie.c | 62 ++++++++++++++++ > > 2 files changed, 134 insertions(+) > > create mode 100644 tools/testing/selftests/bpf/progs/kprobe_multi_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..edfb9f8736c6 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 "kprobe_multi_bpf_cookie.skel.h" > > > > /* uprobe attach point */ > > static void trigger_func(void) > > @@ -63,6 +64,75 @@ static void kprobe_subtest(struct test_bpf_cookie *skel) > > bpf_link__destroy(retlink2); > > } > > > > +static void kprobe_multi_subtest(void) > > +{ > > + DECLARE_LIBBPF_OPTS(bpf_link_create_opts, opts); > > + int err, prog_fd, link1_fd = -1, link2_fd = -1; > > + LIBBPF_OPTS(bpf_test_run_opts, topts); > > consistency ftw, LIBBPF_OPTS ok > > > > + struct kprobe_multi_bpf_cookie *skel = NULL; > > + __u64 addrs[8], cookies[8]; > > + > > [..] > > > diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_bpf_cookie.c b/tools/testing/selftests/bpf/progs/kprobe_multi_bpf_cookie.c > > new file mode 100644 > > index 000000000000..d6f8454ba093 > > --- /dev/null > > +++ b/tools/testing/selftests/bpf/progs/kprobe_multi_bpf_cookie.c > > @@ -0,0 +1,62 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +#include > > +#include > > +#include > > + > > +char _license[] SEC("license") = "GPL"; > > + > > +extern const void bpf_fentry_test1 __ksym; > > +extern const void bpf_fentry_test2 __ksym; > > +extern const void bpf_fentry_test3 __ksym; > > +extern const void bpf_fentry_test4 __ksym; > > +extern const void bpf_fentry_test5 __ksym; > > +extern const void bpf_fentry_test6 __ksym; > > +extern const void bpf_fentry_test7 __ksym; > > +extern const void bpf_fentry_test8 __ksym; > > + > > +/* No tests, just to trigger bpf_fentry_test* through tracing test_run */ > > +SEC("fentry/bpf_modify_return_test") > > +int BPF_PROG(test1) > > +{ > > + return 0; > > +} > > + > > +__u64 test2_result = 0; > > + > > +SEC("kprobe.multi/bpf_fentry_tes??") > > +int test2(struct pt_regs *ctx) > > +{ > > + __u64 cookie = bpf_get_attach_cookie(ctx); > > + __u64 addr = bpf_get_func_ip(ctx); > > + > > + test2_result += (const void *) addr == &bpf_fentry_test1 && cookie == 1; > > + test2_result += (const void *) addr == &bpf_fentry_test2 && cookie == 2; > > + test2_result += (const void *) addr == &bpf_fentry_test3 && cookie == 3; > > + test2_result += (const void *) addr == &bpf_fentry_test4 && cookie == 4; > > + test2_result += (const void *) addr == &bpf_fentry_test5 && cookie == 5; > > + test2_result += (const void *) addr == &bpf_fentry_test6 && cookie == 6; > > + test2_result += (const void *) addr == &bpf_fentry_test7 && cookie == 7; > > + test2_result += (const void *) addr == &bpf_fentry_test8 && cookie == 8; > > this is not parallel mode friendly > > let's filter by pid, but also it's best to do count locally and just > assign it (so that multiple calls of the program still produce the > same value, instead of constantly increasing global variable with each > run) ah I did not think of the paralel run, right, will change thanks, jirka