Skip to content

Commit eb39e37

Browse files
committed
Merge tag 'x86_sev_for_v5.19_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull AMD SEV-SNP support from Borislav Petkov: "The third AMD confidential computing feature called Secure Nested Paging. Add to confidential guests the necessary memory integrity protection against malicious hypervisor-based attacks like data replay, memory remapping and others, thus achieving a stronger isolation from the hypervisor. At the core of the functionality is a new structure called a reverse map table (RMP) with which the guest has a say in which pages get assigned to it and gets notified when a page which it owns, gets accessed/modified under the covers so that the guest can take an appropriate action. In addition, add support for the whole machinery needed to launch a SNP guest, details of which is properly explained in each patch. And last but not least, the series refactors and improves parts of the previous SEV support so that the new code is accomodated properly and not just bolted on" * tag 'x86_sev_for_v5.19_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (60 commits) x86/entry: Fixup objtool/ibt validation x86/sev: Mark the code returning to user space as syscall gap x86/sev: Annotate stack change in the #VC handler x86/sev: Remove duplicated assignment to variable info x86/sev: Fix address space sparse warning x86/sev: Get the AP jump table address from secrets page x86/sev: Add missing __init annotations to SEV init routines virt: sevguest: Rename the sevguest dir and files to sev-guest virt: sevguest: Change driver name to reflect generic SEV support x86/boot: Put globals that are accessed early into the .data section x86/boot: Add an efi.h header for the decompressor virt: sevguest: Fix bool function returning negative value virt: sevguest: Fix return value check in alloc_shared_pages() x86/sev-es: Replace open-coded hlt-loop with sev_es_terminate() virt: sevguest: Add documentation for SEV-SNP CPUID Enforcement virt: sevguest: Add support to get extended report virt: sevguest: Add support to derive key virt: Add SEV-SNP guest driver x86/sev: Register SEV-SNP guest request platform device x86/sev: Provide support for SNP guest request NAEs ...
2 parents 0be3ff0 + ce65652 commit eb39e37

Some content is hidden

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

62 files changed

+3860
-392
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5383,6 +5383,8 @@
53835383

53845384
serialnumber [BUGS=X86-32]
53855385

5386+
sev=option[,option...] [X86-64] See Documentation/x86/x86_64/boot-options.rst
5387+
53865388
shapers= [NET]
53875389
Maximal number of shapers.
53885390

