From patchwork Tue Jun 19 06:10:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akhil P Oommen X-Patchwork-Id: 10473305 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 3A6C1603B5 for ; Tue, 19 Jun 2018 06:10:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A6DE28C14 for ; Tue, 19 Jun 2018 06:10:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EC4B28C34; Tue, 19 Jun 2018 06:10:30 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B457F28C14 for ; Tue, 19 Jun 2018 06:10:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755939AbeFSGKR (ORCPT ); Tue, 19 Jun 2018 02:10:17 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:48262 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755611AbeFSGKP (ORCPT ); Tue, 19 Jun 2018 02:10:15 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 61B7E60376; Tue, 19 Jun 2018 06:10:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529388615; bh=WWQKkjoNwSk17qZqZ78FLMKwyBSASPpHJMus57KH0dw=; h=From:To:Cc:Subject:Date:From; b=YXugDi2Es34bhyKvZNUNknRU6yeCrwbGspRZuIF2UApkfoJtZEehU8GgmBPKXFzS+ MKs0Vjxrg2D1gYxdgmTbCt3BDHazi1XChJpmoc5Ur1Wvy1V1o5VMbfOCcEzLRu+RPl poEx6871YSvLtyU1UzLLOdC85LqXb5DSTW/vU1O0= Received: from akhilpo-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: akhilpo@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 44E88604D4; Tue, 19 Jun 2018 06:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529388614; bh=WWQKkjoNwSk17qZqZ78FLMKwyBSASPpHJMus57KH0dw=; h=From:To:Cc:Subject:Date:From; b=Zjc6ccHnt8DDEQ6zb0SiB41ZVFNKwEsnT19nYYTxNZAzgy0dnpt9pyuo1OdV6mkp8 91qJuSi5C5/ZcY/ofN0AREG//8IGBe5OYnrOLab/NxsAlxyxny2PtiFvwRHbv7bpgp 9ci+gKha91qGVsCo/KlB+oZ4A+vyAt2A8HRInXro= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 44E88604D4 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=akhilpo@codeaurora.org From: Akhil P Oommen To: sumit.semwal@linaro.org, gustavo@padovan.org Cc: linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, jcrouse@codeaurora.org, smasetty@codeaurora.org, linux-arm-msm@vger.kernel.org Subject: [PATCH] dma-buf/fence: Take refcount on the module that owns the fence Date: Tue, 19 Jun 2018 11:40:05 +0530 Message-Id: <1529388605-10044-1-git-send-email-akhilpo@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Each fence object holds function pointers of the module that initialized it. Allowing the module to unload before this fence's release is catastrophic. So, keep a refcount on the module until the fence is released. Signed-off-by: Akhil P Oommen --- drivers/dma-buf/dma-fence.c | 15 ++++++++++++--- include/linux/dma-fence.h | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 4edb9fd..0be8053 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c @@ -18,6 +18,7 @@ * more details. */ +#include #include #include #include @@ -168,6 +169,7 @@ void dma_fence_release(struct kref *kref) { struct dma_fence *fence = container_of(kref, struct dma_fence, refcount); + struct module *module = fence->owner; trace_dma_fence_destroy(fence); @@ -178,6 +180,8 @@ void dma_fence_release(struct kref *kref) fence->ops->release(fence); else dma_fence_free(fence); + + module_put(module); } EXPORT_SYMBOL(dma_fence_release); @@ -556,8 +560,9 @@ struct default_wait_cb { * to check which fence is later by simply using dma_fence_later. */ void -dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, - spinlock_t *lock, u64 context, unsigned seqno) +_dma_fence_init(struct module *module, struct dma_fence *fence, + const struct dma_fence_ops *ops, spinlock_t *lock, + u64 context, unsigned seqno) { BUG_ON(!lock); BUG_ON(!ops || !ops->wait || !ops->enable_signaling || @@ -571,7 +576,11 @@ struct default_wait_cb { fence->seqno = seqno; fence->flags = 0UL; fence->error = 0; + fence->owner = module; + + if (!try_module_get(module)) + fence->owner = NULL; trace_dma_fence_init(fence); } -EXPORT_SYMBOL(dma_fence_init); +EXPORT_SYMBOL(_dma_fence_init); diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index eb9b05a..8159125 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h @@ -36,6 +36,8 @@ /** * struct dma_fence - software synchronization primitive + * @owner: the module that contains fence_ops functions. + * Usually THIS_MODULE. * @refcount: refcount for this fence * @ops: dma_fence_ops associated with this fence * @rcu: used for releasing fence with kfree_rcu @@ -71,6 +73,7 @@ * been completed, or never called at all. */ struct dma_fence { + struct module *owner; struct kref refcount; const struct dma_fence_ops *ops; struct rcu_head rcu; @@ -249,8 +252,11 @@ struct dma_fence_ops { char *str, int size); }; -void dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops, - spinlock_t *lock, u64 context, unsigned seqno); +#define dma_fence_init(fence, ops, lock, context, seqno) _dma_fence_init( \ + THIS_MODULE, fence, ops, lock, context, seqno) +void _dma_fence_init(struct module *module, struct dma_fence *fence, + const struct dma_fence_ops *ops, spinlock_t *lock, u64 context, + unsigned seqno); void dma_fence_release(struct kref *kref); void dma_fence_free(struct dma_fence *fence);