From patchwork Wed Oct 10 06:27:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10633995 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 36A3D112B for ; Wed, 10 Oct 2018 06:27:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C1B129622 for ; Wed, 10 Oct 2018 06:27:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FE6B29633; Wed, 10 Oct 2018 06:27:47 +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 CD22629622 for ; Wed, 10 Oct 2018 06:27:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725864AbeJJNsX (ORCPT ); Wed, 10 Oct 2018 09:48:23 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:41186 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725757AbeJJNsX (ORCPT ); Wed, 10 Oct 2018 09:48:23 -0400 Received: by mail-pf1-f196.google.com with SMTP id m77-v6so2092861pfi.8 for ; Tue, 09 Oct 2018 23:27:45 -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=jb2Mg9ICqHU1CnDdG/kdd+nnL8XMKDUCZ5oGfN6QpsA=; b=X3JTrH+PnmlB5quesyo20amBrIQm4bjWPPn6OfQZAFMtPB8K5fW9NJ1q2UYkt5C2NX lNiYFygKZegh/5pqi0dkJC8LWlLNnPLLNzBhYj4No8SJMSMXSYHHDf6924RXn0DVCHhm 0k6jeEI2wkOCpYGxSvL1aLMT9srl4VEAQCYJE= 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=jb2Mg9ICqHU1CnDdG/kdd+nnL8XMKDUCZ5oGfN6QpsA=; b=nKduA14bPJwesYeFcbGEKX+9nU+goI/sxYMKJ794RaLs11Rh8KPEJHND/Ulp4WMldx ZAKVHnw8Y2GBOD7dTNbqy/DVoeFI+V3hGakdEsSRqRp+ne76gj9TVM04m4PM7Qq8Nii5 7e32tVYU88hp9GyWlaipBtJPBNf0nuvHs2IgCv9r+KUnRD1zoR/Gt/DJt6GcD8EqSmQP tQ0Sc6VXnc6Csx24k2mMMWbeEuE+LSPfhiNE6yyg9moKRKGpNdpfjOrCszf5hSVeQY7l Inxvb5/JkrN2ucOk+qESdG3bJ5RGpcRl4vF20O/9tuVYOE+4mG+VQeFc7+cy++zacAgb L24A== X-Gm-Message-State: ABuFfoj2nu+Qklg4IPfUjMnxEj3EIbsxGE+xObeGzMn0pcozMtYvLtb4 z9f8p5KhrtsE0khCOGSnnqLTIw== X-Google-Smtp-Source: ACcGV603dbMSqwKB5L/o/fIYydcCstBPZB9FXjRPaMqZ8CPzzHQ7duWsWIqxJYNWMqGfig08netmtA== X-Received: by 2002:a63:7419:: with SMTP id p25-v6mr28624596pgc.395.1539152865304; Tue, 09 Oct 2018 23:27:45 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id r65-v6sm31330790pfj.5.2018.10.09.23.27.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 23:27:44 -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 V2 1/4] bnxt_re/lib: Reduce memory barrier calls Date: Wed, 10 Oct 2018 02:27:27 -0400 Message-Id: <1539152850-24357-2-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539152850-24357-1-git-send-email-devesh.sharma@broadcom.com> References: <1539152850-24357-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: Devesh Sharma Signed-off-by: Jonathan Richardson Signed-off-by: JD Zheng --- 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 Wed Oct 10 06:27:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10633999 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 6867D112B for ; Wed, 10 Oct 2018 06:27:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5837F29622 for ; Wed, 10 Oct 2018 06:27:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4B05229633; Wed, 10 Oct 2018 06:27:50 +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 D70F229622 for ; Wed, 10 Oct 2018 06:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726004AbeJJNs0 (ORCPT ); Wed, 10 Oct 2018 09:48:26 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:34247 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725757AbeJJNs0 (ORCPT ); Wed, 10 Oct 2018 09:48:26 -0400 Received: by mail-pg1-f195.google.com with SMTP id g12-v6so2016798pgs.1 for ; Tue, 09 Oct 2018 23:27:48 -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=4Op7D7amJ+7yo2VDNgb3jv3vkhd7Jut52RDtf2vWFBQ=; b=DvvSHqY6HyQWn8a0gwgVeO3C8OWM0k7jjBw457a7x2FgquGCr0w36Pfy/IPwZDtkUd XfCYAu0dkogU9FVlmvyd+63EM3Yo233un4vOtm/+GAiu9gO/fX9ByM3vOE2ddmTALFaq Ic0SRRs0vhVr12l/nxEJBQRBwnq8+6BWvV0LU= 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=4Op7D7amJ+7yo2VDNgb3jv3vkhd7Jut52RDtf2vWFBQ=; b=HeLntOQbGpYBzWf6DqrjjnGaYacjNEX1hwUnncW/xzfJz9tw8guBrgZPxAGPeaI/3U kXIS9Ew/5zKw+0+hpcU310mJrHlBwYLY43S/hMY5cP+yglFHYi0TNv0TDa7dObPZoNdq MFWYOW10X2MXfycq2eSe/xHqDoadoiz8C+ujGwdSxJC0/kxMR72KmYWKkhiUsc5nZJfR rknCisOzyb964S3OmKnRzGVMU8DAQCnohKZc3duPMBRvuj0gkCRjqsAaR/EBvREg9XtJ TUTgiipt7dTgJInWqUpJAYIm9wdse+6Ag3Wi1KjwAl1CaHuPJmn1DamkxEKd7LdT9qA/ YMVA== X-Gm-Message-State: ABuFfohpy2BYMLhPza68M/ai9zGFjYobGQXQoTBRqZzUoeZQBkccXkBP 1L2x0yLwRr7VuUAArNX9Oodepg== X-Google-Smtp-Source: ACcGV60UyUUH96zJKnYwCMrbynWxIAe9lxGpIzqKHs5P12L4W65NjhEf+dyZ4e4SPCidrf7mp1znYQ== X-Received: by 2002:a63:f:: with SMTP id 15-v6mr28421799pga.15.1539152868114; Tue, 09 Oct 2018 23:27:48 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id r65-v6sm31330790pfj.5.2018.10.09.23.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 23:27:47 -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 V2 2/4] bnxt_re/lib: Remove db_lock around doorbell ring Date: Wed, 10 Oct 2018 02:27:28 -0400 Message-Id: <1539152850-24357-3-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539152850-24357-1-git-send-email-devesh.sharma@broadcom.com> References: <1539152850-24357-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: Devesh Sharma Signed-off-by: JD Zheng Signed-off-by: Jonathan Richardson --- providers/bnxt_re/db.c | 9 ++++----- providers/bnxt_re/main.c | 1 - providers/bnxt_re/main.h | 1 - providers/bnxt_re/memory.h | 10 ---------- providers/bnxt_re/verbs.c | 2 -- 5 files changed, 4 insertions(+), 19 deletions(-) diff --git a/providers/bnxt_re/db.c b/providers/bnxt_re/db.c index a79f871..85da182 100644 --- a/providers/bnxt_re/db.c +++ b/providers/bnxt_re/db.c @@ -36,7 +36,7 @@ * Description: Doorbell handling functions. */ -#include +#include #include "main.h" static void bnxt_re_ring_db(struct bnxt_re_dpi *dpi, @@ -44,11 +44,10 @@ 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); + mmio_wc_start(); + mmio_write64_le(dpi->dbpage, *dbval); + mmio_flush_writes(); } 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/memory.h b/providers/bnxt_re/memory.h index aac0ff3..75564c4 100644 --- a/providers/bnxt_re/memory.h +++ b/providers/bnxt_re/memory.h @@ -81,16 +81,6 @@ static inline unsigned long roundup_pow_of_two(unsigned long val) int bnxt_re_alloc_aligned(struct bnxt_re_queue *que, uint32_t pg_size); void bnxt_re_free_aligned(struct bnxt_re_queue *que); -static inline void iowrite64(__u64 *dst, __le64 *src) -{ - *(volatile __le64 *)dst = *src; -} - -static inline void iowrite32(__u32 *dst, __le32 *src) -{ - *(volatile __le32 *)dst = *src; -} - /* Basic queue operation */ static inline uint32_t bnxt_re_is_que_full(struct bnxt_re_queue *que) { 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 Wed Oct 10 06:27:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10634003 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 471FD5CAF for ; Wed, 10 Oct 2018 06:27:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EE4A029622 for ; Wed, 10 Oct 2018 06:27:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E237D29633; Wed, 10 Oct 2018 06:27:52 +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 CDF5C29622 for ; Wed, 10 Oct 2018 06:27:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725757AbeJJNs2 (ORCPT ); Wed, 10 Oct 2018 09:48:28 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:45206 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeJJNs2 (ORCPT ); Wed, 10 Oct 2018 09:48:28 -0400 Received: by mail-pf1-f195.google.com with SMTP id u12-v6so2080580pfn.12 for ; Tue, 09 Oct 2018 23:27:50 -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=JG/CyD4Vi1PwJyz0lIDuqAzJ9Li9fvLhhUls//nHD2SisQM+kYSDW3cc2LZrqRVMhC VyFQfzFQT4j+7BucQ+XM0I7RUSFDJ23iF9aHaWj1lExcq+/gDoBc0rXPGLSF4SdIl0mJ KLqd3KRNIBwH0V3h4zKmpxXNMX0qnBCtdbt+o= 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=WkfAfbv0rLcfeZmpNZi/Wpa6k8viN7E8/IXia9UX6yRKwZdGLzZ5e1mn2APtJw9K7h 8zBTORscRcSFkfq+hEQGnbOMv8skQrdlDKTWhwI/6ET7B5QQ8n0qDnadSDpI3E2qjLZq 6yn0C+Hj+vYq8IaHhAycP0JvI82CK2Ia//Or3W9ZbEojqSzj3pXtMNO375DH8oP7zgUZ UM1a06k3JdOWa+fqM2BEMZ6NyVrwC/IFAZiVk0RtPC5TIzDIEWkud3E3FExsWjgKWXOG Ked6TRuwIKDT2Ov77WOtcMRPUV49gqOPQd8/CTTHBldgXGanoBH/f2NcUtXX3HcqRDQq wcrg== X-Gm-Message-State: ABuFfojXOps1cQbyr3LXoLItqAgkpHzvNfBEuMUO7iM2LylMuH2OmgGq gohVU4QzO5Jvlv1jU6aRy7cT8VnZ+PhBpA== X-Google-Smtp-Source: ACcGV61sWU5yq3fNVOh54g+lZPiGXb0iJbbdLfwbDyk6EWHMuA867wNEuWeRAVUqlVGV9cbb0JmjHw== X-Received: by 2002:a63:26c4:: with SMTP id m187-v6mr28734483pgm.268.1539152870456; Tue, 09 Oct 2018 23:27:50 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id r65-v6sm31330790pfj.5.2018.10.09.23.27.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 23:27:49 -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 V2 3/4] bnxt_re/lib: Fix the frequency of acquiring flush lock Date: Wed, 10 Oct 2018 02:27:29 -0400 Message-Id: <1539152850-24357-4-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539152850-24357-1-git-send-email-devesh.sharma@broadcom.com> References: <1539152850-24357-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 Wed Oct 10 06:27:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 10634001 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 3F7AF69B1 for ; Wed, 10 Oct 2018 06:27:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 44E0329622 for ; Wed, 10 Oct 2018 06:27:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38F8429633; Wed, 10 Oct 2018 06:27:55 +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 C860D29627 for ; Wed, 10 Oct 2018 06:27:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726479AbeJJNsb (ORCPT ); Wed, 10 Oct 2018 09:48:31 -0400 Received: from mail-pg1-f172.google.com ([209.85.215.172]:36563 "EHLO mail-pg1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbeJJNsb (ORCPT ); Wed, 10 Oct 2018 09:48:31 -0400 Received: by mail-pg1-f172.google.com with SMTP id f18-v6so2015605pgv.3 for ; Tue, 09 Oct 2018 23:27:53 -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=WRitM0b31q2LLzTrTkcVakXssfgQcL2OpzhRlA6LON7h+y81ig1o9/2os2IsxF1eaw 9nNtmgGuR2YO2H3V/dyl1saFp0tCl6sBOiUpG+dSbXakRQpPJ6beD8IociJdmZSmcPni yKjgaK7TDcf1+BPJkWM1A8yMc9bifRUTwwrFo= 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=UFbi73eWkYLnGF3P/mLNjfwfMwkLo+jaAHVOc0Uo3wn7txbtjgvEr8rS8b48B4qOpv Mt0Jf8yOb+tqKlmqBvcLJJt8YJXyS92rZlIewBCAIpcdTis0CRKR0W+YeHaJ1DvcPhYD p1cm0u2p0/HGDbf99I3CNakIxTNoIt1JmSMgJ8Al+alDZ3SnHIqYrDg66cQbS98a5zJH JjB+ocKD3ZfoG1cZAAUeoeyf16O+dOU8OA47sdN/aEgwxAAv17RJFXS61lm4vgFn02SE uj8m2geqgIzoTSfnFcv9AYSIhVRpjw4b7baTUMnf363ipjY0rhvscVzq3UrMoBj6w98i 832g== X-Gm-Message-State: ABuFfoixRTrXCcZhE6xzz+jpL7k3fJtF9SNyY+P1kfM07qLem0ke2Jh+ CnhPID6RI2y6+gcMZtG0FR9cog== X-Google-Smtp-Source: ACcGV63f7dGyT5IONAHVI/qE2c3TjZd8zkWBCast0wkQ2ptVL6R8W2cfOpHKyU3/3002SUIlpIsfBg== X-Received: by 2002:a63:7b09:: with SMTP id w9-v6mr28792707pgc.385.1539152873025; Tue, 09 Oct 2018 23:27:53 -0700 (PDT) Received: from neo00-el73.dhcp.broadcom.net ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id r65-v6sm31330790pfj.5.2018.10.09.23.27.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 23:27:52 -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 V2 4/4] bnxt_re/lib: Fix flush list processing during poll_cq Date: Wed, 10 Oct 2018 02:27:30 -0400 Message-Id: <1539152850-24357-5-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539152850-24357-1-git-send-email-devesh.sharma@broadcom.com> References: <1539152850-24357-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)