Documentation/virt/coco/sev-guest.rst

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
.. SPDX-License-Identifier: GPL-2.0
2+
3+
===================================================================
4+
The Definitive SEV Guest API Documentation
5+
===================================================================
6+
7+
1. General description
8+
======================
9+
10+
The SEV API is a set of ioctls that are used by the guest or hypervisor
11+
to get or set a certain aspect of the SEV virtual machine. The ioctls belong
12+
to the following classes:
13+
14+
- Hypervisor ioctls: These query and set global attributes which affect the
15+
whole SEV firmware. These ioctl are used by platform provisioning tools.
16+
17+
- Guest ioctls: These query and set attributes of the SEV virtual machine.
18+
19+
2. API description
20+
==================
21+
22+
This section describes ioctls that is used for querying the SEV guest report
23+
from the SEV firmware. For each ioctl, the following information is provided
24+
along with a description:
25+
26+
Technology:
27+
which SEV technology provides this ioctl. SEV, SEV-ES, SEV-SNP or all.
28+
29+
Type:
30+
hypervisor or guest. The ioctl can be used inside the guest or the
31+
hypervisor.
32+
33+
Parameters:
34+
what parameters are accepted by the ioctl.
35+
36+
Returns:
37+
the return value. General error numbers (-ENOMEM, -EINVAL)
38+
are not detailed, but errors with specific meanings are.
39+
40+
The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device.
41+
The ioctl accepts struct snp_user_guest_request. The input and output structure is
42+
specified through the req_data and resp_data field respectively. If the ioctl fails
43+
to execute due to a firmware error, then fw_err code will be set otherwise the
44+
fw_err will be set to 0x00000000000000ff.
45+
46+
The firmware checks that the message sequence counter is one greater than
47+
the guests message sequence counter. If guest driver fails to increment message
48+
counter (e.g. counter overflow), then -EIO will be returned.
49+
50+
::
51+
52+
struct snp_guest_request_ioctl {
53+
/* Message version number */
54+
__u32 msg_version;
55+
56+
/* Request and response structure address */
57+
__u64 req_data;
58+
__u64 resp_data;
59+
60+
/* firmware error code on failure (see psp-sev.h) */
61+
__u64 fw_err;
62+
};
63+
64+
2.1 SNP_GET_REPORT
65+
------------------
66+
67+
:Technology: sev-snp
68+
:Type: guest ioctl
69+
:Parameters (in): struct snp_report_req
70+
:Returns (out): struct snp_report_resp on success, -negative on error
71+
72+
The SNP_GET_REPORT ioctl can be used to query the attestation report from the
73+
SEV-SNP firmware. The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command
74+
provided by the SEV-SNP firmware to query the attestation report.
75+
76+
On success, the snp_report_resp.data will contains the report. The report
77+
contain the format described in the SEV-SNP specification. See the SEV-SNP
78+
specification for further details.
79+
80+
2.2 SNP_GET_DERIVED_KEY
81+
-----------------------
82+
:Technology: sev-snp
83+
:Type: guest ioctl
84+
:Parameters (in): struct snp_derived_key_req
85+
:Returns (out): struct snp_derived_key_resp on success, -negative on error
86+
87+
The SNP_GET_DERIVED_KEY ioctl can be used to get a key derive from a root key.
88+
The derived key can be used by the guest for any purpose, such as sealing keys
89+
or communicating with external entities.
90+
91+
The ioctl uses the SNP_GUEST_REQUEST (MSG_KEY_REQ) command provided by the
92+
SEV-SNP firmware to derive the key. See SEV-SNP specification for further details
93+
on the various fields passed in the key derivation request.
94+
95+
On success, the snp_derived_key_resp.data contains the derived key value. See
96+
the SEV-SNP specification for further details.
97+
98+
99+
2.3 SNP_GET_EXT_REPORT
100+
----------------------
101+
:Technology: sev-snp
102+
:Type: guest ioctl
103+
:Parameters (in/out): struct snp_ext_report_req
104+
:Returns (out): struct snp_report_resp on success, -negative on error
105+
106+
The SNP_GET_EXT_REPORT ioctl is similar to the SNP_GET_REPORT. The difference is
107+
related to the additional certificate data that is returned with the report.
108+
The certificate data returned is being provided by the hypervisor through the
109+
SNP_SET_EXT_CONFIG.
110+
111+
The ioctl uses the SNP_GUEST_REQUEST (MSG_REPORT_REQ) command provided by the SEV-SNP
112+
firmware to get the attestation report.
113+
114+
On success, the snp_ext_report_resp.data will contain the attestation report
115+
and snp_ext_report_req.certs_address will contain the certificate blob. If the
116+
length of the blob is smaller than expected then snp_ext_report_req.certs_len will
117+
be updated with the expected value.
118+
119+
See GHCB specification for further detail on how to parse the certificate blob.
120+
121+
3. SEV-SNP CPUID Enforcement
122+
============================
123+
124+
SEV-SNP guests can access a special page that contains a table of CPUID values
125+
that have been validated by the PSP as part of the SNP_LAUNCH_UPDATE firmware
126+
command. It provides the following assurances regarding the validity of CPUID
127+
values:
128+
129+
- Its address is obtained via bootloader/firmware (via CC blob), and those
130+
binaries will be measured as part of the SEV-SNP attestation report.
131+
- Its initial state will be encrypted/pvalidated, so attempts to modify
132+
it during run-time will result in garbage being written, or #VC exceptions
133+
being generated due to changes in validation state if the hypervisor tries
134+
to swap the backing page.
135+
- Attempts to bypass PSP checks by the hypervisor by using a normal page, or
136+
a non-CPUID encrypted page will change the measurement provided by the
137+
SEV-SNP attestation report.
138+
- The CPUID page contents are *not* measured, but attempts to modify the
139+
expected contents of a CPUID page as part of guest initialization will be
140+
gated by the PSP CPUID enforcement policy checks performed on the page
141+
during SNP_LAUNCH_UPDATE, and noticeable later if the guest owner
142+
implements their own checks of the CPUID values.
143+
144+
It is important to note that this last assurance is only useful if the kernel
145+
has taken care to make use of the SEV-SNP CPUID throughout all stages of boot.
146+
Otherwise, guest owner attestation provides no assurance that the kernel wasn't
147+
fed incorrect values at some point during boot.
148+
149+
150+
Reference
151+
---------
152+
153+
SEV-SNP and GHCB specification: developer.amd.com/sev
154+
155+
The driver is based on SEV-SNP firmware spec 0.9 and GHCB spec version 2.0.

