linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH rdma-core 0/4] pyverbs fixes
@ 2019-07-10 14:22 Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 1/4] pyverbs: Fix Cython future warning during build Noa Osherovich
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Noa Osherovich @ 2019-07-10 14:22 UTC (permalink / raw)
  To: dledford, jgg, leonro; +Cc: linux-rdma, Noa Osherovich

The following is a series of fixes to pyverbs:
The first two patches clean the compilation warning introduces in
Fedora 30.
The third patch fixes a wrong casting.
The last one fixes the handling of bad work requests in post send and
post recv operations.

Maxim Chicherin (1):
  pyverbs: Avoid casting pointers to object type

Noa Osherovich (3):
  pyverbs: Fix Cython future warning during build
  build: Remove warning-causing compilation flag from pyverbs
  pyverbs: Fix assignments of bad work requests

 CMakeLists.txt                   |  7 +++++
 buildlib/pyverbs_functions.cmake |  7 ++++-
 pyverbs/addr.pxd                 |  2 ++
 pyverbs/base.pxd                 |  2 ++
 pyverbs/cq.pxd                   |  3 ++
 pyverbs/cq.pyx                   | 23 ++------------
 pyverbs/device.pxd               |  2 ++
 pyverbs/libibverbs_enums.pxd     |  3 ++
 pyverbs/mr.pxd                   |  2 ++
 pyverbs/pd.pxd                   |  3 ++
 pyverbs/pd.pyx                   |  4 ---
 pyverbs/qp.pxd                   |  3 ++
 pyverbs/qp.pyx                   | 54 ++++++++++++++++++--------------
 pyverbs/wr.pxd                   |  2 ++
 pyverbs/wr.pyx                   | 17 +++-------
 15 files changed, 73 insertions(+), 61 deletions(-)

-- 
2.21.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH rdma-core 1/4] pyverbs: Fix Cython future warning during build
  2019-07-10 14:22 [PATCH rdma-core 0/4] pyverbs fixes Noa Osherovich
