Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp2901365pxv; Sun, 18 Jul 2021 05:03:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzm8RqH9UyqjkDxEutojhaXh4z7DA3ebv/sqsUa4jSeSE9RQVm1cX8SolugHcizXwI1PZyH X-Received: by 2002:a02:9109:: with SMTP id a9mr17037980jag.93.1626609780182; Sun, 18 Jul 2021 05:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626609780; cv=none; d=google.com; s=arc-20160816; b=Y+Cn0Jv9jOLd5kIdcULQrmN9oJmZe/e/6usT0HPx18EGxU97tL5VH7aFuTx3/DpiMJ Zhxl2UOGJrmWAyZHCcef0Zl9d98hGRsytqtVEkIrs2tEuJ9xCaBZuARqVsZ0ApDvMrXE e9lLnNAHNnTZVCSTqtxf8quaa7UcNHmpEIBKnhxptF4YjiE/KuNcRel6rbWHiQ0IT8bk skfWW5oAsmcr7o1kYfSK6Ts61b2Tmt9e4Y5tOvojXrQR3373rNNf45lHwmqKE+pENFfV yI4SvVQ4ORLgzaH0wB8ly5x8IGMTRVs5MtNYxBIHauis2W6y2BpXTOD63DEuWhSeBMB0 LUXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SUyJg/rU6lZbH59deL5UbunZi1Af09ngOpJbBFEikMw=; b=FRD4VWUpGnsTSWMD03zlHAKGGxRbodIHadDsok7aFSJx1P8FfRPwP8pWQ+YHo6d4Qi aiEFo+XjxeGP5h6T2rroSvjyG23tfj7gyIZpBb5CBea9pwB7qgycg3BkC9do4Kq15viP k+YZqHiaUxVXcTBKKwFr1KGWndd4RhbAyyMaUcsvflybsiLMnYqBaNOcb9Mg8G+JPnwr 1kv4mlbW1ys6Jg5la7ggcSL1GfHsjclF+geKO2Y6qWBsKipjA13ZmVIA1Pn/4uH31nkR RF7ZRMrqrBSw6S4+kbfo7zBpWI92v8OpkBWOTuZ9r5D6c8vGxjb9Be/EDbizhQ+BdkZT pSXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tlBgpCaO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d24si5801850iob.3.2021.07.18.05.02.48; Sun, 18 Jul 2021 05:03:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tlBgpCaO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233776AbhGRMEj (ORCPT + 99 others); Sun, 18 Jul 2021 08:04:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:44376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233673AbhGRMEd (ORCPT ); Sun, 18 Jul 2021 08:04:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3450F610D1; Sun, 18 Jul 2021 12:01:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626609695; bh=/xVusLaIisjwDrhXsvTfDCOTo4UomSFhxaE4UNzqDKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tlBgpCaOgQl+f4P/lZePWrp2FJY1W7wWBVXbsPlBArWT5cbsCdBdIF4RUkXHiSd1J msWD0is3f7tLTVjqsKGWrsRoh6vtRtvLFsNCICtcyyTCkH1Q6aTDxBG5r/SPfekhga 2mSplqEyAGYmfXXbYMOFrF91pEfkEwRYc/0GFEwSuflgFnOTnXuVpe5NZotDIFbdBK MuQusF6riXH45KhMs4F43bzOxgH+ECJGF+qfJYRuAtmRBNY+nuucGA7A7b+GQRJPRi qdWQU+WFgPqMDfZcbxkKK4ClCN5cHZy55CaSyQbEpqd+sdSLLh9J5K8+wGUbR8GL4x mbWfNHeYpUGVg== From: Leon Romanovsky To: Doug Ledford , Jason Gunthorpe Cc: Leon Romanovsky , Adit Ranadive , Ariel Elior , Bernard Metzler , Christian Benvenuti , Dennis Dalessandro , Gal Pressman , linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Michal Kalderon , Mike Marciniszyn , Mustafa Ismail , Naresh Kumar PBS , Nelson Escobar , Potnuri Bharat Teja , Selvin Xavier , Shiraz Saleem , Steve Wise , VMware PV-Drivers , Weihang Li , Wenpeng Liang , Yishai Hadas , Zhu Yanjun Subject: [PATCH rdma-next 9/9] RDMA/mlx5: Drop in-driver verbs object creations Date: Sun, 18 Jul 2021 15:00:59 +0300 Message-Id: X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leon Romanovsky There is no real value in bypassing IB/core APIs for creating standard objects with standard types. The open-coded variant didn't have any restrack task management calls and caused to such objects to be not present when running rdmatoool. Signed-off-by: Leon Romanovsky --- drivers/infiniband/core/verbs.c | 7 ++- drivers/infiniband/hw/mlx5/main.c | 92 +++++++------------------------ 2 files changed, 25 insertions(+), 74 deletions(-) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index a164609c2ee7..89c6987cb5eb 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -1035,7 +1035,8 @@ struct ib_srq *ib_create_srq_user(struct ib_pd *pd, } if (srq->srq_type == IB_SRQT_XRC) { srq->ext.xrc.xrcd = srq_init_attr->ext.xrc.xrcd; - atomic_inc(&srq->ext.xrc.xrcd->usecnt); + if (srq->ext.xrc.xrcd) + atomic_inc(&srq->ext.xrc.xrcd->usecnt); } atomic_inc(&pd->usecnt); @@ -1046,7 +1047,7 @@ struct ib_srq *ib_create_srq_user(struct ib_pd *pd, if (ret) { rdma_restrack_put(&srq->res); atomic_dec(&srq->pd->usecnt); - if (srq->srq_type == IB_SRQT_XRC) + if (srq->srq_type == IB_SRQT_XRC && srq->ext.xrc.xrcd) atomic_dec(&srq->ext.xrc.xrcd->usecnt); if (ib_srq_has_cq(srq->srq_type)) atomic_dec(&srq->ext.cq->usecnt); @@ -1090,7 +1091,7 @@ int ib_destroy_srq_user(struct ib_srq *srq, struct ib_udata *udata) return ret; atomic_dec(&srq->pd->usecnt); - if (srq->srq_type == IB_SRQT_XRC) + if (srq->srq_type == IB_SRQT_XRC && srq->ext.xrc.xrcd) atomic_dec(&srq->ext.xrc.xrcd->usecnt); if (ib_srq_has_cq(srq->srq_type)) atomic_dec(&srq->ext.cq->usecnt); diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c index 7a6bafc19c9b..fbed9e4241e1 100644 --- a/drivers/infiniband/hw/mlx5/main.c +++ b/drivers/infiniband/hw/mlx5/main.c @@ -2802,31 +2802,16 @@ static int mlx5_ib_dev_res_init(struct mlx5_ib_dev *dev) if (!MLX5_CAP_GEN(dev->mdev, xrc)) return -EOPNOTSUPP; - devr->p0 = rdma_zalloc_drv_obj(ibdev, ib_pd); - if (!devr->p0) - return -ENOMEM; - - devr->p0->device = ibdev; - devr->p0->uobject = NULL; - atomic_set(&devr->p0->usecnt, 0); + devr->p0 = ib_alloc_pd(ibdev, 0); + if (IS_ERR(devr->p0)) + return PTR_ERR(devr->p0); - ret = mlx5_ib_alloc_pd(devr->p0, NULL); - if (ret) - goto error0; - - devr->c0 = rdma_zalloc_drv_obj(ibdev, ib_cq); - if (!devr->c0) { - ret = -ENOMEM; + devr->c0 = ib_create_cq(ibdev, NULL, NULL, NULL, &cq_attr); + if (IS_ERR(devr->c0)) { + ret = PTR_ERR(devr->c0); goto error1; } - devr->c0->device = &dev->ib_dev; - atomic_set(&devr->c0->usecnt, 0); - - ret = mlx5_ib_create_cq(devr->c0, &cq_attr, NULL); - if (ret) - goto err_create_cq; - ret = mlx5_cmd_xrcd_alloc(dev->mdev, &devr->xrcdn0, 0); if (ret) goto error2; @@ -2841,45 +2826,22 @@ static int mlx5_ib_dev_res_init(struct mlx5_ib_dev *dev) attr.srq_type = IB_SRQT_XRC; attr.ext.cq = devr->c0; - devr->s0 = rdma_zalloc_drv_obj(ibdev, ib_srq); - if (!devr->s0) { - ret = -ENOMEM; - goto error4; - } - - devr->s0->device = &dev->ib_dev; - devr->s0->pd = devr->p0; - devr->s0->srq_type = IB_SRQT_XRC; - devr->s0->ext.cq = devr->c0; - ret = mlx5_ib_create_srq(devr->s0, &attr, NULL); - if (ret) + devr->s0 = ib_create_srq(devr->p0, &attr); + if (IS_ERR(devr->s0)) { + ret = PTR_ERR(devr->s0); goto err_create; - - atomic_inc(&devr->s0->ext.cq->usecnt); - atomic_inc(&devr->p0->usecnt); - atomic_set(&devr->s0->usecnt, 0); + } memset(&attr, 0, sizeof(attr)); attr.attr.max_sge = 1; attr.attr.max_wr = 1; attr.srq_type = IB_SRQT_BASIC; - devr->s1 = rdma_zalloc_drv_obj(ibdev, ib_srq); - if (!devr->s1) { - ret = -ENOMEM; - goto error5; - } - - devr->s1->device = &dev->ib_dev; - devr->s1->pd = devr->p0; - devr->s1->srq_type = IB_SRQT_BASIC; - devr->s1->ext.cq = devr->c0; - ret = mlx5_ib_create_srq(devr->s1, &attr, NULL); - if (ret) + devr->s1 = ib_create_srq(devr->p0, &attr); + if (IS_ERR(devr->s1)) { + ret = PTR_ERR(devr->s1); goto error6; - - atomic_inc(&devr->p0->usecnt); - atomic_set(&devr->s1->usecnt, 0); + } for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) INIT_WORK(&devr->ports[port].pkey_change_work, @@ -2888,23 +2850,15 @@ static int mlx5_ib_dev_res_init(struct mlx5_ib_dev *dev) return 0; error6: - kfree(devr->s1); -error5: - mlx5_ib_destroy_srq(devr->s0, NULL); + ib_destroy_srq(devr->s0); err_create: - kfree(devr->s0); -error4: mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn1, 0); error3: mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn0, 0); error2: - mlx5_ib_destroy_cq(devr->c0, NULL); -err_create_cq: - kfree(devr->c0); + ib_destroy_cq(devr->c0); error1: - mlx5_ib_dealloc_pd(devr->p0, NULL); -error0: - kfree(devr->p0); + ib_dealloc_pd(devr->p0); return ret; } @@ -2922,16 +2876,12 @@ static void mlx5_ib_dev_res_cleanup(struct mlx5_ib_dev *dev) for (port = 0; port < ARRAY_SIZE(devr->ports); ++port) cancel_work_sync(&devr->ports[port].pkey_change_work); - mlx5_ib_destroy_srq(devr->s1, NULL); - kfree(devr->s1); - mlx5_ib_destroy_srq(devr->s0, NULL); - kfree(devr->s0); + ib_destroy_srq(devr->s1); + ib_destroy_srq(devr->s0); mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn1, 0); mlx5_cmd_xrcd_dealloc(dev->mdev, devr->xrcdn0, 0); - mlx5_ib_destroy_cq(devr->c0, NULL); - kfree(devr->c0); - mlx5_ib_dealloc_pd(devr->p0, NULL); - kfree(devr->p0); + ib_destroy_cq(devr->c0); + ib_dealloc_pd(devr->p0); } static u32 get_core_cap_flags(struct ib_device *ibdev, -- 2.31.1