Skip to content

Commit f5db884

Browse files
codomaniabp3tk0v
authored andcommitted
crypto: ccp: Add the SNP_PLATFORM_STATUS command
This command is used to query the SNP platform status. See the SEV-SNP spec for more details. Signed-off-by: Brijesh Singh <brijesh.singh@amd.com> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com> Signed-off-by: Michael Roth <michael.roth@amd.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20240126041126.1927228-24-michael.roth@amd.com
1 parent c3b86e6 commit f5db884

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

Documentation/virt/coco/sev-guest.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ 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+
struct sev_issue_cmd {
75+
/* Command ID */
76+
__u32 cmd;
77+
78+
/* Command request structure */
79+
__u64 data;
80+
81+
/* Firmware error code on failure (see psp-sev.h) */
82+
__u32 error;
83+
};
84+
85+
7086
2.1 SNP_GET_REPORT
7187
------------------
7288

@@ -124,6 +140,17 @@ be updated with the expected value.
124140

125141
See GHCB specification for further detail on how to parse the certificate blob.
126142

143+
2.4 SNP_PLATFORM_STATUS
144+
-----------------------
145+
:Technology: sev-snp
146+
:Type: hypervisor ioctl cmd
147+
:Parameters (out): struct sev_user_data_snp_status
148+
:Returns (out): 0 on success, -negative on error
149+
150+
The SNP_PLATFORM_STATUS command is used to query the SNP platform status. The
151+
status includes API major, minor version and more. See the SEV-SNP
152+
specification for further details.
153+
127154
3. SEV-SNP CPUID Enforcement
128155
============================
129156

drivers/crypto/ccp/sev-dev.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,55 @@ static int sev_ioctl_do_pdh_export(struct sev_issue_cmd *argp, bool writable)
19411941
return ret;
19421942
}
19431943

1944+
static int sev_ioctl_do_snp_platform_status(struct sev_issue_cmd *argp)
1945+
{
1946+
struct sev_device *sev = psp_master->sev_data;
1947+
struct sev_data_snp_addr buf;
1948+
struct page *status_page;
1949+
void *data;
1950+
int ret;
1951+
1952+
if (!sev->snp_initialized || !argp->data)
1953+
return -EINVAL;
1954+
1955+
status_page = alloc_page(GFP_KERNEL_ACCOUNT);
1956+
if (!status_page)
1957+
return -ENOMEM;
1958+
1959+
data = page_address(status_page);
1960+
1961+
/*
1962+
* Firmware expects status page to be in firmware-owned state, otherwise
1963+
* it will report firmware error code INVALID_PAGE_STATE (0x1A).
1964+
*/
1965+
if (rmp_mark_pages_firmware(__pa(data), 1, true)) {
1966+
ret = -EFAULT;
1967+
goto cleanup;
1968+
}
1969+
1970+
buf.address = __psp_pa(data);
1971+
ret = __sev_do_cmd_locked(SEV_CMD_SNP_PLATFORM_STATUS, &buf, &argp->error);
1972+
1973+
/*
1974+
* Status page will be transitioned to Reclaim state upon success, or
1975+
* left in Firmware state in failure. Use snp_reclaim_pages() to
1976+
* transition either case back to Hypervisor-owned state.
1977+
*/
1978+
if (snp_reclaim_pages(__pa(data), 1, true))
1979+
return -EFAULT;
1980+
1981+
if (ret)
1982+
goto cleanup;
1983+
1984+
if (copy_to_user((void __user *)argp->data, data,
1985+
sizeof(struct sev_user_data_snp_status)))
1986+
ret = -EFAULT;
1987+
1988+
cleanup:
1989+
__free_pages(status_page, 0);
1990+
return ret;
1991+
}
1992+
19441993
static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
19451994
{
19461995
void __user *argp = (void __user *)arg;
@@ -1992,6 +2041,9 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
19922041
case SEV_GET_ID2:
19932042
ret = sev_ioctl_do_get_id2(&input);
19942043
break;
2044+
case SNP_PLATFORM_STATUS:
2045+
ret = sev_ioctl_do_snp_platform_status(&input);
2046+
break;
19952047
default:
19962048
ret = -EINVAL;
19972049
goto out;

include/uapi/linux/psp-sev.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum {
2828
SEV_PEK_CERT_IMPORT,
2929
SEV_GET_ID, /* This command is deprecated, use SEV_GET_ID2 */
3030
SEV_GET_ID2,
31+
SNP_PLATFORM_STATUS,
3132

3233
SEV_MAX,
3334
};

0 commit comments

Comments
 (0)