Skip to content

Commit 38b334f

Browse files
committed
Merge tag 'x86_sev_for_v6.9_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 SEV updates from Borislav Petkov: - Add the x86 part of the SEV-SNP host support. This will allow the kernel to be used as a KVM hypervisor capable of running SNP (Secure Nested Paging) guests. Roughly speaking, SEV-SNP is the ultimate goal of the AMD confidential computing side, providing the most comprehensive confidential computing environment up to date. This is the x86 part and there is a KVM part which did not get ready in time for the merge window so latter will be forthcoming in the next cycle. - Rework the early code's position-dependent SEV variable references in order to allow building the kernel with clang and -fPIE/-fPIC and -mcmodel=kernel - The usual set of fixes, cleanups and improvements all over the place * tag 'x86_sev_for_v6.9_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (36 commits) x86/sev: Disable KMSAN for memory encryption TUs x86/sev: Dump SEV_STATUS crypto: ccp - Have it depend on AMD_IOMMU iommu/amd: Fix failure return from snp_lookup_rmpentry() x86/sev: Fix position dependent variable references in startup code crypto: ccp: Make snp_range_list static x86/Kconfig: Remove CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT Documentation: virt: Fix up pre-formatted text block for SEV ioctls crypto: ccp: Add the SNP_SET_CONFIG command crypto: ccp: Add the SNP_COMMIT command crypto: ccp: Add the SNP_PLATFORM_STATUS command x86/cpufeatures: Enable/unmask SEV-SNP CPU feature KVM: SEV: Make AVIC backing, VMSA and VMCB memory allocation SNP safe crypto: ccp: Add panic notifier for SEV/SNP firmware shutdown on kdump iommu/amd: Clean up RMP entries for IOMMU pages during SNP shutdown crypto: ccp: Handle legacy SEV commands when SNP is enabled crypto: ccp: Handle non-volatile INIT_EX data when SNP is enabled crypto: ccp: Handle the legacy TMR allocation when SNP is enabled x86/sev: Introduce an SNP leaked pages list crypto: ccp: Provide an API to issue SEV and SNP commands ...
2 parents 2edfd10 + c0935fc commit 38b334f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2678
-307
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,9 +3318,7 @@
33183318

33193319
mem_encrypt= [X86-64] AMD Secure Memory Encryption (SME) control
33203320
Valid arguments: on, off
3321-
Default (depends on kernel configuration option):
3322-
on (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=y)
3323-
off (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=n)
3321+
Default: off
33243322
mem_encrypt=on: Activate SME
33253323
mem_encrypt=off: Do not activate SME
33263324

Documentation/arch/x86/amd-memory-encryption.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ The state of SME in the Linux kernel can be documented as follows:
8787
kernel is non-zero).
8888

8989
SME can also be enabled and activated in the BIOS. If SME is enabled and
90-
activated in the BIOS, then all memory accesses will be encrypted and it will
91-
not be necessary to activate the Linux memory encryption support. If the BIOS
92-
merely enables SME (sets bit 23 of the MSR_AMD64_SYSCFG), then Linux can activate
93-
memory encryption by default (CONFIG_AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT=y) or
94-
by supplying mem_encrypt=on on the kernel command line. However, if BIOS does
95-
not enable SME, then Linux will not be able to activate memory encryption, even
96-
if configured to do so by default or the mem_encrypt=on command line parameter
97-
is specified.
90+
activated in the BIOS, then all memory accesses will be encrypted and it
91+
will not be necessary to activate the Linux memory encryption support.
92+
93+
If the BIOS merely enables SME (sets bit 23 of the MSR_AMD64_SYSCFG),
94+
then memory encryption can be enabled by supplying mem_encrypt=on on the
95+
kernel command line. However, if BIOS does not enable SME, then Linux
96+
will not be able to activate memory encryption, even if configured to do
97+
so by default or the mem_encrypt=on command line parameter is specified.
9898

9999
Secure Nested Paging (SNP)
100100
==========================

