[openib-general] registering read-only memory
Michael S. Tsirkin
mst at mellanox.co.il
Thu May 19 01:52:08 PDT 2005
Roland, the following code snippet:
const char foo[]="Michael Tsirkin";
ibv_reg_mr(ctx->pd, foo, strlen(foo), 0);
exposes two problems with ibv_reg_mr:
1. Compiling this code I get a warning:
warning: passing arg 2 of `ibv_reg_mr' discards qualifiers
from pointer target type.
Same if foo is declared volatile.
I suggest changing ibv_reg_mr to accept const volatile void *
as a second parameter.
const is OK since ibv_reg_mr never actually writes to the buffer.
volatile is needed by some applications to prevent the compiler from
assuming it can re-order accesses to this buffer.
Patch attached (below).
2. ibv_reg_mr fails.
Why is that?
System details:
>gcc --version
gcc (GCC) 3.3.3 (SuSE Linux)
>uname -a
Linux swlab156 2.6.11-openib #29 SMP Mon Apr 18 16:17:51 IDT 2005
x86_64 x86_64 x86_64 GNU/Linux
Make ibv_reg_mr accept buffer as volatile const *.
Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>
Index: libibverbs/include/infiniband/verbs.h
===================================================================
--- libibverbs/include/infiniband/verbs.h (revision 2408)
+++ libibverbs/include/infiniband/verbs.h (working copy)
@@ -499,7 +499,7 @@ extern int ibv_dealloc_pd(struct ibv_pd
/**
* ibv_reg_mr - Register a memory region
*/
-extern struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, void *addr,
+extern struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, volatile const void *addr,
size_t length, enum ibv_access_flags access);
/**
Index: libibverbs/src/verbs.c
===================================================================
--- libibverbs/src/verbs.c (revision 2408)
+++ libibverbs/src/verbs.c (working copy)
@@ -64,7 +64,7 @@ int ibv_dealloc_pd(struct ibv_pd *pd)
return pd->context->ops.dealloc_pd(pd);
}
-struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, void *addr,
+struct ibv_mr *ibv_reg_mr(struct ibv_pd *pd, volatile const void *addr,
size_t length, enum ibv_access_flags access)
{
struct ibv_mr *mr;
Index: libmthca/src/mthca.h
===================================================================
--- libmthca/src/mthca.h (revision 2408)
+++ libmthca/src/mthca.h (working copy)
@@ -260,7 +260,7 @@ extern int mthca_query_port(struct ibv_c
extern struct ibv_pd *mthca_alloc_pd(struct ibv_context *context);
extern int mthca_free_pd(struct ibv_pd *pd);
-extern struct ibv_mr *mthca_reg_mr(struct ibv_pd *pd, void *addr,
+extern struct ibv_mr *mthca_reg_mr(struct ibv_pd *pd, volatile const void *addr,
size_t length, enum ibv_access_flags access);
extern int mthca_dereg_mr(struct ibv_mr *mr);
Index: libmthca/src/verbs.c
===================================================================
--- libmthca/src/verbs.c (revision 2408)
+++ libmthca/src/verbs.c (working copy)
@@ -93,7 +93,8 @@ int mthca_free_pd(struct ibv_pd *pd)
return 0;
}
-static struct ibv_mr *__mthca_reg_mr(struct ibv_pd *pd, void *addr,
+static struct ibv_mr *__mthca_reg_mr(struct ibv_pd *pd,
+ volatile const void *addr,
size_t length, uint64_t hca_va,
enum ibv_access_flags access)
{
@@ -113,7 +114,7 @@ static struct ibv_mr *__mthca_reg_mr(str
return mr;
}
-struct ibv_mr *mthca_reg_mr(struct ibv_pd *pd, void *addr,
+struct ibv_mr *mthca_reg_mr(struct ibv_pd *pd, volatile const void *addr,
size_t length, enum ibv_access_flags access)
{
return __mthca_reg_mr(pd, addr, length, (uintptr_t) addr, access);
--
MST - Michael S. Tsirkin
More information about the general
mailing list