From patchwork Fri May 12 10:24:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devesh Sharma X-Patchwork-Id: 9723873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5525D600CB for ; Fri, 12 May 2017 10:24:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49DE0287F3 for ; Fri, 12 May 2017 10:24:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E93528808; Fri, 12 May 2017 10:24:48 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 25B71287F3 for ; Fri, 12 May 2017 10:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756915AbdELKYp (ORCPT ); Fri, 12 May 2017 06:24:45 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:34863 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756901AbdELKYp (ORCPT ); Fri, 12 May 2017 06:24:45 -0400 Received: by mail-pg0-f44.google.com with SMTP id q125so8983734pgq.2 for ; Fri, 12 May 2017 03:24:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=0sdbKcCVrMNCWjHBJvTeJMr9qJKiXTkjEPhCd2zbfe8=; b=QKzsiF9V1vvBQyUxO5COUPzBANbaKhXjcb5fEQIGvldier1iGsnb1POcbZEEwhj3+w MLP7Wm5wp2yh1dU90k9XerwJXZnJXHblWiCyhq80QasRtU+QyA4tGo2YtCzgOa/V3rcZ 9U/9va1j4zBfrg6WNZlabGjot4EgT2mhoCo2g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=0sdbKcCVrMNCWjHBJvTeJMr9qJKiXTkjEPhCd2zbfe8=; b=AoQMuq4W+SE9ta7Rlm+7s8xShO8uhItAJgTZVeLbxq+FqrheM6dBduBXm2epfpMzXh voEq0enYLlUTLQqWOYJmiQM1dvR9mOHyoBu7pTfgBlN7G7UxHq2FAVwiribT2hlfUCg2 q1P5GsxfR3ZSKjswHavJ1UIXpTr/nJa9kDa3KSGICdeltuVQwsiNmfCRnfRpwWNu+ufg 3sQAaOP9ii9gC3QJezohMYUwqwfwiIcRXgV941r4AfJOw+n4CN86IEYsjwPVxz6h4eXI GssMmh6dm8jS9G8gSIlDfTOzpcRQSouTfQgvvtIDnTHUP5pxBq70TNVDIRAu/eNrY2vW WJ4A== X-Gm-Message-State: AODbwcB49M2xEyypqvyC5XZoCnSMVrrbeH4hSQ7tAUiMWs768qXrWpaE 7Vy8ArSKu+phGP16bFw0uw== X-Received: by 10.99.181.11 with SMTP id y11mr3566699pge.54.1494584682662; Fri, 12 May 2017 03:24:42 -0700 (PDT) Received: from neo00-el73.iig.avagotech.net ([192.19.239.250]) by smtp.gmail.com with ESMTPSA id c12sm4901872pfl.79.2017.05.12.03.24.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 May 2017 03:24:41 -0700 (PDT) From: Devesh Sharma To: linux-rdma@vger.kernel.org Subject: [PATCH 4/5] libbnxt_re: unmap DB page during uninit ucontext Date: Fri, 12 May 2017 06:24:25 -0400 Message-Id: <1494584666-11064-5-git-send-email-devesh.sharma@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1494584666-11064-1-git-send-email-devesh.sharma@broadcom.com> References: <1494584666-11064-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 Library is trying to map DPI page every time a new PD is allocated on a given user-context. Similarly, the free-PD is trying to unmap the PD in every call. However, dapltest is trying to ring the DB after a free-PD. Library needs to mmap the DB page only once during first PD allocation on a given user-context. The unmap of DB page should be done during uninit_ucontext. This function is called during ibv_close. Signed-off-by: Devesh Sharma --- providers/bnxt_re/main.c | 9 +++++++++ providers/bnxt_re/verbs.c | 27 ++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/providers/bnxt_re/main.c b/providers/bnxt_re/main.c index da4dd06..29ac7cd 100644 --- a/providers/bnxt_re/main.c +++ b/providers/bnxt_re/main.c @@ -159,6 +159,15 @@ static void bnxt_re_uninit_context(struct verbs_device *vdev, if (cntx->shpg) munmap(cntx->shpg, dev->pg_size); pthread_spin_destroy(&cntx->fqlock); + + /* Un-map DPI only for the first PD that was + * 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; + } } static struct verbs_device_ops bnxt_re_dev_ops = { diff --git a/providers/bnxt_re/verbs.c b/providers/bnxt_re/verbs.c index abe4e2e..d337514 100644 --- a/providers/bnxt_re/verbs.c +++ b/providers/bnxt_re/verbs.c @@ -96,14 +96,17 @@ struct ibv_pd *bnxt_re_alloc_pd(struct ibv_context *ibvctx) dbr = *(uint64_t *)((uint32_t *)&resp + 3); /* Map DB page now. */ - cntx->udpi.dpindx = resp.dpi; - cntx->udpi.dbpage = mmap(NULL, dev->pg_size, PROT_WRITE, MAP_SHARED, - ibvctx->cmd_fd, dbr); - if (cntx->udpi.dbpage == MAP_FAILED) { - (void)ibv_cmd_dealloc_pd(&pd->ibvpd); - goto out; - } - pthread_spin_init(&cntx->udpi.db_lock, PTHREAD_PROCESS_PRIVATE); + if (!cntx->udpi.dbpage) { + cntx->udpi.dpindx = resp.dpi; + cntx->udpi.dbpage = mmap(NULL, dev->pg_size, PROT_WRITE, + MAP_SHARED, ibvctx->cmd_fd, dbr); + if (cntx->udpi.dbpage == MAP_FAILED) { + (void)ibv_cmd_dealloc_pd(&pd->ibvpd); + goto out; + } + pthread_spin_init(&cntx->udpi.db_lock, + PTHREAD_PROCESS_PRIVATE); + } return &pd->ibvpd; out: @@ -114,18 +117,12 @@ out: int bnxt_re_free_pd(struct ibv_pd *ibvpd) { struct bnxt_re_pd *pd = to_bnxt_re_pd(ibvpd); - struct bnxt_re_context *cntx = to_bnxt_re_context(ibvpd->context); - struct bnxt_re_dev *dev = to_bnxt_re_dev(cntx->ibvctx.device); int status; status = ibv_cmd_dealloc_pd(ibvpd); if (status) return status; - - pthread_spin_destroy(&cntx->udpi.db_lock); - if (cntx->udpi.dbpage && (cntx->udpi.dbpage != MAP_FAILED)) - munmap(cntx->udpi.dbpage, dev->pg_size); - + /* DPI un-mapping will be during uninit_ucontext */ free(pd); return 0;