1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2021 Advanced Micro Devices, Inc.
4  *
5  * Author: Brijesh Singh <brijesh.singh@amd.com>
6  *
7  * SEV-SNP API spec is available at https://developer.amd.com/sev
8  */
9 
10 #ifndef __VIRT_SEVGUEST_H__
11 #define __VIRT_SEVGUEST_H__
12 
13 #include <linux/types.h>
14 
15 #define MAX_AUTHTAG_LEN		32
16 
17 /* See SNP spec SNP_GUEST_REQUEST section for the structure */
18 enum msg_type {
19 	SNP_MSG_TYPE_INVALID = 0,
20 	SNP_MSG_CPUID_REQ,
21 	SNP_MSG_CPUID_RSP,
22 	SNP_MSG_KEY_REQ,
23 	SNP_MSG_KEY_RSP,
24 	SNP_MSG_REPORT_REQ,
25 	SNP_MSG_REPORT_RSP,
26 	SNP_MSG_EXPORT_REQ,
27 	SNP_MSG_EXPORT_RSP,
28 	SNP_MSG_IMPORT_REQ,
29 	SNP_MSG_IMPORT_RSP,
30 	SNP_MSG_ABSORB_REQ,
31 	SNP_MSG_ABSORB_RSP,
32 	SNP_MSG_VMRK_REQ,
33 	SNP_MSG_VMRK_RSP,
34 
35 	SNP_MSG_TYPE_MAX
36 };
37 
38 enum aead_algo {
39 	SNP_AEAD_INVALID,
40 	SNP_AEAD_AES_256_GCM,
41 };
42 
43 struct snp_guest_msg_hdr {
44 	u8 authtag[MAX_AUTHTAG_LEN];
45 	u64 msg_seqno;
46 	u8 rsvd1[8];
47 	u8 algo;
48 	u8 hdr_version;
49 	u16 hdr_sz;
50 	u8 msg_type;
51 	u8 msg_version;
52 	u16 msg_sz;
53 	u32 rsvd2;
54 	u8 msg_vmpck;
55 	u8 rsvd3[35];
56 } __packed;
57 
58 struct snp_guest_msg {
59 	struct snp_guest_msg_hdr hdr;
60 	u8 payload[4000];
61 } __packed;
62 
63 /*
64  * The secrets page contains 96-bytes of reserved field that can be used by
65  * the guest OS. The guest OS uses the area to save the message sequence
66  * number for each VMPCK.
67  *
68  * See the GHCB spec section Secret page layout for the format for this area.
69  */
70 struct secrets_os_area {
71 	u32 msg_seqno_0;
72 	u32 msg_seqno_1;
73 	u32 msg_seqno_2;
74 	u32 msg_seqno_3;
75 	u64 ap_jump_table_pa;
76 	u8 rsvd[40];
77 	u8 guest_usage[32];
78 } __packed;
79 
80 #define VMPCK_KEY_LEN		32
81 
82 /* See the SNP spec version 0.9 for secrets page format */
83 struct snp_secrets_page_layout {
84 	u32 version;
85 	u32 imien	: 1,
86 	    rsvd1	: 31;
87 	u32 fms;
88 	u32 rsvd2;
89 	u8 gosvw[16];
90 	u8 vmpck0[VMPCK_KEY_LEN];
91 	u8 vmpck1[VMPCK_KEY_LEN];
92 	u8 vmpck2[VMPCK_KEY_LEN];
93 	u8 vmpck3[VMPCK_KEY_LEN];
94 	struct secrets_os_area os_area;
95 	u8 rsvd3[3840];
96 } __packed;
97 
98 #endif /* __VIRT_SEVGUEST_H__ */
99