From patchwork Wed Nov 8 14:28:58 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: 163059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp951950vqo; Wed, 8 Nov 2023 06:31:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFsaMcwn8EyE/fIfeiIfXR/uozLw9STDB62+FMQuNrkcNe0qOeKNvTZiEAzYgp6WYN666S5 X-Received: by 2002:a05:6871:4a09:b0:1ef:b809:3f26 with SMTP id tz9-20020a0568714a0900b001efb8093f26mr1692443oab.17.1699453903979; Wed, 08 Nov 2023 06:31:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699453903; cv=none; d=google.com; s=arc-20160816; b=HzDjwEBV/J0Il0NG8tBuq8x9mCDRUyjqDhfH94+67wETxguse2QY215CSAkuWSQryV uAsJ4gVpLNVQkphsdPhsCTQdZFmU7p6x+GB2oFBR5fRd73EXDNgSOU85dIOeQik2cP43 soMz1I1V3COBahTRHGIZZfTckDw6MlO6QY90G8foo6d+aIXG5pHtJiapYpKj98QobnQJ 1ErzNpvxicF0L811KIO+GRTxXcWUtncF3QqPBbrIql1D0RSXJWVaXLoQ9Po/fB20XY9u eRBfExdgrWD2MEv8fIQ/aqoNcan4jpUGKwpFAp9lbwi81g8d/Hdz1CuLQSnXPZoJkUk7 jWWg== 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=Ih/5XHqEw/5l3TEf/9UdCF6W+iNz/yPwWmBX6q62fFg=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=NKDMKAF+hHPVoFERcGyzt1DyBEnjo48ZNl5HzPaDKZwS/CLMpVfn+vOu+GuqgMwxkz fWepYhlY5qq/NmxB4dXeD8RkKTbgq1faa9ZGD7tHzkgZQm9xCT43up9EwbKb2b1oJMlK KItp3j4UvsjNcysxmR9mszUtrH44LsqAmLO/Ru1yYLnYtiRvTXKlpSlFo/vlaWFal28B mj6K3HkUeAP+N+4bFOxwVO6mYOHIqGrJNQ+kAfz8VJnzTb8XDTv85MxBlO5qyFbVmHN2 Dy+GQNKZNY9BheZIb7ruZJc3BZOY/6LmUJIMCfSDysIncZRadbfu6NHbRzZKdGnnDiSO V/aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d1ZTNI3b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id oj17-20020a056871581100b001ea35259e96si5240992oac.228.2023.11.08.06.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 06:31:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=d1ZTNI3b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 1FCA7806E3FD; Wed, 8 Nov 2023 06:30:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235203AbjKHO3i (ORCPT + 32 others); Wed, 8 Nov 2023 09:29:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234536AbjKHO3O (ORCPT ); Wed, 8 Nov 2023 09:29:14 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8ACB25B9 for ; Wed, 8 Nov 2023 06:29:04 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C4B5C433CA; Wed, 8 Nov 2023 14:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699453744; bh=nvQ4v2RfL+rW6LQ5jLmbS0C2Mc8Q/AnQKonB+7bHXEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d1ZTNI3bsnagIRwoTIWBdgh0NWIq/kVuR8XOYSIR/+TXg9y1o476kolNHDpAmb1Hu Q7r2iozHRvMq+VkPxWzX6LL3ZEGGJjynRUSILiURkMlULYh9gLKNlfXoZALzB5doKo +2OjAnM1p6vGX0IqFqt241xtd/kqODRrugO7yi+MoilwHKsoThc/5X4eBC4A2BSSvh fi8w55G6EgaXn5kcuNkiZFhr9PZ/SfDZgnDZq8LlOEN1UYayDdCa3/HOiQhFuuPkHC pgnJ/0oBP5jb+rw/NlTTMFCY8LubXUFNMNUK1lFcv1salSHfaz3MimipFWlSlvRqJY fFELcCbHaSUXw== 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 , Guo Ren Subject: [RFC PATCH v2 24/31] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Wed, 8 Nov 2023 23:28:58 +0900 Message-Id: <169945373844.55307.8967183255641266616.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169945345785.55307.5003201137843449313.stgit@devnote2> References: <169945345785.55307.5003201137843449313.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 08 Nov 2023 06:30:43 -0800 (PST) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782006576837343260 X-GMAIL-MSGID: 1782006576837343260 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 from previous series: NOTHING, just forward ported. --- 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 c87e4debf698..c871b195730c 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -172,6 +172,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.