@ 2019-07-10 14:22 ` Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 2/4] build: Remove warning-causing compilation flag from pyverbs Noa Osherovich
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Noa Osherovich @ 2019-07-10 14:22 UTC (permalink / raw)
  To: dledford, jgg, leonro; +Cc: linux-rdma, Noa Osherovich, Maor Gottlieb

Since Cython 0.29, a language_level directive is required in pxd
files. This currently appears as a FutureWarning e.g.:
FutureWarning: Cython directive 'language_level' not set, using 2 for
now (Py2). This will change in a later release!

This patch updates pyverbs' pxd files with this directive.

Signed-off-by: Noa Osherovich <noaos@mellanox.com>
Reviewd-by: Maor Gottlieb <maorg@mellanox.com>
---
 pyverbs/addr.pxd             | 2 ++
 pyverbs/base.pxd             | 2 ++
 pyverbs/cq.pxd               | 3 +++
 pyverbs/device.pxd           | 2 ++
 pyverbs/libibverbs_enums.pxd | 3 +++
 pyverbs/mr.pxd               | 2 ++
 pyverbs/pd.pxd               | 3 +++
 pyverbs/qp.pxd               | 3 +++
 pyverbs/wr.pxd               | 2 ++
 9 files changed, 22 insertions(+)

diff --git a/pyverbs/addr.pxd b/pyverbs/addr.pxd
index 389c2d5bdb2e..e7322e8d7fdd 100644
--- a/pyverbs/addr.pxd
+++ b/pyverbs/addr.pxd
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2018, Mellanox Technologies. All rights reserved. See COPYING file
 
+#cython: language_level=3
+
 from .base cimport PyverbsObject, PyverbsCM
 from pyverbs cimport libibverbs as v
 
diff --git a/pyverbs/base.pxd b/pyverbs/base.pxd
index fa661edb5315..e85f7c020e1c 100644
--- a/pyverbs/base.pxd
+++ b/pyverbs/base.pxd
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2019, Mellanox Technologies. All rights reserved.
 
+#cython: language_level=3
+
 cdef class PyverbsObject(object):
     cdef object __weakref__
     cdef object logger
diff --git a/pyverbs/cq.pxd b/pyverbs/cq.pxd
index 0e3bcdfffb7e..9b8df5dcae39 100644
--- a/pyverbs/cq.pxd
+++ b/pyverbs/cq.pxd
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2019, Mellanox Technologies. All rights reserved.
+
+#cython: language_level=3
+
 from pyverbs.base cimport PyverbsObject, PyverbsCM
 cimport pyverbs.libibverbs as v
 
diff --git a/pyverbs/device.pxd b/pyverbs/device.pxd
index 3cb52bde4603..44c8bc3cbcbc 100644
--- a/pyverbs/device.pxd
+++ b/pyverbs/device.pxd
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2018, Mellanox Technologies. All rights reserved. See COPYING file
 
+#cython: language_level=3
+
 from .base cimport PyverbsObject, PyverbsCM
 cimport pyverbs.libibverbs as v
 
diff --git a/pyverbs/libibverbs_enums.pxd b/pyverbs/libibverbs_enums.pxd
index 85b5092c486f..c347ef31dd2b 100644
--- a/pyverbs/libibverbs_enums.pxd
+++ b/pyverbs/libibverbs_enums.pxd
@@ -1,6 +1,9 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2018, Mellanox Technologies. All rights reserved.
 
+#cython: language_level=3
+
+
 cdef extern from '<infiniband/verbs.h>':
 
     cpdef enum ibv_transport_type:
diff --git a/pyverbs/mr.pxd b/pyverbs/mr.pxd
index 2d76f2dfbe7c..fb46611e6f42 100644
--- a/pyverbs/mr.pxd
+++ b/pyverbs/mr.pxd
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2019, Mellanox Technologies. All rights reserved. See COPYING file
 
+#cython: language_level=3
+
 from pyverbs.base cimport PyverbsCM
 from . cimport libibverbs as v
 
diff --git a/pyverbs/pd.pxd b/pyverbs/pd.pxd
index 07c9158b27eb..e0861b301b7c 100644
--- a/pyverbs/pd.pxd
+++ b/pyverbs/pd.pxd
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2019, Mellanox Technologies. All rights reserved.
+
+#cython: language_level=3
+
 from pyverbs.device cimport Context
 cimport pyverbs.libibverbs as v
 from .base cimport PyverbsCM
diff --git a/pyverbs/qp.pxd b/pyverbs/qp.pxd
index d85bc28992ad..29b9ec4a0221 100644
--- a/pyverbs/qp.pxd
+++ b/pyverbs/qp.pxd
@@ -1,5 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved.
+
+#cython: language_level=3
+
 from pyverbs.base cimport PyverbsObject, PyverbsCM
 cimport pyverbs.libibverbs as v
 
diff --git a/pyverbs/wr.pxd b/pyverbs/wr.pxd
index 64b16091116a..e259249ef7f8 100644
--- a/pyverbs/wr.pxd
+++ b/pyverbs/wr.pxd
@@ -1,6 +1,8 @@
 # SPDX-License-Identifier: (GPL-2.0 OR Linux-OpenIB)
 # Copyright (c) 2019 Mellanox Technologies, Inc. All rights reserved. See COPYING file
 
+#cython: language_level=3
+
 from .base cimport PyverbsCM
 from pyverbs cimport libibverbs as v
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH rdma-core 2/4] build: Remove warning-causing compilation flag from pyverbs
  2019-07-10 14:22 [PATCH rdma-core 0/4] pyverbs fixes Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 1/4] pyverbs: Fix Cython future warning during build Noa Osherovich
@ 2019-07-10 14:22 ` Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 3/4] pyverbs: Avoid casting pointers to object type Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 4/4] pyverbs: Fix assignments of bad work requests Noa Osherovich
  3 siblings, 0 replies; 5+ messages in thread
