Skip to content

Commit cb502f0

Browse files
committed
Merge tag 'x86_sev_for_v6.19_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 SEV updates from Borislav Petkov: - Largely cleanups along with a change to save XSS to the GHCB (Guest-Host Communication Block) in SEV-ES guests so that the hypervisor can determine the guest's XSAVES buffer size properly and thus support shadow stacks in AMD confidential guests * tag 'x86_sev_for_v6.19_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/cc: Fix enum spelling to fix kernel-doc warnings x86/boot: Drop unused sev_enable() fallback x86/coco/sev: Convert has_cpuflag() to use cpu_feature_enabled() x86/sev: Include XSS value in GHCB CPUID request x86/boot: Move boot_*msr helpers to asm/shared/msr.h
2 parents d748981 + 73029e7 commit cb502f0

12 files changed

Lines changed: 45 additions & 55 deletions

File tree

arch/x86/boot/compressed/misc.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,6 @@ bool insn_has_rep_prefix(struct insn *insn);
152152
void sev_insn_decode_init(void);
153153
bool early_setup_ghcb(void);
154154
#else
155-
static inline void sev_enable(struct boot_params *bp)
156-
{
157-
/*
158-
* bp->cc_blob_address should only be set by boot/compressed kernel.
159-
* Initialize it to 0 unconditionally (thus here in this stub too) to
160-
* ensure that uninitialized values from buggy bootloaders aren't
161-
* propagated.
162-
*/
163-
if (bp)
164-
bp->cc_blob_address = 0;
165-
}
166155
static inline void snp_check_features(void) { }
167156
static inline void sev_es_shutdown_ghcb(void) { }
168157
static inline bool sev_es_check_ghcb_fault(unsigned long address)

arch/x86/boot/compressed/sev.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <asm/bootparam.h>
1616
#include <asm/pgtable_types.h>
17+
#include <asm/shared/msr.h>
1718
#include <asm/sev.h>
1819
#include <asm/trapnr.h>
1920
#include <asm/trap_pf.h>
@@ -397,7 +398,7 @@ void sev_enable(struct boot_params *bp)
397398
}
398399

399400
/* Set the SME mask if this is an SEV guest. */
400-
boot_rdmsr(MSR_AMD64_SEV, &m);
401+
raw_rdmsr(MSR_AMD64_SEV, &m);
401402
sev_status = m.q;
402403
if (!(sev_status & MSR_AMD64_SEV_ENABLED))
403404
return;
@@ -446,7 +447,7 @@ u64 sev_get_status(void)
446447
if (sev_check_cpu_support() < 0)
447448
return 0;
448449

449-
boot_rdmsr(MSR_AMD64_SEV, &m);
450+
raw_rdmsr(MSR_AMD64_SEV, &m);
450451
return m.q;
451452
}
452453

@@ -496,7 +497,7 @@ bool early_is_sevsnp_guest(void)
496497
struct msr m;
497498

498499
/* Obtain the address of the calling area to use */
499-
boot_rdmsr(MSR_SVSM_CAA, &m);
500+
raw_rdmsr(MSR_SVSM_CAA, &m);
500501
boot_svsm_caa_pa = m.q;
501502

502503
/*

arch/x86/boot/compressed/sev.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#ifdef CONFIG_AMD_MEM_ENCRYPT
1212

13-
#include "../msr.h"
13+
#include <asm/shared/msr.h>
1414

1515
void snp_accept_memory(phys_addr_t start, phys_addr_t end);
1616
u64 sev_get_status(void);
@@ -20,7 +20,7 @@ static inline u64 sev_es_rd_ghcb_msr(void)
2020
{
2121
struct msr m;
2222

23-
boot_rdmsr(MSR_AMD64_SEV_ES_GHCB, &m);
23+
raw_rdmsr(MSR_AMD64_SEV_ES_GHCB, &m);
2424

2525
return m.q;
2626
}
@@ -30,7 +30,7 @@ static inline void sev_es_wr_ghcb_msr(u64 val)
3030
struct msr m;
3131

3232
m.q = val;
33-
boot_wrmsr(MSR_AMD64_SEV_ES_GHCB, &m);
33+
raw_wrmsr(MSR_AMD64_SEV_ES_GHCB, &m);
3434
}
3535

3636
#else

arch/x86/boot/cpucheck.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
#include <asm/intel-family.h>
2727
#include <asm/processor-flags.h>
2828
#include <asm/msr-index.h>
29+
#include <asm/shared/msr.h>
2930

3031
#include "string.h"
31-
#include "msr.h"
3232

3333
static u32 err_flags[NCAPINTS];
3434

@@ -134,9 +134,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
134134

135135
struct msr m;
136136

137-
boot_rdmsr(MSR_K7_HWCR, &m);
137+
raw_rdmsr(MSR_K7_HWCR, &m);
138138
m.l &= ~(1 << 15);
139-
boot_wrmsr(MSR_K7_HWCR, &m);
139+
raw_wrmsr(MSR_K7_HWCR, &m);
140140

141141
get_cpuflags(); /* Make sure it really did something */
142142
err = check_cpuflags();
@@ -148,9 +148,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
148148

