From: "Daniel P. Berrangé" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Daniel P. Berrangé" <berrange@redhat.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
kvm@vger.kernel.org, "Marcelo Tosatti" <mtosatti@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Dov Murik" <dovmurik@linux.ibm.com>,
"Brijesh Singh" <brijesh.singh@amd.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Eric Blake" <eblake@redhat.com>
Subject: [PULL 6/6] target/i386/sev: Replace qemu_map_ram_ptr with address_space_map
Date: Thu, 18 Nov 2021 13:35:32 +0000 [thread overview]
Message-ID: <20211118133532.2029166-7-berrange@redhat.com> (raw)
In-Reply-To: <20211118133532.2029166-1-berrange@redhat.com>
From: Dov Murik <dovmurik@linux.ibm.com>
Use address_space_map/unmap and check for errors.
Signed-off-by: Dov Murik <dovmurik@linux.ibm.com>
Acked-by: Brijesh Singh <brijesh.singh@amd.com>
[Two lines wrapped for length - Daniel]
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
target/i386/sev.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/target/i386/sev.c b/target/i386/sev.c
index 4fd258a570..025ff7a6f8 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -37,6 +37,7 @@
#include "qapi/qmp/qerror.h"
#include "exec/confidential-guest-support.h"
#include "hw/i386/pc.h"
+#include "exec/address-spaces.h"
#define TYPE_SEV_GUEST "sev-guest"
OBJECT_DECLARE_SIMPLE_TYPE(SevGuestState, SEV_GUEST)
@@ -1232,6 +1233,9 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)
uint8_t kernel_hash[HASH_SIZE];
uint8_t *hashp;
size_t hash_len = HASH_SIZE;
+ hwaddr mapped_len = sizeof(*padded_ht);
+ MemTxAttrs attrs = { 0 };
+ bool ret = true;
/*
* Only add the kernel hashes if the sev-guest configuration explicitly
@@ -1292,7 +1296,12 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)
* Populate the hashes table in the guest's memory at the OVMF-designated
* area for the SEV hashes table
*/
- padded_ht = qemu_map_ram_ptr(NULL, area->base);
+ padded_ht = address_space_map(&address_space_memory, area->base,
+ &mapped_len, true, attrs);
+ if (!padded_ht || mapped_len != sizeof(*padded_ht)) {
+ error_setg(errp, "SEV: cannot map hashes table guest memory area");
+ return false;
+ }
ht = &padded_ht->ht;
ht->guid = sev_hash_table_header_guid;
@@ -1314,10 +1323,13 @@ bool sev_add_kernel_loader_hashes(SevKernelLoaderContext *ctx, Error **errp)
memset(padded_ht->padding, 0, sizeof(padded_ht->padding));
if (sev_encrypt_flash((uint8_t *)padded_ht, sizeof(*padded_ht), errp) < 0) {
- return false;
+ ret = false;
}
- return true;
+ address_space_unmap(&address_space_memory, padded_ht,
+ mapped_len, true, mapped_len);
+
+ return ret;
}
static void
--
2.31.1
next prev parent reply other threads:[~2021-11-18 14:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 13:35 [PULL 0/6 for-6.2] AMD SEV patches Daniel P. Berrangé
2021-11-18 13:35 ` [PULL 1/6] qapi/qom, target/i386: sev-guest: Introduce kernel-hashes=on|off option Daniel P. Berrangé
2021-11-18 13:35 ` [PULL 2/6] target/i386/sev: Add kernel hashes only if sev-guest.kernel-hashes=on Daniel P. Berrangé
2021-11-18 13:35 ` [PULL 3/6] target/i386/sev: Rephrase error message when no hashes table in guest firmware Daniel P. Berrangé
2021-11-18 13:35 ` [PULL 4/6] target/i386/sev: Fail when invalid hashes table area detected Daniel P. Berrangé
2021-11-18 13:35 ` [PULL 5/6] target/i386/sev: Perform padding calculations at compile-time Daniel P. Berrangé
2021-11-18 13:35 ` Daniel P. Berrangé [this message]
2021-11-18 16:37 ` [PULL 0/6 for-6.2] AMD SEV patches Richard Henderson
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=20211118133532.2029166-7-berrange@redhat.com \
--to=berrange@redhat.com \
--cc=armbru@redhat.com \
--cc=brijesh.singh@amd.com \
--cc=dovmurik@linux.ibm.com \
--cc=eblake@redhat.com \
--cc=ehabkost@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).