qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues
@ 2024-06-26 19:49 Richard Henderson
  2024-06-26 19:49 ` [PATCH 1/3] target/i386/sev: Cast id_auth_uaddr through uintptr_t Richard Henderson
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Richard Henderson @ 2024-06-26 19:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, alex.bennee, berrange, philmd

I separated the fixes into 3 smaller patches
that may be easier to review.

r~

Richard Henderson (3):
  target/i386/sev: Cast id_auth_uaddr through uintptr_t
  target/i386/sev: Use size_t for object sizes
  target/i386/sev: Fix printf formats

 target/i386/sev.c        | 41 ++++++++++++++++++++++------------------
 target/i386/trace-events |  2 +-
 2 files changed, 24 insertions(+), 19 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] target/i386/sev: Cast id_auth_uaddr through uintptr_t
  2024-06-26 19:49 [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Richard Henderson
@ 2024-06-26 19:49 ` Richard Henderson
  2024-06-26 19:49 ` [PATCH 2/3] target/i386/sev: Use size_t for object sizes Richard Henderson
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2024-06-26 19:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, alex.bennee, berrange, philmd

This member is __u64 in the kernel structure.
Cast via uintptr_t to match the host's pointer size.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/i386/sev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/target/i386/sev.c b/target/i386/sev.c
index 30b83f1d77..9dfdac69ab 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -2171,13 +2171,13 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
 
     finish->id_block_en = 0;
     g_free(sev_snp_guest->id_block);
-    g_free((guchar *)finish->id_block_uaddr);
+    g_free((void *)(uintptr_t)finish->id_block_uaddr);
 
     /* store the base64 str so we don't need to re-encode in getter */
     sev_snp_guest->id_block = g_strdup(value);
 
     finish->id_block_uaddr =
-        (uint64_t)qbase64_decode(sev_snp_guest->id_block, -1, &len, errp);
+        (uintptr_t)qbase64_decode(sev_snp_guest->id_block, -1, &len, errp);
 
     if (!finish->id_block_uaddr) {
         return;
@@ -2208,13 +2208,13 @@ sev_snp_guest_set_id_auth(Object *obj, const char *value, Error **errp)
     gsize len;
 
     g_free(sev_snp_guest->id_auth);
-    g_free((guchar *)finish->id_auth_uaddr);
+    g_free((void *)(uintptr_t)finish->id_auth_uaddr);
 
     /* store the base64 str so we don't need to re-encode in getter */
     sev_snp_guest->id_auth = g_strdup(value);
 
     finish->id_auth_uaddr =
-        (uint64_t)qbase64_decode(sev_snp_guest->id_auth, -1, &len, errp);
+        (uintptr_t)qbase64_decode(sev_snp_guest->id_auth, -1, &len, errp);
 
     if (!finish->id_auth_uaddr) {
         return;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] target/i386/sev: Use size_t for object sizes
  2024-06-26 19:49 [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Richard Henderson
  2024-06-26 19:49 ` [PATCH 1/3] target/i386/sev: Cast id_auth_uaddr through uintptr_t Richard Henderson
@ 2024-06-26 19:49 ` Richard Henderson
  2024-06-26 19:49 ` [PATCH 3/3] target/i386/sev: Fix printf formats Richard Henderson
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2024-06-26 19:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, alex.bennee, berrange, philmd

This code was using both uint32_t and uint64_t for len.
Consistently use size_t instead.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/i386/sev.c        | 16 ++++++++--------
 target/i386/trace-events |  2 +-
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/target/i386/sev.c b/target/i386/sev.c
index 9dfdac69ab..f96301f81f 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -121,7 +121,7 @@ struct SevCommonStateClass {
                                        Error **errp);
     int (*launch_start)(SevCommonState *sev_common);
     void (*launch_finish)(SevCommonState *sev_common);
-    int (*launch_update_data)(SevCommonState *sev_common, hwaddr gpa, uint8_t *ptr, uint64_t len);
+    int (*launch_update_data)(SevCommonState *sev_common, hwaddr gpa, uint8_t *ptr, size_t len);
     int (*kvm_init)(ConfidentialGuestSupport *cgs, Error **errp);
 };
 
@@ -171,7 +171,7 @@ typedef struct SevLaunchUpdateData {
     QTAILQ_ENTRY(SevLaunchUpdateData) next;
     hwaddr gpa;
     void *hva;
-    uint64_t len;
+    size_t len;
     int type;
 } SevLaunchUpdateData;
 
