Re: [PATCH v2] x86/kernel: skip ROM range scans and validation for SEV-SNP guests

From: Ard Biesheuvel
Date: Mon Mar 11 2024 - 06:43:32 EST


On Sun, 10 Mar 2024 at 18:12, Kevin Loughlin <kevinloughlin@xxxxxxxxxx> wrote:
>
> On Fri, Mar 8, 2024 at 3:44 AM Ard Biesheuvel <ardb@xxxxxxxxxx> wrote:
> >
> > On Fri, 8 Mar 2024 at 12:01, Borislav Petkov <bp@xxxxxxxxx> wrote:
> > >
> > > On Fri, Mar 08, 2024 at 11:30:50AM +0100, Ard Biesheuvel wrote:
> > > > Agree with the analysis and the conclusion. However, this will need to
> > > > be split into generic and x86 specific changes, given that the DMI
> > > > code is shared between all architectures, and explicitly checking for
> > > > SEV-SNP support in generic code is not appropriate.
> > > >
> > > > So what we will need is:
> > >
> > > I was actually thinking of:
> > >
> > > x86_init.resources.probe_roms = snp_probe_roms;
> > >
> > > and snp_probe_roms() is an empty stub.
> > >
> > > Problem solved without ugly sprinkling of checks everywhere.
> > >
> >
> > Indeed. Setting the override could be done in
> > init_hypervisor_platform(), which is called right before from
> > setup_arch().
>
> The call to init_hypervisor_platform() has a comment saying it must
> come after dmi_setup() (i.e., init_hypervisor_platform() would *not*
> work for doing a dmi_setup() override), so I'm currently planning to
> do the overrides at the end of snp_init() in arch/x86/kernel/sev.c
> instead (which comes before both). This would be somewhat similar to
> how there are early setup functions for specific platforms that
> perform init overrides for different reasons (example:
> x86_ce4100_early_setup()). Open to other locations of course.

snp_init() is one of those routines that executes from the 1:1 early
mapping of memory.

Setting a global function pointer will therefore involve special
tricks to ensure that taking the address of this function will produce
an address that uses the correct translation.

So if we can, it would be better to put it somewhere else.