From patchwork Thu Feb 21 18:42:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 10825501 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 371FA184E for ; Fri, 22 Feb 2019 08:22:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F6A831AFD for ; Fri, 22 Feb 2019 08:22:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04D3031B4E; Fri, 22 Feb 2019 08:22:15 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E6A4D31B4D for ; Fri, 22 Feb 2019 08:22:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4233889471; Fri, 22 Feb 2019 08:21:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2205E8916A for ; Thu, 21 Feb 2019 18:42:39 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIs-0000jh-Lh; Thu, 21 Feb 2019 18:42:38 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 33/34] drm/vmwgfx: Convert base IDR to XArray Date: Thu, 21 Feb 2019 10:42:24 -0800 Message-Id: <20190221184226.2149-65-willy@infradead.org> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190221184226.2149-1-willy@infradead.org> References: <20190221184226.2149-1-willy@infradead.org> X-Mailman-Approved-At: Fri, 22 Feb 2019 08:20:52 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding: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=J2CoKvxh5l32wQKArh7dCZszpBuaNKccrvtZ+ihJ4Vc=; b=XwLmruQ1pfNOCuWDCqEWpdxgO /cvLAJtlLE3tNpyUJli8Iwr5yQaSQGFfc5VhUfM+x0EbLSUnosPrYrW3HRucYb53CBA0z3uDfOjsP 5RYcPlZDVmvdJFHgGDJJcG2xlKcI9PEPTVhnNHARRsqlSNVU3Ee8ZKgZn70ibp4MsqYR/S/pfb4ql 47KVVxZlQhNbZrM4HLtwvBpSOoSLbttyA9PnQk8icGP0m+PyZ0yegPs+AGd6iP6GeXOuFEzOsRtGh njwKzh3Q1hP3HXfFpZBUbqRTiONSwsVL+A32FoXzTqwcr3ZhgKOONxV2qNebjWjC0mADiWMlYUqs3 y4Q+1Td3g==; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthew Wilcox MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Matthew Wilcox --- drivers/gpu/drm/vmwgfx/ttm_object.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/ttm_object.c b/drivers/gpu/drm/vmwgfx/ttm_object.c index 36990b80e790..8f394b94060b 100644 --- a/drivers/gpu/drm/vmwgfx/ttm_object.c +++ b/drivers/gpu/drm/vmwgfx/ttm_object.c @@ -77,8 +77,6 @@ struct ttm_object_file { /** * struct ttm_object_device * - * @object_lock: lock that protects the object_hash hash table. - * * @object_hash: hash table for fast lookup of object global names. * * @object_count: Per device object count. @@ -87,14 +85,13 @@ struct ttm_object_file { */ struct ttm_object_device { - spinlock_t object_lock; struct drm_open_hash object_hash; atomic_t object_count; struct ttm_mem_global *mem_glob; struct dma_buf_ops ops; void (*dmabuf_release)(struct dma_buf *dma_buf); size_t dma_buf_size; - struct idr idr; + struct xarray bases; }; /** @@ -172,15 +169,11 @@ int ttm_base_object_init(struct ttm_object_file *tfile, base->ref_obj_release = ref_obj_release; base->object_type = object_type; kref_init(&base->refcount); - idr_preload(GFP_KERNEL); - spin_lock(&tdev->object_lock); - ret = idr_alloc(&tdev->idr, base, 0, 0, GFP_NOWAIT); - spin_unlock(&tdev->object_lock); - idr_preload_end(); + ret = xa_alloc(&tdev->bases, &base->handle, base, xa_limit_31b, + GFP_KERNEL); if (ret < 0) return ret; - base->handle = ret; ret = ttm_ref_object_add(tfile, base, TTM_REF_USAGE, NULL, false); if (unlikely(ret != 0)) goto out_err1; @@ -189,9 +182,7 @@ int ttm_base_object_init(struct ttm_object_file *tfile, return 0; out_err1: - spin_lock(&tdev->object_lock); - idr_remove(&tdev->idr, base->handle); - spin_unlock(&tdev->object_lock); + xa_erase(&tdev->bases, base->handle); return ret; } @@ -201,9 +192,7 @@ static void ttm_release_base(struct kref *kref) container_of(kref, struct ttm_base_object, refcount); struct ttm_object_device *tdev = base->tfile->tdev; - spin_lock(&tdev->object_lock); - idr_remove(&tdev->idr, base->handle); - spin_unlock(&tdev->object_lock); + xa_erase(&tdev->bases, base->handle); /* * Note: We don't use synchronize_rcu() here because it's far @@ -287,7 +276,7 @@ ttm_base_object_lookup_for_ref(struct ttm_object_device *tdev, uint32_t key) struct ttm_base_object *base; rcu_read_lock(); - base = idr_find(&tdev->idr, key); + base = xa_load(&tdev->bases, key); if (base && !kref_get_unless_zero(&base->refcount)) base = NULL; @@ -534,13 +523,12 @@ ttm_object_device_init(struct ttm_mem_global *mem_glob, return NULL; tdev->mem_glob = mem_glob; - spin_lock_init(&tdev->object_lock); atomic_set(&tdev->object_count, 0); ret = drm_ht_create(&tdev->object_hash, hash_order); if (ret != 0) goto out_no_object_hash; - idr_init(&tdev->idr); + xa_init_flags(&tdev->bases, XA_FLAGS_ALLOC); tdev->ops = *ops; tdev->dmabuf_release = tdev->ops.release; tdev->ops.release = ttm_prime_dmabuf_release; @@ -559,8 +547,7 @@ void ttm_object_device_release(struct ttm_object_device **p_tdev) *p_tdev = NULL; - WARN_ON_ONCE(!idr_is_empty(&tdev->idr)); - idr_destroy(&tdev->idr); + WARN_ON_ONCE(!xa_empty(&tdev->bases)); drm_ht_remove(&tdev->object_hash); kfree(tdev);