Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5796462pxb; Thu, 20 Jan 2022 04:54:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzTl8sTuO+fzxQ+1RUIy3Ul/Zu76CbXI1VXq3TKyAIXMRyeuiatJL2GZzDKP7/SUrkuafUZ X-Received: by 2002:a17:903:187:b0:14a:6ee7:682c with SMTP id z7-20020a170903018700b0014a6ee7682cmr37887523plg.105.1642683276494; Thu, 20 Jan 2022 04:54:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642683276; cv=none; d=google.com; s=arc-20160816; b=fVHnR+iNNyEo8fYHE/O0nVMkx7JHIPQsD1AkBr7pWSFgnO/f72svTYVVhu8QBgpLDL 2xwspZ7jCVaDVIrJGds9KGcqw016q4b/W8H3x5AyQ2E/J8yKiZ/nP+3tlDhSnq5gBRN+ guFEp92IPIfw5evux/sONOyXYGNi7e7cJ2s/ToJLHCY671kseXHR6dtWhWbhBAqPBzVc C3N6w95lQpT6pXr3c6AGJCqfBjzVofuszMx5axlpn5DF2itnPjuCF2ClMPdt5x2myT3q mSQzkZL4MH5gs1nlRt6VndRD+nNEJdk3ym4nRRGqgA0LilNt0tG01cGwHS4+uYgc1Chj zxhA== 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=L/3xiTwKonxDCzPOwDPfLLah1H5jM3BzmJPk13Up2Bg=; b=VzxEybgZqlX7UoR1Zzq22LkRRiNlrMoulJJWRS3PCndf7ZSsfVopWKDEOwMTittVz4 DKcJj7TOW2MHW/8hRyL8oISvr6ZGkTqgGnD97XzgfcONrYnjEVcwjJ/krYwziS8ULKzI PAUSh8lJFa42Qu7BA0t+DK99xy42FEhVw7HcHFB+jAugAb+e8CrdBk4nExO+Vgq48zSh O6FN9soXZKTb5IZcXlqEvElUvn3QAQ32eVz0NDlDGCyeSMWDBv/9UU7XMj9avtm3B8vF TIUAG6UXoPvVZT/aJq0hAEnRjr+19VoB62R6eCUWamtQH11leaKizUmwuMyTzhfgrPAS 4f5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FH+7rTyg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si3248495pga.785.2022.01.20.04.54.24; Thu, 20 Jan 2022 04:54:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=FH+7rTyg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343510AbiAROjB (ORCPT + 99 others); Tue, 18 Jan 2022 09:39:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:42411 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241901AbiAROif (ORCPT ); Tue, 18 Jan 2022 09:38:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642516714; 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=L/3xiTwKonxDCzPOwDPfLLah1H5jM3BzmJPk13Up2Bg=; b=FH+7rTyg7syZPn2d8qpwLaWAW52Aa6j6Akijc+Q+IeuqlWe9vU5XtuZFFWLhimZpApW+Bq m6dGUv0hPTaSZ4AbcxqcJ6m0SWdZE8xYsf0PGzeegOXzrTfKF9zDYr2hoJd53PKZE1LaoC AskI51e08XWT9wsL3QDqqjV7aBCQ5nQ= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-457-BIXCOp1mMGeKZvzRGc55Rg-1; Tue, 18 Jan 2022 09:38:33 -0500 X-MC-Unique: BIXCOp1mMGeKZvzRGc55Rg-1 Received: by mail-ed1-f69.google.com with SMTP id ee53-20020a056402293500b004022f34edcbso6497224edb.11 for ; Tue, 18 Jan 2022 06:38:33 -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=L/3xiTwKonxDCzPOwDPfLLah1H5jM3BzmJPk13Up2Bg=; b=2f+37hpmClLPvwuaBVEzz96S6rbqCm03pzh4DnrFECosbW/XkBPavoCVJe/euOiToo HwFOe1Ro83LoOW66RCuxDovjOBxgB3aUgbnqQpWiK4Jql5TkAHkJg+uqbqjELkutLuUy kT9GPFfFvEARLtmiDslqnkspV+G426Mjd18vvgnytZCB8vKyILywFf0o2a/0Nl68kBLk HsETF5RKUGBAeVG3tMcZxDVWCL4hNnGAsDDTeZUooRL3qdMZpw95fJSTS2GNj3dalFes vrm1PrHpGm5XLidvi08CGSAJPZ8gwlgAg3IXp/pkT2+xZZbaDi5I1yYmfjV0kNsbJHrr VNMw== X-Gm-Message-State: AOAM5330m/tDSePsUXIdkXM8+BxybiY8PtuJpJ2R2LpBn0v8aj5K8xLg jmSo1z8m979/1HN8jj+YQemtyAeR5a+EMQreICwkZjseLvwjohvkvl6w4KMRj9uEzkWYkoQjhzk ZN6lJDYkZXPaRkMc6nSQdtib9 X-Received: by 2002:a05:6402:22d2:: with SMTP id dm18mr25313842edb.410.1642516712348; Tue, 18 Jan 2022 06:38:32 -0800 (PST) X-Received: by 2002:a05:6402:22d2:: with SMTP id dm18mr25313829edb.410.1642516712165; Tue, 18 Jan 2022 06:38:32 -0800 (PST) Received: from krava (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id q14sm7065206edv.79.2022.01.18.06.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Jan 2022 06:38:31 -0800 (PST) Date: Tue, 18 Jan 2022 15:38:28 +0100 From: Jiri Olsa To: Andrii Nakryiko Cc: Masami Hiramatsu , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt , "Naveen N . Rao" , Anil S Keshavamurthy , "David S . Miller" Subject: Re: [RFC PATCH v2 0/8] fprobe: Introduce fprobe function entry/exit probe Message-ID: References: <164199616622.1247129.783024987490980883.stgit@devnote2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 14, 2022 at 05:08:32PM -0800, Andrii Nakryiko wrote: > On Wed, Jan 12, 2022 at 6:02 AM Masami Hiramatsu wrote: > > > > Hi Jiri and Alexei, > > > > Here is the 2nd version of fprobe. This version uses the > > ftrace_set_filter_ips() for reducing the registering overhead. > > Note that this also drops per-probe point private data, which > > is not used anyway. > > This per-probe private data is necessary for the feature called BPF > cookie, in which each attachment has a unique user-provided u64 value > associated to it, accessible at runtime through > bpf_get_attach_cookie() helper. One way or another we'll need to > support this to make these multi-attach BPF programs really useful for > generic tracing applications. > > Jiri, > > We've discussed with Alexei this week how cookies can be supported for > multi-attach fentry (where it seems even more challenging than in > kprobe case), and agreed on rather simple solution, which roughly goes > like this. When multi-attaching either fentry/fexit program, save > sorted array of IP addresses and then sorted in the same order as IPs > list of u64 cookies. At runtime, bpf_get_attach_cookie() helper should > somehow get access to these two arrays and functions IP (that we > already have with bpf_get_func_ip()), perform binary search and locate > necessary cookie. This offloads the overhead of finding this cookie to > actual call site of bpf_get_attach_cookie() (and it's a log(N), so not > bad at all, especially if BPF program can be optimized to call this > helper just once). > > I think something like that should be doable for Masami's fprobe-based > multi-attach kprobes, right? That would allow to have super-fast > attachment, but still support BPF cookie per each individual IP/kernel > function attachment. I haven't looked at code thoroughly, though, > please let me know if I'm missing something fundamental. ok, that seems doable, we should be able to get the link struct in bpf_get_attach_cookie_trace and reach both ips and cookies jirka > > > > > This introduces the fprobe, the function entry/exit probe with > > multiple probe point support. This also introduces the rethook > > for hooking function return as same as kretprobe does. This > > abstraction will help us to generalize the fgraph tracer, > > because we can just switch it from rethook in fprobe, depending > > on the kernel configuration. > > > > The patch [1/8] and [7/8] are from your series[1]. Other libbpf > > patches will not be affected by this change. > > > > [1] https://lore.kernel.org/all/20220104080943.113249-1-jolsa@kernel.org/T/#u > > > > I also added an out-of-tree (just for testing) patch at the > > end of this series ([8/8]) for adding a wildcard support to > > the sample program. With that patch, it shows how long the > > registration will take; > > > > # time insmod fprobe_example.ko symbol='btrfs_*' > > [ 36.130947] fprobe_init: 1028 symbols found > > [ 36.177901] fprobe_init: Planted fprobe at btrfs_* > > real 0m 0.08s > > user 0m 0.00s > > sys 0m 0.07s > > > > Thank you, > > > > --- > > > > Jiri Olsa (2): > > ftrace: Add ftrace_set_filter_ips function > > bpf: Add kprobe link for attaching raw kprobes > > > > Masami Hiramatsu (6): > > fprobe: Add ftrace based probe APIs > > rethook: Add a generic return hook > > rethook: x86: Add rethook x86 implementation > > fprobe: Add exit_handler support > > fprobe: Add sample program for fprobe > > [DO NOT MERGE] Out-of-tree: Support wildcard symbol option to sample > > > > > > arch/x86/Kconfig | 1 > > arch/x86/kernel/Makefile | 1 > > arch/x86/kernel/rethook.c | 115 ++++++++++++++++++++ > > include/linux/bpf_types.h | 1 > > include/linux/fprobe.h | 57 ++++++++++ > > include/linux/ftrace.h | 3 + > > include/linux/rethook.h | 74 +++++++++++++ > > include/linux/sched.h | 3 + > > include/uapi/linux/bpf.h | 12 ++ > > kernel/bpf/syscall.c | 195 +++++++++++++++++++++++++++++++++- > > kernel/exit.c | 2 > > kernel/fork.c | 3 + > > kernel/kallsyms.c | 1 > > kernel/trace/Kconfig | 22 ++++ > > kernel/trace/Makefile | 2 > > kernel/trace/fprobe.c | 168 +++++++++++++++++++++++++++++ > > kernel/trace/ftrace.c | 54 ++++++++- > > kernel/trace/rethook.c | 226 +++++++++++++++++++++++++++++++++++++++ > > samples/Kconfig | 7 + > > samples/Makefile | 1 > > samples/fprobe/Makefile | 3 + > > samples/fprobe/fprobe_example.c | 154 +++++++++++++++++++++++++++ > > tools/include/uapi/linux/bpf.h | 12 ++ > > 23 files changed, 1103 insertions(+), 14 deletions(-) > > create mode 100644 arch/x86/kernel/rethook.c > > create mode 100644 include/linux/fprobe.h > > create mode 100644 include/linux/rethook.h > > create mode 100644 kernel/trace/fprobe.c > > create mode 100644 kernel/trace/rethook.c > > create mode 100644 samples/fprobe/Makefile > > create mode 100644 samples/fprobe/fprobe_example.c > > > > -- > > Masami Hiramatsu (Linaro) >