From patchwork Wed Jul 12 03:30:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 118796 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp889287vqm; Tue, 11 Jul 2023 20:41:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlHHg75XtMUpe3rOiV4c/7sEvyzcdd6r710IhPjuT8WnKPGUG/G/zSbgg+bFSjNq6cNc3jBu X-Received: by 2002:a17:907:8186:b0:983:ba44:48af with SMTP id iy6-20020a170907818600b00983ba4448afmr15404297ejc.53.1689133286762; Tue, 11 Jul 2023 20:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689133286; cv=none; d=google.com; s=arc-20160816; b=x57oO57Rr2j45ETHMaJxihX1pKhL4OkadAuuYc/mS0/88AyTA4WL+VeibnHht62kFg Joz+HTxHKVuyyxBpTboqw3+A49DairN9zV6zThrB8FLJ/ANICyQ605N9SWZTN+XVKBe/ MiwDNymSR4E00GNWWLqP8Imk3Wv6A2CLpw1sRgDWtYcYe6uME9HWnY5D4h5WdMjXQi5e yd8fEzfFq3kGurAPFYsRS6YhQBzPckBfupiCUucPZlXWMGe47yfO/Tk3Rjklz0KJKpEk 4rXgSCe2Bd6VvtpfFj+1l/xnOY4/gewiPiBp7WCu8VEvJBMiRS++4GZv4fuAayLCBEMc UE/g== 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=gqqTT4QCfa6L3lWH/ZJ9TDK+7cjlkDZowSBlDkgFYzo=; fh=H+xol+m9/22gljVAiQKilKMt6BHHgyiL3H+/V9q01Lk=; b=vUOzc0/pBMX7OBmlVzRi3BnbgkRm4zmA+cFUT+Rq4hcDHaMVjje33nf/Km5h2DA/9c vqvbfoB3nOVm3Houz2r3hwwjcjMw+5qWFaceJPeOlOSwwwxqTDO5a/Ybh8f7u9IT8dXO h/ybwzi4Rq7Sfy7CyTZ6UWfcIB8HL+E8/L6J/iTA+toGoGWbSXxam8BWfHnAwr53vwIs MknHN8Ls+MhGGhta0snrfJiGwVnEHOW75fq8lWsvas6IA00/SPAHOMkbU5Y7S4rbMT6+ 95V8UJB2Ot5FRbjM5FS/g6aSm4YQ8asgngFLz2lFXgMpzIow+9SB4zp7bKfQ1vXPMjnD 6csg== 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 p2-20020a170906140200b009591dd6c71esi3168518ejc.896.2023.07.11.20.41.01; Tue, 11 Jul 2023 20:41:26 -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 S230254AbjGLDbY (ORCPT + 99 others); Tue, 11 Jul 2023 23:31:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbjGLDbU (ORCPT ); Tue, 11 Jul 2023 23:31:20 -0400 Received: from out0-201.mail.aliyun.com (out0-201.mail.aliyun.com [140.205.0.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97704E5F for ; Tue, 11 Jul 2023 20:31:19 -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=ay29a033018047206;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---.TrdHwby_1689132672; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.TrdHwby_1689132672) by smtp.aliyun-inc.com; Wed, 12 Jul 2023 11:31:13 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Lai Jiangshan" , "Hou Wenlong" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , " =?utf-8?q?maintainer=3AX86_A?= =?utf-8?q?RCHITECTURE_32-BIT_AND_64-BIT?= " , "H. Peter Anvin" , "Josh Poimboeuf" , "Anshuman Khandual" , "Mike Rapoport" , "Pasha Tatashin" Subject: [PATCH RFC 1/7] x86/head/64: Mark startup_gdt and startup_gdt_descr as __initdata Date: Wed, 12 Jul 2023 11:30:05 +0800 Message-Id: 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, RCVD_IN_DNSWL_BLOCKED,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: INBOX X-GMAIL-THRID: 1771184625265233636 X-GMAIL-MSGID: 1771184625265233636 As startup_gdt and startup_gdt_descr are only used in booting, make them as __initdata to allow them to be freed after boot. Signed-off-by: Hou Wenlong --- arch/x86/kernel/head64.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index 49f7629b17f7..dd357807ffb5 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -69,7 +69,7 @@ EXPORT_SYMBOL(vmemmap_base); /* * GDT used on the boot CPU before switching to virtual addresses. */ -static struct desc_struct startup_gdt[GDT_ENTRIES] = { +static struct desc_struct startup_gdt[GDT_ENTRIES] __initdata = { [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff), [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff), [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff), @@ -79,7 +79,7 @@ static struct desc_struct startup_gdt[GDT_ENTRIES] = { * Address needs to be set at runtime because it references the startup_gdt * while the kernel still uses a direct mapping. */ -static struct desc_ptr startup_gdt_descr = { +static struct desc_ptr startup_gdt_descr __initdata = { .size = sizeof(startup_gdt), .address = 0, }; From patchwork Wed Jul 12 03:30:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 118797 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp889936vqm; Tue, 11 Jul 2023 20:43:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlEDIP6x6cV/kDLUJTvpQO99qpTecL24DLDxJDiFHJiIfYZi2jfIBqXrpEWtSHFWIJtsK6Hp X-Received: by 2002:a17:906:198:b0:97e:17cc:cc95 with SMTP id 24-20020a170906019800b0097e17cccc95mr939147ejb.36.1689133405123; Tue, 11 Jul 2023 20:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689133405; cv=none; d=google.com; s=arc-20160816; b=o5lfKu85W+FKzK+eAZL/lEBTVRh85er7n2Bv0kI3mqR78MQSqxj36yT1Ne/Kodm9Tv njZ7tqlcCBOXEKlheBAAA7Hx+r/35j/S1onPc0Bbd5eWCLQo2rNhhdHUPRU1tgCSDArx bUUSP1KH785mxuZB60PToqz1JJyGMknMjRsKqX/sYznSHxeNlGXOUSZh06OjB/ILngHz FTARUesjGa5BhCQx7yc73Rd7iOirX9xefKMAZHYzQdeecRKfPDJijnBIJVTHmil07Pq4 M6A3KqlQZrp5/XnSznGVgdUSHTq3YE3VKlLt3A/TRLRzJdPdErFBYtMaCw0pm4x1Hlrn qeVA== 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=IaoklsihpDsBuHcsyx3jZ7HlSLTZPfM4KhOkH70o93E=; fh=H+xol+m9/22gljVAiQKilKMt6BHHgyiL3H+/V9q01Lk=; b=zFifVn2jj3dTbXh5pokrl4SIAZpvlbuzo1lXimdPymOWMhSd3mt+ZztBBrOaRTBwvO 8fnfQFJAhadg/9v6qVOiRU4x7qBNFCMFMIps/jpbKWmGNOvQ1ILFf65SGSLd1z30qpFM SmsAE9ADEMmMbZZuF7PUEdWAhcQNe5RU8rpPR+pABtAU7l9uv4OaynTVV/dhKEkvTjYj gJB8ZOB2vSGERQSy/x+iJIMeqA/d91ubtkY6DyUm/B22ksuLgNJ6Ol+iZtU9gcQ5GFBU LoOqjE2+egCStzTVv9z+q4IKsb4NUkj061PMXi/5zVRL1cEYeMSVOWdUOV8OMfGUJAEW 8eyw== 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 i13-20020a170906264d00b00993860a6d38si3712465ejc.314.2023.07.11.20.43.02; Tue, 11 Jul 2023 20:43:25 -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 S231741AbjGLDbc (ORCPT + 99 others); Tue, 11 Jul 2023 23:31:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231494AbjGLDbZ (ORCPT ); Tue, 11 Jul 2023 23:31:25 -0400 Received: from out0-195.mail.aliyun.com (out0-195.mail.aliyun.com [140.205.0.195]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67663E5F for ; Tue, 11 Jul 2023 20:31:24 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R431e4;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=13;SR=0;TI=SMTPD_---.TrdQGkX_1689132675; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.TrdQGkX_1689132675) by smtp.aliyun-inc.com; Wed, 12 Jul 2023 11:31:16 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Lai Jiangshan" , "Hou Wenlong" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , " =?utf-8?q?maintainer=3AX86_A?= =?utf-8?q?RCHITECTURE_32-BIT_AND_64-BIT?= " , "H. Peter Anvin" , "Josh Poimboeuf" , "Anshuman Khandual" , "Mike Rapoport" , "Pasha Tatashin" Subject: [PATCH RFC 2/7] x86/head/64: Add missing __head annotation to startup_64_load_idt() Date: Wed, 12 Jul 2023 11:30:06 +0800 Message-Id: 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, RCVD_IN_DNSWL_BLOCKED,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: INBOX X-GMAIL-THRID: 1771184749455733302 X-GMAIL-MSGID: 1771184749455733302 This function is currently only used in the head code and is only called from startup_64_setup_env(). Although it would be inlined by the compiler, it would be better to mark it as __head too. Signed-off-by: Hou Wenlong --- arch/x86/kernel/head64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index dd357807ffb5..5066189b00ac 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -588,7 +588,7 @@ static void set_bringup_idt_handler(gate_desc *idt, int n, void *handler) } /* This runs while still in the direct mapping */ -static void startup_64_load_idt(unsigned long physbase) +static void __head startup_64_load_idt(unsigned long physbase) { struct desc_ptr *desc = fixup_pointer(&bringup_idt_descr, physbase); gate_desc *idt = fixup_pointer(bringup_idt_table, physbase); From patchwork Wed Jul 12 03:30:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 118799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp890541vqm; Tue, 11 Jul 2023 20:45:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlGeGvGXelGbBq1DlDS5346i6UL638Bgumfeobysl72R/N92wc+YD+41Sm5fbcgbF5lHhpu/ X-Received: by 2002:a17:906:109c:b0:994:8e9:67fe with SMTP id u28-20020a170906109c00b0099408e967femr7163936eju.35.1689133527031; Tue, 11 Jul 2023 20:45:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689133527; cv=none; d=google.com; s=arc-20160816; b=fAp28pL9zR5CTaMce1HlF2I3JCWjBb4jvKUMG1HaMzK6DpWJYkCwuBKjjbFin/Jl1e 9METjrXEpKFrigaAAFu+1JaSol1LAA0eLhO+TIcrVDIFQUEVF2H6HTzrlACspp8hx1yh QX13gMRFmXtsWbUjnjzv6KbNFzdJqPokkCb1ajDeLDWM9XFQEZjSgdT14P9VW5Yt6F/x Nt1yp5UH5+rDX5sa/NuKkZ352Ggsa00cEq993m8//uNAtbFhJ1QFLauh7Nh5xFwx9Dd3 jkxgpV/TxMsffR9Y6768FnZ40VAHBcpoVGxrzc9AjmGMDpLmUAwBbeWmsVMJVSMZ+G8S Jnng== 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=HzQcwkYZczVd1WZ9LYoiNZFwcf6IYCdYCbv73gqL4tI=; fh=6kcROGYttX7oh1tPSR92G4/yiyin+OdDTUaLuypjG00=; b=dMlj+gz5luxPDEllG7HSrqCc2XMDfP3kQLx1aw7i3FMsIty6onBEVdzZMA+xCY0fRu UhuFNRcKq+MEklN8LFCEg46s8h3eg7hz+4m0BzkbFuEZED9RaU45pta2jTGymSKD/rkY bLM5zZxL9EJX8o+1bKMcEhanLfP/9OWHI9Cb+81F/PFxW0Fyl6TduoFE1K/iD4FVj1EI +GwF/T0SzLjpRjeqA/ZVnSLyAlOxLWm/Dym5hbXXhTedo+bHzCYEojTCR5EfUgB9y4/O NlXfD19S4vj0FufcD/7TYMf8b68QAFvWBjYGjzW8dskqSMjIisoBYgLA3R7rps/y6fFZ U/Tw== 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 lg15-20020a170906f88f00b00992a9bdb0e4si3825647ejb.309.2023.07.11.20.45.04; Tue, 11 Jul 2023 20:45:27 -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 S231767AbjGLDb7 (ORCPT + 99 others); Tue, 11 Jul 2023 23:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231716AbjGLDbs (ORCPT ); Tue, 11 Jul 2023 23:31:48 -0400 Received: from out0-194.mail.aliyun.com (out0-194.mail.aliyun.com [140.205.0.194]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 599F610EF for ; Tue, 11 Jul 2023 20:31:41 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R741e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047208;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---.TrdHwxy_1689132693; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.TrdHwxy_1689132693) by smtp.aliyun-inc.com; Wed, 12 Jul 2023 11:31:34 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Lai Jiangshan" , "Hou Wenlong" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , " =?utf-8?q?maintainer=3AX86_A?= =?utf-8?q?RCHITECTURE_32-BIT_AND_64-BIT?= " , "H. Peter Anvin" , "Nathan Chancellor" , "Ard Biesheuvel" , "Kirill A. Shutemov" , "Nick Desaulniers" , "Petr Pavlu" , "Xin Li" Subject: [PATCH RFC 4/7] x86/boot/compressed: Adapt sed command if head code is built as PIE Date: Wed, 12 Jul 2023 11:30:08 +0800 Message-Id: <0856eaae3439581fdcb7143389ee4cc00859cc9d.1689130310.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, RCVD_IN_DNSWL_BLOCKED,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: INBOX X-GMAIL-THRID: 1771184877068279421 X-GMAIL-MSGID: 1771184877068279421 When x86/head64_identity.c is built as PIE, all symbols would be set as hidden to omit GOT references. According to the generic ABI, a hidden symbol contained in a relocatable object must be either removed or converted to STB_LOCAL binding by the link-editor when the relocatable object is included in an executable file or shared object. Both gold and ld.lld change the binding of a STV_HIDDEND symbol to STB_LOCAL. However, for GNU ld, it will keep the global hidden. The sed command to generate voffset.h only captures global symbols, so an empty voffset.h would be generated with ld.lld. Therefore, local symbols should also be captured in the sed command. Signed-off-by: Hou Wenlong --- arch/x86/boot/compressed/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile index 40d2ff503079..ca57ad0d2d22 100644 --- a/arch/x86/boot/compressed/Makefile +++ b/arch/x86/boot/compressed/Makefile @@ -79,7 +79,7 @@ LDFLAGS_vmlinux += -T hostprogs := mkpiggy HOST_EXTRACFLAGS += -I$(srctree)/tools/include -sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVW] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' +sed-voffset := -e 's/^\([0-9a-fA-F]*\) [ABCDGRSTVWabcdgrstvw] \(_text\|__bss_start\|_end\)$$/\#define VO_\2 _AC(0x\1,UL)/p' quiet_cmd_voffset = VOFFSET $@ cmd_voffset = $(NM) $< | sed -n $(sed-voffset) > $@ From patchwork Wed Jul 12 03:30:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 118809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp902279vqm; Tue, 11 Jul 2023 21:23:41 -0700 (PDT) X-Google-Smtp-Source: APBJJlGBlbfPjNRC3KEeNS7d2E2vU7TNH8c86TG7oVZ8vnj6np41X2fX8L7mH6Gr8P8HnbPCniER X-Received: by 2002:a17:902:b210:b0:1b6:af1a:7dd3 with SMTP id t16-20020a170902b21000b001b6af1a7dd3mr13396934plr.23.1689135821417; Tue, 11 Jul 2023 21:23:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689135821; cv=none; d=google.com; s=arc-20160816; b=NLfYUziDB0FeGDID7CKzf3Gw4G9HpYa4c+PoBpeSnJ1SfDk+SNcLH3jYvnZRPjIS0r F17mN0sdg0wAnZgZzO2OokFxun+DNTTU9A1v6TOyEi6oKnET/2nO1IbEqwGPvtnzcmEo pMW3x9PyiZajSVLjlr0IoM4TvKeUEI6nlmlOFYLUGedxaLY98JUi0pfjX98atUj63hIy nZ0421gyRKLE8o8q2xll6nLLYWmBlxHFaVGJ9oTxoTx0QFJ8Qp9qXRVuTJDBDiJWo7B0 n6bhIKDpChDLIVXEDYL6ltOhCZoH+f0uoq29AJb98svg+Vj6fyN/mrY9TBT9893g8D8D d9ng== 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=gjSH/t6nxB6L1W/+hIitrfuVZjvmhVAl7C1Xyp91/5g=; fh=c+kVa5gq+Ysz2EtwmFAge2QC8JT1Rdt5mFN1u9CTXFg=; b=WmLdifI4FNgTAlSb19LfEZ5Dy9FlO2NqxWzLIjxg9I7MtXBS/Nu1YxlbYuXt8chOYg RagFy/QUh5Q7DlCnsgnmiRpBbgylabZJW/aQdfjIuYqKimxA0Q+gGHLLdCAwHEi/Q2/o z6O7pt8NZVtEdFaVxnwbJfmrncJWnCme+TtbZan/NixfMdgsG9v9yzCjy3/YMSWJIGO2 4ELW30XjPS0EI8L7I4BP8hFZJ28NrCO2tk5neVogGsRmAM6QBHTAyxw1eVTa4MczT/QX 4Lo8uicLwDXAZ8/hsEew0VGUmy3P0sqmyG/jBK+rC+B0brbwGeHeKUpQN1zYNEObuwEA VGzQ== 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 d7-20020a170903230700b001b9e9b21287si2683234plh.427.2023.07.11.21.23.27; Tue, 11 Jul 2023 21:23:41 -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 S231269AbjGLDcV (ORCPT + 99 others); Tue, 11 Jul 2023 23:32:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbjGLDcK (ORCPT ); Tue, 11 Jul 2023 23:32:10 -0400 Received: from out0-222.mail.aliyun.com (out0-222.mail.aliyun.com [140.205.0.222]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 924B91BDC for ; Tue, 11 Jul 2023 20:32:04 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R221e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047211;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---.TrdETkS_1689132717; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.TrdETkS_1689132717) by smtp.aliyun-inc.com; Wed, 12 Jul 2023 11:31:58 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Lai Jiangshan" , "Hou Wenlong" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , " =?utf-8?q?maintainer=3AX86_A?= =?utf-8?q?RCHITECTURE_32-BIT_AND_64-BIT?= " , "H. Peter Anvin" , "Andy Lutomirski" , "Peter Zijlstra" , "Andrew Morton" , "Anshuman Khandual" , "Stephen Rothwell" , "Michael Kelley" , "Arnd Bergmann" , "Mike Rapoport" , "Josh Poimboeuf" , "Pasha Tatashin" Subject: [PATCH RFC 6/7] x86/sme: Mark code as __head in mem_encrypt_identity.c Date: Wed, 12 Jul 2023 11:30:10 +0800 Message-Id: <65bc4576158690453a23699f119d073b227acede.1689130310.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, RCVD_IN_DNSWL_BLOCKED,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: INBOX X-GMAIL-THRID: 1771187283018850198 X-GMAIL-MSGID: 1771187283018850198 The functions sme_enable() and sme_encrypt_kernel() are only called by the head code which runs in identity virtual address. Therefore, it's better to mark them as __head as well. Signed-off-by: Hou Wenlong --- arch/x86/include/asm/init.h | 2 ++ arch/x86/include/asm/mem_encrypt.h | 8 ++++---- arch/x86/kernel/head64_identity.c | 3 +-- arch/x86/mm/mem_encrypt_identity.c | 27 ++++++++++++++------------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/arch/x86/include/asm/init.h b/arch/x86/include/asm/init.h index 5f1d3c421f68..cc9ccf61b6bd 100644 --- a/arch/x86/include/asm/init.h +++ b/arch/x86/include/asm/init.h @@ -2,6 +2,8 @@ #ifndef _ASM_X86_INIT_H #define _ASM_X86_INIT_H +#define __head __section(".head.text") + struct x86_mapping_info { void *(*alloc_pgt_page)(void *); /* allocate buf for page table */ void *context; /* context for alloc_pgt_page */ diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 7f97a8a97e24..7b6616f67398 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -45,8 +45,8 @@ void __init sme_unmap_bootdata(char *real_mode_data); void __init sme_early_init(void); void __init sev_setup_arch(void); -void __init sme_encrypt_kernel(struct boot_params *bp); -void __init sme_enable(struct boot_params *bp); +void sme_encrypt_kernel(struct boot_params *bp); +void sme_enable(struct boot_params *bp); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size); @@ -75,8 +75,8 @@ static inline void __init sme_unmap_bootdata(char *real_mode_data) { } static inline void __init sme_early_init(void) { } static inline void __init sev_setup_arch(void) { } -static inline void __init sme_encrypt_kernel(struct boot_params *bp) { } -static inline void __init sme_enable(struct boot_params *bp) { } +static inline void sme_encrypt_kernel(struct boot_params *bp) { } +static inline void sme_enable(struct boot_params *bp) { } static inline void sev_es_init_vc_handling(void) { } diff --git a/arch/x86/kernel/head64_identity.c b/arch/x86/kernel/head64_identity.c index 93f5831917bc..521fef98cccd 100644 --- a/arch/x86/kernel/head64_identity.c +++ b/arch/x86/kernel/head64_identity.c @@ -19,6 +19,7 @@ #include #include #include +#include extern pmd_t early_dynamic_pgts[EARLY_DYNAMIC_PAGE_TABLES][PTRS_PER_PMD]; extern unsigned int next_early_pgt; @@ -43,8 +44,6 @@ static struct desc_ptr startup_gdt_descr __initdata = { .address = 0, }; -#define __head __section(".head.text") - #ifdef CONFIG_X86_5LEVEL static bool __head check_la57_support(void) { diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index d73aeb16417f..72aeb0f3dec6 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -46,6 +46,7 @@ #include #include #include +#include #include "mm_internal.h" @@ -99,7 +100,7 @@ static char sme_cmdline_arg[] __initdata = "mem_encrypt"; static char sme_cmdline_on[] __initdata = "on"; static char sme_cmdline_off[] __initdata = "off"; -static void __init sme_clear_pgd(struct sme_populate_pgd_data *ppd) +static void __head sme_clear_pgd(struct sme_populate_pgd_data *ppd) { unsigned long pgd_start, pgd_end, pgd_size; pgd_t *pgd_p; @@ -114,7 +115,7 @@ static void __init sme_clear_pgd(struct sme_populate_pgd_data *ppd) memset(pgd_p, 0, pgd_size); } -static pud_t __init *sme_prepare_pgd(struct sme_populate_pgd_data *ppd) +static pud_t __head *sme_prepare_pgd(struct sme_populate_pgd_data *ppd) { pgd_t *pgd; p4d_t *p4d; @@ -151,7 +152,7 @@ static pud_t __init *sme_prepare_pgd(struct sme_populate_pgd_data *ppd) return pud; } -static void __init sme_populate_pgd_large(struct sme_populate_pgd_data *ppd) +static void __head sme_populate_pgd_large(struct sme_populate_pgd_data *ppd) { pud_t *pud; pmd_t *pmd; @@ -167,7 +168,7 @@ static void __init sme_populate_pgd_large(struct sme_populate_pgd_data *ppd) set_pmd(pmd, __pmd(ppd->paddr | ppd->pmd_flags)); } -static void __init sme_populate_pgd(struct sme_populate_pgd_data *ppd) +static void __head sme_populate_pgd(struct sme_populate_pgd_data *ppd) { pud_t *pud; pmd_t *pmd; @@ -193,7 +194,7 @@ static void __init sme_populate_pgd(struct sme_populate_pgd_data *ppd) set_pte(pte, __pte(ppd->paddr | ppd->pte_flags)); } -static void __init __sme_map_range_pmd(struct sme_populate_pgd_data *ppd) +static void __head __sme_map_range_pmd(struct sme_populate_pgd_data *ppd) { while (ppd->vaddr < ppd->vaddr_end) { sme_populate_pgd_large(ppd); @@ -203,7 +204,7 @@ static void __init __sme_map_range_pmd(struct sme_populate_pgd_data *ppd) } } -static void __init __sme_map_range_pte(struct sme_populate_pgd_data *ppd) +static void __head __sme_map_range_pte(struct sme_populate_pgd_data *ppd) { while (ppd->vaddr < ppd->vaddr_end) { sme_populate_pgd(ppd); @@ -213,7 +214,7 @@ static void __init __sme_map_range_pte(struct sme_populate_pgd_data *ppd) } } -static void __init __sme_map_range(struct sme_populate_pgd_data *ppd, +static void __head __sme_map_range(struct sme_populate_pgd_data *ppd, pmdval_t pmd_flags, pteval_t pte_flags) { unsigned long vaddr_end; @@ -237,22 +238,22 @@ static void __init __sme_map_range(struct sme_populate_pgd_data *ppd, __sme_map_range_pte(ppd); } -static void __init sme_map_range_encrypted(struct sme_populate_pgd_data *ppd) +static void __head sme_map_range_encrypted(struct sme_populate_pgd_data *ppd) { __sme_map_range(ppd, PMD_FLAGS_ENC, PTE_FLAGS_ENC); } -static void __init sme_map_range_decrypted(struct sme_populate_pgd_data *ppd) +static void __head sme_map_range_decrypted(struct sme_populate_pgd_data *ppd) { __sme_map_range(ppd, PMD_FLAGS_DEC, PTE_FLAGS_DEC); } -static void __init sme_map_range_decrypted_wp(struct sme_populate_pgd_data *ppd) +static void __head sme_map_range_decrypted_wp(struct sme_populate_pgd_data *ppd) { __sme_map_range(ppd, PMD_FLAGS_DEC_WP, PTE_FLAGS_DEC_WP); } -static unsigned long __init sme_pgtable_calc(unsigned long len) +static unsigned long __head sme_pgtable_calc(unsigned long len) { unsigned long entries = 0, tables = 0; @@ -289,7 +290,7 @@ static unsigned long __init sme_pgtable_calc(unsigned long len) return entries + tables; } -void __init sme_encrypt_kernel(struct boot_params *bp) +void __head sme_encrypt_kernel(struct boot_params *bp) { unsigned long workarea_start, workarea_end, workarea_len; unsigned long execute_start, execute_end, execute_len; @@ -502,7 +503,7 @@ void __init sme_encrypt_kernel(struct boot_params *bp) native_write_cr3(__native_read_cr3()); } -void __init sme_enable(struct boot_params *bp) +void __head sme_enable(struct boot_params *bp) { const char *cmdline_ptr, *cmdline_arg, *cmdline_on, *cmdline_off; unsigned int eax, ebx, ecx, edx; From patchwork Wed Jul 12 03:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 118800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp891726vqm; Tue, 11 Jul 2023 20:49:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlGzi/PPeRNHri+Q88l4AaQjVvBQCW3ATiRn0Z99caUKIcyWGjVk2QQ/kR1Qu1U1dqo9d7jY X-Received: by 2002:aa7:d043:0:b0:51e:cc7:534d with SMTP id n3-20020aa7d043000000b0051e0cc7534dmr15762298edo.24.1689133758232; Tue, 11 Jul 2023 20:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689133758; cv=none; d=google.com; s=arc-20160816; b=du+QL+qsk1SZiu/+pqwovMLRZfM0ohbLgquMb01oXBwcLKYhtxwj4OMcyyaiG05MVL ExUJapTJkE0a2HREYrcoaIwLyL6cBJGXP4LeYbpGbHBRQiDnaAe+GRScwyPAtDBphJii mO9C0cD6A8uxaDtdiRASU2h4KLxpsPIr3UlQ+L7hogGqKYMUip7aiWps/GPd0aw1kBmb B53nsNkIdkLRRQ9PchV0cd+YOkp5+8Mqrahqq0fiapW1JVqcB3mVMocAclI+coJ4S2xP CfrY0A5p9nzZQm0Kci5LSsofFXH4IVD3rQ+za67/CP7Z7L/+ZZJQsApPQpR+DXQsx7QF oVUw== 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=nJ+axOaYJuTpcodlc6yXfGW4h7eJ/AWARm1N1AHY72I=; fh=g3bs2vx/kX+Tyhj7Th90Ny2Gk3JcG9W//LiDCVLFzAY=; b=WhbgivhCGY5cJtPypZ2IMogXqmEJCGqqQzy2fvS29ksDVCZtdbZduY+UugOzed1T65 B9bZEqMUBmJKAISvslPnwPj7djBeISDhgRgW3myGGfLU+hytF69is/WCJXCBzorwFrHM Kp0KiZyO+h7JgWWKMBOqS5Qm0WCs4t8Iy7X5iksx9zaAHshPmi88BlGSOzzXp3ZVOtEt MVYt2DVx0yJx8JKDngyTBFGOAk8b71RAF8yM6kRbbziI86qzlfBMv69BKAsHSodVQJC1 KBdHn9j1IP8tht4aSGKVlz9pKaD9di5la1YSJ3NBTEiyokdAnP4gB/lmsIdAUy4xr6e5 Bm5Q== 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 y8-20020aa7ccc8000000b0051ddbdeb0c7si3657918edt.350.2023.07.11.20.48.55; Tue, 11 Jul 2023 20:49:18 -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 S231859AbjGLDcl (ORCPT + 99 others); Tue, 11 Jul 2023 23:32:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjGLDcQ (ORCPT ); Tue, 11 Jul 2023 23:32:16 -0400 Received: from out0-207.mail.aliyun.com (out0-207.mail.aliyun.com [140.205.0.207]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 053381BF5 for ; Tue, 11 Jul 2023 20:32:07 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047207;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=11;SR=0;TI=SMTPD_---.TrdHx8q_1689132719; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.TrdHx8q_1689132719) by smtp.aliyun-inc.com; Wed, 12 Jul 2023 11:32:00 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Lai Jiangshan" , "Hou Wenlong" , "Dave Hansen" , "Andy Lutomirski" , "Peter Zijlstra" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , " =?utf-8?q?maintainer=3AX86_ARCHITECTURE?= =?utf-8?q?_32-BIT_AND_64-BIT?= " , "H. Peter Anvin" Subject: [PATCH RFC 7/7] x86/sme: Build the code in mem_encrypt_identity.c as PIE Date: Wed, 12 Jul 2023 11:30:11 +0800 Message-Id: <80367ca39ed736b6fc839c5de99a006f54182c45.1689130310.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, RCVD_IN_DNSWL_BLOCKED,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: INBOX X-GMAIL-THRID: 1771185119494268539 X-GMAIL-MSGID: 1771185119494268539 Similar to head64.c, all the code in mem_encrypt_identity.c runs in identity address. However, it uses inline assembly to use RIP-relative reference for some globals. Therefore, build the code as PIE to force the compiler to generate RIP-relative reference, allowing for all inline assembly to be removed. Suggested-by: Lai Jiangshan Signed-off-by: Hou Wenlong --- The changes have not been tested on AMD SME. arch/x86/mm/Makefile | 3 +++ arch/x86/mm/mem_encrypt_identity.c | 31 +++++------------------------- 2 files changed, 8 insertions(+), 26 deletions(-) -- 2.31.1 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile index c80febc44cd2..f5d7b22c5f1b 100644 --- a/arch/x86/mm/Makefile +++ b/arch/x86/mm/Makefile @@ -32,6 +32,9 @@ obj-y += pat/ # Make sure __phys_addr has no stackprotector CFLAGS_physaddr.o := -fno-stack-protector CFLAGS_mem_encrypt_identity.o := -fno-stack-protector +CFLAGS_mem_encrypt_identity.o += -fPIE -include $(srctree)/include/linux/hidden.h + +CFLAGS_REMOVE_mem_encrypt_identity.o += -mcmodel=kernel CFLAGS_fault.o := -I $(srctree)/$(src)/../include/asm/trace diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index 72aeb0f3dec6..2f292ab4e6a9 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -343,13 +343,7 @@ void __head sme_encrypt_kernel(struct boot_params *bp) } #endif - /* - * We're running identity mapped, so we must obtain the address to the - * SME encryption workarea using rip-relative addressing. - */ - asm ("lea sme_workarea(%%rip), %0" - : "=r" (workarea_start) - : "p" (sme_workarea)); + workarea_start = (unsigned long)(void *)sme_workarea; /* * Calculate required number of workarea bytes needed: @@ -505,7 +499,7 @@ void __head sme_encrypt_kernel(struct boot_params *bp) void __head sme_enable(struct boot_params *bp) { - const char *cmdline_ptr, *cmdline_arg, *cmdline_on, *cmdline_off; + const char *cmdline_ptr; unsigned int eax, ebx, ecx, edx; unsigned long feature_mask; bool active_by_default; @@ -578,21 +572,6 @@ void __head sme_enable(struct boot_params *bp) goto out; } - /* - * Fixups have not been applied to phys_base yet and we're running - * identity mapped, so we must obtain the address to the SME command - * line argument data using rip-relative addressing. - */ - asm ("lea sme_cmdline_arg(%%rip), %0" - : "=r" (cmdline_arg) - : "p" (sme_cmdline_arg)); - asm ("lea sme_cmdline_on(%%rip), %0" - : "=r" (cmdline_on) - : "p" (sme_cmdline_on)); - asm ("lea sme_cmdline_off(%%rip), %0" - : "=r" (cmdline_off) - : "p" (sme_cmdline_off)); - if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT)) active_by_default = true; else @@ -601,12 +580,12 @@ void __head sme_enable(struct boot_params *bp) cmdline_ptr = (const char *)((u64)bp->hdr.cmd_line_ptr | ((u64)bp->ext_cmd_line_ptr << 32)); - if (cmdline_find_option(cmdline_ptr, cmdline_arg, buffer, sizeof(buffer)) < 0) + if (cmdline_find_option(cmdline_ptr, sme_cmdline_arg, buffer, sizeof(buffer)) < 0) return; - if (!strncmp(buffer, cmdline_on, sizeof(buffer))) + if (!strncmp(buffer, sme_cmdline_on, sizeof(buffer))) sme_me_mask = me_mask; - else if (!strncmp(buffer, cmdline_off, sizeof(buffer))) + else if (!strncmp(buffer, sme_cmdline_off, sizeof(buffer))) sme_me_mask = 0; else sme_me_mask = active_by_default ? me_mask : 0;