From: Noa Osherovich @ 2019-07-10 14:22 UTC (permalink / raw)
  To: dledford, jgg, leonro; +Cc: linux-rdma, Noa Osherovich

The -fvar-tracking-assignment flag is causing the following
compilation warning:

note: variable tracking size limit exceeded with '-fvar-tracking-assignments', retrying without

Since it's a debug flag and not necessary for pyverbs functionality,
remove it from pyverbs' build.

Signed-off-by: Noa Osherovich <noaos@mellanox.com>
Reviewd-by: Leon Romanovsky <leonro@mellanox.com>
---
 CMakeLists.txt                   | 7 +++++++
 buildlib/pyverbs_functions.cmake | 7 ++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d2e357c78af..f2cb5c306c04 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -182,6 +182,13 @@ endif()
 
 #-------------------------
 # Setup the basic C compiler
+# Some compilation flags are not supported in clang, lets allow users to know
+# whether gcc or clang is used.
+if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+  set(IS_CLANG_BUILD TRUE)
+else()
+  set(IS_CLANG_BUILD FALSE)
+endif()
 RDMA_BuildType()
 include_directories(${BUILD_INCLUDE})
 
diff --git a/buildlib/pyverbs_functions.cmake b/buildlib/pyverbs_functions.cmake
index 1966cf3ba1a3..81cdd86fc020 100644
--- a/buildlib/pyverbs_functions.cmake
+++ b/buildlib/pyverbs_functions.cmake
@@ -16,8 +16,13 @@ function(rdma_cython_module PY_MODULE)
 
     string(REGEX REPLACE "\\.so$" "" SONAME "${FILENAME}${CMAKE_PYTHON_SO_SUFFIX}")
     add_library(${SONAME} SHARED ${CFILE})
+    # We need to disable -fvar-tracking-assignments. It's only supported in gcc
+    # so make sure we're not using clang before doing that.
+    if (NOT ${IS_CLANG_BUILD})
+      set(PYVERBS_DEBUG_FLAGS "-fno-var-tracking-assignments")
+    endif()
     set_target_properties(${SONAME} PROPERTIES
-	    COMPILE_FLAGS "${CMAKE_C_FLAGS} -fPIC -fno-strict-aliasing -Wno-unused-function -Wno-redundant-decls -Wno-shadow -Wno-cast-function-type -Wno-implicit-fallthrough -Wno-unknown-warning -Wno-unknown-warning-option"
+        COMPILE_FLAGS "${CMAKE_C_FLAGS} -fPIC -fno-strict-aliasing -Wno-unused-function -Wno-redundant-decls -Wno-shadow -Wno-cast-function-type -Wno-implicit-fallthrough -Wno-unknown-warning -Wno-unknown-warning-option ${PYVERBS_DEBUG_FLAGS}"
       LIBRARY_OUTPUT_DIRECTORY "${BUILD_PYTHON}/${PY_MODULE}"
       PREFIX "")
     target_link_libraries(${SONAME} LINK_PRIVATE ${PYTHON_LIBRARIES} ibverbs)
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH rdma-core 3/4] pyverbs: Avoid casting pointers to object type
  2019-07-10 14:22 [PATCH rdma-core 0/4] pyverbs fixes Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 1/4] pyverbs: Fix Cython future warning during build Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 2/4] build: Remove warning-causing compilation flag from pyverbs Noa Osherovich
@ 2019-07-10 14:22 ` Noa Osherovich
  2019-07-10 14:22 ` [PATCH rdma-core 4/4] pyverbs: Fix assignments of bad work requests Noa Osherovich
  3 siblings, 0 replies; 5+ messages in thread
