Skip to contentSkip to conversation

multifd: Be consistente about using uint64_t

PATCH In review Juan Quintela 3 participants 3 messages Jan 17, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 multifd: Be consistente about using uint64_t

We transmit ram_addr_t always as uint64_t. Be consistent in its use (on 64bit system, it is always uint64_t problem is 32bits).

---
 migration/ram.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
migration/ram.c +8 -5
index 96feb4062c..f7482b1b35 100644
@@ -803,7 +803,10 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
     }
 
     for (i = 0; i < p->pages->used; i++) {
-        packet->offset[i] = cpu_to_be64(p->pages->offset[i]);
+        /* there are architectures where ram_addr_t is 32 bit */
+        uint64_t temp = p->pages->offset[i];
+
+        packet->offset[i] = cpu_to_be64(temp);
     }
 }
 
@@ -877,10 +880,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
     }
 
     for (i = 0; i < p->pages->used; i++) {
-        ram_addr_t offset = be64_to_cpu(packet->offset[i]);
+        uint64_t offset = be64_to_cpu(packet->offset[i]);
 
         if (offset > (block->used_length - TARGET_PAGE_SIZE)) {
-            error_setg(errp, "multifd: offset too long " RAM_ADDR_FMT
+            error_setg(errp, "multifd: offset too long %" PRId64
                        " (max " RAM_ADDR_FMT ")",
                        offset, block->max_length);
             return -1;
@@ -1236,7 +1239,7 @@ int multifd_save_setup(void)
         p->id = i;
         p->pages = multifd_pages_init(page_count);
         p->packet_len = sizeof(MultiFDPacket_t)
-                      + sizeof(ram_addr_t) * page_count;
+                      + sizeof(uint64_t) * page_count;
         p->packet = g_malloc0(p->packet_len);
         p->packet->magic = cpu_to_be32(MULTIFD_MAGIC);
         p->packet->version = cpu_to_be32(MULTIFD_VERSION);
@@ -1447,7 +1450,7 @@ int multifd_load_setup(void)
         p->id = i;
         p->pages = multifd_pages_init(page_count);
         p->packet_len = sizeof(MultiFDPacket_t)
-                      + sizeof(ram_addr_t) * page_count;
+                      + sizeof(uint64_t) * page_count;
         p->packet = g_malloc0(p->packet_len);
         p->name = g_strdup_printf("multifdrecv_%d", i);
     }
Signature · 1 line
2.24.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Juan Quintela

We transmit ram_addr_t always as uint64_t. Be consistent in its use (on 64bit system, it is always uint64_t problem is 32bits).

---
  migration/ram.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
migration/ram.c +0 -0
index 96feb4062c..f7482b1b35 100644

migration/ram.c static void multifd_send_fill_packet(MultiFDSendParams *p) · line 807

Quoted 6 lines
migration/ram.c +2 -1
@@ -803,7 +803,10 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
      }
 
      for (i = 0; i < p->pages->used; i++) {
-        packet->offset[i] = cpu_to_be64(p->pages->offset[i]);
+        /* there are architectures where ram_addr_t is 32 bit */
+        uint64_t temp = p->pages->offset[i];

Using a temp variable is clearer than a cast, good.

Quoted 6 lines
migration/ram.c +2 -0
+
+        packet->offset[i] = cpu_to_be64(temp);
      }
  }
 

migration/ram.c static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp) · line 886

