Skip to content

Commit fce96cf

Browse files
codomaniasuryasaimadhu
authored andcommitted
virt: Add SEV-SNP guest driver
The SEV-SNP specification provides the guest a mechanism to communicate with the PSP without risk from a malicious hypervisor who wishes to read, alter, drop or replay the messages sent. The driver uses snp_issue_guest_request() to issue GHCB SNP_GUEST_REQUEST or SNP_EXT_GUEST_REQUEST NAE events to submit the request to PSP. The PSP requires that all communication should be encrypted using key specified through a struct snp_guest_platform_data descriptor. Userspace can use SNP_GET_REPORT ioctl() to query the guest attestation report. See SEV-SNP spec section Guest Messages for more details. [ bp: Remove the "what" from the commit message, massage. ] Signed-off-by: Brijesh Singh <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3a45b37 commit fce96cf

File tree

9 files changed

+862
-0
lines changed

9 files changed

+862
-0
lines changed

Documentation/virt/coco/sevguest.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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+
81+
Reference
82+
---------
83+
84+
SEV-SNP and GHCB specification: developer.amd.com/sev
85+
86+
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/sevguest
1617

1718
.. only:: html and subproject
1819

drivers/virt/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ source "drivers/virt/vboxguest/Kconfig"
4747
source "drivers/virt/nitro_enclaves/Kconfig"
4848

4949
source "drivers/virt/acrn/Kconfig"
50+
51+
source "drivers/virt/coco/sevguest/Kconfig"
52+
5053
endif

drivers/virt/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ obj-y += vboxguest/
99

1010
obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/
1111
obj-$(CONFIG_ACRN_HSM) += acrn/
12+
obj-$(CONFIG_SEV_GUEST) += coco/sevguest/

drivers/virt/coco/sevguest/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
config SEV_GUEST
2+
tristate "AMD SEV Guest driver"
3+
default m
4+
depends on AMD_MEM_ENCRYPT
5+
select CRYPTO_AEAD2
6+
select CRYPTO_GCM
7+
help
8+
SEV-SNP firmware provides the guest a mechanism to communicate with
9+
the PSP without risk from a malicious hypervisor who wishes to read,
10+
alter, drop or replay the messages sent. The driver provides
11+
userspace interface to communicate with the PSP to request the
12+
attestation report and more.
13+
14+
If you choose 'M' here, this module will be called sevguest.

drivers/virt/coco/sevguest/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
obj-$(CONFIG_SEV_GUEST) += sevguest.o

0 commit comments

Comments
 (0)