From patchwork Thu Aug 2 16:13:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10553937 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 CEFF113BB for ; Thu, 2 Aug 2018 16:14:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BE2D62C2F4 for ; Thu, 2 Aug 2018 16:14:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0E7B2C308; Thu, 2 Aug 2018 16:14:37 +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 29C122C2CA for ; Thu, 2 Aug 2018 16:14:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726221AbeHBSGZ (ORCPT ); Thu, 2 Aug 2018 14:06:25 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48789 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726580AbeHBSGZ (ORCPT ); Thu, 2 Aug 2018 14:06:25 -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 w72GEY1I029956; 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 w72GEY6v019396; 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 w72GEY4L019395; 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 3/6] verbs: Introduce ENV to control EIO upon destroy commands Date: Thu, 2 Aug 2018 19:13:33 +0300 Message-Id: <1533226416-19122-4-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 Introduce an environment variable (i.e. RDMAV_ALLOW_DISASSOC_DESTROY) to control the returned code from destroy commands. Once it's set any destroy command that will get an EIO from the kernel is related as a success. In that case the underlying kernel resources for this object had to be already destroyed via the disassociate mechanism and the user space driver and application can safely clean their resources as well. This comes to prevent a memory leak in the user space area. Signed-off-by: Yishai Hadas --- libibverbs/cmd.c | 2 ++ libibverbs/cmd_write.h | 17 +++++++++++++++++ libibverbs/init.c | 4 ++++ libibverbs/man/ibv_open_device.3 | 8 ++++++++ 4 files changed, 31 insertions(+) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index 5bad9a3..89f8778 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -45,6 +45,8 @@ #include "ibverbs.h" #include +bool verbs_allow_disassociate_destroy; + int ibv_cmd_get_context(struct verbs_context *context_ex, struct ibv_get_context *cmd, size_t cmd_size, struct ib_uverbs_get_context_resp *resp, size_t resp_size) diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index ac59525..6ee4f30 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -291,4 +291,21 @@ _execute_write_only(struct ibv_context *context, struct ibv_command_buffer *cmd, #endif +extern bool verbs_allow_disassociate_destroy; + +/* + * Return true if 'ret' indicates that a destroy operation has failed + * and the function should exit. If the kernel destroy failure is being + * ignored then this will set ret to 0, so the calling function appears to succeed. + */ +static inline bool verbs_is_destroy_err(int *ret) +{ + if (*ret == EIO && verbs_allow_disassociate_destroy) { + *ret = 0; + return true; + } + + return *ret != 0; +} + #endif diff --git a/libibverbs/init.c b/libibverbs/init.c index c3451e6..853515d 100644 --- a/libibverbs/init.c +++ b/libibverbs/init.c @@ -50,6 +50,7 @@ #include #include "ibverbs.h" +#include int abi_ver; @@ -705,6 +706,9 @@ int ibverbs_init(void) fprintf(stderr, PFX "Warning: fork()-safety requested " "but init failed\n"); + if (getenv("RDMAV_ALLOW_DISASSOC_DESTROY")) + verbs_allow_disassociate_destroy = true; + sysfs_path = ibv_get_sysfs_path(); if (!sysfs_path) return -ENOSYS; diff --git a/libibverbs/man/ibv_open_device.3 b/libibverbs/man/ibv_open_device.3 index cae2c4d..3a12d2d 100644 --- a/libibverbs/man/ibv_open_device.3 +++ b/libibverbs/man/ibv_open_device.3 @@ -33,6 +33,14 @@ does not release all the resources allocated using context .I context\fR. To avoid resource leaks, the user should release all associated resources before closing a context. + +Setting the environment variable **RDMAV_ALLOW_DISASSOC_DESTROY** tells the +library to relate an EIO from destroy commands as a success as the kernel +resources were already released. This comes to prevent memory leakage in the +user space area upon device disassociation. Applications using this flag cannot +call ibv_get_cq_event or ibv_get_async_event concurrently with any call to an +object destruction function. + .SH "SEE ALSO" .BR ibv_get_device_list (3), .BR ibv_query_device (3),