Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp5824111rwb; Wed, 9 Aug 2023 09:33:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFaDSyxHUy/vq6wZ+Zl8mjvQN6yCWAYBR8b4hB7DnE3FRnpGnzY9Lkfc2aS9hTMy0nVLa10 X-Received: by 2002:a17:90a:bc8c:b0:268:e5db:6e15 with SMTP id x12-20020a17090abc8c00b00268e5db6e15mr2264954pjr.14.1691598793535; Wed, 09 Aug 2023 09:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691598793; cv=none; d=google.com; s=arc-20160816; b=CjZZD3vv/XTfPRZ4sDF0BdEN/413ldipoz26d3Gk8hdKLS5r+MDew7AzeMWpLSwxyu L3gdK8NUwKPwbzD7+uWa0LWvf4B95DoZkRIW3sdkOhwKR1kizcFo8pgbhxtaqhG9meUK hFOMuHdpxKj/oBf7dehFqLCruH38oFHZo+q3CRUzuqs1cOfdEj0IS7SfhEm/uIRXzpd7 C2isLokeJ425dSf+abJI4gqjkXTLrikVureo+F2Vu8i8gElGno0oXjQM8v6jIhITVcFh 28ZnnD6l9nmMBNxN1UWqLE1Z+uCIw8g22ABbnuXiiKTREYzESBIscFS6cHQgESwH7fVa dKzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=xMpn6SbN2eaSRjTRTeLdDj+fif3mbbSQ4nc9edZTZdA=; fh=3JZkHl2ukg7miGavQW0g2JmR/cZkT7HJHfkPx8E7A9s=; b=O9X/ZaaU6Uvskr/W4EGnyGqB9bHVgcLyE4PQcvLeo3s844AAQK6VFQabZoUFVAFgBW 7Za29NTD9H8I6btaTlXen86oyjWCdKHJQWVbNLWkO4jC6BXLWoANBkIuVlvC+eR+K3cJ hNPgoD8dJ7PrNjdQvbWgRsXSbPXBncqsmrCmW7Ob+iv+vX5whjcrai7mbas3QMIyV8SJ s40WrFulCFGsY/Fqy7Y+uncQTwP/5hk6l87lhcEl9WZ2bqxkyLtSKvYksNr2IKiTwAtU SIkOBJ1elfDK6vfOWZygE8PdYQ9Cq0fnd/HLUJ1Alh1SNr42v14H1iG9g+wP/tZKrf1/ pQtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VTFoUM0o; 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=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qe1-20020a17090b4f8100b002681b60504asi1842795pjb.115.2023.08.09.09.33.01; Wed, 09 Aug 2023 09:33:13 -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=@chromium.org header.s=google header.b=VTFoUM0o; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230031AbjHIQKE (ORCPT + 99 others); Wed, 9 Aug 2023 12:10:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjHIQKD (ORCPT ); Wed, 9 Aug 2023 12:10:03 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CB0219E for ; Wed, 9 Aug 2023 09:10:03 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id 98e67ed59e1d1-26837895fc8so3975754a91.0 for ; Wed, 09 Aug 2023 09:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691597402; x=1692202202; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xMpn6SbN2eaSRjTRTeLdDj+fif3mbbSQ4nc9edZTZdA=; b=VTFoUM0oS3XFRrMwLsXKltkF1VN5RVPAXlncucHEJOFf93EqFusEyKe1jrKOOIKe0c 9mvGxd6qeO2oJoDFePnOzjXy1kGtvqGvNFrifMRnd0owBmXQHmB5sgrnFwt5mJ4ywj4H vyne1muga6wEAADqA/Ur2syLuagWmg6YYBAHI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691597402; x=1692202202; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xMpn6SbN2eaSRjTRTeLdDj+fif3mbbSQ4nc9edZTZdA=; b=JUrAf0JXxdQHiQCVIgQp+a4518NatnIxJl4v3cQp+Aka+w0IBHj/c771CnkyE2xl/V F8XQRgflzOkC5uAoWmt14VzwU4wg/mK+HKurpeHdXthfjv0Gcf67QYl96P/Kzlk8ZZAD iyAMdjdsGK+N0HD0zIeh07G9/u5d6ub24lohFlFVDOleQff/p7fMb40gG0kbWR+Hq3tP +bmt3hxFwLo9hpsz3XQG0++Kc2nowZCJmBHDHVI6AG8ISkqD+dKqcok8s1u7yF8acHm2 UG6jTG67GXmNs7h9LBeb9CKMtJD3E6j0UfuHgEdVeQ3l2qQ5J+bGWR23UksmZE0KBK2Y FQDg== X-Gm-Message-State: AOJu0Yy2WYMnLU8JXVVdpK3d9Kv/gOAXEflBDpLgRxPcxFushLsdIEiZ s64rqfqpEWJBB2Q7Psi3uYZOG6HAvGLqlind0JEiTA== X-Received: by 2002:a17:90a:db90:b0:267:fe84:6647 with SMTP id h16-20020a17090adb9000b00267fe846647mr2564394pjv.13.1691597402536; Wed, 09 Aug 2023 09:10:02 -0700 (PDT) MIME-Version: 1.0 References: <169139090386.324433.6412259486776991296.stgit@devnote2> <169139091575.324433.13168120610633669432.stgit@devnote2> <20230809231011.b125bd68887a5659db59905e@kernel.org> In-Reply-To: <20230809231011.b125bd68887a5659db59905e@kernel.org> From: Florent Revest Date: Wed, 9 Aug 2023 18:09:51 +0200 Message-ID: Subject: Re: [RFC PATCH v2 1/6] fprobe: Use fprobe_regs in fprobe entry handler To: Masami Hiramatsu 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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, Aug 9, 2023 at 4:10=E2=80=AFPM 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=E2=80=AFAM Masami Hiramatsu (Google) > > wrote: > > > > > > From: Masami Hiramatsu (Google) > > > > > > This allows fprobes to be available with CONFIG_DYNAMIC_FTRACE_WITH_A= RGS > > > 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_reg= s > 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/ker= nel/trace/fprobe.c?h=3Dtopic/fprobe-ftrace-regs&id=3D2ca022b2753ae0d2a2513c= 95f7ed5b5b727fb2c4#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/ker= nel/trace/ftrace.c?h=3Dtopic/fprobe-ftrace-regs&id=3D2ca022b2753ae0d2a2513c= 95f7ed5b5b727fb2c4#n338 As documented here: https://git.kernel.org/pub/scm/linux/kernel/git/mhiramat/linux.git/tree/inc= lude/linux/ftrace.h?h=3Dtopic/fprobe-ftrace-regs&id=3D2ca022b2753ae0d2a2513= c95f7ed5b5b727fb2c4#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. > > > > > static int > > > kprobe_multi_link_handler(struct fprobe *fp, unsigned long fentry_ip= , > > > - unsigned long ret_ip, struct pt_regs *regs, > > > + unsigned long ret_ip, struct ftrace_regs *f= regs, > > > void *data) > > > { > > > struct bpf_kprobe_multi_link *link; > > > + struct pt_regs *regs =3D ftrace_get_regs(fregs); > > > + > > > + if (!regs) > > > + return 0; > > > > (with the above comment addressed) this means that BPF multi_kprobe > > would successfully attach on builds WITH_ARGS but the programs would > > never actually run because here regs would be 0. This is a confusing > > failure mode for the user. I think that if multi_kprobe won't work > > (because we don't have a pt_regs conversion path yet), the user should > > be notified at attachment time that they won't be getting any events. > > Yes, so I changed it will not be compiled in that case. Ah ok I missed the CONFIG_DYNAMIC_FTRACE_WITH_REGS guard that you keep between patch 1 and 6 to avoid this case. (after patch 6, it's no longer an issue) then that's fine.