From patchwork Thu Nov 22 23:24:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694985 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 9AD2F1709 for ; Thu, 22 Nov 2018 23:24:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 896842C2F0 for ; Thu, 22 Nov 2018 23:24:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DFA52C3A2; Thu, 22 Nov 2018 23:24:27 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 52C042C3A1 for ; Thu, 22 Nov 2018 23:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407890AbeKWKGH (ORCPT ); Fri, 23 Nov 2018 05:06:07 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:46500 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407882AbeKWKGH (ORCPT ); Fri, 23 Nov 2018 05:06:07 -0500 Received: by mail-pg1-f194.google.com with SMTP id w7so2238652pgp.13 for ; Thu, 22 Nov 2018 15:24:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ylh9gXCdZaPjFtu8fiaaalb9lT+AuDBVy/XI8X6FTjw=; b=YEKwpc7DFpzbUcRoY0mwxzPe6xNq9izad52EBZq8vjyyldluXDPKQnGNqkHCo3L3Of Pm0HKI8oytBgB1K3x7+yHLBqfvsi32nW58Lgf9fVg1mpHsqyjEg5EFJC5yukSg2haENg hv68yC0FcRLIksORp6Wg2NoWtlRZDsv5SD8oCwGRK7eqJS1EyZRPXx87R1nlb2MmbuA0 jTgf5oINbJNt9Re011tSTTzrk/N77oqxyYTKEfvjjAgd4OAPEHW2NfinzpFroEx6dDt5 OS4cbwRRFyY2DDEiShr2HgepkD/vYWAKN4cRlUxJ8+H7rUibZUovJkXBtvLyT8gjJ1yK u7yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ylh9gXCdZaPjFtu8fiaaalb9lT+AuDBVy/XI8X6FTjw=; b=AF95ktK1oN1XLEsPBsRf++cEzLdyM31LBf5UhoIioMZhOOCS2v7G4/22AtPzGw64Bc mPBQEoGJKzl2Emm2Br9MtzE3WyNiGeqYAc0AcRYk5ABTCXg1KS0UPZ6cmUHWDh36z0hQ sI0n5uO6e5XP+dcqvJQOZpu6g8lF30f0cSSqj5H/9W/u4qYSx2Sn+hkvbo40e8ww3mld bh7auGuiHtrRBwZBKAX2hfPmSn5MRQxQUS5HLVCpfpH4xC9Cbz7DBbhf+8MKqSFAasFM anHbTe7Bs+oVF2LQ+6W7TCGhX5kBXQmoQwwT30syvNAiBr4Uwl2LQUUbBXyFtEi9lIVP j0VA== X-Gm-Message-State: AGRZ1gJp1fTb1WbIYG0UO+fVhfUXn1XsszruaNNXTs/Xahmu4Mh9a/jJ OJTCA5N0W7lfXLWHRGDIt7zpPo9JWcc= X-Google-Smtp-Source: AJdET5fM3D1kj6vNR6bflC7/FaU93MKsA7xKqH96cJZVJ0hwsz10bXigAWxSTTWK5Ob7FvtTleARQQ== X-Received: by 2002:a62:1043:: with SMTP id y64-v6mr13613581pfi.79.1542929063570; Thu, 22 Nov 2018 15:24:23 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id t4-v6sm53605078pfh.21.2018.11.22.15.24.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 22 Nov 2018 15:24:19 -0800 (PST) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1gPyKY-0007t5-IW; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 08/10] verbs: Replace execute_write with execute_cmd_write/_req Date: Thu, 22 Nov 2018 16:24:14 -0700 Message-Id: <20181122232416.30132-9-jgg@ziepe.ca> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122232416.30132-1-jgg@ziepe.ca> References: <20181122232416.30132-1-jgg@ziepe.ca> 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: Jason Gunthorpe The execute_write protocol can't pass the size of the core structures, so we need to replace it with the more general execute_cmd_write. This is generally a little simpler as it relies on less macro magic to make it work. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd.c | 79 +++++++++++++++++++++++++----------------- libibverbs/cmd_cq.c | 10 ++++-- libibverbs/cmd_write.h | 31 ----------------- libibverbs/verbs.c | 7 ++-- 4 files changed, 59 insertions(+), 68 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index d45082eea0cab3..4679ea673d2cba 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -328,13 +328,14 @@ 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); + struct ibv_dealloc_pd req; int ret; - *req = (struct ib_uverbs_dealloc_pd) { + req.core_payload = (struct ib_uverbs_dealloc_pd){ .pd_handle = pd->handle, }; - ret = execute_write(pd->context, req, NULL); + ret = execute_cmd_write_req(pd->context, IB_USER_VERBS_CMD_DEALLOC_PD, + &req, sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; @@ -375,13 +376,15 @@ 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); + struct ibv_close_xrcd req; int ret; - *req = (struct ib_uverbs_close_xrcd){ + req.core_payload = (struct ib_uverbs_close_xrcd){ .xrcd_handle = xrcd->handle, }; - ret = execute_write(xrcd->xrcd.context, req, NULL); + ret = execute_cmd_write_req(xrcd->xrcd.context, + IB_USER_VERBS_CMD_CLOSE_XRCD, &req, + sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; @@ -447,13 +450,15 @@ 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); + struct ibv_dereg_mr req; int ret; - *req = (struct ib_uverbs_dereg_mr){ + req.core_payload = (struct ib_uverbs_dereg_mr){ .mr_handle = vmr->ibv_mr.handle, }; - ret = execute_write(vmr->ibv_mr.context, req, NULL); + ret = execute_cmd_write_req(vmr->ibv_mr.context, + IB_USER_VERBS_CMD_DEREG_MR, &req, + sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; @@ -487,13 +492,14 @@ 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); + struct ibv_dealloc_mw req; int ret; - *req = (struct ib_uverbs_dealloc_mw) { + req.core_payload = (struct ib_uverbs_dealloc_mw) { .mw_handle = mw->handle, }; - ret = execute_write(mw->context, req, NULL); + ret = execute_cmd_write_req(mw->context, IB_USER_VERBS_CMD_DEALLOC_MW, + &req, sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; @@ -548,13 +554,15 @@ out: int ibv_cmd_req_notify_cq(struct ibv_cq *ibcq, int solicited_only) { - DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ); + struct ibv_req_notify_cq req; - *req = (struct ib_uverbs_req_notify_cq){ + req.core_payload = (struct ib_uverbs_req_notify_cq){ .cq_handle = ibcq->handle, .solicited_only = !!solicited_only, }; - return execute_write(ibcq->context, req, NULL); + return execute_cmd_write_req(ibcq->context, + IB_USER_VERBS_CMD_REQ_NOTIFY_CQ, &req, + sizeof(req)); } int ibv_cmd_resize_cq(struct ibv_cq *cq, int cqe, @@ -762,14 +770,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) { - DECLARE_LEGACY_CORE_BUFS(IB_USER_VERBS_CMD_DESTROY_SRQ); + struct ibv_destroy_srq req; + struct ib_uverbs_destroy_srq_resp resp; int ret; - *req = (struct ib_uverbs_destroy_srq){ + req.core_payload = (struct ib_uverbs_destroy_srq){ .srq_handle = srq->handle, }; - ret = execute_write(srq->context, req, &resp); + ret = execute_cmd_write(srq->context, IB_USER_VERBS_CMD_DESTROY_SRQ, + &req, sizeof(req), &resp, sizeof(resp)); if (verbs_is_destroy_err(&ret)) return ret; @@ -1521,13 +1531,14 @@ 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); + struct ibv_destroy_ah req; int ret; - *req = (struct ib_uverbs_destroy_ah){ + req.core_payload = (struct ib_uverbs_destroy_ah){ .ah_handle = ah->handle, }; - ret = execute_write(ah->context, req, NULL); + ret = execute_cmd_write_req(ah->context, IB_USER_VERBS_CMD_DESTROY_AH, + &req, sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; @@ -1536,14 +1547,16 @@ int ibv_cmd_destroy_ah(struct ibv_ah *ah) int ibv_cmd_destroy_qp(struct ibv_qp *qp) { - DECLARE_LEGACY_CORE_BUFS(IB_USER_VERBS_CMD_DESTROY_QP); + struct ibv_destroy_qp req; + struct ib_uverbs_destroy_qp_resp resp; int ret; - *req = (struct ib_uverbs_destroy_qp){ + req.core_payload = (struct ib_uverbs_destroy_qp){ .qp_handle = qp->handle, }; - ret = execute_write(qp->context, req, &resp); + ret = execute_cmd_write(qp->context, IB_USER_VERBS_CMD_DESTROY_QP, &req, + sizeof(req), &resp, sizeof(resp)); if (verbs_is_destroy_err(&ret)) return ret; @@ -1557,27 +1570,29 @@ 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) { - DECLARE_LEGACY_CORE_REQ(IB_USER_VERBS_CMD_ATTACH_MCAST); + struct ibv_attach_mcast req; - *req = (struct ib_uverbs_attach_mcast){ + req.core_payload = (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); + memcpy(req.gid, gid->raw, sizeof(req.gid)); + return execute_cmd_write_req( + qp->context, IB_USER_VERBS_CMD_ATTACH_MCAST, &req, sizeof(req)); } 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); + struct ibv_detach_mcast req; int ret; - *req = (struct ib_uverbs_detach_mcast){ + req.core_payload = (struct ib_uverbs_detach_mcast){ .qp_handle = qp->handle, .mlid = lid, }; - memcpy(req->gid, gid->raw, sizeof(req->gid)); - ret = execute_write(qp->context, req, NULL); + memcpy(req.gid, gid->raw, sizeof(req.gid)); + ret = execute_cmd_write_req(qp->context, IB_USER_VERBS_CMD_DETACH_MCAST, + &req, sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; diff --git a/libibverbs/cmd_cq.c b/libibverbs/cmd_cq.c index 3406115559aaa7..03e5ca4c5e13bf 100644 --- a/libibverbs/cmd_cq.c +++ b/libibverbs/cmd_cq.c @@ -158,7 +158,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(IB_USER_VERBS_CMD_DESTROY_CQ); + struct ib_uverbs_destroy_cq_resp resp; int ret; fill_attr_out_ptr(cmdb, UVERBS_ATTR_DESTROY_CQ_RESP, &resp); @@ -166,11 +166,15 @@ int ibv_cmd_destroy_cq(struct ibv_cq *cq) switch (execute_ioctl_fallback(cq->context, destroy_cq, cmdb, &ret)) { case TRY_WRITE: { - *req = (struct ib_uverbs_destroy_cq){ + struct ibv_destroy_cq req; + + req.core_payload = (struct ib_uverbs_destroy_cq){ .cq_handle = cq->handle, }; - ret = execute_write(cq->context, req, &resp); + ret = execute_cmd_write(cq->context, + IB_USER_VERBS_CMD_DESTROY_CQ, &req, + sizeof(req), &resp, sizeof(resp)); break; } diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index 2a3c50aa62015c..a585b4acd660ad 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -158,28 +158,6 @@ int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *req); _execute_write_raw_ex(ctx, get_req_hdr_ex(req)) /* For users with no possible UHW bufs. */ -#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; \ @@ -202,8 +180,6 @@ int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *req); * DECLARE_LEGACY_CORE_BUFS. req points to the core payload (with headroom for * the header). */ -#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)) @@ -325,13 +301,6 @@ static inline int execute_write_bufs_ex(struct ibv_context *ctx, void *req) return ENOSYS; } -#undef execute_write -static inline int execute_write(struct ibv_context *ctx, void *req, - void *resp) -{ - return ENOSYS; -} - #endif #if VERBS_WRITE_ONLY diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c index 9121e2d342560c..5edd1bbea413f3 100644 --- a/libibverbs/verbs.c +++ b/libibverbs/verbs.c @@ -342,14 +342,17 @@ LATEST_SYMVER_FUNC(ibv_dereg_mr, 1_1, "IBVERBS_1.1", struct ibv_comp_channel *ibv_create_comp_channel(struct ibv_context *context) { - DECLARE_LEGACY_CORE_BUFS(IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL); + struct ibv_create_comp_channel req; + struct ib_uverbs_create_comp_channel_resp resp; struct ibv_comp_channel *channel; channel = malloc(sizeof *channel); if (!channel) return NULL; - if (execute_write(context, req, &resp)) { + req.core_payload = (struct ib_uverbs_create_comp_channel){}; + if (execute_cmd_write(context, IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL, + &req, sizeof(req), &resp, sizeof(resp))) { free(channel); return NULL; }