From patchwork Fri Sep 30 11:44:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9358047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 304E7600C8 for ; Fri, 30 Sep 2016 11:45:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 211EA29FC3 for ; Fri, 30 Sep 2016 11:45:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15EA229FCB; Fri, 30 Sep 2016 11:45:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49F9029FCA for ; Fri, 30 Sep 2016 11:45:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C1DBA6E9DB; Fri, 30 Sep 2016 11:44:59 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 724326E187; Fri, 30 Sep 2016 11:44:56 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id b4so3090698wmb.2; Fri, 30 Sep 2016 04:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=9X1Q6s7MfIPOHTgxMEwldwiuVw136KLRAXkzCm6NVp4=; b=NDLYxAsVu54chVz2FHWKc44brhgiiWVKawPg9+IE37iKTF+u7VPcdrOZ2/R6nzQ/li 7sTxTYAvPHbPmDEegkIfo0pE920kMh8CkrH7dSa7Dca5p2b4MShpUqRWa4n0WqE6cgcW d5O9BjypBSnBm+FbeeyNdN7dK5+98B8YKcDyqRhgRlPGL5zVlBR9nJtfx52X0Wa2LPxY mZ35nP0G3rqlL+F18bYQ5J8ZamYLnq/R06q1fIOz/gQQ0d4Iy0L713DcUTM1oYMXo0vz 2EVDnT3ZQbYQGZHr548CTUwXVEnGZOHfPFrXAW1iAteq/2+ZXYrc1oK+oY3ueSEIH5ex Jbhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=9X1Q6s7MfIPOHTgxMEwldwiuVw136KLRAXkzCm6NVp4=; b=LDjkFUj3zpeVPnlrYNCn3rRNTVCQ8QiIVWQTFOsnwFGBvWEwOiL9pkKl994BMkk8jn aMiVyJSGUcKaJWu3RIl/Bh2s9RX7pkWQcZGODYpxDlvHRvyeRXe1DWk44gvv8gkW6BNP aSLFYNg5JeNHWIWCF7noLSIRJvpyHtDW0+gy8r/yFrbCO90gbtrkIGOip9TnClu7s1Dn 9TgN/ttqR9eFTBSFJp4GAhypF0S9GnjlS121FJO2sreDXMukPTeQOYLNc0pIw9lJoTBF MyoT386ogLhYeXG7LoZimirsPDsmEPqHIAVFxy4r9YOAOihHE/lPqTVdJPpgPkLqhaYc W17Q== X-Gm-Message-State: AA6/9RkAdRXmquzUReddJbLBfTrHfQHW79gOvz0e+xWoCXL4OiBVOVCba9Ep3j9aERNJrQ== X-Received: by 10.28.23.210 with SMTP id 201mr3325733wmx.58.1475235894857; Fri, 30 Sep 2016 04:44:54 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id pm1sm19242767wjb.40.2016.09.30.04.44.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 04:44:53 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Date: Fri, 30 Sep 2016 12:44:48 +0100 Message-Id: <20160930114448.1941-2-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160930114448.1941-1-chris@chris-wilson.co.uk> References: <20160930114448.1941-1-chris@chris-wilson.co.uk> Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org, stable@vger.kernel.org Subject: [Intel-gfx] [PATCH v2 2/2] drm/prime: Take a ref on the drm_dev when exporting a dma_buf X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP dma_buf may live a long time, longer than the last direct user of the driver. We already hold a reference to the owner module (that prevents the object code from disappearing), but there is no reference to the drm_dev - so the pointers to the driver backend themselves may vanish. Suggested-by: Daniel Vetter Signed-off-by: Chris Wilson Cc: Petri Latvala Cc: Daniel Vetter Cc: stable@vger.kernel.org --- drivers/gpu/drm/armada/armada_gem.c | 9 +++++++-- drivers/gpu/drm/drm_prime.c | 10 +++++++++- drivers/gpu/drm/i915/i915_gem_dmabuf.c | 1 + drivers/gpu/drm/tegra/gem.c | 7 ++++++- drivers/gpu/drm/udl/udl_dmabuf.c | 7 ++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/armada/armada_gem.c b/drivers/gpu/drm/armada/armada_gem.c index cb8f0347b934..bdd3af043827 100644 --- a/drivers/gpu/drm/armada/armada_gem.c +++ b/drivers/gpu/drm/armada/armada_gem.c @@ -541,13 +541,18 @@ armada_gem_prime_export(struct drm_device *dev, struct drm_gem_object *obj, int flags) { DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct dma_buf *dma_buf; exp_info.ops = &armada_gem_prime_dmabuf_ops; exp_info.size = obj->size; - exp_info.flags = O_RDWR; + exp_info.flags = flags; exp_info.priv = obj; - return dma_buf_export(&exp_info); + dma_buf = dma_buf_export(&exp_info); + if (!IS_ERR(dma_buf)) + drm_dev_ref(dev); + + return dma_buf; } struct drm_gem_object * diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 443b6da011ff..add375f54b6d 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -293,9 +293,12 @@ static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, void drm_gem_dmabuf_release(struct dma_buf *dma_buf) { struct drm_gem_object *obj = dma_buf->priv; + struct drm_device *dev = obj->dev; /* drop the reference on the export fd holds */ drm_gem_object_unreference_unlocked(obj); + + drm_dev_unref(dev); } EXPORT_SYMBOL(drm_gem_dmabuf_release); @@ -413,11 +416,16 @@ struct dma_buf *drm_gem_prime_export(struct drm_device *dev, .flags = flags, .priv = obj, }; + struct dma_buf *dma_buf; if (dev->driver->gem_prime_res_obj) exp_info.resv = dev->driver->gem_prime_res_obj(obj); - return dma_buf_export(&exp_info); + dma_buf = dma_buf_export(&exp_info); + if (!IS_ERR(dma_buf)) + drm_dev_ref(dev); + + return dma_buf; } EXPORT_SYMBOL(drm_gem_prime_export); diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c index 10265bb35604..b58b2e63add1 100644 --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c @@ -288,6 +288,7 @@ struct dma_buf *i915_gem_prime_export(struct drm_device *dev, return dma_buf; export_fences(obj, dma_buf); + drm_dev_ref(obj->base.dev); return dma_buf; } diff --git a/drivers/gpu/drm/tegra/gem.c b/drivers/gpu/drm/tegra/gem.c index aa60d9909ea2..aaae8b6ba668 100644 --- a/drivers/gpu/drm/tegra/gem.c +++ b/drivers/gpu/drm/tegra/gem.c @@ -607,13 +607,18 @@ struct dma_buf *tegra_gem_prime_export(struct drm_device *drm, int flags) { DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct dma_buf *dma_buf; exp_info.ops = &tegra_gem_prime_dmabuf_ops; exp_info.size = gem->size; exp_info.flags = flags; exp_info.priv = gem; - return dma_buf_export(&exp_info); + dma_buf = dma_buf_export(&exp_info); + if (!IS_ERR(dma_buf)) + drm_dev_ref(drm); + + return dma_buf; } struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm, diff --git a/drivers/gpu/drm/udl/udl_dmabuf.c b/drivers/gpu/drm/udl/udl_dmabuf.c index e2243edd1ce3..249cc1072112 100644 --- a/drivers/gpu/drm/udl/udl_dmabuf.c +++ b/drivers/gpu/drm/udl/udl_dmabuf.c @@ -203,13 +203,18 @@ struct dma_buf *udl_gem_prime_export(struct drm_device *dev, struct drm_gem_object *obj, int flags) { DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct dma_buf *dma_buf; exp_info.ops = &udl_dmabuf_ops; exp_info.size = obj->size; exp_info.flags = flags; exp_info.priv = obj; - return dma_buf_export(&exp_info); + dma_buf = dma_buf_export(&exp_info); + if (!IS_ERR(dma_buf)) + drm_dev_ref(dev); + + return dma_buf; } static int udl_prime_create(struct drm_device *dev,