From patchwork Sun Nov 5 16:11:57 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: 161682 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2198473vqu; Sun, 5 Nov 2023 08:12:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFZujAQELIdA3MT/09T/7j7hNWk+I9qoiqHM21ewAnNPzDIaH4Ljo8bQ14kDVZt5iFKXC6Y X-Received: by 2002:a17:902:e548:b0:1cc:4488:afba with SMTP id n8-20020a170902e54800b001cc4488afbamr11213697plf.6.1699200742590; Sun, 05 Nov 2023 08:12:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699200742; cv=none; d=google.com; s=arc-20160816; b=k4ixYL8PM+d2RS8g4RuChqMbeWjXryI7DgPYN+BGOpMou1E8TsdSrzpCJ1fJUlX2Gm B2PkqQ16NzwMNTVoQ5MRYlkAbEDM2pKxac8s7oK9EkC1qcXUpb7ynzWQMqrgKiNbaES0 U/ZGw+fk3ys4QvCDxASTI68vSkm2BO+xIQ3wt9My6uavEfI0RZSMuy/CQr1aW2wjN7yv oKL7RJzt+y+iwKBOSVXGy/mZ8ik5chG9ludDMA2iB9NQk2GHSkndhBirOae6xOSZ0gYj 48AF1oeSRNGpCOw4D+2MIwAPrIYm6oHyozLtoP6BOSMoYUCBY7xQzDavVYP8RQDxDePO 1KKg== 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=QjGXXbd2+S66OA9AIyzLhStxKNYnSxyrQSbswVhUyUM=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=nvXRNeA4oSAH5PyzGba5qo7T0JnwfnXJDwYQVZhvI54+980iwsj61O+RP1gECg6rsQ OLB73rYnRvRQsbhsBpDpqOQGSZBzFKVdHk/jr8m/g9RxjUzsiYoDzRucJfQgYQckf+qJ 0aGU1X4enb6Ql1AsUil/eDf/94xPw4HlVY0fL7YAMtxBL7Ih2TY65bZiMnKv8Ng47AnH Fz9KvIqVpLPQhZ6Z6lEVzm9O1yOroBhYDhrpLNU+aJ+Rd9j3qJxVLliLHkraH0gOQzZX nUQvt3hXlZpxHB12wUwKfzkHA8qx6OLPOOaz/grWG+Kk/6RDta96n6qN42eNKcUVhqBM AFlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOu4qL9y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id lh4-20020a170903290400b001cc3e75b2d2si5866781plb.446.2023.11.05.08.12.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:12:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bOu4qL9y; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 5DCBC804705A; Sun, 5 Nov 2023 08:12:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229468AbjKEQMS (ORCPT + 34 others); Sun, 5 Nov 2023 11:12:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229850AbjKEQMH (ORCPT ); Sun, 5 Nov 2023 11:12:07 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFE97123 for ; Sun, 5 Nov 2023 08:12:04 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 803E2C433C7; Sun, 5 Nov 2023 16:12:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699200724; bh=vk7wW23Tf7Fx6d6+RxROO/tS9W9QJV09ekq203vNHlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bOu4qL9yDmBwLqq8yLMtEshX1dvrrI23mX14nn5KTizYb62gVzWSwPBQ63E/L6wfH T/Mrt6azvN04jRkQrKAmFTJyuTLgLeBCwsDX0p6D/gKAloVK9nqSMQCXIbYZZpPFzL IVKIVLRra1NPM+Wg0wdGufy5qm2m4ml3mlYm4EVNU2+TdgCERNasGRXxOQfxYP7H/b DedDBIQe9cwh9/OvBxcXd/s3MFHFdxTXyLFE2ethoyrcaWcgrJzs6hQloqco4IFMpw MnPo9caW1dbtOi9FHePoVjuUyg2yAyNJveVhceuLRtuqe4aJ5V78xnmvHBhlsyxJAM hgE5NoBXcwIpQ== 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 27/32] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Mon, 6 Nov 2023 01:11:57 +0900 Message-Id: <169920071741.482486.15046208284937337125.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169920038849.482486.15796387219966662967.stgit@devnote2> References: <169920038849.482486.15796387219966662967.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-2.7 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,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 05 Nov 2023 08:12:21 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781741118157381366 X-GMAIL-MSGID: 1781741118157381366 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 894117e909dd..3d0ff6e2c4bf 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -147,6 +147,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.