From: Tyler Fanelli <tfanelli@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, mtosatti@redhat.com, stefanha@redhat.com,
philmd@linaro.org, berrange@redhat.com,
marcandre.lureau@gmail.com, Tyler Fanelli <tfanelli@redhat.com>
Subject: [RFC PATCH v2 9/9] i386/sev: Replace SEV_ATTESTATION_REPORT with sev library equivalent
Date: Wed, 4 Oct 2023 16:34:18 -0400 [thread overview]
Message-ID: <20231004203418.56508-10-tfanelli@redhat.com> (raw)
In-Reply-To: <20231004203418.56508-1-tfanelli@redhat.com>
The LAUNCH_ATTESTATION ioctl fetches the guest VM's attestation report
from the PSP.
If the API ioctl call fails, fw_error will be set accordingly.
Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
---
target/i386/sev.c | 81 ++++++++++-------------------------------------
target/i386/sev.h | 2 ++
2 files changed, 18 insertions(+), 65 deletions(-)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 764a89d3a4..bedb8f379e 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -160,27 +160,6 @@ static const char *const sev_fw_errlist[] = {
#define SEV_FW_MAX_ERROR ARRAY_SIZE(sev_fw_errlist)
-static int
-sev_ioctl(int fd, int cmd, void *data, int *error)
-{
- int r;
- struct kvm_sev_cmd input;
-
- memset(&input, 0x0, sizeof(input));
-
- input.id = cmd;
- input.sev_fd = fd;
- input.data = (__u64)(unsigned long)data;
-
- r = kvm_vm_ioctl(kvm_state, KVM_MEMORY_ENCRYPT_OP, &input);
-
- if (error) {
- *error = input.error;
- }
-
- return r;
-}
-
static int
sev_platform_ioctl(int fd, int cmd, void *data, int *error)
{
@@ -629,75 +608,47 @@ SevCapability *qmp_query_sev_capabilities(Error **errp)
return sev_get_capabilities(errp);
}
-static SevAttestationReport *sev_get_attestation_report(const char *mnonce,
- Error **errp)
+SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce_b64,
+ Error **errp)
{
- struct kvm_sev_attestation_report input = {};
SevAttestationReport *report = NULL;
- SevGuestState *sev = sev_guest;
- g_autofree guchar *data = NULL;
- g_autofree guchar *buf = NULL;
- gsize len;
- int err = 0, ret;
+ g_autofree guchar *data = NULL, *mnonce = NULL;
+ gsize len, data_len;
+ int ret, fw_error;
+ KVMState *s = kvm_state;
if (!sev_enabled()) {
error_setg(errp, "SEV is not enabled");
return NULL;
}
- /* lets decode the mnonce string */
- buf = g_base64_decode(mnonce, &len);
- if (!buf) {
+ mnonce = g_base64_decode(mnonce_b64, &len);
+ if (!mnonce) {
error_setg(errp, "SEV: failed to decode mnonce input");
return NULL;
}
- /* verify the input mnonce length */
- if (len != sizeof(input.mnonce)) {
- error_setg(errp, "SEV: mnonce must be %zu bytes (got %" G_GSIZE_FORMAT ")",
- sizeof(input.mnonce), len);
+ if (len != SEV_ATTESTATION_REPORT_MNONCE_SIZE) {
+ error_setg(errp, "SEV: mnonce must be %d bytes (found %" G_GSIZE_FORMAT ")",
+ SEV_ATTESTATION_REPORT_MNONCE_SIZE, len);
return NULL;
}
- /* Query the report length */
- ret = sev_ioctl(sev->sev_fd, KVM_SEV_GET_ATTESTATION_REPORT,
- &input, &err);
- if (ret < 0) {
- if (err != SEV_RET_INVALID_LEN) {
- error_setg(errp, "SEV: Failed to query the attestation report"
- " length ret=%d fw_err=%d (%s)",
- ret, err, fw_error_to_str(err));
- return NULL;
- }
- }
-
- data = g_malloc(input.len);
- input.uaddr = (unsigned long)data;
- memcpy(input.mnonce, buf, sizeof(input.mnonce));
-
- /* Query the report */
- ret = sev_ioctl(sev->sev_fd, KVM_SEV_GET_ATTESTATION_REPORT,
- &input, &err);
+ ret = sev_attestation_report(s->vmfd, mnonce, len, (void *) data,
+ (unsigned int *) &data_len, &fw_error);
if (ret) {
error_setg_errno(errp, errno, "SEV: Failed to get attestation report"
- " ret=%d fw_err=%d (%s)", ret, err, fw_error_to_str(err));
- return NULL;
+ " ret = %d fw_err=%d (%s)", ret, fw_error, fw_error_to_str(fw_error));
}
report = g_new0(SevAttestationReport, 1);
- report->data = g_base64_encode(data, input.len);
+ report->data = g_base64_encode(data, data_len);
- trace_kvm_sev_attestation_report(mnonce, report->data);
+ trace_kvm_sev_attestation_report((char *) mnonce, report->data);
return report;
}
-SevAttestationReport *qmp_query_sev_attestation_report(const char *mnonce,
- Error **errp)
-{
- return sev_get_attestation_report(mnonce, errp);
-}
-
static int
sev_read_file_base64(const char *filename, guchar **data, gsize *len)
{
diff --git a/target/i386/sev.h b/target/i386/sev.h
index f1af28eca0..a90909450c 100644
--- a/target/i386/sev.h
+++ b/target/i386/sev.h
@@ -48,6 +48,8 @@ bool sev_es_enabled(void);
#define sev_es_enabled() 0
#endif
+#define SEV_ATTESTATION_REPORT_MNONCE_SIZE 16
+
uint32_t sev_get_cbit_position(void);
uint32_t sev_get_reduced_phys_bits(void);
bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp);
--
2.40.1
prev parent reply other threads:[~2023-10-04 20:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-04 20:34 [RFC PATCH v2 0/9] i386/sev: Use C API of Rust SEV library Tyler Fanelli
2023-10-04 20:34 ` [RFC PATCH v2 1/9] Add Rust SEV library as subproject Tyler Fanelli
2023-10-05 6:03 ` Philippe Mathieu-Daudé
2023-10-05 23:41 ` Tyler Fanelli
2023-10-11 3:05 ` Tyler Fanelli
2023-10-05 15:54 ` Stefan Hajnoczi
2023-10-11 3:10 ` Tyler Fanelli
2023-10-13 18:09 ` Manos Pitsidianakis
2023-10-13 18:20 ` Tyler Fanelli
2023-10-16 9:16 ` Daniel P. Berrangé
2023-10-16 13:38 ` Philippe Mathieu-Daudé
2023-10-16 13:51 ` Stefan Hajnoczi
2024-03-05 13:47 ` Daniel P. Berrangé
2024-03-05 15:40 ` Philippe Mathieu-Daudé
2023-10-04 20:34 ` [RFC PATCH v2 2/9] i386/sev: Replace INIT and ES_INIT ioctls with sev library equivalents Tyler Fanelli
2023-10-04 20:34 ` [RFC PATCH v2 3/9] i386/sev: Replace LAUNCH_START ioctl with sev library equivalent Tyler Fanelli
2023-10-04 20:34 ` [RFC PATCH v2 4/9] i386/sev: Replace UPDATE_DATA " Tyler Fanelli
2023-10-04 20:34 ` [RFC PATCH v2 5/9] i386/sev: Replace LAUNCH_UPDATE_VMSA " Tyler Fanelli
2023-10-04 20:34 ` [RFC PATCH v2 6/9] i386/sev: Replace LAUNCH_MEASURE " Tyler Fanelli
2023-10-04 20:34 ` [RFC PATCH v2 7/9] i386/sev: Replace LAUNCH_SECRET " Tyler Fanelli
2023-10-04 20:34 ` [RFC PATCH v2 8/9] i386/sev: Replace LAUNCH_FINISH " Tyler Fanelli
2023-10-04 20:34 ` Tyler Fanelli [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231004203418.56508-10-tfanelli@redhat.com \
--to=tfanelli@redhat.com \
--cc=berrange@redhat.com \
--cc=marcandre.lureau@gmail.com \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).