Re: [PATCH v7 6/6] x86/efi: Safely enable unaccepted memory in UEFI

From: Tom Lendacky
Date: Wed Apr 05 2023 - 16:12:32 EST


On 4/5/23 14:06, Kirill A. Shutemov wrote:
On Wed, Apr 05, 2023 at 09:15:15AM -0700, Dave Hansen wrote:
On 4/5/23 06:44, Ard Biesheuvel wrote:
Given that the intent here is to retain compatibility with
unenlightened workloads (i.e., which do not upgrade their kernels), I
think it is perfectly reasonable to drop this from mainline at some
point.

OK, so there are three firmware types that matter:

1. Today's SEV-SNP deployed firmware.

SNP support is originally available as part of the edk2-stable202202 release.

2. Near future SEV-SNP firmware that exposes the new ExitBootServices()
protocol that allows guests that speak the protocol to boot faster
by participating in the unaccepted memory dance.

This is already out and available as part of the edk2-stable202302 release.

But it did come out after general SNP support, so the near future terminology works.

3. Far future firmware that doesn't have the ExitBootServices() protocol

There are also three kernel types:
1. Old kernels with zero unaccepted memory support: no
ExitBootServices() protocol support and no hypercalls to accept pages
2. Kernels that can accept pages and twiddle the ExitBootServices() flag
3. Future kernels that can accept pages, but have had ExitBootServices()
support removed.

That leads to nine possible mix-and-match firmware/kernel combos. I'm
personally assuming that folks are going to *try* to run with all of
these combos and will send us kernel folks bug reports if they see
regressions. Let's just enumerate all of them and their implications
before we go consult our crystal balls about what folks will actually do
in the future.

So, here we go:

| Kernel |
| |
| Unenlightened | Enlightened | Dropped UEFI |
Firmware | ~5.19?? | ~6.4?? | protocol |
|---------------+-------------+--------------|
Deployed | Slow boot | Slow boot | Slow boot |
Near future | Slow boot | Fast boot | Slow boot |
Far future | Crashes?? | Fast Boot | Fast boot |

I hope I got that all right.

Looks correct to me (with Kirill's description below in place of the "Crashes??").


The thing that worries me is the "Near future firmware" where someone
runs a ~6.4 kernel and has a fast boot experience. They upgrade to a
newer, "dropped protocol" kernel and their boot gets slower.

Right, so that is what begs the question of when to actually drop the call. Or does it really need to be dropped? It's a small patch to execute a boot services call, I guess I don't see the big deal of it being there.
If the firmware still has the protocol, the call is made, if it doesn't, its not. In the overall support for unaccepted memory, this seems to be a very minor piece.


I'm also a little fuzzy about what an ancient enlightened kernel would
do on a "far future" firmware that requires unaccepted memory support.
I _think_ those kernels would hit some unaccepted memory, and
#VC/#VE/#whatever and die. Is that right, or is there some fallback there?

The far future firmware in this scheme would expose unaccepted memory in
EFI memory map without need of kernel to declare unaccepted memory
support. The unenlightened kernel in this case will not be able to use the
memory and consider it reserved. Only memory accepted by firmware will be
accessible. Depending on how much memory firmware would pre-accept it can
be OOM, but more likely it will boot fine with the fraction of memory
usable.

Right, since a typical Qemu VM has a 2GB hole for PCI/MMIO, the guest is likely to only see 2GB of memory available to it.

Thanks,
Tom