Skip to content

Commit 3a45dc2

Browse files
codomaniabp3tk0v
authored andcommitted
crypto: ccp: Define the SEV-SNP commands
AMD introduced the next generation of SEV called SEV-SNP (Secure Nested Paging). SEV-SNP builds upon existing SEV and SEV-ES functionality while adding new hardware security protection. Define the commands and structures used to communicate with the AMD-SP when creating and managing the SEV-SNP guests. The SEV-SNP firmware spec is available at developer.amd.com/sev. [ mdr: update SNP command list and SNP status struct based on current spec, use C99 flexible arrays, fix kernel-doc issues. ] Signed-off-by: Brijesh Singh <[email protected]> Co-developed-by: Ashish Kalra <[email protected]> Signed-off-by: Ashish Kalra <[email protected]> Signed-off-by: Michael Roth <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 661b1c6 commit 3a45dc2

File tree

3 files changed

+337
-0
lines changed

3 files changed

+337
-0
lines changed

drivers/crypto/ccp/sev-dev.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ static int sev_cmd_buffer_len(int cmd)
130130
switch (cmd) {
131131
case SEV_CMD_INIT: return sizeof(struct sev_data_init);
132132
case SEV_CMD_INIT_EX: return sizeof(struct sev_data_init_ex);
133+
case SEV_CMD_SNP_SHUTDOWN_EX: return sizeof(struct sev_data_snp_shutdown_ex);
134+
case SEV_CMD_SNP_INIT_EX: return sizeof(struct sev_data_snp_init_ex);
133135
case SEV_CMD_PLATFORM_STATUS: return sizeof(struct sev_user_data_status);
134136
case SEV_CMD_PEK_CSR: return sizeof(struct sev_data_pek_csr);
135137
case SEV_CMD_PEK_CERT_IMPORT: return sizeof(struct sev_data_pek_cert_import);
@@ -158,6 +160,20 @@ static int sev_cmd_buffer_len(int cmd)
158160
case SEV_CMD_GET_ID: return sizeof(struct sev_data_get_id);
159161
case SEV_CMD_ATTESTATION_REPORT: return sizeof(struct sev_data_attestation_report);
160162
case SEV_CMD_SEND_CANCEL: return sizeof(struct sev_data_send_cancel);
163+
case SEV_CMD_SNP_GCTX_CREATE: return sizeof(struct sev_data_snp_addr);
164+
case SEV_CMD_SNP_LAUNCH_START: return sizeof(struct sev_data_snp_launch_start);
165+
case SEV_CMD_SNP_LAUNCH_UPDATE: return sizeof(struct sev_data_snp_launch_update);
166+
case SEV_CMD_SNP_ACTIVATE: return sizeof(struct sev_data_snp_activate);
167+
case SEV_CMD_SNP_DECOMMISSION: return sizeof(struct sev_data_snp_addr);
168+
case SEV_CMD_SNP_PAGE_RECLAIM: return sizeof(struct sev_data_snp_page_reclaim);
169+
case SEV_CMD_SNP_GUEST_STATUS: return sizeof(struct sev_data_snp_guest_status);
170+
case SEV_CMD_SNP_LAUNCH_FINISH: return sizeof(struct sev_data_snp_launch_finish);
171+
case SEV_CMD_SNP_DBG_DECRYPT: return sizeof(struct sev_data_snp_dbg);
172+
case SEV_CMD_SNP_DBG_ENCRYPT: return sizeof(struct sev_data_snp_dbg);
173+
case SEV_CMD_SNP_PAGE_UNSMASH: return sizeof(struct sev_data_snp_page_unsmash);
174+
case SEV_CMD_SNP_PLATFORM_STATUS: return sizeof(struct sev_data_snp_addr);
175+
case SEV_CMD_SNP_GUEST_REQUEST: return sizeof(struct sev_data_snp_guest_request);
176+
case SEV_CMD_SNP_CONFIG: return sizeof(struct sev_user_data_snp_config);
161177
default: return 0;
162178
}
163179

