Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp425233imm; Fri, 14 Sep 2018 00:11:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYj7tBgiptPabWhr1GfLz8lG+pvNN7iNhMiA4HPHEPiATZOxdlFoxyKFM0PquBBlENO8VzK X-Received: by 2002:a62:8d16:: with SMTP id z22-v6mr11063292pfd.181.1536909089598; Fri, 14 Sep 2018 00:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536909089; cv=none; d=google.com; s=arc-20160816; b=GhZKSpxzCA2c5mUKlgBsBMD3rdvS1q6ggaQ7jgdY4nb4OlXMgmSJ9/ZBt3Ur5g1KCt QrnJYPa+MOvImclG2uj0LWcvg8ytrjEajPvPQcKkENrdoK8EzTOlHbN7xAVoeHliKZhf GfbKI71H8MMMe+S/5iuMkHErZOnJXfKvz0E9tlhoyxNDarng2rSRBpFpwfKmukevZO0H +eQHEO7T2sW3icYhKIbv3TRXFmCxxroIw+pkiSt2pWMPrTkpOmhW5iHkpso1eQcO3ZZ0 4mx+U4ry7ozzLqoCQEsipnU7sg+NDOjtPDpgwbM1M4+MJarOyL5l7EBSCp8Fi/ZlTg1q MQzQ== 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=S6bMJJjnONE/rJVsS5EVotc4UfzFdLzoxVSU9il9R6s=; b=CM3qwSAI5FCl52FTEO7Y7mfmhX3qgScHQYaOwcbyhRRxpgo63qdBliZn5dpb1QtD8t ANkmrNOoJoWmCxBsCegO683WGGER6O1IjC6WD/6U1smrMBFoZX3xK0BOo2Vh8y3gHcto dm9E4OrPU2avcoALxsbmEYYQP6hZbiDfJRvAnl6q4raw2k2aOKbHu8oiHr96oXVOJ+24 Iy5qsSBz4SDgzFYAsLl6iRFy0z/43wjTuwAoy1zrIQuOcc9KoBUG8i9QItRhICu80bj9 rBjndK4tvy6zP4JSIvQcldObQ1gU3ZQ6Lg9vQSYVU7bd9qs4hbyBsYMeSduGwNj3NnpG JfJQ== 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 e17-v6si5657378pgv.615.2018.09.14.00.11.14; Fri, 14 Sep 2018 00:11:29 -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 S1727834AbeINMYO (ORCPT + 99 others); Fri, 14 Sep 2018 08:24:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:46892 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727005AbeINMYN (ORCPT ); Fri, 14 Sep 2018 08:24:13 -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 B20A9AC3B; Fri, 14 Sep 2018 07:11:04 +0000 (UTC) Date: Fri, 14 Sep 2018 09:10:56 +0200 From: Borislav Petkov To: Brijesh Singh Cc: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Tom Lendacky , Thomas Gleixner , "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: <20180914071056.GA4747@zn.tnic> References: <1536875471-17391-1-git-send-email-brijesh.singh@amd.com> <1536875471-17391-2-git-send-email-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1536875471-17391-2-git-send-email-brijesh.singh@amd.com> 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 Thu, Sep 13, 2018 at 04:51:10PM -0500, Brijesh Singh wrote: > kvmclock defines few static variables which are shared with the > hypervisor during the kvmclock initialization. ... > diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c > index 8047379..c16af27 100644 > --- a/arch/x86/kernel/head64.c > +++ b/arch/x86/kernel/head64.c > @@ -112,6 +112,7 @@ 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; > @@ -235,6 +236,21 @@ unsigned long __head __startup_64(unsigned long physaddr, > 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(); > + } > + } Why isn't this chunk at the end of sme_encrypt_kernel() instead of here? > + /* > * Return the SME encryption mask (if SME is active) to be used as a > * modifier for the initial pgdir entry programmed into CR3. > */ > diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S > index 9c77d2d..0d618ee 100644 > --- a/arch/x86/kernel/vmlinux.lds.S > +++ b/arch/x86/kernel/vmlinux.lds.S > @@ -65,6 +65,23 @@ jiffies_64 = jiffies; > #define ALIGN_ENTRY_TEXT_BEGIN . = ALIGN(PMD_SIZE); > #define ALIGN_ENTRY_TEXT_END . = ALIGN(PMD_SIZE); > > +/* > + * This section contains data which will be mapped as decrypted. Memory > + * encryption operates on a page basis. Make this section PMD-aligned > + * to avoid splitting the pages while mapping the section early. > + * > + * Note: We use a separate section so that only this section gets > + * decrypted to avoid exposing more than we wish. > + */ > +#define BSS_DECRYPTED \ > + . = ALIGN(PMD_SIZE); \ > + __start_bss_decrypted = .; \ > + *(.bss..decrypted); \ > + . = ALIGN(PAGE_SIZE); \ > + __start_bss_decrypted_unused = .; \ > + . = ALIGN(PMD_SIZE); \ > + __end_bss_decrypted = .; \ > + > #else > > #define X86_ALIGN_RODATA_BEGIN > @@ -74,6 +91,7 @@ jiffies_64 = jiffies; > > #define ALIGN_ENTRY_TEXT_BEGIN > #define ALIGN_ENTRY_TEXT_END > +#define BSS_DECRYPTED > > #endif > > @@ -345,6 +363,7 @@ SECTIONS > __bss_start = .; > *(.bss..page_aligned) > *(.bss) > + BSS_DECRYPTED > . = ALIGN(PAGE_SIZE); > __bss_stop = .; Putting it in the BSS would need a bit of care in the future as it poses a certain ordering on the calls in x86_64_start_kernel() (not that there isn't any now :)): You have: x86_64_start_kernel: ... clear_bss(); ... x86_64_start_reservations() -> ... -> setup_arch() -> kvmclock_init() so it would be prudent to put at least a comment somewhere, say, over the definition of BSS_DECRYPTED or so, that attention should be paid to the clear_bss() call early. Thx. -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --