From patchwork Wed Nov 8 14:28:23 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: 163055 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:aa0b:0:b0:403:3b70:6f57 with SMTP id k11csp950471vqo; Wed, 8 Nov 2023 06:29:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeGULPAwSZJjnkOKnn0k1i/AZ6DXdE5p1ugWV1cg94HL994kb0V9lHWvu0fO8kx6UB8GYF X-Received: by 2002:a05:6a20:7352:b0:181:6f91:efe with SMTP id v18-20020a056a20735200b001816f910efemr2180966pzc.19.1699453778025; Wed, 08 Nov 2023 06:29:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699453778; cv=none; d=google.com; s=arc-20160816; b=xy3zdnllGvmNEnsKFdZzHnAc7IMaDOMKceEaPu3/Ib4N32y1hmG0+TkTjlK32hXpRX W8eVzENymf2bCtMStOc34VhB8YU4xRlEjkx6KtU2Fs1mYcT9LYf2Bqr+9HG3YYi8ASlN 68E51/G/BmxMStYZsB+T6sz7lD8GhA3s5/fZDMDL9ED8RJEg/pErUWBM8vqpxhdqYH3K VDWuFwBCJmcoeMIYBFSzJgJWFljR38hlprWiIV299xPxyaA1PK/2INBXfvjbVvJfyxVA OzgeEDrSzjD95eZcNUhwqmSUGlTWBTBFtwzeFS3DTDKS/anc2813HQGgTBnn8WufB91t w0PQ== 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=HORBnO/i80DFeqiJ6regmn9dF9RfhznkF2yqPCT6krk=; fh=SIgps5XdV0XNwjZfT2uAI7g3mrspDldK9Qs8qQAfoa4=; b=mTxjGRa6UGNKPIqH6yOg3R5aM7e80uRkDV+9NEOgscHk30aXrUbOYLPlLkKrhIg2hB pQigDvyMIPKeFFqwebPjS5wyxQ39KHTNicGwkRhjgbVheUEJ04UnRwELZirx/6OH0DLt iPlJLq3zdwRtrAQUVbsE0WQoKWZ0rldRLr9cbuUkK8OTei0oBXW/ATyA4AJUod3mC74R 7P0ExBgBLVdfD87ydIZzwKFEJZakbHMY6YO+dwxie3p3AsMXusIeDBVvc0hPWi/GVI8P d13XyuIFcI0ULZVAgOgiYEmzGNDVEhaYa4V/FJpC6myNbyM55MBe/4DWQxsFW6xfa3yC Bj+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=eBc2p8Oo; 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 r15-20020aa78b8f000000b006bdf2250a36si12016127pfd.353.2023.11.08.06.29.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Nov 2023 06:29:38 -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=eBc2p8Oo; 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 1B9A081DC614; Wed, 8 Nov 2023 06:29:32 -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 S1343736AbjKHO3B (ORCPT + 32 others); Wed, 8 Nov 2023 09:29:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235399AbjKHO2g (ORCPT ); Wed, 8 Nov 2023 09:28:36 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C3E3213B for ; Wed, 8 Nov 2023 06:28:29 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A424C433C8; Wed, 8 Nov 2023 14:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699453709; bh=G3M7rbLjDgrYIoVpHOxqlUDZWOOF6wiqlb0+xA/Zo8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eBc2p8Oovhos6kzYacPKsTG2cNxhxOf8Zc9rKcUW5GN5AHQLo8RjtjINvAETh0q6G 7L1hdzBjsdJUvpWoFoOqRFMth+slPDl0CKH39BBf7/lrTNEp7Q13ZI/MWjqIH7gv1l 6orjGNmYalsNsgRNFjwA5tGGGGgPHXRAsvATWYc3TOhGgGoh2+mMrpi4cTJRNyfX/L /8f1wRO2HxRUua3LjREkEPer52K25ScmIJJdCxQ8LMhBUNwihl14mMdDIRr02KoM9Z g81tT2GZ9RBIYxEQZNc+Dk8Epnkrb0xZBu2A45FMsu/yBCTFAH/CyHSR/NCAHlj7t/ FquFR4zRAVsCw== 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 21/31] x86/ftrace: Enable HAVE_FUNCTION_GRAPH_FREGS Date: Wed, 8 Nov 2023 23:28:23 +0900 Message-Id: <169945370304.55307.2480628822573420604.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:29:32 -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: 1782006445082831243 X-GMAIL-MSGID: 1782006445082831243 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) --- Changes in v2: - Save rsp register and drop clearing orig_ax. --- arch/x86/Kconfig | 3 ++- arch/x86/kernel/ftrace_64.S | 36 ++++++++++++++++++++++++++++-------- 2 files changed, 30 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..029b0e3a0206 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -348,21 +348,41 @@ STACK_FRAME_NON_STANDARD_FP(__fentry__) SYM_CODE_START(return_to_handler) UNWIND_HINT_UNDEFINED ANNOTATE_NOENDBR - subq $24, %rsp + /* + * Save the registers requires for ftrace_regs; + * rax, rcx, rdx, rdi, rsi, r8, r9 and rbp + */ + 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 %rbp, RBP(%rsp) + /* + * orig_ax is not cleared because it is used for indicating the direct + * trampoline in the fentry. + */ + + leaq FRAME_SIZE(%rsp), %rcx + movq %rcx, RSP(%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