From patchwork Wed Aug 23 15:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 136708 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp622013vqm; Wed, 23 Aug 2023 10:49:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEQSQoNcHTwr2CwqN5gtj4Ma0m3F/G7wKOAmfph1jCf6dClIm9wzBf7TEAhqExkYGftAn2h X-Received: by 2002:aa7:cb4d:0:b0:527:251e:1be8 with SMTP id w13-20020aa7cb4d000000b00527251e1be8mr10362112edt.13.1692812945430; Wed, 23 Aug 2023 10:49:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692812945; cv=none; d=google.com; s=arc-20160816; b=oey8R4SJlRp9u4B6w2p/p9Y/m6xNryaknBzuCU+Cg9xljxIPQ+xo8C7HHzhBZwWgQX A+QxDd6vMLsWGFfwq/ppUIUPmHyEPeebunpowa9ODAPKDRKQq9tyN7H3cEMXZpKlBLhH dwQWfkS7pSR7qmnhS7Sjj8wHTj15D9Vnk0mY6fTVYbVqo0tZ67JVZsAjA5e87pTjqrrB 9FlHh57Hv1stdI4zI4VixET4FL0yYqtwqP/uPD+w7oe2NRazdyNqxP7O3lRIUfXt7riw S3ZEw+iAd13zlnT1ksOKB4WPBJ+ZHhL6Lv63oqiXkWJ1RA4Fi38xfj7D22+iBjSyFFRr y/JQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qP/XumMPOxQSC7Lw4wfrijQUrZ0p896RF40OUcSskR8=; fh=nNLeqPmm07c4DrdDej5z+HdJpmx5SqFFnpeka2nrMVM=; b=mPjAtOSf7U6wBkGRTqiIbXXLrVMKY/ms/DuGUszYosISuFw1TMz8RWt9pozzZIqY5G 1xK6a/dkt7xglmzufktjojlj7Uk/WOFydr7bG9geSr2mwxBXu8zurRtnN9A0ddu3QaN+ nn3IDcz3Ofy30HWUNl7/ZgWEgCTEDuYdSSGedom3SChwf3BynjMVyKCAAh0F15pCRYjs Ljw0S5zVn/EV87Kuw5pVU0RDPVmP8J7az4gzZny5iSG1EjGoeG33LhLPbldON78eZZlh zDUVsbaCcPPr2Nc8asj23K2dZsrc7Kz5TpTNXAUy6OtdUeWUtWcCrfI32cyCkxrh9eN3 TYIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=idnQDC5l; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v26-20020aa7dbda000000b00525641e460bsi9738768edt.190.2023.08.23.10.48.40; Wed, 23 Aug 2023 10:49:05 -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=idnQDC5l; 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 S237090AbjHWPSN (ORCPT + 99 others); Wed, 23 Aug 2023 11:18:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237054AbjHWPSC (ORCPT ); Wed, 23 Aug 2023 11:18:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79F40172C; Wed, 23 Aug 2023 08:17:41 -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 CFCF565204; Wed, 23 Aug 2023 15:16:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 861ECC433C8; Wed, 23 Aug 2023 15:16:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692803792; bh=auDMVayuMUnIghRCjZjrPWMDbCTvhrmJ85LBeBWaOGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=idnQDC5l9kLB2hyhfoXnPf1loh2XKxbpGcY8DJZ5SLBavLSuj44HdsBXOcjDpDwQ5 ZI5t0CfuyBLSm5i5uZSoIBAuXpp63LOfObzv1TS2ycufkhRNqkQGp1OM3IBRPXbpRy ixQaeLTcPKpLAdKdCD8SR3ECsMM80aEYGhKyHF0L7BMUypixqQGRXnWhbryp3t9ep7 IITfB5m6Z/FrWF52KlTtKT1mL/EF4t2Yqn/p6upUmw+yAMo5s0HdcMnDFT16+PeVnK 1H6m654UZlKF8iRVbA5k1+AvunRXEwP0WpU7E2DhXWFOlocJIPGHit1xf9uZXF1Bzu 8hFXdKjx12CHg== From: "Masami Hiramatsu (Google)" To: Alexei Starovoitov , Steven Rostedt , Florent Revest Cc: 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: [PATCH v4 5/9] ftrace: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Thu, 24 Aug 2023 00:16:26 +0900 Message-Id: <169280378611.282662.4078983611827223131.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169280372795.282662.9784422934484459769.stgit@devnote2> References: <169280372795.282662.9784422934484459769.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775043027125152603 X-GMAIL-MSGID: 1775043027125152603 From: Masami Hiramatsu (Google) Add ftrace_partial_regs() which converts the ftrace_regs to pt_regs. If the architecture defines its own ftrace_regs, this copies partial registers to pt_regs and returns it. If not, ftrace_regs is the same as pt_regs and ftrace_partial_regs() will return ftrace_regs::regs. Signed-off-by: Masami Hiramatsu (Google) Acked-by: Florent Revest --- Changes in v3: - Fix to use pt_regs::regs instead of x. - Return ftrace_regs::regs forcibly if HAVE_PT_REGS_COMPAT_FTRACE_REGS=y. - Fix typo. - Fix to copy correct registers to the pt_regs on arm64. Changes in v4: - Change the patch order in the series so that fprobe event can use this. --- arch/arm64/include/asm/ftrace.h | 11 +++++++++++ include/linux/ftrace.h | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index ab158196480c..5ad24f315d52 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -137,6 +137,17 @@ ftrace_override_function_with_return(struct ftrace_regs *fregs) fregs->pc = fregs->lr; } +static __always_inline struct pt_regs * +ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs) +{ + memcpy(regs->regs, fregs->regs, sizeof(u64) * 9); + regs->sp = fregs->sp; + regs->pc = fregs->pc; + regs->regs[29] = fregs->fp; + regs->regs[30] = fregs->lr; + return regs; +} + int ftrace_regs_query_register_offset(const char *name); int ftrace_init_nop(struct module *mod, struct dyn_ftrace *rec); diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index c0a42d0860b8..a6ed2aa71efc 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -165,6 +165,23 @@ static __always_inline struct pt_regs *ftrace_get_regs(struct ftrace_regs *fregs return arch_ftrace_get_regs(fregs); } +#if !defined(CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS) || \ + defined(CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST) + +static __always_inline struct pt_regs * +ftrace_partial_regs(struct ftrace_regs *fregs, struct pt_regs *regs) +{ + /* + * If CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST=y, ftrace_regs memory + * layout is the same as pt_regs. So always returns that address. + * Since arch_ftrace_get_regs() will check some members and may return + * NULL, we can not use it. + */ + return &fregs->regs; +} + +#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_PT_REGS_TO_FTRACE_REGS_CAST */ + /* * When true, the ftrace_regs_{get,set}_*() functions may be used on fregs. * Note: this can be true even when ftrace_get_regs() cannot provide a pt_regs.