From patchwork Wed Jul 10 14:22:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 11038667 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7FE71805 for ; Wed, 10 Jul 2019 14:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DADC9288AF for ; Wed, 10 Jul 2019 14:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEA7F288C5; Wed, 10 Jul 2019 14:31:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16F22288CF for ; Wed, 10 Jul 2019 14:31:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726617AbfGJOb6 (ORCPT ); Wed, 10 Jul 2019 10:31:58 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:47974 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727190AbfGJOb5 (ORCPT ); Wed, 10 Jul 2019 10:31:57 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Jul 2019 17:31:51 +0300 Received: from reg-l-vrt-059-007.mtl.labs.mlnx (reg-l-vrt-059-007.mtl.labs.mlnx [10.135.59.7]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6AEVpIj004077; Wed, 10 Jul 2019 17:31:51 +0300 From: Noa Osherovich To: dledford@redhat.com, jgg@mellanox.com, leonro@mellanox.com Cc: linux-rdma@vger.kernel.org, Noa Osherovich , Maor Gottlieb Subject: [PATCH rdma-core 1/4] pyverbs: Fix Cython future warning during build Date: Wed, 10 Jul 2019 17:22:48 +0300 Message-Id: <20190710142251.9396-2-noaos@mellanox.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190710142251.9396-1-noaos@mellanox.com> References: <20190710142251.9396-1-noaos@mellanox.com> MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewd-by: Maor Gottlieb --- 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 '': 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 From patchwork Wed Jul 10 14:22:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 11038663 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D856912 for ; Wed, 10 Jul 2019 14:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70746288AF for ; Wed, 10 Jul 2019 14:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61CF6288F6; Wed, 10 Jul 2019 14:31:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EC23288AF for ; Wed, 10 Jul 2019 14:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727263AbfGJOb5 (ORCPT ); Wed, 10 Jul 2019 10:31:57 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:47976 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727154AbfGJOb5 (ORCPT ); Wed, 10 Jul 2019 10:31:57 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Jul 2019 17:31:51 +0300 Received: from reg-l-vrt-059-007.mtl.labs.mlnx (reg-l-vrt-059-007.mtl.labs.mlnx [10.135.59.7]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6AEVpIk004077; Wed, 10 Jul 2019 17:31:51 +0300 From: Noa Osherovich To: dledford@redhat.com, jgg@mellanox.com, leonro@mellanox.com Cc: linux-rdma@vger.kernel.org, Noa Osherovich Subject: [PATCH rdma-core 2/4] build: Remove warning-causing compilation flag from pyverbs Date: Wed, 10 Jul 2019 17:22:49 +0300 Message-Id: <20190710142251.9396-3-noaos@mellanox.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190710142251.9396-1-noaos@mellanox.com> References: <20190710142251.9396-1-noaos@mellanox.com> MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewd-by: Leon Romanovsky --- 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) From patchwork Wed Jul 10 14:22:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 11038671 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 747DC6C5 for ; Wed, 10 Jul 2019 14:32:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65541288AF for ; Wed, 10 Jul 2019 14:32:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59BA9288B8; Wed, 10 Jul 2019 14:32:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93908288CF for ; Wed, 10 Jul 2019 14:32:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727190AbfGJOb7 (ORCPT ); Wed, 10 Jul 2019 10:31:59 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:47977 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726098AbfGJOb7 (ORCPT ); Wed, 10 Jul 2019 10:31:59 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Jul 2019 17:31:51 +0300 Received: from reg-l-vrt-059-007.mtl.labs.mlnx (reg-l-vrt-059-007.mtl.labs.mlnx [10.135.59.7]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6AEVpIl004077; Wed, 10 Jul 2019 17:31:51 +0300 From: Noa Osherovich To: dledford@redhat.com, jgg@mellanox.com, leonro@mellanox.com Cc: linux-rdma@vger.kernel.org, Maxim Chicherin , Maor Gottlieb Subject: [PATCH rdma-core 3/4] pyverbs: Avoid casting pointers to object type Date: Wed, 10 Jul 2019 17:22:50 +0300 Message-Id: <20190710142251.9396-4-noaos@mellanox.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190710142251.9396-1-noaos@mellanox.com> References: <20190710142251.9396-1-noaos@mellanox.com> MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Maxim Chicherin When casting a C pointer into 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 Reviewd-by: Maor Gottlieb --- 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 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, cq_context, - channel.channel, - comp_vector) + channel.cc, comp_vector) channel.add_ref(self) else: self.cq = v.ibv_create_cq(context.context, cqe, cq_context, @@ -162,10 +157,6 @@ cdef class CQ(PyverbsCM): """ v.ibv_ack_cq_events(self.cq, num_events) - @property - def _cq(self): - return 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 = 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 self.cq - - @property - def _ibv_cq(self): - return 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 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 = qp_context if scq is not None: if type(scq) is CQ: - self.attr.send_cq = scq._cq + self.attr.send_cq = (rcq).cq elif type(scq) is CQEX: - self.attr.send_cq = scq._ibv_cq + self.attr.send_cq = (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 = rcq._cq + self.attr.recv_cq = (rcq).cq elif type(rcq) is CQEX: - self.attr.recv_cq = rcq._ibv_cq + self.attr.recv_cq = (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 = val._cq + self.attr.send_cq = (val).cq elif type(val) is CQEX: - self.attr.send_cq = val._ibv_cq + self.attr.send_cq = (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 = val._cq + self.attr.recv_cq = (val).cq elif type(val) is CQEX: - self.attr.recv_cq = val._ibv_cq + self.attr.recv_cq = (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 = scq._cq + self.attr.send_cq = (rcq).cq elif type(scq) is CQEX: - self.attr.send_cq = scq._ibv_cq + self.attr.send_cq = (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 = rcq._cq + self.attr.recv_cq = (rcq).cq elif type(rcq) is CQEX: - self.attr.recv_cq = rcq._ibv_cq + self.attr.recv_cq = (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 = 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 = val._cq + self.attr.send_cq = (val).cq elif type(val) is CQEX: - self.attr.send_cq = val._ibv_cq + self.attr.send_cq = (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 = val._cq + self.attr.recv_cq = (val).cq elif type(val) is CQEX: - self.attr.recv_cq = val._ibv_cq + self.attr.recv_cq = (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 = val._pd + def pd(self, PD val): + self.attr.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 = (self.sge.addr + off) - return sg_data[:length] - - def _get_sge(self): - return 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(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(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 = 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 = tmp + src = (sg[i]).sge memcpy(dst, src, sizeof(v.ibv_sge)) dst += 1 From patchwork Wed Jul 10 14:22:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noa Osherovich X-Patchwork-Id: 11038669 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92A086C5 for ; Wed, 10 Jul 2019 14:32:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82E2E288AF for ; Wed, 10 Jul 2019 14:32:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77055288C5; Wed, 10 Jul 2019 14:32:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 580EA288B8 for ; Wed, 10 Jul 2019 14:31:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727154AbfGJOb5 (ORCPT ); Wed, 10 Jul 2019 10:31:57 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:47975 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725911AbfGJOb5 (ORCPT ); Wed, 10 Jul 2019 10:31:57 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from noaos@mellanox.com) with ESMTPS (AES256-SHA encrypted); 10 Jul 2019 17:31:51 +0300 Received: from reg-l-vrt-059-007.mtl.labs.mlnx (reg-l-vrt-059-007.mtl.labs.mlnx [10.135.59.7]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id x6AEVpIm004077; Wed, 10 Jul 2019 17:31:51 +0300 From: Noa Osherovich To: dledford@redhat.com, jgg@mellanox.com, leonro@mellanox.com Cc: linux-rdma@vger.kernel.org, Noa Osherovich , Maor Gottlieb Subject: [PATCH rdma-core 4/4] pyverbs: Fix assignments of bad work requests Date: Wed, 10 Jul 2019 17:22:51 +0300 Message-Id: <20190710142251.9396-5-noaos@mellanox.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190710142251.9396-1-noaos@mellanox.com> References: <20190710142251.9396-1-noaos@mellanox.com> MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewd-by: Maor Gottlieb --- 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 = 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 = 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))