Documentation/virt/coco/sev-guest.rst

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ counter (e.g. counter overflow), then -EIO will be returned.
6767
};
6868
};
6969

70+
The host ioctls are issued to a file descriptor of the /dev/sev device.
71+
The ioctl accepts the command ID/input structure documented below.
72+
73+
::
74+
75+
struct sev_issue_cmd {
76+
/* Command ID */
77+
__u32 cmd;
78+
79+
/* Command request structure */
80+
__u64 data;
81+
82+
/* Firmware error code on failure (see psp-sev.h) */
83+
__u32 error;
84+
};
85+
86+
7087
2.1 SNP_GET_REPORT
7188
------------------
7289

@@ -124,6 +141,41 @@ be updated with the expected value.
124141

125142
See GHCB specification for further detail on how to parse the certificate blob.
126143

144+
2.4 SNP_PLATFORM_STATUS
145+
-----------------------
146+
:Technology: sev-snp
147+
:Type: hypervisor ioctl cmd
148+
:Parameters (out): struct sev_user_data_snp_status
149+
:Returns (out): 0 on success, -negative on error
150+
151+
The SNP_PLATFORM_STATUS command is used to query the SNP platform status. The
152+
status includes API major, minor version and more. See the SEV-SNP
153+
specification for further details.
154+
155+
2.5 SNP_COMMIT
156+
--------------
157+
:Technology: sev-snp
158+
:Type: hypervisor ioctl cmd
159+
:Returns (out): 0 on success, -negative on error
160+
161+
SNP_COMMIT is used to commit the currently installed firmware using the
162+
SEV-SNP firmware SNP_COMMIT command. This prevents roll-back to a previously
163+
committed firmware version. This will also update the reported TCB to match
164+
that of the currently installed firmware.
165+
166+
2.6 SNP_SET_CONFIG
167+
------------------
168+
:Technology: sev-snp
169+
:Type: hypervisor ioctl cmd
170+
:Parameters (in): struct sev_user_data_snp_config
171+
:Returns (out): 0 on success, -negative on error
172+
173+
SNP_SET_CONFIG is used to set the system-wide configuration such as
174+
reported TCB version in the attestation report. The command is similar
175+
to SNP_CONFIG command defined in the SEV-SNP spec. The current values of
176+
the firmware parameters affected by this command can be queried via
177+
SNP_PLATFORM_STATUS.
178+
127179
3. SEV-SNP CPUID Enforcement
128180
============================
129181

arch/x86/Kbuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ obj-y += net/
2828

2929
obj-$(CONFIG_KEXEC_FILE) += purgatory/
3030

31+
obj-y += virt/svm/
32+
3133
# for cleaning
3234
subdir- += boot tools

arch/x86/Kconfig

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,19 +1548,6 @@ config AMD_MEM_ENCRYPT
15481548
This requires an AMD processor that supports Secure Memory
15491549
Encryption (SME).
15501550

1551-
config AMD_MEM_ENCRYPT_ACTIVE_BY_DEFAULT
1552-
bool "Activate AMD Secure Memory Encryption (SME) by default"
1553-
depends on AMD_MEM_ENCRYPT
1554-
help
1555-
Say yes to have system memory encrypted by default if running on
1556-
an AMD processor that supports Secure Memory Encryption (SME).
1557-
1558-
If set to Y, then the encryption of system memory can be
1559-
deactivated with the mem_encrypt=off command line option.
1560-
1561-
If set to N, then the encryption of system memory can be
1562-
activated with the mem_encrypt=on command line option.
1563-
15641551
# Common NUMA Features
15651552
config NUMA
15661553
bool "NUMA Memory Allocation and Scheduler Support"

arch/x86/boot/compressed/sev.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ void do_boot_stage2_vc(struct pt_regs *regs, unsigned long exit_code)
304304
if (result != ES_OK)
305305
goto finish;
306306

