From patchwork Thu Jun 27 11:48:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 2792081 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 E9900C0AB1 for ; Thu, 27 Jun 2013 11:56:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8ADF62027C for ; Thu, 27 Jun 2013 11:56:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 4D5EB2027A for ; Thu, 27 Jun 2013 11:56:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 42BF0E654B for ; Thu, 27 Jun 2013 04:56:56 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f172.google.com (mail-we0-f172.google.com [74.125.82.172]) by gabe.freedesktop.org (Postfix) with ESMTP id E0924E5C4E for ; Thu, 27 Jun 2013 04:48:51 -0700 (PDT) Received: by mail-we0-f172.google.com with SMTP id q56so484260wes.31 for ; Thu, 27 Jun 2013 04:48:50 -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=E9LqwAAjsHz2IbzlN8Y4m2JDQgFt1dSpR6Gl+0y25pk=; b=Wp4SQI7SgrLvSZJaugwnNL+tRJX9+R+vjlP69d4ULJCSuPeLo6/99bbM11dZj85pxA GZEXAvMrfwJaKY24O/V+tAwGN7VjXlUm2toBC2pZZuQfcI9+1aFjPlldowNX/6oOOTuu RueNw5VkJMgCnfS2lUIIunR+ULEdjlWjZYcX359RtPLcwinE/eLy31RsRof201Gq+k/T f9GQJG5yXKmFrWw/g0DrzyNX45eEmE7Sr9PvgrHH/gkDwXUE/QRLY/n0xbItE5hHza3L 8s/fDNXTiSF+pyO81jU2+yugAZTct5CRK/Hb4DmZv+QJqeuER0mIG80Isy8CqlpwnRA+ gAuQ== X-Received: by 10.180.92.98 with SMTP id cl2mr5604489wib.43.1372333730515; Thu, 27 Jun 2013 04:48:50 -0700 (PDT) Received: from localhost (5ED49945.cm-7-5c.dynamic.ziggo.nl. [94.212.153.69]) by mx.google.com with ESMTPSA id j20sm3071780wie.7.2013.06.27.04.48.48 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 27 Jun 2013 04:48:50 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Thu, 27 Jun 2013 13:48:48 +0200 From: Maarten Lankhorst To: Dave Airlie Subject: [PATCH WW 03/13] drm/nouveau: make flipping lockdep safe Date: Thu, 27 Jun 2013 13:48:18 +0200 Message-Id: <1372333708-29884-4-git-send-email-maarten.lankhorst@canonical.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1372333708-29884-1-git-send-email-maarten.lankhorst@canonical.com> References: <1372333708-29884-1-git-send-email-maarten.lankhorst@canonical.com> Cc: 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: , 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 X-Spam-Status: No, score=-5.4 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 cli->mutex was inverted with reservations, and multiple reservations were used without a ticket, fix both. This commit had to be done after the previous commit, because otherwise ttm_eu_* calls would use a different seqno counter.. Signed-off-by: Maarten Lankhorst --- drivers/gpu/drm/nouveau/nouveau_display.c | 103 +++++++++++++----------------- 1 file changed, 45 insertions(+), 58 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c index f17dc2a..87afb0c 100644 --- a/drivers/gpu/drm/nouveau/nouveau_display.c +++ b/drivers/gpu/drm/nouveau/nouveau_display.c @@ -26,6 +26,7 @@ #include #include +#include #include "nouveau_fbcon.h" #include "dispnv04/hw.h" @@ -457,51 +458,6 @@ nouveau_display_resume(struct drm_device *dev) } static int -nouveau_page_flip_reserve(struct nouveau_bo *old_bo, - struct nouveau_bo *new_bo) -{ - int ret; - - ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM); - if (ret) - return ret; - - ret = ttm_bo_reserve(&new_bo->bo, false, false, false, 0); - if (ret) - goto fail; - - if (likely(old_bo != new_bo)) { - ret = ttm_bo_reserve(&old_bo->bo, false, false, false, 0); - if (ret) - goto fail_unreserve; - } - - return 0; - -fail_unreserve: - ttm_bo_unreserve(&new_bo->bo); -fail: - nouveau_bo_unpin(new_bo); - return ret; -} - -static void -nouveau_page_flip_unreserve(struct nouveau_bo *old_bo, - struct nouveau_bo *new_bo, - struct nouveau_fence *fence) -{ - nouveau_bo_fence(new_bo, fence); - ttm_bo_unreserve(&new_bo->bo); - - if (likely(old_bo != new_bo)) { - nouveau_bo_fence(old_bo, fence); - ttm_bo_unreserve(&old_bo->bo); - } - - nouveau_bo_unpin(old_bo); -} - -static int nouveau_page_flip_emit(struct nouveau_channel *chan, struct nouveau_bo *old_bo, struct nouveau_bo *new_bo, @@ -563,6 +519,9 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, struct nouveau_page_flip_state *s; struct nouveau_channel *chan = NULL; struct nouveau_fence *fence; + struct list_head res; + struct ttm_validate_buffer res_val[2]; + struct ww_acquire_ctx ticket; int ret; if (!drm->channel) @@ -572,25 +531,43 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, if (!s) return -ENOMEM; - /* Don't let the buffers go away while we flip */ - ret = nouveau_page_flip_reserve(old_bo, new_bo); - if (ret) - goto fail_free; - - /* Initialize a page flip struct */ - *s = (struct nouveau_page_flip_state) - { { }, event, nouveau_crtc(crtc)->index, - fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y, - new_bo->bo.offset }; - /* Choose the channel the flip will be handled in */ + spin_lock(&old_bo->bo.bdev->fence_lock); fence = new_bo->bo.sync_obj; if (fence) chan = fence->channel; if (!chan) chan = drm->channel; + spin_unlock(&old_bo->bo.bdev->fence_lock); + mutex_lock(&chan->cli->mutex); + if (new_bo != old_bo) { + ret = nouveau_bo_pin(new_bo, TTM_PL_FLAG_VRAM); + if (likely(!ret)) { + res_val[0].bo = &old_bo->bo; + res_val[1].bo = &new_bo->bo; + INIT_LIST_HEAD(&res); + list_add_tail(&res_val[0].head, &res); + list_add_tail(&res_val[1].head, &res); + ret = ttm_eu_reserve_buffers(&ticket, &res); + if (ret) + nouveau_bo_unpin(new_bo); + } + } else + ret = ttm_bo_reserve(&new_bo->bo, false, false, false, 0); + + if (ret) { + mutex_unlock(&chan->cli->mutex); + goto fail_free; + } + + /* Initialize a page flip struct */ + *s = (struct nouveau_page_flip_state) + { { }, event, nouveau_crtc(crtc)->index, + fb->bits_per_pixel, fb->pitches[0], crtc->x, crtc->y, + new_bo->bo.offset }; + /* Emit a page flip */ if (nv_device(drm->device)->card_type >= NV_50) { ret = nv50_display_flip_next(crtc, fb, chan, 0); @@ -608,12 +585,22 @@ nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb, /* Update the crtc struct and cleanup */ crtc->fb = fb; - nouveau_page_flip_unreserve(old_bo, new_bo, fence); + if (old_bo != new_bo) { + ttm_eu_fence_buffer_objects(&ticket, &res, fence); + nouveau_bo_unpin(old_bo); + } else { + nouveau_bo_fence(new_bo, fence); + ttm_bo_unreserve(&new_bo->bo); + } nouveau_fence_unref(&fence); return 0; fail_unreserve: - nouveau_page_flip_unreserve(old_bo, new_bo, NULL); + if (old_bo != new_bo) { + ttm_eu_backoff_reservation(&ticket, &res); + nouveau_bo_unpin(new_bo); + } else + ttm_bo_unreserve(&new_bo->bo); fail_free: kfree(s); return ret;