Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp368995rwl; Wed, 9 Aug 2023 16:11:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFS3o6ZvQJpDxjT3hlZb9NXFoHo48FPPu+8wvxL/lQolUa8d91fBvB4dmc9w5KZ497aeLD5 X-Received: by 2002:a05:6a20:8f03:b0:137:57fc:4f9d with SMTP id b3-20020a056a208f0300b0013757fc4f9dmr783626pzk.10.1691622714435; Wed, 09 Aug 2023 16:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691622714; cv=none; d=google.com; s=arc-20160816; b=IkdcFXE1xCUCMfw4HTTbZzXkkcBeDhfBEP169+OEH/DvK6YA9V4gQ2nyQmwDdXT9S6 74VTpoRVleNyrsOYza7g+uFMGjK7mz2Tt5rkJcwY8cGj72TuvdLFVVIpImjMZwQK/hQV 5aorupPBTmtIu2MVPCRtk1VLN/WX20soI0EWa+CTOs8OJzw45UY6IyjK0MPyVX64hRtQ XLoW9qFruzRwRKA4WSmZYjiM/wfG4kSaXeoJFTeLeb8t2us+BiRv0UCt0zB+NHq7sHRk zTjFe0wfhlngp6gsWWXWe+yhKsfgQgzDCrjxcU5qH0cANn3HkhYXAY1P/f1rpAsx2Lf7 vp9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=zSJdOi753GQitTamjPpftViTrpoCI0TIbKDZPGc8R00=; fh=g9Bw0epkbGk1DkAgG7vR8XN0xStfTcipNOxWcjLkU0g=; b=jt7eR6Rrlbppgnj6Uc5cyCvvjnsdoB0Z5gJZ+lNGA3hbXQ5Hsb+X4aDIRmErAgmrXi O2052luuwhzw+pRKhy33bjOjFkMEFyJQeEB1s0Vv7+6bOr3w5oUE0oV/Liw3fjin35kc W055QvEHNWj1JZXj3tpqxB70UrrdmK2mVfmfFw5dbAEkIdt4wNGYEyoiTT8HHZWQVD8k DI6dDo8V0Wf13WOwDcmP7N+/cbbQbf8l/JwQe7gdEEijdiHCCzTYsIwIbtc7JFbwbT7w IrD3g3jiLrqGp8NjoCwIG2l2RXbeoTyfOpTs9LTx3CWHB2we2ZAfwDqVFkGgn6E5z3F6 zrcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aEUC8hu2; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a14-20020a056a001d0e00b00656f1d69ec6si213138pfx.292.2023.08.09.16.11.41; Wed, 09 Aug 2023 16:11:54 -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=@kernel.org header.s=k20201202 header.b=aEUC8hu2; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231616AbjHIWOG (ORCPT + 99 others); Wed, 9 Aug 2023 18:14:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229765AbjHIWOG (ORCPT ); Wed, 9 Aug 2023 18:14:06 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BA9F2699; Wed, 9 Aug 2023 15:13:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7E13C64B46; Wed, 9 Aug 2023 22:13:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E473C433C7; Wed, 9 Aug 2023 22:13:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691619216; bh=0SR9DPqseRHiCXQ+j6+0+QSN4Sn6OOxeM42Im3uazes=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aEUC8hu248uC08A4L5iDh0a+W+mlid8cOQvoZghQ0ePtWWP3/01VWwKlMokaVoStR +yoxh3hV/rweR2hv0YPrigzI8RzRzYptpjK3gStXmzsm7ruL2sM0U5XfHLKjGZwE/p pPnKJU08RLf12NVdtwlhoJtHISSFK48EM8lzMEeky31FVgscBf/BbjBOyTX3DDJa/1 9yluawRZ/bHdkUJj6boWBctDa3g1Vsy5Gsc4oWziBVg1b2Sl73ejFosS3ymDeil0+B zNBNk3AE/+0fKDSQpKeEy3+xPOyc5EoeY5lkfeuOrf0gbEEiNgUrfkC99fJV+kpsxX jY6X4ZUgLojRA== Date: Thu, 10 Aug 2023 07:13:30 +0900 From: Masami Hiramatsu (Google) To: Florent Revest Cc: Alexei Starovoitov , Steven Rostedt , linux-trace-kernel@vger.kernel.org, LKML , Martin KaFai Lau , bpf , Sven Schnelle , Alexei Starovoitov , Jiri Olsa , Arnaldo Carvalho de Melo , Daniel Borkmann , Alan Maguire , Mark Rutland , Peter Zijlstra , Thomas Gleixner Subject: Re: [RFC PATCH v2 1/6] fprobe: Use fprobe_regs in fprobe entry handler Message-Id: <20230810071330.d41a728f996f76e3243f469e@kernel.org> In-Reply-To: References: <169139090386.324433.6412259486776991296.stgit@devnote2> <169139091575.324433.13168120610633669432.stgit@devnote2> <20230809231011.b125bd68887a5659db59905e@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS 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 Wed, 9 Aug 2023 18:17:47 +0200 Florent Revest wrote: > On Wed, Aug 9, 2023 at 6:09 PM Florent Revest wrote: > > > > On Wed, Aug 9, 2023 at 4:10 PM Masami Hiramatsu wrote: > > > > > > Hi Florent, > > > > > > On Wed, 9 Aug 2023 12:28:38 +0200 > > > Florent Revest wrote: > > > > > > > On Mon, Aug 7, 2023 at 8:48 AM Masami Hiramatsu (Google) > > > > wrote: > > > > > > > > > > From: Masami Hiramatsu (Google) > > > > > > > > > > This allows fprobes to be available with CONFIG_DYNAMIC_FTRACE_WITH_ARGS > > > > > instead of CONFIG_DYNAMIC_FTRACE_WITH_REGS, then we can enable fprobe > > > > > on arm64. > > > > > > > > This patch lets fprobe code build on configs WITH_ARGS and !WITH_REGS > > > > but fprobe wouldn't run on these builds because fprobe still registers > > > > to ftrace with FTRACE_OPS_FL_SAVE_REGS, which would fail on > > > > !WITH_REGS. Shouldn't we also let the fprobe_init callers decide > > > > whether they want REGS or not ? > > > > > > Ah, I think you meant FPROBE_EVENTS? Yes I forgot to add the dependency > > > on it. But fprobe itself can work because fprobe just pass the ftrace_regs > > > to the handlers. (Note that exit callback may not work until next patch) > > > > No, I mean that fprobe still registers its ftrace ops with the > > FTRACE_OPS_FL_SAVE_REGS flag: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/tree/kernel/trace/fprobe.c?h=topic/fprobe-ftrace-regs&id=2ca022b2753ae0d2a2513c95f7ed5b5b727fb2c4#n185 > > > > Which means that __register_ftrace_function will return -EINVAL on > > builds !WITH_REGS: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/tree/kernel/trace/ftrace.c?h=topic/fprobe-ftrace-regs&id=2ca022b2753ae0d2a2513c95f7ed5b5b727fb2c4#n338 > > > > As documented here: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/tree/include/linux/ftrace.h?h=topic/fprobe-ftrace-regs&id=2ca022b2753ae0d2a2513c95f7ed5b5b727fb2c4#n188 > > > > There are two parts to using sparse pt_regs. One is "static": having > > WITH_ARGS in the config, the second one is "dynamic": a ftrace ops > > needs to specify that it doesn't want to go through the ftrace > > trampoline that saves a full pt_regs, by not giving > > FTRACE_OPS_FL_SAVE_REGS. If we want fprobe to work on builds > > !WITH_REGS then we should both remove Kconfig dependencies to > > WITH_REGS (like you've done) but also stop passing this ftrace ops > > flag. > > Said in a different way: there are arches that support both WITH_ARGS > and WITH_REGS (like x86 actually). They have two ftrace trampolines > compiled in: ftrace_caller and ftrace_regs_caller, one for each > usecase. If you register to ftrace with the FTRACE_OPS_FL_SAVE_REGS > flag you are telling it that what you want is a pt_regs. If you are > trying to move away from pt_regs and support ftrace_regs in the more > general case (meaning, in the case where it can contain a sparse > pt_regs) then you should stop passing that flag so you go through the > lighter, faster trampoline and test your code in the circumstances > where ftrace_regs isn't just a regular pt_regs but an actually sparse > or light data structure. > > I hope that makes my thoughts clearer? It's a hairy topic ahah Ah, I see your point. static void fprobe_init(struct fprobe *fp) { fp->nmissed = 0; if (fprobe_shared_with_kprobes(fp)) fp->ops.func = fprobe_kprobe_handler; else fp->ops.func = fprobe_handler; fp->ops.flags |= FTRACE_OPS_FL_SAVE_REGS; <---- This flag! } So it should be FTRACE_OPS_FL_ARGS. Let me fix that. Thank you! -- Masami Hiramatsu (Google)