]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
crypto: ccp: Add the SNP_SET_CONFIG command
authorBrijesh Singh <brijesh.singh@amd.com>
Fri, 26 Jan 2024 04:11:25 +0000 (22:11 -0600)
committerBorislav Petkov (AMD) <bp@alien8.de>
Mon, 29 Jan 2024 19:34:19 +0000 (20:34 +0100)
The SEV-SNP firmware provides the SNP_CONFIG command used to set various
system-wide configuration values for SNP guests, such as the reported
TCB version used when signing guest attestation reports. Add an
interface to set this via userspace.

  [ mdr: Squash in doc patch from Dionna, drop extended request/
    certificate handling and simplify this to a simple wrapper around
    SNP_CONFIG fw cmd. ]

Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
Co-developed-by: Alexey Kardashevskiy <aik@amd.com>
Signed-off-by: Alexey Kardashevskiy <aik@amd.com>
Co-developed-by: Dionna Glaze <dionnaglaze@google.com>
Signed-off-by: Dionna Glaze <dionnaglaze@google.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-26-michael.roth@amd.com
Documentation/virt/coco/sev-guest.rst
drivers/crypto/ccp/sev-dev.c
include/uapi/linux/psp-sev.h

index 007ae828aa2ab71af211fd8b827c3cc952ee3a95..14c9de997b7d34d7e9e0c4352dbf9a174ea08d38 100644 (file)
@@ -162,6 +162,19 @@ SEV-SNP firmware SNP_COMMIT command. This prevents roll-back to a previously
 committed firmware version. This will also update the reported TCB to match
 that of the currently installed firmware.
 
+2.6 SNP_SET_CONFIG
+------------------
+:Technology: sev-snp
+:Type: hypervisor ioctl cmd
+:Parameters (in): struct sev_user_data_snp_config
+:Returns (out): 0 on success, -negative on error
+
+SNP_SET_CONFIG is used to set the system-wide configuration such as
+reported TCB version in the attestation report. The command is similar
+to SNP_CONFIG command defined in the SEV-SNP spec. The current values of
+the firmware parameters affected by this command can be queried via
+SNP_PLATFORM_STATUS.
+
 3. SEV-SNP CPUID Enforcement
 ============================
 
index 6e375d15755cbce1f728177629bb7b875034356b..f1a5795ffadb01673516a26b4030765b0721adcf 100644 (file)
@@ -2004,6 +2004,23 @@ static int sev_ioctl_do_snp_commit(struct sev_issue_cmd *argp)
        return __sev_do_cmd_locked(SEV_CMD_SNP_COMMIT, &buf, &argp->error);
 }
 
+static int sev_ioctl_do_snp_set_config(struct sev_issue_cmd *argp, bool writable)
+{
+       struct sev_device *sev = psp_master->sev_data;
+       struct sev_user_data_snp_config config;
+
+       if (!sev->snp_initialized || !argp->data)
+               return -EINVAL;
+
+       if (!writable)
+               return -EPERM;
+
+       if (copy_from_user(&config, (void __user *)argp->data, sizeof(config)))
+               return -EFAULT;
+
+       return __sev_do_cmd_locked(SEV_CMD_SNP_CONFIG, &config, &argp->error);
+}
+
 static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
 {
        void __user *argp = (void __user *)arg;
@@ -2061,6 +2078,9 @@ static long sev_ioctl(struct file *file, unsigned int ioctl, unsigned long arg)
        case SNP_COMMIT:
                ret = sev_ioctl_do_snp_commit(&input);
                break;
+       case SNP_SET_CONFIG:
+               ret = sev_ioctl_do_snp_set_config(&input, writable);
+               break;
        default:
                ret = -EINVAL;
                goto out;
index 35c207664e95d1a3fe7a325ad45147297f232a13..b7a2c2ee35b7e8099178cc410f9756b2b5f3ce44 100644 (file)
@@ -30,6 +30,7 @@ enum {
        SEV_GET_ID2,
        SNP_PLATFORM_STATUS,
        SNP_COMMIT,
+       SNP_SET_CONFIG,
 
        SEV_MAX,
 };