Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp846602imm; Fri, 14 Sep 2018 07:14:33 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYrJmicZCleCdjGarMXrR8guO/2BU7egpDFQrElqpSh8T0p+cJvDHnklDEmbplWUK2UfSzO X-Received: by 2002:a17:902:33c2:: with SMTP id b60-v6mr12403764plc.11.1536934473699; Fri, 14 Sep 2018 07:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536934473; cv=none; d=google.com; s=arc-20160816; b=kItx8FXT7vFlTm5litN1ulaVV1H3SjBKHDW5IuWzSXtzG+sEyMzJJQFlt2xy1R1Jg0 3TBRkHLYroy+CKWoJt4Dtywi0VGFasuGceZ2VXC+IzLoJWaQVcwkEGC9icXJdz26cxy5 ZvqvM+RfWxIfJ3YNQcNjEYC3pWvlquzKP2GLEXP7u8iMjOvhC7/u59ePNvv/Iey5h6cZ ICzE9Pf8L099DOAGIlFZ85xVzO4cG3Jo7AE8Y9H7fwHFfVvNptPUIDlUQih7HcUHAI/5 KEaCc1gFVtc+VA9Vgnx/agHfrD6nOFFQUT/fF/itpWR12LfYLS71f6fNPLShr8Ka5fXK bl6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=pluHg57vMwqWOBxkYQlF7jELAnWpcfoSLRix58qxMR4=; b=g/T4msy1KnLcvGy2VPHySdJZotawFPLvelOZje9GKR0+eLwpbG9Q9rEX6OqqgHPKCA 2Jf6JfL4mWlzRThCGFgyqGLlqNzPfRcr8tEJZbo49nVzOY0hN6R/Ed3wuLBZJmoIgCWv 4Bn7Ua+z/x8wY+RSkhCCwpRgPd1Ts1wv99OmrxDSorl054OqO3AEcc7VLXImwaSyANMd /CvyH6X55am+eMORGUGx3JkJioYYb/qQXkqCNcSc1FZ1jzEimBsvo6HBM40DLXb2CX5n FSyy7GHMSnWgi94DqHJWfCSf7gu/M43AKQgfuXudUWkfE/hF8L+JKffiEPbfd2zY+ttw +FUw== 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 y193-v6si6914580pgd.512.2018.09.14.07.14.09; Fri, 14 Sep 2018 07:14:33 -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 S1728057AbeINT1H (ORCPT + 99 others); Fri, 14 Sep 2018 15:27:07 -0400 Received: from mx2.suse.de ([195.135.220.15]:44842 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727013AbeINT1G (ORCPT ); Fri, 14 Sep 2018 15:27:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 84E21AE83; Fri, 14 Sep 2018 14:12:23 +0000 (UTC) Date: Fri, 14 Sep 2018 16:12:16 +0200 From: Borislav Petkov To: Thomas Gleixner , Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Tom Lendacky , "H. Peter Anvin" , Paolo Bonzini , Sean Christopherson , Radim =?utf-8?B?S3LEjW3DocWZ?= Subject: Re: [PATCH v8 1/2] x86/mm: add .bss..decrypted section to hold shared variables Message-ID: <20180914141216.GA29898@zn.tnic> References: <1536875471-17391-1-git-send-email-brijesh.singh@amd.com> <1536875471-17391-2-git-send-email-brijesh.singh@amd.com> <20180914071056.GA4747@zn.tnic> <3517a0db-2f64-6d09-7100-dced40561d08@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 14, 2018 at 02:17:05PM +0200, Thomas Gleixner wrote: > > The sme_encrypt_kernel() does not have access to pmd (after pointer > > fixup is applied). You can extend the sme_encrypt_kernel() to pass an > > additional arguments but then we start getting in include hell. The pmd > > is defined as "pmdval_t". If we extend the sme_encrypt_kernel() then  > > asm/mem_encrypt.h need to include the header file which defines > > "pmdval_t". Adding the 'asm/pgtable_type.h' was causing all kind of > > compilation errors. I didn't spend much time on it. IMO, we really don't > > need to go in this path unless we see some value from doing this. > > Keep it here then. *For what is worth*, a simple forward declaration works. I've taken the 64-bit forward declaration of pmdval_t as SME is 64-bit only anyway. The below diff ontop passes the mandatory all*config smoke builds: --- arch/x86/include/asm/mem_encrypt.h | 6 ++++-- arch/x86/kernel/head64.c | 18 +----------------- arch/x86/mm/mem_encrypt_identity.c | 18 +++++++++++++++++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/arch/x86/include/asm/mem_encrypt.h b/arch/x86/include/asm/mem_encrypt.h index 616f8e637bc3..67c0e6cfdfb3 100644 --- a/arch/x86/include/asm/mem_encrypt.h +++ b/arch/x86/include/asm/mem_encrypt.h @@ -19,6 +19,8 @@ #include +typedef unsigned long pmdval_t; + #ifdef CONFIG_AMD_MEM_ENCRYPT extern u64 sme_me_mask; @@ -40,7 +42,7 @@ void __init sme_unmap_bootdata(char *real_mode_data); void __init sme_early_init(void); -void __init sme_encrypt_kernel(struct boot_params *bp); +void __init sme_encrypt_kernel(struct boot_params *bp, pmdval_t *pmd); void __init sme_enable(struct boot_params *bp); int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size); @@ -69,7 +71,7 @@ static inline void __init sme_unmap_bootdata(char *real_mode_data) { } static inline void __init sme_early_init(void) { } -static inline void __init sme_encrypt_kernel(struct boot_params *bp) { } +static inline void __init sme_encrypt_kernel(struct boot_params *bp, pmdval_t *pmd) { } static inline void __init sme_enable(struct boot_params *bp) { } static inline bool sme_active(void) { return false; } diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c index c16af27eb23f..6f8e9b534e80 100644 --- a/arch/x86/kernel/head64.c +++ b/arch/x86/kernel/head64.c @@ -112,7 +112,6 @@ static bool __head check_la57_support(unsigned long physaddr) unsigned long __head __startup_64(unsigned long physaddr, struct boot_params *bp) { - unsigned long vaddr, vaddr_end; unsigned long load_delta, *p; unsigned long pgtable_flags; pgdval_t *pgd; @@ -233,22 +232,7 @@ unsigned long __head __startup_64(unsigned long physaddr, *fixup_long(&phys_base, physaddr) += load_delta - sme_get_me_mask(); /* Encrypt the kernel and related (if SME is active) */ - sme_encrypt_kernel(bp); - - /* - * Clear the memory encryption mask from the .bss..decrypted section. - * The bss section will be memset to zero later in the initialization so - * there is no need to zero it after changing the memory encryption - * attribute. - */ - if (mem_encrypt_active()) { - vaddr = (unsigned long)__start_bss_decrypted; - vaddr_end = (unsigned long)__end_bss_decrypted; - for (; vaddr < vaddr_end; vaddr += PMD_SIZE) { - i = pmd_index(vaddr); - pmd[i] -= sme_get_me_mask(); - } - } + sme_encrypt_kernel(bp, pmd); /* * Return the SME encryption mask (if SME is active) to be used as a diff --git a/arch/x86/mm/mem_encrypt_identity.c b/arch/x86/mm/mem_encrypt_identity.c index a19ef1a416ff..9dbc145d10f8 100644 --- a/arch/x86/mm/mem_encrypt_identity.c +++ b/arch/x86/mm/mem_encrypt_identity.c @@ -267,15 +267,17 @@ static unsigned long __init sme_pgtable_calc(unsigned long len) return entries + tables; } -void __init sme_encrypt_kernel(struct boot_params *bp) +void __init sme_encrypt_kernel(struct boot_params *bp, pmdval_t *pmd) { unsigned long workarea_start, workarea_end, workarea_len; unsigned long execute_start, execute_end, execute_len; unsigned long kernel_start, kernel_end, kernel_len; unsigned long initrd_start, initrd_end, initrd_len; struct sme_populate_pgd_data ppd; + unsigned long vaddr, vaddr_end; unsigned long pgtable_area_len; unsigned long decrypted_base; + int i; if (!sme_active()) return; @@ -467,6 +469,20 @@ void __init sme_encrypt_kernel(struct boot_params *bp) /* Flush the TLB - no globals so cr3 is enough */ native_write_cr3(__native_read_cr3()); + + /* + * Clear the memory encryption mask from the .bss..decrypted section. + * The bss section will be memset to zero later in the initialization so + * there is no need to zero it after changing the memory encryption + * attribute. + */ + vaddr = (unsigned long)__start_bss_decrypted; + vaddr_end = (unsigned long)__end_bss_decrypted; + + for (; vaddr < vaddr_end; vaddr += PMD_SIZE) { + i = pmd_index(vaddr); + pmd[i] -= sme_get_me_mask(); + } } void __init sme_enable(struct boot_params *bp) -- 2.17.0.582.gccdcbd54c SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --