Message ID | b53a0e6996f35e8cc5b216a174ec2b3c58e30860.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 b10csp824178vqo; Fri, 28 Apr 2023 03:17:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5HzkGmiVS/SetraPwcoW/b0Xw3T5rbDxo4yoAkpZNol4bLFM1BpFb7bpNM5SRcKpxTo+5O X-Received: by 2002:a05:6a21:398e:b0:f0:6aaf:1abf with SMTP id ad14-20020a056a21398e00b000f06aaf1abfmr5901916pzc.4.1682677043491; Fri, 28 Apr 2023 03:17:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682677043; cv=none; d=google.com; s=arc-20160816; b=nf4Pm9HK3tQjDbddv+8x83eN0FN4Z6W9EuYu68JbzDVn5rJSaGJt6gGG6/6K3Lg/pF RJu6slXCLRX1hO+NrbjFomgr7ZyzJatKEIxLdiqWXsyJIXprR8w+Fj7Y9WZchziIggvo FxnRS1WuAX4hRCGdvWzxUZ0IIFOZsKvBzPQEZfsE3q1JJp6gqKkJ/ieb+WmlJ0SOYtpO rhvRURxP5MLu+mzxQk9+sckqVwnk641Ml/OLPlUPZPHfSp/L/CFxEeehWQm9+jctb5zS SXNrNx0TNhQ5OiBWJ2epcvTwLg6jW4PNG+wj9KH+1P2ezFxHVt2WKy5ft6zpPg2x+XHX jrFQ== 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=BpdtSE05DbOZZ0btNTmC6i8q/9pqNl0eZ1fSGDvAIQA=; b=dR1sdJ36jRMzfAZJ4QiokJYj3vj7EGQmZ+HXRlnxu2SFQJ2sH3g4t/C2zIkHyJwnMS Aq0jYEJi1fjCOPffOU10olbw05nwxUpzqWpAsFSSx/tSxRHXWdZ2bduH6JlFyjs5Id0A RYbjwrHtYlXE62PlQGTLyW5RYAD3/4xipzLbXdGuFXT1k+w3rf3sm8Q7zrm+HaD62VP4 5FVsOaxmt2dFpRkXWqIpZfyjGdw15MQ5uj6XgSkJrMRd36r1cumXNts+jYVXyR8jHpNX JU1+TOW8n5G8nkQpUbsm8RxQ/Jc5m+RZ/Xk3gEuOS/Y5SUQDh8KUIgTaabia/lku5C+e 1s8w== 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 c25-20020a631c19000000b00503355255cdsi16278307pgc.488.2023.04.28.03.17.08; Fri, 28 Apr 2023 03:17:23 -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 S1345863AbjD1KB5 (ORCPT <rfc822;chrisjones.unixmen@gmail.com> + 99 others); Fri, 28 Apr 2023 06:01:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345847AbjD1KBc (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 28 Apr 2023 06:01:32 -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 9875944AB for <linux-kernel@vger.kernel.org>; Fri, 28 Apr 2023 03:01:06 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047198;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=16;SR=0;TI=SMTPD_---.STDfsHv_1682675644; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.STDfsHv_1682675644) by smtp.aliyun-inc.com; Fri, 28 Apr 2023 17:54:05 +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>, "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>, "Juergen Gross" <jgross@suse.com>, "Anshuman Khandual" <anshuman.khandual@arm.com>, "Mike Rapoport" <rppt@kernel.org>, "Josh Poimboeuf" <jpoimboe@kernel.org>, "Pasha Tatashin" <pasha.tatashin@soleen.com> Subject: [PATCH RFC 40/43] x86/boot: Fill kernel image puds dynamically Date: Fri, 28 Apr 2023 17:51:20 +0800 Message-Id: <b53a0e6996f35e8cc5b216a174ec2b3c58e30860.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?1764414763318524115?= X-GMAIL-MSGID: =?utf-8?q?1764414763318524115?= |
Series |
x86/pie: Make kernel image's virtual address flexible
|
|
Commit Message
Hou Wenlong
April 28, 2023, 9:51 a.m. UTC
For PIE kernel, it could be randomized in any address. Later, kernel
image would be moved down the top 2G, so fille kernel image puds
dynamically.
Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com>
Cc: Thomas Garnier <thgarnie@chromium.org>a
Cc: Lai Jiangshan <jiangshan.ljs@antgroup.com>
Cc: Kees Cook <keescook@chromium.org>
---
arch/x86/kernel/head64.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 8295b547b64f..c5cd61aab8ae 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -239,8 +239,18 @@ unsigned long __head __startup_64(unsigned long physaddr, } pud = fixup_pointer(&level3_kernel_pgt, physaddr); - pud[510] += load_delta; - pud[511] += load_delta; + if (IS_ENABLED(CONFIG_X86_PIE)) { + pud[510] = 0; + pud[511] = 0; + + i = pud_index(text_base); + pgtable_flags = _KERNPG_TABLE_NOENC - __START_KERNEL_map + load_delta; + pud[i] = pgtable_flags + SYM_ABS_VAL(level2_kernel_pgt); + pud[i + 1] = pgtable_flags + SYM_ABS_VAL(level2_fixmap_pgt); + } else { + pud[510] += load_delta; + pud[511] += load_delta; + } pmd = fixup_pointer(level2_fixmap_pgt, physaddr); for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--)