On-demand paging support was added in libibverbs v1.2.0 in
commit https://github.com/linux-rdma/rdma-core/commit/e500adc7b1

We don't check the libibverbs, so add a meson check on the
IBV_ACCESS_ON_DEMAND symbol, and define HAVE_IBV_ACCESS_ON_DEMAND
if found. Restrict rdma_support_odp() so it returns %false when
on-demand paging is not supported.

This fixes:

  migration/rdma.c: In function 'rdma_support_odp':
  migration/rdma.c:1133:12: error: variable 'attr' has initializer but 
incomplete type
   1133 |     struct ibv_device_attr_ex attr = {0};
        |            ^~~~~~~~~~~~~~~~~~
  migration/rdma.c:1135:9: warning: implicit declaration of function 
'ibv_query_device_ex'; did you mean 'ibv_query_device'? 
[-Wimplicit-function-declaration]
   1135 |     if (ibv_query_device_ex(dev, NULL, &attr)) {
        |         ^~~~~~~~~~~~~~~~~~~
        |         ibv_query_device
  migration/rdma.c:1135:9: warning: nested extern declaration of 
'ibv_query_device_ex' [-Wnested-externs]
  migration/rdma.c:1139:38: error: 'IBV_ODP_SUPPORT' undeclared (first use in 
this function); did you mean 'IBV_QP_PORT'?
   1139 |     if (attr.odp_caps.general_caps & IBV_ODP_SUPPORT) {
        |                                      ^~~~~~~~~~~~~~~
        |                                      IBV_QP_PORT
  migration/rdma.c: In function 'qemu_rdma_reg_whole_ram_blocks':
  migration/rdma.c:1189:27: error: 'IBV_ACCESS_ON_DEMAND' undeclared (first use 
in this function); did you mean 'IBV_ACCESS_MW_BIND'?
   1189 |                 access |= IBV_ACCESS_ON_DEMAND;
        |                           ^~~~~~~~~~~~~~~~~~~~
        |                           IBV_ACCESS_MW_BIND
  ninja: build stopped: subcommand failed.

Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
 meson.build      | 3 +++
 migration/rdma.c | 6 ++++++
 2 files changed, 9 insertions(+)

diff --git a/meson.build b/meson.build
index 837a2bdb56..7c6436ac9e 100644
--- a/meson.build
+++ b/meson.build
@@ -2410,6 +2410,9 @@ if rdma.found()
                        cc.has_function('ibv_advise_mr',
                                        dependencies: rdma,
                                        prefix: '#include 
<infiniband/verbs.h>'))
+  config_host_data.set('HAVE_IBV_ACCESS_ON_DEMAND',
+                       cc.has_header_symbol('infiniband/verbs.h',
+                                            'IBV_ACCESS_ON_DEMAND'))
 endif
 
 have_asan_fiber = false
diff --git a/migration/rdma.c b/migration/rdma.c
index 855753c671..4717fb3143 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -1127,9 +1127,14 @@ static int qemu_rdma_alloc_qp(RDMAContext *rdma)
     return 0;
 }
 
+#ifndef HAVE_IBV_ACCESS_ON_DEMAND
+#define IBV_ACCESS_ON_DEMAND 0
+#endif
+
 /* Check whether On-Demand Paging is supported by RDAM device */
 static bool rdma_support_odp(struct ibv_context *dev)
 {
+#ifdef HAVE_IBV_ACCESS_ON_DEMAND
     struct ibv_device_attr_ex attr = {0};
 
     if (ibv_query_device_ex(dev, NULL, &attr)) {
@@ -1139,6 +1144,7 @@ static bool rdma_support_odp(struct ibv_context *dev)
     if (attr.odp_caps.general_caps & IBV_ODP_SUPPORT) {
         return true;
     }
+#endif
 
     return false;
 }
-- 
2.41.0


Reply via email to