From patchwork Sun Nov 5 16:11:21 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: 161681 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2198314vqu; Sun, 5 Nov 2023 08:12:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IHRgUZo5HDXxBJkMZpWni+BmsLqYjAYUqfULFBRPvETdvGz3UqKK4TW0/iBl2S/WKQ4iYcC X-Received: by 2002:a05:6602:2e0a:b0:79f:da3d:c47f with SMTP id o10-20020a0566022e0a00b0079fda3dc47fmr35412425iow.13.1699200724348; Sun, 05 Nov 2023 08:12:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699200724; cv=none; d=google.com; s=arc-20160816; b=PeNOiw/OuIVovyWEUJJQdxXJekKMg2ptJ7zQp1XRln2oqx/hvI6jUTIY3uUuFSII+C 1dMIN3Pjhgjh8L5hbXTpLBE9As2KQ/lor8QIMNgS3ocwtRBJ2s5phCWJykVYspb2Ao/C PAWyAveGVxv4g9g9CGkmbQ/EIICdEeyCed1ClAi5AM+SVDZBkETbpjtrChK/Dn0VESaY DLRcso/aQsgBWpDVY8a4YIsPDN4OzGf3E0uWmWqDvsNTSbzT5Q3zosAFOO2dLGL04OEy sZP0vxptdqkcdBPZ2+rTIAjHUrdKd5ZjdBdkocUgi/r2QHLiexAPKl9P4/tLa3nMIsfX ihbQ== 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=ypeCKydyuVrJMXXG3zrJT9IZ2I/o5mVj+aArxSLXgc4=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=AsO2OjTvCcyPDnwAYQKmgWktUxTGiHUgSlv2GB/ystBcJxI1G3sffymrTZl1fgwf7I 4UTrUxjV+bbuDKCiU5xiwTIKmBWqcUPv3YmB2eMtXf+5yB1LlmQvmQpruX7fX40yP9uK UQSzVip6DW5V7INWovFlKAdf4Q4+dC9CEIMH4pBAjGzqNjgrEa+jHgs5etXHcnRx8rBx Lnk+U70aGkagTG1XMcfS4w7tZijxIs4T5+N43ALbiSpxRnhasu/W8ei67mYnj+duuIVk pjtkTCZVBZI2dM1sR3qCCwynfK0WCN+EK5FOvvU+J+OhAXpBU8ye8mCQ6ulGUwxs9FRN KlDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Q5tYib6A; 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id i26-20020aa787da000000b00690ba709d02si5949396pfo.381.2023.11.05.08.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Nov 2023 08:12:04 -0800 (PST) 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=Q5tYib6A; 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 2CB29808D29E; Sun, 5 Nov 2023 08:11:57 -0800 (PST) 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 S229549AbjKEQLi (ORCPT + 34 others); Sun, 5 Nov 2023 11:11:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229893AbjKEQLa (ORCPT ); Sun, 5 Nov 2023 11:11:30 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32B19D61 for ; Sun, 5 Nov 2023 08:11:28 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B17FAC433C7; Sun, 5 Nov 2023 16:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699200687; bh=6GBLrBVom66jXJpUAXFDmsg+lvD8A70XktPU9o8fCJA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q5tYib6AKnSqhWsonloeJknpIvRW9fg3a+vNV71bChclAFYAYNRfWrO+MILCIcRpm 9JnCBUK/LFtRP+NJDxXpJqF71Vc7FTYssu9PmodHCpcyTaYx6srLQH7UcWrqkFtWUl R+Omc3GTxTMctRyBIwDdrCcDFNjbDpM+9p/7WFpcKHT116znYOD6sjIOLNpyfscsUl jaCntjjwMs2D2xtms6ZEAlAZjN1yPT9PwZ0AtgnooGw2PYgaCZQ3MsPZ/UOtAahxzX co+yneulf26eGDWF3flL5b/ZoPTQSdMRGjXN7tcqRqJXfZz0jinRYh+ge68PdKAOiA aJY0VKMZ5iJhg== 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 24/32] x86/ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Date: Mon, 6 Nov 2023 01:11:21 +0900 Message-Id: <169920068069.482486.6540417903833579700.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=-1.8 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 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, 05 Nov 2023 08:11:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781741098372018673 X-GMAIL-MSGID: 1781741098372018673 From: Masami Hiramatsu (Google) Support HAVE_FUNCTION_GRAPH_FREGS on x86-64, which saves ftrace_regs on the stack in ftrace_graph return trampoline so that the callbacks can access registers via ftrace_regs APIs. Note that this only recovers 'rax' and 'rdx' registers because other registers are not used anymore and recovered by caller. 'rax' and 'rdx' will be used for passing the return value. Signed-off-by: Masami Hiramatsu (Google) --- arch/x86/Kconfig | 3 ++- arch/x86/kernel/ftrace_64.S | 30 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 66bfabae8814..4b4c2f9d67da 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -219,7 +219,8 @@ config X86 select HAVE_FAST_GUP select HAVE_FENTRY if X86_64 || DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD - select HAVE_FUNCTION_GRAPH_RETVAL if HAVE_FUNCTION_GRAPH_TRACER + select HAVE_FUNCTION_GRAPH_FREGS if HAVE_DYNAMIC_FTRACE_WITH_ARGS + select HAVE_FUNCTION_GRAPH_RETVAL if !HAVE_DYNAMIC_FTRACE_WITH_ARGS select HAVE_FUNCTION_GRAPH_TRACER if X86_32 || (X86_64 && DYNAMIC_FTRACE) select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index 945cfa5f7239..41351a621753 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -348,21 +348,35 @@ STACK_FRAME_NON_STANDARD_FP(__fentry__) SYM_CODE_START(return_to_handler) UNWIND_HINT_UNDEFINED ANNOTATE_NOENDBR - subq $24, %rsp + /* + * We add enough stack to save all regs, but saves only registers + * for function params. + */ + subq $(FRAME_SIZE), %rsp + movq %rax, RAX(%rsp) + movq %rcx, RCX(%rsp) + movq %rdx, RDX(%rsp) + movq %rsi, RSI(%rsp) + movq %rdi, RDI(%rsp) + movq %r8, R8(%rsp) + movq %r9, R9(%rsp) + movq $0, ORIG_RAX(%rsp) + movq %rbp, RBP(%rsp) - /* Save the return values */ - movq %rax, (%rsp) - movq %rdx, 8(%rsp) - movq %rbp, 16(%rsp) movq %rsp, %rdi call ftrace_return_to_handler movq %rax, %rdi - movq 8(%rsp), %rdx - movq (%rsp), %rax - addq $24, %rsp + /* + * Restore only rax and rdx because other registers are not used + * for return value nor callee saved. Caller will reuse/recover it. + */ + movq RDX(%rsp), %rdx + movq RAX(%rsp), %rax + + addq $(FRAME_SIZE), %rsp /* * Jump back to the old return address. This cannot be JMP_NOSPEC rdi * since IBT would demand that contain ENDBR, which simply isn't so for