Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp746106lqh; Fri, 31 May 2024 15:49:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNVY2xX8M3SKgyjTKjrbdRLAYDT9St1NX8FUAwWREZKn2O5Tj/1X7evdazl6LVmYAutVHNmOUUWRzgGsCQ5cHjgHMcEq47yFupnBBMCw== X-Google-Smtp-Source: AGHT+IHyAayUbe5pcgGC2Wx27A78lKPHXyWmlBKj/v3/qFgj1xNm/Zew8Q6bfVqA8+ZSiQky0syc X-Received: by 2002:a05:6870:c69b:b0:250:7f7e:fa6a with SMTP id 586e51a60fabf-2508ba92253mr4116388fac.23.1717195798002; Fri, 31 May 2024 15:49:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717195797; cv=pass; d=google.com; s=arc-20160816; b=BHoEM9N8XC/e2jcYuEg+yFMa8sVlYoGGw6v9P3l/C4I7MKOwXyVV68lYWomWNOKMTv aoqHlrNHUle2ZRwS1btCIQ2ZX+V7u7Qr0/08fi+D75fcvO8r3baHBfGLDmvu3PUoaRuF QUMHncaXFH4bFfigrPg/h0lU9v2ifSOMyH1hG6nf72enOXKlJZ7EdxebAUZNFDAq0yhD jbi5Ft5IS7kPNsQ/arY09PPef+ajGwvvdaViq31iDMjn0P3k54XsuF0HaVKWG3i9kvp7 RciqCS7c1pENgnDtIQFmtZcdXmPzrNwdVGda9OAGyNX1e77cKSmeJi8fuKRBoiL5X5BN EI+Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=oC2DXuVU/3v3UpS0SNzdnKFhOs79F0YJRKWmJ/p1zcI=; fh=CONbk9IM1KeoX7M3ojYzAuH3rM9roTZPm7jJ9UBDXA8=; b=pH8tpaYJc6fgXbh5P2tlsdU+FgJNpHVYa6tkcZNTbXsjYMyxtimSBjk+gkKS+zpcZ7 ExlAPkom8TNLleJHShhw91ZDLXnn6d3S4Riquzq8yZofM8bjuxgoI1NMGReqEdVsvcZj DeRBncAg6hIwVW+WmX4mChHhAWo1DIAX1mRSZePiO9PWF7KxpO8vuDSVWWYo9c9uocGm kXgCLXFWROm3FXjMw9vp8UO+m5pEytdITDgkqBr9qOMurXNDDMeWFIxz77psdSgupwUc sfBbAbHb9j75P7ks+TW7l0Tdh7Unjy/+OSYLSDsEeRgNDU6IGsxDWzJAN0lnrbKupB1s 6pQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-197572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197572-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4b43e6b6si32297676d6.609.2024.05.31.15.49.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 15:49:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-197572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-197572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-197572-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9BE1B1C22195 for ; Fri, 31 May 2024 22:49:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 260CF824BD; Fri, 31 May 2024 22:49:48 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C6D9168DA; Fri, 31 May 2024 22:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717195787; cv=none; b=PS0R2U7N7GDkQpM98T99QOSXTWr9iGb0CjJd/pC1jE04oC69RvsOVOZxjJjdjSZcuFfxrH7No0MLazrgCzgFZHlXWSueER0yuVawedoifHnlHkOeej6th5onrmtUrnanO0OdJCh7EqcX6RPoGrltJQ/1O4vvRHbZQdnsmT3oKuw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717195787; c=relaxed/simple; bh=+UQy7NFH7cIoreL6KRBvahvgtAOgRsqyhcKdhRpeoNk=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lpXlCAHIGQrs33NFnr89/bW8qY0TGjjshLgzNt6bvqmRkU080LnOObdWP2iZxziQMSkrFmY1MHV8MSiQ/ZonLnPRFx+riLG1VhawlDHTUGmKPEV0ZZVtlMLCyiwlfPXBVP3ASkWrihKotH8ulVywsjXAktGiMhYB1ciWPf1HuOs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DB3AC116B1; Fri, 31 May 2024 22:49:42 +0000 (UTC) Date: Fri, 31 May 2024 18:49:10 -0400 From: Steven Rostedt To: "Masami Hiramatsu (Google)" Cc: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Mark Rutland , Mathieu Desnoyers , Andrew Morton , Alexei Starovoitov , Florent Revest , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Peter Zijlstra , Thomas Gleixner , Guo Ren Subject: Re: [PATCH 10/20] function_graph: Have the instances use their own ftrace_ops for filtering Message-ID: <20240531184910.799635e8@rorschach.local.home> In-Reply-To: <20240531235023.a0b2b207362eba2f8b5c16f7@kernel.org> References: <20240525023652.903909489@goodmis.org> <20240525023742.786834257@goodmis.org> <20240530223057.21c2a779@rorschach.local.home> <20240531121241.c586189caad8d31d597f614d@kernel.org> <20240531020346.6c13e2d4@rorschach.local.home> <20240531235023.a0b2b207362eba2f8b5c16f7@kernel.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 31 May 2024 23:50:23 +0900 Masami Hiramatsu (Google) wrote: > So is it similar to the fprobe/kprobe, use shared signle ftrace_ops, > but keep each fgraph has own hash table? Sort of. I created helper functions in ftrace that lets you have a "manager ftrace_ops" that will be used to assign to ftrace (with the function that will demultiplex), and then you can have "subops" that can be assigned that is per user. Here's a glimpse of the code: /** * ftrace_startup_subops - enable tracing for subops of an ops * @ops: Manager ops (used to pick all the functions of its subops) * @subops: A new ops to add to @ops * @command: Extra commands to use to enable tracing * * The @ops is a manager @ops that has the filter that includes all the functions * that its list of subops are tracing. Adding a new @subops will add the * functions of @subops to @ops. */ int ftrace_startup_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int command) { struct ftrace_hash *filter_hash; struct ftrace_hash *notrace_hash; struct ftrace_hash *save_filter_hash; struct ftrace_hash *save_notrace_hash; int size_bits; int ret; if (unlikely(ftrace_disabled)) return -ENODEV; ftrace_ops_init(ops); ftrace_ops_init(subops); /* Make everything canonical (Just in case!) */ if (!ops->func_hash->filter_hash) ops->func_hash->filter_hash = EMPTY_HASH; if (!ops->func_hash->notrace_hash) ops->func_hash->notrace_hash = EMPTY_HASH; if (!subops->func_hash->filter_hash) subops->func_hash->filter_hash = EMPTY_HASH; if (!subops->func_hash->notrace_hash) subops->func_hash->notrace_hash = EMPTY_HASH; /* For the first subops to ops just enable it normally */ if (list_empty(&ops->subop_list)) { /* Just use the subops hashes */ filter_hash = copy_hash(subops->func_hash->filter_hash); notrace_hash = copy_hash(subops->func_hash->notrace_hash); if (!filter_hash || !notrace_hash) { free_ftrace_hash(filter_hash); free_ftrace_hash(notrace_hash); return -ENOMEM; } save_filter_hash = ops->func_hash->filter_hash; save_notrace_hash = ops->func_hash->notrace_hash; ops->func_hash->filter_hash = filter_hash; ops->func_hash->notrace_hash = notrace_hash; list_add(&subops->list, &ops->subop_list); ret = ftrace_startup(ops, command); if (ret < 0) { list_del(&subops->list); ops->func_hash->filter_hash = save_filter_hash; ops->func_hash->notrace_hash = save_notrace_hash; free_ftrace_hash(filter_hash); free_ftrace_hash(notrace_hash); } else { free_ftrace_hash(save_filter_hash); free_ftrace_hash(save_notrace_hash); subops->flags |= FTRACE_OPS_FL_ENABLED; } return ret; } /* * Here there's already something attached. Here are the rules: * o If either filter_hash is empty then the final stays empty * o Otherwise, the final is a superset of both hashes * o If either notrace_hash is empty then the final stays empty * o Otherwise, the final is an intersection between the hashes */ if (ops->func_hash->filter_hash == EMPTY_HASH || subops->func_hash->filter_hash == EMPTY_HASH) { filter_hash = EMPTY_HASH; } else { size_bits = max(ops->func_hash->filter_hash->size_bits, subops->func_hash->filter_hash->size_bits); filter_hash = alloc_and_copy_ftrace_hash(size_bits, ops->func_hash->filter_hash); if (!filter_hash) return -ENOMEM; ret = append_hash(&filter_hash, subops->func_hash->filter_hash); if (ret < 0) { free_ftrace_hash(filter_hash); return ret; } } if (ops->func_hash->notrace_hash == EMPTY_HASH || subops->func_hash->notrace_hash == EMPTY_HASH) { notrace_hash = EMPTY_HASH; } else { size_bits = max(ops->func_hash->filter_hash->size_bits, subops->func_hash->filter_hash->size_bits); notrace_hash = alloc_ftrace_hash(size_bits); if (!notrace_hash) { free_ftrace_hash(filter_hash); return -ENOMEM; } ret = intersect_hash(¬race_hash, ops->func_hash->filter_hash, subops->func_hash->filter_hash); if (ret < 0) { free_ftrace_hash(filter_hash); free_ftrace_hash(notrace_hash); return ret; } } list_add(&subops->list, &ops->subop_list); ret = ftrace_update_ops(ops, filter_hash, notrace_hash); free_ftrace_hash(filter_hash); free_ftrace_hash(notrace_hash); if (ret < 0) list_del(&subops->list); return ret; } /** * ftrace_shutdown_subops - Remove a subops from a manager ops * @ops: A manager ops to remove @subops from * @subops: The subops to remove from @ops * @command: Any extra command flags to add to modifying the text * * Removes the functions being traced by the @subops from @ops. Note, it * will not affect functions that are being traced by other subops that * still exist in @ops. * * If the last subops is removed from @ops, then @ops is shutdown normally. */ int ftrace_shutdown_subops(struct ftrace_ops *ops, struct ftrace_ops *subops, int command) { struct ftrace_hash *filter_hash; struct ftrace_hash *notrace_hash; int ret; if (unlikely(ftrace_disabled)) return -ENODEV; list_del(&subops->list); if (list_empty(&ops->subop_list)) { /* Last one, just disable the current ops */ ret = ftrace_shutdown(ops, command); if (ret < 0) { list_add(&subops->list, &ops->subop_list); return ret; } subops->flags &= ~FTRACE_OPS_FL_ENABLED; free_ftrace_hash(ops->func_hash->filter_hash); free_ftrace_hash(ops->func_hash->notrace_hash); ops->func_hash->filter_hash = EMPTY_HASH; ops->func_hash->notrace_hash = EMPTY_HASH; return 0; } /* Rebuild the hashes without subops */ filter_hash = append_hashes(ops); notrace_hash = intersect_hashes(ops); if (!filter_hash || !notrace_hash) { free_ftrace_hash(filter_hash); free_ftrace_hash(notrace_hash); list_add(&subops->list, &ops->subop_list); return -ENOMEM; } ret = ftrace_update_ops(ops, filter_hash, notrace_hash); if (ret < 0) list_add(&subops->list, &ops->subop_list); free_ftrace_hash(filter_hash); free_ftrace_hash(notrace_hash); return ret; } > > > This removes the need to touch the architecture code. It can also be > > used by fprobes to handle the attachments to functions for several > > different sets of callbacks. > > > > I'll send out patches soon. > > OK, I'll wait for that. I'm just cleaning it up. I'll post it tomorrow (your today). -- Steve