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)