From patchwork Thu Sep 20 17:08:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10608237 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 5EE386CB for ; Thu, 20 Sep 2018 17:08:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 490E52E259 for ; Thu, 20 Sep 2018 17:08:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D04E2E25F; Thu, 20 Sep 2018 17:08:56 +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 2BD092E259 for ; Thu, 20 Sep 2018 17:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731520AbeITWxU (ORCPT ); Thu, 20 Sep 2018 18:53:20 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36021 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeITWxU (ORCPT ); Thu, 20 Sep 2018 18:53:20 -0400 Received: by mail-wr1-f68.google.com with SMTP id e1-v6so10185444wrt.3 for ; Thu, 20 Sep 2018 10:08:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dmnTugGbvgb1lV78aN61zqtM3RQJsUNaFUKSiVDGApI=; b=L2LCt/nm3FzfU5LPZcVw/DsxIpXuFklGS8Rl0nG7+syy2IcoN2o8mZY5bMK4oucoIQ rDK8RG/SegI8WWEjRudZnxb31E4K06SyPiXRidwGyjWZDcTxDfDCIa8nHUZWgU6C4N+T HiAZHqF4PnsI6Ok515nJZUMMb0snDKpDKlrNs= 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; bh=dmnTugGbvgb1lV78aN61zqtM3RQJsUNaFUKSiVDGApI=; b=nyaFXVx9eFejLwsUWXRyZokjHx5gOUlLPiFzaLRQi3WwBIBqvAxe24tpF2J8m2ItcS E4r5EL7PuHYRz+SIGdBMMqCnFjtv5cENUTHv28nvyjB9aJLAnE/QAtq7duEMhcsxjZf8 iCMfiKvaADVCfJa1UGu+3JclFPFfrsuo0ael8jqq51SO/VT6KZQTUElt8iJtrRRUmo/p wMpg9U2fH9aMP6z8xb3nufpb2lJNGJc+/34EZac9NavTaKhkyURmE8a19ibwsu085CBc w4JkUSiuw6v1tjpZw6nWmFFe1zs/swpouHRqFpZnbAth/vscFJMqrRkQPTmLYpquh3ge lucw== X-Gm-Message-State: APzg51CDSeGtpbnT8qpWffdKWvxoBPT4bqe7fr192DpMQAJ7Eme4Pj2z oFaFRivBpp8BAXVRr24VWcM6TQ== X-Google-Smtp-Source: ANB0VdZE+u+n0kNXh88Q6IIJMehiFaghyDlIujOP6RFm+UgUxCxVbMkDI3rh91qEaBAVnvDI8qprjg== X-Received: by 2002:a5d:6b01:: with SMTP id v1-v6mr16472704wrw.208.1537463331750; Thu, 20 Sep 2018 10:08:51 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id v133-v6sm3458232wma.36.2018.09.20.10.08.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 10:08:51 -0700 (PDT) From: Devesh Sharma To: jgg@mellanox.com, dledford@redhat.com Cc: linux-rdma@vger.kernel.org, NMoreyChaisemartin@suse.de, Devesh Sharma , Jonathan Richardson , JD Zheng Subject: [PATCH rdma-core 1/4] bnxt_re/lib: Reduce memory barrier calls Date: Thu, 20 Sep 2018 13:08:31 -0400 Message-Id: <1537463314-7807-2-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> References: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move wmb calls (ring doorbell) out of the loop when processing work requests in post send. This reduces the number of calls and increases performance. in some cases it improves the performance by 35%. Signed-off-by: Jonathan Richardson Signed-off-by: JD Zheng Signed-off-by: Devesh Sharma --- providers/bnxt_re/verbs.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index 0036cc5..9ce1454 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -1222,31 +1222,32 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr, struct bnxt_re_bsqe *hdr; struct bnxt_re_wrid *wrid; struct bnxt_re_psns *psns; - void *sqe; - int ret = 0, bytes = 0; uint8_t is_inline = false; + int ret = 0, bytes = 0; + bool ring_db = false; + void *sqe; pthread_spin_lock(&sq->qlock); while (wr) { if ((qp->qpst != IBV_QPS_RTS) && (qp->qpst != IBV_QPS_SQD)) { *bad = wr; - pthread_spin_unlock(&sq->qlock); - return EINVAL; + ret = EINVAL; + goto bad_wr; } if ((qp->qptyp == IBV_QPT_UD) && (wr->opcode != IBV_WR_SEND && wr->opcode != IBV_WR_SEND_WITH_IMM)) { *bad = wr; - pthread_spin_unlock(&sq->qlock); - return EINVAL; + ret = EINVAL; + goto bad_wr; } if (bnxt_re_is_que_full(sq) || wr->num_sge > qp->cap.max_ssge) { *bad = wr; - pthread_spin_unlock(&sq->qlock); - return ENOMEM; + ret = ENOMEM; + goto bad_wr; } sqe = (void *)(sq->va + (sq->tail * sq->stride)); @@ -1305,9 +1306,10 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr, bnxt_re_incr_tail(sq); qp->wqe_cnt++; wr = wr->next; - bnxt_re_ring_sq_db(qp); - if (qp->wqe_cnt == BNXT_RE_UD_QP_HW_STALL && qp->qptyp == - IBV_QPT_UD) { + ring_db = true; + + if (qp->wqe_cnt == BNXT_RE_UD_QP_HW_STALL && + qp->qptyp == IBV_QPT_UD) { /* Move RTS to RTS since it is time. */ struct ibv_qp_attr attr; int attr_mask; @@ -1319,6 +1321,10 @@ int bnxt_re_post_send(struct ibv_qp *ibvqp, struct ibv_send_wr *wr, } } +bad_wr: + if (ring_db) + bnxt_re_ring_sq_db(qp); + pthread_spin_unlock(&sq->qlock); return ret; } From patchwork Thu Sep 20 17:08:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10608239 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 0C02314DA for ; Thu, 20 Sep 2018 17:09:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB2642E259 for ; Thu, 20 Sep 2018 17:09:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF1112E25F; Thu, 20 Sep 2018 17:09:00 +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 C12322E259 for ; Thu, 20 Sep 2018 17:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728997AbeITWxZ (ORCPT ); Thu, 20 Sep 2018 18:53:25 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40580 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeITWxY (ORCPT ); Thu, 20 Sep 2018 18:53:24 -0400 Received: by mail-wr1-f67.google.com with SMTP id y8-v6so6520231wrh.7 for ; Thu, 20 Sep 2018 10:08:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TM9ewyNVC7zUzXF5PqhW3Uv0LjjZ2WKk9uV2hty3eEs=; b=JlRz9+8DzV33IcI8Sc7x9DUQUO5Yu5lA74fprkoMn/YcNUz7UA+xmkm0LsTC64c/YC Q0f+wa76yPyn+Pb4tlwSj1F3XCedtw1XZpyP2nez+S39ysQcy991+o24IvB2m85g2i04 7HuTve+g9ueFOtfdxI8W8f7YXxjMM7sNq/KWs= 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; bh=TM9ewyNVC7zUzXF5PqhW3Uv0LjjZ2WKk9uV2hty3eEs=; b=nw9HMMT/BYXB8vE5XrAnhT0OXukTam7Pio6m4fNxnyS3p6WKH7ypnsuFtQcteBXeVd /Vv5BSyw9CGMHmV7TVrO3IyBRqEtM26hM/M/rlDVizvjaTaaVuJ+0cD/+I8gP6Yoaqe0 rLziAKXi19fAPXV4avF8rC0p/20HfZ2PdXBVFA9cBBIhP/blVGqLr4cMpj+0uY1lbfTS k2wuk5Sri+p2ewPliRmxkPvb/+1gLtmddXRbKGpPRaV/d+fhf1NYAKyCRXyb2eoXO87P yu4m0AgzDgjS308/oBvHbtgGGLrjWlJanyzCdwXEnQsI1cDesOWoIObcDK5A4zIZnzEH sihw== X-Gm-Message-State: APzg51CvQu3snEg5j2nyBuxQyZj7upgsxmjli8s1PM+whol4JraJVXOR jP/6Z0d648BeHAQpr6xG2VBcDg== X-Google-Smtp-Source: ANB0VdYVmwAamlQtA3Hxf64uGRF5bFLEUPN28eWPhDDX4EhgLrf9qwsOYltw84kar9Xh8nIQ9H93BA== X-Received: by 2002:adf:ed88:: with SMTP id c8-v6mr34480220wro.264.1537463336579; Thu, 20 Sep 2018 10:08:56 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id v133-v6sm3458232wma.36.2018.09.20.10.08.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 10:08:55 -0700 (PDT) From: Devesh Sharma To: jgg@mellanox.com, dledford@redhat.com Cc: linux-rdma@vger.kernel.org, NMoreyChaisemartin@suse.de, Devesh Sharma , JD Zheng , Jonathan Richardson Subject: [PATCH rdma-core 2/4] bnxt_re/lib: Remove db_lock around doorbell ring Date: Thu, 20 Sep 2018 13:08:32 -0400 Message-Id: <1537463314-7807-3-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> References: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Remove the lock around the doorbell. It isn't necessary and was a bottleneck for multithreaded clients. Performance of spdk improves by 40% with it removed. Signed-off-by: JD Zheng Signed-off-by: Jonathan Richardson Signed-off-by: Devesh Sharma --- providers/bnxt_re/db.c | 2 -- providers/bnxt_re/main.c | 1 - providers/bnxt_re/main.h | 1 - providers/bnxt_re/verbs.c | 2 -- 4 files changed, 6 deletions(-) diff --git a/providers/bnxt_re/db.c b/providers/bnxt_re/db.c index a79f871..2896ceb 100644 --- a/providers/bnxt_re/db.c +++ b/providers/bnxt_re/db.c @@ -44,11 +44,9 @@ static void bnxt_re_ring_db(struct bnxt_re_dpi *dpi, { __le64 *dbval; - pthread_spin_lock(&dpi->db_lock); dbval = (__le64 *)&hdr->indx; udma_to_device_barrier(); iowrite64(dpi->dbpage, dbval); - pthread_spin_unlock(&dpi->db_lock); } static void bnxt_re_init_db_hdr(struct bnxt_re_db_hdr *hdr, uint32_t indx, diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c index 54e3cc3..a1ba06a 100644 --- a/providers/bnxt_re/main.c +++ b/providers/bnxt_re/main.c @@ -167,7 +167,6 @@ static void bnxt_re_free_context(struct ibv_context *ibvctx) * allocated in this context. */ if (cntx->udpi.dbpage && cntx->udpi.dbpage != MAP_FAILED) { - pthread_spin_destroy(&cntx->udpi.db_lock); munmap(cntx->udpi.dbpage, dev->pg_size); cntx->udpi.dbpage = NULL; } diff --git a/providers/bnxt_re/main.h b/providers/bnxt_re/main.h index 16f55f9..0b5c749 100644 --- a/providers/bnxt_re/main.h +++ b/providers/bnxt_re/main.h @@ -59,7 +59,6 @@ struct bnxt_re_dpi { __u32 dpindx; __u64 *dbpage; - pthread_spinlock_t db_lock; }; struct bnxt_re_pd { diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index 9ce1454..8e9fd8c 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -110,8 +110,6 @@ struct ibv_pd *bnxt_re_alloc_pd(struct ibv_context *ibvctx) (void)ibv_cmd_dealloc_pd(&pd->ibvpd); goto out; } - pthread_spin_init(&cntx->udpi.db_lock, - PTHREAD_PROCESS_PRIVATE); } return &pd->ibvpd; From patchwork Thu Sep 20 17:08:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10608241 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 4F5D214DA for ; Thu, 20 Sep 2018 17:09:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38B822E259 for ; Thu, 20 Sep 2018 17:09:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CC6A2E25F; Thu, 20 Sep 2018 17:09:03 +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 D9ED32E259 for ; Thu, 20 Sep 2018 17:09:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727746AbeITWx2 (ORCPT ); Thu, 20 Sep 2018 18:53:28 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40585 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeITWx2 (ORCPT ); Thu, 20 Sep 2018 18:53:28 -0400 Received: by mail-wr1-f66.google.com with SMTP id y8-v6so6520412wrh.7 for ; Thu, 20 Sep 2018 10:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JlA0FgK0MhyHqAmlZKl1AT0XWSwuLQftS+GW37q8utQ=; b=bvfJaRuUcYwYEpI6FeOwnnxAhXZcwibxiugEJA1zVYj21KsFKCUW/ITEO23f8RWKzc 08Z0dCON7v2+2FOFpBqY5nLi3Eg3VmOxSiJmhHe2RyT1FZmbLi+Io/beCVICJarA78jY eUdOZpTzT1+uAR2zM0ZAgb2S3VlQzNtZHhs5U= 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; bh=JlA0FgK0MhyHqAmlZKl1AT0XWSwuLQftS+GW37q8utQ=; b=OzdLw4JdVSr6udPWxPp+IYq8xKhHX8VafZ58p75npx1vQXQtL318XgRtMRAOo4oF17 O+T2dDdcBKoPmMI2ZKLZybn5oTcqQ0tkthwvTBkldGNPhmov5IMQnKUMnB9nWKVVlzSX f1JHWNhF6mdvZdZh7eji0kmsDpPysIIWhP09veGVKvte/ZxZw4eOZbdK4MvSyXHmRncM k3QjeWzJkZEx3tfZ2zbToyeOm8oInSzrikLprPKfO2dqmsZgjYS/EamPpMLAwkPBPlQX FSHiBQJkjm2jW+p7xH3pSMSPuu6n/vVPAdsz1BhPfunC1QDNNjUPAl0HBBiomddi3gpH SGNA== X-Gm-Message-State: APzg51DxVHUxIhAv98BSzSdBPMkgBzmlGOLM9alpVE5vBR+mjKq/+ZEW iW9UqN7ljuLYMCO3hGDG4f3uUQ== X-Google-Smtp-Source: ANB0VdY0kn3WfLoN44ddyttBOiEIxG4Ndx/q32BI/qDoPYPDZ7G/IZFid0G1u0CjP/Rk4rCZBuQWCg== X-Received: by 2002:a5d:6b01:: with SMTP id v1-v6mr16473449wrw.208.1537463340359; Thu, 20 Sep 2018 10:09:00 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id v133-v6sm3458232wma.36.2018.09.20.10.08.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 10:08:59 -0700 (PDT) From: Devesh Sharma To: jgg@mellanox.com, dledford@redhat.com Cc: linux-rdma@vger.kernel.org, NMoreyChaisemartin@suse.de, Devesh Sharma Subject: [PATCH rdma-core 3/4] bnxt_re/lib: Fix the frequency of acquiring flush lock Date: Thu, 20 Sep 2018 13:08:33 -0400 Message-Id: <1537463314-7807-4-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> References: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The flush lock should be tried only if there is some room left in the WC array supplied from consumer. Signed-off-by: Devesh Sharma --- providers/bnxt_re/verbs.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index 8e9fd8c..570dfc1 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -686,12 +686,13 @@ int bnxt_re_poll_cq(struct ibv_cq *ibvcq, int nwc, struct ibv_wc *wc) cq->deferred_arm_flags = 0; } pthread_spin_unlock(&cq->cqq.qlock); - /* Check if anything is there to flush. */ - pthread_spin_lock(&cntx->fqlock); left = nwc - dqed; - if (left) + if (left) { + /* Check if anything is there to flush. */ + pthread_spin_lock(&cntx->fqlock); dqed += bnxt_re_poll_flush_lists(cq, left, (wc + dqed)); - pthread_spin_unlock(&cntx->fqlock); + pthread_spin_unlock(&cntx->fqlock); + } return dqed; } From patchwork Thu Sep 20 17:08:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10608243 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 B52AF6CB for ; Thu, 20 Sep 2018 17:09:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9EB472E259 for ; Thu, 20 Sep 2018 17:09:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9348C2E25F; Thu, 20 Sep 2018 17:09:08 +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 840C32E259 for ; Thu, 20 Sep 2018 17:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728444AbeITWxd (ORCPT ); Thu, 20 Sep 2018 18:53:33 -0400 Received: from mail-wm1-f48.google.com ([209.85.128.48]:40933 "EHLO mail-wm1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726193AbeITWxd (ORCPT ); Thu, 20 Sep 2018 18:53:33 -0400 Received: by mail-wm1-f48.google.com with SMTP id 207-v6so276793wme.5 for ; Thu, 20 Sep 2018 10:09:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X6mjAlxMc08BwxsV+1YgfYp1HWJ059WaKq78KBKtzhE=; b=aH9sAwjODSElWgGXFz+8+ENbcCEH6FRILSME4oK/bz9eesHaW2L2SygvmPlOmPMgVL zM6hJ6gtnRH3Gr3f4vGt83pAHNAxXiWz0+1EBWybrsiwKrQUT+meus646dBr903chTXj hXnbI1R3ZV2kGcULubKq7yOUenc98Lq/8gTR8= 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; bh=X6mjAlxMc08BwxsV+1YgfYp1HWJ059WaKq78KBKtzhE=; b=WcQNhdry4/bTOn9kqcjb/GJRTeqlsD8XkSQLlABWrXJkMRxohU9nQT6K2TU/99vHjX P7xE82yKne0Yt7mBhYZdf/YuiMBea+n07Sjg9vllKITFKP79FZsDUU3xs8+a2dskPD7C SyYVo8Jr3uMqvtErBq3dSVkQmd2Bf5ArSV1S6E2v/Ry5bZaDufyIu9x2DzRRSQjzilWc jn19OH2e9it6+7RT0QBL1wf13r8AyW1W9wW4CC4G7W03YdlLSQsC8GcK9qWHRRz7E5Bk v3WA+jPstraTnMhuwiK3lmI3xoSTzToRdKVGNLJk1z+JW4KdTm7OI/Fo6LzW6uSxgQJ7 nj+g== X-Gm-Message-State: APzg51B1lGtw2eYhMwVsRdOWz2UnIChwIHVqKF44n2GW/8mjhPFG4P5O mf7GYsGIwTbOPprMEd/MJ3VYBA== X-Google-Smtp-Source: ANB0VdYH1gT5lXjfbHsC2GIXBR0GvUE8rWrVYJWZRKgWKYRO5HX4WwA+Te8P7U7n+bcmOO+K46JNvw== X-Received: by 2002:a1c:48d:: with SMTP id 135-v6mr3569869wme.128.1537463344754; Thu, 20 Sep 2018 10:09:04 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id v133-v6sm3458232wma.36.2018.09.20.10.09.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Sep 2018 10:09:04 -0700 (PDT) From: Devesh Sharma To: jgg@mellanox.com, dledford@redhat.com Cc: linux-rdma@vger.kernel.org, NMoreyChaisemartin@suse.de, Selvin Xavier , Somnath Kotur , Devesh Sharma Subject: [PATCH rdma-core 4/4] bnxt_re/lib: Fix flush list processing during poll_cq Date: Thu, 20 Sep 2018 13:08:34 -0400 Message-Id: <1537463314-7807-5-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> References: <1537463314-7807-1-git-send-email-devesh.sharma@broadcom.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Selvin Xavier During flush list processing as a part of poll_cq, the budget is not calculated correctly according to the number of polled completions. Work completion structure pointers are incremented each time but budget is not decremented correspondingly. So, library might end up polling more than the budget. Since the caller would have wc structures list with number of entries equal to the budget, completing more than budget can cause segmentation fault in libbnxt_re. Reorganized the code to have a common subroutine to poll from a given flush-list. Signed-off-by: Selvin Xavier Signed-off-by: Somnath Kotur Signed-off-by: Devesh Sharma --- providers/bnxt_re/verbs.c | 76 +++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index 570dfc1..39b29b0 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -630,46 +630,64 @@ static int bnxt_re_poll_flush_wcs(struct bnxt_re_queue *que, return cnt; } -static int bnxt_re_poll_flush_lists(struct bnxt_re_cq *cq, uint32_t nwc, - struct ibv_wc *ibvwc) +static int bnxt_re_poll_flush_wqes(struct bnxt_re_cq *cq, + struct list_head *lhead, + struct ibv_wc *ibvwc, + int32_t nwc) { struct bnxt_re_fque_node *cur, *tmp; - struct bnxt_re_qp *qp; + struct bnxt_re_wrid *wridp; struct bnxt_re_queue *que; - int dqed = 0, left; + struct bnxt_re_qp *qp; + bool sq_list = false; + uint32_t polled = 0; + + sq_list = (lhead == &cq->sfhead) ? true : false; + if (!list_empty(lhead)) { + list_for_each_safe(lhead, cur, tmp, list) { + if (sq_list) { + qp = container_of(cur, struct bnxt_re_qp, + snode); + que = qp->sqq; + wridp = qp->swrid; + } else { + qp = container_of(cur, struct bnxt_re_qp, + rnode); + que = qp->rqq; + wridp = qp->rwrid; + } + if (bnxt_re_is_que_empty(que)) + continue; + polled += bnxt_re_poll_flush_wcs(que, wridp, + ibvwc + polled, + qp->qpid, + nwc - polled); + if (!(nwc - polled)) + break; + } + } + + return polled; +} + +static int bnxt_re_poll_flush_lists(struct bnxt_re_cq *cq, uint32_t nwc, + struct ibv_wc *ibvwc) +{ + int left, polled = 0; /* Check if flush Qs are empty */ if (list_empty(&cq->sfhead) && list_empty(&cq->rfhead)) return 0; - if (!list_empty(&cq->sfhead)) { - list_for_each_safe(&cq->sfhead, cur, tmp, list) { - qp = container_of(cur, struct bnxt_re_qp, snode); - que = qp->sqq; - if (bnxt_re_is_que_empty(que)) - continue; - dqed = bnxt_re_poll_flush_wcs(que, qp->swrid, ibvwc, - qp->qpid, nwc); - } - } + polled = bnxt_re_poll_flush_wqes(cq, &cq->sfhead, ibvwc, nwc); + left = nwc - polled; - left = nwc - dqed; if (!left) - return dqed; - - if (!list_empty(&cq->rfhead)) { - list_for_each_safe(&cq->rfhead, cur, tmp, list) { - qp = container_of(cur, struct bnxt_re_qp, rnode); - que = qp->rqq; - if (!que || bnxt_re_is_que_empty(que)) - continue; - dqed += bnxt_re_poll_flush_wcs(que, qp->rwrid, - ibvwc + dqed, qp->qpid, - left); - } - } + return polled; - return dqed; + polled += bnxt_re_poll_flush_wqes(cq, &cq->rfhead, + ibvwc + polled, left); + return polled; } int bnxt_re_poll_cq(struct ibv_cq *ibvcq, int nwc, struct ibv_wc *wc)