@@ -884,7 +884,7 @@ sev_snp_launch_update(SevSnpGuestState *sev_snp_guest,
 
     if (!data->hva || !data->len) {
         error_report("SNP_LAUNCH_UPDATE called with invalid address"
-                     "/ length: %p / %lx",
+                     "/ length: %p / %zx",
                      data->hva, data->len);
         return 1;
     }
@@ -943,7 +943,8 @@ out:
 }
 
 static int
-sev_launch_update_data(SevCommonState *sev_common, hwaddr gpa, uint8_t *addr, uint64_t len)
+sev_launch_update_data(SevCommonState *sev_common, hwaddr gpa,
+                       uint8_t *addr, size_t len)
 {
     int ret, fw_error;
     struct kvm_sev_launch_update_data update;
@@ -1088,8 +1089,7 @@ sev_launch_finish(SevCommonState *sev_common)
 }
 
 static int
-snp_launch_update_data(uint64_t gpa, void *hva,
-                       uint32_t len, int type)
+snp_launch_update_data(uint64_t gpa, void *hva, size_t len, int type)
 {
     SevLaunchUpdateData *data;
 
@@ -1106,7 +1106,7 @@ snp_launch_update_data(uint64_t gpa, void *hva,
 
 static int
 sev_snp_launch_update_data(SevCommonState *sev_common, hwaddr gpa,
-                           uint8_t *ptr, uint64_t len)
+                           uint8_t *ptr, size_t len)
 {
        int ret = snp_launch_update_data(gpa, ptr, len,
                                          KVM_SEV_SNP_PAGE_TYPE_NORMAL);
@@ -1163,7 +1163,7 @@ sev_snp_cpuid_info_fill(SnpCpuidInfo *snp_cpuid_info,
 }
 
 static int
-snp_launch_update_cpuid(uint32_t cpuid_addr, void *hva, uint32_t cpuid_len)
+snp_launch_update_cpuid(uint32_t cpuid_addr, void *hva, size_t cpuid_len)
 {
     KvmCpuidInfo kvm_cpuid_info = {0};
     SnpCpuidInfo snp_cpuid_info;
diff --git a/target/i386/trace-events b/target/i386/trace-events
index 06b44ead2e..51301673f0 100644
--- a/target/i386/trace-events
+++ b/target/i386/trace-events
@@ -6,7 +6,7 @@ kvm_memcrypt_register_region(void *addr, size_t len) "addr %p len 0x%zx"
 kvm_memcrypt_unregister_region(void *addr, size_t len) "addr %p len 0x%zx"
 kvm_sev_change_state(const char *old, const char *new) "%s -> %s"
 kvm_sev_launch_start(int policy, void *session, void *pdh) "policy 0x%x session %p pdh %p"
-kvm_sev_launch_update_data(void *addr, uint64_t len) "addr %p len 0x%" PRIx64
+kvm_sev_launch_update_data(void *addr, size_t len) "addr %p len 0x%zx"
 kvm_sev_launch_measurement(const char *value) "data %s"
 kvm_sev_launch_finish(void) ""
 kvm_sev_launch_secret(uint64_t hpa, uint64_t hva, uint64_t secret, int len) "hpa 0x%" PRIx64 " hva 0x%" PRIx64 " data 0x%" PRIx64 " len %d"
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] target/i386/sev: Fix printf formats
  2024-06-26 19:49 [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Richard Henderson
  2024-06-26 19:49 ` [PATCH 1/3] target/i386/sev: Cast id_auth_uaddr through uintptr_t Richard Henderson
  2024-06-26 19:49 ` [PATCH 2/3] target/i386/sev: Use size_t for object sizes Richard Henderson
@ 2024-06-26 19:49 ` Richard Henderson
  2024-06-27  6:17 ` [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Philippe Mathieu-Daudé
  2024-06-27 14:58 ` Paolo Bonzini
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2024-06-26 19:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, alex.bennee, berrange, philmd

hwaddr uses HWADDR_PRIx, sizeof yields size_t so uses %zu,
and gsize uses G_GSIZE_FORMAT.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/i386/sev.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/target/i386/sev.c b/target/i386/sev.c
index f96301f81f..74ed9948ca 100644
--- a/target/i386/sev.c
+++ b/target/i386/sev.c
@@ -932,8 +932,9 @@ sev_snp_launch_update(SevSnpGuestState *sev_snp_guest,
 
 out:
     if (!ret && update.gfn_start << TARGET_PAGE_BITS != data->gpa + data->len) {
-        error_report("SEV-SNP: expected update of GPA range %lx-%lx,"
-                     "got GPA range %lx-%llx",
+        error_report("SEV-SNP: expected update of GPA range %"
+                     HWADDR_PRIx "-%" HWADDR_PRIx ","
+                     "got GPA range %" HWADDR_PRIx "-%llx",
                      data->gpa, data->gpa + data->len, data->gpa,
                      update.gfn_start << TARGET_PAGE_BITS);
         ret = -EIO;
@@ -2146,7 +2147,8 @@ sev_snp_guest_set_guest_visible_workarounds(Object *obj, const char *value,
     }
 
     if (len != sizeof(start->gosvw)) {
-        error_setg(errp, "parameter length of %lu exceeds max of %lu",
+        error_setg(errp, "parameter length of %" G_GSIZE_FORMAT
+                   " exceeds max of %zu",
                    len, sizeof(start->gosvw));
         return;
     }
@@ -2184,7 +2186,8 @@ sev_snp_guest_set_id_block(Object *obj, const char *value, Error **errp)
     }
 
     if (len != KVM_SEV_SNP_ID_BLOCK_SIZE) {
-        error_setg(errp, "parameter length of %lu not equal to %u",
+        error_setg(errp, "parameter length of %" G_GSIZE_FORMAT
+                   " not equal to %u",
                    len, KVM_SEV_SNP_ID_BLOCK_SIZE);
         return;
     }
@@ -2221,7 +2224,8 @@ sev_snp_guest_set_id_auth(Object *obj, const char *value, Error **errp)
     }
 
     if (len > KVM_SEV_SNP_ID_AUTH_SIZE) {
-        error_setg(errp, "parameter length:ID_AUTH %lu exceeds max of %u",
+        error_setg(errp, "parameter length:ID_AUTH %" G_GSIZE_FORMAT
+                   " exceeds max of %u",
                    len, KVM_SEV_SNP_ID_AUTH_SIZE);
         return;
     }
@@ -2287,7 +2291,8 @@ sev_snp_guest_set_host_data(Object *obj, const char *value, Error **errp)
     }
 
     if (len != sizeof(finish->host_data)) {
-        error_setg(errp, "parameter length of %lu not equal to %lu",
+        error_setg(errp, "parameter length of %" G_GSIZE_FORMAT
+                   " not equal to %zu",
                    len, sizeof(finish->host_data));
         return;
     }
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues
  2024-06-26 19:49 [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Richard Henderson
                   ` (2 preceding siblings ...)
  2024-06-26 19:49 ` [PATCH 3/3] target/i386/sev: Fix printf formats Richard Henderson
@ 2024-06-27  6:17 ` Philippe Mathieu-Daudé
  2024-06-27 14:58 ` Paolo Bonzini
  4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-06-27  6:17 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: pbonzini, alex.bennee, berrange

On 26/6/24 21:49, Richard Henderson wrote:

> Richard Henderson (3):
>    target/i386/sev: Cast id_auth_uaddr through uintptr_t
>    target/i386/sev: Use size_t for object sizes
>    target/i386/sev: Fix printf formats

Series:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues
  2024-06-26 19:49 [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Richard Henderson
                   ` (3 preceding siblings ...)
  2024-06-27  6:17 ` [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Philippe Mathieu-Daudé
@ 2024-06-27 14:58 ` Paolo Bonzini
  4 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2024-06-27 14:58 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel, alex.bennee, berrange, philmd

On Wed, Jun 26, 2024 at 9:49 PM Richard Henderson
<richard.henderson@linaro.org> wrote:
> I separated the fixes into 3 smaller patches
> that may be easier to review.

Oops, I missed this. I queued patches 2-3, while for the first one I
prefer the version I sent at

https://lore.kernel.org/qemu-devel/20240627145357.1038664-1-pbonzini@redhat.com/

(patches 1-4)

Paolo

> r~
>
> Richard Henderson (3):
>   target/i386/sev: Cast id_auth_uaddr through uintptr_t
>   target/i386/sev: Use size_t for object sizes
>   target/i386/sev: Fix printf formats
>
>  target/i386/sev.c        | 41 ++++++++++++++++++++++------------------
>  target/i386/trace-events |  2 +-
>  2 files changed, 24 insertions(+), 19 deletions(-)
>
> --
> 2.34.1
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-27 14:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-26 19:49 [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Richard Henderson
2024-06-26 19:49 ` [PATCH 1/3] target/i386/sev: Cast id_auth_uaddr through uintptr_t Richard Henderson
2024-06-26 19:49 ` [PATCH 2/3] target/i386/sev: Use size_t for object sizes Richard Henderson
2024-06-26 19:49 ` [PATCH 3/3] target/i386/sev: Fix printf formats Richard Henderson
2024-06-27  6:17 ` [PATCH 0/3] target/i386/sev: Fix 32-bit host build issues Philippe Mathieu-Daudé
2024-06-27 14:58 ` Paolo Bonzini

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).