Skip to contentSkip to conversation

migration/rdma: clang compilation fix

PATCH In review Marcel Apfelbaum 3 participants 4 messages Mar 4, 2019 – Mar 5, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 migration/rdma: clang compilation fix

Configuring QEMU with:

        ../configure --cc=clang --enable-rdma

Leads to compilation error:

CC migration/rdma.o
CC migration/block.o
qemu/migration/rdma.c:3615:58: error: taking address of packed member 'rkey' of class or structure

      'RDMARegisterResult' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
                                                         ^~~~~~~~~~~~~~~~

Fix it by using a temp local variable.

---

v1 -> v2:
- Use a temp local variable (Dave)

 migration/rdma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/rdma.c +4 -1
index 54a3c11540..e39ee77558 100644
@@ -3611,13 +3611,16 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque)
                 }
                 chunk_start = ram_chunk_start(block, chunk);
                 chunk_end = ram_chunk_end(block, chunk + reg->chunks);
+                /* avoid "-Waddress-of-packed-member" warning */
+                uint32_t tmp_rkey = 0;
                 if (qemu_rdma_register_and_get_keys(rdma, block,
-                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
+                            (uintptr_t)host_addr, NULL, &tmp_rkey,
                             chunk, chunk_start, chunk_end)) {
                     error_report("cannot get rkey");
                     ret = -EINVAL;
                     goto out;
                 }
+                reg_result->rkey = tmp_rkey;
 
                 reg_result->host_addr = (uintptr_t)block->local_host_addr;
 
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · * Marcel Apfelbaum ([email protected]) wrote:

Configuring QEMU with:

        ../configure --cc=clang --enable-rdma

Leads to compilation error:

CC migration/rdma.o
CC migration/block.o
qemu/migration/rdma.c:3615:58: error: taking address of packed member 'rkey' of class or structure

Quoted 6 lines
      'RDMARegisterResult' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
                                                         ^~~~~~~~~~~~~~~~

Fix it by using a temp local variable.

Quoted 33 lines

---

v1 -> v2:
- Use a temp local variable (Dave)

 migration/rdma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/rdma.c +4 -1
index 54a3c11540..e39ee77558 100644
@@ -3611,13 +3611,16 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque)
                 }
                 chunk_start = ram_chunk_start(block, chunk);
                 chunk_end = ram_chunk_end(block, chunk + reg->chunks);
+                /* avoid "-Waddress-of-packed-member" warning */
+                uint32_t tmp_rkey = 0;
                 if (qemu_rdma_register_and_get_keys(rdma, block,
-                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
+                            (uintptr_t)host_addr, NULL, &tmp_rkey,
                             chunk, chunk_start, chunk_end)) {
                     error_report("cannot get rkey");
                     ret = -EINVAL;
                     goto out;
                 }
+                reg_result->rkey = tmp_rkey;
 
                 reg_result->host_addr = (uintptr_t)block->local_host_addr;
 
Signature · 1 line
2.17.1

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

Reviewed-by on v2 1/1
#2 lore raw
In reply to Marcel Apfelbaum
Quoted 11 lines · Marcel Apfelbaum

Configuring QEMU with:

        ../configure --cc=clang --enable-rdma

Leads to compilation error:

CC migration/rdma.o
CC migration/block.o
qemu/migration/rdma.c:3615:58: error: taking address of packed member 'rkey' of class or structure

      'RDMARegisterResult' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
                                                         ^~~~~~~~~~~~~~~~
Quoted 7 lines

Fix it by using a temp local variable.

---

v1 -> v2:
- Use a temp local variable (Dave)

Way cleaner than your v1 :)

migration/rdma.c static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) · line 3614

Quoted 13 lines
 migration/rdma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/rdma.c +1 -0
index 54a3c11540..e39ee77558 100644
@@ -3611,13 +3611,16 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque)
                 }
                 chunk_start = ram_chunk_start(block, chunk);
                 chunk_end = ram_chunk_end(block, chunk + reg->chunks);
+                /* avoid "-Waddress-of-packed-member" warning */

No sure the comment is helpful.

migration/rdma.c static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque) · line 3615

Quoted 1 line
migration/rdma.c +1 -0
+                uint32_t tmp_rkey = 0;

Probably no need to zero-initialize.

Anyway:

Quoted 13 lines
migration/rdma.c +2 -1
                 if (qemu_rdma_register_and_get_keys(rdma, block,
-                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
+                            (uintptr_t)host_addr, NULL, &tmp_rkey,
                             chunk, chunk_start, chunk_end)) {
                     error_report("cannot get rkey");
                     ret = -EINVAL;
                     goto out;
                 }
+                reg_result->rkey = tmp_rkey;
 
                 reg_result->host_addr = (uintptr_t)block->local_host_addr;
 
#3 lore raw
In reply to Marcel Apfelbaum
Quoted 8 lines · * Marcel Apfelbaum ([email protected]) wrote:

Configuring QEMU with:

        ../configure --cc=clang --enable-rdma

Leads to compilation error:

CC migration/rdma.o
CC migration/block.o
qemu/migration/rdma.c:3615:58: error: taking address of packed member 'rkey' of class or structure

Quoted 6 lines
      'RDMARegisterResult' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member]
                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
                                                         ^~~~~~~~~~~~~~~~

Fix it by using a temp local variable.

Queued

Quoted 34 lines

---

v1 -> v2:
- Use a temp local variable (Dave)

 migration/rdma.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
migration/rdma.c +4 -1
index 54a3c11540..e39ee77558 100644
@@ -3611,13 +3611,16 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque)
                 }
                 chunk_start = ram_chunk_start(block, chunk);
                 chunk_end = ram_chunk_end(block, chunk + reg->chunks);
+                /* avoid "-Waddress-of-packed-member" warning */
+                uint32_t tmp_rkey = 0;
                 if (qemu_rdma_register_and_get_keys(rdma, block,
-                            (uintptr_t)host_addr, NULL, &reg_result->rkey,
+                            (uintptr_t)host_addr, NULL, &tmp_rkey,
                             chunk, chunk_start, chunk_end)) {
                     error_report("cannot get rkey");
                     ret = -EINVAL;
                     goto out;
                 }
+                reg_result->rkey = tmp_rkey;
 
                 reg_result->host_addr = (uintptr_t)block->local_host_addr;
 
Signature · 1 line
2.17.1

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