From patchwork Mon Jan 14 14:08:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 1972071 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id A197DDF23A for ; Mon, 14 Jan 2013 14:06:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 70169E61D8 for ; Mon, 14 Jan 2013 06:06:28 -0800 (PST) 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 CA16FE5D41 for ; Mon, 14 Jan 2013 06:06:16 -0800 (PST) Received: by mail-we0-f172.google.com with SMTP id r3so2111600wey.3 for ; Mon, 14 Jan 2013 06:06:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=QaD0/MBxQpC61U0pdZv6R0jT0EPvM4KUT0M/5xVV4O4=; b=NHzQd0Puve9QWpTZfP12baT/Y9t9xehD5tY1P6DgaHBLgcNDl2+lh/w87e8QYW9FRx zp/dGL9AYpDqIomdBoq3/VjBcIu9mI4xx/CFxNF9ziMrA1b4/h3Y6LIu2V5wPzNau4gi tlbn7pXW8HHClSoTuMbNuzzW3VNSTG3H7AUFs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=QaD0/MBxQpC61U0pdZv6R0jT0EPvM4KUT0M/5xVV4O4=; b=UURbfyNkx8QzEacU+raj8weHwRFRvgnWy6YdUpwEmys0CZ/LETODrY+was2ZZtstqA J3XduAPNr0hJRkUD+bVwSaqaSASshmgth22Zkn1/+mv5KvrzxzV+dq609hWPO1vNjN01 /Fo9TmRGag03yqQ/LylVOOjkszh6lZynl/imaUYWiZEktJ8IDelpD+5Z51ZYOzXCFmH3 wg8rTaiBTtBXUgegEXt5eR5hYb9sHyC5Jm1L10C+3K9aiY/AwTEcJnmHlYl0TXiBALly Q9s2fdg0hr/FprB+7h3M08mQSVv43xSZQ9kbY1SN8LDES204ZVFTJL24egBzRuMOd1h4 byDw== X-Received: by 10.194.88.202 with SMTP id bi10mr18353435wjb.5.1358172375627; Mon, 14 Jan 2013 06:06:15 -0800 (PST) Received: from phenom.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPS id dm3sm12919539wib.9.2013.01.14.06.06.14 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jan 2013 06:06:14 -0800 (PST) From: Daniel Vetter To: DRI Development Subject: [PATCH] drm/ttm: fix fence locking in ttm_buffer_object_transfer, 2nd try Date: Mon, 14 Jan 2013 15:08:14 +0100 Message-Id: <1358172494-6068-1-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <50F3D977.9090003@canonical.com> References: <50F3D977.9090003@canonical.com> X-Gm-Message-State: ALoCoQllMf/m4VsvCtq1DLtzM9Cb5MANXA5w0TsVGn+nSNoed1AofjUUhZ8PY4bJ4CIEp7RFoq1r Cc: Daniel Vetter , Jerome Glisse 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 This fixes up commit e8e89622ed361c46bf90ba4828e685a8b603f7e5 Author: Daniel Vetter Date: Tue Dec 18 22:25:11 2012 +0100 drm/ttm: fix fence locking in ttm_buffer_object_transfer which leaves behind a might_sleep in atomic context, since the fence_lock spinlock is held over a kmalloc(GFP_KERNEL) call. The fix is to revert the above commit and only take the lock where we need it, around the call to ->sync_obj_ref. v2: Fixup things noticed by Maarten Lankhorst: - Brown paper bag locking bug. - No need for kzalloc if we clear the entire thing on the next line. - check for bo->sync_obj (totally unlikely race, but still someone else could have snuck in) and clear fbo->sync_obj if it's cleared already. Reported-by: Dave Airlie Cc: Jerome Glisse Cc: Maarten Lankhorst Signed-off-by: Daniel Vetter Reviewed-by: Maarten Lankhorst --- drivers/gpu/drm/ttm/ttm_bo_util.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index d73d6e3..544e407 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -422,7 +422,7 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, struct ttm_bo_device *bdev = bo->bdev; struct ttm_bo_driver *driver = bdev->driver; - fbo = kzalloc(sizeof(*fbo), GFP_KERNEL); + fbo = kmalloc(sizeof(*fbo), GFP_KERNEL); if (!fbo) return -ENOMEM; @@ -441,7 +441,12 @@ static int ttm_buffer_object_transfer(struct ttm_buffer_object *bo, fbo->vm_node = NULL; atomic_set(&fbo->cpu_writers, 0); - fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj); + spin_lock(&bdev->fence_lock); + if (bo->sync_obj) + fbo->sync_obj = driver->sync_obj_ref(bo->sync_obj); + else + fbo->sync_obj = NULL; + spin_unlock(&bdev->fence_lock); kref_init(&fbo->list_kref); kref_init(&fbo->kref); fbo->destroy = &ttm_transfered_destroy; @@ -654,13 +659,11 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo, */ set_bit(TTM_BO_PRIV_FLAG_MOVING, &bo->priv_flags); - - /* ttm_buffer_object_transfer accesses bo->sync_obj */ - ret = ttm_buffer_object_transfer(bo, &ghost_obj); spin_unlock(&bdev->fence_lock); if (tmp_obj) driver->sync_obj_unref(&tmp_obj); + ret = ttm_buffer_object_transfer(bo, &ghost_obj); if (ret) return ret;