From: Tom Lendacky <thomas.lendacky@amd.com>
To: Borislav Petkov <bp@alien8.de>
Cc: x86@kernel.org, Brijesh Singh <brijesh.singh@amd.com>,
linux-kernel@vger.kernel.org, Ingo Molnar <mingo@redhat.com>,
"H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH v1 3/3] x86/mm: Encrypt the initrd earlier for BSP microcode update
Date: Thu, 21 Dec 2017 10:48:29 -0600 [thread overview]
Message-ID: <cf742b88-49ac-7420-ebee-3523c267bde4@amd.com> (raw)
In-Reply-To: <20171221144925.76ge77xraapgzm36@pd.tnic>
On 12/21/2017 8:49 AM, Borislav Petkov wrote:
> 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.
This is very early in the boot and the boot parameters have not been
copied to boot_params yet, so I need the pointer. And since the routines
in arch/x86/kernel/setup.c also use boot_params, those would have to be
modified to accept a pointer rather than automatically using boot_params.
I'm not sure it's worth all that.
Thanks,
Tom
>
> Thx.
>
next prev parent reply other threads:[~2017-12-21 16:48 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-07 23:33 [PATCH v1 0/3] x86: SME: BSP/SME microcode update fix Tom Lendacky
2017-12-07 23:33 ` [PATCH v1 1/3] x86/mm: Centralize PMD flags in sme_encrypt_kernel() Tom Lendacky
2017-12-20 19:13 ` Borislav Petkov
2017-12-20 19:59 ` Tom Lendacky
2017-12-07 23:34 ` [PATCH v1 2/3] x86/mm: Prepare sme_encrypt_kernel() for PAGE aligned encryption Tom Lendacky
2017-12-21 12:58 ` Borislav Petkov
2017-12-21 16:35 ` Tom Lendacky
2017-12-07 23:34 ` [PATCH v1 3/3] x86/mm: Encrypt the initrd earlier for BSP microcode update Tom Lendacky
2017-12-21 14:49 ` Borislav Petkov
2017-12-21 16:48 ` Tom Lendacky [this message]
2017-12-21 17:13 ` Borislav Petkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cf742b88-49ac-7420-ebee-3523c267bde4@amd.com \
--to=thomas.lendacky@amd.com \
--cc=bp@alien8.de \
--cc=brijesh.singh@amd.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®