Quoted 9 lines
migration/ram.c +2 -2
@@ -877,10 +880,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
      }
 
      for (i = 0; i < p->pages->used; i++) {
-        ram_addr_t offset = be64_to_cpu(packet->offset[i]);
+        uint64_t offset = be64_to_cpu(packet->offset[i]);
 
          if (offset > (block->used_length - TARGET_PAGE_SIZE)) {
-            error_setg(errp, "multifd: offset too long " RAM_ADDR_FMT
+            error_setg(errp, "multifd: offset too long %" PRId64

Nitpick: PRIu64 for uint64_t.

Using PRIu64:

Quoted 22 lines
migration/ram.c +2 -2
                         " (max " RAM_ADDR_FMT ")",
                         offset, block->max_length);
              return -1;
@@ -1236,7 +1239,7 @@ int multifd_save_setup(void)
          p->id = i;
          p->pages = multifd_pages_init(page_count);
          p->packet_len = sizeof(MultiFDPacket_t)
-                      + sizeof(ram_addr_t) * page_count;
+                      + sizeof(uint64_t) * page_count;
          p->packet = g_malloc0(p->packet_len);
          p->packet->magic = cpu_to_be32(MULTIFD_MAGIC);
          p->packet->version = cpu_to_be32(MULTIFD_VERSION);
@@ -1447,7 +1450,7 @@ int multifd_load_setup(void)
          p->id = i;
          p->pages = multifd_pages_init(page_count);
          p->packet_len = sizeof(MultiFDPacket_t)
-                      + sizeof(ram_addr_t) * page_count;
+                      + sizeof(uint64_t) * page_count;
          p->packet = g_malloc0(p->packet_len);
          p->name = g_strdup_printf("multifdrecv_%d", i);
      }
Reviewed-by on v1 1/1
#2 lore raw
In reply to Juan Quintela
Quoted 4 lines · * Juan Quintela ([email protected]) wrote:

We transmit ram_addr_t always as uint64_t. Be consistent in its use (on 64bit system, it is always uint64_t problem is 32bits).

(Note typo in subject )

Quoted 54 lines
---
 migration/ram.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
migration/ram.c +8 -5
index 96feb4062c..f7482b1b35 100644
@@ -803,7 +803,10 @@ static void multifd_send_fill_packet(MultiFDSendParams *p)
     }
 
     for (i = 0; i < p->pages->used; i++) {
-        packet->offset[i] = cpu_to_be64(p->pages->offset[i]);
+        /* there are architectures where ram_addr_t is 32 bit */
+        uint64_t temp = p->pages->offset[i];
+
+        packet->offset[i] = cpu_to_be64(temp);
     }
 }
 
@@ -877,10 +880,10 @@ static int multifd_recv_unfill_packet(MultiFDRecvParams *p, Error **errp)
     }
 
     for (i = 0; i < p->pages->used; i++) {
-        ram_addr_t offset = be64_to_cpu(packet->offset[i]);
+        uint64_t offset = be64_to_cpu(packet->offset[i]);
 
         if (offset > (block->used_length - TARGET_PAGE_SIZE)) {
-            error_setg(errp, "multifd: offset too long " RAM_ADDR_FMT
+            error_setg(errp, "multifd: offset too long %" PRId64
                        " (max " RAM_ADDR_FMT ")",
                        offset, block->max_length);
             return -1;
@@ -1236,7 +1239,7 @@ int multifd_save_setup(void)
         p->id = i;
         p->pages = multifd_pages_init(page_count);
         p->packet_len = sizeof(MultiFDPacket_t)
-                      + sizeof(ram_addr_t) * page_count;
+                      + sizeof(uint64_t) * page_count;
         p->packet = g_malloc0(p->packet_len);
         p->packet->magic = cpu_to_be32(MULTIFD_MAGIC);
         p->packet->version = cpu_to_be32(MULTIFD_VERSION);
@@ -1447,7 +1450,7 @@ int multifd_load_setup(void)
         p->id = i;
         p->pages = multifd_pages_init(page_count);
         p->packet_len = sizeof(MultiFDPacket_t)
-                      + sizeof(ram_addr_t) * page_count;
+                      + sizeof(uint64_t) * page_count;
         p->packet = g_malloc0(p->packet_len);
         p->name = g_strdup_printf("multifdrecv_%d", i);
     }
Signature · 1 line
2.24.1

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK