Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752267AbdLUOti (ORCPT ); Thu, 21 Dec 2017 09:49:38 -0500 Received: from mail.skyhub.de ([5.9.137.197]:49236 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751406AbdLUOtg (ORCPT ); Thu, 21 Dec 2017 09:49:36 -0500 Date: Thu, 21 Dec 2017 15:49:25 +0100 From: Borislav Petkov To: Tom Lendacky Cc: x86@kernel.org, Brijesh Singh , linux-kernel@vger.kernel.org, Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner Subject: Re: [PATCH v1 3/3] x86/mm: Encrypt the initrd earlier for BSP microcode update Message-ID: <20171221144925.76ge77xraapgzm36@pd.tnic> References: <20171207233342.29646.12858.stgit@tlendack-t1.amdoffice.net> <20171207233410.29646.27816.stgit@tlendack-t1.amdoffice.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20171207233410.29646.27816.stgit@tlendack-t1.amdoffice.net> User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3063 Lines: 80 On Thu, Dec 07, 2017 at 05:34:10PM -0600, Tom Lendacky wrote: > Currently the BSP microcode update code examines the initrd very early > in the boot process. If SME is active, the initrd is treated as being > encrypted but it has not been encrypted (in place) yet. Update the > early boot code that encrypts the kernel to also encrypt the initrd so > that early BSP microcode updates work. ... > diff --git a/arch/x86/mm/mem_encrypt.c b/arch/x86/mm/mem_encrypt.c > index 1f0efb8..60df247 100644 > --- a/arch/x86/mm/mem_encrypt.c > +++ b/arch/x86/mm/mem_encrypt.c > @@ -731,11 +731,12 @@ static unsigned long __init sme_pgtable_calc(unsigned long len) > return total; > } > > -void __init sme_encrypt_kernel(void) > +void __init sme_encrypt_kernel(struct boot_params *bp) > { > 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; > unsigned long pgtable_area_len; > unsigned long decrypted_base; > pgd_t *pgd; > @@ -744,14 +745,15 @@ void __init sme_encrypt_kernel(void) > return; > > /* > - * Prepare for encrypting the kernel by building new pagetables with > - * the necessary attributes needed to encrypt the kernel in place. > + * Prepare for encrypting the kernel and initrd by building new > + * pagetables with the necessary attributes needed to encrypt the > + * kernel in place. > * > * One range of virtual addresses will map the memory occupied > - * by the kernel as encrypted. > + * by the kernel and initrd as encrypted. > * > * Another range of virtual addresses will map the memory occupied > - * by the kernel as decrypted and write-protected. > + * by the kernel and initrd as decrypted and write-protected. > * > * The use of write-protect attribute will prevent any of the > * memory from being cached. > @@ -762,6 +764,20 @@ void __init sme_encrypt_kernel(void) > kernel_end = ALIGN(__pa_symbol(_end), PMD_PAGE_SIZE); > kernel_len = kernel_end - kernel_start; > > + initrd_start = 0; > + initrd_end = 0; > + initrd_len = 0; > +#ifdef CONFIG_BLK_DEV_INITRD > + initrd_len = (unsigned long)bp->hdr.ramdisk_size | > + ((unsigned long)bp->ext_ramdisk_size << 32); > + if (initrd_len) { > + initrd_start = (unsigned long)bp->hdr.ramdisk_image | > + ((unsigned long)bp->ext_ramdisk_image << 32); > + initrd_end = PAGE_ALIGN(initrd_start + initrd_len); > + initrd_len = initrd_end - initrd_start; > + } > +#endif In a prepatch, pls make get_ramdisk_image() and get_ramdisk_size() from arch/x86/kernel/setup.c accessible to this code too. Also, add dummies for the !CONFIG_BLK_DEV_INITRD case so that you can simply call them here, regardless of the CONFIG_BLK_DEV_INITRD setting. Then you won't need boot_params ptr either and that would simplify the diff a bit. Thx. -- Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.