Message ID | 0092ce94b325ad8eb47ff4f95e012f9af1a127de.1682673543.git.houwenlong.hwl@antgroup.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp823567vqo; Fri, 28 Apr 2023 03:16:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+D+w+7iVo8ePSq3djg9bhl+WkfEmT2eOeyr4xDp5/ohw0oGq7rFoYIKDPCORn6axwBRnY X-Received: by 2002:a17:90b:4d86:b0:247:af63:483 with SMTP id oj6-20020a17090b4d8600b00247af630483mr4657725pjb.46.1682676964028; Fri, 28 Apr 2023 03:16:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682676964; cv=none; d=google.com; s=arc-20160816; b=kHVkH4SNX48lRjVaWCSMTwHzvLVNWhikGc9+avi1IO20imZrTZOjAMl/kme9VVHuJ9 XX1nrPHWiLJmphJ+9btKq1PFtg2ViXLtrJXV3DwtEetp+U3ZlNL8rTHFN/hAO0OPfpBn a62+ZQzmGVwnezMDpc/i4uAeMH85eKkAowB5EP7UZRV+XZPraRg9DZtLicUU71Gti2qK Hvt/SHfL1acHrcxO3boGrebGcy9lKpHGQGuTCh/dDhVekq6CvXBknSsdwXjx62w3TzEy TTTj7GSMc0pNJIaA7NpXNXKLRj9/WYtFcQkpzA+D4e8d4+I0T56aF9kNKlpkOZcPvAhi 1N+A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=isBkn1tLNfql1GLqc9X8doCnxzEXWQyuL3aVxGfq4tY=; b=0MyEiSom0OZFnm6OupJEmD2LbV7YP9L4zJwBPydP4/l44Bdqf+LqBYPJl2HQM3V7Uq tumGBSqEr9VtPn0WUPhr8+hYIQWim7mUeGxrvdGS9xCmH9XDLeTTHfs7SbliE7/xPku/ zhtkgo5J/1VDuOgOlwOWMHNnKMneF63xWswA05jxaomDxe+T/O52uXCjCTch/gXuEK6i nuvQqPgKzUSOeUhX4xNJcqImsQRaFitOQqWyHe+eWJRUb97a7IXVxr1zkH/0oFWtQVU9 qSw8sclm7F5u6sgzKiWHwiSRRWfSkiDc8IJ9WwMMukaq98tzKBtKMg+DeJP7qYhgUa31 /E/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id il13-20020a17090b164d00b0023418ec51f8si26331178pjb.136.2023.04.28.03.15.47; Fri, 28 Apr 2023 03:16:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345832AbjD1JzB (ORCPT <rfc822;chrisjones.unixmen@gmail.com> + 99 others); Fri, 28 Apr 2023 05:55:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345886AbjD1Jyv (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Apr 2023 05:54:51 -0400 Received: from out187-3.us.a.mail.aliyun.com (out187-3.us.a.mail.aliyun.com [47.90.187.3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36E0D5593; Fri, 28 Apr 2023 02:54:24 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047201;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---.STDfs4A_1682675577; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.STDfs4A_1682675577) by smtp.aliyun-inc.com; Fri, 28 Apr 2023 17:52:58 +0800 From: "Hou Wenlong" <houwenlong.hwl@antgroup.com> To: linux-kernel@vger.kernel.org Cc: "Thomas Garnier" <thgarnie@chromium.org>, "Lai Jiangshan" <jiangshan.ljs@antgroup.com>, "Kees Cook" <keescook@chromium.org>, "Hou Wenlong" <houwenlong.hwl@antgroup.com>, "Steven Rostedt" <rostedt@goodmis.org>, "Masami Hiramatsu" <mhiramat@kernel.org>, "Mark Rutland" <mark.rutland@arm.com>, "Thomas Gleixner" <tglx@linutronix.de>, "Ingo Molnar" <mingo@redhat.com>, "Borislav Petkov" <bp@alien8.de>, "Dave Hansen" <dave.hansen@linux.intel.com>, <x86@kernel.org>, "H. Peter Anvin" <hpa@zytor.com>, <linux-trace-kernel@vger.kernel.org> Subject: [PATCH RFC 21/43] x86/ftrace: Adapt assembly for PIE support Date: Fri, 28 Apr 2023 17:51:01 +0800 Message-Id: <0092ce94b325ad8eb47ff4f95e012f9af1a127de.1682673543.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <cover.1682673542.git.houwenlong.hwl@antgroup.com> References: <cover.1682673542.git.houwenlong.hwl@antgroup.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764414680489788045?= X-GMAIL-MSGID: =?utf-8?q?1764414680489788045?= |
Series |
x86/pie: Make kernel image's virtual address flexible
|
|
Commit Message
Hou Wenlong
April 28, 2023, 9:51 a.m. UTC
Change the assembly code to use only relative references of symbols for
the kernel to be PIE compatible.
Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
Cc: Thomas Garnier <thgarnie@chromium.org>
Cc: Lai Jiangshan <jiangshan.ljs@antgroup.com>
Cc: Kees Cook <keescook@chromium.org>
---
arch/x86/kernel/ftrace_64.S | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
Comments
On Fri, 28 Apr 2023 17:51:01 +0800 "Hou Wenlong" <houwenlong.hwl@antgroup.com> wrote: > Change the assembly code to use only relative references of symbols for > the kernel to be PIE compatible. > > Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> > Cc: Thomas Garnier <thgarnie@chromium.org> > Cc: Lai Jiangshan <jiangshan.ljs@antgroup.com> > Cc: Kees Cook <keescook@chromium.org> > --- > arch/x86/kernel/ftrace_64.S | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S > index eddb4fabc16f..411fa4148e18 100644 > --- a/arch/x86/kernel/ftrace_64.S > +++ b/arch/x86/kernel/ftrace_64.S > @@ -315,7 +315,14 @@ STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller) > SYM_FUNC_START(__fentry__) > CALL_DEPTH_ACCOUNT > > +#ifdef CONFIG_X86_PIE > + pushq %r8 > + leaq ftrace_stub(%rip), %r8 > + cmpq %r8, ftrace_trace_function(%rip) > + popq %r8 > +#else > cmpq $ftrace_stub, ftrace_trace_function > +#endif > jnz trace > RET > > @@ -329,7 +336,7 @@ trace: > * ip and parent ip are used and the list function is called when > * function tracing is enabled. > */ > - movq ftrace_trace_function, %r8 > + movq ftrace_trace_function(%rip), %r8 > CALL_NOSPEC r8 > restore_mcount_regs > I really don't want to add more updates to !DYNAMIC_FTRACE. This code only exists to make sure I don't break it for other architectures. How about diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 442eccc00960..ee4d0713139d 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -37,7 +37,7 @@ config X86_64 config FORCE_DYNAMIC_FTRACE def_bool y - depends on X86_32 + depends on X86_32 || X86_PIE depends on FUNCTION_TRACER select DYNAMIC_FTRACE help ? -- Steve
On Fri, Apr 28, 2023 at 09:37:19PM +0800, Steven Rostedt wrote: > On Fri, 28 Apr 2023 17:51:01 +0800 > "Hou Wenlong" <houwenlong.hwl@antgroup.com> wrote: > > > Change the assembly code to use only relative references of symbols for > > the kernel to be PIE compatible. > > > > Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> > > Cc: Thomas Garnier <thgarnie@chromium.org> > > Cc: Lai Jiangshan <jiangshan.ljs@antgroup.com> > > Cc: Kees Cook <keescook@chromium.org> > > --- > > arch/x86/kernel/ftrace_64.S | 9 ++++++++- > > 1 file changed, 8 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S > > index eddb4fabc16f..411fa4148e18 100644 > > --- a/arch/x86/kernel/ftrace_64.S > > +++ b/arch/x86/kernel/ftrace_64.S > > @@ -315,7 +315,14 @@ STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller) > > SYM_FUNC_START(__fentry__) > > CALL_DEPTH_ACCOUNT > > > > +#ifdef CONFIG_X86_PIE > > + pushq %r8 > > + leaq ftrace_stub(%rip), %r8 > > + cmpq %r8, ftrace_trace_function(%rip) > > + popq %r8 > > +#else > > cmpq $ftrace_stub, ftrace_trace_function > > +#endif > > jnz trace > > RET > > > > @@ -329,7 +336,7 @@ trace: > > * ip and parent ip are used and the list function is called when > > * function tracing is enabled. > > */ > > - movq ftrace_trace_function, %r8 > > + movq ftrace_trace_function(%rip), %r8 > > CALL_NOSPEC r8 > > restore_mcount_regs > > > > I really don't want to add more updates to !DYNAMIC_FTRACE. This code only > exists to make sure I don't break it for other architectures. > > How about > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > index 442eccc00960..ee4d0713139d 100644 > --- a/arch/x86/Kconfig > +++ b/arch/x86/Kconfig > @@ -37,7 +37,7 @@ config X86_64 > > config FORCE_DYNAMIC_FTRACE > def_bool y > - depends on X86_32 > + depends on X86_32 || X86_PIE > depends on FUNCTION_TRACER > select DYNAMIC_FTRACE > help > > > ? > OK, I'll drop it. Actually, I select DYNAMIC_FTRACE when CONFIG_RETPOLINE is enabled for PIE due to the indirect call for __fentry__() in patch 34. Thanks. > -- Steve
diff --git a/arch/x86/kernel/ftrace_64.S b/arch/x86/kernel/ftrace_64.S index eddb4fabc16f..411fa4148e18 100644 --- a/arch/x86/kernel/ftrace_64.S +++ b/arch/x86/kernel/ftrace_64.S @@ -315,7 +315,14 @@ STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller) SYM_FUNC_START(__fentry__) CALL_DEPTH_ACCOUNT +#ifdef CONFIG_X86_PIE + pushq %r8 + leaq ftrace_stub(%rip), %r8 + cmpq %r8, ftrace_trace_function(%rip) + popq %r8 +#else cmpq $ftrace_stub, ftrace_trace_function +#endif jnz trace RET @@ -329,7 +336,7 @@ trace: * ip and parent ip are used and the list function is called when * function tracing is enabled. */ - movq ftrace_trace_function, %r8 + movq ftrace_trace_function(%rip), %r8 CALL_NOSPEC r8 restore_mcount_regs