Skip to content

Commit 428080c

Browse files
ardbiesheuvelbp3tk0v
authored andcommitted
x86/sev: Move early startup code into .head.text section
In preparation for implementing rigorous build time checks to enforce that only code that can support it will be called from the early 1:1 mapping of memory, move SEV init code that is called in this manner to the .head.text section. Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Tested-by: Tom Lendacky <thomas.lendacky@amd.com> Link: https://lore.kernel.org/r/20240227151907.387873-19-ardb+git@google.com
1 parent 48204ab commit 428080c

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

arch/x86/boot/compressed/sev.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ static bool fault_in_kernel_space(unsigned long address)
116116
#undef __init
117117
#define __init
118118

119+
#undef __head
120+
#define __head
121+
119122
#define __BOOT_COMPRESSED
120123

121124
/* Basic instruction decoding support needed */

arch/x86/include/asm/sev.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,16 @@ static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate)
213213
struct snp_guest_request_ioctl;
214214

215215
void setup_ghcb(void);
216-
void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
217-
unsigned long npages);
218-
void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
219-
unsigned long npages);
216+
void early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
217+
unsigned long npages);
218+
void early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
219+
unsigned long npages);
220220
void __init snp_prep_memory(unsigned long paddr, unsigned int sz, enum psc_op op);
221221
void snp_set_memory_shared(unsigned long vaddr, unsigned long npages);
222222
void snp_set_memory_private(unsigned long vaddr, unsigned long npages);
223223
void snp_set_wakeup_secondary_cpu(void);
224224
bool snp_init(struct boot_params *bp);
225-
void __init __noreturn snp_abort(void);
225+
void __noreturn snp_abort(void);
226226
int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio);
227227
void snp_accept_memory(phys_addr_t start, phys_addr_t end);
228228
u64 snp_get_unsupported_features(u64 status);

arch/x86/kernel/sev-shared.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ static bool __init sev_es_check_cpu_features(void)
9393
return true;
9494
}
9595

96-
static void __noreturn sev_es_terminate(unsigned int set, unsigned int reason)
96+
static void __head __noreturn
97+
sev_es_terminate(unsigned int set, unsigned int reason)
9798
{
9899
u64 val = GHCB_MSR_TERM_REQ;
99100

@@ -330,13 +331,7 @@ static int sev_cpuid_hv(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid
330331
*/
331332
static const struct snp_cpuid_table *snp_cpuid_get_table(void)
332333
{
333-
void *ptr;
334-
335-
asm ("lea cpuid_table_copy(%%rip), %0"
336-
: "=r" (ptr)
337-
: "p" (&cpuid_table_copy));
338-
339-
return ptr;
334+
return &RIP_REL_REF(cpuid_table_copy);
340335
}
341336

342337
/*
@@ -395,7 +390,7 @@ static u32 snp_cpuid_calc_xsave_size(u64 xfeatures_en, bool compacted)
395390
return xsave_size;
396391
}
397392

398-
static bool
393+
static bool __head
399394
snp_cpuid_get_validated_func(struct cpuid_leaf *leaf)
400395
{
401396
const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();
@@ -532,7 +527,8 @@ static int snp_cpuid_postprocess(struct ghcb *ghcb, struct es_em_ctxt *ctxt,
532527
* Returns -EOPNOTSUPP if feature not enabled. Any other non-zero return value
533528
* should be treated as fatal by caller.
534529
*/
535-
static int snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_leaf *leaf)
530+
static int __head
531+
snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_leaf *leaf)
536532
{
537533
const struct snp_cpuid_table *cpuid_table = snp_cpuid_get_table();
538534

@@ -574,7 +570,7 @@ static int snp_cpuid(struct ghcb *ghcb, struct es_em_ctxt *ctxt, struct cpuid_le
574570
* page yet, so it only supports the MSR based communication with the
575571
* hypervisor and only the CPUID exit-code.
576572
*/
577-
void __init do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
573+
void __head do_vc_no_ghcb(struct pt_regs *regs, unsigned long exit_code)
578574
{
579575
unsigned int subfn = lower_bits(regs->cx, 32);
580576
unsigned int fn = lower_bits(regs->ax, 32);
@@ -1025,7 +1021,8 @@ struct cc_setup_data {
10251021
* Search for a Confidential Computing blob passed in as a setup_data entry
10261022
* via the Linux Boot Protocol.
10271023
*/
1028-
static struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp)
1024+
static __head
1025+
struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp)
10291026
{
10301027
struct cc_setup_data *sd = NULL;
10311028
struct setup_data *hdr;
@@ -1052,7 +1049,7 @@ static struct cc_blob_sev_info *find_cc_blob_setup_data(struct boot_params *bp)
10521049
* mapping needs to be updated in sync with all the changes to virtual memory
10531050
* layout and related mapping facilities throughout the boot process.
10541051
*/
1055-
static void __init setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
1052+
static void __head setup_cpuid_table(const struct cc_blob_sev_info *cc_info)
10561053
{
10571054
const struct snp_cpuid_table *cpuid_table_fw, *cpuid_table;
10581055
int i;

arch/x86/kernel/sev.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/psp-sev.h>
2626
#include <uapi/linux/sev-guest.h>
2727

28+
#include <asm/init.h>
2829
#include <asm/cpu_entry_area.h>
2930
#include <asm/stacktrace.h>
3031
#include <asm/sev.h>
@@ -682,8 +683,9 @@ static u64 __init get_jump_table_addr(void)
682683
return ret;
683684
}
684685

685-
static void early_set_pages_state(unsigned long vaddr, unsigned long paddr,
686-
unsigned long npages, enum psc_op op)
686+
static void __head
687+
early_set_pages_state(unsigned long vaddr, unsigned long paddr,
688+
unsigned long npages, enum psc_op op)
687689
{
688690
unsigned long paddr_end;
689691
u64 val;
@@ -739,7 +741,7 @@ static void early_set_pages_state(unsigned long vaddr, unsigned long paddr,
739741
sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC);
740742
}
741743

742-
void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
744+
void __head early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
743745
unsigned long npages)
744746
{
745747
/*
@@ -2062,7 +2064,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs)
20622064
*
20632065
* Scan for the blob in that order.
20642066
*/
2065-
static __init struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
2067+
static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
20662068
{
20672069
struct cc_blob_sev_info *cc_info;
20682070

@@ -2088,7 +2090,7 @@ static __init struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
20882090
return cc_info;
20892091
}
20902092

2091-
bool __init snp_init(struct boot_params *bp)
2093+
bool __head snp_init(struct boot_params *bp)
20922094
{
20932095
struct cc_blob_sev_info *cc_info;
20942096

@@ -2110,7 +2112,7 @@ bool __init snp_init(struct boot_params *bp)
21102112
return true;
21112113
}
21122114

2113-
void __init __noreturn snp_abort(void)
2115+
void __head __noreturn snp_abort(void)
21142116
{
21152117
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED);
21162118
}

0 commit comments

Comments
 (0)