From patchwork Fri Apr 28 09:51:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 88575 Return-Path: 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 + 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 ); 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" To: linux-kernel@vger.kernel.org Cc: "Thomas Garnier" , "Lai Jiangshan" , "Kees Cook" , "Hou Wenlong" , "Steven Rostedt" , "Masami Hiramatsu" , "Mark Rutland" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "H. Peter Anvin" , 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: References: MIME-Version: 1.0 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: 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?= Change the assembly code to use only relative references of symbols for the kernel to be PIE compatible. Signed-off-by: Hou Wenlong Cc: Thomas Garnier Cc: Lai Jiangshan Cc: Kees Cook --- 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