From patchwork Tue Jan 14 15:52:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 3486521 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 42182C02DC for ; Tue, 14 Jan 2014 15:52:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2C2ED20219 for ; Tue, 14 Jan 2014 15:52:49 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 06FA120218 for ; Tue, 14 Jan 2014 15:52:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0E08EFD210; Tue, 14 Jan 2014 07:52:42 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by gabe.freedesktop.org (Postfix) with ESMTP id CB3B7FD208; Tue, 14 Jan 2014 07:52:36 -0800 (PST) Received: from 5ed49945.cm-7-5c.dynamic.ziggo.nl ([94.212.153.69] helo=[192.168.1.128]) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1W36I8-0003St-1q; Tue, 14 Jan 2014 15:52:36 +0000 Message-ID: <52D55D43.4070805@canonical.com> Date: Tue, 14 Jan 2014 16:52:35 +0100 From: Maarten Lankhorst User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Ben Skeggs Subject: [PATCH 2/2] drm/nouveau: require cli->mutex in RING_SPACE References: <52D55C6A.80804@canonical.com> In-Reply-To: <52D55C6A.80804@canonical.com> Cc: "nouveau@lists.freedesktop.org" , "dri-devel@lists.freedesktop.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: , Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, 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 There are some cases where it's fine to not hold the cli->mutex, but in those cases we are the only caller and we should really be able to acquire cli->mutex without blocking. This patch will prevent future occurrences where commands are sent to a channel without proper locking. Signed-off-by: Maarten Lankhorst diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouveau/nouveau_abi16.c index 900fae01793e..20959e445d05 100644 --- a/drivers/gpu/drm/nouveau/nouveau_abi16.c +++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c @@ -153,10 +153,12 @@ nouveau_abi16_fini(struct nouveau_abi16 *abi16) struct nouveau_cli *cli = (void *)abi16->client; struct nouveau_abi16_chan *chan, *temp; + mutex_lock(&cli->mutex); /* cleanup channels */ list_for_each_entry_safe(chan, temp, &abi16->channels, head) { nouveau_abi16_chan_fini(abi16, chan); } + mutex_unlock(&cli->mutex); /* destroy the device object */ nouveau_object_del(abi16->client, NVDRM_CLIENT, NVDRM_DEVICE); diff --git a/drivers/gpu/drm/nouveau/nouveau_dma.h b/drivers/gpu/drm/nouveau/nouveau_dma.h index 984004d66a6d..82465bd0b59b 100644 --- a/drivers/gpu/drm/nouveau/nouveau_dma.h +++ b/drivers/gpu/drm/nouveau/nouveau_dma.h @@ -107,6 +107,7 @@ RING_SPACE(struct nouveau_channel *chan, int size) { int ret; + lockdep_assert_held(&chan->cli->mutex); ret = nouveau_dma_wait(chan, 1, size); if (ret) return ret; diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.c b/drivers/gpu/drm/nouveau/nouveau_drm.c index f7a6568cfa6a..a60c404d59e4 100644 --- a/drivers/gpu/drm/nouveau/nouveau_drm.c +++ b/drivers/gpu/drm/nouveau/nouveau_drm.c @@ -476,7 +476,9 @@ nouveau_drm_load(struct drm_device *dev, unsigned long flags) nouveau_sysfs_init(dev); nouveau_hwmon_init(dev); + mutex_lock(&drm->client.mutex); nouveau_accel_init(drm); + mutex_unlock(&drm->client.mutex); nouveau_fbcon_init(dev); if (nouveau_runtime_pm != 0) { @@ -562,17 +564,17 @@ nouveau_do_suspend(struct drm_device *dev) ttm_bo_evict_mm(&drm->ttm.bdev, TTM_PL_VRAM); NV_INFO(drm, "waiting for kernel channels to go idle...\n"); - if (drm->cechan) { + ret = 0; + mutex_lock(&drm->client.mutex); + if (drm->cechan) ret = nouveau_channel_idle(drm->cechan); - if (ret) - return ret; - } - if (drm->channel) { + if (drm->channel && !ret) ret = nouveau_channel_idle(drm->channel); - if (ret) - return ret; - } + mutex_unlock(&drm->client.mutex); + if (ret) + return ret; + NV_INFO(drm, "suspending client object trees...\n"); if (drm->fence && nouveau_fence(drm)->suspend) { diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c index 7903e0ed3c75..aec87e1d3855 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c +++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c @@ -357,7 +357,7 @@ nouveau_fbcon_create(struct drm_fb_helper *helper, mutex_unlock(&dev->struct_mutex); - if (chan) { + if (chan && !WARN_ON(!mutex_trylock(&drm->client.mutex))) { ret = -ENODEV; if (device->card_type < NV_50) ret = nv04_fbcon_accel_init(info); @@ -366,6 +366,7 @@ nouveau_fbcon_create(struct drm_fb_helper *helper, ret = nv50_fbcon_accel_init(info); else ret = nvc0_fbcon_accel_init(info); + mutex_unlock(&drm->client.mutex); if (ret == 0) info->fbops = &nouveau_fbcon_ops;