Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp662415rdh; Sun, 24 Sep 2023 06:38:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH4fLahcRzKKtGD/SZvDICyHkbGQg1tcBsHLPNca5oykFMk1YDg4yYtz0C3irEhggxr1GuL X-Received: by 2002:a05:6808:1289:b0:3a8:443b:d87b with SMTP id a9-20020a056808128900b003a8443bd87bmr5716600oiw.34.1695562690574; Sun, 24 Sep 2023 06:38:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695562690; cv=none; d=google.com; s=arc-20160816; b=kA/wBujyMBZ2k4+22fwz6cMIB2sOY/DiYWnGxHc6fhQGIm3hx7FY8Upidlfmv2y5Ey l+yTLiUZ1/Pf2vEag86mY3Baf4QwIdf8enP+971cLpJKFP4DqblXB3NZ7qRIsDm4uDP7 xbHYuRUa9cF1K9FzhvdUfrHhhB0e5tI/3wGyjoLA5MEQhzXHumt3hhPg/kQYHwAC+e9C +wsymFrADu5fTHfVCo8NfeQWz5/a+NSS6mLTTt7epbTVX5oB5VvofR3TKjR+ycgZy8vt v5rswOvZSXIkB7hdIr1pk/htaMOH771+uq5QYuOu90NErQoLWy+vkXVzPHoPxuZvosCH eCKg== 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:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id bk13-20020a056a02028d00b00582f2161cb4si291179pgb.300.2023.09.24.06.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Sep 2023 06:38:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; 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:5 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 groat.vger.email (Postfix) with ESMTP id 8E34B80298A1; Sun, 24 Sep 2023 06:38:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230148AbjIXNiI (ORCPT + 99 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Sun, 24 Sep 2023 06:38:07 -0700 (PDT) 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.