From patchwork Thu Feb 21 18:41:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10825425 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 644691390 for ; Fri, 22 Feb 2019 08:21:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54C1631AE4 for ; Fri, 22 Feb 2019 08:21:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4913231B10; Fri, 22 Feb 2019 08:21:06 +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 B843931AE4 for ; Fri, 22 Feb 2019 08:21:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD5CA89213; Fri, 22 Feb 2019 08:20:53 +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 0A62B88F9A for ; Thu, 21 Feb 2019 18:42:31 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIk-0000cb-Km; Thu, 21 Feb 2019 18:42:30 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 08/34] drm: Remove linked lists for lessees Date: Thu, 21 Feb 2019 10:41:36 -0800 Message-Id: <20190221184226.2149-17-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=9EeiSOL4vl+mNU7ZnffI/2Xuh5cBDOK/nzX2V/B4AiU=; b=Jp4x3mSKUDj8b9uoZiO3vYW7f 2H/zkU1rYbcvINn/JoxsqAEmDO6I3wkI/4gwf+KoXV1+web+LmsnI1WVWAAi9XxsxwsmSzODH4gM/ 0Yilc8VaFIipx8vZ8hHyWeQLgTPvFcok4pfyXWwmq6whfvijGVrp3fOxYxlTOXlfuR4X25XxKzzIn hWg5vyTZwOafAwzKWCs9qPjCsqS5Mxd8+WbnxduBRL7cvi7CM1WuC4zE9iTzSqjIhp4jxMMs+btH/ SHzisPk8ewe5rBn2zk+hEX7jrw0dx/BoMobUjajUhO9pwrAmMuw5t3JV++OrQDV+hJ5A2gn4g70Sg ihA2rBc4A==; 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 These are already tracked in the XArray so we do not need to also keep a doubly-linked list. Signed-off-by: Matthew Wilcox --- drivers/gpu/drm/drm_auth.c | 4 +-- drivers/gpu/drm/drm_lease.c | 58 ++++++++++++++++++------------------- include/drm/drm_auth.h | 4 +-- 3 files changed, 30 insertions(+), 36 deletions(-) diff --git a/drivers/gpu/drm/drm_auth.c b/drivers/gpu/drm/drm_auth.c index 28767f55b30b..1813507f9b9c 100644 --- a/drivers/gpu/drm/drm_auth.c +++ b/drivers/gpu/drm/drm_auth.c @@ -110,10 +110,8 @@ struct drm_master *drm_master_create(struct drm_device *dev) /* initialize the tree of output resource lessees */ master->lessor = NULL; master->lessee_id = 0; - INIT_LIST_HEAD(&master->lessees); - INIT_LIST_HEAD(&master->lessee_list); idr_init(&master->leases); - xa_init_flags(&master->lessee_xa, XA_FLAGS_ALLOC1); + xa_init_flags(&master->lessees, XA_FLAGS_ALLOC1); return master; } diff --git a/drivers/gpu/drm/drm_lease.c b/drivers/gpu/drm/drm_lease.c index c02587443b61..47830f9ec616 100644 --- a/drivers/gpu/drm/drm_lease.c +++ b/drivers/gpu/drm/drm_lease.c @@ -20,9 +20,6 @@ #include #include -#define drm_for_each_lessee(lessee, lessor) \ - list_for_each_entry((lessee), &(lessor)->lessees, lessee_list) - static uint64_t drm_lease_idr_object; /** @@ -54,7 +51,7 @@ static struct drm_master* _drm_find_lessee(struct drm_master *master, int lessee_id) { lockdep_assert_held(&master->dev->mode_config.idr_mutex); - return xa_load(&drm_lease_owner(master)->lessee_xa, lessee_id); + return xa_load(&drm_lease_owner(master)->lessees, lessee_id); } /** @@ -90,9 +87,10 @@ static int _drm_lease_held_master(struct drm_master *master, int id) static bool _drm_has_leased(struct drm_master *master, int id) { struct drm_master *lessee; + unsigned long index; lockdep_assert_held(&master->dev->mode_config.idr_mutex); - drm_for_each_lessee(lessee, master) + xa_for_each(&master->lessees, index, lessee) if (_drm_lease_held_master(lessee, id)) return true; return false; @@ -231,13 +229,12 @@ static struct drm_master *drm_lease_create(struct drm_master *lessor, struct idr } /* Insert the new lessee into the tree */ - error = xa_alloc(&drm_lease_owner(lessor)->lessee_xa, - &lessee->lessee_id, lessee, xa_limit_32b, GFP_KERNEL); + error = xa_alloc(&drm_lease_owner(lessor)->lessees, &lessee->lessee_id, + lessee, xa_limit_32b, GFP_KERNEL); if (error < 0) goto out_lessee; lessee->lessor = drm_master_get(lessor); - list_add_tail(&lessee->lessee_list, &lessor->lessees); /* Move the leases over */ lessee->leases = *leases; @@ -271,20 +268,13 @@ void drm_lease_destroy(struct drm_master *master) DRM_DEBUG_LEASE("drm_lease_destroy %d\n", master->lessee_id); - /* This master is referenced by all lessees, hence it cannot be destroyed - * until all of them have been - */ - WARN_ON(!list_empty(&master->lessees)); + WARN_ON(!xa_empty(&master->lessees)); /* Remove this master from the lessee array in the owner */ if (master->lessee_id != 0) { DRM_DEBUG_LEASE("remove master %d from device list of lessees\n", master->lessee_id); - xa_erase(&drm_lease_owner(master)->lessee_xa, master->lessee_id); + xa_erase(&drm_lease_owner(master)->lessees, master->lessee_id); } - - /* Remove this master from any lessee list it may be on */ - list_del(&master->lessee_list); - mutex_unlock(&dev->mode_config.idr_mutex); if (master->lessor) { @@ -313,27 +303,34 @@ static void _drm_lease_revoke(struct drm_master *top) * the tree is fully connected, we can do this without recursing */ for (;;) { + struct drm_master *tmp; + unsigned long index = 0; + DRM_DEBUG_LEASE("revoke leases for %p %d\n", master, master->lessee_id); /* Evacuate the lease */ idr_for_each_entry(&master->leases, entry, object) idr_remove(&master->leases, object); - /* Depth-first list walk */ + /* Depth-first tree walk */ + tmp = xa_find(&master->lessees, &index, ULONG_MAX, XA_PRESENT); /* Down */ - if (!list_empty(&master->lessees)) { - master = list_first_entry(&master->lessees, struct drm_master, lessee_list); - } else { - /* Up */ - while (master != top && master == list_last_entry(&master->lessor->lessees, struct drm_master, lessee_list)) - master = master->lessor; - - if (master == top) + if (tmp) { + master = tmp; + continue; + } + /* Over */ + while (master != top) { + index = master->lessee_id; + tmp = xa_find_after(&master->lessor->lessees, &index, + ULONG_MAX, XA_PRESENT); + if (tmp) { + master = tmp; break; - - /* Over */ - master = list_next_entry(master, lessee_list); + } + /* Up */ + master = master->lessor; } } } @@ -612,6 +609,7 @@ int drm_mode_list_lessees_ioctl(struct drm_device *dev, __u32 __user *lessee_ids = (__u32 __user *) (uintptr_t) (arg->lessees_ptr); __u32 count_lessees = arg->count_lessees; struct drm_master *lessor = lessor_priv->master, *lessee; + unsigned long index; int count; int ret = 0; @@ -627,7 +625,7 @@ int drm_mode_list_lessees_ioctl(struct drm_device *dev, mutex_lock(&dev->mode_config.idr_mutex); count = 0; - drm_for_each_lessee(lessee, lessor) { + xa_for_each(&lessor->lessees, index, lessee) { /* Only list un-revoked leases */ if (!idr_is_empty(&lessee->leases)) { if (count_lessees > count) { diff --git a/include/drm/drm_auth.h b/include/drm/drm_auth.h index f1e092406caa..fbb58264538b 100644 --- a/include/drm/drm_auth.h +++ b/include/drm/drm_auth.h @@ -90,10 +90,8 @@ struct drm_master { struct drm_master *lessor; int lessee_id; - struct list_head lessee_list; - struct list_head lessees; struct idr leases; - struct xarray lessee_xa; + struct xarray lessees; }; struct drm_master *drm_master_get(struct drm_master *master);