From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68B03C3A589 for ; Tue, 20 Aug 2019 22:33:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 368F022DA7 for ; Tue, 20 Aug 2019 22:33:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="PYEGuzi8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731076AbfHTWdE (ORCPT ); Tue, 20 Aug 2019 18:33:04 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:36968 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730918AbfHTWdC (ORCPT ); Tue, 20 Aug 2019 18:33:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GhaNEwgY9CnMnSHUSTDErNiB07Wo4XxOmrPuy4e52lA=; b=PYEGuzi8ENINCho5gGabj9jbKU 8kOv8BoxzPDN7bN2pdSRRkdndHEU9d0nzsWvdFRLnYcseaqj5Pec6RAm5hNFAsq5bnAiPzZX3Ce9B JhQAqZLMRCL8xDspn8gXgLLJX/itM9JjC09ARIIz1D0jG8vOvWzvz1cZcxnvQ4nBTXqQ/sMSR+emD SGcAsl3HTCDkP40g9VSCCTCUxJyqpjPJZ7FXdisXXyIZhHqaJ2qBs60NcpIGv/+ldnENuedM2CK+/ tE0ZiAtxvULPnWiobJGhO2hJjyNVkpORJmNcXNCI8BzpfcsG7U3Awm88so8MYOjAv8yOwq/BB4w5H OsaEI95g==; Received: from willy by bombadil.infradead.org with local (Exim 4.92 #3 (Red Hat Linux)) id 1i0CgX-0005pw-UX; Tue, 20 Aug 2019 22:33:01 +0000 From: Matthew Wilcox To: netdev@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" Subject: [PATCH 05/38] mlx5: Convert mlx5_qp_table to XArray Date: Tue, 20 Aug 2019 15:32:26 -0700 Message-Id: <20190820223259.22348-6-willy@infradead.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190820223259.22348-1-willy@infradead.org> References: <20190820223259.22348-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: "Matthew Wilcox (Oracle)" Fix the locking in destroy_resource_common() to be irq-disable rather than irq-save. wait_for_completion() can sleep, so this function must not be callable from interrupt context. Signed-off-by: Matthew Wilcox (Oracle) --- drivers/net/ethernet/mellanox/mlx5/core/qp.c | 38 ++++++-------------- include/linux/mlx5/driver.h | 8 ++--- include/linux/mlx5/qp.h | 2 +- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/qp.c b/drivers/net/ethernet/mellanox/mlx5/core/qp.c index b8ba74de9555..e3367290b5ce 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/qp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/qp.c @@ -49,13 +49,11 @@ mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn) struct mlx5_core_rsc_common *common; unsigned long flags; - spin_lock_irqsave(&table->lock, flags); - - common = radix_tree_lookup(&table->tree, rsn); + xa_lock_irqsave(&table->array, flags); + common = xa_load(&table->array, rsn); if (common) atomic_inc(&common->refcount); - - spin_unlock_irqrestore(&table->lock, flags); + xa_unlock_irqrestore(&table->array, flags); return common; } @@ -197,35 +195,22 @@ static int create_resource_common(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp, int rsc_type) { - struct mlx5_qp_table *table = &dev->priv.qp_table; - int err; - - qp->common.res = rsc_type; - spin_lock_irq(&table->lock); - err = radix_tree_insert(&table->tree, - qp->qpn | (rsc_type << MLX5_USER_INDEX_LEN), - qp); - spin_unlock_irq(&table->lock); - if (err) - return err; - atomic_set(&qp->common.refcount, 1); init_completion(&qp->common.free); qp->pid = current->pid; - return 0; + qp->common.res = rsc_type; + return xa_err(xa_store_irq(&dev->priv.qp_table.array, + qp->qpn | (rsc_type << MLX5_USER_INDEX_LEN), + qp, GFP_KERNEL)); } static void destroy_resource_common(struct mlx5_core_dev *dev, struct mlx5_core_qp *qp) { - struct mlx5_qp_table *table = &dev->priv.qp_table; - unsigned long flags; + struct xarray *xa = &dev->priv.qp_table.array; - spin_lock_irqsave(&table->lock, flags); - radix_tree_delete(&table->tree, - qp->qpn | (qp->common.res << MLX5_USER_INDEX_LEN)); - spin_unlock_irqrestore(&table->lock, flags); + xa_erase_irq(xa, qp->qpn | (qp->common.res << MLX5_USER_INDEX_LEN)); mlx5_core_put_rsc((struct mlx5_core_rsc_common *)qp); wait_for_completion(&qp->common.free); } @@ -524,10 +509,7 @@ EXPORT_SYMBOL_GPL(mlx5_core_qp_modify); void mlx5_init_qp_table(struct mlx5_core_dev *dev) { struct mlx5_qp_table *table = &dev->priv.qp_table; - - memset(table, 0, sizeof(*table)); - spin_lock_init(&table->lock); - INIT_RADIX_TREE(&table->tree, GFP_ATOMIC); + xa_init_flags(&table->array, XA_FLAGS_LOCK_IRQ); mlx5_qp_debugfs_init(dev); table->nb.notifier_call = rsc_event_notifier; diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index df23f17eed64..ba8f59b11920 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -448,12 +448,8 @@ struct mlx5_core_health { }; struct mlx5_qp_table { - struct notifier_block nb; - - /* protect radix tree - */ - spinlock_t lock; - struct radix_tree_root tree; + struct notifier_block nb; + struct xarray array; }; struct mlx5_vf_context { diff --git a/include/linux/mlx5/qp.h b/include/linux/mlx5/qp.h index ae63b1ae9004..6d1577a1ca41 100644 --- a/include/linux/mlx5/qp.h +++ b/include/linux/mlx5/qp.h @@ -555,7 +555,7 @@ struct mlx5_qp_context { static inline struct mlx5_core_qp *__mlx5_qp_lookup(struct mlx5_core_dev *dev, u32 qpn) { - return radix_tree_lookup(&dev->priv.qp_table.tree, qpn); + return xa_load(&dev->priv.qp_table.array, qpn); } int mlx5_core_create_dct(struct mlx5_core_dev *dev, -- 2.23.0.rc1