include/linux/psp-sev.h

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,36 @@ enum sev_cmd {
7878
SEV_CMD_DBG_DECRYPT = 0x060,
7979
SEV_CMD_DBG_ENCRYPT = 0x061,
8080

81+
/* SNP specific commands */
82+
SEV_CMD_SNP_INIT = 0x081,
83+
SEV_CMD_SNP_SHUTDOWN = 0x082,
84+
SEV_CMD_SNP_PLATFORM_STATUS = 0x083,
85+
SEV_CMD_SNP_DF_FLUSH = 0x084,
86+
SEV_CMD_SNP_INIT_EX = 0x085,
87+
SEV_CMD_SNP_SHUTDOWN_EX = 0x086,
88+
SEV_CMD_SNP_DECOMMISSION = 0x090,
89+
SEV_CMD_SNP_ACTIVATE = 0x091,
90+
SEV_CMD_SNP_GUEST_STATUS = 0x092,
91+
SEV_CMD_SNP_GCTX_CREATE = 0x093,
92+
SEV_CMD_SNP_GUEST_REQUEST = 0x094,
93+
SEV_CMD_SNP_ACTIVATE_EX = 0x095,
94+
SEV_CMD_SNP_LAUNCH_START = 0x0A0,
95+
SEV_CMD_SNP_LAUNCH_UPDATE = 0x0A1,
96+
SEV_CMD_SNP_LAUNCH_FINISH = 0x0A2,
97+
SEV_CMD_SNP_DBG_DECRYPT = 0x0B0,
98+
SEV_CMD_SNP_DBG_ENCRYPT = 0x0B1,
99+
SEV_CMD_SNP_PAGE_SWAP_OUT = 0x0C0,
100+
SEV_CMD_SNP_PAGE_SWAP_IN = 0x0C1,
101+
SEV_CMD_SNP_PAGE_MOVE = 0x0C2,
102+
SEV_CMD_SNP_PAGE_MD_INIT = 0x0C3,
103+
SEV_CMD_SNP_PAGE_SET_STATE = 0x0C6,
104+
SEV_CMD_SNP_PAGE_RECLAIM = 0x0C7,
105+
SEV_CMD_SNP_PAGE_UNSMASH = 0x0C8,
106+
SEV_CMD_SNP_CONFIG = 0x0C9,
107+
SEV_CMD_SNP_DOWNLOAD_FIRMWARE_EX = 0x0CA,
108+
SEV_CMD_SNP_COMMIT = 0x0CB,
109+
SEV_CMD_SNP_VLEK_LOAD = 0x0CD,
110+
81111
SEV_CMD_MAX,
82112
};
83113

@@ -523,6 +553,241 @@ struct sev_data_attestation_report {
523553
u32 len; /* In/Out */
524554
} __packed;
525555

