Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2291482iof; Wed, 8 Jun 2022 01:36:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwul5sSSgvm7sbg7j1MhU1FUo3i7I0I2jZZBX0LtI/YS6pbqAu4NAxi/vFSQhco5fW4WDKB X-Received: by 2002:aa7:9a49:0:b0:51b:aa7f:d078 with SMTP id x9-20020aa79a49000000b0051baa7fd078mr37952305pfj.71.1654677384208; Wed, 08 Jun 2022 01:36:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654677384; cv=none; d=google.com; s=arc-20160816; b=aexSeRQIRbWAp768CGA9gtEgXXnjcOHrzQAXnmVblgIThSXUo67aD7BLF+7UuRM6pn yz2ETZa0Y9KoInJjcWK451wZ67FSmRlDJFLqHW+2lw3vbPnCefldMOTJHiXQLYaQeDuD zpyLjVYIw+o78/GzRGT1F2jFUQs3NwJjdqiqsSjbdB7H0KHC5ZzcIjZJEHqfvBifNx0M W7OuNaYl1YEwg44FB3kLVSRMru4oZywy19wlEyzLtKHD8SVqR1M7La5adEmdg4ET+lvZ zS2IeSgaX/lkM98ftfTgJKahlfCZ/IqnDM50nTDRSS4UgJUa0k5IKDuYVzz6L5bCRrAN Li8A== 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=YbEob6Rmm6pW1VPB8x8xhq32k/5rIyV9Dc/pG7KqAkg=; b=PKtbHRspaWO8L56sJE18cYwOX6eAOhkGBFuWmR/bz6HdGxg/2CKAc3rOcrgwZC3IAU uT0ZOtOr5fsLS1vMvqhvUpMNdsvKp4lin955dXjDcjlSU19pj7XIdJax6ROlj9Vh75v1 fe1rt05rXc/+NrO+kso+H8u81sZp3vxi9g0yrSfTuZfmWMbd6290Ogh+9t+YCwlXdnm2 0M5moPjdHKSDU2J58Ve4w06CvJCj9zHMv4XAVSrO+UZJRa5HcnThlfZDskSl9pRxeamR xIDOkl/n7ipW3pHPMj2zBNnqEZzuQBlMvBcWOb5ssCxYb7ODo/V2DQ9kS+1ehEqYt0LL Z8Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=GI0jVjQZ; 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 iw19-20020a170903045300b0016252715440si26129463plb.494.2022.06.08.01.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:36:24 -0700 (PDT) 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=GI0jVjQZ; 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 09D801FE8EC; Wed, 8 Jun 2022 01:01:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241179AbiFHHMb (ORCPT + 99 others); Wed, 8 Jun 2022 03:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244536AbiFHFzR (ORCPT ); Wed, 8 Jun 2022 01:55:17 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD19943E825; Tue, 7 Jun 2022 21:10:45 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id h19so25461834edj.0; Tue, 07 Jun 2022 21:10:45 -0700 (PDT) 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=YbEob6Rmm6pW1VPB8x8xhq32k/5rIyV9Dc/pG7KqAkg=; b=GI0jVjQZLILiQ/Tf7p28dLzb0ZGX0dmbmVrUCTCv2aaMWEzhi5C+mf6fzbOyfOfC4v DtND2szIO5P1xElGhFy5aC+NfmF2hW6XcM2viPgx3Wpws1oIVTxXWY8LoXy3zZ3JZWnG TmvY12l/YuxLstyYM4ufse+EeHFcEDuXpwfGdW4K/elO1eJa3YXKUstV5qhAuKyW20Df T4Z9YcBeyddwIASLSa3q9hYYTC05rTLihICtL+SZcJRb5wlPg376yg1VY32+WUEPbMMJ R6SKtiRIJWw6JVVUQi/7oMWf8c47eUtd6UUA+NYVKepEi8lsUrVjoqFVoHETzP3UE7o/ /New== 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=YbEob6Rmm6pW1VPB8x8xhq32k/5rIyV9Dc/pG7KqAkg=; b=izFT4+4tqAfWO4CI9stu5zCChnYFdy42sWq9V7RCZPdmm1kZ20zk34cJS3/rSog+jM Ou6bgJB+Mi7GG0m68rgkrEkQZnvZjIZ4okK6r7s8xg6wQBrs/ttVBuH1wUMEdEDHXGCY RvI/RcwUbT/QivJoQbLdo4RvBZ0/CIHXSZi0a5SYC1ad64FmSNgTUuut+CrJ5OlO9+xS H+wv7YU0pCadS/+d3QVYcPF4zVvhz/ZXdrr1qsMksowTVyb2PO3Wf0/MSvGDaVuTLhB3 jhenTu/ysnQnyD9ssdtIVulT5g8FDaUWv/rQZRbq22emZvAX90G6RJbS9r5yyI3fCJwt sIuw== X-Gm-Message-State: AOAM530OBy8UjR5cdi/bORFwiBZzHzCNvMbUXB6Nqtvv/56Jrxc7RMuQ rhxPA5QC1FXmBjqWpRntgST1RnH5+zSGawH6zj0= X-Received: by 2002:a05:6402:5168:b0:42d:d3f6:2a1b with SMTP id d8-20020a056402516800b0042dd3f62a1bmr36245673ede.94.1654661444352; Tue, 07 Jun 2022 21:10:44 -0700 (PDT) MIME-Version: 1.0 References: <20220606184731.437300-1-jolsa@kernel.org> <20220606184731.437300-4-jolsa@kernel.org> In-Reply-To: From: Alexei Starovoitov Date: Tue, 7 Jun 2022 21:10:32 -0700 Message-ID: Subject: Re: [PATCHv2 bpf 3/3] bpf: Force cookies array to follow symbols sorting To: Jiri Olsa Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Network Development , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt , Masami Hiramatsu 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, Jun 7, 2022 at 12:56 PM Jiri Olsa wrote: > > On Tue, Jun 07, 2022 at 11:40:47AM -0700, Alexei Starovoitov wrote: > > On Mon, Jun 6, 2022 at 11:48 AM Jiri Olsa wrote: > > > > > > When user specifies symbols and cookies for kprobe_multi link > > > interface it's very likely the cookies will be misplaced and > > > returned to wrong functions (via get_attach_cookie helper). > > > > > > The reason is that to resolve the provided functions we sort > > > them before passing them to ftrace_lookup_symbols, but we do > > > not do the same sort on the cookie values. > > > > > > Fixing this by using sort_r function with custom swap callback > > > that swaps cookie values as well. > > > > > > Fixes: 0236fec57a15 ("bpf: Resolve symbols with ftrace_lookup_symbols for kprobe multi link") > > > Signed-off-by: Jiri Olsa > > > > It looks good, but something in this patch is causing a regression: > > ./test_progs -t kprobe_multi > > test_kprobe_multi_test:PASS:load_kallsyms 0 nsec > > #80/1 kprobe_multi_test/skel_api:OK > > #80/2 kprobe_multi_test/link_api_addrs:OK > > #80/3 kprobe_multi_test/link_api_syms:OK > > #80/4 kprobe_multi_test/attach_api_pattern:OK > > #80/5 kprobe_multi_test/attach_api_addrs:OK > > #80/6 kprobe_multi_test/attach_api_syms:OK > > #80/7 kprobe_multi_test/attach_api_fails:OK > > test_bench_attach:PASS:get_syms 0 nsec > > test_bench_attach:PASS:kprobe_multi_empty__open_and_load 0 nsec > > libbpf: prog 'test_kprobe_empty': failed to attach: No such process > > test_bench_attach:FAIL:bpf_program__attach_kprobe_multi_opts > > unexpected error: -3 > > #80/8 kprobe_multi_test/bench_attach:FAIL > > #80 kprobe_multi_test:FAIL > > looks like kallsyms search failed to find some symbol, > but I can't reproduce with: > > ./vmtest.sh -- ./test_progs -t kprobe_multi > > can you share .config you used? I don't think it's config related. Patch 2 is doing: - if (!bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbols_cmp)) + sym = bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbols_cmp); + if (!sym) + return 0; + + idx = sym - args->syms; + if (args->addrs[idx]) return 0; addr = ftrace_location(addr); if (!addr) return 0; - args->addrs[args->found++] = addr; + args->addrs[idx] = addr; + args->found++; return args->found == args->cnt ? 1 : 0; There are plenty of functions with the same name in available_filter_functions. So if (args->addrs[idx]) return 0; triggers for a lot of them. At the end args->found != args->cnt. Here is trivial debug patch: diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 601ccf1b2f09..c567cf56cb57 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -8037,8 +8037,10 @@ static int kallsyms_callback(void *data, const char *name, return 0; idx = sym - args->syms; - if (args->addrs[idx]) + if (args->addrs[idx]) { + printk("idx %x name %s\n", idx, name); return 0; + } addr = ftrace_location(addr); if (!addr) @@ -8078,6 +8080,7 @@ int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *a err = kallsyms_on_each_symbol(kallsyms_callback, &args); if (err < 0) return err; + printk("found %zd cnt %zd\n", args.found, args.cnt); return args.found == args.cnt ? 0 : -ESRCH; } [ 13.096160] idx a500 name unregister_vclock [ 13.096930] idx 82fb name pt_regs_offset [ 13.106969] idx 92be name set_root [ 13.107290] idx 4414 name event_function [ 13.112570] idx 7d1d name phy_init [ 13.114459] idx 7d13 name phy_exit [ 13.114777] idx ab91 name watchdog [ 13.115730] found 46921 cnt 47036 I don't understand how it works for you at all. It passes in BPF CI only because we don't run kprobe_multi_test/bench_attach there (yet).