From patchwork Thu Jan 19 00:33:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 6288 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 4E7DE23E29 for ; Thu, 19 Jan 2012 00:33:07 +0000 (UTC) Received: from mail-bk0-f52.google.com (mail-bk0-f52.google.com [209.85.214.52]) by fiordland.canonical.com (Postfix) with ESMTP id 38442A1809F for ; Thu, 19 Jan 2012 00:33:07 +0000 (UTC) Received: by bkbzt4 with SMTP id zt4so3739585bkb.11 for ; Wed, 18 Jan 2012 16:33:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer; bh=+UWL9Wou4s1Wj+eWsKOhc+Avx/+DZZ87WP2klPC94ps=; b=U7PCWfkFuN4RxQ+8VmAxAlC5fGeOUz2O1FNLOE5tmNj77x5D36OnGlJixfITq8qUDi MYDt+EbNlYJyBZvIV0WbmqmmNb0ValumFrnStPNWQGQhb1J3M2ncWlQpyM7KgMZ5Qjkp tOQHqaybxZzjBFKNEwiq9AsDbQN34tjZ893MI= Received: by 10.204.152.20 with SMTP id e20mr9112400bkw.117.1326933186873; Wed, 18 Jan 2012 16:33:06 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.82.144 with SMTP id ac16cs164439bkc; Wed, 18 Jan 2012 16:33:06 -0800 (PST) Received: by 10.236.124.15 with SMTP id w15mr9374965yhh.82.1326933184730; Wed, 18 Jan 2012 16:33:04 -0800 (PST) Received: from mail-gx0-f178.google.com (mail-gx0-f178.google.com [209.85.161.178]) by mx.google.com with ESMTPS id l67si19337146yhm.90.2012.01.18.16.33.04 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 18 Jan 2012 16:33:04 -0800 (PST) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.161.178 as permitted sender) client-ip=209.85.161.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.161.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by ggnp1 with SMTP id p1so1553182ggn.37 for ; Wed, 18 Jan 2012 16:33:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=+UWL9Wou4s1Wj+eWsKOhc+Avx/+DZZ87WP2klPC94ps=; b=UuL35fQysb+XCqimF2HwzFSGbfdGk180cQ8a3z7ARQ9utJcmMMfcmxZejdVbSpU2lZ f1ru+Kys0UWB3KCQ9//ptXfioSsuqFyuxDT42X4LNVn8W4uxFwVP5oTCUwjaYKzI7AQo L+3hTGIWI33k4Nxvf7fXfA1fFjSUbPGTVEi/A= Received: by 10.101.131.12 with SMTP id i12mr10854356ann.7.1326933184227; Wed, 18 Jan 2012 16:33:04 -0800 (PST) Received: from localhost (dragon.ti.com. [192.94.94.33]) by mx.google.com with ESMTPS id p1sm1645102anj.17.2012.01.18.16.33.02 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 18 Jan 2012 16:33:03 -0800 (PST) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, Greg KH , Tomi Valkeinen , Andy Gross , Rob Clark Subject: [PATCH] drm/omap: fix locking issue Date: Wed, 18 Jan 2012 18:33:02 -0600 Message-Id: <1326933182-21236-1-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.5.4 From: Rob Clark The create/free mmap offset code must be synchronized. Yet only some callers of omap_gem_mmap_offset() held struct_mutex. Leading to various crashes around drm_mm_insert_helper_range(). (In the free-object path, which is currently the only place we drm_gem_free_mmap_offset(), struct_mutex is already held.) Signed-off-by: Rob Clark --- drivers/staging/omapdrm/omap_gem.c | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/staging/omapdrm/omap_gem.c b/drivers/staging/omapdrm/omap_gem.c index ae1ad35..b7d6f88 100644 --- a/drivers/staging/omapdrm/omap_gem.c +++ b/drivers/staging/omapdrm/omap_gem.c @@ -116,6 +116,9 @@ struct omap_gem_object { } *sync; }; +static int get_pages(struct drm_gem_object *obj, struct page ***pages); +static uint64_t mmap_offset(struct drm_gem_object *obj); + /* To deal with userspace mmap'ings of 2d tiled buffers, which (a) are * not necessarily pinned in TILER all the time, and (b) when they are * they are not necessarily page aligned, we reserve one or more small @@ -149,7 +152,7 @@ static void evict_entry(struct drm_gem_object *obj, { if (obj->dev->dev_mapping) { size_t size = PAGE_SIZE * usergart[fmt].height; - loff_t off = omap_gem_mmap_offset(obj) + + loff_t off = mmap_offset(obj) + (entry->obj_pgoff << PAGE_SHIFT); unmap_mapping_range(obj->dev->dev_mapping, off, size, 1); } @@ -189,8 +192,6 @@ static inline bool is_shmem(struct drm_gem_object *obj) return obj->filp != NULL; } -static int get_pages(struct drm_gem_object *obj, struct page ***pages); - static DEFINE_SPINLOCK(sync_lock); /** ensure backing pages are allocated */ @@ -251,7 +252,7 @@ static void omap_gem_detach_pages(struct drm_gem_object *obj) } /** get mmap offset */ -uint64_t omap_gem_mmap_offset(struct drm_gem_object *obj) +static uint64_t mmap_offset(struct drm_gem_object *obj) { if (!obj->map_list.map) { /* Make it mmapable */ @@ -267,6 +268,15 @@ uint64_t omap_gem_mmap_offset(struct drm_gem_object *obj) return (uint64_t)obj->map_list.hash.key << PAGE_SHIFT; } +uint64_t omap_gem_mmap_offset(struct drm_gem_object *obj) +{ + uint64_t offset; + mutex_lock(&obj->dev->struct_mutex); + offset = mmap_offset(obj); + mutex_unlock(&obj->dev->struct_mutex); + return offset; +} + /** get mmap size */ size_t omap_gem_mmap_size(struct drm_gem_object *obj) {