556+
/**
557+
* struct sev_data_snp_download_firmware - SNP_DOWNLOAD_FIRMWARE command params
558+
*
559+
* @address: physical address of firmware image
560+
* @len: length of the firmware image
561+
*/
562+
struct sev_data_snp_download_firmware {
563+
u64 address; /* In */
564+
u32 len; /* In */
565+
} __packed;
566+
567+
/**
568+
* struct sev_data_snp_activate - SNP_ACTIVATE command params
569+
*
570+
* @gctx_paddr: system physical address guest context page
571+
* @asid: ASID to bind to the guest
572+
*/
573+
struct sev_data_snp_activate {
574+
u64 gctx_paddr; /* In */
575+
u32 asid; /* In */
576+
} __packed;
577+
578+
/**
579+
* struct sev_data_snp_addr - generic SNP command params
580+
*
581+
* @address: physical address of generic data param
582+
*/
583+
struct sev_data_snp_addr {
584+
u64 address; /* In/Out */
585+
} __packed;
586+
587+
/**
588+
* struct sev_data_snp_launch_start - SNP_LAUNCH_START command params
589+
*
590+
* @gctx_paddr: system physical address of guest context page
591+
* @policy: guest policy
592+
* @ma_gctx_paddr: system physical address of migration agent
593+
* @ma_en: the guest is associated with a migration agent
594+
* @imi_en: launch flow is launching an IMI (Incoming Migration Image) for the
595+
* purpose of guest-assisted migration.
596+
* @rsvd: reserved
597+
* @gosvw: guest OS-visible workarounds, as defined by hypervisor
598+
*/
599+
struct sev_data_snp_launch_start {
600+
u64 gctx_paddr; /* In */
601+
u64 policy; /* In */
602+
u64 ma_gctx_paddr; /* In */
603+
u32 ma_en:1; /* In */
604+
u32 imi_en:1; /* In */
605+
u32 rsvd:30;
606+
u8 gosvw[16]; /* In */
607+
} __packed;
608+
609+
/* SNP support page type */
610+
enum {
611+
SNP_PAGE_TYPE_NORMAL = 0x1,
612+
SNP_PAGE_TYPE_VMSA = 0x2,
613+
SNP_PAGE_TYPE_ZERO = 0x3,
614+
SNP_PAGE_TYPE_UNMEASURED = 0x4,
615+
SNP_PAGE_TYPE_SECRET = 0x5,
616+
SNP_PAGE_TYPE_CPUID = 0x6,
617+
618+
SNP_PAGE_TYPE_MAX
619+
};
620+
621+
/**
622+
* struct sev_data_snp_launch_update - SNP_LAUNCH_UPDATE command params
623+
*
624+
* @gctx_paddr: system physical address of guest context page
625+
* @page_size: page size 0 indicates 4K and 1 indicates 2MB page
626+
* @page_type: encoded page type
627+
* @imi_page: indicates that this page is part of the IMI (Incoming Migration
628+
* Image) of the guest
629+
* @rsvd: reserved
630+
* @rsvd2: reserved
631+
* @address: system physical address of destination page to encrypt
632+
* @rsvd3: reserved
633+
* @vmpl1_perms: VMPL permission mask for VMPL1
634+
* @vmpl2_perms: VMPL permission mask for VMPL2
635+
* @vmpl3_perms: VMPL permission mask for VMPL3
636+
* @rsvd4: reserved
637+
*/
638+
struct sev_data_snp_launch_update {
639+
u64 gctx_paddr; /* In */
640+
u32 page_size:1; /* In */
641+
u32 page_type:3; /* In */
642+
u32 imi_page:1; /* In */
643+
u32 rsvd:27;
644+
u32 rsvd2;
645+
u64 address; /* In */
646+
u32 rsvd3:8;
647+
u32 vmpl1_perms:8; /* In */
648+
u32 vmpl2_perms:8; /* In */
649+
u32 vmpl3_perms:8; /* In */
650+
u32 rsvd4;
651+
} __packed;
652+
653+
/**
654+
* struct sev_data_snp_launch_finish - SNP_LAUNCH_FINISH command params
655+
*
656+
* @gctx_paddr: system physical address of guest context page
657+
* @id_block_paddr: system physical address of ID block
658+
* @id_auth_paddr: system physical address of ID block authentication structure
659+
* @id_block_en: indicates whether ID block is present
660+
* @auth_key_en: indicates whether author key is present in authentication structure
661+
* @rsvd: reserved
662+
* @host_data: host-supplied data for guest, not interpreted by firmware
663+
*/
664+
struct sev_data_snp_launch_finish {
665+
u64 gctx_paddr;
666+
u64 id_block_paddr;
667+
u64 id_auth_paddr;
668+
u8 id_block_en:1;
669+
u8 auth_key_en:1;
670+
u64 rsvd:62;
671+
u8 host_data[32];
672+
} __packed;
673+
674+
/**
675+
* struct sev_data_snp_guest_status - SNP_GUEST_STATUS command params
676+
*
677+
* @gctx_paddr: system physical address of guest context page
678+
* @address: system physical address of guest status page
679+
*/
680+
struct sev_data_snp_guest_status {
681+
u64 gctx_paddr;
682+
u64 address;
683+
} __packed;
684+
685+
/**
686+
* struct sev_data_snp_page_reclaim - SNP_PAGE_RECLAIM command params
687+
*
688+
* @paddr: system physical address of page to be claimed. The 0th bit in the
689+
* address indicates the page size. 0h indicates 4KB and 1h indicates
690+
* 2MB page.
691+
*/
692+
struct sev_data_snp_page_reclaim {
693+
u64 paddr;
694+
} __packed;
695+
696+
/**
697+
* struct sev_data_snp_page_unsmash - SNP_PAGE_UNSMASH command params
698+
*
699+
* @paddr: system physical address of page to be unsmashed. The 0th bit in the
700+
* address indicates the page size. 0h indicates 4 KB and 1h indicates
701+
* 2 MB page.
702+
*/
703+
struct sev_data_snp_page_unsmash {
704+
u64 paddr;
705+
} __packed;
706+
707+
/**
708+
* struct sev_data_snp_dbg - DBG_ENCRYPT/DBG_DECRYPT command parameters
709+
*
710+
* @gctx_paddr: system physical address of guest context page
711+
* @src_addr: source address of data to operate on
712+
* @dst_addr: destination address of data to operate on
713+
*/
714+
struct sev_data_snp_dbg {
715+
u64 gctx_paddr; /* In */
716+
u64 src_addr; /* In */
717+
u64 dst_addr; /* In */
718+
} __packed;
719+
720+
/**
721+
* struct sev_data_snp_guest_request - SNP_GUEST_REQUEST command params
722+
*
723+
* @gctx_paddr: system physical address of guest context page
724+
* @req_paddr: system physical address of request page
725+
* @res_paddr: system physical address of response page
726+
*/
727+
struct sev_data_snp_guest_request {
728+
u64 gctx_paddr; /* In */
729+
u64 req_paddr; /* In */
730+
u64 res_paddr; /* In */
731+
} __packed;
732+
733+
/**
734+
* struct sev_data_snp_init_ex - SNP_INIT_EX structure
735+
*
736+
* @init_rmp: indicate that the RMP should be initialized.
737+
* @list_paddr_en: indicate that list_paddr is valid
738+
* @rsvd: reserved
739+
* @rsvd1: reserved
740+
* @list_paddr: system physical address of range list
741+
* @rsvd2: reserved
742+
*/
743+
struct sev_data_snp_init_ex {
744+
u32 init_rmp:1;
745+
u32 list_paddr_en:1;
746+
u32 rsvd:30;
747+
u32 rsvd1;
748+
u64 list_paddr;
749+
u8 rsvd2[48];
750+
} __packed;
751+
752+
/**
753+
* struct sev_data_range - RANGE structure
754+
*
755+
* @base: system physical address of first byte of range
756+
* @page_count: number of 4KB pages in this range
757+
* @rsvd: reserved
758+
*/
759+
struct sev_data_range {
760+
u64 base;
761+
u32 page_count;
762+
u32 rsvd;
763+
} __packed;
764+
765+
/**
766+
* struct sev_data_range_list - RANGE_LIST structure
767+
*
768+
* @num_elements: number of elements in RANGE_ARRAY
769+
* @rsvd: reserved
770+
* @ranges: array of num_elements of type RANGE
771+
*/
772+
struct sev_data_range_list {
773+
u32 num_elements;
774+
u32 rsvd;
775+
struct sev_data_range ranges[];
776+
} __packed;
777+
778+
/**
779+
* struct sev_data_snp_shutdown_ex - SNP_SHUTDOWN_EX structure
780+
*
781+
* @len: length of the command buffer read by the PSP
782+
* @iommu_snp_shutdown: Disable enforcement of SNP in the IOMMU
783+
* @rsvd1: reserved
784+
*/
785+
struct sev_data_snp_shutdown_ex {
786+
u32 len;
787+
u32 iommu_snp_shutdown:1;
788+
u32 rsvd1:31;
789+
} __packed;
790+
526791
#ifdef CONFIG_CRYPTO_DEV_SP_PSP
527792

