From patchwork Thu Feb 21 18:42:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10825439 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 2EB5E1390 for ; Fri, 22 Feb 2019 08:21:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FC76311FE for ; Fri, 22 Feb 2019 08:21:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1428C31A4F; Fri, 22 Feb 2019 08:21:20 +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 A40E231AEE for ; Fri, 22 Feb 2019 08:21:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EAA7D8932D; Fri, 22 Feb 2019 08:20:54 +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 3B0A18916C 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-0000jt-Qk; Thu, 21 Feb 2019 18:42:38 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 34/34] drm/vmwgfx: Convert res_idr to XArray Date: Thu, 21 Feb 2019 10:42:25 -0800 Message-Id: <20190221184226.2149-66-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=Vr5NI1kkOBVS0pKja/cWdKceNYpKvjTFXjvc0DZpOEg=; b=l+RRullMwt6AiBYXk6cf1nJUP MnBqsDBjiQv4o9cYZYexRfrxA8IeHZzTvuk+KrcMWe77mM5b9DgSB5UIS0Kjn3EsH+e68/cZP0wf9 BWW7DaOP1qPwarf7qdgK36jDxgS3rXRg8OhWu9ul9XapRyys4XlcJxTvd8+HBPKMo//iEqByNUvRH NssPag8XvTO3UmBfUyPDOoTIPtGyfOSzOYfdaH4y6MKBN+1NTqW25d+6geM8h87ZeQkNVJifs66NQ 36bv635f1olZgMenZauEBLTa5cE20UNzIPttET9q9FyEIn6PQjG+yTsdJOR4BN9cVZw64WlqAN4hK VVsRPt8iQ==; 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/vmwgfx_drv.c | 9 +------ drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 3 ++- drivers/gpu/drm/vmwgfx/vmwgfx_resource.c | 31 ++++++------------------ 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index 25afb1d594e3..2d121fbe5c93 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -677,7 +677,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) spin_lock_init(&dev_priv->cursor_lock); for (i = vmw_res_context; i < vmw_res_max; ++i) { - idr_init(&dev_priv->res_idr[i]); + xa_init_flags(&dev_priv->resources[i], XA_FLAGS_ALLOC1); INIT_LIST_HEAD(&dev_priv->res_lru[i]); } @@ -988,9 +988,6 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) out_err4: memunmap(dev_priv->mmio_virt); out_err0: - for (i = vmw_res_context; i < vmw_res_max; ++i) - idr_destroy(&dev_priv->res_idr[i]); - if (dev_priv->ctx.staged_bindings) vmw_binding_state_free(dev_priv->ctx.staged_bindings); kfree(dev_priv); @@ -1000,7 +997,6 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) static void vmw_driver_unload(struct drm_device *dev) { struct vmw_private *dev_priv = vmw_priv(dev); - enum vmw_res_type i; unregister_pm_notifier(&dev_priv->pm_nb); @@ -1039,9 +1035,6 @@ static void vmw_driver_unload(struct drm_device *dev) if (dev_priv->ctx.staged_bindings) vmw_binding_state_free(dev_priv->ctx.staged_bindings); - for (i = vmw_res_context; i < vmw_res_max; ++i) - idr_destroy(&dev_priv->res_idr[i]); - kfree(dev_priv); } diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index cd607ba9c2fe..e7613a33a773 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -484,7 +484,8 @@ struct vmw_private { */ spinlock_t resource_lock; - struct idr res_idr[vmw_res_max]; + struct xarray resources[vmw_res_max]; + /* * Block lastclose from racing with firstopen. */ diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c index 3025bfc001a1..d8cc329a9c0e 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_resource.c @@ -56,13 +56,11 @@ vmw_resource_reference_unless_doomed(struct vmw_resource *res) void vmw_resource_release_id(struct vmw_resource *res) { struct vmw_private *dev_priv = res->dev_priv; - struct idr *idr = &dev_priv->res_idr[res->func->res_type]; + struct xarray *xa = &dev_priv->resources[res->func->res_type]; - spin_lock(&dev_priv->resource_lock); if (res->id != -1) - idr_remove(idr, res->id); + xa_erase(xa, res->id); res->id = -1; - spin_unlock(&dev_priv->resource_lock); } static void vmw_resource_release(struct kref *kref) @@ -70,8 +68,7 @@ static void vmw_resource_release(struct kref *kref) struct vmw_resource *res = container_of(kref, struct vmw_resource, kref); struct vmw_private *dev_priv = res->dev_priv; - int id; - struct idr *idr = &dev_priv->res_idr[res->func->res_type]; + struct xarray *xa = &dev_priv->resources[res->func->res_type]; spin_lock(&dev_priv->resource_lock); list_del_init(&res->lru_head); @@ -101,16 +98,12 @@ static void vmw_resource_release(struct kref *kref) res->hw_destroy(res); } - id = res->id; + if (res->id != -1) + xa_erase(xa, res->id); if (res->res_free != NULL) res->res_free(res); else kfree(res); - - spin_lock(&dev_priv->resource_lock); - if (id != -1) - idr_remove(idr, id); - spin_unlock(&dev_priv->resource_lock); } void vmw_resource_unreference(struct vmw_resource **p_res) @@ -133,21 +126,11 @@ void vmw_resource_unreference(struct vmw_resource **p_res) int vmw_resource_alloc_id(struct vmw_resource *res) { struct vmw_private *dev_priv = res->dev_priv; - int ret; - struct idr *idr = &dev_priv->res_idr[res->func->res_type]; + struct xarray *xa = &dev_priv->resources[res->func->res_type]; BUG_ON(res->id != -1); - idr_preload(GFP_KERNEL); - spin_lock(&dev_priv->resource_lock); - - ret = idr_alloc(idr, res, 1, 0, GFP_NOWAIT); - if (ret >= 0) - res->id = ret; - - spin_unlock(&dev_priv->resource_lock); - idr_preload_end(); - return ret < 0 ? ret : 0; + return xa_alloc(xa, &res->id, res, xa_limit_31b, GFP_NOWAIT); } /**