From patchwork Sat Aug 12 05:37:46 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: 134824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1547288vqi; Fri, 11 Aug 2023 23:17:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkETgLnemrjH1tYEuIb8dMhCLTZ0ma8+oTUlK34z9YVpuYxBR3ENwO65SlKWTsLu0dQmcW X-Received: by 2002:a05:6a00:2489:b0:63a:ea82:b7b7 with SMTP id c9-20020a056a00248900b0063aea82b7b7mr5642563pfv.28.1691821064873; Fri, 11 Aug 2023 23:17:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691821064; cv=none; d=google.com; s=arc-20160816; b=GwQ7wJTLnQtkZK588Yf/pDWZfbmhGGDjnfrpSJgRkZouewSQanNfXTBJLQ+Ln90vJ8 ezwypuS9IRta3HaqnyL+xYuDWKtilYFr1i5rlj5HNuWrYLPXlF7IBX89tZnSSocUtw7x NiCgdQeOEL7YMD2M52BeLwOjnWf83UBQMKqHnoB5Y81pwwscofPKe3tx+wHeE+ot1+f+ jt9rsTLnyLELCyGHPE1sGgY7DdCXBOrijvio4gqWHxv+ZG4lzQnhvw6HLREQ6cbdcUls bAwW9gZS9OcEaEh46aNIkCWOJ0J/FmHTWfDQGuj5k4e264u4XEwFAPNEF4805OhAb4li /ycA== 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=6u/SP7jCKr+kuRCoOC3/fX5RXNtkBk+5cCuCHqpDV+k=; fh=nNLeqPmm07c4DrdDej5z+HdJpmx5SqFFnpeka2nrMVM=; b=KfjV6d3XQ62QuYrD6f5vrNJEbnjf7C4/DErMUD3+cbtzzc34HIWpMwgQYBss5qKApS tBXyPromk+0C9Vo+ePyETbEvz5G6vSUQYgNStjmLkZBtshcpr37TEv4zEU7A9TEUAfc5 y11bLie2wMD5F6heH3/7xbn/m3k+kK/2loz+u3ydTLgaoGLMokOXj8de/OJ+DtnEn8DC KBuCanqYdFxkHDzoj8SCz03DUcJXgf1204gkIcfxX3H+4NyylXQxZBezvI2iZICmS3l0 pUmk/csgA7Uflm6RwR252ViUediMM3IWLbFnwmof20FA7lFYG1XYlwt9dTaF84e4X8NQ sHDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="r/iaF88f"; 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 q18-20020a056a00089200b006878da95c2csi4606994pfj.81.2023.08.11.23.17.31; Fri, 11 Aug 2023 23:17:44 -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="r/iaF88f"; 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 S236302AbjHLFh5 (ORCPT + 99 others); Sat, 12 Aug 2023 01:37:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236221AbjHLFh4 (ORCPT ); Sat, 12 Aug 2023 01:37:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CE442D69; Fri, 11 Aug 2023 22:37:54 -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 96F736405A; Sat, 12 Aug 2023 05:37:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61953C433C7; Sat, 12 Aug 2023 05:37:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691818673; bh=CEHOSZbi9FJS29a7d+B13NM/f0jx4Qwp0DObzr3ONVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r/iaF88fGLKh04qQMuviOSGCmeO0+C/yJ/IuYPOnZ1aZjTtaGYr/0fT4Naxj6G4l8 ODCGhNnht3p0WT9yBFiUv52pxY+XlNp2MkbJITBeyfVB0j+e5N+jhx6Eoq0FngXY2r SFy0kEaClON9tPBYCF9VlVg9uRvhD+lNyC2QOvpOymtcYrUlsN6pT4BlisW5bxTMZF w++4XPuY2INCKYyuwkgAwWw9DLVAUAQJss/tbbICqbJw5nSHDklCJBfeVGQlEa6ABJ YtBz7MmfsTSqagEdShULsPM4BNrltoEzzOBuPh2S21f+MEtF0qwKECWKalmn5N93iu r5bqR5KjNRSdQ== 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 v3 6/8] ftrace: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Sat, 12 Aug 2023 14:37:46 +0900 Message-Id: <169181866661.505132.3229847361646568033.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169181859570.505132.10136520092011157898.stgit@devnote2> References: <169181859570.505132.10136520092011157898.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: 1774002965224184990 X-GMAIL-MSGID: 1774002965224184990 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) --- 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. --- 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 3b3a0b1f592f..dcb8ee38d78a 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -159,6 +159,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.