From patchwork Sat Aug 5 14:58:35 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: 131495 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp512870vqr; Sat, 5 Aug 2023 08:29:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHPgvEKbSva5izmVMqzZtx3qrQGLekHRggjiaKI7L5972PYVeXBRhg4k+FUx1/24vtUXv1Q X-Received: by 2002:a17:903:32ce:b0:1b9:e97f:38ac with SMTP id i14-20020a17090332ce00b001b9e97f38acmr3853255plr.56.1691249390404; Sat, 05 Aug 2023 08:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691249390; cv=none; d=google.com; s=arc-20160816; b=P3V9KZ2KzdTd1w4oExzjWkETeSwhkBiFCjxhWs81+rKYlneMuQp4o6QA8UVslGWaO4 YCwSbUX7VRGD4uF+5jGChwFl9Bb//AUkCEyjPeCuMnSKcpLMpVltfe4K1/9yFlMOzKS6 vLtyfP04vJshzkQLjKRivABjXfS/D+NX2jeuutF8fSo8tWU/QGnDhbJqaD8CPrKsxGLg QdDHb5jZQ/iV0NIZT4k8lvrZ/NKkm/V+jjXSndK7ntUom7kltdZl0rVYQPSQIFJFhtyu 7K/3Emov0CrjxBemntz/7nOGqbDF91YP7zcplIVkn8H/iKt/QgDO/kpUTCAUhZi9MI/J +S1w== 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=SjnmLm9PgCJSyQ0i1XSERXDDT+lqIL31uKAKMcT68Ho=; fh=nNLeqPmm07c4DrdDej5z+HdJpmx5SqFFnpeka2nrMVM=; b=DX61CJmFWGax9doGp/oxmmWwvogRtj0MHq9kk3ere8/Gm2kuJzDYbuL8Qengo2pHgL xqZNrH/SzrkWrK0N18HUabC+baIOEFDh65mcydpmUGcs1+ct83i1/9vOSG1NmIRrylVL kR87vhMASBVwyFNC5//50g9nk1X9VbSNzU5Q6pybUXPKYu7u47j3DYPkK+M6QUyz1uI5 M0dqjqnFibAhpSHi5UCD7DhM6HhN7b3359xHKGSqWZ/94crPtWaday1teantZIhPl6Sj 4yB1HRrx/k2x2lgKO7h3l/wM4JCh+nrJtqCnmav03JAxD4NCIcDsM4h7SzTqbxAYJeqx /avw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Xii3jTe8; 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 h15-20020a170902f54f00b001b8aa6b6acesi3373358plf.387.2023.08.05.08.29.26; Sat, 05 Aug 2023 08:29:50 -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=Xii3jTe8; 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 S229896AbjHEO6z (ORCPT + 99 others); Sat, 5 Aug 2023 10:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbjHEO6x (ORCPT ); Sat, 5 Aug 2023 10:58:53 -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 2D3E044BD; Sat, 5 Aug 2023 07:58:43 -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 B629260B21; Sat, 5 Aug 2023 14:58:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CF05C433C8; Sat, 5 Aug 2023 14:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691247522; bh=7WBz3LPX1X/CQd4LTl08Nwgbo3NlVRw25ijSgFRSKc8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Xii3jTe8lh9gNRhhBKJ+Ly1Mn4Po/eAk2+pWT4wL3m02oVIKiaHld5ecavbbtqKyH LVdx90xzfnKfZcIPvuhrzDb+4mCbFd74kxk0beGJ3yWRSZPm9qVN/QZBYQMle0fcV3 lHzWtiZ+bvfAc+6ETbeNw+z+fhp10k6ekEkGecSZ6E1ynMuWXV/g3Sd/m3/IhqG6K5 YkomnbtxMrsQfFuIsWMeirZeBq8/jVY5Auo33J9j+X16DlY8qS8ORm8kd5v9txHzwP YcejHo5dWWLyihua0zSGsZHzbOc9Xoo3ByVlCp05M3COhGUTXS8aRZqsWCJGv21SPd FYrvp1eDraPAQ== 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: [RFC PATCH 4/5] ftrace: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Sat, 5 Aug 2023 23:58:35 +0900 Message-Id: <169124751584.186149.17291016280237570755.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169124746774.186149.2326708176801468806.stgit@devnote2> References: <169124746774.186149.2326708176801468806.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773403520603810930 X-GMAIL-MSGID: 1773403520603810930 From: Masami Hiramatsu (Google) Add ftrace_partial_regs() which converts the ftrace_regas 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) --- arch/arm64/include/asm/ftrace.h | 11 +++++++++++ include/linux/ftrace.h | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index ab158196480c..b108cd6718cf 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) * 10); + regs->sp = fregs->sp; + regs->pc = fregs->pc; + regs->x[29] = fregs->fp; + regs->x[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 ce156c7704ee..f4fbc493aceb 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -139,6 +139,17 @@ 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_COMPAT_FTRACE_REGS) + +static __always_inline struct pt_regs * +ftrace_partial_regs(const struct ftrace_regs *fregs, struct pt_regs *regs) +{ + return arch_ftrace_get_regs((struct ftrace_regs *)fregs); +} + +#endif /* !CONFIG_HAVE_DYNAMIC_FTRACE_WITH_ARGS || CONFIG_HAVE_PT_REGS_COMPAT_FTRACE_REGS */ + /* * 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.