From patchwork Thu Nov 22 23:24:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694973 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 0DFEE13B5 for ; Thu, 22 Nov 2018 23:24:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F081C2BF0F for ; Thu, 22 Nov 2018 23:24:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E47832C2F0; Thu, 22 Nov 2018 23:24:22 +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 91C612BF0F for ; Thu, 22 Nov 2018 23:24:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407877AbeKWKGD (ORCPT ); Fri, 23 Nov 2018 05:06:03 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:46500 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389637AbeKWKGD (ORCPT ); Fri, 23 Nov 2018 05:06:03 -0500 Received: by mail-pl1-f194.google.com with SMTP id t13so9786678ply.13 for ; Thu, 22 Nov 2018 15:24:21 -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=BZQr5HeVODM40YLLTiCLxuWMnX3brO18XbPQTTqt4ME=; b=ZvJMN95Np6vYXz4ZKumaX2eyf+dNIqPO4A4Ho3ye4VkmHFfDrMt2GKYFevIXon7bjr KYafoqdm0/+F3fD7xNdI6kpKaKx9CX0zMJw1MoYIe1RT8A9NM2QJp8K77bzNnrBhHzo/ OYH2VdBKUEpDa3hHNJlXZc+DiqJndQxfYxve/DMV8htUMlmj95KjRefeCAwWnxS0oUW3 lQzU0gzUEnygGI8pd8PmgfNK3Ng4nUeeIGaAVWPpCB5IFcXMCFbgLU0XJnNwT5c4AhgD 3oGzJvc7I3sXCkgX+E6Mopgj7B0GCx2hnDSTv01FLGAOZgFZajncet3bUTTbVGzhxva6 znig== 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=BZQr5HeVODM40YLLTiCLxuWMnX3brO18XbPQTTqt4ME=; b=acVfPshwXyqt2o3qUJd3MEvNz5X/ZP9cWebatu/BOtPnQnRMe8dPyeDWEkEpTfFx64 OqexHR9otcdYUY0vTPLike4Zgc86Wsu8eQg1LMNM5r2+JZeJg01Dlpg39/4wBMRlSBed pIof0MyCETOXz9ktEK9XNwWn91JT4MojCD175ShSPhWYdw4yRH845+au/YXMGVElVVTf CNDibOfoswPyMg9n5TF0S/Lu+wvm0TUTpeLSnPqUTa8vRroh6xl0+76cQ/evmbs7OlWe cuJmxsewMsRj7UrKImECIZFqIb7HciwhIJXP8y4gyk3iIC0Mxub36F/GGFk1JdgM63pl 9dMg== X-Gm-Message-State: AA+aEWaCdgE4PHpLw1H/IENrdzLKNW9MXe/6sUl+C1w5Xw4bo959TVNc sIwgPgcfqk7CAxBriVKyujUEBd2Ul7g= X-Google-Smtp-Source: AFSGD/Vk+xLxWeXU2pIEODXIG1xZTCinq6vwj+P62vkY1rqXNcyPsrZKemjt7daSBQX11yWB8qrDdA== X-Received: by 2002:a17:902:50e:: with SMTP id 14mr5081221plf.141.1542929060428; Thu, 22 Nov 2018 15:24:20 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id j6sm23388921pfg.126.2018.11.22.15.24.18 (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-0007sK-99; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 01/10] verbs: Fix wrong command structure usage Date: Thu, 22 Nov 2018 16:24:07 -0700 Message-Id: <20181122232416.30132-2-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 Several places were using the wrong command buffer type for the command being executed. It turns out none of these are bugs since both structs have identical members and layouts, but it causes the type checking in later patches to get angry. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index d88b3aa816eac4..af6ea5cfe12a0f 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -1425,7 +1425,7 @@ int ibv_cmd_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr, struct ibv_recv_wr **bad_wr) { struct ibv_post_recv *cmd; - struct ib_uverbs_post_send_resp resp; + struct ib_uverbs_post_recv_resp resp; struct ibv_recv_wr *i; struct ib_uverbs_recv_wr *n, *tmp; struct ibv_sge *s; @@ -1486,7 +1486,7 @@ int ibv_cmd_post_srq_recv(struct ibv_srq *srq, struct ibv_recv_wr *wr, struct ibv_recv_wr **bad_wr) { struct ibv_post_srq_recv *cmd; - struct ib_uverbs_post_recv_resp resp; + struct ib_uverbs_post_srq_recv_resp resp; struct ibv_recv_wr *i; struct ib_uverbs_recv_wr *n, *tmp; struct ibv_sge *s; @@ -1841,7 +1841,7 @@ int ibv_cmd_create_flow(struct ibv_qp *qp, size_t ucmd_size) { struct ibv_create_flow *cmd; - struct ib_uverbs_destroy_flow resp; + struct ib_uverbs_create_flow_resp resp; size_t cmd_size; size_t written_size; int i, err; From patchwork Thu Nov 22 23:24:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694979 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 1A80D1709 for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B39C2BF0F for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F41802C3A6; Thu, 22 Nov 2018 23:24:24 +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 9F4272C196 for ; Thu, 22 Nov 2018 23:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389637AbeKWKGF (ORCPT ); Fri, 23 Nov 2018 05:06:05 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:34137 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407881AbeKWKGF (ORCPT ); Fri, 23 Nov 2018 05:06:05 -0500 Received: by mail-pl1-f194.google.com with SMTP id f12-v6so9804388plo.1 for ; Thu, 22 Nov 2018 15:24:22 -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=QQikufbD0iOr/0/ZUuc7CKm9Xm0Jpny4Z1c4eIngpSc=; b=ABD0FeS9B+vVMlRNqWPkLWqXHqFgaCoZHRl87NrBODBSJw3ExIi+0AXTFCmkJvz3BV kuKpZ7i24tsdub1jG/fkIgtznUuChUq2Z/yHUKWGDktpLZJrzNDSeMgsqsmZaooEI0Kq G5p8G7P6IeWABiS+RpdhK43+S39I2bhxoYTROARZ0ABXqS17islo3iFJDHLNVXblpT/z QdjKO2LnGmNU1yG0s8bf0Qc40mdNX/XbxIbk3qRArvNUZVezrrPvNZHvEj51HeIlO7la ZPlrLQRWCmX4lwCO3VFXzXDls2XUmxCyGR9ZnQ0jI88XUEHXv3Pjpc/4qKNRqGnZIxL+ 7bzg== 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=QQikufbD0iOr/0/ZUuc7CKm9Xm0Jpny4Z1c4eIngpSc=; b=QmHvSpaEvFQ9/dbUyQyeOvkpltD0crehI2uUq1+weDdqSLtvizLIGutQ+nr7lFIwEt g/5IOv9TXPSqXUwgt9wpmtAAXTuGtrz9hcEp7x5IYx6Ij0Jy3jBtK1jtMszBYF1lU+jE qbbooP9j3vJ/s3ZESnGJponsk98RzgL47usirbIil52vhCZYSK7ema1MQvDMmXqzudAi KxMMkLw7ikCV4Fo27ufbJGuKwNprmdhweaVDBKInGFI9TSCawj1tvrCDvF2PqdPt5r6S uWMIMJm58It4Hj8G3Cy71dDEViU88G4zoL6gwOUkva/e0w9zsYWtXMDIRJYLrp9ssFB5 HMVw== X-Gm-Message-State: AA+aEWZEGFYrcFLC86FpvLFhUdfs1cRJyRU96y0vEnPiKihr/1+A0c+v liXaDCfRT8A/BRgaUTBYSllF6bghtJI= X-Google-Smtp-Source: AFSGD/X0wBP09YLA87vObK54tN6GGN+3YDHlvGjJufYjZnWuan+K+PVWMINF2NODGdOsmK//t0zccA== X-Received: by 2002:a17:902:6907:: with SMTP id j7mr12702358plk.221.1542929062202; Thu, 22 Nov 2018 15:24:22 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id z14sm39126680pgv.47.2018.11.22.15.24.18 (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-0007sR-AM; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 02/10] verbs: Add explicit arguments to DECLARE_CMD_BUFFER_COMPAT() Date: Thu, 22 Nov 2018 16:24:08 -0700 Message-Id: <20181122232416.30132-3-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 It is hard to read when this macro implicitly reaches into the argument list to get the parameters. Type them again.. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd_cq.c | 8 ++++++-- libibverbs/cmd_write.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libibverbs/cmd_cq.c b/libibverbs/cmd_cq.c index 766951888e9f99..3406115559aaa7 100644 --- a/libibverbs/cmd_cq.c +++ b/libibverbs/cmd_cq.c @@ -119,7 +119,9 @@ int ibv_cmd_create_cq(struct ibv_context *context, int cqe, size_t cmd_size, struct ib_uverbs_create_cq_resp *resp, size_t resp_size) { - DECLARE_CMD_BUFFER_COMPAT(cmdb, UVERBS_OBJECT_CQ, UVERBS_METHOD_CQ_CREATE); + DECLARE_CMD_BUFFER_COMPAT(cmdb, UVERBS_OBJECT_CQ, + UVERBS_METHOD_CQ_CREATE, cmd, cmd_size, resp, + resp_size); return ibv_icmd_create_cq(context, cqe, channel, comp_vector, 0, cq, cmdb); @@ -133,7 +135,9 @@ int ibv_cmd_create_cq_ex(struct ibv_context *context, struct ib_uverbs_ex_create_cq_resp *resp, size_t resp_size) { - DECLARE_CMD_BUFFER_COMPAT(cmdb, UVERBS_OBJECT_CQ, UVERBS_METHOD_CQ_CREATE); + DECLARE_CMD_BUFFER_COMPAT(cmdb, UVERBS_OBJECT_CQ, + UVERBS_METHOD_CQ_CREATE, cmd, cmd_size, resp, + resp_size); uint32_t flags = 0; if (!check_comp_mask(cq_attr->comp_mask, IBV_CQ_INIT_ATTR_MASK_FLAGS)) diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index 6ee4f30813bb67..98aa58a26d6728 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -98,7 +98,8 @@ void *_write_get_resp_ex(struct ibv_command_buffer *link, void _write_set_uhw(struct ibv_command_buffer *cmdb, const void *req, size_t core_req_size, size_t req_size, void *resp, size_t core_resp_size, size_t resp_size); -#define DECLARE_CMD_BUFFER_COMPAT(_name, _object_id, _method_id) \ +#define DECLARE_CMD_BUFFER_COMPAT(_name, _object_id, _method_id, cmd, \ + cmd_size, resp, resp_size) \ DECLARE_COMMAND_BUFFER(_name, _object_id, _method_id, 2); \ _write_set_uhw(_name, cmd, sizeof(*cmd), cmd_size, resp, \ sizeof(*resp), resp_size) From patchwork Thu Nov 22 23:24:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694981 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 AE44513B5 for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EAF32BF0F for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9318A2C3A1; Thu, 22 Nov 2018 23:24:25 +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 3FEBF2BF0F for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407886AbeKWKGG (ORCPT ); Fri, 23 Nov 2018 05:06:06 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37923 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407882AbeKWKGF (ORCPT ); Fri, 23 Nov 2018 05:06:05 -0500 Received: by mail-pl1-f196.google.com with SMTP id e5so9790208plb.5 for ; Thu, 22 Nov 2018 15:24:23 -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=SPHKZbTHoqaAH/sy5JoX737zYXFvGU00VKKOiu6FWyg=; b=WEsp8SdXT3qVaYj2+iJOaBc9bgYo6/ng+JFowXXyaoJ/glVd1Isgnx/Z/nRonBm238 H/2JwuAIjqQH9X7x6yit4xVIWBKw3qfD1s3ZuBFrSdkZ4bcCTAzauljecGjVWA9fAvE1 yMikD9O1DFl90YP1bW0lAuRNg2zdAdwCpTlRHVX9HaDPExOBLiNmBsIKDaP72N9c5glY hEo1dFtmfyLOy9s0E7d7cp7dehuPVVfaNeRiR4e/Px8/eHQd20VdG0u+6ZiiU0c7dWXB USy5K4ZBchN5PZ00HoAiW5ey3p06hCz+f82xruMAdHHm65QcbSMTsW1pG7oNZglFr8bI nitw== 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=SPHKZbTHoqaAH/sy5JoX737zYXFvGU00VKKOiu6FWyg=; b=GdVXrTm1/eJ/JnmIvFUkZkwLvohM4INzmf+UILf7hJJiKqatPqR8E4D7tXtpkOo9YD 8d5YSck0ur1sOrO4dr57VS8c7kMxucHI+VftYVIsPRphI5CtT6rLf0bo/nRxccoHSkXA SpEZvPhdyBIXhU86vMT946O8IOzNbLgN7NkYwthx/ARBaNhNvhCF5uvZyw7genba7kOy d+Th0b5eta684pGqNnypsDEamNAuRGmyhezIni2Be98Br4b38XxvhNie4jxgviO2UXll W/VmZCHEGIKoqxc3zZeu4iCozQ8KQsLOAsC23RZ/mxI10wehlG4GWVyoYfJzi4vjFDVM CuXQ== X-Gm-Message-State: AA+aEWYY0fDVh3fg6It4KuyEryQJPC0Qv4GMby0xW1HzxEFooPBYSz+E 0jV0HYHP8NWILrJ83QcPnLE2v2vBorA= X-Google-Smtp-Source: AFSGD/X8sFNPLCCxG5A8tqhdwcEXOfTQmX7ZPMshJvUV/m0J86WuF43tOUHs0JpDoxuzXioIojd3Jg== X-Received: by 2002:a17:902:b78b:: with SMTP id e11mr13213131pls.90.1542929062555; Thu, 22 Nov 2018 15:24:22 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id p9-v6sm56859210pfa.22.2018.11.22.15.24.18 (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-0007sZ-BZ; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 03/10] verbs: Move ibv_create_comp_channel to use execute_write Date: Thu, 22 Nov 2018 16:24:09 -0700 Message-Id: <20181122232416.30132-4-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 This was missed in commit 2eeecc77cdbc ("verbs: Convert write path callers to use DECLARE_LEGACY_CORE_BUFS") as it was not in cmd.c. Signed-off-by: Jason Gunthorpe --- libibverbs/verbs.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c index 37a458a2e6ccc7..9121e2d342560c 100644 --- a/libibverbs/verbs.c +++ b/libibverbs/verbs.c @@ -46,6 +46,7 @@ #include #include +#include #include "ibverbs.h" #ifndef NRESOLVE_NEIGH @@ -341,22 +342,18 @@ 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_comp_channel *channel; - struct ibv_create_comp_channel cmd; - struct ib_uverbs_create_comp_channel_resp resp; channel = malloc(sizeof *channel); if (!channel) return NULL; - IBV_INIT_CMD_RESP(&cmd, sizeof cmd, CREATE_COMP_CHANNEL, &resp, sizeof resp); - if (write(context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) { + if (execute_write(context, req, &resp)) { free(channel); return NULL; } - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); - channel->context = context; channel->fd = resp.fd; channel->refcnt = 0; From patchwork Thu Nov 22 23:24:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694983 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 5791013B5 for ; Thu, 22 Nov 2018 23:24:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45D6F2BF0F for ; Thu, 22 Nov 2018 23:24:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A3D22C2F0; Thu, 22 Nov 2018 23:24:26 +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 8F2FD2C196 for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407888AbeKWKGH (ORCPT ); Fri, 23 Nov 2018 05:06:07 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43949 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407881AbeKWKGG (ORCPT ); Fri, 23 Nov 2018 05:06:06 -0500 Received: by mail-pl1-f194.google.com with SMTP id gn14so9796612plb.10 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=RNaGLromelH47v92nmEft8tiB2pV5fewesSVDn0Bmb4=; b=QhFL58JGNHi4P9f/Z/QZJqjXrCL9oE8Cr1GblHbx5b6EKhZ3nWppYGiH4msAWUWE8k Zoayt5CFHXI7MKl4jIckpwNKVljGv2mrwx5sRNbHvHBddZneoLEpnWLunDwGmc3xqJST Iv1YaB12xaWBVomERpLTrh1N4+aI5pvF9GCh7RXGyE3rLud8mfxcb0MmGXQbqdFpZCpp sSTK4KOZigzoiDXBt/fhdaCfCeQJrg+kvo0Xq912qES1PsXA8e2m6dkf+wxFZm7VPXaA rvNLQuEH7h9UT5WOn0gaQkflE0Lt8rIhfyENI4Bk7vfEAI+uOjowRkLEQsVKOgmsBGks qdLA== 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=RNaGLromelH47v92nmEft8tiB2pV5fewesSVDn0Bmb4=; b=Y5c43MMV58fxXs8t1KO8ZoYSJS2KbdcVPvxnbUHnMk/M5O1FOqZwg4wJMyAGbRZnbH 0JT5sJr84gRYoUxkGuhM4xjFEkz2WDfhCqJw4BJO+LGioj7zaZDQiqrwxtwLLTXY6qhT BoqM8paz4EH1lwR9wMd6Ll6zYNmSkwfExOngJkRzp7P/xIpfQTsEcfaOrf0v1N4nSto1 rLNnNPx7qYKsIzbKgyacGx1uor6v/Feetb4+kDLmDsHGvt+iByKunw0p0+E4Vywa159G avlgMVZKiKGzisrraSGuWuFzc3g7wXNfUwK34pQ0WS2GP2PWiXlcvXhFSNkGiyM/dsQT 5WaA== X-Gm-Message-State: AA+aEWa5iJDYPh01J31jz1UPcqIOcm9qFIjwmVx5zutmdoE9EeVlfxgn P1js9v2wYStBMSgjPBR8BsmO/VG8tsI= X-Google-Smtp-Source: AFSGD/WmRHBW6hafmmwvKcuMpvSbJwGRVnbR9ER5hErh/vsvNg5ajYiP45xdWTRV6ZRXrwkN1RKzGg== X-Received: by 2002:a17:902:b118:: with SMTP id q24mr13286718plr.209.1542929063160; 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 v15sm36858094pfn.94.2018.11.22.15.24.18 (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-0007sh-Ck; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 04/10] verbs: Consolidate duplicate code in create_rwq_ind_table Date: Thu, 22 Nov 2018 16:24:10 -0700 Message-Id: <20181122232416.30132-5-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 usual pattern for an _ex API with a core flex array is to have the core code allocate the variable length command buffer and memcpy the udata into the end of it. Tidy this up to follow the usual pattern. Since no drivers have udata here don't bother passing anything from the driver. Also update the PABI to v22. Signed-off-by: Jason Gunthorpe --- CMakeLists.txt | 3 ++- debian/control | 2 +- debian/libibverbs1.symbols | 2 +- libibverbs/cmd.c | 33 +++++++++++++-------------------- libibverbs/driver.h | 4 ---- providers/mlx4/verbs.c | 25 +++---------------------- providers/mlx5/verbs.c | 24 +++--------------------- 7 files changed, 23 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ca5d49d7301cd2..09cf3a123feb48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,8 +59,9 @@ set(PACKAGE_NAME "RDMA") # See Documentation/versioning.md set(PACKAGE_VERSION "22.0") # When this is changed the values in these files need changing too: +# debian/control # debian/libibverbs1.symbols -set(IBVERBS_PABI_VERSION "21") +set(IBVERBS_PABI_VERSION "22") set(IBVERBS_PROVIDER_SUFFIX "-rdmav${IBVERBS_PABI_VERSION}.so") #------------------------- diff --git a/debian/control b/debian/control index 92888f9aeb2cab..4debe4e961e812 100644 --- a/debian/control +++ b/debian/control @@ -151,7 +151,7 @@ Section: libs Pre-Depends: ${misc:Pre-Depends} Depends: adduser, ${misc:Depends}, ${shlibs:Depends} Recommends: ibverbs-providers -Breaks: ibverbs-providers (<< 21~) +Breaks: ibverbs-providers (<< 22~) Description: Library for direct userspace use of RDMA (InfiniBand/iWARP) libibverbs is a library that allows userspace processes to use RDMA "verbs" as described in the InfiniBand Architecture Specification and diff --git a/debian/libibverbs1.symbols b/debian/libibverbs1.symbols index 643435ad146097..774862e63751ae 100644 --- a/debian/libibverbs1.symbols +++ b/debian/libibverbs1.symbols @@ -3,7 +3,7 @@ libibverbs.so.1 libibverbs1 #MINVER# IBVERBS_1.0@IBVERBS_1.0 1.1.6 IBVERBS_1.1@IBVERBS_1.1 1.1.6 IBVERBS_1.5@IBVERBS_1.5 20 - (symver)IBVERBS_PRIVATE_21 21 + (symver)IBVERBS_PRIVATE_22 22 ibv_ack_async_event@IBVERBS_1.0 1.1.6 ibv_ack_async_event@IBVERBS_1.1 1.1.6 ibv_ack_cq_events@IBVERBS_1.0 1.1.6 diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index af6ea5cfe12a0f..d485b934a63818 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -2028,38 +2028,31 @@ int ibv_cmd_destroy_wq(struct ibv_wq *wq) int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, struct ibv_rwq_ind_table_init_attr *init_attr, struct ibv_rwq_ind_table *rwq_ind_table, - struct ibv_create_rwq_ind_table *cmd, - size_t cmd_core_size, - size_t cmd_size, struct ib_uverbs_ex_create_rwq_ind_table_resp *resp, - size_t resp_core_size, size_t resp_size) { - int err, i; - uint32_t required_tbl_size, alloc_tbl_size; - uint32_t *tbl_start; - int num_tbl_entries; + struct ibv_create_rwq_ind_table *cmd; + int err; + unsigned int i; + unsigned int num_tbl_entries; + size_t cmd_size; if (init_attr->comp_mask >= IBV_CREATE_IND_TABLE_RESERVED) return EINVAL; - alloc_tbl_size = cmd_core_size - sizeof(*cmd); num_tbl_entries = 1 << init_attr->log_ind_tbl_size; - /* Data must be u64 aligned */ - required_tbl_size = (num_tbl_entries * sizeof(uint32_t)) < sizeof(uint64_t) ? - sizeof(uint64_t) : (num_tbl_entries * sizeof(uint32_t)); - - if (alloc_tbl_size < required_tbl_size) - return EINVAL; + /* The entire message must be size aligned to 8 bytes. */ + cmd_size = sizeof(*cmd) + num_tbl_entries * sizeof(cmd->wq_handles[0]); + cmd_size = (cmd_size + 7) / 8 * 8; + cmd = alloca(cmd_size); - tbl_start = (uint32_t *)((uint8_t *)cmd + sizeof(*cmd)); for (i = 0; i < num_tbl_entries; i++) - tbl_start[i] = init_attr->ind_tbl[i]->handle; + cmd->wq_handles[i] = init_attr->ind_tbl[i]->handle; - IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size, + IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, cmd_size, CREATE_RWQ_IND_TBL, resp, - resp_core_size, resp_size); + sizeof(*resp), resp_size); cmd->log_ind_tbl_size = init_attr->log_ind_tbl_size; cmd->comp_mask = 0; @@ -2069,7 +2062,7 @@ int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); - if (resp->response_length < resp_core_size) + if (resp->response_length < sizeof(*resp)) return EINVAL; rwq_ind_table->ind_tbl_handle = resp->ind_tbl_handle; diff --git a/libibverbs/driver.h b/libibverbs/driver.h index adf46c39e87112..cc879fb61335c7 100644 --- a/libibverbs/driver.h +++ b/libibverbs/driver.h @@ -562,11 +562,7 @@ int ibv_cmd_destroy_wq(struct ibv_wq *wq); int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, struct ibv_rwq_ind_table_init_attr *init_attr, struct ibv_rwq_ind_table *rwq_ind_table, - struct ibv_create_rwq_ind_table *cmd, - size_t cmd_core_size, - size_t cmd_size, struct ib_uverbs_ex_create_rwq_ind_table_resp *resp, - size_t resp_core_size, size_t resp_size); int ibv_cmd_destroy_rwq_ind_table(struct ibv_rwq_ind_table *rwq_ind_table); int ibv_cmd_create_counters(struct ibv_context *context, diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c index 5b32bd5635ee1f..a88454e405c717 100644 --- a/providers/mlx4/verbs.c +++ b/providers/mlx4/verbs.c @@ -1613,42 +1613,23 @@ int mlx4_destroy_wq(struct ibv_wq *ibwq) struct ibv_rwq_ind_table *mlx4_create_rwq_ind_table(struct ibv_context *context, struct ibv_rwq_ind_table_init_attr *init_attr) { - struct ibv_create_rwq_ind_table *cmd; struct ib_uverbs_ex_create_rwq_ind_table_resp resp = {}; struct ibv_rwq_ind_table *ind_table; - uint32_t required_tbl_size; - unsigned int num_tbl_entries; - int cmd_size; int err; - num_tbl_entries = 1 << init_attr->log_ind_tbl_size; - /* Data must be u64 aligned */ - required_tbl_size = - (num_tbl_entries * sizeof(uint32_t)) < sizeof(uint64_t) ? - sizeof(uint64_t) : (num_tbl_entries * sizeof(uint32_t)); - - cmd_size = required_tbl_size + sizeof(*cmd); - cmd = calloc(1, cmd_size); - if (!cmd) - return NULL; - ind_table = calloc(1, sizeof(*ind_table)); if (!ind_table) - goto free_cmd; + return NULL; - err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table, cmd, - cmd_size, cmd_size, &resp, - sizeof(resp), sizeof(resp)); + err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table, &resp, + sizeof(resp)); if (err) goto err; - free(cmd); return ind_table; err: free(ind_table); -free_cmd: - free(cmd); return NULL; } diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 46ab8a8935ea70..22a3b9ff23c98c 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -3258,42 +3258,24 @@ int mlx5_destroy_flow(struct ibv_flow *flow_id) struct ibv_rwq_ind_table *mlx5_create_rwq_ind_table(struct ibv_context *context, struct ibv_rwq_ind_table_init_attr *init_attr) { - struct ibv_create_rwq_ind_table *cmd; struct mlx5_create_rwq_ind_table_resp resp; struct ibv_rwq_ind_table *ind_table; - uint32_t required_tbl_size; - int num_tbl_entries; - int cmd_size; int err; - num_tbl_entries = 1 << init_attr->log_ind_tbl_size; - /* Data must be u64 aligned */ - required_tbl_size = (num_tbl_entries * sizeof(uint32_t)) < sizeof(uint64_t) ? - sizeof(uint64_t) : (num_tbl_entries * sizeof(uint32_t)); - - cmd_size = required_tbl_size + sizeof(*cmd); - cmd = calloc(1, cmd_size); - if (!cmd) - return NULL; - memset(&resp, 0, sizeof(resp)); ind_table = calloc(1, sizeof(*ind_table)); if (!ind_table) - goto free_cmd; + return NULL; - err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table, cmd, - cmd_size, cmd_size, &resp.ibv_resp, sizeof(resp.ibv_resp), - sizeof(resp)); + err = ibv_cmd_create_rwq_ind_table(context, init_attr, ind_table, + &resp.ibv_resp, sizeof(resp)); if (err) goto err; - free(cmd); return ind_table; err: free(ind_table); -free_cmd: - free(cmd); return NULL; } From patchwork Thu Nov 22 23:24:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694989 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 C58EF13B5 for ; Thu, 22 Nov 2018 23:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2F562C196 for ; Thu, 22 Nov 2018 23:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A74682C3A1; Thu, 22 Nov 2018 23:24:28 +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 4CA0C2C196 for ; Thu, 22 Nov 2018 23:24:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439018AbeKWKGI (ORCPT ); Fri, 23 Nov 2018 05:06:08 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44181 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407889AbeKWKGI (ORCPT ); Fri, 23 Nov 2018 05:06:08 -0500 Received: by mail-pl1-f193.google.com with SMTP id s5-v6so9787239plq.11 for ; Thu, 22 Nov 2018 15:24:25 -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=GC39Uc7P3gi/7p1CcD37cNNGJJnALDeGhpvP20OXJ10=; b=Kdvte6tL3jMSNczSEa88TX7MTSQOzo/Iuy1sJajJ3Dj0gu9n2Vo6K+tc4JwFPvY1h2 y0NCvDTIcTtXpHCzDC2h0mxRLjbTnZCSEx47pj/g5wcGaPVmOdjHDudsB7d4H6FNcUjN BRQlKPpAZDQ0WKQkGgGzTx+DJSEBy4QRBa9nntuHeduGQdiE88N8tmlwePzsicb0n942 KsxRhIGLAejrg7uS3lZu3Dg0h4Kz+Egs0UBJsB5Mm5M+NmpdrvvBZKYTW+dJ1EcEURKU QWls9JLTc67JtnyyseR9Lnnpy3o3XdQ+zrFDUFth6iFvqvHREcZ5amTWGatzrV3NZbcB cJVw== 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=GC39Uc7P3gi/7p1CcD37cNNGJJnALDeGhpvP20OXJ10=; b=De6yzQVPRQevGz3bhy7BJiZIMNIRt8DTMUN1Ko9lerZ/u5Gx6LR7yEGm7AQZdW/nFI KUvMKFzH0hScnuMXh4JJu2prig9w8AvZV57mwYl7AZtREtGGtFzfXfhavoGKvEFk2n1r mnYO09F9aqSL6OBlguIN+n9ylt0m+IvIcRU2nboVQ1OSXXaov5Xn7fDbixGXkpBjspbp qiugN4fLRxtki5bK1Il38Lw8G2aYq+LakkKEhvjhpHF5eFCoLwvcJJND9Y/t2Tf1TYUY NH7mttqcQuqWiX0+U+l3/Iwb6pcjGxxE3biBfiWqe9Hv2Yvffnckf8HqrL2VCHAEStLt o9Hw== X-Gm-Message-State: AA+aEWZQdMemTuO1nDOr3avnmyDMHAn7CSsq5g3pnPrnne20B+oQPib+ aY6n6gEoW2E2B2599SvJ1zLkG/4V+6s= X-Google-Smtp-Source: AFSGD/WNp6Us8de/NWwdwfRss2cJl80QjRNeLKS5RIw/fFpwYIczIMeoX/1POr7yC6yUuXwbTc3oAg== X-Received: by 2002:a17:902:541:: with SMTP id 59mr5062699plf.88.1542929064326; Thu, 22 Nov 2018 15:24:24 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id b27sm48210842pfh.113.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-0007sn-E3; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 05/10] verbs: Replace IBV_INIT_CMD_RESP() with execute_cmd_write Date: Thu, 22 Nov 2018 16:24:11 -0700 Message-Id: <20181122232416.30132-6-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 Replace the entire IBV_INIT_CMD_RESP(); write(); VALGRIND_MAKE_MEM_DEFINED(); Sequence with a single function call. This signature has enough information for the execute call to compute the location of all 5 components of a write command. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd.c | 214 ++++++++++++++++++-------------------- libibverbs/cmd_fallback.c | 17 +++ libibverbs/cmd_write.h | 38 +++++++ libibverbs/ibverbs.h | 8 -- 4 files changed, 158 insertions(+), 119 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index d485b934a63818..8123aae1ad89b8 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -51,12 +51,13 @@ 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) { - IBV_INIT_CMD_RESP(cmd, cmd_size, GET_CONTEXT, resp, resp_size); - - if (write(context_ex->context.cmd_fd, cmd, cmd_size) != cmd_size) - return errno; + int ret; - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(&context_ex->context, + IB_USER_VERBS_CMD_GET_CONTEXT, cmd, cmd_size, + resp, resp_size); + if (ret) + return ret; context_ex->context.async_fd = resp->async_fd; context_ex->context.num_comp_vectors = resp->num_comp_vectors; @@ -116,13 +117,12 @@ int ibv_cmd_query_device(struct ibv_context *context, struct ibv_query_device *cmd, size_t cmd_size) { struct ib_uverbs_query_device_resp resp; + int ret; - IBV_INIT_CMD_RESP(cmd, cmd_size, QUERY_DEVICE, &resp, sizeof resp); - - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_cmd_write(context, IB_USER_VERBS_CMD_QUERY_DEVICE, cmd, + cmd_size, &resp, sizeof(resp)); + if (ret) + return ret; memset(device_attr->fw_ver, 0, sizeof device_attr->fw_ver); copy_query_dev_fields(device_attr, &resp, raw_fw_ver); @@ -282,16 +282,16 @@ int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num, struct ibv_query_port *cmd, size_t cmd_size) { struct ib_uverbs_query_port_resp resp; + int ret; - IBV_INIT_CMD_RESP(cmd, cmd_size, QUERY_PORT, &resp, sizeof resp); cmd->port_num = port_num; memset(cmd->reserved, 0, sizeof cmd->reserved); memset(&resp, 0, sizeof(resp)); - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_cmd_write(context, IB_USER_VERBS_CMD_QUERY_PORT, cmd, + cmd_size, &resp, sizeof(resp)); + if (ret) + return ret; port_attr->state = resp.state; port_attr->max_mtu = resp.max_mtu; @@ -322,12 +322,12 @@ int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd, struct ibv_alloc_pd *cmd, size_t cmd_size, struct ib_uverbs_alloc_pd_resp *resp, size_t resp_size) { - IBV_INIT_CMD_RESP(cmd, cmd_size, ALLOC_PD, resp, resp_size); - - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; + int ret; - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(context, IB_USER_VERBS_CMD_ALLOC_PD, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; pd->handle = resp->pd_handle; pd->context = context; @@ -356,7 +356,7 @@ int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, struct ibv_open_xrcd *cmd, size_t cmd_size, struct ib_uverbs_open_xrcd_resp *resp, size_t resp_size) { - IBV_INIT_CMD_RESP(cmd, cmd_size, OPEN_XRCD, resp, resp_size); + int ret; if (attr->comp_mask >= IBV_XRCD_INIT_ATTR_RESERVED) return ENOSYS; @@ -367,10 +367,10 @@ int ibv_cmd_open_xrcd(struct ibv_context *context, struct verbs_xrcd *xrcd, cmd->fd = attr->fd; cmd->oflags = attr->oflags; - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(context, IB_USER_VERBS_CMD_OPEN_XRCD, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; xrcd->xrcd.context = context; xrcd->comp_mask = 0; @@ -403,8 +403,7 @@ int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, size_t cmd_size, struct ib_uverbs_reg_mr_resp *resp, size_t resp_size) { - - IBV_INIT_CMD_RESP(cmd, cmd_size, REG_MR, resp, resp_size); + int ret; cmd->start = (uintptr_t) addr; cmd->length = length; @@ -412,10 +411,10 @@ int ibv_cmd_reg_mr(struct ibv_pd *pd, void *addr, size_t length, cmd->pd_handle = pd->handle; cmd->access_flags = access; - if (write(pd->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(pd->context, IB_USER_VERBS_CMD_REG_MR, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; vmr->ibv_mr.handle = resp->mr_handle; vmr->ibv_mr.lkey = resp->lkey; @@ -432,7 +431,7 @@ int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr, size_t cmd_sz, struct ib_uverbs_rereg_mr_resp *resp, size_t resp_sz) { - IBV_INIT_CMD_RESP(cmd, cmd_sz, REREG_MR, resp, resp_sz); + int ret; cmd->mr_handle = vmr->ibv_mr.handle; cmd->flags = flags; @@ -442,10 +441,10 @@ int ibv_cmd_rereg_mr(struct verbs_mr *vmr, uint32_t flags, void *addr, cmd->pd_handle = (flags & IBV_REREG_MR_CHANGE_PD) ? pd->handle : 0; cmd->access_flags = access; - if (write(vmr->ibv_mr.context->cmd_fd, cmd, cmd_sz) != cmd_sz) - return errno; - - (void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_sz); + ret = execute_cmd_write(vmr->ibv_mr.context, IB_USER_VERBS_CMD_REREG_MR, + cmd, cmd_sz, resp, resp_sz); + if (ret) + return ret; vmr->ibv_mr.lkey = resp->lkey; vmr->ibv_mr.rkey = resp->rkey; @@ -475,15 +474,16 @@ int ibv_cmd_alloc_mw(struct ibv_pd *pd, enum ibv_mw_type type, size_t cmd_size, struct ib_uverbs_alloc_mw_resp *resp, size_t resp_size) { - IBV_INIT_CMD_RESP(cmd, cmd_size, ALLOC_MW, resp, resp_size); + int ret; + cmd->pd_handle = pd->handle; cmd->mw_type = type; memset(cmd->reserved, 0, sizeof(cmd->reserved)); - if (write(pd->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(pd->context, IB_USER_VERBS_CMD_ALLOC_MW, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; mw->context = pd->context; mw->pd = pd; @@ -522,17 +522,16 @@ int ibv_cmd_poll_cq(struct ibv_cq *ibcq, int ne, struct ibv_wc *wc) if (!resp) return -1; - IBV_INIT_CMD_RESP(&cmd, sizeof cmd, POLL_CQ, resp, rsize); cmd.cq_handle = ibcq->handle; cmd.ne = ne; - if (write(ibcq->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) { + ret = execute_cmd_write_no_uhw(ibcq->context, IB_USER_VERBS_CMD_POLL_CQ, + &cmd, sizeof(cmd), resp, rsize); + if (ret) { ret = -1; goto out; } - (void) VALGRIND_MAKE_MEM_DEFINED(resp, rsize); - for (i = 0; i < resp->count; i++) { wc[i].wr_id = resp->wc[i].wr_id; wc[i].status = resp->wc[i].status; @@ -571,14 +570,15 @@ int ibv_cmd_resize_cq(struct ibv_cq *cq, int cqe, struct ibv_resize_cq *cmd, size_t cmd_size, struct ib_uverbs_resize_cq_resp *resp, size_t resp_size) { - IBV_INIT_CMD_RESP(cmd, cmd_size, RESIZE_CQ, resp, resp_size); + int ret; + cmd->cq_handle = cq->handle; cmd->cqe = cqe; - if (write(cq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(cq->context, IB_USER_VERBS_CMD_RESIZE_CQ, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; cq->cqe = resp->cqe; @@ -590,17 +590,18 @@ int ibv_cmd_create_srq(struct ibv_pd *pd, struct ibv_create_srq *cmd, size_t cmd_size, struct ib_uverbs_create_srq_resp *resp, size_t resp_size) { - IBV_INIT_CMD_RESP(cmd, cmd_size, CREATE_SRQ, resp, resp_size); + int ret; + cmd->user_handle = (uintptr_t) srq; cmd->pd_handle = pd->handle; cmd->max_wr = attr->attr.max_wr; cmd->max_sge = attr->attr.max_sge; cmd->srq_limit = attr->attr.srq_limit; - if (write(pd->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(pd->context, IB_USER_VERBS_CMD_CREATE_SRQ, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; srq->handle = resp->srq_handle; srq->context = pd->context; @@ -627,8 +628,7 @@ int ibv_cmd_create_srq_ex(struct ibv_context *context, struct ib_uverbs_create_srq_resp *resp, size_t resp_size) { struct verbs_xrcd *vxrcd = NULL; - - IBV_INIT_CMD_RESP(cmd, cmd_size, CREATE_XSRQ, resp, resp_size); + int ret; if (attr_ex->comp_mask >= IBV_SRQ_INIT_ATTR_RESERVED) return ENOSYS; @@ -664,10 +664,10 @@ int ibv_cmd_create_srq_ex(struct ibv_context *context, return EINVAL; } - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(context, IB_USER_VERBS_CMD_CREATE_XSRQ, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; srq->srq.handle = resp->srq_handle; srq->srq.context = context; @@ -760,15 +760,15 @@ int ibv_cmd_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, struct ibv_query_srq *cmd, size_t cmd_size) { struct ib_uverbs_query_srq_resp resp; + int ret; - IBV_INIT_CMD_RESP(cmd, cmd_size, QUERY_SRQ, &resp, sizeof resp); cmd->srq_handle = srq->handle; cmd->reserved = 0; - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_cmd_write(srq->context, IB_USER_VERBS_CMD_QUERY_SRQ, cmd, + cmd_size, &resp, sizeof(resp)); + if (ret) + return ret; srq_attr->max_wr = resp.max_wr; srq_attr->max_sge = resp.max_sge; @@ -962,8 +962,6 @@ int ibv_cmd_create_qp_ex(struct ibv_context *context, struct verbs_xrcd *vxrcd = NULL; int err; - IBV_INIT_CMD_RESP(cmd, cmd_size, CREATE_QP, resp, resp_size); - if (attr_ex->comp_mask > (IBV_QP_INIT_ATTR_XRCD | IBV_QP_INIT_ATTR_PD)) return ENOSYS; @@ -972,10 +970,10 @@ int ibv_cmd_create_qp_ex(struct ibv_context *context, if (err) return err; - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + err = execute_cmd_write(context, IB_USER_VERBS_CMD_CREATE_QP, cmd, + cmd_size, resp, resp_size); + if (err) + return err; if (abi_ver == 4) { struct ibv_create_qp_resp_v4 *resp_v4 = @@ -1003,7 +1001,7 @@ int ibv_cmd_create_qp(struct ibv_pd *pd, struct ibv_create_qp *cmd, size_t cmd_size, struct ib_uverbs_create_qp_resp *resp, size_t resp_size) { - IBV_INIT_CMD_RESP(cmd, cmd_size, CREATE_QP, resp, resp_size); + int ret; cmd->user_handle = (uintptr_t) qp; cmd->pd_handle = pd->handle; @@ -1020,10 +1018,10 @@ int ibv_cmd_create_qp(struct ibv_pd *pd, cmd->is_srq = !!attr->srq; cmd->reserved = 0; - if (write(pd->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(pd->context, IB_USER_VERBS_CMD_CREATE_QP, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; qp->handle = resp->qp_handle; qp->qp_num = resp->qpn; @@ -1063,7 +1061,7 @@ int ibv_cmd_open_qp(struct ibv_context *context, struct verbs_qp *qp, struct ib_uverbs_create_qp_resp *resp, size_t resp_size) { struct verbs_xrcd *xrcd; - IBV_INIT_CMD_RESP(cmd, cmd_size, OPEN_QP, resp, resp_size); + int ret; if (attr->comp_mask >= IBV_QP_OPEN_ATTR_RESERVED) return ENOSYS; @@ -1079,10 +1077,10 @@ int ibv_cmd_open_qp(struct ibv_context *context, struct verbs_qp *qp, cmd->qpn = attr->qp_num; cmd->qp_type = attr->qp_type; - if (write(context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(context, IB_USER_VERBS_CMD_OPEN_QP, cmd, + cmd_size, resp, resp_size); + if (ret) + return ret; qp->qp.handle = resp->qp_handle; qp->qp.context = context; @@ -1112,6 +1110,7 @@ int ibv_cmd_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, struct ibv_query_qp *cmd, size_t cmd_size) { struct ib_uverbs_query_qp_resp resp; + int ret; /* * Starting with IBV_QP_RATE_LIMIT the attribute must go through the @@ -1120,14 +1119,13 @@ int ibv_cmd_query_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, if (attr_mask & ~(IBV_QP_RATE_LIMIT - 1)) return EOPNOTSUPP; - IBV_INIT_CMD_RESP(cmd, cmd_size, QUERY_QP, &resp, sizeof resp); cmd->qp_handle = qp->handle; cmd->attr_mask = attr_mask; - if (write(qp->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_cmd_write(qp->context, IB_USER_VERBS_CMD_QUERY_QP, cmd, + cmd_size, &resp, sizeof(resp)); + if (ret) + return ret; attr->qkey = resp.qkey; attr->rq_psn = resp.rq_psn; @@ -1342,7 +1340,7 @@ int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, unsigned wr_count = 0; unsigned sge_count = 0; int cmd_size; - int ret = 0; + int ret; for (i = wr; i; i = i->next) { wr_count++; @@ -1352,7 +1350,6 @@ int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, cmd_size = sizeof *cmd + wr_count * sizeof *n + sge_count * sizeof *s; cmd = alloca(cmd_size); - IBV_INIT_CMD_RESP(cmd, cmd_size, POST_SEND, &resp, sizeof resp); cmd->qp_handle = ibqp->handle; cmd->wr_count = wr_count; cmd->sge_count = sge_count; @@ -1404,10 +1401,9 @@ int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, } resp.bad_wr = 0; - if (write(ibqp->context->cmd_fd, cmd, cmd_size) != cmd_size) - ret = errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_cmd_write_no_uhw(ibqp->context, + IB_USER_VERBS_CMD_POST_SEND, cmd, + cmd_size, &resp, sizeof(resp)); wr_count = resp.bad_wr; if (wr_count) { @@ -1432,7 +1428,7 @@ int ibv_cmd_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr, unsigned wr_count = 0; unsigned sge_count = 0; int cmd_size; - int ret = 0; + int ret; for (i = wr; i; i = i->next) { wr_count++; @@ -1442,7 +1438,6 @@ int ibv_cmd_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr, cmd_size = sizeof *cmd + wr_count * sizeof *n + sge_count * sizeof *s; cmd = alloca(cmd_size); - IBV_INIT_CMD_RESP(cmd, cmd_size, POST_RECV, &resp, sizeof resp); cmd->qp_handle = ibqp->handle; cmd->wr_count = wr_count; cmd->sge_count = sge_count; @@ -1465,10 +1460,9 @@ int ibv_cmd_post_recv(struct ibv_qp *ibqp, struct ibv_recv_wr *wr, } resp.bad_wr = 0; - if (write(ibqp->context->cmd_fd, cmd, cmd_size) != cmd_size) - ret = errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_cmd_write_no_uhw(ibqp->context, + IB_USER_VERBS_CMD_POST_RECV, cmd, + cmd_size, &resp, sizeof(resp)); wr_count = resp.bad_wr; if (wr_count) { @@ -1493,7 +1487,7 @@ int ibv_cmd_post_srq_recv(struct ibv_srq *srq, struct ibv_recv_wr *wr, unsigned wr_count = 0; unsigned sge_count = 0; int cmd_size; - int ret = 0; + int ret; for (i = wr; i; i = i->next) { wr_count++; @@ -1503,7 +1497,6 @@ int ibv_cmd_post_srq_recv(struct ibv_srq *srq, struct ibv_recv_wr *wr, cmd_size = sizeof *cmd + wr_count * sizeof *n + sge_count * sizeof *s; cmd = alloca(cmd_size); - IBV_INIT_CMD_RESP(cmd, cmd_size, POST_SRQ_RECV, &resp, sizeof resp); cmd->srq_handle = srq->handle; cmd->wr_count = wr_count; cmd->sge_count = sge_count; @@ -1526,10 +1519,9 @@ int ibv_cmd_post_srq_recv(struct ibv_srq *srq, struct ibv_recv_wr *wr, } resp.bad_wr = 0; - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - ret = errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof resp); + ret = execute_cmd_write_no_uhw(srq->context, + IB_USER_VERBS_CMD_POST_SRQ_RECV, cmd, + cmd_size, &resp, sizeof(resp)); wr_count = resp.bad_wr; if (wr_count) { @@ -1549,8 +1541,8 @@ int ibv_cmd_create_ah(struct ibv_pd *pd, struct ibv_ah *ah, size_t resp_size) { struct ibv_create_ah cmd; + int ret; - IBV_INIT_CMD_RESP(&cmd, sizeof cmd, CREATE_AH, resp, resp_size); cmd.user_handle = (uintptr_t) ah; cmd.pd_handle = pd->handle; cmd.attr.dlid = attr->dlid; @@ -1565,10 +1557,10 @@ int ibv_cmd_create_ah(struct ibv_pd *pd, struct ibv_ah *ah, cmd.attr.grh.traffic_class = attr->grh.traffic_class; memcpy(cmd.attr.grh.dgid, attr->grh.dgid.raw, 16); - if (write(pd->context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + ret = execute_cmd_write(pd->context, IB_USER_VERBS_CMD_CREATE_AH, &cmd, + sizeof(cmd), resp, resp_size); + if (ret) + return ret; ah->handle = resp->ah_handle; ah->context = pd->context; diff --git a/libibverbs/cmd_fallback.c b/libibverbs/cmd_fallback.c index 2aac6cb9f24c92..3a43a0c569776f 100644 --- a/libibverbs/cmd_fallback.c +++ b/libibverbs/cmd_fallback.c @@ -244,6 +244,23 @@ int _execute_write_raw(struct ibv_context *ctx, struct ib_uverbs_cmd_hdr *hdr, return 0; } +int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, + struct ib_uverbs_cmd_hdr *req, size_t core_req_size, + size_t req_size, void *resp, size_t core_resp_size, + size_t resp_size) +{ + req->command = write_method; + req->in_words = __check_divide(req_size, 4); + req->out_words = __check_divide(resp_size, 4); + + if (write(ctx->cmd_fd, req, req_size) != req_size) + return errno; + + if (resp) + VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + return 0; +} + int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *hdr) { size_t write_bytes = diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index 98aa58a26d6728..c7a7ef0b50a22b 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -207,6 +207,44 @@ int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *req); #define execute_write_ex(ctx, req) \ _execute_write_raw_ex(ctx, get_req_hdr_ex(req)) +/* + * For write() only commands that have fixed core structures and may take uhw + * driver data. The last arguments are the same ones passed into the typical + * ibv_cmd_* function. execute_cmd_write deduces the length of the core + * structure based on the KABI struct linked to the enum op code. + */ +int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, + struct ib_uverbs_cmd_hdr *req, size_t core_req_size, + size_t req_size, void *resp, size_t core_resp_size, + size_t resp_size); +#define execute_cmd_write(ctx, enum, cmd, cmd_size, resp, resp_size) \ + ({ \ + (cmd)->core_payload.response = ioctl_ptr_to_u64(resp); \ + _execute_cmd_write( \ + ctx, enum, \ + &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \ + sizeof(*(cmd)), cmd_size, \ + resp + check_type(resp, IBV_KABI_RESP(enum) *), \ + sizeof(*(resp)), resp_size); \ + }) + +/* + * Execute a write command that does not have a uhw component. THe cmd_size + * and resp_size are the lengths of the core structure. This version is only + * needed if the core structure ends in a flex array, as the internal sizeof() + * in execute_cmd_write() will give the wrong size. + */ +#define execute_cmd_write_no_uhw(ctx, enum, cmd, cmd_size, resp, resp_size) \ + ({ \ + (cmd)->core_payload.response = ioctl_ptr_to_u64(resp); \ + _execute_cmd_write( \ + ctx, enum, \ + &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \ + cmd_size, cmd_size, \ + resp + check_type(resp, IBV_KABI_RESP(enum) *), \ + resp_size, resp_size); \ + }) + /* * These two macros are used only with execute_ioctl_fallback - they allow the * IOCTL code to be elided by the compiler when disabled. diff --git a/libibverbs/ibverbs.h b/libibverbs/ibverbs.h index 5954cea30986a5..c99d617eace611 100644 --- a/libibverbs/ibverbs.h +++ b/libibverbs/ibverbs.h @@ -93,14 +93,6 @@ static inline const struct verbs_context_ops *get_ops(struct ibv_context *ctx) (cmd)->hdr.out_words = 0; \ } while (0) -#define IBV_INIT_CMD_RESP(cmd, size, opcode, out, outsize) \ - do { \ - (cmd)->hdr.command = IB_USER_VERBS_CMD_##opcode; \ - (cmd)->hdr.in_words = (size) / 4; \ - (cmd)->hdr.out_words = (outsize) / 4; \ - (cmd)->response = (uintptr_t) (out); \ - } while (0) - static inline uint32_t _cmd_ex(uint32_t cmd) { return IB_USER_VERBS_CMD_FLAG_EXTENDED | cmd; From patchwork Thu Nov 22 23:24:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694977 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 06E7013B5 for ; Thu, 22 Nov 2018 23:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAA232C2F0 for ; Thu, 22 Nov 2018 23:24:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF66C2C3A1; Thu, 22 Nov 2018 23:24:24 +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 5B8212BF0F for ; Thu, 22 Nov 2018 23:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407883AbeKWKGF (ORCPT ); Fri, 23 Nov 2018 05:06:05 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34136 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389637AbeKWKGF (ORCPT ); Fri, 23 Nov 2018 05:06:05 -0500 Received: by mail-pl1-f193.google.com with SMTP id f12-v6so9804385plo.1 for ; Thu, 22 Nov 2018 15:24:22 -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=zSJGlxOrn/Ub24PCVPiLHtSCkQlPAmuTG/OHc9Yo/t8=; b=h3uOexgmCwbv+oto8ae7pEbXU4H6eDOBL2WxtfN+qzBiWhAhxOkxfmUA0i/auLP/zu Uyy4elufxZswr2f45rnbBcJfH4MJYGWt4w/MSCei2yaBTc+7qrJCAByhS3TFdoQxy5RX nTUcRsZiz+pVtcZX/KVAW6REYSQSVW5EwTaZfVdNDhKUnQjkKkysjypEOsG9NxOqdffO r4BagcWu9BqPzqFv3oxK5bwyiinjhno6uSq9Y+fz12g5FKCtlUaE8M77TzHN+aUiFeiq NoYQAUnOkt0pBZXpCtLsIFj0fuBaTr1D2XdTAcap+S40H6/LhZbsuDRozQ37wHJQ92PH FE2w== 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=zSJGlxOrn/Ub24PCVPiLHtSCkQlPAmuTG/OHc9Yo/t8=; b=cEd6OqzxBqfOuK8Gr1PhALYBDRFu/G/kqa1Yp2ZNK51ebAeX0iyNK8FX/edXWV8v/P EVvylRcxZnuWAt3tJtMakv1SxzQpL3qk9cqmg+r88MVHr2dNMnT+0UASZ3mDVY6pGFxY yrYAYAmRoRSA4pZNHCb5CWrPASM3hkHO8oPPOZHGr4xqSzpeRuCR5tH6OwxB7p602nwk tHCTvk41CeaAvlNd93n2yR4J+6g6Fp7i6ryw7LbK+eS9qSaHWsmT4jC7IwWPa7+DDFnw CHzFHeYFjOai9rUug663AVGXrG8b+MmRb1EN/m953dB5pOtyahuWeyXSFzH+jQfAnety AUxg== X-Gm-Message-State: AA+aEWbqSXT4ja9XMfLK42CuZRs6z9hGeN+hQvYrH2pAwTEeMUNwbI06 /OtkeA8O23Rc1cIBgpjCfYm4imIWn3Q= X-Google-Smtp-Source: AFSGD/V5DRgjJbFmR2LIRAWVRNzEWu0vXgk2KT4kFcRrKyA1BX9LdBExLj12Pm00PFMq2Tx85/zURQ== X-Received: by 2002:a17:902:34a:: with SMTP id 68mr4521646pld.268.1542929061799; Thu, 22 Nov 2018 15:24:21 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id u69sm49256208pfj.116.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-0007st-G6; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 06/10] verbs: Replace IBV_INIT_CMD() with execute_cmd_write_resp Date: Thu, 22 Nov 2018 16:24:12 -0700 Message-Id: <20181122232416.30132-7-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 Replace the entire IBV_INIT_CMD_RESP(); write(); return errno; Sequence with a single function call. This signature has enough information for the execute call to compute the location of all 5 components of a write command. This requires adding a the _v3 version of modify_srq to the command macros. This can be done without a lot of complexity by using core_payload instead of the struct member aliases. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd.c | 36 ++++++++++++------------------------ libibverbs/cmd_write.h | 11 +++++++++++ libibverbs/ibverbs.h | 7 ------- libibverbs/kern-abi.h | 6 ++++-- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index 8123aae1ad89b8..d759ec89c843cc 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -719,19 +719,15 @@ static int ibv_cmd_modify_srq_v3(struct ibv_srq *srq, cmd = alloca(cmd_size); memcpy(cmd + 1, new_cmd + 1, new_cmd_size - sizeof *new_cmd); - IBV_INIT_CMD(cmd, cmd_size, MODIFY_SRQ); - - cmd->srq_handle = srq->handle; - cmd->attr_mask = srq_attr_mask; - cmd->max_wr = srq_attr->max_wr; - cmd->srq_limit = srq_attr->srq_limit; - cmd->max_sge = 0; - cmd->reserved = 0; - - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; + cmd->core_payload = (struct ib_uverbs_modify_srq_v3){ + .srq_handle = srq->handle, + .attr_mask = srq_attr_mask, + .max_wr = srq_attr->max_wr, + .srq_limit = srq_attr->srq_limit, + }; - return 0; + return execute_cmd_write_req( + srq->context, IB_USER_VERBS_CMD_MODIFY_SRQ_V3, cmd, cmd_size); } int ibv_cmd_modify_srq(struct ibv_srq *srq, @@ -743,17 +739,13 @@ int ibv_cmd_modify_srq(struct ibv_srq *srq, return ibv_cmd_modify_srq_v3(srq, srq_attr, srq_attr_mask, cmd, cmd_size); - IBV_INIT_CMD(cmd, cmd_size, MODIFY_SRQ); - cmd->srq_handle = srq->handle; cmd->attr_mask = srq_attr_mask; cmd->max_wr = srq_attr->max_wr; cmd->srq_limit = srq_attr->srq_limit; - if (write(srq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - return 0; + return execute_cmd_write_req(srq->context, IB_USER_VERBS_CMD_MODIFY_SRQ, + cmd, cmd_size); } int ibv_cmd_query_srq(struct ibv_srq *srq, struct ibv_srq_attr *srq_attr, @@ -1288,14 +1280,10 @@ int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, if (attr_mask & ~(IBV_QP_RATE_LIMIT - 1)) return EOPNOTSUPP; - IBV_INIT_CMD(cmd, cmd_size, MODIFY_QP); - copy_modify_qp_fields(qp, attr, attr_mask, &cmd->core_payload); - if (write(qp->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - return 0; + return execute_cmd_write_req(qp->context, IB_USER_VERBS_CMD_MODIFY_QP, + cmd, cmd_size); } int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr, diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index c7a7ef0b50a22b..7ae26359b25f29 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -228,6 +228,17 @@ int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, sizeof(*(resp)), resp_size); \ }) +/* For write() commands that have no respone */ +#define execute_cmd_write_req(ctx, enum, cmd, cmd_size) \ + ({ \ + static_assert(sizeof(IBV_KABI_RESP(enum)) == 0, \ + "Method has a response!"); \ + _execute_cmd_write( \ + ctx, enum, \ + &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \ + sizeof(*(cmd)), cmd_size, NULL, 0, 0); \ + }) + /* * Execute a write command that does not have a uhw component. THe cmd_size * and resp_size are the lengths of the core structure. This version is only diff --git a/libibverbs/ibverbs.h b/libibverbs/ibverbs.h index c99d617eace611..c70114f11e9bad 100644 --- a/libibverbs/ibverbs.h +++ b/libibverbs/ibverbs.h @@ -86,13 +86,6 @@ static inline const struct verbs_context_ops *get_ops(struct ibv_context *ctx) return &get_priv(ctx)->ops; } -#define IBV_INIT_CMD(cmd, size, opcode) \ - do { \ - (cmd)->hdr.command = IB_USER_VERBS_CMD_##opcode; \ - (cmd)->hdr.in_words = (size) / 4; \ - (cmd)->hdr.out_words = 0; \ - } while (0) - static inline uint32_t _cmd_ex(uint32_t cmd) { return IB_USER_VERBS_CMD_FLAG_EXTENDED | cmd; diff --git a/libibverbs/kern-abi.h b/libibverbs/kern-abi.h index 8c07b8d2731adb..dc2f33d3f78e45 100644 --- a/libibverbs/kern-abi.h +++ b/libibverbs/kern-abi.h @@ -277,8 +277,7 @@ struct ibv_kern_spec { }; }; -struct ibv_modify_srq_v3 { - struct ib_uverbs_cmd_hdr hdr; +struct ib_uverbs_modify_srq_v3 { __u32 srq_handle; __u32 attr_mask; __u32 max_wr; @@ -286,6 +285,9 @@ struct ibv_modify_srq_v3 { __u32 srq_limit; __u32 reserved; }; +#define _STRUCT_ib_uverbs_modify_srq_v3 +enum { IB_USER_VERBS_CMD_MODIFY_SRQ_V3 = IB_USER_VERBS_CMD_MODIFY_SRQ }; +DECLARE_CMDX(IB_USER_VERBS_CMD_MODIFY_SRQ_V3, ibv_modify_srq_v3, ib_uverbs_modify_srq_v3, empty); struct ibv_create_qp_resp_v3 { __u32 qp_handle; From patchwork Thu Nov 22 23:24:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694987 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 A304E1709 for ; Thu, 22 Nov 2018 23:24:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 903A52C3A1 for ; Thu, 22 Nov 2018 23:24:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8463F2C3A7; Thu, 22 Nov 2018 23:24:28 +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 0797A2BF0F for ; Thu, 22 Nov 2018 23:24:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407893AbeKWKGI (ORCPT ); Fri, 23 Nov 2018 05:06:08 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46329 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407881AbeKWKGH (ORCPT ); Fri, 23 Nov 2018 05:06:07 -0500 Received: by mail-pf1-f194.google.com with SMTP id c73so2474129pfe.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=xzHexJ6Ur7XvY0W2gTAkHyYzBmymt3jh3E9HkE5ZgDI=; b=eemZzske53/y9Yh0kvu4UM96mdcbdYZqdCsVAyPA6DtwtPREHnxXY6VHrreBjPjyJ/ YaDyhHp04oCMZSclfhylughs2jNt66XKaltciiFTZPlNGMiRqCvOQXki4TuIETlCdc85 lh3l08klDhAigpydwBYRrbW7OFdq28MT+jj4fdTlEVKHtY57AcTvbC+CkyJWP1b/xSzW uFfZc8Kh051Mg0dVjRRkPYBAqaVYqHbqPfFsb/aAJG8SRxvlR2vndxReLuBkJBTTdCU6 lrFaLAHqZcVnux+y+/0i0no4Z7UCzsT0lc68JecAjBHCxpBxRp978qzo3ruz2DNxwA6z 3wJQ== 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=xzHexJ6Ur7XvY0W2gTAkHyYzBmymt3jh3E9HkE5ZgDI=; b=uVaK2l4VMJiiSXI3JEotU3xFbi8kd/E7YwdWOZN7+PAes6yEM++1EDtfOzU2iqj8wV Yto7fkNTNLtPID+NDwRBZKD8VEBCPkELNwAzBOlY9iPno09XAIbzKtAVXA8mLi2xcDMc 26oKoiEtC++8eJenFweNe2F/0DcTL1JDgV5xqjRmlLtD2PvGGkaMhYA/YQ0qWdFy0mca EVSFIsh8ZllF7E6Xj7BA/2eITy7hb8FNtYfNNY+OM2/5L98UkTXE7aPxxOG7vxseCD96 sufgzL2wPgLGFkG9Cnxs/w5ZdOzDxwSGCiBVvXVeJWMwc3XubsL8+cu0n6VJYI4J17f5 sMzA== X-Gm-Message-State: AA+aEWYa5kkc3dSwmroOTMgQizDgAO1PStunl+6L7J4jj26/8AG05g8A D+A6qGDqnOo2H/0n8jVjMCh/rWwTGRk= X-Google-Smtp-Source: AFSGD/U9ohiJp/dhOpagX5k9Nhu94jWzMBWeD0LnGtbr+58FLvylw84/6VXGj7VrNDfhBbKBEeEsIQ== X-Received: by 2002:a62:2c4d:: with SMTP id s74mr11138007pfs.6.1542929063936; 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 g190sm51868812pgc.28.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-0007sz-HN; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 07/10] verbs: Replace IBV_INIT_CMD_RESP_EX*() with execute_cmd_write_ex Date: Thu, 22 Nov 2018 16:24:13 -0700 Message-Id: <20181122232416.30132-8-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 Replace the entire IBV_INIT_CMD_RESP_EX*(); write(); VALGRIND_MAKE_MEM_DEFINED(); Sequence with a single function call. This signature has enough information for the execute call to compute the location of all 5 components of a write command. This also eliminates the legacy cmd/resp_core_size parameters. These existed to provide some limited compatibility for providers built against a different version of verbs, which is not supported any more. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd.c | 159 ++++++++++++-------------------------- libibverbs/cmd_fallback.c | 36 +++++++++ libibverbs/cmd_ioctl.c | 1 + libibverbs/cmd_write.h | 30 +++++++ libibverbs/driver.h | 13 +--- libibverbs/ibverbs.h | 34 -------- providers/mlx4/verbs.c | 24 ++---- providers/mlx5/verbs.c | 48 ++++-------- 8 files changed, 146 insertions(+), 199 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index d759ec89c843cc..d45082eea0cab3 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -135,10 +135,8 @@ int ibv_cmd_query_device_ex(struct ibv_context *context, struct ibv_device_attr_ex *attr, size_t attr_size, uint64_t *raw_fw_ver, struct ibv_query_device_ex *cmd, - size_t cmd_core_size, size_t cmd_size, struct ib_uverbs_ex_query_device_resp *resp, - size_t resp_core_size, size_t resp_size) { int err; @@ -150,23 +148,16 @@ int ibv_cmd_query_device_ex(struct ibv_context *context, sizeof(attr->comp_mask)) return EINVAL; - if (resp_core_size < offsetof(struct ib_uverbs_ex_query_device_resp, - response_length) + - sizeof(resp->response_length)) - return EINVAL; - - IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size, - QUERY_DEVICE, resp, resp_core_size, - resp_size); cmd->comp_mask = 0; cmd->reserved = 0; memset(attr->orig_attr.fw_ver, 0, sizeof(attr->orig_attr.fw_ver)); memset(&attr->comp_mask, 0, attr_size - sizeof(attr->orig_attr)); - err = write(context->cmd_fd, cmd, cmd_size); - if (err != cmd_size) - return errno; - (void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + err = execute_cmd_write_ex(context, IB_USER_VERBS_EX_CMD_QUERY_DEVICE, + cmd, cmd_size, resp, resp_size); + if (err) + return err; + copy_query_dev_fields(&attr->orig_attr, &resp->base, raw_fw_ver); /* Report back supported comp_mask bits. For now no comp_mask bit is * defined */ @@ -886,10 +877,8 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context, struct verbs_qp *qp, int vqp_sz, struct ibv_qp_init_attr_ex *qp_attr, struct ibv_create_qp_ex *cmd, - size_t cmd_core_size, size_t cmd_size, struct ib_uverbs_ex_create_qp_resp *resp, - size_t resp_core_size, size_t resp_size) { struct verbs_xrcd *vxrcd = NULL; @@ -898,15 +887,7 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context, if (qp_attr->comp_mask >= IBV_QP_INIT_ATTR_RESERVED) return EINVAL; - if (resp_core_size < - offsetof(struct ib_uverbs_ex_create_qp_resp, response_length) + - sizeof(resp->response_length)) - return EINVAL; - - memset(cmd, 0, cmd_core_size); - - IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size, CREATE_QP, resp, - resp_core_size, resp_size); + memset(&cmd->core_payload, 0, sizeof(cmd->core_payload)); err = create_qp_ex_common(qp, qp_attr, vxrcd, ibv_create_qp_ex_to_reg(cmd)); @@ -916,9 +897,6 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context, if (qp_attr->comp_mask & IBV_QP_INIT_ATTR_CREATE_FLAGS) { if (qp_attr->create_flags & ~CREATE_QP_EX2_SUP_CREATE_FLAGS) return EINVAL; - if (cmd_core_size < offsetof(struct ibv_create_qp_ex, create_flags) + - sizeof(qp_attr->create_flags)) - return EINVAL; cmd->create_flags = qp_attr->create_flags; if (qp_attr->create_flags & IBV_QP_CREATE_SOURCE_QPN) @@ -926,18 +904,14 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context, } if (qp_attr->comp_mask & IBV_QP_INIT_ATTR_IND_TABLE) { - if (cmd_core_size < offsetof(struct ibv_create_qp_ex, rwq_ind_tbl_handle) + - sizeof(cmd->rwq_ind_tbl_handle)) - return EINVAL; cmd->rwq_ind_tbl_handle = qp_attr->rwq_ind_tbl->ind_tbl_handle; cmd->comp_mask = IB_UVERBS_CREATE_QP_MASK_IND_TABLE; } - err = write(context->cmd_fd, cmd, cmd_size); - if (err != cmd_size) - return errno; - - (void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + err = execute_cmd_write_ex(context, IB_USER_VERBS_EX_CMD_CREATE_QP, + cmd, cmd_size, resp, resp_size); + if (err) + return err; create_qp_handle_resp_common(context, qp, qp_attr, &resp->base, vxrcd, vqp_sz); @@ -1288,17 +1262,10 @@ int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask, struct ibv_modify_qp_ex *cmd, - size_t cmd_core_size, size_t cmd_size, + size_t cmd_size, struct ib_uverbs_ex_modify_qp_resp *resp, - size_t resp_core_size, size_t resp_size) + size_t resp_size) { - if (resp_core_size < offsetof(struct ib_uverbs_ex_modify_qp_resp, - response_length) + sizeof(resp->response_length)) - return EINVAL; - - IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size, MODIFY_QP, - resp, resp_core_size, resp_size); - copy_modify_qp_fields(qp, attr, attr_mask, &cmd->base); if (attr_mask & IBV_QP_RATE_LIMIT) { @@ -1309,12 +1276,8 @@ int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr, return EINVAL; } - if (write(qp->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - (void)VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); - - return 0; + return execute_cmd_write_ex(qp->context, IB_USER_VERBS_EX_CMD_MODIFY_QP, + cmd, cmd_size, resp, resp_size); } int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, @@ -1847,7 +1810,7 @@ int ibv_cmd_create_flow(struct ibv_qp *qp, err = ib_spec_to_kern_spec(ib_spec, kern_spec); if (err) { errno = err; - goto err; + return err; } cmd->flow_attr.size += ((struct ibv_kern_spec *)kern_spec)->hdr.size; @@ -1861,19 +1824,16 @@ int ibv_cmd_create_flow(struct ibv_qp *qp, written_size += ucmd_size; } - IBV_INIT_CMD_RESP_EX_VCMD(cmd, written_size - ucmd_size, - written_size, CREATE_FLOW, - &resp, sizeof(resp)); - if (write(qp->context->cmd_fd, cmd, written_size) != written_size) - goto err; - - (void) VALGRIND_MAKE_MEM_DEFINED(&resp, sizeof(resp)); + err = execute_cmd_write_ex_full(qp->context, + IB_USER_VERBS_EX_CMD_CREATE_FLOW, cmd, + written_size - ucmd_size, written_size, + &resp, sizeof(resp), sizeof(resp)); + if (err) + return err; flow_id->context = qp->context; flow_id->handle = resp.flow_handle; return 0; -err: - return errno; } int ibv_cmd_destroy_flow(struct ibv_flow *flow_id) @@ -1895,10 +1855,8 @@ int ibv_cmd_create_wq(struct ibv_context *context, struct ibv_wq_init_attr *wq_init_attr, struct ibv_wq *wq, struct ibv_create_wq *cmd, - size_t cmd_core_size, size_t cmd_size, struct ib_uverbs_ex_create_wq_resp *resp, - size_t resp_core_size, size_t resp_size) { int err; @@ -1906,10 +1864,6 @@ int ibv_cmd_create_wq(struct ibv_context *context, if (wq_init_attr->comp_mask >= IBV_WQ_INIT_ATTR_RESERVED) return EINVAL; - IBV_INIT_CMD_RESP_EX_V(cmd, cmd_core_size, cmd_size, - CREATE_WQ, resp, - resp_core_size, resp_size); - cmd->user_handle = (uintptr_t)wq; cmd->pd_handle = wq_init_attr->pd->handle; cmd->cq_handle = wq_init_attr->cq->handle; @@ -1918,22 +1872,18 @@ int ibv_cmd_create_wq(struct ibv_context *context, cmd->max_wr = wq_init_attr->max_wr; cmd->comp_mask = 0; - if (cmd_core_size >= offsetof(struct ibv_create_wq, create_flags) + - sizeof(cmd->create_flags)) { - if (wq_init_attr->comp_mask & IBV_WQ_INIT_ATTR_FLAGS) { - if (wq_init_attr->create_flags & ~(IBV_WQ_FLAGS_RESERVED - 1)) - return EOPNOTSUPP; - cmd->create_flags = wq_init_attr->create_flags; - } + if (wq_init_attr->comp_mask & IBV_WQ_INIT_ATTR_FLAGS) { + if (wq_init_attr->create_flags & ~(IBV_WQ_FLAGS_RESERVED - 1)) + return EOPNOTSUPP; + cmd->create_flags = wq_init_attr->create_flags; } - err = write(context->cmd_fd, cmd, cmd_size); - if (err != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + err = execute_cmd_write_ex(context, IB_USER_VERBS_EX_CMD_CREATE_WQ, + cmd, cmd_size, resp, resp_size); + if (err) + return err; - if (resp->response_length < resp_core_size) + if (resp->response_length < sizeof(*resp)) return EINVAL; wq->handle = resp->wq_handle; @@ -1949,31 +1899,30 @@ int ibv_cmd_create_wq(struct ibv_context *context, } int ibv_cmd_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr, - struct ibv_modify_wq *cmd, size_t cmd_core_size, - size_t cmd_size) + struct ibv_modify_wq *cmd, size_t cmd_size) { + int err; + if (attr->attr_mask >= IBV_WQ_ATTR_RESERVED) return EINVAL; - memset(cmd, 0, cmd_core_size); - IBV_INIT_CMD_EX(cmd, cmd_size, MODIFY_WQ); + memset(cmd, 0, sizeof(*cmd)); cmd->curr_wq_state = attr->curr_wq_state; cmd->wq_state = attr->wq_state; - if (cmd_core_size >= offsetof(struct ibv_modify_wq, flags_mask) + - sizeof(cmd->flags_mask)) { - if (attr->attr_mask & IBV_WQ_ATTR_FLAGS) { - if (attr->flags_mask & ~(IBV_WQ_FLAGS_RESERVED - 1)) - return EOPNOTSUPP; - cmd->flags = attr->flags; - cmd->flags_mask = attr->flags_mask; - } + if (attr->attr_mask & IBV_WQ_ATTR_FLAGS) { + if (attr->flags_mask & ~(IBV_WQ_FLAGS_RESERVED - 1)) + return EOPNOTSUPP; + cmd->flags = attr->flags; + cmd->flags_mask = attr->flags_mask; } cmd->wq_handle = wq->handle; cmd->attr_mask = attr->attr_mask; - if (write(wq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; + err = execute_cmd_write_ex_req( + wq->context, IB_USER_VERBS_EX_CMD_MODIFY_WQ, cmd, cmd_size); + if (err) + return err; if (attr->attr_mask & IBV_WQ_ATTR_STATE) wq->state = attr->wq_state; @@ -2030,17 +1979,15 @@ int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, for (i = 0; i < num_tbl_entries; i++) cmd->wq_handles[i] = init_attr->ind_tbl[i]->handle; - IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, cmd_size, - CREATE_RWQ_IND_TBL, resp, - sizeof(*resp), resp_size); cmd->log_ind_tbl_size = init_attr->log_ind_tbl_size; cmd->comp_mask = 0; - err = write(context->cmd_fd, cmd, cmd_size); - if (err != cmd_size) - return errno; - - (void) VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + err = execute_cmd_write_ex_full(context, + IB_USER_VERBS_EX_CMD_CREATE_RWQ_IND_TBL, + cmd, cmd_size, cmd_size, resp, + sizeof(*resp), resp_size); + if (err) + return err; if (resp->response_length < sizeof(*resp)) return EINVAL; @@ -2076,16 +2023,12 @@ int ibv_cmd_modify_cq(struct ibv_cq *cq, if (attr->attr_mask >= IBV_CQ_ATTR_RESERVED) return EINVAL; - IBV_INIT_CMD_EX(cmd, cmd_size, MODIFY_CQ); - cmd->cq_handle = cq->handle; cmd->attr_mask = attr->attr_mask; cmd->attr.cq_count = attr->moderate.cq_count; cmd->attr.cq_period = attr->moderate.cq_period; cmd->reserved = 0; - if (write(cq->context->cmd_fd, cmd, cmd_size) != cmd_size) - return errno; - - return 0; + return execute_cmd_write_ex_req( + cq->context, IB_USER_VERBS_EX_CMD_MODIFY_CQ, cmd, cmd_size); } diff --git a/libibverbs/cmd_fallback.c b/libibverbs/cmd_fallback.c index 3a43a0c569776f..cad8b21756a6a6 100644 --- a/libibverbs/cmd_fallback.c +++ b/libibverbs/cmd_fallback.c @@ -38,6 +38,7 @@ #include #include +#include /* * Check if the command buffer provided by the driver includes anything that @@ -285,3 +286,38 @@ int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *hdr) return 0; } + +/* + * req_size is the total length of the ex_hdr, core payload and driver data. + * core_req_size is the total length of the ex_hdr and core_payload. + */ +int _execute_cmd_write_ex(struct ibv_context *ctx, unsigned int write_method, + struct ex_hdr *req, size_t core_req_size, + size_t req_size, void *resp, size_t core_resp_size, + size_t resp_size) +{ + req->hdr.command = IB_USER_VERBS_CMD_FLAG_EXTENDED | write_method; + req->hdr.in_words = + __check_divide(core_req_size - sizeof(struct ex_hdr), 8); + req->hdr.out_words = __check_divide(core_resp_size, 8); + req->ex_hdr.provider_in_words = + __check_divide(req_size - core_req_size, 8); + req->ex_hdr.provider_out_words = + __check_divide(resp_size - core_resp_size, 8); + req->ex_hdr.response = ioctl_ptr_to_u64(resp); + req->ex_hdr.cmd_hdr_reserved = 0; + + /* + * Users assumes the stack buffer is zeroed before passing to the + * kernel for writing. + */ + if (resp) + memset(resp, 0, resp_size); + + if (write(ctx->cmd_fd, req, req_size) != req_size) + return errno; + + if (resp) + VALGRIND_MAKE_MEM_DEFINED(resp, resp_size); + return 0; +} diff --git a/libibverbs/cmd_ioctl.c b/libibverbs/cmd_ioctl.c index c12442f319a570..bb6ab45ebba96e 100644 --- a/libibverbs/cmd_ioctl.c +++ b/libibverbs/cmd_ioctl.c @@ -38,6 +38,7 @@ #include #include +#include /* Number of attrs in this and all the link'd buffers */ unsigned int __ioctl_final_num_attrs(unsigned int num_attrs, diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index 7ae26359b25f29..2a3c50aa62015c 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -256,6 +256,36 @@ int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, resp_size, resp_size); \ }) +/* + * For write() commands that use the _ex protocol. _full allows the caller to + * specify all 4 sizes directly. This version is used when the core structs + * end in a flex array. The normal and req versions are similar to write() and + * deduce the length of the core struct from the enum. + */ +int _execute_cmd_write_ex(struct ibv_context *ctx, unsigned int write_method, + struct ex_hdr *req, size_t core_req_size, + size_t req_size, void *resp, size_t core_resp_size, + size_t resp_size); +#define execute_cmd_write_ex_full(ctx, enum, cmd, core_cmd_size, cmd_size, \ + resp, core_resp_size, resp_size) \ + _execute_cmd_write_ex( \ + ctx, enum, &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \ + core_cmd_size, cmd_size, \ + resp + check_type(resp, IBV_KABI_RESP(enum) *), \ + core_resp_size, resp_size) +#define execute_cmd_write_ex(ctx, enum, cmd, cmd_size, resp, resp_size) \ + execute_cmd_write_ex_full(ctx, enum, cmd, sizeof(*(cmd)), cmd_size, \ + resp, sizeof(*(resp)), resp_size) +#define execute_cmd_write_ex_req(ctx, enum, cmd, cmd_size) \ + ({ \ + static_assert(sizeof(IBV_KABI_RESP(enum)) == 0, \ + "Method has a response!"); \ + _execute_cmd_write_ex( \ + ctx, enum, \ + &(cmd)->hdr + check_type(cmd, IBV_ABI_REQ(enum) *), \ + sizeof(*(cmd)), cmd_size, NULL, 0, 0); \ + }) + /* * These two macros are used only with execute_ioctl_fallback - they allow the * IOCTL code to be elided by the compiler when disabled. diff --git a/libibverbs/driver.h b/libibverbs/driver.h index cc879fb61335c7..9030dc81d37ca4 100644 --- a/libibverbs/driver.h +++ b/libibverbs/driver.h @@ -413,10 +413,8 @@ int ibv_cmd_query_device_ex(struct ibv_context *context, struct ibv_device_attr_ex *attr, size_t attr_size, uint64_t *raw_fw_ver, struct ibv_query_device_ex *cmd, - size_t cmd_core_size, size_t cmd_size, struct ib_uverbs_ex_query_device_resp *resp, - size_t resp_core_size, size_t resp_size); int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num, struct ibv_port_attr *port_attr, @@ -501,10 +499,8 @@ int ibv_cmd_create_qp_ex2(struct ibv_context *context, struct verbs_qp *qp, int vqp_sz, struct ibv_qp_init_attr_ex *qp_attr, struct ibv_create_qp_ex *cmd, - size_t cmd_core_size, size_t cmd_size, struct ib_uverbs_ex_create_qp_resp *resp, - size_t resp_core_size, size_t resp_size); int ibv_cmd_open_qp(struct ibv_context *context, struct verbs_qp *qp, int vqp_sz, @@ -520,9 +516,9 @@ int ibv_cmd_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, struct ibv_modify_qp *cmd, size_t cmd_size); int ibv_cmd_modify_qp_ex(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask, struct ibv_modify_qp_ex *cmd, - size_t cmd_core_size, size_t cmd_size, + size_t cmd_size, struct ib_uverbs_ex_modify_qp_resp *resp, - size_t resp_core_size, size_t resp_size); + size_t resp_size); int ibv_cmd_destroy_qp(struct ibv_qp *qp); int ibv_cmd_post_send(struct ibv_qp *ibqp, struct ibv_send_wr *wr, struct ibv_send_wr **bad_wr); @@ -548,16 +544,13 @@ int ibv_cmd_create_wq(struct ibv_context *context, struct ibv_wq_init_attr *wq_init_attr, struct ibv_wq *wq, struct ibv_create_wq *cmd, - size_t cmd_core_size, size_t cmd_size, struct ib_uverbs_ex_create_wq_resp *resp, - size_t resp_core_size, size_t resp_size); int ibv_cmd_destroy_flow_action(struct verbs_flow_action *action); int ibv_cmd_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr, - struct ibv_modify_wq *cmd, size_t cmd_core_size, - size_t cmd_size); + struct ibv_modify_wq *cmd, size_t cmd_size); int ibv_cmd_destroy_wq(struct ibv_wq *wq); int ibv_cmd_create_rwq_ind_table(struct ibv_context *context, struct ibv_rwq_ind_table_init_attr *init_attr, diff --git a/libibverbs/ibverbs.h b/libibverbs/ibverbs.h index c70114f11e9bad..24843b49fdb3c7 100644 --- a/libibverbs/ibverbs.h +++ b/libibverbs/ibverbs.h @@ -37,9 +37,6 @@ #include #include - -#include - #include #define INIT __attribute__((constructor)) @@ -86,35 +83,4 @@ static inline const struct verbs_context_ops *get_ops(struct ibv_context *ctx) return &get_priv(ctx)->ops; } -static inline uint32_t _cmd_ex(uint32_t cmd) -{ - return IB_USER_VERBS_CMD_FLAG_EXTENDED | cmd; -} - -#define IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, size, opcode, out, resp_size,\ - outsize) \ - do { \ - size_t c_size = cmd_size - sizeof(struct ex_hdr); \ - (cmd)->hdr.hdr.command = \ - _cmd_ex(IB_USER_VERBS_EX_CMD_##opcode); \ - (cmd)->hdr.hdr.in_words = ((c_size) / 8); \ - (cmd)->hdr.hdr.out_words = ((resp_size) / 8); \ - (cmd)->hdr.ex_hdr.provider_in_words = (((size) - (cmd_size))/8);\ - (cmd)->hdr.ex_hdr.provider_out_words = \ - (((outsize) - (resp_size)) / 8); \ - (cmd)->hdr.ex_hdr.response = (uintptr_t) (out); \ - (cmd)->hdr.ex_hdr.cmd_hdr_reserved = 0; \ - } while (0) - -#define IBV_INIT_CMD_RESP_EX_VCMD(cmd, cmd_size, size, opcode, out, outsize) \ - IBV_INIT_CMD_RESP_EX_V(cmd, cmd_size, size, opcode, out, \ - sizeof(*(out)), outsize) - -#define IBV_INIT_CMD_RESP_EX(cmd, size, opcode, out, outsize) \ - IBV_INIT_CMD_RESP_EX_V(cmd, sizeof(*(cmd)), size, opcode, out, \ - sizeof(*(out)), outsize) - -#define IBV_INIT_CMD_EX(cmd, size, opcode) \ - IBV_INIT_CMD_RESP_EX_V(cmd, sizeof(*(cmd)), size, opcode, NULL, 0, 0) - #endif /* IB_VERBS_H */ diff --git a/providers/mlx4/verbs.c b/providers/mlx4/verbs.c index a88454e405c717..7a357b5da2759f 100644 --- a/providers/mlx4/verbs.c +++ b/providers/mlx4/verbs.c @@ -80,10 +80,8 @@ int mlx4_query_device_ex(struct ibv_context *context, int err; err = ibv_cmd_query_device_ex(context, input, attr, attr_size, - &raw_fw_ver, - &cmd.ibv_cmd, sizeof(cmd.ibv_cmd), sizeof(cmd), - &resp.ibv_resp, sizeof(resp.ibv_resp), - sizeof(resp)); + &raw_fw_ver, &cmd.ibv_cmd, sizeof(cmd), + &resp.ibv_resp, sizeof(resp)); if (err) return err; @@ -785,10 +783,9 @@ static int mlx4_cmd_create_qp_ex_rss(struct ibv_context *context, sizeof(cmd_ex.rx_hash_key)); ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp, - sizeof(qp->verbs_qp), attr, - &cmd_ex.ibv_cmd, sizeof(cmd_ex.ibv_cmd), + sizeof(qp->verbs_qp), attr, &cmd_ex.ibv_cmd, sizeof(cmd_ex), &resp.ibv_resp, - sizeof(resp.ibv_resp), sizeof(resp)); + sizeof(resp)); return ret; } @@ -841,10 +838,9 @@ static int mlx4_cmd_create_qp_ex(struct ibv_context *context, cmd_ex.drv_payload = cmd->drv_payload; ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp, - sizeof(qp->verbs_qp), attr, - &cmd_ex.ibv_cmd, sizeof(cmd_ex.ibv_cmd), + sizeof(qp->verbs_qp), attr, &cmd_ex.ibv_cmd, sizeof(cmd_ex), &resp.ibv_resp, - sizeof(resp.ibv_resp), sizeof(resp)); + sizeof(resp)); return ret; } @@ -1479,10 +1475,7 @@ struct ibv_wq *mlx4_create_wq(struct ibv_context *context, pthread_mutex_lock(&to_mctx(context)->qp_table_mutex); ret = ibv_cmd_create_wq(context, attr, &qp->wq, &cmd.ibv_cmd, - sizeof(cmd.ibv_cmd), - sizeof(cmd), - &resp, sizeof(resp), - sizeof(resp)); + sizeof(cmd), &resp, sizeof(resp)); if (ret) goto err_rq_db; @@ -1529,8 +1522,7 @@ int mlx4_modify_wq(struct ibv_wq *ibwq, struct ibv_wq_attr *attr) struct mlx4_modify_wq cmd = {}; int ret; - ret = ibv_cmd_modify_wq(ibwq, attr, &cmd.ibv_cmd, sizeof(cmd.ibv_cmd), - sizeof(cmd)); + ret = ibv_cmd_modify_wq(ibwq, attr, &cmd.ibv_cmd, sizeof(cmd)); if (!ret && (attr->attr_mask & IBV_WQ_ATTR_STATE) && (ibwq->state == IBV_WQS_RESET)) { diff --git a/providers/mlx5/verbs.c b/providers/mlx5/verbs.c index 22a3b9ff23c98c..9378c07e1ee2ba 100644 --- a/providers/mlx5/verbs.c +++ b/providers/mlx5/verbs.c @@ -1557,10 +1557,9 @@ static int mlx5_cmd_create_rss_qp(struct ibv_context *context, attr->rx_hash_conf.rx_hash_key_len); ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp, - sizeof(qp->verbs_qp), attr, - &cmd_ex_rss.ibv_cmd, sizeof(cmd_ex_rss.ibv_cmd), - sizeof(cmd_ex_rss), &resp.ibv_resp, - sizeof(resp.ibv_resp), sizeof(resp)); + sizeof(qp->verbs_qp), attr, + &cmd_ex_rss.ibv_cmd, sizeof(cmd_ex_rss), + &resp.ibv_resp, sizeof(resp)); if (ret) return ret; @@ -1588,10 +1587,9 @@ static int mlx5_cmd_create_qp_ex(struct ibv_context *context, cmd_ex.drv_payload = cmd->drv_payload; ret = ibv_cmd_create_qp_ex2(context, &qp->verbs_qp, - sizeof(qp->verbs_qp), attr, - &cmd_ex.ibv_cmd, sizeof(cmd_ex.ibv_cmd), + sizeof(qp->verbs_qp), attr, &cmd_ex.ibv_cmd, sizeof(cmd_ex), &resp->ibv_resp, - sizeof(resp->ibv_resp), sizeof(*resp)); + sizeof(*resp)); return ret; } @@ -2154,11 +2152,8 @@ static int modify_dct(struct ibv_qp *qp, struct ibv_qp_attr *attr, bool dct_create; int ret; - ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask, - &cmd_ex, - sizeof(cmd_ex), sizeof(cmd_ex), - &resp.ibv_resp, - sizeof(resp.ibv_resp), sizeof(resp)); + ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask, &cmd_ex, sizeof(cmd_ex), + &resp.ibv_resp, sizeof(resp)); if (ret) return ret; @@ -2249,11 +2244,8 @@ int mlx5_modify_qp(struct ibv_qp *qp, struct ibv_qp_attr *attr, } if (attr_mask & MLX5_MODIFY_QP_EX_ATTR_MASK) - ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask, - &cmd_ex, - sizeof(cmd_ex), sizeof(cmd_ex), - &resp, - sizeof(resp), sizeof(resp)); + ret = ibv_cmd_modify_qp_ex(qp, attr, attr_mask, &cmd_ex, + sizeof(cmd_ex), &resp, sizeof(resp)); else ret = ibv_cmd_modify_qp(qp, attr, attr_mask, &cmd, sizeof(cmd)); @@ -2320,10 +2312,8 @@ int mlx5_modify_qp_rate_limit(struct ibv_qp *qp, qp_attr.rate_limit = attr->rate_limit; ret = ibv_cmd_modify_qp_ex(qp, &qp_attr, IBV_QP_RATE_LIMIT, - &cmd.ibv_cmd, - sizeof(cmd.ibv_cmd), sizeof(cmd), - &resp, - sizeof(resp), sizeof(resp)); + &cmd.ibv_cmd, sizeof(cmd), &resp, + sizeof(resp)); return ret; } @@ -2816,11 +2806,10 @@ int mlx5_query_device_ex(struct ibv_context *context, memset(&cmd, 0, sizeof(cmd)); memset(&resp, 0, sizeof(resp)); - err = ibv_cmd_query_device_ex(context, input, attr, attr_size, - &raw_fw_ver, - &cmd.ibv_cmd, sizeof(cmd.ibv_cmd), sizeof(cmd), - &resp.ibv_resp, sizeof(resp.ibv_resp), - cmd_supp_uhw ? sizeof(resp) : sizeof(resp.ibv_resp)); + err = ibv_cmd_query_device_ex( + context, input, attr, attr_size, &raw_fw_ver, &cmd.ibv_cmd, + sizeof(cmd), &resp.ibv_resp, + cmd_supp_uhw ? sizeof(resp) : sizeof(resp.ibv_resp)); if (err) return err; @@ -3018,10 +3007,7 @@ static struct ibv_wq *create_wq(struct ibv_context *context, } err = ibv_cmd_create_wq(context, attr, &rwq->wq, &cmd.ibv_cmd, - sizeof(cmd.ibv_cmd), - sizeof(cmd), - &resp.ibv_resp, sizeof(resp.ibv_resp), - sizeof(resp)); + sizeof(cmd), &resp.ibv_resp, sizeof(resp)); if (err) goto err_create; @@ -3077,7 +3063,7 @@ int mlx5_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr) } } - return ibv_cmd_modify_wq(wq, attr, &cmd.ibv_cmd, sizeof(cmd.ibv_cmd), sizeof(cmd)); + return ibv_cmd_modify_wq(wq, attr, &cmd.ibv_cmd, sizeof(cmd)); } int mlx5_destroy_wq(struct ibv_wq *wq) 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; } From patchwork Thu Nov 22 23:24:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694975 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 0E5AD13B5 for ; Thu, 22 Nov 2018 23:24:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1BA12BF0F for ; Thu, 22 Nov 2018 23:24:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E608C2C2F0; Thu, 22 Nov 2018 23:24:23 +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 711D22BF0F for ; Thu, 22 Nov 2018 23:24:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2407879AbeKWKGE (ORCPT ); Fri, 23 Nov 2018 05:06:04 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:32982 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389637AbeKWKGE (ORCPT ); Fri, 23 Nov 2018 05:06:04 -0500 Received: by mail-pf1-f193.google.com with SMTP id c123so1797257pfb.0 for ; Thu, 22 Nov 2018 15:24:21 -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=c/bwxF/BAuF+3s7oqIGh60IYXquCwd4ZbG1fzFP5T28=; b=Vf0TSo1JL8Jspj32wUuBILlPAD3x0kewOMOJkNp/YM9XX0jp95/3ceJAka5Yny62YR CFEAQoo0+sfiZnxS98q0v8U9TvRR5ZeVk9Mi3Tuyi94IHlOtEhFietLbdzksT4hcS7Zr PGUwxiHpJtMRAJjn9FnHNSca5ipgbmMWyxWaeev9GCxNbT5AVuStpw8QJN125bk5YhRH +9spOXUbnTEd6S3fNAyn8sFcNChwU5QBJ8XeCaU8vLtN2T0y7+Rtl9ZSwB7RzrgzjKoE sPUZrIVSkThgH/3vvoiCTopnHzCXuSQGT1A+ZfosIMxL9V4nsq0VbnXxSEsSdS7HEFEn oExw== 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=c/bwxF/BAuF+3s7oqIGh60IYXquCwd4ZbG1fzFP5T28=; b=KflUU9RuQ4dNEwobEcmoxHZt47sjhXI323E71ghbXmUOV9TIPQzetowKPKb5SRh1ng xt3+jC8nXNsVV/OnMeATKuux11P5LpgvJZUooN6LVw6+ROet3GRItX+5nTpecC07fo/z EFz9LBPn19IJDgA0bZ7WfFqsmHg8d6S9kBfHjzbI8+GOE/asdR1R6dkEFJOj0kXEtDU+ spD+xfK7/pfmNBUybmcjMu1n/88Tle9VzqIsNujt98kIOyvAvzXHBQfjtGzP3ARbHby0 nlMEU38YmxyXpouqmL3NtFvFOoeyzjziHYx22kMoO+B/FpwyfHsBOVrjSBYEuGi5+bnw StyQ== X-Gm-Message-State: AA+aEWbNFJf7gBI0fnfaWAQoYAuI8b6RKK9zCNJz0o5/8EiPQ1IwBb/f c4qQE8wkT8qdOSN8QgYRH23ogjfts/g= X-Google-Smtp-Source: AFSGD/VLtCPadUhI99MiuAcVJzJPpLzIltZBs2bcbgTT793lCuOnyCCwFOSex4sXDnfndxeRPcw/Qw== X-Received: by 2002:a63:2744:: with SMTP id n65mr11689032pgn.65.1542929060812; Thu, 22 Nov 2018 15:24:20 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id g14-v6sm50303520pfg.98.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-0007tB-KG; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 09/10] verbs: Replace execute_write_ex with execute_cmd_ex/_resp Date: Thu, 22 Nov 2018 16:24:15 -0700 Message-Id: <20181122232416.30132-10-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 Create consistency with all the other ways to invoke write(). Signed-off-by: Jason Gunthorpe --- libibverbs/cmd.c | 24 +++++++++++++++--------- libibverbs/cmd_write.h | 26 -------------------------- 2 files changed, 15 insertions(+), 35 deletions(-) diff --git a/libibverbs/cmd.c b/libibverbs/cmd.c index 4679ea673d2cba..a824202e7dbd5f 100644 --- a/libibverbs/cmd.c +++ b/libibverbs/cmd.c @@ -1853,13 +1853,15 @@ int ibv_cmd_create_flow(struct ibv_qp *qp, int ibv_cmd_destroy_flow(struct ibv_flow *flow_id) { - DECLARE_LEGACY_CORE_BUFS_EX(IB_USER_VERBS_EX_CMD_DESTROY_FLOW); + struct ibv_destroy_flow req; int ret; - *req = (struct ib_uverbs_destroy_flow){ + req.core_payload = (struct ib_uverbs_destroy_flow){ .flow_handle = flow_id->handle, }; - ret = execute_write_ex(flow_id->context, req); + ret = execute_cmd_write_ex_req(flow_id->context, + IB_USER_VERBS_EX_CMD_DESTROY_FLOW, &req, + sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; @@ -1947,14 +1949,16 @@ int ibv_cmd_modify_wq(struct ibv_wq *wq, struct ibv_wq_attr *attr, int ibv_cmd_destroy_wq(struct ibv_wq *wq) { - DECLARE_LEGACY_CORE_BUFS_EX(IB_USER_VERBS_EX_CMD_DESTROY_WQ); + struct ibv_destroy_wq req; + struct ib_uverbs_ex_destroy_wq_resp resp; int ret; - *req = (struct ib_uverbs_ex_destroy_wq){ + req.core_payload = (struct ib_uverbs_ex_destroy_wq){ .wq_handle = wq->handle, }; - ret = execute_write_ex(wq->context, req); + ret = execute_cmd_write_ex(wq->context, IB_USER_VERBS_EX_CMD_DESTROY_WQ, + &req, sizeof(req), &resp, sizeof(resp)); if (verbs_is_destroy_err(&ret)) return ret; @@ -2015,13 +2019,15 @@ 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); + struct ibv_destroy_rwq_ind_table req; int ret; - *req = (struct ib_uverbs_ex_destroy_rwq_ind_table){ + req.core_payload = (struct ib_uverbs_ex_destroy_rwq_ind_table){ .ind_tbl_handle = rwq_ind_table->ind_tbl_handle, }; - ret = execute_write_ex(rwq_ind_table->context, req); + ret = execute_cmd_write_ex_req(rwq_ind_table->context, + IB_USER_VERBS_EX_CMD_DESTROY_RWQ_IND_TBL, + &req, sizeof(req)); if (verbs_is_destroy_err(&ret)) return ret; diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index a585b4acd660ad..88ff66600bc118 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -157,32 +157,6 @@ int _execute_write_raw_ex(struct ibv_context *ctx, struct ex_hdr *req); #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_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_ex(ctx, req) \ - _execute_write_raw_ex(ctx, get_req_hdr_ex(req)) - /* * For write() only commands that have fixed core structures and may take uhw * driver data. The last arguments are the same ones passed into the typical From patchwork Thu Nov 22 23:24:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 10694993 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 BD82E13B5 for ; Thu, 22 Nov 2018 23:24:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB6642BF0F for ; Thu, 22 Nov 2018 23:24:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FDFB2C196; Thu, 22 Nov 2018 23:24:30 +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 6823E2C3A2 for ; Thu, 22 Nov 2018 23:24:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439029AbeKWKGJ (ORCPT ); Fri, 23 Nov 2018 05:06:09 -0500 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38598 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407882AbeKWKGJ (ORCPT ); Fri, 23 Nov 2018 05:06:09 -0500 Received: by mail-pf1-f196.google.com with SMTP id q1so2495155pfi.5 for ; Thu, 22 Nov 2018 15:24:25 -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=e40MdpIfycy9zo/lPd9LlFnB8JQYNisvvPKWuENOMlU=; b=BFGBDzsbCB3SKeNiSwo1WAUxUuEM/iQ/Fl6wh3DAT9+41mbiGkEFYJ9xulHRvJD1c1 yFYk9ZtzpUY5DUJH3Nwb7syDjkl9iLuo1U2KyT42Bx4jkVAYDSZ0cif/zH5p6vrlwOvR 4zEQpNzzDWRfNnGT07WJr971OJGw5Lt/yJ0jlStpG0bYmOXvsbOdAl3DFjUofWUTv4bS TgL0G/fTlx5rrvMJsy6a8V9BtrHQiBlBdvhgeKMkM75yC3nZPl2Vhh8u+oYS+6Ih8zp9 9vmLm7zV0eLhQRnkyA+aRJhMN5Zavs1tBzShmZmuVCQUMjuwBrOInzwKGBcHlPMG1DUL 4wfw== 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=e40MdpIfycy9zo/lPd9LlFnB8JQYNisvvPKWuENOMlU=; b=Kd/OIsLKRPf2s63ponIwqhEvB+TJv6uBnNdYrrxFVyZqt8tsEOfCLHG5mv+cPP1cy0 6iOKvvB/MILBojF5LnQ3vMsm9ow9RhVrhf+Sw3LgpGVpFs83iE3His1ytQ9XvZ37UiLZ VdDyBAjK1Dmoh1a0COE4pAMpEcTGrLmTEmo+rvwQ5sc8r+MX9MyeWsyOZU/Nog/DDatT cywZo+/6xkzOCmMNpos9vBNY7dToc2uqSL5n8nS6ikZvG2a1rSx9oZ6ZnNJp2ezRfBZj sdW7Fo2+9ZrLAUgEEk3nt7pgpPbpcytOXbpqp3MqavvHWDjcAj+M8EOI+fxRWnq5HJL3 ki3g== X-Gm-Message-State: AGRZ1gL1NYTPEP5bVmP2xLChjJLskl6DFFuPCM1+z2L2T2gaZyBWSfDO xRro36KBXy74QL4Cv8itcMpVKMIiBNY= X-Google-Smtp-Source: AJdET5fmUGp1uTtcRZ+mpltlevpgfZw56M132t5DlpvUc88xVZDVkXsCzRab+T7YqLMm7pXplsqMkw== X-Received: by 2002:a62:130c:: with SMTP id b12mr13444281pfj.247.1542929064805; Thu, 22 Nov 2018 15:24:24 -0800 (PST) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id i62sm34923189pge.44.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-0007tH-Ln; Thu, 22 Nov 2018 16:24:18 -0700 From: Jason Gunthorpe To: linux-rdma@vger.kernel.org Cc: Jason Gunthorpe Subject: [PATCH rdma-core 10/10] verbs: use the execute_cmd_write/_ex path for the ioctl fallback Date: Thu, 22 Nov 2018 16:24:16 -0700 Message-Id: <20181122232416.30132-11-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 This is slightly less efficient than the old path, but it creates only two places where write() are called. Signed-off-by: Jason Gunthorpe --- libibverbs/cmd_cq.c | 6 ++- libibverbs/cmd_fallback.c | 68 +------------------------------- libibverbs/cmd_write.h | 83 +++++++++++++++++++++------------------ 3 files changed, 51 insertions(+), 106 deletions(-) diff --git a/libibverbs/cmd_cq.c b/libibverbs/cmd_cq.c index 03e5ca4c5e13bf..542daa7b63936f 100644 --- a/libibverbs/cmd_cq.c +++ b/libibverbs/cmd_cq.c @@ -69,7 +69,8 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe, .comp_channel = channel ? channel->fd : -1, }; - ret = execute_write_bufs(cq->context, req, resp); + ret = execute_write_bufs( + cq->context, IB_USER_VERBS_CMD_CREATE_CQ, req, resp); if (ret) return ret; @@ -90,7 +91,8 @@ static int ibv_icmd_create_cq(struct ibv_context *context, int cqe, .flags = flags, }; - ret = execute_write_bufs_ex(cq->context, req); + ret = execute_write_bufs_ex( + cq->context, IB_USER_VERBS_EX_CMD_CREATE_CQ, req, resp); if (ret) return ret; diff --git a/libibverbs/cmd_fallback.c b/libibverbs/cmd_fallback.c index cad8b21756a6a6..0e50503e003484 100644 --- a/libibverbs/cmd_fallback.c +++ b/libibverbs/cmd_fallback.c @@ -120,8 +120,7 @@ enum write_fallback _execute_ioctl_fallback(struct ibv_context *ctx, * directly before the UHW memory (see _write_set_uhw) */ 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 *onstack, size_t size) { struct ib_uverbs_cmd_hdr *hdr; @@ -139,13 +138,11 @@ void *_write_get_req(struct ibv_command_buffer *link, hdr->in_words = __check_divide(size, 4); } - hdr->command = cmdnum; - return hdr + 1; } void *_write_get_req_ex(struct ibv_command_buffer *link, struct ex_hdr *onstack, - size_t size, uint32_t cmdnum) + size_t size) { struct ex_hdr *hdr; size_t full_size = size + sizeof(*hdr); @@ -156,17 +153,12 @@ void *_write_get_req_ex(struct ibv_command_buffer *link, struct ex_hdr *onstack, assert(uhw->attr_id == UVERBS_ATTR_UHW_IN); assert(link->uhw_in_headroom_dwords * 4 >= full_size); hdr = (void *)((uintptr_t)uhw->data - full_size); - hdr->hdr.in_words = __check_divide(size, 8); hdr->ex_hdr.provider_in_words = __check_divide(uhw->len, 8); } else { hdr = onstack; - hdr->hdr.in_words = __check_divide(size, 8); 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; } @@ -205,46 +197,15 @@ void *_write_get_resp_ex(struct ibv_command_buffer *link, assert(uhw->attr_id == UVERBS_ATTR_UHW_OUT); assert(link->uhw_out_headroom_dwords * 4 >= resp_size); resp_start = (void *)((uintptr_t)uhw->data - resp_size); - hdr->hdr.out_words = __check_divide(resp_size, 8); hdr->ex_hdr.provider_out_words = __check_divide(uhw->len, 8); } else { resp_start = onstack; - hdr->hdr.out_words = __check_divide(resp_size, 8); hdr->ex_hdr.provider_out_words = 0; } - hdr->ex_hdr.response = ioctl_ptr_to_u64(resp_start); - return resp_start; } -int _execute_write_raw(struct ibv_context *ctx, struct ib_uverbs_cmd_hdr *hdr, - void *resp) -{ - /* - * Users assumes the stack buffer is zeroed before passing to the - * kernel for writing. - */ - 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; - - if (resp) - VALGRIND_MAKE_MEM_DEFINED(resp, hdr->out_words * 4); - - return 0; -} - int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, struct ib_uverbs_cmd_hdr *req, size_t core_req_size, size_t req_size, void *resp, size_t core_resp_size, @@ -262,31 +223,6 @@ int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, return 0; } -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; - void *resp = (void *)(uintptr_t)hdr->ex_hdr.response; - - /* - * Users assumes the stack buffer is zeroed before passing to the - * kernel for writing. - */ - if (resp) - memset(resp, 0, resp_bytes); - - if (write(ctx->cmd_fd, hdr, write_bytes) != write_bytes) - return errno; - - if (resp) - VALGRIND_MAKE_MEM_DEFINED(resp, resp_bytes); - - return 0; -} - /* * req_size is the total length of the ex_hdr, core payload and driver data. * core_req_size is the total length of the ex_hdr and core_payload. diff --git a/libibverbs/cmd_write.h b/libibverbs/cmd_write.h index 88ff66600bc118..1d8c462522e2a9 100644 --- a/libibverbs/cmd_write.h +++ b/libibverbs/cmd_write.h @@ -40,21 +40,10 @@ #include -static inline struct ib_uverbs_cmd_hdr *get_req_hdr(void *req) -{ - return ((struct ib_uverbs_cmd_hdr *)req) - 1; -} - -static inline struct ex_hdr *get_req_hdr_ex(void *req) -{ - return ((struct ex_hdr *)req) - 1; -} - 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 *onstack, size_t size); void *_write_get_req_ex(struct ibv_command_buffer *link, struct ex_hdr *onstack, - size_t size, uint32_t cmdnum); + size_t size); void *_write_get_resp(struct ibv_command_buffer *link, struct ib_uverbs_cmd_hdr *hdr, void *onstack, size_t resp_size); @@ -71,23 +60,26 @@ void *_write_get_resp_ex(struct ibv_command_buffer *link, #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_REQ(_enum) *req = \ + _write_get_req(_link, &__req_onstack.hdr, sizeof(*req)); \ IBV_KABI_RESP(_enum) *resp = ({ \ - void *_resp = _write_get_resp(_link, get_req_hdr(req), \ - &__resp_onstack, sizeof(*resp)); \ + void *_resp = _write_get_resp( \ + _link, \ + &container_of(req, IBV_ABI_REQ(_enum), core_payload) \ + ->hdr, \ + &__resp_onstack, sizeof(*resp)); \ _resp; \ }) #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_REQ(_enum) *req = \ + _write_get_req_ex(_link, &__req_onstack.hdr, sizeof(*req)); \ IBV_KABI_RESP(_enum) *resp = _write_get_resp_ex( \ - _link, get_req_hdr_ex(req), &__resp_onstack, sizeof(*resp)) + _link, \ + &container_of(req, IBV_ABI_REQ(_enum), core_payload)->hdr, \ + &__resp_onstack, sizeof(*resp)) /* * This macro is used to implement the compatibility command call wrappers. @@ -143,20 +135,6 @@ enum write_fallback _execute_ioctl_fallback(struct ibv_context *ctx, #define execute_ioctl_fallback(ctx, cmd_name, cmdb, ret) \ _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(struct ibv_context *ctx, struct ib_uverbs_cmd_hdr *req, - void *resp); - -/* For users of DECLARE_LEGACY_UHW_BUFS */ -#define execute_write_bufs(ctx, req, resp) \ - _execute_write_raw(ctx, get_req_hdr(req), 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(ctx, req) \ - _execute_write_raw_ex(ctx, get_req_hdr_ex(req)) - /* * For write() only commands that have fixed core structures and may take uhw * driver data. The last arguments are the same ones passed into the typical @@ -206,6 +184,18 @@ int _execute_cmd_write(struct ibv_context *ctx, unsigned int write_method, resp_size, resp_size); \ }) +/* + * For users of DECLARE_LEGACY_UHW_BUFS, in this case the machinery has + * already stored the full req/resp length in the hdr. + */ +#define execute_write_bufs(ctx, enum, req, resp) \ + ({ \ + IBV_ABI_REQ(enum) *_hdr = \ + container_of(req, IBV_ABI_REQ(enum), core_payload); \ + execute_cmd_write(ctx, enum, _hdr, _hdr->hdr.in_words * 4, \ + resp, _hdr->hdr.out_words * 4); \ + }) + /* * For write() commands that use the _ex protocol. _full allows the caller to * specify all 4 sizes directly. This version is used when the core structs @@ -236,6 +226,20 @@ int _execute_cmd_write_ex(struct ibv_context *ctx, unsigned int write_method, sizeof(*(cmd)), cmd_size, NULL, 0, 0); \ }) +/* For users of DECLARE_LEGACY_UHW_BUFS_EX */ +#define execute_write_bufs_ex(ctx, enum, req, resp) \ + ({ \ + IBV_ABI_REQ(enum) *_hdr = \ + container_of(req, IBV_ABI_REQ(enum), core_payload); \ + execute_cmd_write_ex( \ + ctx, enum, _hdr, \ + sizeof(*_hdr) + \ + _hdr->hdr.ex_hdr.provider_in_words * 8, \ + resp, \ + sizeof(*(resp)) + \ + _hdr->hdr.ex_hdr.provider_out_words * 8); \ + }) + /* * These two macros are used only with execute_ioctl_fallback - they allow the * IOCTL code to be elided by the compiler when disabled. @@ -263,14 +267,17 @@ _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(struct ibv_context *ctx, void *req, +static inline int execute_write_bufs(struct ibv_context *ctx, + unsigned int write_command, void *req, void *resp) { return ENOSYS; } #undef execute_write_bufs_ex -static inline int execute_write_bufs_ex(struct ibv_context *ctx, void *req) +static inline int execute_write_bufs_ex(struct ibv_context *ctx, + unsigned int write_command, void *req, + void *resp) { return ENOSYS; }