From patchwork Sun Oct 7 07:23:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shamir Rabinovitch X-Patchwork-Id: 10629371 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 1175817E3 for ; Sun, 7 Oct 2018 07:23:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9E7529174 for ; Sun, 7 Oct 2018 07:23:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDC3C2917D; Sun, 7 Oct 2018 07:23: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, UNPARSEABLE_RELAY 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 6195F2917C for ; Sun, 7 Oct 2018 07:23:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbeJGOaP (ORCPT ); Sun, 7 Oct 2018 10:30:15 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:43272 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726351AbeJGOaP (ORCPT ); Sun, 7 Oct 2018 10:30:15 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w977IwVJ153934; Sun, 7 Oct 2018 07:23:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=u2RWFxYEmAikxjzwJ4y+tH9VT13h77Nlg781Whp6u/0=; b=J/x6KudjkBOgIUpYoqkYPxXCqj9XiIbemWYtjjsjunNFp6Mlr8n2otnyQ/ut1A32tUKt NNkaEzvQF5LK8LNmlsvR3GIWU2Im8aD4FwfU4gCGIEKHyeupP3AHBGJAzx2UkY0oEuaf ZMc1wlohHHLHgAy4+GlFgZRX0RsOGnGQiPJ/wGHjp7K2+9nqQHi4onZvboufRziUQNsi AeGc760o2PWBJTmHYG8tpQvyCZNm3f2pfOU/td2IFUxdsicQ3aW9v2FufAtv7F/WViM8 ee6UPRWEV9+MTjJUFzrNFJMHZNYZgskfRnvkcpofuA9wYFb7hXxDz9L/lnlwdbwxFHE4 7Q== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2mxnpqj0ax-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 07 Oct 2018 07:23:51 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w977NoUM018734 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 7 Oct 2018 07:23:50 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w977Nnc1021332; Sun, 7 Oct 2018 07:23:49 GMT Received: from localhost.localdomain (/77.127.47.118) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Sun, 07 Oct 2018 07:23:48 +0000 From: Shamir Rabinovitch To: linux-rdma@vger.kernel.org Cc: dledford@redhat.com, jgg@ziepe.ca, leon@kernel.org, santosh.shilimkar@oracle.com, shamir.rabinovitch@oracle.com Subject: [PATCH 1/3] RDMA/restrack: resource-tracker should not use uobject pointers Date: Sun, 7 Oct 2018 10:23:06 +0300 Message-Id: <20181007072308.10936-2-shamir.rabinovitch@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181007072308.10936-1-shamir.rabinovitch@oracle.com> References: <20181007072308.10936-1-shamir.rabinovitch@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9038 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810070078 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 uobject pointers should not be used in ib core layer. they only belong to ib uverbs. as result, resource tracker should not use them as well. Signed-off-by: Shamir Rabinovitch --- drivers/infiniband/core/core_priv.h | 1 + drivers/infiniband/core/cq.c | 1 + drivers/infiniband/core/restrack.c | 16 +--------------- drivers/infiniband/core/uverbs_cmd.c | 3 +++ drivers/infiniband/core/uverbs_std_types_cq.c | 1 + drivers/infiniband/core/verbs.c | 3 +++ include/rdma/restrack.h | 4 ++++ 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index d7399d5b1cb6..4b98a967b821 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -324,6 +324,7 @@ static inline struct ib_qp *_ib_create_qp(struct ib_device *dev, */ if (attr->qp_type < IB_QPT_XRC_INI) { qp->res.type = RDMA_RESTRACK_QP; + qp->res.user = !!uobj; rdma_restrack_add(&qp->res); } else qp->res.valid = false; diff --git a/drivers/infiniband/core/cq.c b/drivers/infiniband/core/cq.c index 9271f7290005..456e8b41ce16 100644 --- a/drivers/infiniband/core/cq.c +++ b/drivers/infiniband/core/cq.c @@ -161,6 +161,7 @@ struct ib_cq *__ib_alloc_cq(struct ib_device *dev, void *private, goto out_destroy_cq; cq->res.type = RDMA_RESTRACK_CQ; + cq->res.user = false; cq->res.kern_name = caller; rdma_restrack_add(&cq->res); diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c index bcc693fffd4c..fb26ee566b00 100644 --- a/drivers/infiniband/core/restrack.c +++ b/drivers/infiniband/core/restrack.c @@ -138,21 +138,7 @@ static struct ib_device *res_to_dev(struct rdma_restrack_entry *res) static bool res_is_user(struct rdma_restrack_entry *res) { - switch (res->type) { - case RDMA_RESTRACK_PD: - return container_of(res, struct ib_pd, res)->uobject; - case RDMA_RESTRACK_CQ: - return container_of(res, struct ib_cq, res)->uobject; - case RDMA_RESTRACK_QP: - return container_of(res, struct ib_qp, res)->uobject; - case RDMA_RESTRACK_CM_ID: - return !res->kern_name; - case RDMA_RESTRACK_MR: - return container_of(res, struct ib_mr, res)->pd->uobject; - default: - WARN_ONCE(true, "Wrong resource tracking type %u\n", res->type); - return false; - } + return res->user; } void rdma_restrack_add(struct rdma_restrack_entry *res) diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c index 91d3e4029cd5..ef83813aefc2 100644 --- a/drivers/infiniband/core/uverbs_cmd.c +++ b/drivers/infiniband/core/uverbs_cmd.c @@ -379,6 +379,7 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file, memset(&resp, 0, sizeof resp); resp.pd_handle = uobj->id; pd->res.type = RDMA_RESTRACK_PD; + pd->res.user = true; rdma_restrack_add(&pd->res); if (copy_to_user(u64_to_user_ptr(cmd.response), &resp, sizeof resp)) { @@ -716,6 +717,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file, mr->uobject = uobj; atomic_inc(&pd->usecnt); mr->res.type = RDMA_RESTRACK_MR; + mr->res.user = true; rdma_restrack_add(&mr->res); uobj->object = mr; @@ -1039,6 +1041,7 @@ static struct ib_ucq_object *create_cq(struct ib_uverbs_file *file, sizeof(resp.response_length); cq->res.type = RDMA_RESTRACK_CQ; + cq->res.user = true; rdma_restrack_add(&cq->res); ret = cb(file, obj, &resp, ucore, context); diff --git a/drivers/infiniband/core/uverbs_std_types_cq.c b/drivers/infiniband/core/uverbs_std_types_cq.c index 5b5f2052cd52..fbd442b276e3 100644 --- a/drivers/infiniband/core/uverbs_std_types_cq.c +++ b/drivers/infiniband/core/uverbs_std_types_cq.c @@ -129,6 +129,7 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)( obj->uobject.user_handle = user_handle; atomic_set(&cq->usecnt, 0); cq->res.type = RDMA_RESTRACK_CQ; + cq->res.user = true; rdma_restrack_add(&cq->res); ret = uverbs_copy_to(attrs, UVERBS_ATTR_CREATE_CQ_RESP_CQE, &cq->cqe, diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index ee5fc8408add..415b4297fc7e 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -264,6 +264,7 @@ struct ib_pd *__ib_alloc_pd(struct ib_device *device, unsigned int flags, } pd->res.type = RDMA_RESTRACK_PD; + pd->res.user = false; pd->res.kern_name = caller; rdma_restrack_add(&pd->res); @@ -1890,6 +1891,7 @@ struct ib_cq *__ib_create_cq(struct ib_device *device, cq->cq_context = cq_context; atomic_set(&cq->usecnt, 0); cq->res.type = RDMA_RESTRACK_CQ; + cq->res.user = false; cq->res.kern_name = caller; rdma_restrack_add(&cq->res); } @@ -1972,6 +1974,7 @@ struct ib_mr *ib_alloc_mr(struct ib_pd *pd, atomic_inc(&pd->usecnt); mr->need_inval = false; mr->res.type = RDMA_RESTRACK_MR; + mr->res.user = false; rdma_restrack_add(&mr->res); } diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h index 9654d33edd98..18e0fa032b45 100644 --- a/include/rdma/restrack.h +++ b/include/rdma/restrack.h @@ -112,6 +112,10 @@ struct rdma_restrack_entry { * @type: various objects in restrack database */ enum rdma_restrack_type type; + /** + * @user: user resource + */ + bool user; }; /**