From patchwork Thu Aug 2 16:13:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10553945 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 1E1FF13BB for ; Thu, 2 Aug 2018 16:14:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EFC82C2CA for ; Thu, 2 Aug 2018 16:14:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03AA82C311; Thu, 2 Aug 2018 16:14:43 +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 72C462C2F4 for ; Thu, 2 Aug 2018 16:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726745AbeHBSGb (ORCPT ); Thu, 2 Aug 2018 14:06:31 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48801 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726673AbeHBSGa (ORCPT ); Thu, 2 Aug 2018 14:06:30 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 2 Aug 2018 19:17:59 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [10.7.2.17]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w72GEYxB029962; Thu, 2 Aug 2018 19:14:34 +0300 Received: from vnc17.mtl.labs.mlnx (vnc17.mtl.labs.mlnx [127.0.0.1]) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8) with ESMTP id w72GEYSM019409; Thu, 2 Aug 2018 19:14:34 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w72GEYxI019408; Thu, 2 Aug 2018 19:14:34 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, jgg@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core 5/6] mlx4: Move to use verbs_allow_disassociate_destroy Date: Thu, 2 Aug 2018 19:13:35 +0300 Message-Id: <1533226416-19122-6-git-send-email-yishaih@mellanox.com> X-Mailer: git-send-email 1.8.2.3 In-Reply-To: <1533226416-19122-1-git-send-email-yishaih@mellanox.com> References: <1533226416-19122-1-git-send-email-yishaih@mellanox.com> 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 Cleanup the private handling of mlx4 and move to use the generic verbs support for verbs_allow_disassociate_destroy. For backwards compatible support once MLX4_DEVICE_FATAL_CLEANUP is set turn to use the verbs mechanism as well. Signed-off-by: Yishai Hadas --- libibverbs/init.c | 6 ++++++ providers/mlx4/mlx4.c | 12 ------------ providers/mlx4/mlx4.h | 6 ------ providers/mlx4/srq.c | 2 +- providers/mlx4/verbs.c | 22 +++++++++++----------- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/libibverbs/init.c b/libibverbs/init.c index 853515d..a4c5f9e 100644 --- a/libibverbs/init.c +++ b/libibverbs/init.c @@ -699,6 +699,7 @@ out: int ibverbs_init(void) { const char *sysfs_path; + char *env_value; int ret; if (getenv("RDMAV_FORK_SAFE") || getenv("IBV_FORK_SAFE")) @@ -706,6 +707,11 @@ int ibverbs_init(void) fprintf(stderr, PFX "Warning: fork()-safety requested " "but init failed\n"); + /* Backward compatibility for the mlx4 driver env */ + env_value = getenv("MLX4_DEVICE_FATAL_CLEANUP"); + if (env_value) + verbs_allow_disassociate_destroy = strcmp(env_value, "0") != 0; + if (getenv("RDMAV_ALLOW_DISASSOC_DESTROY")) verbs_allow_disassociate_destroy = true; diff --git a/providers/mlx4/mlx4.c b/providers/mlx4/mlx4.c index 43e730f..1e418dc 100644 --- a/providers/mlx4/mlx4.c +++ b/providers/mlx4/mlx4.c @@ -43,8 +43,6 @@ #include "mlx4.h" #include "mlx4-abi.h" -int mlx4_cleanup_upon_device_fatal = 0; - #ifndef PCI_VENDOR_ID_MELLANOX #define PCI_VENDOR_ID_MELLANOX 0x15b3 #endif @@ -133,15 +131,6 @@ static const struct verbs_context_ops mlx4_ctx_ops = { .query_rt_values = mlx4_query_rt_values, }; -static void mlx4_read_env(void) -{ - char *env_value; - - env_value = getenv("MLX4_DEVICE_FATAL_CLEANUP"); - if (env_value) - mlx4_cleanup_upon_device_fatal = (strcmp(env_value, "0")) ? 1 : 0; -} - static int mlx4_map_internal_clock(struct mlx4_device *mdev, struct ibv_context *ibv_ctx) { @@ -184,7 +173,6 @@ static struct verbs_context *mlx4_alloc_context(struct ibv_device *ibdev, verbs_ctx = &context->ibv_ctx; - mlx4_read_env(); if (dev->abi_version <= MLX4_UVERBS_NO_DEV_CAPS_ABI_VERSION) { if (ibv_cmd_get_context(verbs_ctx, &cmd, sizeof(cmd), &resp_v3.ibv_resp, sizeof(resp_v3))) diff --git a/providers/mlx4/mlx4.h b/providers/mlx4/mlx4.h index a174d09..191ccb4 100644 --- a/providers/mlx4/mlx4.h +++ b/providers/mlx4/mlx4.h @@ -299,12 +299,6 @@ static inline void mlx4_update_cons_index(struct mlx4_cq *cq) *cq->set_ci_db = htobe32(cq->cons_index & 0xffffff); } -extern int mlx4_cleanup_upon_device_fatal; -static inline int cleanup_on_fatal(int ret) -{ - return (ret == EIO && mlx4_cleanup_upon_device_fatal); -} - int mlx4_alloc_buf(struct mlx4_buf *buf, size_t size, int page_size); void mlx4_free_buf(struct mlx4_buf *buf); diff --git a/providers/mlx4/srq.c b/providers/mlx4/srq.c index 00d9a70..3b44548 100644 --- a/providers/mlx4/srq.c +++ b/providers/mlx4/srq.c @@ -307,7 +307,7 @@ int mlx4_destroy_xrc_srq(struct ibv_srq *srq) pthread_spin_unlock(&mcq->lock); ret = ibv_cmd_destroy_srq(srq); - if (ret && !cleanup_on_fatal(ret)) { + if (ret) { pthread_spin_lock(&mcq->lock); mlx4_store_xsrq(&mctx->xsrq_table, msrq->verbs_srq.srq_num, msrq); pthread_spin_unlock(&mcq->lock); diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c index 40e94c4..5b32bd5 100644 --- a/providers/mlx4/verbs.c +++ b/providers/mlx4/verbs.c @@ -232,7 +232,7 @@ int mlx4_free_pd(struct ibv_pd *pd) int ret; ret = ibv_cmd_dealloc_pd(pd); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; free(to_mpd(pd)); @@ -269,7 +269,7 @@ int mlx4_close_xrcd(struct ibv_xrcd *ib_xrcd) int ret; ret = ibv_cmd_close_xrcd(xrcd); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; free(xrcd); @@ -322,7 +322,7 @@ int mlx4_dereg_mr(struct verbs_mr *vmr) int ret; ret = ibv_cmd_dereg_mr(vmr); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; free(vmr); @@ -356,7 +356,7 @@ int mlx4_dealloc_mw(struct ibv_mw *mw) int ret; ret = ibv_cmd_dealloc_mw(mw); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; free(mw); @@ -647,7 +647,7 @@ int mlx4_destroy_cq(struct ibv_cq *cq) int ret; ret = ibv_cmd_destroy_cq(cq); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; mlx4_free_db(to_mctx(cq->context), MLX4_DB_TYPE_CQ, to_mcq(cq)->set_ci_db); @@ -751,7 +751,7 @@ int mlx4_destroy_srq(struct ibv_srq *srq) return mlx4_destroy_xrc_srq(srq); ret = ibv_cmd_destroy_srq(srq); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; mlx4_free_db(to_mctx(srq->context), MLX4_DB_TYPE_RQ, to_msrq(srq)->db); @@ -1220,7 +1220,7 @@ static int _mlx4_destroy_qp_rss(struct ibv_qp *ibqp) int ret; ret = ibv_cmd_destroy_qp(ibqp); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; free(qp); @@ -1238,7 +1238,7 @@ int mlx4_destroy_qp(struct ibv_qp *ibqp) pthread_mutex_lock(&to_mctx(ibqp->context)->qp_table_mutex); ret = ibv_cmd_destroy_qp(ibqp); - if (ret && !cleanup_on_fatal(ret)) { + if (ret) { pthread_mutex_unlock(&to_mctx(ibqp->context)->qp_table_mutex); return ret; } @@ -1567,7 +1567,7 @@ int mlx4_destroy_flow(struct ibv_flow *flow_id) ret = ibv_cmd_destroy_flow(flow_id); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; free(flow_id); @@ -1584,7 +1584,7 @@ int mlx4_destroy_wq(struct ibv_wq *ibwq) pthread_mutex_lock(&mcontext->qp_table_mutex); ret = ibv_cmd_destroy_wq(ibwq); - if (ret && !cleanup_on_fatal(ret)) { + if (ret) { pthread_mutex_unlock(&mcontext->qp_table_mutex); return ret; } @@ -1658,7 +1658,7 @@ int mlx4_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table) ret = ibv_cmd_destroy_rwq_ind_table(rwq_ind_table); - if (ret && !cleanup_on_fatal(ret)) + if (ret) return ret; free(rwq_ind_table);