From patchwork Thu Aug 2 16:13:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10553947 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 A7DDB13B4 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 95DEA2C2CA for ; Thu, 2 Aug 2018 16:14:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A0342C2F4; 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 969D52C30A for ; Thu, 2 Aug 2018 16:14:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726673AbeHBSGb (ORCPT ); Thu, 2 Aug 2018 14:06:31 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48800 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726636AbeHBSGb (ORCPT ); Thu, 2 Aug 2018 14:06:31 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 2 Aug 2018 19:17:58 +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 w72GEXi1029950; Thu, 2 Aug 2018 19:14:33 +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 w72GEXIw019386; Thu, 2 Aug 2018 19:14:33 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w72GEXSp019383; Thu, 2 Aug 2018 19:14:33 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, jgg@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core 1/6] verbs: Use the new kabi macros with the write fallback system Date: Thu, 2 Aug 2018 19:13:31 +0300 Message-Id: <1533226416-19122-2-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 From: Jason Gunthorpe To access the kabi structs for a WRITE command everything should use the enum name now, not the '_prefix' as these command did. This guarantees that all types match the enum number. Signed-off-by: Jason Gunthorpe Signed-off-by: Yishai Hadas --- libibverbs/cmd_cq.c | 16 ++--- libibverbs/cmd_fallback.c | 54 ++++++++------ libibverbs/cmd_write.h | 176 +++++++++++++++++++++------------------------- 3 files changed, 120 insertions(+), 126 deletions(-) diff --git a/libibverbs/cmd_cq.c b/libibverbs/cmd_cq.c index 3f1254a..0f4780a 100644 --- a/libibverbs/cmd_cq.c +++ b/libibverbs/cmd_cq.c @@ -60,7 +60,7 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe, switch (execute_ioctl_fallback(cq->context, create_cq, cmdb, &ret)) { case TRY_WRITE: { - DECLARE_LEGACY_UHW_BUFS(link, create_cq); + DECLARE_LEGACY_UHW_BUFS(link, IB_USER_VERBS_CMD_CREATE_CQ); *req = (struct ib_uverbs_create_cq){ .user_handle = (uintptr_t)cq, @@ -69,8 +69,7 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe, .comp_channel = channel ? channel->fd : -1, }; - ret = execute_write_bufs(IB_USER_VERBS_CMD_CREATE_CQ, - cq->context, req, resp); + ret = execute_write_bufs(cq->context, req, resp); if (ret) return ret; @@ -80,7 +79,8 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe, return 0; } case TRY_WRITE_EX: { - DECLARE_LEGACY_UHW_BUFS_EX(link, create_cq); + DECLARE_LEGACY_UHW_BUFS_EX(link, + IB_USER_VERBS_EX_CMD_CREATE_CQ); *req = (struct ib_uverbs_ex_create_cq){ .user_handle = (uintptr_t)cq, @@ -90,8 +90,7 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe, .flags = flags, }; - ret = execute_write_bufs_ex(IB_USER_VERBS_EX_CMD_CREATE_CQ, - cq->context, req, resp); + ret = execute_write_bufs_ex(cq->context, req); if (ret) return ret; @@ -152,7 +151,7 @@ int ibv_cmd_destroy_cq(struct ibv_cq *cq) { DECLARE_FBCMD_BUFFER(cmdb, UVERBS_OBJECT_CQ, UVERBS_METHOD_CQ_DESTROY, 2, NULL); - DECLARE_LEGACY_CORE_BUFS(destroy_cq); + DECLARE_LEGACY_CORE_BUFS(IB_USER_VERBS_CMD_DESTROY_CQ); int ret; fill_attr_out_ptr(cmdb, UVERBS_ATTR_DESTROY_CQ_RESP, &resp); @@ -164,8 +163,7 @@ int ibv_cmd_destroy_cq(struct ibv_cq *cq) .cq_handle = cq->handle, }; - ret = execute_write(IB_USER_VERBS_CMD_DESTROY_CQ, cq->context, - req, &resp); + ret = execute_write(cq->context, req, &resp); break; } diff --git a/libibverbs/cmd_fallback.c b/libibverbs/cmd_fallback.c index a943215..2aac6cb 100644 --- a/libibverbs/cmd_fallback.c +++ b/libibverbs/cmd_fallback.c @@ -118,8 +118,9 @@ enum write_fallback _execute_ioctl_fallback(struct ibv_context *ctx, * on the stack (if the driver didn't provide a UHW) or arranged to be * directly before the UHW memory (see _write_set_uhw) */ -void *_write_get_req(struct ibv_command_buffer *link, void *onstack, - size_t size) +void *_write_get_req(struct ibv_command_buffer *link, + struct ib_uverbs_cmd_hdr *onstack, size_t size, + uint32_t cmdnum) { struct ib_uverbs_cmd_hdr *hdr; @@ -137,13 +138,15 @@ void *_write_get_req(struct ibv_command_buffer *link, void *onstack, hdr->in_words = __check_divide(size, 4); } + hdr->command = cmdnum; + return hdr + 1; } -void *_write_get_req_ex(struct ibv_command_buffer *link, void *onstack, - size_t size) +void *_write_get_req_ex(struct ibv_command_buffer *link, struct ex_hdr *onstack, + size_t size, uint32_t cmdnum) { - struct _ib_ex_hdr *hdr; + struct ex_hdr *hdr; size_t full_size = size + sizeof(*hdr); if (link->uhw_in_idx != _UHW_NO_INDEX) { @@ -160,6 +163,9 @@ void *_write_get_req_ex(struct ibv_command_buffer *link, void *onstack, hdr->ex_hdr.provider_in_words = 0; } + hdr->hdr.command = IB_USER_VERBS_CMD_FLAG_EXTENDED | cmdnum; + hdr->ex_hdr.cmd_hdr_reserved = 0; + return hdr + 1; } @@ -186,7 +192,7 @@ void *_write_get_resp(struct ibv_command_buffer *link, } void *_write_get_resp_ex(struct ibv_command_buffer *link, - struct _ib_ex_hdr *hdr, void *onstack, + struct ex_hdr *hdr, void *onstack, size_t resp_size) { void *resp_start; @@ -206,51 +212,59 @@ void *_write_get_resp_ex(struct ibv_command_buffer *link, hdr->ex_hdr.provider_out_words = 0; } + hdr->ex_hdr.response = ioctl_ptr_to_u64(resp_start); + return resp_start; } -int _execute_write_raw(unsigned int cmdnum, struct ibv_context *ctx, - struct ib_uverbs_cmd_hdr *hdr, void *resp) +int _execute_write_raw(struct ibv_context *ctx, struct ib_uverbs_cmd_hdr *hdr, + void *resp) { - hdr->command = cmdnum; - /* * Users assumes the stack buffer is zeroed before passing to the * kernel for writing. */ - memset(resp, 0, hdr->out_words * 4); + if (resp) { + /* + * The helper macros prove the response is at offset 0 of the + * request. + */ + uint64_t *response = (uint64_t *)(hdr + 1); + + *response = ioctl_ptr_to_u64(resp); + memset(resp, 0, hdr->out_words * 4); + } if (write(ctx->cmd_fd, hdr, hdr->in_words * 4) != hdr->in_words * 4) return errno; - VALGRIND_MAKE_MEM_DEFINED(resp, hdr->out_words * 4); + if (resp) + VALGRIND_MAKE_MEM_DEFINED(resp, hdr->out_words * 4); return 0; } -int _execute_write_raw_ex(uint32_t cmdnum, struct ibv_context *ctx, - struct _ib_ex_hdr *hdr, void *resp) +int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *hdr) { size_t write_bytes = sizeof(*hdr) + (hdr->hdr.in_words + hdr->ex_hdr.provider_in_words) * 8; size_t resp_bytes = (hdr->hdr.out_words + hdr->ex_hdr.provider_out_words) * 8; - - hdr->hdr.command = IB_USER_VERBS_CMD_FLAG_EXTENDED | cmdnum; - hdr->ex_hdr.cmd_hdr_reserved = 0; - hdr->ex_hdr.response = ioctl_ptr_to_u64(resp); + void *resp = (void *)(uintptr_t)hdr->ex_hdr.response; /* * Users assumes the stack buffer is zeroed before passing to the * kernel for writing. */ - memset(resp, 0, resp_bytes); + if (resp) + memset(resp, 0, resp_bytes); if (write(ctx->cmd_fd, hdr, write_bytes) != write_bytes) return errno; - VALGRIND_MAKE_MEM_DEFINED(resp, resp_bytes); + if (resp) + VALGRIND_MAKE_MEM_DEFINED(resp, resp_bytes); return 0; } diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index cd0f371..ac59525 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -45,80 +45,49 @@ static inline struct ib_uverbs_cmd_hdr *get_req_hdr(void *req) return ((struct ib_uverbs_cmd_hdr *)req) - 1; } -struct _ib_ex_hdr { - struct ib_uverbs_cmd_hdr hdr; - struct ib_uverbs_ex_cmd_hdr ex_hdr; -}; - -static inline struct _ib_ex_hdr *get_req_hdr_ex(void *req) +static inline struct ex_hdr *get_req_hdr_ex(void *req) { - return ((struct _ib_ex_hdr *)req) - 1; + return ((struct ex_hdr *)req) - 1; } -/* - * When using these new interfaces the kernel UAPI structs 'ib_uverbs_*' are - * used, not the structs from kern-abi.h. The only difference between the two - * is the inclusion of the header in the kern-abi.h struct. This macro creates - * memory on the stack that includes both the header and the struct. - */ -#define DECLARE_LEGACY_REQ_BUF_CORE(_name, _pattern) \ - struct { \ - struct ib_uverbs_cmd_hdr hdr; \ - struct ib_uverbs_##_pattern core_payload; \ - } _name - -#define DECLARE_LEGACY_REQ_BUF_CORE_EX(_name, _pattern) \ - struct { \ - struct ib_uverbs_cmd_hdr hdr; \ - struct ib_uverbs_ex_cmd_hdr ex_hdr; \ - struct ib_uverbs_ex_##_pattern core_payload; \ - } _name - -void *_write_get_req(struct ibv_command_buffer *link, void *onstack, - size_t size); -void *_write_get_req_ex(struct ibv_command_buffer *link, void *onstack, - size_t size); +void *_write_get_req(struct ibv_command_buffer *link, + struct ib_uverbs_cmd_hdr *onstack, size_t size, + uint32_t cmdnum); +void *_write_get_req_ex(struct ibv_command_buffer *link, struct ex_hdr *onstack, + size_t size, uint32_t cmdnum); void *_write_get_resp(struct ibv_command_buffer *link, struct ib_uverbs_cmd_hdr *hdr, void *onstack, size_t resp_size); void *_write_get_resp_ex(struct ibv_command_buffer *link, - struct _ib_ex_hdr *hdr, void *onstack, + struct ex_hdr *hdr, void *onstack, size_t resp_size); -#define DECLARE_LEGACY_REQ_BUF(_name, _link, _pattern) \ - DECLARE_LEGACY_REQ_BUF_CORE(__##_name##_onstack, _pattern); \ - struct ib_uverbs_##_pattern *_name = \ - _write_get_req(_link, &__##_name##_onstack, sizeof(*_name)) - -#define DECLARE_LEGACY_REQ_BUF_EX(_name, _link, _pattern) \ - DECLARE_LEGACY_REQ_BUF_CORE_EX(__##_name##_onstack, _pattern); \ - struct ib_uverbs_ex_##_pattern *_name = \ - _write_get_req_ex(_link, &__##_name##_onstack, sizeof(*_name)) - -#define DECLARE_LEGACY_RESP_BUF(_name, _link, _req, _pattern) \ - struct ib_uverbs_##_pattern##_resp __##_name##_onstack, \ - *_name = _write_get_resp(_link, get_req_hdr(_req), \ - &__##_name##_onstack, sizeof(*_name)) - -#define DECLARE_LEGACY_RESP_BUF_EX(_name, _link, _req, _pattern) \ - struct ib_uverbs_ex_##_pattern##_resp __##_name##_onstack, \ - *_name = _write_get_resp_ex(_link, get_req_hdr_ex(_req), \ - &__##_name##_onstack, \ - sizeof(*_name)) - /* * This macro creates 'req' and 'resp' pointers in the local stack frame that * point to the core code write command structures patterned off _pattern. * * This should be done before calling execute_write_bufs */ -#define DECLARE_LEGACY_UHW_BUFS(_link, _pattern) \ - DECLARE_LEGACY_REQ_BUF(req, _link, _pattern); \ - DECLARE_LEGACY_RESP_BUF(resp, _link, req, _pattern) +#define DECLARE_LEGACY_UHW_BUFS(_link, _enum) \ + IBV_ABI_REQ(_enum) __req_onstack; \ + IBV_KABI_RESP(_enum) __resp_onstack; \ + static_assert(offsetof(IBV_KABI_REQ(_enum), response) == 0, \ + "Bad response offset"); \ + IBV_KABI_REQ(_enum) *req = _write_get_req(_link, &__req_onstack.hdr, \ + sizeof(*req), _enum); \ + IBV_KABI_RESP(_enum) *resp = ({ \ + void *_resp = _write_get_resp(_link, get_req_hdr(req), \ + &__resp_onstack, sizeof(*resp)); \ + _resp; \ + }) -#define DECLARE_LEGACY_UHW_BUFS_EX(_link, _pattern) \ - DECLARE_LEGACY_REQ_BUF_EX(req, _link, _pattern); \ - DECLARE_LEGACY_RESP_BUF_EX(resp, _link, req, _pattern) +#define DECLARE_LEGACY_UHW_BUFS_EX(_link, _enum) \ + IBV_ABI_REQ(_enum) __req_onstack; \ + IBV_KABI_RESP(_enum) __resp_onstack; \ + IBV_KABI_REQ(_enum) *req = _write_get_req_ex( \ + _link, &__req_onstack.hdr, sizeof(*req), _enum); \ + IBV_KABI_RESP(_enum) *resp = _write_get_resp_ex( \ + _link, get_req_hdr_ex(req), &__resp_onstack, sizeof(*resp)) /* * This macro is used to implement the compatibility command call wrappers. @@ -174,51 +143,68 @@ enum write_fallback _execute_ioctl_fallback(struct ibv_context *ctx, _execute_ioctl_fallback(ctx, _CMD_BIT(cmd_name), cmdb, ret) /* These helpers replace the raw write() and IBV_INIT_CMD macros */ -int _execute_write_raw(unsigned int cmdnum, struct ibv_context *ctx, - struct ib_uverbs_cmd_hdr *req, void *resp); +int _execute_write_raw(struct ibv_context *ctx, struct ib_uverbs_cmd_hdr *req, + void *resp); /* For users of DECLARE_LEGACY_UHW_BUFS */ -#define execute_write_bufs(cmdnum, ctx, req, resp) \ - ({ \ - (req)->response = ioctl_ptr_to_u64(resp); \ - _execute_write_raw(cmdnum, ctx, get_req_hdr(req), resp); \ - }) +#define execute_write_bufs(ctx, req, resp) \ + _execute_write_raw(ctx, get_req_hdr(req), resp) -int _execute_write_raw_ex(uint32_t cmdnum, struct ibv_context *ctx, - struct _ib_ex_hdr *req, void *resp); +int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *req); /* For users of DECLARE_LEGACY_UHW_BUFS_EX */ -#define execute_write_bufs_ex(cmdnum, ctx, req, resp) \ - _execute_write_raw_ex(cmdnum, ctx, get_req_hdr_ex(req), resp) - -static inline int _execute_write(uint32_t cmdnum, struct ibv_context *ctx, - void *req, size_t req_len, void *resp, - size_t resp_len) -{ - struct ib_uverbs_cmd_hdr *hdr = get_req_hdr(req); - - hdr->in_words = req_len / 4; - hdr->out_words = resp_len / 4; - return _execute_write_raw(cmdnum, ctx, hdr, resp); -} +#define execute_write_bufs_ex(ctx, req) \ + _execute_write_raw_ex(ctx, get_req_hdr_ex(req)) /* For users with no possible UHW bufs. */ -#define DECLARE_LEGACY_CORE_BUFS(_pattern) \ - DECLARE_LEGACY_REQ_BUF_CORE(__req_onstack, _pattern); \ - struct ib_uverbs_##_pattern *const req = &__req_onstack.core_payload; \ - struct ib_uverbs_##_pattern##_resp resp +#define DECLARE_LEGACY_CORE_BUFS(_enum) \ + IBV_ABI_REQ(_enum) __req_onstack; \ + IBV_KABI_RESP(_enum) resp; \ + static_assert(offsetof(IBV_KABI_REQ(_enum), response) == 0, \ + "Bad response offset"); \ + IBV_KABI_REQ(_enum) *const req = ({ \ + __req_onstack.hdr.command = _enum; \ + __req_onstack.hdr.in_words = sizeof(__req_onstack) / 4; \ + __req_onstack.hdr.out_words = sizeof(resp) / 4; \ + &__req_onstack.core_payload; \ + }) +#define DECLARE_LEGACY_CORE_REQ(_enum) \ + IBV_ABI_REQ(_enum) __req_onstack; \ + static_assert(sizeof(IBV_KABI_RESP(_enum)) == 0, \ + "Method has a response!"); \ + IBV_KABI_REQ(_enum) *const req = ({ \ + __req_onstack.hdr.command = _enum; \ + __req_onstack.hdr.in_words = sizeof(__req_onstack) / 4; \ + __req_onstack.hdr.out_words = 0; \ + &__req_onstack.core_payload; \ + }) + +#define DECLARE_LEGACY_CORE_BUFS_EX(_enum) \ + IBV_ABI_REQ(_enum) __req_onstack; \ + IBV_KABI_RESP(_enum) resp; \ + IBV_KABI_REQ(_enum) *const req = ({ \ + __req_onstack.hdr.hdr.command = \ + IB_USER_VERBS_CMD_FLAG_EXTENDED | _enum; \ + __req_onstack.hdr.hdr.in_words = \ + (sizeof(__req_onstack) - sizeof(struct ex_hdr)) / 8; \ + __req_onstack.hdr.hdr.out_words = sizeof(resp) / 8; \ + __req_onstack.hdr.ex_hdr.cmd_hdr_reserved = 0; \ + __req_onstack.hdr.ex_hdr.provider_in_words = 0; \ + __req_onstack.hdr.ex_hdr.provider_out_words = 0; \ + __req_onstack.hdr.ex_hdr.response = \ + (sizeof(resp) == 0) ? 0 : ioctl_ptr_to_u64(&resp); \ + &__req_onstack.core_payload; \ + }) /* * For users with no UHW bufs. To be used in conjunction with * DECLARE_LEGACY_CORE_BUFS. req points to the core payload (with headroom for * the header). */ -#define execute_write(cmdnum, ctx, req, resp) \ - ({ \ - (req)->response = ioctl_ptr_to_u64(resp); \ - _execute_write(cmdnum, ctx, req, sizeof(*req), resp, \ - sizeof(*resp)); \ - }) +#define execute_write(ctx, req, resp) \ + _execute_write_raw(ctx, get_req_hdr(req), resp) +#define execute_write_ex(ctx, req) \ + _execute_write_raw_ex(ctx, get_req_hdr_ex(req)) /* * These two macros are used only with execute_ioctl_fallback - they allow the @@ -247,24 +233,20 @@ _execute_ioctl_only(struct ibv_context *context, struct ibv_command_buffer *cmd, _execute_ioctl_only(ctx, cmdb, ret) #undef execute_write_bufs -static inline int execute_write_bufs(uint32_t cmdnum, - struct ibv_context *ctx, void *req, +static inline int execute_write_bufs(struct ibv_context *ctx, void *req, void *resp) { return ENOSYS; } #undef execute_write_bufs_ex -static inline int execute_write_bufs_ex(uint32_t cmdnum, - struct ibv_context *ctx, void *req, - void *resp) +static inline int execute_write_bufs_ex(struct ibv_context *ctx, void *req) { return ENOSYS; } #undef execute_write -static inline int execute_write(uint32_t cmdnum, - struct ibv_context *ctx, void *req, +static inline int execute_write(struct ibv_context *ctx, void *req, void *resp) { return ENOSYS; From patchwork Thu Aug 2 16:13:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10553943 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 0EE8E13BB for ; Thu, 2 Aug 2018 16:14:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F12692C2CA for ; Thu, 2 Aug 2018 16:14:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E5C2F2C30A; Thu, 2 Aug 2018 16:14:39 +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 1EE172C2CA for ; Thu, 2 Aug 2018 16:14:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726547AbeHBSG1 (ORCPT ); Thu, 2 Aug 2018 14:06:27 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48786 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726636AbeHBSG1 (ORCPT ); Thu, 2 Aug 2018 14:06:27 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 2 Aug 2018 19:17:58 +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 w72GEXRr029953; 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 w72GEX6I019392; Thu, 2 Aug 2018 19:14:33 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w72GEXYj019389; Thu, 2 Aug 2018 19:14:33 +0300 From: Yishai Hadas To: linux-rdma@vger.kernel.org Cc: yishaih@mellanox.com, jgg@mellanox.com, majd@mellanox.com Subject: [PATCH rdma-core 2/6] verbs: Convert write path callers to use DECLARE_LEGACY_CORE_BUFS Date: Thu, 2 Aug 2018 19:13:32 +0300 Message-Id: <1533226416-19122-3-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 From: Jason Gunthorpe This changes all the write cmd wrappers that do not use UDATA to directly use execute write and the new methods. This removes a lot of duplicated code and makes this code closer to something that can be moved into the ioctl fallback pattern. As part of this patch the ibv_cmd_dealloc_mw was cleaned-up to not get cmd and its size from its callers as there is no real usage for it in both user space and kernel. Signed-off-by: Jason Gunthorpe Signed-off-by: Yishai Hadas --- libibverbs/cmd.c | 206 ++++++++++++++++++++----------------------------- libibverbs/driver.h | 3 +- providers/mlx4/verbs.c | 3 +- providers/mlx5/verbs.c | 3 +- 4 files changed, 87 insertions(+), 128 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index 0e60193..5bad9a3 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -41,6 +41,7 @@ #include #include +#include #include "ibverbs.h" #include @@ -334,15 +335,12 @@ int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd, int ibv_cmd_dealloc_pd(struct ibv_pd *pd) { - struct ibv_dealloc_pd cmd; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DEALLOC_PD); - IBV_INIT_CMD(&cmd, sizeof cmd, DEALLOC_PD); - cmd.pd_handle = pd->handle; - - if (write(pd->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; - - return 0; + *req = (struct ib_uverbs_dealloc_pd) { + .pd_handle = pd->handle, + }; + return execute_write(pd->context, req, NULL); } int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, @@ -379,15 +377,12 @@ int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, int ibv_cmd_close_xrcd(struct verbs_xrcd *xrcd) { - struct ibv_close_xrcd cmd; - - IBV_INIT_CMD(&cmd, sizeof cmd, CLOSE_XRCD); - cmd.xrcd_handle = xrcd->handle; - - if (write(xrcd->xrcd.context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_CLOSE_XRCD); - return 0; + *req = (struct ib_uverbs_close_xrcd){ + .xrcd_handle = xrcd->handle, + }; + return execute_write(xrcd->xrcd.context, req, NULL); } int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, @@ -450,16 +445,12 @@ int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr, int ibv_cmd_dereg_mr(struct verbs_mr *vmr) { - struct ibv_dereg_mr cmd; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DEREG_MR); - IBV_INIT_CMD(&cmd, sizeof cmd, DEREG_MR); - cmd.mr_handle = vmr->ibv_mr.handle; - - if (write(vmr->ibv_mr.context->cmd_fd, &cmd, sizeof(cmd)) != - sizeof(cmd)) - return errno; - - return 0; + *req = (struct ib_uverbs_dereg_mr){ + .mr_handle = vmr->ibv_mr.handle, + }; + return execute_write(vmr->ibv_mr.context, req, NULL); } int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, @@ -486,16 +477,14 @@ int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, return 0; } -int ibv_cmd_dealloc_mw(struct ibv_mw *mw, - struct ibv_dealloc_mw *cmd, size_t cmd_size) +int ibv_cmd_dealloc_mw(struct ibv_mw *mw) { - IBV_INIT_CMD(cmd, cmd_size, DEALLOC_MW); - cmd->mw_handle = mw->handle; - - if (write(mw->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DEALLOC_MW); - return 0; + *req = (struct ib_uverbs_dealloc_mw) { + .mw_handle = mw->handle, + }; + return execute_write(mw->context, req, NULL); } int ibv_cmd_poll_cq(struct ibv_cq *ibcq, int ne, struct ibv_wc *wc) @@ -547,16 +536,13 @@ out: int ibv_cmd_req_notify_cq(struct ibv_cq *ibcq, int solicited_only) { - struct ibv_req_notify_cq cmd; - - IBV_INIT_CMD(&cmd, sizeof cmd, REQ_NOTIFY_CQ); - cmd.cq_handle = ibcq->handle; - cmd.solicited_only = !!solicited_only; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ); - if (write(ibcq->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; - - return 0; + *req = (struct ib_uverbs_req_notify_cq){ + .cq_handle = ibcq->handle, + .solicited_only = !!solicited_only, + }; + return execute_write(ibcq->context, req, NULL); } int ibv_cmd_resize_cq(struct ibv_cq *cq, int cqe, @@ -771,17 +757,16 @@ int ibv_cmd_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, int ibv_cmd_destroy_srq(struct ibv_srq *srq) { - struct ibv_destroy_srq cmd; - struct ib_uverbs_destroy_qp_resp resp; - - IBV_INIT_CMD_RESP(&cmd, sizeof cmd, DESTROY_SRQ, &resp, sizeof resp); - cmd.srq_handle = srq->handle; - cmd.reserved = 0; + DECLARE_LEGACY_CORE_BUFS(IB_USER_VERBS_CMD_DESTROY_SRQ); + int ret; - if (write(srq->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; + *req = (struct ib_uverbs_destroy_srq){ + .srq_handle = srq->handle, + }; - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_write(srq->context, req, &resp); + if (ret) + return ret; pthread_mutex_lock(&srq->mutex); while (srq->events_completed != resp.events_reported) @@ -1571,30 +1556,26 @@ int ibv_cmd_create_ah(struct ibv_pd *pd, struct ibv_ah *ah, int ibv_cmd_destroy_ah(struct ibv_ah *ah) { - struct ibv_destroy_ah cmd; - - IBV_INIT_CMD(&cmd, sizeof cmd, DESTROY_AH); - cmd.ah_handle = ah->handle; - - if (write(ah->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DESTROY_AH); - return 0; + *req = (struct ib_uverbs_destroy_ah){ + .ah_handle = ah->handle, + }; + return execute_write(ah->context, req, NULL); } int ibv_cmd_destroy_qp(struct ibv_qp *qp) { - struct ibv_destroy_qp cmd; - struct ib_uverbs_destroy_qp_resp resp; + DECLARE_LEGACY_CORE_BUFS(IB_USER_VERBS_CMD_DESTROY_QP); + int ret; - IBV_INIT_CMD_RESP(&cmd, sizeof cmd, DESTROY_QP, &resp, sizeof resp); - cmd.qp_handle = qp->handle; - cmd.reserved = 0; + *req = (struct ib_uverbs_destroy_qp){ + .qp_handle = qp->handle, + }; - if (write(qp->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_write(qp->context, req, &resp); + if (ret) + return ret; pthread_mutex_lock(&qp->mutex); while (qp->events_completed != resp.events_reported) @@ -1606,34 +1587,26 @@ int ibv_cmd_destroy_qp(struct ibv_qp *qp) int ibv_cmd_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid) { - struct ibv_attach_mcast cmd; - - IBV_INIT_CMD(&cmd, sizeof cmd, ATTACH_MCAST); - memcpy(cmd.gid, gid->raw, sizeof cmd.gid); - cmd.qp_handle = qp->handle; - cmd.mlid = lid; - cmd.reserved = 0; - - if (write(qp->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; - - return 0; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_ATTACH_MCAST); + + *req = (struct ib_uverbs_attach_mcast){ + .qp_handle = qp->handle, + .mlid = lid, + }; + memcpy(req->gid, gid->raw, sizeof(req->gid)); + return execute_write(qp->context, req, NULL); } int ibv_cmd_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid) { - struct ibv_detach_mcast cmd; - - IBV_INIT_CMD(&cmd, sizeof cmd, DETACH_MCAST); - memcpy(cmd.gid, gid->raw, sizeof cmd.gid); - cmd.qp_handle = qp->handle; - cmd.mlid = lid; - cmd.reserved = 0; - - if (write(qp->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; - - return 0; + DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DETACH_MCAST); + + *req = (struct ib_uverbs_detach_mcast){ + .qp_handle = qp->handle, + .mlid = lid, + }; + memcpy(req->gid, gid->raw, sizeof(req->gid)); + return execute_write(qp->context, req, NULL); } static int buffer_is_zero(char *addr, ssize_t size) @@ -1893,16 +1866,12 @@ err: int ibv_cmd_destroy_flow(struct ibv_flow *flow_id) { - struct ibv_destroy_flow cmd; - int ret = 0; - - memset(&cmd, 0, sizeof(cmd)); - IBV_INIT_CMD_EX(&cmd, sizeof(cmd), DESTROY_FLOW); - cmd.flow_handle = flow_id->handle; + DECLARE_LEGACY_CORE_BUFS_EX(IB_USER_VERBS_EX_CMD_DESTROY_FLOW); - if (write(flow_id->context->cmd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) - ret = errno; - return ret; + *req = (struct ib_uverbs_destroy_flow){ + .flow_handle = flow_id->handle, + }; + return execute_write_ex(flow_id->context, req); } int ibv_cmd_create_wq(struct ibv_context *context, @@ -1997,18 +1966,16 @@ int ibv_cmd_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr, int ibv_cmd_destroy_wq(struct ibv_wq *wq) { - struct ibv_destroy_wq cmd; - struct ib_uverbs_ex_destroy_wq_resp resp; - int ret = 0; - - memset(&cmd, 0, sizeof(cmd)); - memset(&resp, 0, sizeof(resp)); + DECLARE_LEGACY_CORE_BUFS_EX(IB_USER_VERBS_EX_CMD_DESTROY_WQ); + int ret; - IBV_INIT_CMD_RESP_EX(&cmd, sizeof(cmd), DESTROY_WQ, &resp, sizeof(resp)); - cmd.wq_handle = wq->handle; + *req = (struct ib_uverbs_ex_destroy_wq){ + .wq_handle = wq->handle, + }; - if (write(wq->context->cmd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) - return errno; + ret = execute_write_ex(wq->context, req); + if (ret) + return ret; if (resp.response_length < sizeof(resp)) return EINVAL; @@ -2018,7 +1985,7 @@ int ibv_cmd_destroy_wq(struct ibv_wq *wq) pthread_cond_wait(&wq->cond, &wq->mutex); pthread_mutex_unlock(&wq->mutex); - return ret; + return 0; } int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, @@ -2076,17 +2043,12 @@ int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, int ibv_cmd_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table) { - struct ibv_destroy_rwq_ind_table cmd; - int ret = 0; - - memset(&cmd, 0, sizeof(cmd)); - IBV_INIT_CMD_EX(&cmd, sizeof(cmd), DESTROY_RWQ_IND_TBL); - cmd.ind_tbl_handle = rwq_ind_table->ind_tbl_handle; + DECLARE_LEGACY_CORE_BUFS_EX(IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); - if (write(rwq_ind_table->context->cmd_fd, &cmd, sizeof(cmd)) != sizeof(cmd)) - ret = errno; - - return ret; + *req = (struct ib_uverbs_ex_destroy_rwq_ind_table){ + .ind_tbl_handle = rwq_ind_table->ind_tbl_handle, + }; + return execute_write_ex(rwq_ind_table->context, req); } diff --git a/libibverbs/driver.h b/libibverbs/driver.h index 64c8757..50962f8 100644 --- a/libibverbs/driver.h +++ b/libibverbs/driver.h @@ -435,8 +435,7 @@ int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, struct ibv_mw *mw, struct ibv_alloc_mw *cmd, size_t cmd_size, struct ib_uverbs_alloc_mw_resp *resp, size_t resp_size); -int ibv_cmd_dealloc_mw(struct ibv_mw *mw, - struct ibv_dealloc_mw *cmd, size_t cmd_size); +int ibv_cmd_dealloc_mw(struct ibv_mw *mw); int ibv_cmd_create_cq(struct ibv_context *context, int cqe, struct ibv_comp_channel *channel, int comp_vector, struct ibv_cq *cq, diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c index de778bb..40e94c4 100644 --- a/providers/mlx4/verbs.c +++ b/providers/mlx4/verbs.c @@ -354,9 +354,8 @@ struct ibv_mw *mlx4_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type) int mlx4_dealloc_mw(struct ibv_mw *mw) { int ret; - struct ibv_dealloc_mw cmd; - ret = ibv_cmd_dealloc_mw(mw, &cmd, sizeof(cmd)); + ret = ibv_cmd_dealloc_mw(mw); if (ret && !cleanup_on_fatal(ret)) return ret; diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index a6e0ae3..25f0d5f 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -518,9 +518,8 @@ struct ibv_mw *mlx5_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type) int mlx5_dealloc_mw(struct ibv_mw *mw) { int ret; - struct ibv_dealloc_mw cmd; - ret = ibv_cmd_dealloc_mw(mw, &cmd, sizeof(cmd)); + ret = ibv_cmd_dealloc_mw(mw); if (ret) return ret; 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), From patchwork Thu Aug 2 16:13:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10553941 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 59C839093 for ; Thu, 2 Aug 2018 16:14:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A19C2C2CA for ; Thu, 2 Aug 2018 16:14:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E2792C2F7; Thu, 2 Aug 2018 16:14:38 +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 B9C4D2C2CA for ; Thu, 2 Aug 2018 16:14:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726654AbeHBSG0 (ORCPT ); Thu, 2 Aug 2018 14:06:26 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48788 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726547AbeHBSG0 (ORCPT ); Thu, 2 Aug 2018 14:06:26 -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 w72GEYGx029959; 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 w72GEYTI019400; 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 w72GEYuG019399; 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 4/6] verbs: Consider EIO upon write destroy commands Date: Thu, 2 Aug 2018 19:13:34 +0300 Message-Id: <1533226416-19122-5-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 Use verbs_is_destroy_err() upon write destroy commands to consider the EIO use case. Signed-off-by: Yishai Hadas --- libibverbs/cmd.c | 62 +++++++++++++++++++++++++++++++++++++++++++---------- libibverbs/cmd_cq.c | 2 +- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index 89f8778..d88b3aa 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -338,11 +338,16 @@ int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd, int ibv_cmd_dealloc_pd(struct ibv_pd *pd) { DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DEALLOC_PD); + int ret; *req = (struct ib_uverbs_dealloc_pd) { .pd_handle = pd->handle, }; - return execute_write(pd->context, req, NULL); + ret = execute_write(pd->context, req, NULL); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, @@ -380,11 +385,16 @@ int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, int ibv_cmd_close_xrcd(struct verbs_xrcd *xrcd) { DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_CLOSE_XRCD); + int ret; *req = (struct ib_uverbs_close_xrcd){ .xrcd_handle = xrcd->handle, }; - return execute_write(xrcd->xrcd.context, req, NULL); + ret = execute_write(xrcd->xrcd.context, req, NULL); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, @@ -448,11 +458,16 @@ int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr, int ibv_cmd_dereg_mr(struct verbs_mr *vmr) { DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DEREG_MR); + int ret; *req = (struct ib_uverbs_dereg_mr){ .mr_handle = vmr->ibv_mr.handle, }; - return execute_write(vmr->ibv_mr.context, req, NULL); + ret = execute_write(vmr->ibv_mr.context, req, NULL); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, @@ -482,11 +497,16 @@ int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, int ibv_cmd_dealloc_mw(struct ibv_mw *mw) { DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DEALLOC_MW); + int ret; *req = (struct ib_uverbs_dealloc_mw) { .mw_handle = mw->handle, }; - return execute_write(mw->context, req, NULL); + ret = execute_write(mw->context, req, NULL); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_poll_cq(struct ibv_cq *ibcq, int ne, struct ibv_wc *wc) @@ -767,7 +787,7 @@ int ibv_cmd_destroy_srq(struct ibv_srq *srq) }; ret = execute_write(srq->context, req, &resp); - if (ret) + if (verbs_is_destroy_err(&ret)) return ret; pthread_mutex_lock(&srq->mutex); @@ -1559,11 +1579,16 @@ int ibv_cmd_create_ah(struct ibv_pd *pd, struct ibv_ah *ah, int ibv_cmd_destroy_ah(struct ibv_ah *ah) { DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DESTROY_AH); + int ret; *req = (struct ib_uverbs_destroy_ah){ .ah_handle = ah->handle, }; - return execute_write(ah->context, req, NULL); + ret = execute_write(ah->context, req, NULL); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_destroy_qp(struct ibv_qp *qp) @@ -1576,7 +1601,7 @@ int ibv_cmd_destroy_qp(struct ibv_qp *qp) }; ret = execute_write(qp->context, req, &resp); - if (ret) + if (verbs_is_destroy_err(&ret)) return ret; pthread_mutex_lock(&qp->mutex); @@ -1602,13 +1627,18 @@ int ibv_cmd_attach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t l int ibv_cmd_detach_mcast(struct ibv_qp *qp, const union ibv_gid *gid, uint16_t lid) { DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_DETACH_MCAST); + int ret; *req = (struct ib_uverbs_detach_mcast){ .qp_handle = qp->handle, .mlid = lid, }; memcpy(req->gid, gid->raw, sizeof(req->gid)); - return execute_write(qp->context, req, NULL); + ret = execute_write(qp->context, req, NULL); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } static int buffer_is_zero(char *addr, ssize_t size) @@ -1869,11 +1899,16 @@ err: int ibv_cmd_destroy_flow(struct ibv_flow *flow_id) { DECLARE_LEGACY_CORE_BUFS_EX(IB_USER_VERBS_EX_CMD_DESTROY_FLOW); + int ret; *req = (struct ib_uverbs_destroy_flow){ .flow_handle = flow_id->handle, }; - return execute_write_ex(flow_id->context, req); + ret = execute_write_ex(flow_id->context, req); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_create_wq(struct ibv_context *context, @@ -1976,7 +2011,7 @@ int ibv_cmd_destroy_wq(struct ibv_wq *wq) }; ret = execute_write_ex(wq->context, req); - if (ret) + if (verbs_is_destroy_err(&ret)) return ret; if (resp.response_length < sizeof(resp)) @@ -2046,11 +2081,16 @@ int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, int ibv_cmd_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table) { DECLARE_LEGACY_CORE_BUFS_EX(IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL); + int ret; *req = (struct ib_uverbs_ex_destroy_rwq_ind_table){ .ind_tbl_handle = rwq_ind_table->ind_tbl_handle, }; - return execute_write_ex(rwq_ind_table->context, req); + ret = execute_write_ex(rwq_ind_table->context, req); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } diff --git a/libibverbs/cmd_cq.c b/libibverbs/cmd_cq.c index 0f4780a..73cd2f2 100644 --- a/libibverbs/cmd_cq.c +++ b/libibverbs/cmd_cq.c @@ -171,7 +171,7 @@ int ibv_cmd_destroy_cq(struct ibv_cq *cq) break; } - if (ret) + if (verbs_is_destroy_err(&ret)) return ret; pthread_mutex_lock(&cq->mutex); 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); From patchwork Thu Aug 2 16:13:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yishai Hadas X-Patchwork-Id: 10553949 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 56FF413BB for ; Thu, 2 Aug 2018 16:14:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 474112C2CA for ; Thu, 2 Aug 2018 16:14:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BB0D2C30A; Thu, 2 Aug 2018 16:14:49 +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 BE4E52C2CA for ; Thu, 2 Aug 2018 16:14:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727067AbeHBSGg (ORCPT ); Thu, 2 Aug 2018 14:06:36 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:48835 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726636AbeHBSGf (ORCPT ); Thu, 2 Aug 2018 14:06:35 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from yishaih@mellanox.com) with ESMTPS (AES256-SHA encrypted); 2 Aug 2018 19:18:07 +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 w72GEgCq029988; Thu, 2 Aug 2018 19:14:42 +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 w72GEYdM019414; Thu, 2 Aug 2018 19:14:42 +0300 Received: (from yishaih@localhost) by vnc17.mtl.labs.mlnx (8.13.8/8.13.8/Submit) id w72GEYuF019413; 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 6/6] Consider EIO upon ioctl destroy commands Date: Thu, 2 Aug 2018 19:13:36 +0300 Message-Id: <1533226416-19122-7-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 Use verbs_is_destroy_err() upon ioctl destroy commands to consider the EIO use case. Signed-off-by: Yishai Hadas --- libibverbs/cmd_counters.c | 8 +++++++- libibverbs/cmd_dm.c | 7 ++++++- libibverbs/cmd_flow_action.c | 8 +++++++- libibverbs/libibverbs.map.in | 1 + providers/mlx5/verbs.c | 2 ++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libibverbs/cmd_counters.c b/libibverbs/cmd_counters.c index 13e66d5..ed57f25 100644 --- a/libibverbs/cmd_counters.c +++ b/libibverbs/cmd_counters.c @@ -33,6 +33,7 @@ #include #include #include +#include int ibv_cmd_create_counters(struct ibv_context *context, struct ibv_counters_init_attr *init_attr, @@ -65,9 +66,14 @@ int ibv_cmd_destroy_counters(struct verbs_counters *vcounters) DECLARE_COMMAND_BUFFER(cmd, UVERBS_OBJECT_COUNTERS, UVERBS_METHOD_COUNTERS_DESTROY, 1); + int ret; fill_attr_in_obj(cmd, UVERBS_ATTR_DESTROY_COUNTERS_HANDLE, vcounters->handle); - return execute_ioctl(vcounters->counters.context, cmd); + ret = execute_ioctl(vcounters->counters.context, cmd); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_read_counters(struct verbs_counters *vcounters, diff --git a/libibverbs/cmd_dm.c b/libibverbs/cmd_dm.c index e2018c3..86b1331 100644 --- a/libibverbs/cmd_dm.c +++ b/libibverbs/cmd_dm.c @@ -62,10 +62,15 @@ int ibv_cmd_free_dm(struct verbs_dm *dm) { DECLARE_COMMAND_BUFFER(cmdb, UVERBS_OBJECT_DM, UVERBS_METHOD_DM_FREE, 1); + int ret; fill_attr_in_obj(cmdb, UVERBS_ATTR_FREE_DM_HANDLE, dm->handle); - return execute_ioctl(dm->dm.context, cmdb); + ret = execute_ioctl(dm->dm.context, cmdb); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } int ibv_cmd_reg_dm_mr(struct ibv_pd *pd, struct verbs_dm *dm, diff --git a/libibverbs/cmd_flow_action.c b/libibverbs/cmd_flow_action.c index 1782fb7..0bb8149 100644 --- a/libibverbs/cmd_flow_action.c +++ b/libibverbs/cmd_flow_action.c @@ -33,6 +33,7 @@ #include #include #include +#include static void scrub_esp_encap(struct ibv_flow_action_esp_encap *esp_encap) { @@ -120,9 +121,14 @@ int ibv_cmd_destroy_flow_action(struct verbs_flow_action *action) { DECLARE_COMMAND_BUFFER(cmd, UVERBS_OBJECT_FLOW_ACTION, UVERBS_METHOD_FLOW_ACTION_DESTROY, 1); + int ret; fill_attr_in_obj(cmd, UVERBS_ATTR_DESTROY_FLOW_ACTION_HANDLE, action->handle); - return execute_ioctl(action->action.context, cmd); + ret = execute_ioctl(action->action.context, cmd); + if (verbs_is_destroy_err(&ret)) + return ret; + + return 0; } diff --git a/libibverbs/libibverbs.map.in b/libibverbs/libibverbs.map.in index c6a65ad..80ef2a1 100644 --- a/libibverbs/libibverbs.map.in +++ b/libibverbs/libibverbs.map.in @@ -177,6 +177,7 @@ IBVERBS_PRIVATE_@IBVERBS_PABI_VERSION@ { ibv_cmd_resize_cq; ibv_query_gid_type; ibv_register_driver; + verbs_allow_disassociate_destroy; verbs_register_driver_@IBVERBS_PABI_VERSION@; verbs_set_ops; verbs_uninit_context; diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 25f0d5f..82efc4d 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -50,6 +50,7 @@ #include #include #include +#include #include "mlx5.h" #include "mlx5-abi.h" @@ -3606,6 +3607,7 @@ int mlx5dv_destroy_flow_matcher(struct mlx5dv_flow_matcher *flow_matcher) fill_attr_in_obj(cmd, MLX5_IB_ATTR_FLOW_MATCHER_DESTROY_HANDLE, flow_matcher->handle); ret = execute_ioctl(flow_matcher->context, cmd); + verbs_is_destroy_err(&ret); if (ret) return ret;