From patchwork Wed Jul 23 15:26:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4611761 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 74AF69F2B8 for ; Wed, 23 Jul 2014 15:31:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 77DB8201BF for ; Wed, 23 Jul 2014 15:31:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8EDFF20172 for ; Wed, 23 Jul 2014 15:31:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B14526E665; Wed, 23 Jul 2014 08:31:02 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A4856E665 for ; Wed, 23 Jul 2014 08:31:01 -0700 (PDT) Received: by mail-wi0-f174.google.com with SMTP id d1so8083071wiv.7 for ; Wed, 23 Jul 2014 08:31:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ms8dxWsyDGNI9zaeEguTD00Mj8M0l58mEaag6ibq+4o=; b=T+1ZqW4kDOZYEwsHXg3sT1kg5pjV5ldOhP+p7jMsAbG1dlxHwmfsbYctKV/kgFBbvT bsL3sV7J9dLDcAGa5RxziqLxYiUG7iNyjZj+CptEbTNgJku/os9YBwkgiiQ229DmhptB rw9y/bAVbtVpVF4BsJrg9ywooO4/U88RHM57uCgdWe+b7dDvaNELlyHJ7PhdG0DZYVyN hwE57JK2vSLJj00JP6PqPU+Mk2bezERp7Bnh0fq/7Wyt9nGTcMVmvpIFBbKaP9Dr6u14 rgTVFW7/ASEr2M8APSk/9jPUWUGCXMdCEB60Jysuix8apXOo4r6+vg4hWAuz/haRU7lG 4QuA== X-Received: by 10.180.91.225 with SMTP id ch1mr26491431wib.34.1406129460374; Wed, 23 Jul 2014 08:31:00 -0700 (PDT) Received: from david-tp.localdomain (stgt-5f71b1a8.pool.mediaWays.net. [95.113.177.168]) by mx.google.com with ESMTPSA id bx2sm7092580wjb.47.2014.07.23.08.30.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jul 2014 08:30:59 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 11/12] drm: make minor->index available early Date: Wed, 23 Jul 2014 17:26:46 +0200 Message-Id: <1406129207-1302-12-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.0.2 In-Reply-To: <1406129207-1302-1-git-send-email-dh.herrmann@gmail.com> References: <1406129207-1302-1-git-send-email-dh.herrmann@gmail.com> Cc: Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of allocating the minor-index during registration, we now do this during allocation. This way, debug-messages between minor-allocation and minor-registration will now use the correct minor instead of 0. Same is done for unregistration vs. free, so debug-messages between device-shutdown and device-destruction show proper indices. Even though minor-indices are allocated early, we don't enable minor lookup early. Instead, we keep the entry set to NULL and replace it during registration / unregistration. This way, the index is allocated but lookup only works if registered. Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_stub.c | 84 +++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c index b249f14..8b24db5 100644 --- a/drivers/gpu/drm/drm_stub.c +++ b/drivers/gpu/drm/drm_stub.c @@ -256,6 +256,8 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, static int drm_minor_alloc(struct drm_device *dev, unsigned int type) { struct drm_minor *minor; + unsigned long flags; + int r; minor = kzalloc(sizeof(*minor), GFP_KERNEL); if (!minor) @@ -264,57 +266,68 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) minor->type = type; minor->dev = dev; + idr_preload(GFP_KERNEL); + spin_lock_irqsave(&drm_minor_lock, flags); + r = idr_alloc(&drm_minors_idr, + NULL, + 64 * type, + 64 * (type + 1), + GFP_NOWAIT); + spin_unlock_irqrestore(&drm_minor_lock, flags); + idr_preload_end(); + + if (r < 0) + goto err_free; + + minor->index = r; + *drm_minor_get_slot(dev, type) = minor; return 0; + +err_free: + kfree(minor); + return r; } static void drm_minor_free(struct drm_device *dev, unsigned int type) { - struct drm_minor **slot; + struct drm_minor **slot, *minor; + unsigned long flags; slot = drm_minor_get_slot(dev, type); - if (*slot) { - drm_mode_group_destroy(&(*slot)->mode_group); - kfree(*slot); - *slot = NULL; - } + minor = *slot; + if (!minor) + return; + + drm_mode_group_destroy(&minor->mode_group); + + spin_lock_irqsave(&drm_minor_lock, flags); + idr_remove(&drm_minors_idr, minor->index); + spin_unlock_irqrestore(&drm_minor_lock, flags); + + kfree(minor); + *slot = NULL; } static int drm_minor_register(struct drm_device *dev, unsigned int type) { - struct drm_minor *new_minor; + struct drm_minor *minor; unsigned long flags; int ret; - int minor_id; DRM_DEBUG("\n"); - new_minor = *drm_minor_get_slot(dev, type); - if (!new_minor) + minor = *drm_minor_get_slot(dev, type); + if (!minor) return 0; - idr_preload(GFP_KERNEL); - spin_lock_irqsave(&drm_minor_lock, flags); - minor_id = idr_alloc(&drm_minors_idr, - NULL, - 64 * type, - 64 * (type + 1), - GFP_NOWAIT); - spin_unlock_irqrestore(&drm_minor_lock, flags); - idr_preload_end(); - - if (minor_id < 0) - return minor_id; - - new_minor->index = minor_id; - - ret = drm_debugfs_init(new_minor, minor_id, drm_debugfs_root); + ret = drm_debugfs_init(minor, minor->index, drm_debugfs_root); if (ret) { DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n"); - goto err_id; + return ret; } - ret = drm_sysfs_device_add(new_minor); + ret = drm_sysfs_device_add(minor); if (ret) { DRM_ERROR("DRM: Error sysfs_device_add.\n"); goto err_debugfs; @@ -322,19 +335,14 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) /* replace NULL with @minor so lookups will succeed from now on */ spin_lock_irqsave(&drm_minor_lock, flags); - idr_replace(&drm_minors_idr, new_minor, new_minor->index); + idr_replace(&drm_minors_idr, minor, minor->index); spin_unlock_irqrestore(&drm_minor_lock, flags); - DRM_DEBUG("new minor assigned %d\n", minor_id); + DRM_DEBUG("new minor registered %d\n", minor->index); return 0; err_debugfs: - drm_debugfs_cleanup(new_minor); -err_id: - spin_lock_irqsave(&drm_minor_lock, flags); - idr_remove(&drm_minors_idr, minor_id); - spin_unlock_irqrestore(&drm_minor_lock, flags); - new_minor->index = 0; + drm_debugfs_cleanup(minor); return ret; } @@ -347,10 +355,10 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) if (!minor || !minor->kdev) return; + /* replace @minor with NULL so lookups will fail from now on */ spin_lock_irqsave(&drm_minor_lock, flags); - idr_remove(&drm_minors_idr, minor->index); + idr_replace(&drm_minors_idr, NULL, minor->index); spin_unlock_irqrestore(&drm_minor_lock, flags); - minor->index = 0; drm_debugfs_cleanup(minor); drm_sysfs_device_remove(minor);