528793
/**

include/uapi/linux/psp-sev.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ typedef enum {
6969
SEV_RET_RESOURCE_LIMIT,
7070
SEV_RET_SECURE_DATA_INVALID,
7171
SEV_RET_INVALID_KEY = 0x27,
72+
SEV_RET_INVALID_PAGE_SIZE,
73+
SEV_RET_INVALID_PAGE_STATE,
74+
SEV_RET_INVALID_MDATA_ENTRY,
75+
SEV_RET_INVALID_PAGE_OWNER,
76+
SEV_RET_INVALID_PAGE_AEAD_OFLOW,
77+
SEV_RET_RMP_INIT_REQUIRED,
7278
SEV_RET_MAX,
7379
} sev_ret_code;
7480

@@ -155,6 +161,56 @@ struct sev_user_data_get_id2 {
155161
__u32 length; /* In/Out */
156162
} __packed;
157163

164+
/**
165+
* struct sev_user_data_snp_status - SNP status
166+
*
167+
* @api_major: API major version
168+
* @api_minor: API minor version
169+
* @state: current platform state
170+
* @is_rmp_initialized: whether RMP is initialized or not
171+
* @rsvd: reserved
172+
* @build_id: firmware build id for the API version
173+
* @mask_chip_id: whether chip id is present in attestation reports or not
174+
* @mask_chip_key: whether attestation reports are signed or not
175+
* @vlek_en: VLEK (Version Loaded Endorsement Key) hashstick is loaded
176+
* @rsvd1: reserved
177+
* @guest_count: the number of guest currently managed by the firmware
178+
* @current_tcb_version: current TCB version
179+
* @reported_tcb_version: reported TCB version
180+
*/
181+
struct sev_user_data_snp_status {
182+
__u8 api_major; /* Out */
183+
__u8 api_minor; /* Out */
184+
__u8 state; /* Out */
185+
__u8 is_rmp_initialized:1; /* Out */
186+
__u8 rsvd:7;
187+
__u32 build_id; /* Out */
188+
__u32 mask_chip_id:1; /* Out */
189+
__u32 mask_chip_key:1; /* Out */
190+
__u32 vlek_en:1; /* Out */
191+
__u32 rsvd1:29;
192+
__u32 guest_count; /* Out */
193+
__u64 current_tcb_version; /* Out */
194+
__u64 reported_tcb_version; /* Out */
195+
} __packed;
196+
197+
/**
198+
* struct sev_user_data_snp_config - system wide configuration value for SNP.
199+
*
200+
* @reported_tcb: the TCB version to report in the guest attestation report.
201+
* @mask_chip_id: whether chip id is present in attestation reports or not
202+
* @mask_chip_key: whether attestation reports are signed or not
203+
* @rsvd: reserved
204+
* @rsvd1: reserved
205+
*/
206+
struct sev_user_data_snp_config {
207+
__u64 reported_tcb ; /* In */
208+
__u32 mask_chip_id:1; /* In */
209+
__u32 mask_chip_key:1; /* In */
210+
__u32 rsvd:30; /* In */
211+
__u8 rsvd1[52];
212+
} __packed;
213+
158214
/**
159215
* struct sev_issue_cmd - SEV ioctl parameters
160216
*

0 commit comments

Comments
 (0)