Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2594166rwd; Fri, 9 Jun 2023 13:48:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4obhe30GGu9lv8p0FoGymGp2X51ApMjXr00LxH09N/m6zJJ/gtGgZmxqzwZjhV3wd8zruK X-Received: by 2002:a05:6a20:7485:b0:116:df6e:c857 with SMTP id p5-20020a056a20748500b00116df6ec857mr2721536pzd.16.1686343738182; Fri, 09 Jun 2023 13:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686343738; cv=none; d=google.com; s=arc-20160816; b=0fYwGMzXKNwEu/MEBMhnQIPrLknVrCVeV8q0EimHXD1twyGowZ2aLZv8UnLMBMTjp9 B6rU026ehsGKDe5LH7jR9yyDcVfQ/fZ5Lt2NFWtA+uICRlBQMaXh1vI5GLqMpa06TUEa 73C1fIqsWF16ukN6ZxACjSw5BPvS3hUOs9O3Z7pK67hkU4nxyPC5hA2tpBvijZvd8ZQY uUt96+YfiIO53/lRwBbajrO+teATDHO0W0toCwOy7TxUJkEOGrLBIBGN0DpGJEt+DNMv QCMdLs8nmqI+hGuh4lRPeyuIhhksVaJZraBqnvd0u7sENbpCJn/z5S15lIL7KofBgWN+ 6fNg== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=4QbmTscgL0W4LNSr/7q9vHr3/nK0DxnmRxkiPOyTnLw=; b=uzE8egqWyLJ01tP9J0QF26JSysExNOx8UBrom+wzuihecN4E8Q41IWMhxnUZliMPK6 nMqfBMmtkTxdTWLNjaue5IwE6Ijb+O6wQOJKUi62rfRv/aoZ3RDwgoZK6y+wUhr8uApD e3vRgIjAI4XG+HicMJjJtKclhO0MPQsH9pKhep44ymTHcetMQMZo6Zk2x57taEG7KB4w xIQqMRBboJBBFuhSUze/f4Wdam3NM06476CoHh+8gIycAVVhHFl4qpPf/TiD9CD20LkX lGdBSTgYIcSNK7jZ4pYW5hijBNLMfiKOr6gG17UjLBLDEzn+y2nUH1C8dC+sKrZgiFPw ICiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=UPhpET1v; 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 k11-20020a637b4b000000b00543f6a35a43si3236952pgn.306.2023.06.09.13.48.45; Fri, 09 Jun 2023 13:48:58 -0700 (PDT) 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=20221208 header.b=UPhpET1v; 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 S232147AbjFIUiH (ORCPT + 99 others); Fri, 9 Jun 2023 16:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbjFIUiF (ORCPT ); Fri, 9 Jun 2023 16:38:05 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7917330C8; Fri, 9 Jun 2023 13:38:03 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-650c89c7e4fso2298172b3a.0; Fri, 09 Jun 2023 13:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686343083; x=1688935083; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=4QbmTscgL0W4LNSr/7q9vHr3/nK0DxnmRxkiPOyTnLw=; b=UPhpET1va9qipboE/8cau9bR3DIRjMvfr1w4qvTl2rexd1cpITZ+sdPHjkYag7SmZH Sx4jSVMmVPAvwvR7iG0MMjrC3jfUGGFs8EpwgU5Qljm0idreDw6J6xOLB5TxhaNHXV76 G5SSCxF3zK/jG2hyCoqawCMCQKAnS5wqX6A+nXHTIGHt3KtUEI5ANpYYsS5fQSNhWoKN JQwjpNsQQCvHpzG4oPJlRF5OzVo7zRKUzM/2MUJnqHac/n+X+qyPlCAByHgsuGfUXxf8 7b9XPCwIVZAZRvExJzEdLx7qgSkfIWdUZFBr7qW4P89bOMxKljMNXVgxk3r+7FGQPswz lyGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686343083; x=1688935083; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4QbmTscgL0W4LNSr/7q9vHr3/nK0DxnmRxkiPOyTnLw=; b=Yz0yRFampe4waQRHmU1dUMk60EXi+0vS8MbXaEr2+qKSNzBFrO2KoQcHPkmrVvH121 P6wtiv7HsFQI3pVHbQtcseAez5MeOK74IMvq8HT6IYtLTtgQPA5pYSB5FSwQxAPyBZ1I lzqECdTBl9ZIHYUpIFLwgYqINvbd0PPvksjAGpG4KsofP0tp9a2Jxn7R6WIelQaIJ2iA NJFP1xJsR9Xjl0xGmc5TJSvbAxybBysAbb7xjz4lay5g4uDQx7iPUQ2i90jxBNyZIk41 g2u49llqeb5ePNBny3UyzsvwoFV1/vFOVGvwSVMFqupoKw/5STMp2aobSp3RLaP8Ywr8 h0RQ== X-Gm-Message-State: AC+VfDyrYOslfp2cgtBpv0RRmFhl2/KS7B5K8Qj21uC9bnWCcs3FL5BG ppOlBW80vzQuZ7XuxN2ng4Y3D47nkmg= X-Received: by 2002:a05:6a00:24c9:b0:64d:4412:9923 with SMTP id d9-20020a056a0024c900b0064d44129923mr2899985pfv.3.1686343082568; Fri, 09 Jun 2023 13:38:02 -0700 (PDT) Received: from krava (c-67-160-222-115.hsd1.ca.comcast.net. [67.160.222.115]) by smtp.gmail.com with ESMTPSA id p18-20020aa78612000000b006414b2c9efasm3034301pfn.123.2023.06.09.13.38.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 13:38:02 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Fri, 9 Jun 2023 13:37:59 -0700 To: Andrii Nakryiko Cc: Jiri Olsa , Mark Rutland , Steven Rostedt , Masami Hiramatsu , Andrii Nakryiko , lkml , linux-trace-kernel@vger.kernel.org, bpf@vger.kernel.org, Jackie Liu Subject: Re: [PATCH RFC] ftrace: Show all functions with addresses in available_filter_functions_addrs Message-ID: References: <20230608212613.424070-1-jolsa@kernel.org> <20230608192748.435a1dbf@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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, Jun 09, 2023 at 11:29:59AM -0700, Andrii Nakryiko wrote: > On Fri, Jun 9, 2023 at 9:44 AM Jiri Olsa wrote: > > > > On Fri, Jun 09, 2023 at 09:24:10AM +0100, Mark Rutland wrote: > > > On Thu, Jun 08, 2023 at 04:55:40PM -0700, Andrii Nakryiko wrote: > > > > On Thu, Jun 8, 2023 at 4:27 PM Steven Rostedt wrote: > > > > > On Thu, 8 Jun 2023 15:43:03 -0700 Andrii Nakryiko wrote: > > > > > > On Thu, Jun 8, 2023 at 2:26 PM Jiri Olsa wrote: > > > > > > > There are BPF tools that allow user to specify regex/glob of kernel > > > > functions to attach to. This regex/glob is checked against > > > > available_filter_functions to check which functions are traceable. All > > > > good. But then also it's important to have corresponding memory > > > > addresses for selected functions (for many reasons, e.g., to have > > > > non-ambiguous and fast attachment by address instead of by name, or > > > > for some post-processing based on captured IP addresses, etc). And > > > > that means that now we need to also parse /proc/kallsyms and > > > > cross-join it with data fetched from available_filter_functions. > > > > > > > > All this is unnecessary if avalable_filter_functions would just > > > > provide function address in the first place. It's a huge > > > > simplification. And saves memory and CPU. > > > > > > Do you need the address of the function entry-point or the address of the > > > patch-site within the function? Those can differ, and the rec->ip address won't > > > necessarily equal the address in /proc/kallsyms, so the pointer in > > > /proc/kallsyms won't (always) match the address we could print for the ftrace site. > > > > > > On arm64, today we can have offsets of +0, +4, and +8, and within a single > > > kernel image different functions can have different offsets. I suspect in > > > future that we may have more potential offsets (e.g. due to changes for HW/SW > > > CFI). > > > > so we need that for kprobe_multi bpf link, which is based on fprobe, > > and that uses ftrace_set_filter_ips to setup the ftrace_ops filter > > > > and ftrace_set_filter_ips works fine with ip address being the address > > of the patched instruction (it's matched in ftrace_location) > > > > but right, I did not realize this.. it might cause confusion if people > > don't know it's patch-side addresses.. not sure if there's easy way to > > get real function address out of rec->ip, but it will also get more > > complicated on x86 when IBT is enabled, will check > > ok, sorry, I'm confused. Two questions: > > 1. when attaching kprobe_multi, does bpf() syscall expect function > address or (func+offset_of_mcount) address? I hope it's the former, > just function's address? it can be both, the fprobe/ftrace filter setup will take care of looking up and translating the provided address to the patch-side address > > 2. If rec->ip is not function's address, can we somehow adjust the > value to be a function address before printing it? that's tricky because on x86 with IBT we would need to read the first instruction and check if it's endbr to get the real address, like we do in get_entry_ip: #ifdef CONFIG_X86_KERNEL_IBT static unsigned long get_entry_ip(unsigned long fentry_ip) { u32 instr; /* Being extra safe in here in case entry ip is on the page-edge. */ if (get_kernel_nofault(instr, (u32 *) fentry_ip - 1)) return fentry_ip; if (is_endbr(instr)) fentry_ip -= ENDBR_INSN_SIZE; return fentry_ip; } #else #define get_entry_ip(fentry_ip) fentry_ip #endif I'm not familiar with arm implementation, so I'm not sure if there's a way to do this but in any case Steven wants to keep the patch-side address: https://lore.kernel.org/bpf/CAEf4BzbgsLOoLKyscq6S95QeehVoAzOnQ=xmsFz8dfEUAnhObw@mail.gmail.com/T/#m19a97bbc8f8236ad869c9f8ad0cc7dbce0722d92 jirka > > In short, I think it's confusing to have addresses with +0 or +4 or +8 > offsets. It would be great if we can just keep it +0 at the interface > level (when attach and in available_filter_functions_addrs). > > > > > or we could just use patch-side addresses and reflect that in the file's > > name like 'available_filter_functions_patch_addrs' .. it's already long > > name ;-) > > > > jirka