Skip to content

Commit e90a104

Browse files
committed
x86/sev: Move early startup code into .head.text section
JIRA: https://issues.redhat.com/browse/RHEL-39439 commit 428080c Author: Ard Biesheuvel <ardb@kernel.org> Date: Tue Feb 27 16:19:16 2024 +0100 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 Signed-off-by: Bandan Das <bsd@redhat.com>
1 parent 0f7f7b6 commit e90a104

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
@@ -216,16 +216,16 @@ static inline int pvalidate(unsigned long vaddr, bool rmp_psize, bool validate)
216216
struct snp_guest_request_ioctl;
217217

218218
void setup_ghcb(void);
219-
void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
220-
unsigned long npages);
221-
void __init early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
222-
unsigned long npages);
219+
void early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
220+
unsigned long npages);
221+
void early_snp_set_memory_shared(unsigned long vaddr, unsigned long paddr,
222+
unsigned long npages);
223223
void __init snp_prep_memory(unsigned long paddr, unsigned int sz, enum psc_op op);
224224
void snp_set_memory_shared(unsigned long vaddr, unsigned long npages);
225225
void snp_set_memory_private(unsigned long vaddr, unsigned long npages);
226226
void snp_set_wakeup_secondary_cpu(void);
227227
bool snp_init(struct boot_params *bp);
228-
void __init __noreturn snp_abort(void);
228+
void __noreturn snp_abort(void);
229229
int snp_issue_guest_request(u64 exit_code, struct snp_req_data *input, struct snp_guest_request_ioctl *rio);
230230
void snp_accept_memory(phys_addr_t start, phys_addr_t end);
231231
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>
@@ -701,8 +702,9 @@ static u64 __init get_jump_table_addr(void)
701702
return ret;
702703
}
703704

704-
static void early_set_pages_state(unsigned long vaddr, unsigned long paddr,
705-
unsigned long npages, enum psc_op op)
705+
static void __head
706+
early_set_pages_state(unsigned long vaddr, unsigned long paddr,
707+
unsigned long npages, enum psc_op op)
706708
{
707709
unsigned long paddr_end;
708710
u64 val;
@@ -758,7 +760,7 @@ static void early_set_pages_state(unsigned long vaddr, unsigned long paddr,
758760
sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_PSC);
759761
}
760762

761-
void __init early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
763+
void __head early_snp_set_memory_private(unsigned long vaddr, unsigned long paddr,
762764
unsigned long npages)
763765
{
764766
/*
@@ -2081,7 +2083,7 @@ bool __init handle_vc_boot_ghcb(struct pt_regs *regs)
20812083
*
20822084
* Scan for the blob in that order.
20832085
*/
2084-
static __init struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
2086+
static __head struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
20852087
{
20862088
struct cc_blob_sev_info *cc_info;
20872089

@@ -2107,7 +2109,7 @@ static __init struct cc_blob_sev_info *find_cc_blob(struct boot_params *bp)
21072109
return cc_info;
21082110
}
21092111

2110-
bool __init snp_init(struct boot_params *bp)
2112+
bool __head snp_init(struct boot_params *bp)
21112113
{
21122114
struct cc_blob_sev_info *cc_info;
21132115

@@ -2129,7 +2131,7 @@ bool __init snp_init(struct boot_params *bp)
21292131
return true;
21302132
}
21312133

2132-
void __init __noreturn snp_abort(void)
2134+
void __head __noreturn snp_abort(void)
21332135
{
21342136
sev_es_terminate(SEV_TERM_SET_GEN, GHCB_SNP_UNSUPPORTED);
21352137
}

0 commit comments

Comments
 (0)