linux-efi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: Demi Marie Obenour <demi@invisiblethingslab.com>
Cc: "Jan Beulich" <jbeulich@suse.com>,
	xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org,
	linux-efi@vger.kernel.org, "Juergen Gross" <jgross@suse.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Oleksandr Tyshchenko" <oleksandr_tyshchenko@epam.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Anton Vorontsov" <anton@enomsg.org>,
	"Colin Cross" <ccross@android.com>,
	"Tony Luck" <tony.luck@intel.com>,
	"Marek Marczykowski-Górecki" <marmarek@invisiblethingslab.com>
Subject: Re: [PATCH v4 1/2] Avoid using EFI tables Xen may have clobbered
Date: Fri, 30 Sep 2022 20:27:09 +0200	[thread overview]
Message-ID: <CAMj1kXHBBbCNV3CLesqZi7ttmmi8y4tZ1KO5vievy_CJrU2o3Q@mail.gmail.com> (raw)
In-Reply-To: <YzcjeiOW8+i2Zxsd@itl-email>

On Fri, 30 Sept 2022 at 19:12, Demi Marie Obenour
<demi@invisiblethingslab.com> wrote:
>
> On Fri, Sep 30, 2022 at 06:30:57PM +0200, Ard Biesheuvel wrote:
> > On Fri, 30 Sept 2022 at 08:44, Jan Beulich <jbeulich@suse.com> wrote:
> > >
> > > On 30.09.2022 01:02, Demi Marie Obenour wrote:
> > > > Memory of type EFI_CONVENTIONAL_MEMORY, EFI_LOADER_CODE, EFI_LOADER_DATA,
> > > > EFI_BOOT_SERVICES_CODE, and EFI_BOOT_SERVICES_DATA may be clobbered by
> > > > Xen before Linux gets to start using it.  Therefore, Linux under Xen
> > > > must not use EFI tables from such memory.  Most of the remaining EFI
> > > > memory types are not suitable for EFI tables, leaving only
> > > > EFI_ACPI_RECLAIM_MEMORY, EFI_RUNTIME_SERVICES_DATA, and
> > > > EFI_RUNTIME_SERVICES_CODE.  When running under Xen, Linux should only
> > > > use tables that are located in one of these types of memory.
> > > >
> > > > This patch ensures this, and also adds a function
> > > > (xen_config_table_memory_region_max()) that will be used later to
> > > > replace the usage of the EFI memory map in esrt.c when running under
> > > > Xen.  This function can also be used in mokvar-table.c and efi-bgrt.c,
> > > > but I have not implemented this.
> > > >
> > > > Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
> > >
> > > In Xen we don't clobber EfiBootServices{Code,Data} when xen.efi was passed
> > > "-mapbs". Should we perhaps extend the interface such that Dom0 can then
> > > also use tables located in such regions, perhaps by faking
> > > EFI_MEMORY_RUNTIME in the attributes returned by XEN_FW_EFI_MEM_INFO?
> > >
> >
> > I know this ship has sailed for x86, but for the sake of other
> > architectures, I'd strongly recommend leaving the EFI_MEMORY_RUNTIME
> > bits alone, for the same reasons I gave earlier. (Runtime mappings for
> > the firmware code itself, page table fragmentation etc etc)
>
> Why do you say that it has sailed for x86?
>

The x86 EFI code in Linux makes changes to the EFI memory map in many
different places in the code. On other architectures, we have managed
to avoid this, so that the EFI memory map is always identical to the
one provided by the firmware at boot.

> > I know very little about Xen, but based on the context you provided in
> > this thread, I'd say that the best approach from the Xen side is to
> > convert all EfiBootServicesData regions that have configuration tables
> > pointing into them into EfiAcpiReclaimMemory.
>
> Should Xen convert the entire region, or should it try to reserve only
> the memory it needs?  The latter would require it to parse the
> configuration tables.  Is there a list of configuration tables that can
> legitimately be in EfiBootServicesData regions?
>

Not really, no. So you would have to convert the entire region
/unless/ Xen knows the GUID, and therefore knows how to derive the
size of the table, allowing it to reserve memory more conservatively.
However, I doubt whether this is worth it: splitting entries implies
rewriting the memory map, which is a thing I'd rather avoid if I were
in your shoes.

> > I take it XEN_FW_EFI_MEM_INFO is an existing interface? If so, you
> > might do the same for the returned type - EfiBootServicesData ->
> > EfiAcpiReclaimMemory, and not muck about with the EFI_MEMORY_RUNTIME
> > attribute.
>
> It is indeed an existing interface, and this is a much better idea than
> what you proposed.

Right.

  reply	other threads:[~2022-09-30 18:27 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-29 23:02 [PATCH v4 0/2] EFI improvements for Xen dom0 Demi Marie Obenour
2022-09-29 23:02 ` [PATCH v4 1/2] Avoid using EFI tables Xen may have clobbered Demi Marie Obenour
2022-09-30  6:44   ` Jan Beulich
2022-09-30 16:30     ` Ard Biesheuvel
2022-09-30 17:11       ` Demi Marie Obenour
2022-09-30 18:27         ` Ard Biesheuvel [this message]
2022-09-30 18:50           ` Demi Marie Obenour
2022-10-01  0:30           ` Demi Marie Obenour
2022-10-04  8:22             ` Jan Beulich
2022-10-04 15:46               ` Demi Marie Obenour
2022-10-05  6:15                 ` Jan Beulich
2022-10-05 18:11                   ` Demi Marie Obenour
2022-10-05 21:28                     ` Ard Biesheuvel
2022-10-06  1:40                       ` Demi Marie Obenour
2022-10-06  7:31                         ` Ard Biesheuvel
2022-10-06 14:43                           ` Demi Marie Obenour
2022-10-06 16:19                             ` Ard Biesheuvel
2022-10-06 17:22                               ` Demi Marie Obenour
2022-10-06 17:56                                 ` Ard Biesheuvel
2022-10-06  9:22                     ` Jan Beulich
2022-09-30 16:38     ` Demi Marie Obenour
2022-09-30 16:25   ` Ard Biesheuvel
2022-09-30 18:15     ` Demi Marie Obenour
2022-09-30 18:42       ` Ard Biesheuvel
2022-09-30 19:00         ` Demi Marie Obenour
2022-09-29 23:02 ` [PATCH v4 2/2] Support ESRT in Xen dom0 Demi Marie Obenour
2022-09-30 16:36   ` Ard Biesheuvel
2022-09-30 18:21     ` Demi Marie Obenour
2022-09-30 19:11       ` Ard Biesheuvel
2022-09-30 20:20         ` Demi Marie Obenour
2022-09-30 20:59           ` Ard Biesheuvel
2022-09-30 21:24             ` Ard Biesheuvel
2022-09-30 22:22               ` Demi Marie Obenour
2022-09-30 22:25             ` Demi Marie Obenour

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=CAMj1kXHBBbCNV3CLesqZi7ttmmi8y4tZ1KO5vievy_CJrU2o3Q@mail.gmail.com \
    --to=ardb@kernel.org \
    --cc=anton@enomsg.org \
    --cc=ccross@android.com \
    --cc=demi@invisiblethingslab.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=keescook@chromium.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marmarek@invisiblethingslab.com \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=sstabellini@kernel.org \
    --cc=tony.luck@intel.com \
    --cc=xen-devel@lists.xenproject.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;
as well as URLs for NNTP newsgroup(s).