From patchwork Wed Jul 23 15:26:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4611701 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9513DC0514 for ; Wed, 23 Jul 2014 15:30:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B164720172 for ; Wed, 23 Jul 2014 15:30:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id C75E220107 for ; Wed, 23 Jul 2014 15:30:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 173476E65F; Wed, 23 Jul 2014 08:30:44 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com [74.125.82.44]) by gabe.freedesktop.org (Postfix) with ESMTP id E42266E65D for ; Wed, 23 Jul 2014 08:30:42 -0700 (PDT) Received: by mail-wg0-f44.google.com with SMTP id m15so1351558wgh.3 for ; Wed, 23 Jul 2014 08:30:42 -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=D/3QtPI1++5RoGE4qZTTe9415VqC6w3Bgq8wfh+lbyQ=; b=bwgp82RKk+v9PpA5CqDvJB8h5pDttkwYkyJuwcw8HZb8OiOGoKIuCke3TQMeTuy4Fk KeLkG6Az2iU13/6yRcgOPRtZjdb0Oi1QL6u+CXdVY7jO8Q70KJXvqVbmggEsFvckFdkQ 3/OFE9nOIkF/qFWBpqVIwXIsZHL6ppsyNfObqgbULgkW9vvQrHGzZ4+/D3573JXg0JSC CxG/zYsWJsSzNg2Kmj+756B0VaWjvMFJVHAdr+5oQWX3CCsQmp0IYk1/G9tSiqDqxcbI +UGfavKJGGiUYNcSgtRJde9BnUPTJby/GYpzmqnOyYW3oo3kIyUoUPyTYkd0PSV8xo6+ qy4g== X-Received: by 10.194.134.70 with SMTP id pi6mr2983748wjb.1.1406129441942; Wed, 23 Jul 2014 08:30:41 -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.38 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Jul 2014 08:30:41 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 04/12] drm: extract legacy ctxbitmap flushing Date: Wed, 23 Jul 2014 17:26:39 +0200 Message-Id: <1406129207-1302-5-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 The ctxbitmap code is only used by legacy drivers so lets try to keep it as separated as possible. Furthermore, the locking is non-obvious and kinda weird with ctxlist_mutex *and* struct_mutex. Keeping all ctxbitmap access in one file is much easier to review and makes drm_release() more readable. Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_context.c | 30 ++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_fops.c | 20 +------------------- include/drm/drmP.h | 1 + 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c index a4b017b..c045505 100644 --- a/drivers/gpu/drm/drm_context.c +++ b/drivers/gpu/drm/drm_context.c @@ -111,6 +111,36 @@ void drm_ctxbitmap_cleanup(struct drm_device * dev) mutex_unlock(&dev->struct_mutex); } +/** + * drm_ctxbitmap_flush() - Flush all contexts owned by a file + * @dev: DRM device to operate on + * @file: Open file to flush contexts for + * + * This iterates over all contexts on @dev and drops them if they're owned by + * @file. Note that after this call returns, new contexts might be added if + * the file is still alive. + */ +void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) +{ + struct drm_ctx_list *pos, *tmp; + + mutex_lock(&dev->ctxlist_mutex); + + list_for_each_entry_safe(pos, tmp, &dev->ctxlist, head) { + if (pos->tag == file && + pos->handle != DRM_KERNEL_CONTEXT) { + if (dev->driver->context_dtor) + dev->driver->context_dtor(dev, pos->handle); + + drm_ctxbitmap_free(dev, pos->handle); + list_del(&pos->head); + kfree(pos); + } + } + + mutex_unlock(&dev->ctxlist_mutex); +} + /*@}*/ /******************************************************************/ diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index 8e73519..fb81d1c 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c @@ -452,25 +452,7 @@ int drm_release(struct inode *inode, struct file *filp) if (dev->driver->driver_features & DRIVER_GEM) drm_gem_release(dev, file_priv); - mutex_lock(&dev->ctxlist_mutex); - if (!list_empty(&dev->ctxlist)) { - struct drm_ctx_list *pos, *n; - - list_for_each_entry_safe(pos, n, &dev->ctxlist, head) { - if (pos->tag == file_priv && - pos->handle != DRM_KERNEL_CONTEXT) { - if (dev->driver->context_dtor) - dev->driver->context_dtor(dev, - pos->handle); - - drm_ctxbitmap_free(dev, pos->handle); - - list_del(&pos->head); - kfree(pos); - } - } - } - mutex_unlock(&dev->ctxlist_mutex); + drm_ctxbitmap_flush(dev, file_priv); mutex_lock(&dev->master_mutex); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index d1730c5..d91e09f 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1242,6 +1242,7 @@ extern int drm_rmctx(struct drm_device *dev, void *data, extern int drm_ctxbitmap_init(struct drm_device *dev); extern void drm_ctxbitmap_cleanup(struct drm_device *dev); extern void drm_ctxbitmap_free(struct drm_device *dev, int ctx_handle); +extern void drm_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file); extern int drm_setsareactx(struct drm_device *dev, void *data, struct drm_file *file_priv);