Received: by 10.213.65.68 with SMTP id h4csp203882imn; Wed, 28 Mar 2018 01:49:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx48uO9rGKq19ADj+JtpnLrGcbpV8dxb3qLvwsR9PeSDyzbuGuuma+7rRPpz1dkz1YDZWKMp8 X-Received: by 2002:a17:902:102:: with SMTP id 2-v6mr2902064plb.48.1522226960732; Wed, 28 Mar 2018 01:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522226960; cv=none; d=google.com; s=arc-20160816; b=EGS0M1UK+Jkcpn6P5y/vRIUCTXBOy4P0R4rqDqDSmJbTA2VB51sDTngptCsB/MDHn7 Ikup/Mnb9lI62wZNGWFD4p+1X3D3YCAWD5Tqc3YsQNkn4slT3f9nX2ZL18ntOHyOJcZ0 MBo3iq57maoRut06fzGbNnTnk3AVmjuvbgrY7lCWFa9KRhc/9mgLpQPK4VrgPSY8p8Kz sAswxEStODSRQ2PFYi9gOFRMnVvQnhPd7c5h1GIuMYX7sfMVv3uqqNeHjg/Xcmd0N+u8 5twpICVqm3VL9FUSuB/6AYRMs/7fqvWlCQdAoXWyXCDZlDFCwwgyfuzVfv0k35xmA9dI PuUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date:arc-authentication-results; bh=sWRucYwD7zLDSqJPik4lGZXEZma7ugOoULkwQAX5lUE=; b=UH2rDseAUm+WAvPZnYh3vt2tO58EreVnB1Sp7XeDA0WSXmnmx8JJTkb8Drb16NanF+ FIhL59Ce+3RSswYJzH6hE0xh7PpvBBDmZLLonQW6BUwh7fZIBCJEEDlh3EdzQJKz6ONe wZgiUPBlK64v3Kij8lalqa1WCUGLIlsRmT9RHWQ6Z4MLmVuohgt3B2MQVuQ8G+0KljI5 b0xnp0JA6M/MFhMCAytYLZemkPSu/jlTxNcIZz96a53rWJPaguqu1WqWTRPluunnH56u v0qkHz/+zmEnoZ283FJXP76EAwAMsG9poesUX7zGDAl5vs/544z3ehxrhOlVroiGxl8v oEWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f5-v6si3109512plf.223.2018.03.28.01.49.06; Wed, 28 Mar 2018 01:49:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752785AbeC1IrM (ORCPT + 99 others); Wed, 28 Mar 2018 04:47:12 -0400 Received: from terminus.zytor.com ([198.137.202.136]:38927 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752479AbeC1IrI (ORCPT ); Wed, 28 Mar 2018 04:47:08 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTP id w2S8kV16991465; Wed, 28 Mar 2018 01:46:31 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id w2S8kUD8991462; Wed, 28 Mar 2018 01:46:30 -0700 Date: Wed, 28 Mar 2018 01:46:30 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Tom Lendacky Message-ID: Cc: bp@alien8.de, tglx@linutronix.de, brijesh.singh@amd.com, thomas.lendacky@amd.com, hpa@zytor.com, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, mingo@kernel.org Reply-To: mingo@kernel.org, kirill.shutemov@linux.intel.com, hpa@zytor.com, linux-kernel@vger.kernel.org, brijesh.singh@amd.com, thomas.lendacky@amd.com, bp@alien8.de, tglx@linutronix.de In-Reply-To: <20180327220711.8702.55842.stgit@tlendack-t1.amdoffice.net> References: <20180327220711.8702.55842.stgit@tlendack-t1.amdoffice.net> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/mm] x86/boot: Fix SEV boot failure from change to __PHYSICAL_MASK_SHIFT Git-Commit-ID: 07344b15a994acadbe439aa4e75127ed1ccca099 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 07344b15a994acadbe439aa4e75127ed1ccca099 Gitweb: https://git.kernel.org/tip/07344b15a994acadbe439aa4e75127ed1ccca099 Author: Tom Lendacky AuthorDate: Tue, 27 Mar 2018 17:07:11 -0500 Committer: Thomas Gleixner CommitDate: Wed, 28 Mar 2018 10:42:57 +0200 x86/boot: Fix SEV boot failure from change to __PHYSICAL_MASK_SHIFT In arch/x86/boot/compressed/kaslr_64.c, CONFIG_AMD_MEM_ENCRYPT support was initially #undef'd to support SME with minimal effort. When support for SEV was added, the #undef remained and some minimal support for setting the encryption bit was added for building identity mapped pagetable entries. Commit b83ce5ee9147 ("x86/mm/64: Make __PHYSICAL_MASK_SHIFT always 52") changed __PHYSICAL_MASK_SHIFT from 46 to 52 in support of 5-level paging. This change resulted in SEV guests failing to boot because the encryption bit was no longer being automatically masked out. The compressed boot path now requires sme_me_mask to be defined in order for the pagetable functions, such as pud_present(), to properly mask out the encryption bit (currently bit 47) when evaluating pagetable entries. Add an sme_me_mask variable in arch/x86/boot/compressed/mem_encrypt.S, which is set when SEV is active, delete the #undef CONFIG_AMD_MEM_ENCRYPT from arch/x86/boot/compressed/kaslr_64.c and use sme_me_mask when building the identify mapped pagetable entries. Fixes: b83ce5ee9147 ("x86/mm/64: Make __PHYSICAL_MASK_SHIFT always 52") Signed-off-by: Tom Lendacky Signed-off-by: Thomas Gleixner Cc: Borislav Petkov Cc: Brijesh Singh Cc: "Kirill A. Shutemov" Cc: "H. Peter Anvin" Link: https://lkml.kernel.org/r/20180327220711.8702.55842.stgit@tlendack-t1.amdoffice.net --- arch/x86/boot/compressed/kaslr_64.c | 14 ++++---------- arch/x86/boot/compressed/mem_encrypt.S | 17 ++++++++++------- arch/x86/boot/compressed/misc.h | 2 +- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/arch/x86/boot/compressed/kaslr_64.c b/arch/x86/boot/compressed/kaslr_64.c index b5e5e02f8cde..522d11431433 100644 --- a/arch/x86/boot/compressed/kaslr_64.c +++ b/arch/x86/boot/compressed/kaslr_64.c @@ -16,13 +16,6 @@ #define __pa(x) ((unsigned long)(x)) #define __va(x) ((void *)((unsigned long)(x))) -/* - * The pgtable.h and mm/ident_map.c includes make use of the SME related - * information which is not used in the compressed image support. Un-define - * the SME support to avoid any compile and link errors. - */ -#undef CONFIG_AMD_MEM_ENCRYPT - /* No PAGE_TABLE_ISOLATION support needed either: */ #undef CONFIG_PAGE_TABLE_ISOLATION @@ -85,13 +78,14 @@ static struct x86_mapping_info mapping_info; /* Locates and clears a region for a new top level page table. */ void initialize_identity_maps(void) { - unsigned long sev_me_mask = get_sev_encryption_mask(); + /* If running as an SEV guest, the encryption mask is required. */ + set_sev_encryption_mask(); /* Init mapping_info with run-time function/buffer pointers. */ mapping_info.alloc_pgt_page = alloc_pgt_page; mapping_info.context = &pgt_data; - mapping_info.page_flag = __PAGE_KERNEL_LARGE_EXEC | sev_me_mask; - mapping_info.kernpg_flag = _KERNPG_TABLE | sev_me_mask; + mapping_info.page_flag = __PAGE_KERNEL_LARGE_EXEC | sme_me_mask; + mapping_info.kernpg_flag = _KERNPG_TABLE; /* * It should be impossible for this not to already be true, diff --git a/arch/x86/boot/compressed/mem_encrypt.S b/arch/x86/boot/compressed/mem_encrypt.S index 54f5f6625a73..eaa843a52907 100644 --- a/arch/x86/boot/compressed/mem_encrypt.S +++ b/arch/x86/boot/compressed/mem_encrypt.S @@ -88,9 +88,7 @@ ENTRY(get_sev_encryption_bit) ENDPROC(get_sev_encryption_bit) .code64 -ENTRY(get_sev_encryption_mask) - xor %rax, %rax - +ENTRY(set_sev_encryption_mask) #ifdef CONFIG_AMD_MEM_ENCRYPT push %rbp push %rdx @@ -101,9 +99,7 @@ ENTRY(get_sev_encryption_mask) testl %eax, %eax jz .Lno_sev_mask - xor %rdx, %rdx - bts %rax, %rdx /* Create the encryption mask */ - mov %rdx, %rax /* ... and return it */ + bts %rax, sme_me_mask(%rip) /* Create the encryption mask */ .Lno_sev_mask: movq %rbp, %rsp /* Restore original stack pointer */ @@ -112,9 +108,16 @@ ENTRY(get_sev_encryption_mask) pop %rbp #endif + xor %rax, %rax ret -ENDPROC(get_sev_encryption_mask) +ENDPROC(set_sev_encryption_mask) .data enc_bit: .int 0xffffffff + +#ifdef CONFIG_AMD_MEM_ENCRYPT + .balign 8 +GLOBAL(sme_me_mask) + .quad 0 +#endif diff --git a/arch/x86/boot/compressed/misc.h b/arch/x86/boot/compressed/misc.h index 4d369c308ed7..9e11be4cae19 100644 --- a/arch/x86/boot/compressed/misc.h +++ b/arch/x86/boot/compressed/misc.h @@ -114,6 +114,6 @@ static inline void console_init(void) { } #endif -unsigned long get_sev_encryption_mask(void); +void set_sev_encryption_mask(void); #endif