136 lines
4.1 KiB
Diff
136 lines
4.1 KiB
Diff
|
|
From f6753191237118294d04193908db503bb87619f7 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Brijesh Singh <brijesh.singh@amd.com>
|
||
|
|
Date: Tue, 27 Jul 2021 12:10:23 +0000
|
||
|
|
Subject: [PATCH] target/i386: sev: provide callback to setup outgoing context
|
||
|
|
|
||
|
|
cherry-picked from https://github.com/AMDESE/qemu/commit/7521883afc0.
|
||
|
|
|
||
|
|
The user provides the target machine's Platform Diffie-Hellman key (PDH)
|
||
|
|
and certificate chain before starting the SEV guest migration. Cache the
|
||
|
|
certificate chain as we need them while creating the outgoing context.
|
||
|
|
|
||
|
|
Signed-off-by: Brijesh Singh <brijesh.singh@amd.com>
|
||
|
|
Co-developed-by: Ashish Kalra <ashish.kalra@amd.com>
|
||
|
|
Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
|
||
|
|
[ Fix conflict. ]
|
||
|
|
Signed-off-by: hanliyang <hanliyang@hygon.cn>
|
||
|
|
---
|
||
|
|
target/i386/sev.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++
|
||
|
|
target/i386/sev.h | 2 ++
|
||
|
|
2 files changed, 61 insertions(+)
|
||
|
|
|
||
|
|
diff --git a/target/i386/sev.c b/target/i386/sev.c
|
||
|
|
index 1a9d1db7a8..10233511cf 100644
|
||
|
|
--- a/target/i386/sev.c
|
||
|
|
+++ b/target/i386/sev.c
|
||
|
|
@@ -73,6 +73,12 @@ struct SevGuestState {
|
||
|
|
int sev_fd;
|
||
|
|
SevState state;
|
||
|
|
gchar *measurement;
|
||
|
|
+ guchar *remote_pdh;
|
||
|
|
+ size_t remote_pdh_len;
|
||
|
|
+ guchar *remote_plat_cert;
|
||
|
|
+ size_t remote_plat_cert_len;
|
||
|
|
+ guchar *amd_cert;
|
||
|
|
+ size_t amd_cert_len;
|
||
|
|
|
||
|
|
uint32_t reset_cs;
|
||
|
|
uint32_t reset_ip;
|
||
|
|
@@ -157,6 +163,12 @@ static const char *const sev_fw_errlist[] = {
|
||
|
|
|
||
|
|
#define SEV_FW_MAX_ERROR ARRAY_SIZE(sev_fw_errlist)
|
||
|
|
|
||
|
|
+#define SEV_FW_BLOB_MAX_SIZE 0x4000 /* 16KB */
|
||
|
|
+
|
||
|
|
+static struct ConfidentialGuestMemoryEncryptionOps sev_memory_encryption_ops = {
|
||
|
|
+ .save_setup = sev_save_setup,
|
||
|
|
+};
|
||
|
|
+
|
||
|
|
static int
|
||
|
|
sev_ioctl(int fd, int cmd, void *data, int *error)
|
||
|
|
{
|
||
|
|
@@ -906,6 +918,48 @@ sev_vm_state_change(void *opaque, bool running, RunState state)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
+static inline bool check_blob_length(size_t value)
|
||
|
|
+{
|
||
|
|
+ if (value > SEV_FW_BLOB_MAX_SIZE) {
|
||
|
|
+ error_report("invalid length max=%d got=%ld",
|
||
|
|
+ SEV_FW_BLOB_MAX_SIZE, value);
|
||
|
|
+ return false;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return true;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
+int sev_save_setup(const char *pdh, const char *plat_cert,
|
||
|
|
+ const char *amd_cert)
|
||
|
|
+{
|
||
|
|
+ SevGuestState *s = sev_guest;
|
||
|
|
+
|
||
|
|
+ s->remote_pdh = g_base64_decode(pdh, &s->remote_pdh_len);
|
||
|
|
+ if (!check_blob_length(s->remote_pdh_len)) {
|
||
|
|
+ goto error;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ s->remote_plat_cert = g_base64_decode(plat_cert,
|
||
|
|
+ &s->remote_plat_cert_len);
|
||
|
|
+ if (!check_blob_length(s->remote_plat_cert_len)) {
|
||
|
|
+ goto error;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ s->amd_cert = g_base64_decode(amd_cert, &s->amd_cert_len);
|
||
|
|
+ if (!check_blob_length(s->amd_cert_len)) {
|
||
|
|
+ goto error;
|
||
|
|
+ }
|
||
|
|
+
|
||
|
|
+ return 0;
|
||
|
|
+
|
||
|
|
+error:
|
||
|
|
+ g_free(s->remote_pdh);
|
||
|
|
+ g_free(s->remote_plat_cert);
|
||
|
|
+ g_free(s->amd_cert);
|
||
|
|
+
|
||
|
|
+ return 1;
|
||
|
|
+}
|
||
|
|
+
|
||
|
|
int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
|
||
|
|
{
|
||
|
|
SevGuestState *sev
|
||
|
|
@@ -920,6 +974,9 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
|
||
|
|
return 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
+ ConfidentialGuestSupportClass *cgs_class =
|
||
|
|
+ (ConfidentialGuestSupportClass *) object_get_class(OBJECT(cgs));
|
||
|
|
+
|
||
|
|
ret = ram_block_discard_disable(true);
|
||
|
|
if (ret) {
|
||
|
|
error_report("%s: cannot disable RAM discard", __func__);
|
||
|
|
@@ -1013,6 +1070,8 @@ int sev_kvm_init(ConfidentialGuestSupport *cgs, Error **errp)
|
||
|
|
qemu_add_machine_init_done_notifier(&sev_machine_done_notify);
|
||
|
|
qemu_add_vm_change_state_handler(sev_vm_state_change, sev);
|
||
|
|
|
||
|
|
+ cgs_class->memory_encryption_ops = &sev_memory_encryption_ops;
|
||
|
|
+
|
||
|
|
cgs->ready = true;
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
diff --git a/target/i386/sev.h b/target/i386/sev.h
|
||
|
|
index e7499c95b1..e96de021f5 100644
|
||
|
|
--- a/target/i386/sev.h
|
||
|
|
+++ b/target/i386/sev.h
|
||
|
|
@@ -51,6 +51,8 @@ uint32_t sev_get_reduced_phys_bits(void);
|
||
|
|
bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp);
|
||
|
|
|
||
|
|
int sev_encrypt_flash(uint8_t *ptr, uint64_t len, Error **errp);
|
||
|
|
+int sev_save_setup(const char *pdh, const char *plat_cert,
|
||
|
|
+ const char *amd_cert);
|
||
|
|
int sev_inject_launch_secret(const char *hdr, const char *secret,
|
||
|
|
uint64_t gpa, Error **errp);
|
||
|
|
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|