On 6/3/24 23:43, Paolo Bonzini wrote:
From: Brijesh Singh <brijesh.si...@amd.com>
Process any queued up launch data and encrypt/measure it into the SNP
guest instance prior to initial guest launch.
This also updates the KVM_SEV_SNP_LAUNCH_UPDATE call to handle partial
update responses.
Signed-off-by: Brijesh Singh <brijesh.si...@amd.com>
Co-developed-by: Michael Roth <michael.r...@amd.com>
Signed-off-by: Michael Roth <michael.r...@amd.com>
Co-developed-by: Pankaj Gupta <pankaj.gu...@amd.com>
Signed-off-by: Pankaj Gupta <pankaj.gu...@amd.com>
Message-ID: <20240530111643.1091816-17-pankaj.gu...@amd.com>
Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
---
target/i386/sev.c | 112 ++++++++++++++++++++++++++++++++++++++-
target/i386/trace-events | 2 +
2 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index e89b87d2f55..ef2e592ca76 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -756,6 +756,76 @@ out:
return ret;
}
+static const char *
+snp_page_type_to_str(int type)
+{
+ switch (type) {
+ case KVM_SEV_SNP_PAGE_TYPE_NORMAL: return "Normal";
+ case KVM_SEV_SNP_PAGE_TYPE_ZERO: return "Zero";
+ case KVM_SEV_SNP_PAGE_TYPE_UNMEASURED: return "Unmeasured";
+ case KVM_SEV_SNP_PAGE_TYPE_SECRETS: return "Secrets";
+ case KVM_SEV_SNP_PAGE_TYPE_CPUID: return "Cpuid";
+ default: return "unknown";
+ }
+}
+
+static int
+sev_snp_launch_update(SevSnpGuestState *sev_snp_guest,
+ SevLaunchUpdateData *data)
+{
+ int ret, fw_error;
+ struct kvm_sev_snp_launch_update update = {0};
+
+ if (!data->hva || !data->len) {
+ error_report("SNP_LAUNCH_UPDATE called with invalid address"
+ "/ length: %p / %lx",
+ data->hva, data->len);
This patch does not compile on 32-bit x86:
../src/target/i386/sev.c: In function 'sev_snp_launch_update':
../src/target/i386/sev.c:886:22: error: format '%lx' expects argument of type 'long
unsigned int', but argument 3 has type 'uint64_t' {aka 'long long unsigned int'}
[-Werror=format=]
886 | error_report("SNP_LAUNCH_UPDATE called with invalid address"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
887 | "/ length: %p / %lx",
888 | data->hva, data->len);
| ~~~~~~~~~
| |
| uint64_t {aka long long unsigned
int}
../src/target/i386/sev.c:935:22: error: format '%lx' expects argument of type 'long
unsigned int', but argument 2 has type 'hwaddr' {aka 'long long unsigned int'}
[-Werror=format=]
935 | error_report("SEV-SNP: expected update of GPA range %lx-%lx,"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
936 | "got GPA range %lx-%llx",
937 | data->gpa, data->gpa + data->len, data->gpa,
| ~~~~~~~~~
| |
| hwaddr {aka long long unsigned int}
../src/target/i386/sev.c:935:22: error: format '%lx' expects argument of type 'long
unsigned int', but argument 3 has type 'long long unsigned int' [-Werror=format=]
935 | error_report("SEV-SNP: expected update of GPA range %lx-%lx,"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
936 | "got GPA range %lx-%llx",
937 | data->gpa, data->gpa + data->len, data->gpa,
| ~~~~~~~~~~~~~~~~~~~~~
| |
| long long unsigned int
../src/target/i386/sev.c:935:22: error: format '%lx' expects argument of type 'long
unsigned int', but argument 4 has type 'hwaddr' {aka 'long long unsigned int'}
[-Werror=format=]
935 | error_report("SEV-SNP: expected update of GPA range %lx-%lx,"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
936 | "got GPA range %lx-%llx",
937 | data->gpa, data->gpa + data->len, data->gpa,
| ~~~~~~~~~
| |
| hwaddr {aka long long
unsigned int}
In file included from ../src/target/i386/sev.c:22:
../src/target/i386/sev.c: In function
'sev_snp_guest_set_guest_visible_workarounds':
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of
type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'}
[-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2149:9: note: in expansion of macro 'error_setg'
2149 | error_setg(errp, "parameter length of %lu exceeds max of %lu",
| ^~~~~~~~~~
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of
type 'long unsigned int', but argument 7 has type 'unsigned int' [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2149:9: note: in expansion of macro 'error_setg'
2149 | error_setg(errp, "parameter length of %lu exceeds max of %lu",
| ^~~~~~~~~~
../src/target/i386/sev.c: In function 'sev_snp_guest_set_id_block':
../src/target/i386/sev.c:2174:12: error: cast to pointer from integer of different size
[-Werror=int-to-pointer-cast]
2174 | g_free((guchar *)finish->id_block_uaddr);
| ^
../src/target/i386/sev.c:2180:9: error: cast from pointer to integer of different size
[-Werror=pointer-to-int-cast]
2180 | (uint64_t)qbase64_decode(sev_snp_guest->id_block, -1, &len,
errp);
| ^
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of
type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'}
[-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2187:9: note: in expansion of macro 'error_setg'
2187 | error_setg(errp, "parameter length of %lu not equal to %u",
| ^~~~~~~~~~
../src/target/i386/sev.c: In function 'sev_snp_guest_set_id_auth':
../src/target/i386/sev.c:2211:12: error: cast to pointer from integer of different size
[-Werror=int-to-pointer-cast]
2211 | g_free((guchar *)finish->id_auth_uaddr);
| ^
../src/target/i386/sev.c:2217:9: error: cast from pointer to integer of different size
[-Werror=pointer-to-int-cast]
2217 | (uint64_t)qbase64_decode(sev_snp_guest->id_auth, -1, &len,
errp);
| ^
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of
type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'}
[-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2224:9: note: in expansion of macro 'error_setg'
2224 | error_setg(errp, "parameter length:ID_AUTH %lu exceeds max of
%u",
| ^~~~~~~~~~
../src/target/i386/sev.c: In function 'sev_snp_guest_set_host_data':
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of
type 'long unsigned int', but argument 6 has type 'gsize' {aka 'unsigned int'}
[-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2290:9: note: in expansion of macro 'error_setg'
2290 | error_setg(errp, "parameter length of %lu not equal to %lu",
| ^~~~~~~~~~
/home/rth/qemu/src/include/qapi/error.h:319:25: error: format '%lu' expects argument of
type 'long unsigned int', but argument 7 has type 'unsigned int' [-Werror=format=]
319 | (fmt), ## __VA_ARGS__)
| ^~~~~
../src/target/i386/sev.c:2290:9: note: in expansion of macro 'error_setg'
2290 | error_setg(errp, "parameter length of %lu not equal to %lu",
| ^~~~~~~~~~
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.
r~