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)