[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e06d90cc-544b-5280-f8cd-b25684214b4a@linux.microsoft.com>
Date: Fri, 17 Feb 2023 13:51:17 +0100
From: Jeremi Piotrowski <jpiotrowski@...ux.microsoft.com>
To: Dexuan Cui <decui@...rosoft.com>
Cc: Tom Lendacky <thomas.lendacky@....com>,
Borislav Petkov <bp@...en8.de>,
"sandipan.das@....com" <sandipan.das@....com>,
"Gupta, Pankaj" <pankaj.gupta@....com>,
"ray.huang@....com" <ray.huang@....com>,
"brijesh.singh@....com" <brijesh.singh@....com>,
"michael.roth@....com" <michael.roth@....com>,
"kvm@...r.kernel.org" <kvm@...r.kernel.org>,
"x86@...nel.org" <x86@...nel.org>,
Tianyu Lan <Tianyu.Lan@...rosoft.com>,
"linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: Re: Does earlyprintk=ttyS0 work for an AMD SNP guest on KVM?
On 16/02/2023 18:58, Dexuan Cui wrote:
>> From: Jeremi Piotrowski <jpiotrowski@...ux.microsoft.com>
>> Sent: Thursday, February 16, 2023 1:15 AM
>>> ...
>>> alloc_pgt_page() fails to allocate memory because both
>>> pages->pgt_buf_offset and pages->pgt_buf_size are zero.
>>>
>>>
>>> pgt_data.pgt_buf_size is zero because of this line in
>>> initialize_identity_maps()
>>> pgt_data.pgt_buf_size = BOOT_PGT_SIZE - BOOT_INIT_PGT_SIZE;
>>>
>>> void initialize_identity_maps(void *rmode)
>>> {
>>> ...
>>> top_level_pgt = read_cr3_pa();
>>> if (p4d_offset((pgd_t *)top_level_pgt, 0) == (p4d_t *)_pgtable) {
>>> pgt_data.pgt_buf = _pgtable + BOOT_INIT_PGT_SIZE;
>>> pgt_data.pgt_buf_size = BOOT_PGT_SIZE -
>>> BOOT_INIT_PGT_SIZE;
>>> memset(pgt_data.pgt_buf, 0, pgt_data.pgt_buf_size);
>>> } else {
>>> pgt_data.pgt_buf = _pgtable;
>>> pgt_data.pgt_buf_size = BOOT_PGT_SIZE;
>>> memset(pgt_data.pgt_buf, 0, pgt_data.pgt_buf_size);
>>> top_level_pgt = (unsigned
>>> long)alloc_pgt_page(&pgt_data);
>>
>> I just tested an SNP guest on KVM with and without
>> CONFIG_RANDOMIZE_BASE.
>> In both cases we end up in the else() branch.
>> With CONFIG_RANDOMIZE_BASE BOOT_PGT_SIZE=0x13000
>> Without CONFIG_RANDOMMIZE_BASE BOOT_PGT_SIZE=0x6000.
>>
>> So in both cases pgt_data.pgt_buf_size != 0.
>>
>> Getting into that first branch would require having 5-level paging supported
>> (CONFIG_X86_5LEVEL=y) and enabled inside the guest, I don't have that on
>> any
>> hardware I have access to.
>>
>> Jeremi
>
> CONFIG_X86_5LEVEL is not set for my kernel.
>
> The comment before the first branch says:
> On 4-level paging, p4d_offset(top_level_pgt, 0) is equal to 'top_level_pgt'.
>
> IIUC this means 'top_level_pgt' is equal to '_pgtable'? i.e. without
> CONFIG_RANDOMIZE_BASE, pgt_data.pgt_buf_size should be 0.
>
> Not sure why it's not getting into the first branch for you.
Sorry, I got two things confused here. The relevant part of the comment is this:
"If we came here via startup_32(), cr3 will be _pgtable already".
Booting a (non-SNP) guest via BIOS I end up in the first branch. Upstream SNP support
requires OVMF (UEFI) so we'll always reach the kernel in 64-bit mode (startup_64?),
and end up in the second branch.
Jeremi
Powered by blists - more mailing lists