From patchwork Wed Aug 14 22:02:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 2844812 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 87BABBF546 for ; Wed, 14 Aug 2013 22:08:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8009220508 for ; Wed, 14 Aug 2013 22:08:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 8ED45204FE for ; Wed, 14 Aug 2013 22:08:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 75C65E6C0A for ; Wed, 14 Aug 2013 15:08:39 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ee0-f45.google.com (mail-ee0-f45.google.com [74.125.83.45]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A4C8E5CB8 for ; Wed, 14 Aug 2013 15:03:04 -0700 (PDT) Received: by mail-ee0-f45.google.com with SMTP id c50so10735eek.32 for ; Wed, 14 Aug 2013 15:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JFnF1C88YeTMt7Wgb5TRzP3KfNdI6SOvDIdprkqwh2g=; b=ew7XJUxOGQz7NjQCSalIX/BtLO+PqLwtMRhnYVPv6w/3ZR5YQQf7Cebzf7Z3KJKPoC vsLR70zGENbF+yYRli4E2HeqnOatH/XLu6KCclct+E1p4F6u5rgf+erQZIyD1Nnmeasf rxx0IlFkFiBbgJGix+dGX4S4z8pGHc0XC5m0A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JFnF1C88YeTMt7Wgb5TRzP3KfNdI6SOvDIdprkqwh2g=; b=mH4XkitnFIpeMDMqs5Jx0pMYqF8TaxFvhohvUfL3Q6whpt+JoadTWym4IbskZwGCR+ qJnRIpAy9RMaIVziSlqQg/kLNsEHk5LcOjd4W/x/c8B/wQeDH2RvVOU7drN/P/w6peiG DNI3LKVCZsctzg4hGC8bUXc5wHADHXUM9wHrrcDe2hUCKjk/qhQ02A0bVOYO/AsHnoyx yxcXGqiHCt3WHI0dznZ/JnAd0gK0K4mOp0QNWJ5LFFZUBZ8EWiqiUtGjRVRPHukDvLTH YNplYPVlMQPemuCshtEkSooIRTRTT1Exv6kvDAiZSwwxZnC1dv9RF4Y0QnX7yHOew+nf 8LsQ== X-Gm-Message-State: ALoCoQkpS49OMCKHiNdzlzP806+sz5t9+A02okAUt/rzBQpjDstTR+PLd6C1SeIYl3NI/6mFgdSi X-Received: by 10.14.8.199 with SMTP id 47mr77732eer.101.1376517783395; Wed, 14 Aug 2013 15:03:03 -0700 (PDT) Received: from aaron.ffwll.local (178-83-130-250.dynamic.hispeed.ch. [178.83.130.250]) by mx.google.com with ESMTPSA id m54sm78874820eex.2.2013.08.14.15.03.01 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 14 Aug 2013 15:03:02 -0700 (PDT) From: Daniel Vetter To: Intel Graphics Development , DRI Development Subject: [PATCH 03/20] drm/prime: remove cargo-cult locking from map_sg helper Date: Thu, 15 Aug 2013 00:02:32 +0200 Message-Id: <1376517769-7171-4-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1376517769-7171-1-git-send-email-daniel.vetter@ffwll.ch> References: <1376517769-7171-1-git-send-email-daniel.vetter@ffwll.ch> Cc: Daniel Vetter , Laurent Pinchart 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=-6.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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 I've checked both implementations (radeon/nouveau) and they both grab the page array from ttm simply by dereferencing it and then wrapping it up with drm_prime_pages_to_sg in the callback and map it with dma_map_sg (in the helper). Only the grabbing of the underlying page array is anything we need to be concerned about, and either those pages are pinned independently, or we're screwed no matter what. And indeed, nouveau/radeon pin the backing storage in their attach/detach functions. Since I've created this patch cma prime support for dma_buf was added. drm_gem_cma_prime_get_sg_table only calls kzalloc and the creates&maps the sg table with dma_get_sgtable. It doesn't touch any gem object state otherwise. So the cma helpers also look safe. The only thing we might claim it does is prevent concurrent mapping of dma_buf attachments. But a) that's not allowed and b) the current code is racy already since it checks whether the sg mapping exists _before_ grabbing the lock. So the dev->struct_mutex locking here does absolutely nothing useful, but only distracts. Remove it. This should also help Maarten's work to eventually pin the backing storage more dynamically by preventing locking inversions around dev->struct_mutex. v2: Add analysis for recently added cma helper prime code. Cc: Laurent Pinchart Cc: Maarten Lankhorst Acked-by: Laurent Pinchart Acked-by: Maarten Lankhorst Signed-off-by: Daniel Vetter --- drivers/gpu/drm/drm_prime.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index a35f206..f115962 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -167,8 +167,6 @@ static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, if (WARN_ON(prime_attach->dir != DMA_NONE)) return ERR_PTR(-EBUSY); - mutex_lock(&obj->dev->struct_mutex); - sgt = obj->dev->driver->gem_prime_get_sg_table(obj); if (!IS_ERR(sgt)) { @@ -182,7 +180,6 @@ static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, } } - mutex_unlock(&obj->dev->struct_mutex); return sgt; }