From: Noa Osherovich @ 2019-07-10 14:22 UTC (permalink / raw)
  To: dledford, jgg, leonro; +Cc: linux-rdma, Maxim Chicherin, Maor Gottlieb

From: Maxim Chicherin <maximc@mellanox.com>

When casting a C pointer into <object> type python assumes that the
head of the struct is the reference count. The reference count is
incremented every time another variable points to this object.
The result is that the first member of the C struct, which is wrapped
by python object, is incremented. E.g. PD holds ibv_pd pointer, so the
first field of ibv_pd which is ibv_context address is incremented by
1, meaning ibv_context pointer holds invalid address.

Signed-off-by: Maxim Chicherin <maximc@mellanox.com>
Reviewd-by: Maor Gottlieb <maorg@mellanox.com>
---
 pyverbs/cq.pyx | 23 +++--------------------
 pyverbs/pd.pyx |  4 ----
 pyverbs/qp.pyx | 39 +++++++++++++++++++--------------------
 pyverbs/wr.pyx | 17 +++++------------
 4 files changed, 27 insertions(+), 56 deletions(-)

diff --git a/pyverbs/cq.pyx b/pyverbs/cq.pyx
index dd475759337c..dc09924e88a9 100644
--- a/pyverbs/cq.pyx
+++ b/pyverbs/cq.pyx
@@ -59,10 +59,6 @@ cdef class CompChannel(PyverbsCM):
         if isinstance(obj, CQ) or isinstance(obj, CQEX):
             self.cqs.add(obj)
 