149149
struct msr m;
150150

151-
boot_rdmsr(MSR_VIA_FCR, &m);
151+
raw_rdmsr(MSR_VIA_FCR, &m);
152152
m.l |= (1 << 1) | (1 << 7);
153-
boot_wrmsr(MSR_VIA_FCR, &m);
153+
raw_wrmsr(MSR_VIA_FCR, &m);
154154

155155
set_bit(X86_FEATURE_CX8, cpu.flags);
156156
err = check_cpuflags();
@@ -160,14 +160,14 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
160160
struct msr m, m_tmp;
161161
u32 level = 1;
162162

163-
boot_rdmsr(0x80860004, &m);
163+
raw_rdmsr(0x80860004, &m);
164164
m_tmp = m;
165165
m_tmp.l = ~0;
166-
boot_wrmsr(0x80860004, &m_tmp);
166+
raw_wrmsr(0x80860004, &m_tmp);
167167
asm("cpuid"
168168
: "+a" (level), "=d" (cpu.flags[0])
169169
: : "ecx", "ebx");
170-
boot_wrmsr(0x80860004, &m);
170+
raw_wrmsr(0x80860004, &m);
171171

172172
err = check_cpuflags();
173173
} else if (err == 0x01 &&

arch/x86/boot/msr.h

Lines changed: 0 additions & 26 deletions
This file was deleted.

arch/x86/boot/startup/sev-shared.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <asm/setup_data.h>
1313

1414
#ifndef __BOOT_COMPRESSED
15-
#define has_cpuflag(f) boot_cpu_has(f)
15+
#define has_cpuflag(f) cpu_feature_enabled(f)
1616
#else
1717
#undef WARN
1818
#define WARN(condition, format...) (!!(condition))

arch/x86/coco/sev/vc-handle.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ static enum es_result vc_read_mem(struct es_em_ctxt *ctxt,
352352

353353
#define sev_printk(fmt, ...) printk(fmt, ##__VA_ARGS__)
354354
#define error(v)
355-
#define has_cpuflag(f) boot_cpu_has(f)
356355

357356
#include "vc-shared.c"
358357

arch/x86/coco/sev/vc-shared.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
#ifndef __BOOT_COMPRESSED
4+
#define has_cpuflag(f) cpu_feature_enabled(f)
5+
#endif
6+
37
static enum es_result vc_check_opcode_bytes(struct es_em_ctxt *ctxt,
48
unsigned long exit_code)
59
{
@@ -546,6 +550,13 @@ static enum es_result vc_handle_cpuid(struct ghcb *ghcb,
546550
/* xgetbv will cause #GP - use reset value for xcr0 */
547551
ghcb_set_xcr0(ghcb, 1);
548552

553+
if (has_cpuflag(X86_FEATURE_SHSTK) && regs->ax == 0xd && regs->cx == 1) {
554+
struct msr m;
555+
556+
raw_rdmsr(MSR_IA32_XSS, &m);
557+
ghcb_set_xss(ghcb, m.q);
558+
}
559+
549560
ret = sev_es_ghcb_hv_call(ghcb, ctxt, SVM_EXIT_CPUID, 0, 0);
550561
if (ret != ES_OK)
551562
return ret;

arch/x86/include/asm/shared/msr.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,19 @@ struct msr {
1212
};
1313
};
1414

15+
/*
16+
* The kernel proper already defines rdmsr()/wrmsr(), but they are not for the
17+
* boot kernel since they rely on tracepoint/exception handling infrastructure
18+
* that's not available here.
19+
*/
20+
static inline void raw_rdmsr(unsigned int reg, struct msr *m)
21+
{
22+
asm volatile("rdmsr" : "=a" (m->l), "=d" (m->h) : "c" (reg));
23+
}
24+
25+
static inline void raw_wrmsr(unsigned int reg, const struct msr *m)
26+
{
27+
asm volatile("wrmsr" : : "c" (reg), "a"(m->l), "d" (m->h) : "memory");
28+
}
29+
1530
#endif /* _ASM_X86_SHARED_MSR_H */

arch/x86/include/asm/svm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,5 +701,6 @@ DEFINE_GHCB_ACCESSORS(sw_exit_info_1)
701701
DEFINE_GHCB_ACCESSORS(sw_exit_info_2)
702702
DEFINE_GHCB_ACCESSORS(sw_scratch)
703703
DEFINE_GHCB_ACCESSORS(xcr0)
704+
DEFINE_GHCB_ACCESSORS(xss)
704705

705706
#endif

0 commit comments

Comments
 (0)