2009-08-19 14:48:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Thomas Gleixner <tglx@linutronix.de>
|
|
|
|
*
|
|
|
|
* For licencing details see kernel-base/COPYING
|
|
|
|
*/
|
x86/sev: Skip ROM range scans and validation for SEV-SNP guests
SEV-SNP requires encrypted memory to be validated before access.
Because the ROM memory range is not part of the e820 table, it is not
pre-validated by the BIOS. Therefore, if a SEV-SNP guest kernel wishes
to access this range, the guest must first validate the range.
The current SEV-SNP code does indeed scan the ROM range during early
boot and thus attempts to validate the ROM range in probe_roms().
However, this behavior is neither sufficient nor necessary for the
following reasons:
* With regards to sufficiency, if EFI_CONFIG_TABLES are not enabled and
CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK is set, the kernel will
attempt to access the memory at SMBIOS_ENTRY_POINT_SCAN_START (which
falls in the ROM range) prior to validation.
For example, Project Oak Stage 0 provides a minimal guest firmware
that currently meets these configuration conditions, meaning guests
booting atop Oak Stage 0 firmware encounter a problematic call chain
during dmi_setup() -> dmi_scan_machine() that results in a crash
during boot if SEV-SNP is enabled.
* With regards to necessity, SEV-SNP guests generally read garbage
(which changes across boots) from the ROM range, meaning these scans
are unnecessary. The guest reads garbage because the legacy ROM range
is unencrypted data but is accessed via an encrypted PMD during early
boot (where the PMD is marked as encrypted due to potentially mapping
actually-encrypted data in other PMD-contained ranges).
In one exceptional case, EISA probing treats the ROM range as
unencrypted data, which is inconsistent with other probing.
Continuing to allow SEV-SNP guests to use garbage and to inconsistently
classify ROM range encryption status can trigger undesirable behavior.
For instance, if garbage bytes appear to be a valid signature, memory
may be unnecessarily reserved for the ROM range. Future code or other
use cases may result in more problematic (arbitrary) behavior that
should be avoided.
While one solution would be to overhaul the early PMD mapping to always
treat the ROM region of the PMD as unencrypted, SEV-SNP guests do not
currently rely on data from the ROM region during early boot (and even
if they did, they would be mostly relying on garbage data anyways).
As a simpler solution, skip the ROM range scans (and the otherwise-
necessary range validation) during SEV-SNP guest early boot. The
potential SEV-SNP guest crash due to lack of ROM range validation is
thus avoided by simply not accessing the ROM range.
In most cases, skip the scans by overriding problematic x86_init
functions during sme_early_init() to SNP-safe variants, which can be
likened to x86_init overrides done for other platforms (ex: Xen); such
overrides also avoid the spread of cc_platform_has() checks throughout
the tree.
In the exceptional EISA case, still use cc_platform_has() for the
simplest change, given (1) checks for guest type (ex: Xen domain status)
are already performed here, and (2) these checks occur in a subsys
initcall instead of an x86_init function.
[ bp: Massage commit message, remove "we"s. ]
Fixes: 9704c07bf9f7 ("x86/kernel: Validate ROM memory before accessing when SEV-SNP is active")
Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20240313121546.2964854-1-kevinloughlin@google.com
2024-03-13 12:15:46 +00:00
|
|
|
#include <linux/dmi.h>
|
2009-08-19 14:48:38 +02:00
|
|
|
#include <linux/init.h>
|
2009-08-29 17:51:26 +02:00
|
|
|
#include <linux/ioport.h>
|
2016-07-13 20:18:56 -04:00
|
|
|
#include <linux/export.h>
|
2010-10-06 16:12:28 -04:00
|
|
|
#include <linux/pci.h>
|
2024-08-09 17:52:55 +02:00
|
|
|
#include <linux/acpi.h>
|
2009-08-19 14:48:38 +02:00
|
|
|
|
2018-02-20 20:05:05 +02:00
|
|
|
#include <asm/acpi.h>
|
2009-08-19 14:36:27 +02:00
|
|
|
#include <asm/bios_ebda.h>
|
2009-08-20 13:19:57 +02:00
|
|
|
#include <asm/paravirt.h>
|
2009-08-29 16:24:51 +02:00
|
|
|
#include <asm/pci_x86.h>
|
2009-08-20 10:41:58 +02:00
|
|
|
#include <asm/mpspec.h>
|
2009-08-19 14:55:50 +02:00
|
|
|
#include <asm/setup.h>
|
2009-08-19 12:35:53 +02:00
|
|
|
#include <asm/apic.h>
|
2017-01-27 10:27:10 +01:00
|
|
|
#include <asm/e820/api.h>
|
2009-08-19 15:37:03 +02:00
|
|
|
#include <asm/time.h>
|
2009-08-20 09:41:38 +02:00
|
|
|
#include <asm/irq.h>
|
2012-03-28 12:37:36 -04:00
|
|
|
#include <asm/io_apic.h>
|
2012-09-26 12:44:37 +02:00
|
|
|
#include <asm/hpet.h>
|
2019-11-20 15:33:57 +01:00
|
|
|
#include <asm/memtype.h>
|
2009-08-20 17:06:25 +02:00
|
|
|
#include <asm/tsc.h>
|
2009-10-27 16:34:44 +09:00
|
|
|
#include <asm/iommu.h>
|
2011-11-10 13:43:05 +00:00
|
|
|
#include <asm/mach_traps.h>
|
2020-08-26 13:16:50 +02:00
|
|
|
#include <asm/irqdomain.h>
|
2022-11-23 12:45:23 +01:00
|
|
|
#include <asm/realmode.h>
|
2009-08-19 14:48:38 +02:00
|
|
|
|
x86: delete __cpuinit usage from all x86 files
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
are flagged as __cpuinit -- so if we remove the __cpuinit from
arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
content into no-ops as early as possible, since that will get rid
of these warnings. In any case, they are temporary and harmless.
This removes all the arch/x86 uses of the __cpuinit macros from
all C files. x86 only had the one __CPUINIT used in assembly files,
and it wasn't paired off with a .previous or a __FINIT, so we can
delete it directly w/o any corresponding additional change there.
[1] https://lkml.org/lkml/2013/5/20/589
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2013-06-18 18:23:59 -04:00
|
|
|
void x86_init_noop(void) { }
|
2009-08-20 12:05:01 +02:00
|
|
|
void __init x86_init_uint_noop(unsigned int unused) { }
|
2018-02-21 10:42:32 +01:00
|
|
|
static int __init iommu_init_noop(void) { return 0; }
|
|
|
|
static void iommu_shutdown_noop(void) { }
|
2019-07-16 12:26:09 +08:00
|
|
|
bool __init bool_x86_init_noop(void) { return false; }
|
|
|
|
void x86_op_int_noop(int cpu) { }
|
2023-04-10 22:55:28 -07:00
|
|
|
int set_rtc_noop(const struct timespec64 *now) { return -EINVAL; }
|
|
|
|
void get_rtc_noop(struct timespec64 *now) { }
|
2019-10-10 17:28:56 +08:00
|
|
|
|
|
|
|
static __initconst const struct of_device_id of_cmos_match[] = {
|
|
|
|
{ .compatible = "motorola,mc146818" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allow devicetree configured systems to disable the RTC by setting the
|
|
|
|
* corresponding DT node's status property to disabled. Code is optimized
|
|
|
|
* out for CONFIG_OF=n builds.
|
|
|
|
*/
|
|
|
|
static __init void x86_wallclock_init(void)
|
|
|
|
{
|
|
|
|
struct device_node *node = of_find_matching_node(NULL, of_cmos_match);
|
|
|
|
|
|
|
|
if (node && !of_device_is_available(node)) {
|
|
|
|
x86_platform.get_wallclock = get_rtc_noop;
|
|
|
|
x86_platform.set_wallclock = set_rtc_noop;
|
|
|
|
}
|
|
|
|
}
|
2009-08-19 14:48:38 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The platform setup functions are preset with the default functions
|
|
|
|
* for standard PC hardware.
|
|
|
|
*/
|
2009-09-16 08:42:26 +02:00
|
|
|
struct x86_init_ops x86_init __initdata = {
|
2009-08-19 14:43:56 +02:00
|
|
|
|
|
|
|
.resources = {
|
2011-03-08 10:36:19 -08:00
|
|
|
.probe_roms = probe_roms,
|
2009-08-19 14:55:50 +02:00
|
|
|
.reserve_resources = reserve_standard_io_resources,
|
2017-01-28 09:58:49 +01:00
|
|
|
.memory_setup = e820__memory_setup_default,
|
x86/sev: Skip ROM range scans and validation for SEV-SNP guests
SEV-SNP requires encrypted memory to be validated before access.
Because the ROM memory range is not part of the e820 table, it is not
pre-validated by the BIOS. Therefore, if a SEV-SNP guest kernel wishes
to access this range, the guest must first validate the range.
The current SEV-SNP code does indeed scan the ROM range during early
boot and thus attempts to validate the ROM range in probe_roms().
However, this behavior is neither sufficient nor necessary for the
following reasons:
* With regards to sufficiency, if EFI_CONFIG_TABLES are not enabled and
CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK is set, the kernel will
attempt to access the memory at SMBIOS_ENTRY_POINT_SCAN_START (which
falls in the ROM range) prior to validation.
For example, Project Oak Stage 0 provides a minimal guest firmware
that currently meets these configuration conditions, meaning guests
booting atop Oak Stage 0 firmware encounter a problematic call chain
during dmi_setup() -> dmi_scan_machine() that results in a crash
during boot if SEV-SNP is enabled.
* With regards to necessity, SEV-SNP guests generally read garbage
(which changes across boots) from the ROM range, meaning these scans
are unnecessary. The guest reads garbage because the legacy ROM range
is unencrypted data but is accessed via an encrypted PMD during early
boot (where the PMD is marked as encrypted due to potentially mapping
actually-encrypted data in other PMD-contained ranges).
In one exceptional case, EISA probing treats the ROM range as
unencrypted data, which is inconsistent with other probing.
Continuing to allow SEV-SNP guests to use garbage and to inconsistently
classify ROM range encryption status can trigger undesirable behavior.
For instance, if garbage bytes appear to be a valid signature, memory
may be unnecessarily reserved for the ROM range. Future code or other
use cases may result in more problematic (arbitrary) behavior that
should be avoided.
While one solution would be to overhaul the early PMD mapping to always
treat the ROM region of the PMD as unencrypted, SEV-SNP guests do not
currently rely on data from the ROM region during early boot (and even
if they did, they would be mostly relying on garbage data anyways).
As a simpler solution, skip the ROM range scans (and the otherwise-
necessary range validation) during SEV-SNP guest early boot. The
potential SEV-SNP guest crash due to lack of ROM range validation is
thus avoided by simply not accessing the ROM range.
In most cases, skip the scans by overriding problematic x86_init
functions during sme_early_init() to SNP-safe variants, which can be
likened to x86_init overrides done for other platforms (ex: Xen); such
overrides also avoid the spread of cc_platform_has() checks throughout
the tree.
In the exceptional EISA case, still use cc_platform_has() for the
simplest change, given (1) checks for guest type (ex: Xen domain status)
are already performed here, and (2) these checks occur in a subsys
initcall instead of an x86_init function.
[ bp: Massage commit message, remove "we"s. ]
Fixes: 9704c07bf9f7 ("x86/kernel: Validate ROM memory before accessing when SEV-SNP is active")
Signed-off-by: Kevin Loughlin <kevinloughlin@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: <stable@kernel.org>
Link: https://lore.kernel.org/r/20240313121546.2964854-1-kevinloughlin@google.com
2024-03-13 12:15:46 +00:00
|
|
|
.dmi_setup = dmi_setup,
|
2009-08-19 14:43:56 +02:00
|
|
|
},
|
2009-08-20 12:05:01 +02:00
|
|
|
|
|
|
|
.mpparse = {
|
2009-08-20 09:27:29 +02:00
|
|
|
.setup_ioapic_ids = x86_init_noop,
|
2024-02-13 22:05:02 +01:00
|
|
|
.find_mptable = mpparse_find_mptable,
|
2024-02-13 22:05:14 +01:00
|
|
|
.early_parse_smp_cfg = mpparse_parse_early_smp_config,
|
|
|
|
.parse_smp_cfg = mpparse_parse_smp_config,
|
2009-08-20 12:05:01 +02:00
|
|
|
},
|
2009-08-20 09:41:38 +02:00
|
|
|
|
|
|
|
.irqs = {
|
|
|
|
.pre_vector_init = init_ISA_irqs,
|
2009-08-20 09:59:09 +02:00
|
|
|
.intr_init = native_init_IRQ,
|
2020-01-23 12:54:53 +01:00
|
|
|
.intr_mode_select = apic_intr_mode_select,
|
2020-08-26 13:16:50 +02:00
|
|
|
.intr_mode_init = apic_intr_mode_init,
|
|
|
|
.create_pci_msi_domain = native_create_pci_msi_domain,
|
2009-08-20 09:41:38 +02:00
|
|
|
},
|
2009-08-20 13:04:10 +02:00
|
|
|
|
|
|
|
.oem = {
|
|
|
|
.arch_setup = x86_init_noop,
|
2009-08-20 13:19:57 +02:00
|
|
|
.banner = default_banner,
|
2009-08-20 13:04:10 +02:00
|
|
|
},
|
2009-08-20 14:30:02 +02:00
|
|
|
|
|
|
|
.paging = {
|
2012-08-21 21:22:38 +01:00
|
|
|
.pagetable_init = native_pagetable_init,
|
2009-08-20 14:30:02 +02:00
|
|
|
},
|
2009-08-19 12:35:53 +02:00
|
|
|
|
|
|
|
.timers = {
|
|
|
|
.setup_percpu_clockev = setup_boot_APIC_clock,
|
2009-08-19 15:37:03 +02:00
|
|
|
.timer_init = hpet_time_init,
|
2019-10-10 17:28:56 +08:00
|
|
|
.wallclock_init = x86_wallclock_init,
|
2009-08-19 12:35:53 +02:00
|
|
|
},
|
2009-11-10 19:46:12 +09:00
|
|
|
|
|
|
|
.iommu = {
|
|
|
|
.iommu_init = iommu_init_noop,
|
|
|
|
},
|
2009-08-29 16:24:51 +02:00
|
|
|
|
|
|
|
.pci = {
|
|
|
|
.init = x86_default_pci_init,
|
2009-08-29 17:47:33 +02:00
|
|
|
.init_irq = x86_default_pci_init_irq,
|
2009-08-29 17:51:26 +02:00
|
|
|
.fixup_irqs = x86_default_pci_fixup_irqs,
|
2009-08-29 16:24:51 +02:00
|
|
|
},
|
2017-11-09 14:27:35 +01:00
|
|
|
|
|
|
|
.hyper = {
|
|
|
|
.init_platform = x86_init_noop,
|
2017-11-09 14:27:38 +01:00
|
|
|
.guest_late_init = x86_init_noop,
|
2017-11-09 14:27:35 +01:00
|
|
|
.x2apic_available = bool_x86_init_noop,
|
2020-10-24 22:35:32 +01:00
|
|
|
.msi_ext_dest_id = bool_x86_init_noop,
|
2017-11-09 14:27:35 +01:00
|
|
|
.init_mem_mapping = x86_init_noop,
|
2018-04-10 16:36:10 -07:00
|
|
|
.init_after_bootmem = x86_init_noop,
|
2017-11-09 14:27:35 +01:00
|
|
|
},
|
2018-02-19 11:09:05 +01:00
|
|
|
|
|
|
|
.acpi = {
|
2019-08-19 17:17:51 -07:00
|
|
|
.set_root_pointer = x86_default_set_root_pointer,
|
2018-10-10 08:14:56 +02:00
|
|
|
.get_root_pointer = x86_default_get_root_pointer,
|
2018-02-20 20:05:05 +02:00
|
|
|
.reduced_hw_early_init = acpi_generic_reduced_hw_init,
|
2018-02-19 11:09:05 +01:00
|
|
|
},
|
2009-08-19 12:35:53 +02:00
|
|
|
};
|
|
|
|
|
x86: delete __cpuinit usage from all x86 files
The __cpuinit type of throwaway sections might have made sense
some time ago when RAM was more constrained, but now the savings
do not offset the cost and complications. For example, the fix in
commit 5e427ec2d0 ("x86: Fix bit corruption at CPU resume time")
is a good example of the nasty type of bugs that can be created
with improper use of the various __init prefixes.
After a discussion on LKML[1] it was decided that cpuinit should go
the way of devinit and be phased out. Once all the users are gone,
we can then finally remove the macros themselves from linux/init.h.
Note that some harmless section mismatch warnings may result, since
notify_cpu_starting() and cpu_up() are arch independent (kernel/cpu.c)
are flagged as __cpuinit -- so if we remove the __cpuinit from
arch specific callers, we will also get section mismatch warnings.
As an intermediate step, we intend to turn the linux/init.h cpuinit
content into no-ops as early as possible, since that will get rid
of these warnings. In any case, they are temporary and harmless.
This removes all the arch/x86 uses of the __cpuinit macros from
all C files. x86 only had the one __CPUINIT used in assembly files,
and it wasn't paired off with a .previous or a __FINIT, so we can
delete it directly w/o any corresponding additional change there.
[1] https://lkml.org/lkml/2013/5/20/589
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Acked-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
2013-06-18 18:23:59 -04:00
|
|
|
struct x86_cpuinit_ops x86_cpuinit = {
|
2012-02-07 15:52:44 +01:00
|
|
|
.early_percpu_clock_init = x86_init_noop,
|
2009-08-19 12:35:53 +02:00
|
|
|
.setup_percpu_clockev = setup_secondary_APIC_clock,
|
2023-05-31 09:44:26 +02:00
|
|
|
.parallel_bringup = true,
|
2009-08-19 14:48:38 +02:00
|
|
|
};
|
2009-08-20 17:06:25 +02:00
|
|
|
|
2010-02-26 10:49:12 -06:00
|
|
|
static void default_nmi_init(void) { };
|
|
|
|
|
2024-06-14 12:58:52 +03:00
|
|
|
static int enc_status_change_prepare_noop(unsigned long vaddr, int npages, bool enc) { return 0; }
|
|
|
|
static int enc_status_change_finish_noop(unsigned long vaddr, int npages, bool enc) { return 0; }
|
2022-02-22 22:35:28 -06:00
|
|
|
static bool enc_tlb_flush_required_noop(bool enc) { return false; }
|
|
|
|
static bool enc_cache_flush_required_noop(void) { return false; }
|
2024-06-14 12:58:55 +03:00
|
|
|
static void enc_kexec_begin_noop(void) {}
|
|
|
|
static void enc_kexec_finish_noop(void) {}
|
2023-03-08 18:40:02 -08:00
|
|
|
static bool is_private_mmio_noop(u64 addr) {return false; }
|
2022-02-22 22:35:28 -06:00
|
|
|
|
2016-08-08 16:29:06 -07:00
|
|
|
struct x86_platform_ops x86_platform __ro_after_init = {
|
2018-07-19 16:55:45 -04:00
|
|
|
.calibrate_cpu = native_calibrate_cpu_early,
|
2009-08-20 17:06:25 +02:00
|
|
|
.calibrate_tsc = native_calibrate_tsc,
|
2009-09-10 10:48:56 +08:00
|
|
|
.get_wallclock = mach_get_cmos_time,
|
2022-08-13 15:10:34 +02:00
|
|
|
.set_wallclock = mach_set_cmos_time,
|
2009-10-27 16:34:44 +09:00
|
|
|
.iommu_shutdown = iommu_shutdown_noop,
|
2009-11-23 14:46:07 -08:00
|
|
|
.is_untracked_pat_range = is_ISA_range,
|
2010-07-05 23:03:18 +08:00
|
|
|
.nmi_init = default_nmi_init,
|
2011-11-10 13:43:05 +00:00
|
|
|
.get_nmi_reason = default_get_nmi_reason,
|
2022-02-22 22:35:28 -06:00
|
|
|
.save_sched_clock_state = tsc_save_sched_clock_state,
|
|
|
|
.restore_sched_clock_state = tsc_restore_sched_clock_state,
|
2022-11-23 12:45:23 +01:00
|
|
|
.realmode_reserve = reserve_real_mode,
|
|
|
|
.realmode_init = init_real_mode,
|
2017-11-09 14:27:35 +01:00
|
|
|
.hyper.pin_vcpu = x86_op_int_noop,
|
2023-03-08 18:40:02 -08:00
|
|
|
.hyper.is_private_mmio = is_private_mmio_noop,
|
2022-02-22 22:35:28 -06:00
|
|
|
|
|
|
|
.guest = {
|
|
|
|
.enc_status_change_prepare = enc_status_change_prepare_noop,
|
|
|
|
.enc_status_change_finish = enc_status_change_finish_noop,
|
|
|
|
.enc_tlb_flush_required = enc_tlb_flush_required_noop,
|
|
|
|
.enc_cache_flush_required = enc_cache_flush_required_noop,
|
2024-06-14 12:58:55 +03:00
|
|
|
.enc_kexec_begin = enc_kexec_begin_noop,
|
|
|
|
.enc_kexec_finish = enc_kexec_finish_noop,
|
2022-02-22 22:35:28 -06:00
|
|
|
},
|
2009-08-20 17:06:25 +02:00
|
|
|
};
|
2010-07-07 16:57:46 -07:00
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(x86_platform);
|
2013-08-09 22:27:06 +02:00
|
|
|
|
2018-02-14 13:46:55 +08:00
|
|
|
struct x86_apic_ops x86_apic_ops __ro_after_init = {
|
|
|
|
.io_apic_read = native_io_apic_read,
|
|
|
|
.restore = native_restore_boot_irq_mode,
|
2012-03-28 12:37:36 -04:00
|
|
|
};
|