From patchwork Mon Oct 29 17:35:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilija Hadzic X-Patchwork-Id: 1664951 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id DA13A3FCF7 for ; Mon, 29 Oct 2012 17:40:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CB7099FD70 for ; Mon, 29 Oct 2012 10:40:11 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qa0-f49.google.com (mail-qa0-f49.google.com [209.85.216.49]) by gabe.freedesktop.org (Postfix) with ESMTP id BF30C9F706 for ; Mon, 29 Oct 2012 10:36:57 -0700 (PDT) Received: by mail-qa0-f49.google.com with SMTP id a17so1575847qae.15 for ; Mon, 29 Oct 2012 10:36:56 -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:x-mailer:in-reply-to:references; bh=lLXdjPcVzlTCcEiSYhhsobyP0vD7v89L4o2SMSw8fVg=; b=mltN/NkMYTf/KE0t3MKyoZe/3FYilDfSWHDzIAU3uIngptbh312xVNIvibhXjzH8xi 3mqdcoXJAQOT7y3zh9xR/nuJtUF88KTVxmqdkyptaAzbsJ7GsxycXDVpnolNdpayg5hL j5m87eEkhykdM22kQQl7nDzwfHSQcX4xJt7+0P0O3La9Jkt7hehyZbjqyrTvbSSMrw1C iBbr1kCBWCgmQWmrytkIwAoQ3daEKeNLww2uKTgJXT0YooVIQsaVaQOz8nI2Gim7GBkB Q9G/SPOQhedmXloWx0x6TKtjr71gWsQ/wyBOsOrM3RYUkYTbCzBW2HrEVvjWbWe9R6fx tPnw== Received: by 10.224.187.198 with SMTP id cx6mr18702969qab.56.1351532216885; Mon, 29 Oct 2012 10:36:56 -0700 (PDT) Received: from localhost.localdomain (pool-71-255-86-113.nwrknj.east.verizon.net. [71.255.86.113]) by mx.google.com with ESMTPS id hw8sm6302864qab.9.2012.10.29.10.36.55 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 29 Oct 2012 10:36:56 -0700 (PDT) From: Ilija Hadzic To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/2] drm: set dev_mapping before calling drm_open_helper Date: Mon, 29 Oct 2012 13:35:01 -0400 Message-Id: <1351532101-8523-2-git-send-email-ihadzic@research.bell-labs.com> X-Mailer: git-send-email 1.7.12.4 In-Reply-To: <1351532101-8523-1-git-send-email-ihadzic@research.bell-labs.com> References: <1351532101-8523-1-git-send-email-ihadzic@research.bell-labs.com> Cc: stable@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Some drivers (specifically vmwgfx) look at dev_mapping in their open hook, so we have to set dev->dev_mapping earlier in the process. Reference: http://lists.freedesktop.org/archives/dri-devel/2012-October/029420.html Signed-off-by: Ilija Hadzic Reported-by: Thomas Hellstrom Cc: stable@vger.kernel.org Reviewed-by: Thomas Hellstrom --- drivers/gpu/drm/drm_fops.c | 47 +++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index af68eca..133b413 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c @@ -121,6 +121,8 @@ int drm_open(struct inode *inode, struct file *filp) int minor_id = iminor(inode); struct drm_minor *minor; int retcode = 0; + int need_setup = 0; + struct address_space *old_mapping; minor = idr_find(&drm_minors_idr, minor_id); if (!minor) @@ -132,26 +134,37 @@ int drm_open(struct inode *inode, struct file *filp) if (drm_device_is_unplugged(dev)) return -ENODEV; + if (!dev->open_count++) + need_setup = 1; + mutex_lock(&dev->struct_mutex); + old_mapping = dev->dev_mapping; + if (old_mapping == NULL) + dev->dev_mapping = &inode->i_data; + /* ihold ensures nobody can remove inode with our i_data */ + ihold(container_of(dev->dev_mapping, struct inode, i_data)); + inode->i_mapping = dev->dev_mapping; + filp->f_mapping = dev->dev_mapping; + mutex_unlock(&dev->struct_mutex); + retcode = drm_open_helper(inode, filp, dev); - if (!retcode) { - atomic_inc(&dev->counts[_DRM_STAT_OPENS]); - if (!dev->open_count++) { - retcode = drm_setup(dev); - if (retcode) - dev->open_count--; - } - } - if (!retcode) { - mutex_lock(&dev->struct_mutex); - if (dev->dev_mapping == NULL) - dev->dev_mapping = &inode->i_data; - /* ihold ensures nobody can remove inode with our i_data */ - ihold(container_of(dev->dev_mapping, struct inode, i_data)); - inode->i_mapping = dev->dev_mapping; - filp->f_mapping = dev->dev_mapping; - mutex_unlock(&dev->struct_mutex); + if (retcode) + goto err_undo; + atomic_inc(&dev->counts[_DRM_STAT_OPENS]); + if (need_setup) { + retcode = drm_setup(dev); + if (retcode) + goto err_undo; } + return 0; +err_undo: + mutex_lock(&dev->struct_mutex); + filp->f_mapping = old_mapping; + inode->i_mapping = old_mapping; + iput(container_of(dev->dev_mapping, struct inode, i_data)); + dev->dev_mapping = old_mapping; + mutex_unlock(&dev->struct_mutex); + dev->open_count--; return retcode; } EXPORT_SYMBOL(drm_open);