Documentation/virt/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Linux Virtualization Support
1313
guest-halt-polling
1414
ne_overview
1515
acrn/index
16+
coco/sev-guest
1617

1718
.. only:: html and subproject
1819

Documentation/x86/x86_64/boot-options.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,17 @@ Miscellaneous
310310
Do not use GB pages for kernel direct mappings.
311311
gbpages
312312
Use GB pages for kernel direct mappings.
313+
314+
315+
AMD SEV (Secure Encrypted Virtualization)
316+
=========================================
317+
Options relating to AMD SEV, specified via the following format:
318+
319+
::
320+
321+
sev=option1[,option2]
322+
323+
The available options are:
324+
325+
debug
326+
Enable debug messages.

Documentation/x86/zero-page.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Offset/Size Proto Name Meaning
1919
058/008 ALL tboot_addr Physical address of tboot shared page
2020
060/010 ALL ist_info Intel SpeedStep (IST) BIOS support information
2121
(struct ist_info)
22+
070/008 ALL acpi_rsdp_addr Physical address of ACPI RSDP table
2223
080/010 ALL hd0_info hd0 disk parameter, OBSOLETE!!
2324
090/010 ALL hd1_info hd1 disk parameter, OBSOLETE!!
2425
0A0/010 ALL sys_desc_table System description table (struct sys_desc_table),
@@ -27,6 +28,7 @@ Offset/Size Proto Name Meaning
2728
0C0/004 ALL ext_ramdisk_image ramdisk_image high 32bits
2829
0C4/004 ALL ext_ramdisk_size ramdisk_size high 32bits
2930
0C8/004 ALL ext_cmd_line_ptr cmd_line_ptr high 32bits
31+
13C/004 ALL cc_blob_address Physical address of Confidential Computing blob
3032
140/080 ALL edid_info Video mode setup (struct edid_info)
3133
1C0/020 ALL efi_info EFI 32 information (struct efi_info)
3234
1E0/004 ALL alt_mem_k Alternative mem check, in KB

arch/x86/boot/compressed/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ endif
103103
vmlinux-objs-$(CONFIG_ACPI) += $(obj)/acpi.o
104104

105105
vmlinux-objs-$(CONFIG_EFI_MIXED) += $(obj)/efi_thunk_$(BITS).o
106+
vmlinux-objs-$(CONFIG_EFI) += $(obj)/efi.o
106107
efi-obj-$(CONFIG_EFI_STUB) = $(objtree)/drivers/firmware/efi/libstub/lib.a
107108

108109
$(obj)/vmlinux: $(vmlinux-objs-y) $(efi-obj-y) FORCE

0 commit comments

Comments
 (0)