307+
result = vc_check_opcode_bytes(&ctxt, exit_code);
308+
if (result != ES_OK)
309+
goto finish;
310+
307311
switch (exit_code) {
308312
case SVM_EXIT_RDTSC:
309313
case SVM_EXIT_RDTSCP:
@@ -365,7 +369,7 @@ static void enforce_vmpl0(void)
365369
MSR_AMD64_SNP_VMPL_SSS | \
366370
MSR_AMD64_SNP_SECURE_TSC | \
367371
MSR_AMD64_SNP_VMGEXIT_PARAM | \
368-
MSR_AMD64_SNP_VMSA_REG_PROTECTION | \
372+
MSR_AMD64_SNP_VMSA_REG_PROT | \
369373
MSR_AMD64_SNP_RESERVED_BIT13 | \
370374
MSR_AMD64_SNP_RESERVED_BIT15 | \
371375
MSR_AMD64_SNP_RESERVED_MASK)

arch/x86/coco/core.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <asm/processor.h>
1515

1616
enum cc_vendor cc_vendor __ro_after_init = CC_VENDOR_NONE;
17-
static u64 cc_mask __ro_after_init;
17+
u64 cc_mask __ro_after_init;
1818

1919
static bool noinstr intel_cc_platform_has(enum cc_attr attr)
2020
{
@@ -148,8 +148,3 @@ u64 cc_mkdec(u64 val)
148148
}
149149
}
150150
EXPORT_SYMBOL_GPL(cc_mkdec);
151-
152-
__init void cc_set_mask(u64 mask)
153-
{
154-
cc_mask = mask;
155-
}

arch/x86/include/asm/asm.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@
113113

114114
#endif
115115

116+
#ifndef __ASSEMBLY__
117+
#ifndef __pic__
118+
static __always_inline __pure void *rip_rel_ptr(void *p)
119+
{
120+
asm("leaq %c1(%%rip), %0" : "=r"(p) : "i"(p));
121+
122+
return p;
123+
}
124+
#define RIP_REL_REF(var) (*(typeof(&(var)))rip_rel_ptr(&(var)))
125+
#else
126+
#define RIP_REL_REF(var) (var)
127+
#endif
128+
#endif
129+
116130
/*
117131
* Macros to generate condition code outputs from inline assembly,
118132
* The output operand must be type "bool".

arch/x86/include/asm/coco.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#ifndef _ASM_X86_COCO_H
33
#define _ASM_X86_COCO_H
44

5+
#include <asm/asm.h>
56
#include <asm/types.h>
67

78
enum cc_vendor {
@@ -12,7 +13,13 @@ enum cc_vendor {
1213

1314
#ifdef CONFIG_ARCH_HAS_CC_PLATFORM
1415
extern enum cc_vendor cc_vendor;
15-
void cc_set_mask(u64 mask);
16+
extern u64 cc_mask;
17+
18+
static inline void cc_set_mask(u64 mask)
19+
{
20+
RIP_REL_REF(cc_mask) = mask;
21+
}
22+
1623
u64 cc_mkenc(u64 val);
1724
u64 cc_mkdec(u64 val);
1825
#else

arch/x86/include/asm/cpufeatures.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@
442442
#define X86_FEATURE_SEV (19*32+ 1) /* AMD Secure Encrypted Virtualization */
443443
#define X86_FEATURE_VM_PAGE_FLUSH (19*32+ 2) /* "" VM Page Flush MSR is supported */
444444
#define X86_FEATURE_SEV_ES (19*32+ 3) /* AMD Secure Encrypted Virtualization - Encrypted State */
445+
#define X86_FEATURE_SEV_SNP (19*32+ 4) /* AMD Secure Encrypted Virtualization - Secure Nested Paging */
445446
#define X86_FEATURE_V_TSC_AUX (19*32+ 9) /* "" Virtual TSC_AUX */
446447
#define X86_FEATURE_SME_COHERENT (19*32+10) /* "" AMD hardware-enforced cache coherency */
447448
#define X86_FEATURE_DEBUG_SWAP (19*32+14) /* AMD SEV-ES full debug state swap support */

0 commit comments

Comments
 (0)