From patchwork Thu Dec 20 13:41:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhu Yanjun X-Patchwork-Id: 10738907 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 AEF11746 for ; Thu, 20 Dec 2018 13:40:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A123287EA for ; Thu, 20 Dec 2018 13:40:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8AD8D288BA; Thu, 20 Dec 2018 13:40:09 +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 1DDBF287EA for ; Thu, 20 Dec 2018 13:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733185AbeLTNkH (ORCPT ); Thu, 20 Dec 2018 08:40:07 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:40364 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733163AbeLTNkG (ORCPT ); Thu, 20 Dec 2018 08:40:06 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wBKDcpOs186346; Thu, 20 Dec 2018 13:40:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id; s=corp-2018-07-02; bh=I1NCgr8Bqnphgi9orRUuniDgGVIzNxDbuCG14VEQci0=; b=oAtudITEePNuvbBgQLtUAMsUjan4FE4ckI1k8NdsgM8n68yKpLnBNbqbozgqZAL/paGu XIMsm/b/zASnSZFgT+KTQ3ue/hJeHNQ1HPi2rnbvFrWiv1iYFbR4DbpNBggjFLPj9HQK i/IYE72KkLAGKZm4fxdU9xjxewWaCqK1Vi0yXnlAC5YkOQzDTkbwVFjJCk+9O976Acwv 2CNPqmc7Hkxqsfl170rcA2RYNmfUluY74WrA+GZmVer1MQEDWvHW0vZsWb4aVPmYC1Mq uEqIL6y10Wv5pAD+rI1sg/Dy94NqBqbbvddHfB36NiFppIenHWfh8OEuxWs14SS31cQc Eg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2pfh3a7988-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Dec 2018 13:39:59 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wBKDdsrR009173 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Dec 2018 13:39:54 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wBKDdrIk005023; Thu, 20 Dec 2018 13:39:53 GMT Received: from shipfan.cn.oracle.com (/10.113.210.105) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 20 Dec 2018 05:39:53 -0800 From: Zhu Yanjun To: monis@mellanox.com, dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org Subject: [PATCHv2 1/1] IB: rxe: remove pool state Date: Thu, 20 Dec 2018 08:41:47 -0500 Message-Id: <1545313307-11562-1-git-send-email-yanjun.zhu@oracle.com> X-Mailer: git-send-email 2.7.4 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9112 signatures=668680 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=876 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812200113 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 The pool state is the duplicate of pool ref_cnt. If ref_cnt > 0, it indicates that state is valid. If ref_cnt = 0, it indicates that state is invalid. Signed-off-by: Zhu Yanjun --- V1->V2: Follow Jason's advice, the state is replaced with ref_cnt. --- drivers/infiniband/sw/rxe/rxe_pool.c | 20 +++----------------- drivers/infiniband/sw/rxe/rxe_pool.h | 6 ------ 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c index 36b53fb..d8f969d 100644 --- a/drivers/infiniband/sw/rxe/rxe_pool.c +++ b/drivers/infiniband/sw/rxe/rxe_pool.c @@ -222,8 +222,6 @@ int rxe_pool_init( pool->key_size = rxe_type_info[type].key_size; } - pool->state = RXE_POOL_STATE_VALID; - out: return err; } @@ -232,7 +230,6 @@ static void rxe_pool_release(struct kref *kref) { struct rxe_pool *pool = container_of(kref, struct rxe_pool, ref_cnt); - pool->state = RXE_POOL_STATE_INVALID; kfree(pool->table); } @@ -243,14 +240,9 @@ static void rxe_pool_put(struct rxe_pool *pool) int rxe_pool_cleanup(struct rxe_pool *pool) { - unsigned long flags; - - write_lock_irqsave(&pool->pool_lock, flags); - pool->state = RXE_POOL_STATE_INVALID; if (atomic_read(&pool->num_elem) > 0) pr_warn("%s pool destroyed with unfree'd elem\n", pool_name(pool)); - write_unlock_irqrestore(&pool->pool_lock, flags); rxe_pool_put(pool); @@ -380,17 +372,11 @@ void rxe_drop_index(void *arg) void *rxe_alloc(struct rxe_pool *pool) { struct rxe_pool_entry *elem; - unsigned long flags; might_sleep_if(!(pool->flags & RXE_POOL_ATOMIC)); - read_lock_irqsave(&pool->pool_lock, flags); - if (pool->state != RXE_POOL_STATE_VALID) { - read_unlock_irqrestore(&pool->pool_lock, flags); + if (!kref_get_unless_zero(&pool->ref_cnt)) return NULL; - } - kref_get(&pool->ref_cnt); - read_unlock_irqrestore(&pool->pool_lock, flags); kref_get(&pool->rxe->ref_cnt); @@ -438,7 +424,7 @@ void *rxe_pool_get_index(struct rxe_pool *pool, u32 index) read_lock_irqsave(&pool->pool_lock, flags); - if (pool->state != RXE_POOL_STATE_VALID) + if (!kref_read(&pool->ref_cnt)) goto out; node = pool->tree.rb_node; @@ -470,7 +456,7 @@ void *rxe_pool_get_key(struct rxe_pool *pool, void *key) read_lock_irqsave(&pool->pool_lock, flags); - if (pool->state != RXE_POOL_STATE_VALID) + if (!kref_read(&pool->ref_cnt)) goto out; node = pool->tree.rb_node; diff --git a/drivers/infiniband/sw/rxe/rxe_pool.h b/drivers/infiniband/sw/rxe/rxe_pool.h index aa4ba30..eeca733 100644 --- a/drivers/infiniband/sw/rxe/rxe_pool.h +++ b/drivers/infiniband/sw/rxe/rxe_pool.h @@ -73,11 +73,6 @@ struct rxe_type_info { extern struct rxe_type_info rxe_type_info[]; -enum rxe_pool_state { - RXE_POOL_STATE_INVALID, - RXE_POOL_STATE_VALID, -}; - struct rxe_pool_entry { struct rxe_pool *pool; struct kref ref_cnt; @@ -94,7 +89,6 @@ struct rxe_pool { size_t elem_size; struct kref ref_cnt; void (*cleanup)(struct rxe_pool_entry *obj); - enum rxe_pool_state state; enum rxe_pool_flags flags; enum rxe_elem_type type;