-    @property
-    def channel(self):
-        return <object>self.cc
-
 
 cdef class CQ(PyverbsCM):
     """
@@ -84,8 +80,7 @@ cdef class CQ(PyverbsCM):
         """
         if channel is not None:
             self.cq = v.ibv_create_cq(context.context, cqe, <void*>cq_context,
-                                      <v.ibv_comp_channel*>channel.channel,
-                                      comp_vector)
+                                      channel.cc, comp_vector)
             channel.add_ref(self)
         else:
             self.cq = v.ibv_create_cq(context.context, cqe, <void*>cq_context,
@@ -162,10 +157,6 @@ cdef class CQ(PyverbsCM):
         """
         v.ibv_ack_cq_events(self.cq, num_events)
 
-    @property
-    def _cq(self):
-        return <object>self.cq
-
     def __str__(self):
         print_format = '{:22}: {:<20}\n'
         return 'CQ\n' +\
@@ -215,9 +206,9 @@ cdef class CqInitAttrEx(PyverbsObject):
     def comp_channel(self):
         return self.channel
     @comp_channel.setter
-    def comp_channel(self, val):
+    def comp_channel(self, CompChannel val):
         self.channel = val
-        self.attr.channel = <v.ibv_comp_channel*>val
+        self.attr.channel = val.cc
 
     @property
     def comp_vector(self):
@@ -364,14 +355,6 @@ cdef class CQEX(PyverbsCM):
     def wr_id(self, val):
         self.cq.wr_id = val
 
-    @property
-    def _cq(self):
-        return <object>self.cq
-
-    @property
-    def _ibv_cq(self):
-        return <object>self.ibv_cq
-
     def __str__(self):
         print_format = '{:<22}: {:<20}\n'
         return 'Extended CQ:\n' +\
diff --git a/pyverbs/pd.pyx b/pyverbs/pd.pyx
index 4b5dc139c59f..7cd0876682b2 100644
--- a/pyverbs/pd.pyx
+++ b/pyverbs/pd.pyx
@@ -67,7 +67,3 @@ cdef class PD(PyverbsCM):
             self.qps.add(obj)
         else:
             raise PyverbsError('Unrecognized object type')
-
-    @property
-    def _pd(self):
-        return <object>self.pd
diff --git a/pyverbs/qp.pyx b/pyverbs/qp.pyx
index b33993a106e9..47a2158a5acc 100644
--- a/pyverbs/qp.pyx
+++ b/pyverbs/qp.pyx
@@ -101,9 +101,9 @@ cdef class QPInitAttr(PyverbsObject):
         self.attr.qp_context = <void*>qp_context
         if scq is not None:
             if type(scq) is CQ:
-                self.attr.send_cq = <v.ibv_cq*>scq._cq
+                self.attr.send_cq = (<CQ>rcq).cq
             elif type(scq) is CQEX:
-                self.attr.send_cq = <v.ibv_cq*>scq._ibv_cq
+                self.attr.send_cq = (<CQEX>rcq).ibv_cq
             else:
                 raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
                                        format(t=type(scq)))
@@ -111,9 +111,9 @@ cdef class QPInitAttr(PyverbsObject):
 
         if rcq is not None:
             if type(rcq) is CQ:
-                self.attr.recv_cq = <v.ibv_cq*>rcq._cq
+                self.attr.recv_cq = (<CQ>rcq).cq
             elif type(rcq) is CQEX:
-                self.attr.recv_cq = <v.ibv_cq*>rcq._ibv_cq
+                self.attr.recv_cq = (<CQEX>rcq).ibv_cq
             else:
                 raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
                                        format(t=type(rcq)))
@@ -129,9 +129,9 @@ cdef class QPInitAttr(PyverbsObject):
     @send_cq.setter
     def send_cq(self, val):
         if type(val) is CQ:
-            self.attr.send_cq = <v.ibv_cq*>val._cq
+            self.attr.send_cq = (<CQ>val).cq
         elif type(val) is CQEX:
-            self.attr.send_cq = <v.ibv_cq*>val._ibv_cq
+            self.attr.send_cq = (<CQEX>val).ibv_cq
         self.scq = val
 
     @property
@@ -140,9 +140,9 @@ cdef class QPInitAttr(PyverbsObject):
     @recv_cq.setter
     def recv_cq(self, val):
         if type(val) is CQ:
-            self.attr.recv_cq = <v.ibv_cq*>val._cq
+            self.attr.recv_cq = (<CQ>val).cq
         elif type(val) is CQEX:
-            self.attr.recv_cq = <v.ibv_cq*>val._ibv_cq
+            self.attr.recv_cq = (<CQEX>val).ibv_cq
         self.rcq = val
 
     @property
@@ -218,9 +218,9 @@ cdef class QPInitAttrEx(PyverbsObject):
         _copy_caps(cap, self)
         if scq is not None:
             if type(scq) is CQ:
-                self.attr.send_cq = <v.ibv_cq*>scq._cq
+                self.attr.send_cq = (<CQ>rcq).cq
             elif type(scq) is CQEX:
-                self.attr.send_cq = <v.ibv_cq*>scq._ibv_cq
+                self.attr.send_cq = (<CQEX>rcq).ibv_cq
             else:
                 raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
                                        format(t=type(scq)))
@@ -228,12 +228,12 @@ cdef class QPInitAttrEx(PyverbsObject):
 
         if rcq is not None:
             if type(rcq) is CQ:
-                self.attr.recv_cq = <v.ibv_cq*>rcq._cq
+                self.attr.recv_cq = (<CQ>rcq).cq
             elif type(rcq) is CQEX:
-                self.attr.recv_cq = <v.ibv_cq*>rcq._ibv_cq
+                self.attr.recv_cq = (<CQEX>rcq).ibv_cq
             else:
                 raise PyverbsUserError('Expected CQ/CQEX, got {t}'.\
-                                       format(type(rcq)))
+                                       format(t=type(rcq)))
         self.rcq = rcq
 
         self.attr.srq = NULL  # Until SRQ support is added
@@ -247,7 +247,6 @@ cdef class QPInitAttrEx(PyverbsObject):
             raise PyverbsUserError('XRCD and RSS are not yet supported in pyverbs')
         self.attr.comp_mask = comp_mask
         if pd is not None:
-            self.attr.pd = <v.ibv_pd*>pd._pd
             self.pd = pd
         self.attr.create_flags = create_flags
         self.attr.max_tso_header = max_tso_header
@@ -259,9 +258,9 @@ cdef class QPInitAttrEx(PyverbsObject):
     @send_cq.setter
     def send_cq(self, val):
         if type(val) is CQ:
-            self.attr.send_cq = <v.ibv_cq*>val._cq
+            self.attr.send_cq = (<CQ>val).cq
         elif type(val) is CQEX:
-            self.attr.send_cq = <v.ibv_cq*>val._ibv_cq
+            self.attr.send_cq = (<CQEX>val).ibv_cq
         self.scq = val
 
     @property
@@ -270,9 +269,9 @@ cdef class QPInitAttrEx(PyverbsObject):
     @recv_cq.setter
     def recv_cq(self, val):
         if type(val) is CQ:
-            self.attr.recv_cq = <v.ibv_cq*>val._cq
+            self.attr.recv_cq = (<CQ>val).cq
         elif type(val) is CQEX:
-            self.attr.recv_cq = <v.ibv_cq*>val._ibv_cq
+            self.attr.recv_cq = (<CQEX>val).ibv_cq
         self.rcq = val
 
     @property
@@ -311,8 +310,8 @@ cdef class QPInitAttrEx(PyverbsObject):
     def pd(self):
         return self.pd
     @pd.setter
-    def pd(self, val):
-        self.attr.pd = <v.ibv_pd*>val._pd
+    def pd(self, PD val):
+        self.attr.pd = <v.ibv_pd*>val.pd
         self.pd = val
 
     @property
diff --git a/pyverbs/wr.pyx b/pyverbs/wr.pyx
index 2dc766282db3..3003224a8f32 100644
--- a/pyverbs/wr.pyx
+++ b/pyverbs/wr.pyx
@@ -53,10 +53,7 @@ cdef class SGE(PyverbsCM):
         cdef char *sg_data
         cdef int off = offset
         sg_data = <char*>(self.sge.addr + off)
-        return <object>sg_data[:length]
-
-    def _get_sge(self):
-        return <object>self.sge
+        return sg_data[:length]
 
     def __str__(self):
         print_format = '{:22}: {:<20}\n'
@@ -104,7 +101,7 @@ cdef class RecvWR(PyverbsCM):
         if self.recv_wr.sg_list == NULL:
             raise PyverbsRDMAErrno('Failed to malloc SG buffer')
         dst = self.recv_wr.sg_list
-        copy_sg_array(<object>dst, sg, num_sge)
+        copy_sg_array(dst, sg, num_sge)
         self.recv_wr.num_sge = num_sge
         self.recv_wr.wr_id = wr_id
         if next_wr is not None:
@@ -166,7 +163,7 @@ cdef class SendWR(PyverbsCM):
         if self.send_wr.sg_list == NULL:
             raise PyverbsRDMAErrno('Failed to malloc SG buffer')
         dst = self.send_wr.sg_list
-        copy_sg_array(<object>dst, sg, num_sge)
+        copy_sg_array(dst, sg, num_sge)
         self.send_wr.num_sge = num_sge
         self.send_wr.wr_id = wr_id
         if next_wr is not None:
@@ -298,13 +295,9 @@ def send_flags_to_str(flags):
     return flags_str
 
 
-cdef copy_sg_array(dst_obj, sg, num_sge):
-    cdef v.ibv_sge *dst = <v.ibv_sge*>dst_obj
+cdef copy_sg_array(v.ibv_sge *dst, sg, num_sge):
     cdef v.ibv_sge *src
     for i in range(num_sge):
-        # Avoid 'storing unsafe C derivative of temporary Python' errors
-        # that will occur if we merge the two following lines.
-        tmp = sg[i]._get_sge()
-        src = <v.ibv_sge*>tmp
+        src = (<SGE>sg[i]).sge
         memcpy(dst, src, sizeof(v.ibv_sge))
         dst += 1
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH rdma-core 4/4] pyverbs: Fix assignments of bad work requests
  2019-07-10 14:22 [PATCH rdma-core 0/4] pyverbs fixes Noa Osherovich
                   ` (2 preceding siblings ...)
  2019-07-10 14:22 ` [PATCH rdma-core 3/4] pyverbs: Avoid casting pointers to object type Noa Osherovich
@ 2019-07-10 14:22 ` Noa Osherovich
  3 siblings, 0 replies; 5+ messages in thread
From: Noa Osherovich @ 2019-07-10 14:22 UTC (permalink / raw)
  To: dledford, jgg, leonro; +Cc: linux-rdma, Noa Osherovich, Maor Gottlieb

The bad work request content wasn't properly copied from the C
object, fix copying to contain the bad work request data.

Signed-off-by: Noa Osherovich <noaos@mellanox.com>
Reviewd-by: Maor Gottlieb <maorg@mellanox.com>
---
 pyverbs/qp.pyx | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/pyverbs/qp.pyx b/pyverbs/qp.pyx
index 47a2158a5acc..ad89c94c002e 100644
--- a/pyverbs/qp.pyx
+++ b/pyverbs/qp.pyx
@@ -14,6 +14,9 @@ cimport pyverbs.libibverbs as v
 from pyverbs.pd cimport PD
 
 
+cdef extern from 'string.h':
+    void *memcpy(void *dest, const void *src, size_t n);
+
 cdef class QPCap(PyverbsObject):
     def __cinit__(self, max_send_wr=1, max_recv_wr=10, max_send_sge=1,
                       max_recv_sge=1, max_inline_data=0):
@@ -963,10 +966,12 @@ cdef class QP(PyverbsCM):
         :return: None
         """
         cdef v.ibv_recv_wr *my_bad_wr
+        # In order to provide a pointer to a pointer, use a temporary cdef'ed
+        # variable.
         rc = v.ibv_post_recv(self.qp, &wr.recv_wr, &my_bad_wr)
         if rc != 0:
-            if bad_wr is not None:
-                bad_wr.wr = <object>my_bad_wr
+            if (bad_wr):
+                memcpy(&bad_wr.recv_wr, my_bad_wr, sizeof(bad_wr.recv_wr))
             raise PyverbsRDMAErrno('Failed to post recv (returned {rc})'.
                                    format(rc=rc))
 
@@ -978,11 +983,13 @@ cdef class QP(PyverbsCM):
                        case of a failure
         :return: None
         """
+        # In order to provide a pointer to a pointer, use a temporary cdef'ed
+        # variable.
         cdef v.ibv_send_wr *my_bad_wr
         rc = v.ibv_post_send(self.qp, &wr.send_wr, &my_bad_wr)
         if rc != 0:
-            if bad_wr is not None:
-                bad_wr.wr = <object>my_bad_wr
+            if (bad_wr):
+                memcpy(&bad_wr.send_wr, my_bad_wr, sizeof(bad_wr.send_wr))
             raise PyverbsRDMAErrno('Failed to post send (returned {rc})'.
                                    format(rc=rc))
 
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-10 14:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-10 14:22 [PATCH rdma-core 0/4] pyverbs fixes Noa Osherovich
2019-07-10 14:22 ` [PATCH rdma-core 1/4] pyverbs: Fix Cython future warning during build Noa Osherovich
2019-07-10 14:22 ` [PATCH rdma-core 2/4] build: Remove warning-causing compilation flag from pyverbs Noa Osherovich
2019-07-10 14:22 ` [PATCH rdma-core 3/4] pyverbs: Avoid casting pointers to object type Noa Osherovich
2019-07-10 14:22 ` [PATCH rdma-core 4/4] pyverbs: Fix assignments of bad work requests Noa Osherovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).