[PATCH 2/5] target/i386: SEV: store pointer to decoded id_block in SevSnpGuest

Paolo Bonzini posted 5 patches 5 months ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
[PATCH 2/5] target/i386: SEV: store pointer to decoded id_block in SevSnpGuest
Posted by Paolo Bonzini 5 months ago
Do not rely on finish->id_block_uaddr, so that there are no casts from
pointer to uint64_t.  They break on 32-bit hosts.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/sev.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/target/i386/sev.c b/target/i386/sev.c
index 6daa8c264cd..2d4cfd41e83 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -153,6 +153,7 @@ struct SevSnpGuestState {
     /* configuration parameters */
     char *guest_visible_workarounds;
     char *id_block_base64;
+    uint8_t *id_block;
     char *id_auth;
     char *host_data;
 
@@ -2170,16 +2171,15 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
     gsize len;
 
     finish->id_block_en = 0;
+    g_free(sev_snp_guest->id_block);
     g_free(sev_snp_guest->id_block_base64);
-    g_free((guchar *)finish->id_block_uaddr);
 
     /* store the base64 str so we don't need to re-encode in getter */
     sev_snp_guest->id_block_base64 = g_strdup(value);
+    sev_snp_guest->id_block =
+        qbase64_decode(sev_snp_guest->id_block_base64, -1, &len, errp);
 
-    finish->id_block_uaddr =
-        (uint64_t)qbase64_decode(sev_snp_guest->id_block_base64, -1, &len, errp);
-
-    if (!finish->id_block_uaddr) {
+    if (!sev_snp_guest->id_block) {
         return;
     }
 
@@ -2190,6 +2190,7 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
     }
 
     finish->id_block_en = 1;
+    finish->id_block_uaddr = (uintptr_t)sev_snp_guest->id_block;
 }
 
 static char *
-- 
2.45.2
Re: [PATCH 2/5] target/i386: SEV: store pointer to decoded id_block in SevSnpGuest
Posted by Richard Henderson 5 months ago
On 6/27/24 07:53, Paolo Bonzini wrote:
> Do not rely on finish->id_block_uaddr, so that there are no casts from
> pointer to uint64_t.  They break on 32-bit hosts.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   target/i386/sev.c | 11 ++++++-----
>   1 file changed, 6 insertions(+), 5 deletions(-)

Yes, that is better than my patch 1.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~

> 
> diff --git a/target/i386/sev.c b/target/i386/sev.c
> index 6daa8c264cd..2d4cfd41e83 100644
> --- a/target/i386/sev.c
> +++ b/target/i386/sev.c
> @@ -153,6 +153,7 @@ struct SevSnpGuestState {
>       /* configuration parameters */
>       char *guest_visible_workarounds;
>       char *id_block_base64;
> +    uint8_t *id_block;
>       char *id_auth;
>       char *host_data;
>   
> @@ -2170,16 +2171,15 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
>       gsize len;
>   
>       finish->id_block_en = 0;
> +    g_free(sev_snp_guest->id_block);
>       g_free(sev_snp_guest->id_block_base64);
> -    g_free((guchar *)finish->id_block_uaddr);
>   
>       /* store the base64 str so we don't need to re-encode in getter */
>       sev_snp_guest->id_block_base64 = g_strdup(value);
> +    sev_snp_guest->id_block =
> +        qbase64_decode(sev_snp_guest->id_block_base64, -1, &len, errp);
>   
> -    finish->id_block_uaddr =
> -        (uint64_t)qbase64_decode(sev_snp_guest->id_block_base64, -1, &len, errp);
> -
> -    if (!finish->id_block_uaddr) {
> +    if (!sev_snp_guest->id_block) {
>           return;
>       }
>   
> @@ -2190,6 +2190,7 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
>       }
>   
>       finish->id_block_en = 1;
> +    finish->id_block_uaddr = (uintptr_t)sev_snp_guest->id_block;
>   }
>   
>   static char *