public inbox for linux-efi@vger.kernel.org
 help / color / mirror / Atom feed
From: Usama Arif <usamaarif642@gmail.com>
To: Ard Biesheuvel <ardb@kernel.org>, Breno Leitao <leitao@debian.org>
Cc: linux-efi@vger.kernel.org, kexec@lists.infradead.org,
	ebiederm@xmission.com, bhe@redhat.com, vgoyal@redhat.com,
	tglx@linutronix.de, dave.hansen@linux.intel.com, x86@kernel.org,
	linux-kernel@vger.kernel.org, rmikey@meta.com, gourry@gourry.net
Subject: Re: [RFC] efi/tpm: add efi.tpm_log as a reserved region in 820_table_firmware
Date: Thu, 12 Sep 2024 16:35:06 +0100	[thread overview]
Message-ID: <9d3962f1-96b6-44a3-a7d3-10fbfbe06164@gmail.com> (raw)
In-Reply-To: <CAMj1kXG842OSYu4GPm-ocyvpBDowPGaXAftqGExxjZ4=dGyt5g@mail.gmail.com>



On 12/09/2024 16:21, Ard Biesheuvel wrote:
> On Thu, 12 Sept 2024 at 16:29, Breno Leitao <leitao@debian.org> wrote:
>>
>> On Thu, Sep 12, 2024 at 03:10:43PM +0200, Ard Biesheuvel wrote:
>>> On Thu, 12 Sept 2024 at 15:03, Breno Leitao <leitao@debian.org> wrote:
>>>> On Thu, Sep 12, 2024 at 12:51:57PM +0200, Ard Biesheuvel wrote:
>>>>> I don't see how this could be an EFI bug, given that it does not deal
>>>>> with E820 tables at all.
>>>>
>>>> I want to back up a little bit and make sure I am following the
>>>> discussion.
>>>>
>>>> From what I understand from previous discussion, we have an EFI bug as
>>>> the root cause of this issue.
>>>>
>>>> This happens because the EFI does NOT mark the EFI TPM event log memory
>>>> region as reserved (EFI_RESERVED_TYPE).
>>>
>>> Why do you think EFI should use EFI_RESERVED_TYPE in this case?
>>>
>>> The EFI spec is very clear that EFI_RESERVED_TYPE really shouldn't be
>>> used for anything by EFI itself. It is quite common for EFI
>>> configuration tables to be passed as EfiRuntimeServicesData (SMBIOS),
>>> EfiBootServicesData (ESRT) or EFiAcpiReclaim (ACPI tables).
>>>
>>> Reserved memory is mostly for memory that even the firmware does not
>>> know what it is for, i.e., particular platform specific uses.
>>>
>>> In general, it is up to the OS to ensure that EFI configuration tables
>>> that it cares about should be reserved in the correct way.
>>
>> Thanks for the explanation.
>>
>> So, if I understand what you meant here, the TPM event log memory range
>> shouldn't be listed as a memory region in EFI memory map (as passed by
>> the firmware to the OS).
>>
>> Hence, this is not a EFI firmware bug, but a OS/Kernel bug.
>>
>> Am I correct with the statements above?
>>
> 
> No, not entirely. But I also missed the face that this table is
> actually created by the EFI stub in Linux, not the firmware. It is
> *not* the same memory region that the TPM2 ACPI table describes, and
> so what the various specs say about that is entirely irrelevant.
> 
> The TPM event log configuration table is created by the EFI stub,
> which uses the TCG2::GetEventLog () protocol method to obtain it. This
> must be done by the EFI stub because these protocols will no longer be
> available once the OS boots. But the data is not used by the EFI stub,
> only by the OS, which is why it is passed in memory like this.
> 
> The memory in question is allocated as EFI_LOADER_DATA, and so we are
> relying on the OS to know that this memory is special, and needs to be
> preserved.
> 
> I think the solution here is to use a different memory type:
> 
> --- a/drivers/firmware/efi/libstub/tpm.c
> +++ b/drivers/firmware/efi/libstub/tpm.c
> @@ -96,7 +96,7 @@ static void efi_retrieve_tcg2_eventlog(int version,
> efi_physical_addr_t log_loca
>         }
> 
>         /* Allocate space for the logs and copy them. */
> -       status = efi_bs_call(allocate_pool, EFI_LOADER_DATA,
> +       status = efi_bs_call(allocate_pool, EFI_ACPI_RECLAIM_MEMORY,
>                              sizeof(*log_tbl) + log_size, (void **)&log_tbl);
> 
>         if (status != EFI_SUCCESS) {
> 
> which will be treated appropriately by the existing EFI-to-E820
> conversion logic.

I have tested above diff, and it works! No memory corruption.

The region comes up as ACPI data:
[    0.000000] BIOS-e820: [mem 0x000000007fb6d000-0x000000007fb7efff] ACPI data                                                                                                                               

and kexec doesnt interfere with it.

Thanks,
Usama


  reply	other threads:[~2024-09-12 15:35 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-11 10:41 [RFC] efi/tpm: add efi.tpm_log as a reserved region in 820_table_firmware Usama Arif
2024-09-11 11:51 ` Ard Biesheuvel
2024-09-11 14:34   ` Usama Arif
2024-09-12 10:23   ` Usama Arif
2024-09-12 10:51     ` Ard Biesheuvel
2024-09-12 11:17       ` Usama Arif
2024-09-12 13:03       ` Breno Leitao
2024-09-12 13:10         ` Ard Biesheuvel
2024-09-12 13:54           ` Usama Arif
2024-09-12 14:05             ` Ard Biesheuvel
2024-09-12 14:14               ` Ard Biesheuvel
2024-09-13 10:56                 ` Dave Young
2024-09-13 11:06                   ` Usama Arif
2024-09-13 11:13                     ` Dave Young
2024-09-13 11:49                       ` Dave Young
2024-09-13 11:56                         ` Usama Arif
2024-09-13 12:52                           ` Dave Young
2024-09-14  6:46                   ` Dave Young
2024-09-14  8:31                     ` Ard Biesheuvel
2024-09-14  9:24                       ` Dave Young
2024-09-14  9:46                         ` Dave Young
2024-09-12 14:29           ` Breno Leitao
2024-09-12 15:21             ` Ard Biesheuvel
2024-09-12 15:35               ` Usama Arif [this message]
2024-09-12 15:45                 ` Ard Biesheuvel
2024-09-12 16:22         ` James Bottomley
2024-09-13 11:57           ` Breno Leitao
2024-09-13 12:07             ` James Bottomley
2024-09-16 20:20               ` Eric W. Biederman
2024-09-17  6:45                 ` Ard Biesheuvel
2024-09-17 15:24                   ` Eric W. Biederman
2024-09-17 15:35                     ` Ard Biesheuvel
2024-09-18  3:13                       ` Eric W. Biederman
2024-09-18  7:36                         ` Ard Biesheuvel
2024-10-09  9:10                           ` Jonathan McDowell
2024-10-09 10:46                             ` Breno Leitao
2024-10-09 14:05                               ` Jonathan McDowell

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=9d3962f1-96b6-44a3-a7d3-10fbfbe06164@gmail.com \
    --to=usamaarif642@gmail.com \
    --cc=ardb@kernel.org \
    --cc=bhe@redhat.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=ebiederm@xmission.com \
    --cc=gourry@gourry.net \
    --cc=kexec@lists.infradead.org \
    --cc=leitao@debian.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rmikey@meta.com \
    --cc=tglx@linutronix.de \
    --cc=vgoyal@redhat.com \
    --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