Commit c5c30a37 authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Borislav Petkov (AMD)
Browse files

x86/boot: Move startup code out of __head section



Move startup code out of the __head section, now that this no longer has
a special significance. Move everything into .text or .init.text as
appropriate, so that startup code is not kept around unnecessarily.

  [ bp: Fold in hunk to fix 32-bit CPU hotplug:
    Reported-by: default avatarkernel test robot <oliver.sang@intel.com>
    Closes: https://lore.kernel.org/oe-lkp/202509022207.56fd97f4-lkp@intel.com

 ]

Signed-off-by: default avatarArd Biesheuvel <ardb@kernel.org>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/20250828102202.1849035-45-ardb+git@google.com
parent e7b88bc0
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -32,9 +32,6 @@ struct ghcb *boot_ghcb;
#undef __init
#define __init

#undef __head
#define __head

#define __BOOT_COMPRESSED

u8 snp_vmpl;
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@
static gate_desc bringup_idt_table[NUM_EXCEPTION_VECTORS] __page_aligned_data;

/* This may run while still in the direct mapping */
void __head startup_64_load_idt(void *vc_handler)
void startup_64_load_idt(void *vc_handler)
{
	struct desc_ptr desc = {
		.address = (unsigned long)rip_rel_ptr(bringup_idt_table),
@@ -46,7 +46,7 @@ void __head startup_64_load_idt(void *vc_handler)
/*
 * Setup boot CPU state needed before kernel switches to virtual addresses.
 */
void __head startup_64_setup_gdt_idt(void)
void __init startup_64_setup_gdt_idt(void)
{
	struct gdt_page *gp = rip_rel_ptr((void *)(__force unsigned long)&gdt_page);
	void *handler = NULL;
+2 −2
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ static inline bool check_la57_support(void)
	return true;
}

static unsigned long __head sme_postprocess_startup(struct boot_params *bp,
static unsigned long __init sme_postprocess_startup(struct boot_params *bp,
						    pmdval_t *pmd,
						    unsigned long p2v_offset)
{
@@ -84,7 +84,7 @@ static unsigned long __head sme_postprocess_startup(struct boot_params *bp,
 * the 1:1 mapping of memory. Kernel virtual addresses can be determined by
 * subtracting p2v_offset from the RIP-relative address.
 */
unsigned long __head __startup_64(unsigned long p2v_offset,
unsigned long __init __startup_64(unsigned long p2v_offset,
				  struct boot_params *bp)
{
	pmd_t (*early_pgts)[PTRS_PER_PMD] = rip_rel_ptr(early_dynamic_pgts);
+18 −18
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ static u32 cpuid_ext_range_max __ro_after_init;

bool sev_snp_needs_sfw;

void __head __noreturn
void __noreturn
sev_es_terminate(unsigned int set, unsigned int reason)
{
	u64 val = GHCB_MSR_TERM_REQ;
@@ -52,7 +52,7 @@ sev_es_terminate(unsigned int set, unsigned int reason)
/*
 * The hypervisor features are available from GHCB version 2 onward.
 */
u64 get_hv_features(void)
u64 __init get_hv_features(void)
{
	u64 val;

@@ -222,7 +222,7 @@ const struct snp_cpuid_table *snp_cpuid_get_table(void)
 *
 * Return: XSAVE area size on success, 0 otherwise.
 */
static u32 __head snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted)
static u32 snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted)
{
	const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();
	u64 xfeatures_found = 0;
@@ -258,7 +258,7 @@ static u32 __head snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted)
	return xsave_size;
}

static bool __head
static bool
snp_cpuid_get_validated_func(struct cpuid_leaf *leaf)
{
	const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();
@@ -300,7 +300,7 @@ static void snp_cpuid_hv_msr(void *ctx, struct cpuid_leaf *leaf)
		sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_CPUID_HV);
}

static int __head
static int
snp_cpuid_postprocess(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf),
		      void *ctx, struct cpuid_leaf *leaf)
{
@@ -396,7 +396,7 @@ snp_cpuid_postprocess(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf),
 * Returns -EOPNOTSUPP if feature not enabled. Any other non-zero return value
 * should be treated as fatal by caller.
 */
int __head snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf),
int snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf),
	      void *ctx, struct cpuid_leaf *leaf)
{
	const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();
@@ -439,7 +439,7 @@ int __head snp_cpuid(void (*cpuid_fn)(void *ctx, struct cpuid_leaf *leaf),
 * page yet, so it only supports the MSR based communication with the
 * hypervisor and only the CPUID exit-code.
 */
void __head do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
void do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
{
	unsigned int subfn = lower_bits(regs->cx, 32);
	unsigned int fn = lower_bits(regs->ax, 32);
@@ -515,7 +515,7 @@ struct cc_setup_data {
 * Search for a Confidential Computing blob passed in as a setup_data entry
 * via the Linux Boot Protocol.
 */
static __head
static __init
struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp)
{
	struct cc_setup_data *sd = NULL;
@@ -543,7 +543,7 @@ struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp)
 * mapping needs to be updated in sync with all the changes to virtual memory
 * layout and related mapping facilities throughout the boot process.
 */
static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
static void __init setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
{
	const struct snp_cpuid_table *cpuid_table_fw, *cpuid_table;
	int i;
@@ -571,7 +571,7 @@ static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
	}
}

static int __head svsm_call_msr_protocol(struct svsm_call *call)
static int svsm_call_msr_protocol(struct svsm_call *call)
{
	int ret;

@@ -582,7 +582,7 @@ static int __head svsm_call_msr_protocol(struct svsm_call *call)
	return ret;
}

static void __head svsm_pval_4k_page(unsigned long paddr, bool validate,
static void svsm_pval_4k_page(unsigned long paddr, bool validate,
			      struct svsm_ca *caa, u64 caa_pa)
{
	struct svsm_pvalidate_call *pc;
@@ -624,7 +624,7 @@ static void __head svsm_pval_4k_page(unsigned long paddr, bool validate,
	native_local_irq_restore(flags);
}

static void __head pvalidate_4k_page(unsigned long vaddr, unsigned long paddr,
static void pvalidate_4k_page(unsigned long vaddr, unsigned long paddr,
			      bool validate, struct svsm_ca *caa, u64 caa_pa)
{
	int ret;
@@ -645,7 +645,7 @@ static void __head pvalidate_4k_page(unsigned long vaddr, unsigned long paddr,
		sev_evict_cache((void *)vaddr, 1);
}

static void __head __page_state_change(unsigned long vaddr, unsigned long paddr,
static void __page_state_change(unsigned long vaddr, unsigned long paddr,
			        const struct psc_desc *desc)
{
	u64 val, msr;
@@ -684,7 +684,7 @@ static void __head __page_state_change(unsigned long vaddr, unsigned long paddr,
 * Maintain the GPA of the SVSM Calling Area (CA) in order to utilize the SVSM
 * services needed when not running in VMPL0.
 */
static bool __head svsm_setup_ca(const struct cc_blob_sev_info *cc_info,
static bool __init svsm_setup_ca(const struct cc_blob_sev_info *cc_info,
				 void *page)
{
	struct snp_secrets_page *secrets_page;
+7 −7
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@
/* Include code shared with pre-decompression boot stage */
#include "sev-shared.c"

void __head
void __init
early_set_pages_state(unsigned long vaddr, unsigned long paddr,
		      unsigned long npages, const struct psc_desc *desc)
{
@@ -63,7 +63,7 @@ early_set_pages_state(unsigned long vaddr, unsigned long paddr,
	}
}

void __head early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
					 unsigned long npages)
{
	struct psc_desc d = {
@@ -88,7 +88,7 @@ void __head early_snp_set_memory_private(unsigned long vaddr, unsigned long padd
	early_set_pages_state(vaddr, paddr, npages, &d);
}

void __head early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
					unsigned long npages)
{
	struct psc_desc d = {
@@ -123,7 +123,7 @@ void __head early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr
 *
 * Scan for the blob in that order.
 */
static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
static struct cc_blob_sev_info *__init find_cc_blob(struct boot_params *bp)
{
	struct cc_blob_sev_info *cc_info;

@@ -149,7 +149,7 @@ static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
	return cc_info;
}

static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
static void __init svsm_setup(struct cc_blob_sev_info *cc_info)
{
	struct snp_secrets_page *secrets = (void *)cc_info->secrets_phys;
	struct svsm_call call = {};
@@ -190,7 +190,7 @@ static __head void svsm_setup(struct cc_blob_sev_info *cc_info)
	boot_svsm_caa_pa = pa;
}

bool __head snp_init(struct boot_params *bp)
bool __init snp_init(struct boot_params *bp)
{
	struct cc_blob_sev_info *cc_info;

@@ -219,7 +219,7 @@ bool __head snp_init(struct boot_params *bp)
	return true;
}

void __head __noreturn snp_abort(void)
void __init __noreturn snp_abort(void)
{
	sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED);
}
Loading