From patchwork Sun Sep 24 13:37:12 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: 144082 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp668500vqu; Sun, 24 Sep 2023 06:38:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHf/yXghBBSU6iBF/U5ZTc8UgmilTRjlGf4y9RQPBcjvRPOIvxe6n7Xcc+xr1uEzqbZQGY7 X-Received: by 2002:a17:90a:53a5:b0:268:ef84:b0cd with SMTP id y34-20020a17090a53a500b00268ef84b0cdmr3652334pjh.18.1695562687506; Sun, 24 Sep 2023 06:38:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562687; cv=none; d=google.com; s=arc-20160816; b=l2GcFK/9ThXeC0l5dJfnfAUmnjkJoP/DMMRCepu0jBWr5y/1tOTLBcI9RFmRC0pTFG TDFS5isZMxBT6611vogjcL7II6nDHAyotr74SNNxXSWMHEMT5vdGpqCITc7IQc6dSikY iKOJkemDbdqZGSu7Qz/vqU9jBn9RaUWSWNX7dype3D9H/HPyzXH44Sf2ejnij9S0cTqC +3SSFNmC8Q90zY3UqLQIa2pAb5ph+oWJfINswW+CYY3vTlluBz8ujVMShAQ8DW698ZRT C6l+gApi4nMZ0leTFZalzZt5AOBg9aUgP+Jlj9kSc7f1a9nBhBVEZjCIIF9mgwctrYUf SNGw== 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=ncge2Zm0yn9fPwwh80aPqSVlA9HyWb2Nt1pMIwQ9oyg=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=W58T6WIyU7oaqrJ/hyjDU6XeFP6xcJP/yoMpVEZdzR0oGHzuIqOzVNhuGU4NMNS5zR vTbcFHdkuxWDS6WREWVZSaIJgEP4O6WicEPqwP+6p1om4gpbIUUrxHi+Q8GMdE9FSIH4 ufRZ4u38otlgNV/gLmPCbC1j1Ed/MVzcSw7fJi4+v3SliXz5N6rhBmSThlqxr0ps1I6k uT05zxJ1ICyzL41QACmDe4J3mr3zbQ75qp55qbVeKt28qdH7tz1szHrMq8ueYKSqzru6 bG6SCnrtyVeW7bcYOjabYrx3TVlLbT7Gm89PIWyesNSWf7bZ0gpl8YPZ6G56Kv/REJYh 2CrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HE5ucNqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id t2-20020a17090aba8200b00276bdabe471si1119538pjr.163.2023.09.24.06.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=HE5ucNqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 2A88B8029AF1; Sun, 24 Sep 2023 06:38:06 -0700 (PDT) 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 S230168AbjIXNiI (ORCPT + 30 others); Sun, 24 Sep 2023 09:38:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbjIXNhv (ORCPT ); Sun, 24 Sep 2023 09:37:51 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B75361AB for ; Sun, 24 Sep 2023 06:37:19 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 869FAC433C7; Sun, 24 Sep 2023 13:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695562639; bh=z3ZqUJHGicIifDXnSOHi+t2Ua5M0QIoavgEAxehdPoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HE5ucNqgLQ6mEyv5bXIhJHQFfj8vqMflwi8sAXOd+r/H9A2fcYyvgNzrF5aLrM0rq Gnn88OCM45M4cgm1ZQ7zAPV25NOTja+1iT+JWKYWyKkcUojtYaudI5f3L6clmtSE2g 5/0HrCCah3Igi9JDGgSKUvLSXSBoBDnMLVT1OrHDPHU87Lfq5uptwOeto28FJB537Z zxt6cdDCq3A2bd1RT0qIBVQvH7qatk/eQ1LYEgUFEnlTL41DhpWvKisjmh3BwP8B8S 1XV7tvJl15gzEi6hOEyKgFti4ZpfKx5bkECyuOBmtplpl3StNTBjyVOOUNk94eizZY GcddpbvM7kI9w== 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: [PATCH v5 07/12] tracing: Add ftrace_partial_regs() for converting ftrace_regs to pt_regs Date: Sun, 24 Sep 2023 22:37:12 +0900 Message-Id: <169556263259.146934.4055143510535198098.stgit@devnote2> X-Mailer: git-send-email 2.34.1 In-Reply-To: <169556254640.146934.5654329452696494756.stgit@devnote2> References: <169556254640.146934.5654329452696494756.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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:38:06 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777926340112918865 X-GMAIL-MSGID: 1777926340112918865 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. Changes in v5: - Fix tag in the title (ftrace: -> tracing:) --- 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 39a765c71f7e..819511ab75b7 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -173,6 +173,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.