Skip to contentSkip to conversation

migration: Don't use *_to_cpup()

PATCH Superseded Peter Maydell 2 participants 3 messages Jun 10, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 migration: Don't use *_to_cpup()

The *_to_cpup() functions just compose a pointer dereference with a *_to_cpu() byteswap. Instead use ld*_p(), which handles potential pointer misaligment and avoids the need to cast the pointer.

---
The motivation here is that I'd like to get rid of _to_cpup()
entirely: we don't have many places that use it.

---
 migration/migration.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
migration/migration.c +6 -6
index 7ecbade..551da0a 100644
@@ -1381,7 +1381,7 @@ static void *source_return_path_thread(void *opaque)
         /* OK, we have the message and the data */
         switch (header_type) {
         case MIG_RP_MSG_SHUT:
-            sibling_error = be32_to_cpup((uint32_t *)buf);
+            sibling_error = ldl_be_p(buf);
             trace_source_return_path_thread_shut(sibling_error);
             if (sibling_error) {
                 error_report("RP: Sibling indicated error %d", sibling_error);
@@ -1395,13 +1395,13 @@ static void *source_return_path_thread(void *opaque)
             goto out;
 
         case MIG_RP_MSG_PONG:
-            tmp32 = be32_to_cpup((uint32_t *)buf);
+            tmp32 = ldl_be_p(buf);
             trace_source_return_path_thread_pong(tmp32);
             break;
 
         case MIG_RP_MSG_REQ_PAGES:
-            start = be64_to_cpup((uint64_t *)buf);
-            len = be32_to_cpup((uint32_t *)(buf + 8));
+            start = ldq_be_p(buf);
+            len = ldl_be_p(buf + 8);
             migrate_handle_rp_req_pages(ms, NULL, start, len);
             break;
 
@@ -1409,8 +1409,8 @@ static void *source_return_path_thread(void *opaque)
             expected_len = 12 + 1; /* header + termination */
 
             if (header_len >= expected_len) {
-                start = be64_to_cpup((uint64_t *)buf);
-                len = be32_to_cpup((uint32_t *)(buf + 8));
+                start = ldq_be_p(buf);
+                len = ldl_be_p(buf + 8);
                 /* Now we expect an idstr */
                 tmp32 = buf[12]; /* Length of the following idstr */
                 buf[13 + tmp32] = '\0';
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Peter Maydell

The *_to_cpup() functions just compose a pointer dereference with a *_to_cpu() byteswap. Instead use ld*_p(), which handles potential pointer misaligment and avoids the need to cast the pointer.

s/misaligment/misalignment/

Quoted 9 lines

---
The motivation here is that I'd like to get rid of _to_cpup()
entirely: we don't have many places that use it.

---
 migration/migration.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 17 lines · Eric Blake
Quoted 3 lines · Peter Maydell

The *_to_cpup() functions just compose a pointer dereference with a *_to_cpu() byteswap. Instead use ld*_p(), which handles potential pointer misaligment and avoids the need to cast the pointer.

s/misaligment/misalignment/

Quoted 9 lines

---
The motivation here is that I'd like to get rid of _to_cpup()
entirely: we don't have many places that use it.

---
 migration/migration.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
Quoted 1 line

Thanks. I just noticed that I missed the use of cpu_to_be64w() for loads, so I'll send a v2.

-- PMM