From patchwork Thu Feb 21 18:41:44 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: 10825497 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 57AD1139A for ; Fri, 22 Feb 2019 08:22:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45C3131B3D for ; Fri, 22 Feb 2019 08:22:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 36CEC31B5E; Fri, 22 Feb 2019 08:22:14 +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 48F7031B3D for ; Fri, 22 Feb 2019 08:22:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9756F8945A; Fri, 22 Feb 2019 08:21:29 +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 6417289061 for ; Thu, 21 Feb 2019 18:42:32 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIl-0000dn-Vz; Thu, 21 Feb 2019 18:42:31 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 12/34] drm/agp: Convert bo_list_handles to XArray Date: Thu, 21 Feb 2019 10:41:44 -0800 Message-Id: <20190221184226.2149-25-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=NdqfHzho97JdjbSEcpaPrb53w+OVEx3xgfATurPgtDo=; b=gfsp1alo4H+QDsyJnCf5Dt/70 NlJ1UsXV/9dhsTJJTcYgeIyzP6U1h0q0e9Chg2Dd36/nSMk6/YS0o34gBVDKWIJbqmRbtNE3NIZPj mo9c7H2h+I2CsQbY+eVNRAa7RP4y5cI8bNv8xedCLRH5NsgdGmxxEFuISQJgm1KBFzFCm3VosU8Kc qP3ScQKkPmVeg7fq5xIDSIpBtXaLn1uOdmle56J+mDLJPyv8ThXkY5fZSFwNBuLFD2wRBCZa2GJCM 8S2BC/uG0YRJZpTkzNj3UQq1mpioCIh9kd04qCYRpCjuOYcPL31cfPuu+rsfnjurgk7akM/wEfc2I oUWy8J+XQ==; 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/amd/amdgpu/amdgpu.h | 3 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 22 ++++++++------------- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 10 ++++------ 3 files changed, 13 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index bcef6ea4bcf9..6a704aaa7dbe 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -406,8 +406,7 @@ struct amdgpu_fpriv { struct amdgpu_vm vm; struct amdgpu_bo_va *prt_va; struct amdgpu_bo_va *csa_va; - struct mutex bo_list_lock; - struct idr bo_list_handles; + struct xarray bo_list_handles; struct amdgpu_ctx_mgr ctx_mgr; }; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c index 5c79da8e1150..76439a52a6b0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c @@ -153,9 +153,7 @@ static void amdgpu_bo_list_destroy(struct amdgpu_fpriv *fpriv, int id) { struct amdgpu_bo_list *list; - mutex_lock(&fpriv->bo_list_lock); - list = idr_remove(&fpriv->bo_list_handles, id); - mutex_unlock(&fpriv->bo_list_lock); + list = xa_erase(&fpriv->bo_list_handles, id); if (list) kref_put(&list->refcount, amdgpu_bo_list_free); } @@ -164,7 +162,7 @@ int amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id, struct amdgpu_bo_list **result) { rcu_read_lock(); - *result = idr_find(&fpriv->bo_list_handles, id); + *result = xa_load(&fpriv->bo_list_handles, id); if (*result && kref_get_unless_zero(&(*result)->refcount)) { rcu_read_unlock(); @@ -278,15 +276,13 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, if (r) goto error_free; - mutex_lock(&fpriv->bo_list_lock); - r = idr_alloc(&fpriv->bo_list_handles, list, 1, 0, GFP_KERNEL); - mutex_unlock(&fpriv->bo_list_lock); + r = xa_alloc(&fpriv->bo_list_handles, &handle, list, + xa_limit_31b, GFP_KERNEL); if (r < 0) { amdgpu_bo_list_put(list); return r; } - handle = r; break; case AMDGPU_BO_LIST_OP_DESTROY: @@ -300,13 +296,11 @@ int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data, if (r) goto error_free; - mutex_lock(&fpriv->bo_list_lock); - old = idr_replace(&fpriv->bo_list_handles, list, handle); - mutex_unlock(&fpriv->bo_list_lock); - - if (IS_ERR(old)) { + old = xa_store(&fpriv->bo_list_handles, handle, list, + GFP_KERNEL); + if (xa_is_err(old)) { amdgpu_bo_list_put(list); - r = PTR_ERR(old); + r = xa_err(old); goto error_free; } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index bc62bf41b7e9..1a5bf3a4f5d9 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -986,8 +986,7 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) goto error_vm; } - mutex_init(&fpriv->bo_list_lock); - idr_init(&fpriv->bo_list_handles); + xa_init_flags(&fpriv->bo_list_handles, XA_FLAGS_ALLOC1); amdgpu_ctx_mgr_init(&fpriv->ctx_mgr); @@ -1026,7 +1025,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, struct amdgpu_bo_list *list; struct amdgpu_bo *pd; unsigned int pasid; - int handle; + unsigned long handle; if (!fpriv) return; @@ -1058,11 +1057,10 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, amdgpu_pasid_free_delayed(pd->tbo.resv, pasid); amdgpu_bo_unref(&pd); - idr_for_each_entry(&fpriv->bo_list_handles, list, handle) + xa_for_each(&fpriv->bo_list_handles, handle, list) amdgpu_bo_list_put(list); - idr_destroy(&fpriv->bo_list_handles); - mutex_destroy(&fpriv->bo_list_lock); + xa_destroy(&fpriv->bo_list_handles); kfree(fpriv); file_priv->driver_priv = NULL;