Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp637593imm; Fri, 22 Jun 2018 02:42:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKkGUD2RGBZpl/hD72evNsMayoN6LQxstR/7tY/I47NtKHNx3anM9Odmi2N3vc5r9ZMbpTs X-Received: by 2002:a63:7c55:: with SMTP id l21-v6mr780758pgn.352.1529660559128; Fri, 22 Jun 2018 02:42:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529660559; cv=none; d=google.com; s=arc-20160816; b=zllvGcgdVVs04qjHYWtQVGG0f4rmo9c0sS5Dl1LvF4VxUZVFTIY5CHfLyQaTlbF2tB zD4J2MV5JAgDsUeinYqiJhhdfxE5D3FLnCW1yhIzatnhKKGUNmBcfIQ02DQbZOots9vz 14RZQRbvqErrub2InMBedxfE2/NXwrvyBNhjr5ZjW+RJ8RKJC8gf8oKWWnOvkHJ7FpoZ ECPeArjO2itH45OMUQc4KpJ80gssNHkbcJxxZoAupolrLoNvMTA4U1M+w2wvK5vs7x1I tAfWpBXnPCE2PvuaBWXZaj4U8P9r1ZI5Oxld2I/vw6+AItz2ofri/tP0VUZDET9JUJyj 9hJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=XnZBHnkTpqZnzzN3xWTtB/yQdzuOwkJwqMr6p0M0SyY=; b=IpwghbxhS76zkjNExjDr3HjGpS4ZGoBcMKUkpHXKTWbj6ypDPHy5iz6laFh42onsO3 UykqezsDblcxQKLvpMInYn98rPQyv9T1EOaLN7qFmGLYZ5ju9xqIY09dmrCn0bi9dYKY X6XnBCQQIUlAGnzEInFX7acr22qrbOCmQ59sUrrNYYbm4r5hFAzKFG9thqTvatehs8BU s49Y0aEM3sD78A0ChtWR2t4RHthtsRhdpeawYkkTwbyL1/chZD6unKtJWVIuPf0WHBlr rvFqgWgmLVELqGml4lPZ9rCBvk+tsVbxiJCvS1lB5qp2Hh9sABYKFKYF/2L/lG8fG5i/ xqyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=OkxtkbZj; dkim=pass header.i=@codeaurora.org header.s=default header.b=AeyrUvcS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k13-v6si6013956pgt.659.2018.06.22.02.42.25; Fri, 22 Jun 2018 02:42:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=OkxtkbZj; dkim=pass header.i=@codeaurora.org header.s=default header.b=AeyrUvcS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751806AbeFVJkV (ORCPT + 99 others); Fri, 22 Jun 2018 05:40:21 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:50618 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751210AbeFVJkU (ORCPT ); Fri, 22 Jun 2018 05:40:20 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A682F60B10; Fri, 22 Jun 2018 09:40:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529660419; bh=rsjQvQr+qhugQkjMhyWqJybbHrqrj0sd4izeL1zFQZ4=; h=From:To:Cc:Subject:Date:From; b=OkxtkbZjX4+ZpR00Nq73n41RBHn9eH6sm+nDkAyxvNo5ciyFOdKZ4990GDKyGIUHa dnDTC647iyiR4DMexB+BxG7YRtVzyva5Xx6fWrs0mVfLQJz5tQR86Nez//brIfZUAd YXT1WQuhRCBVGHwYYVe848aN/e+4hek/8pYPgINQ= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 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 13B4760376; Fri, 22 Jun 2018 09:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1529660418; bh=rsjQvQr+qhugQkjMhyWqJybbHrqrj0sd4izeL1zFQZ4=; h=From:To:Cc:Subject:Date:From; b=AeyrUvcS/KikAOfPzcEc6tG0TMeM8cYwUEDe9g3gZvP47MYnPnSinqB2WUKnxzi9s nGcwMg7P1HmUdX8b2+Vv2h9kEXwG7sFHX7bgwa8qb4IlLj3IxTL7XGeWpLgbycUNRT u6k/Mrvm1Xal9zEYiLDcD3JWxDfqe5b+ajgHak/I= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 13B4760376 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, jcrouse@codeaurora.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: smasetty@codeaurora.org, akhilpo@codeaurora.org, linux-arm-msm@vger.kernel.org Subject: [PATCH v2] dma-buf/fence: Take refcount on the module that owns the fence Date: Fri, 22 Jun 2018 15:10:07 +0530 Message-Id: <1529660407-6266-1-git-send-email-akhilpo@codeaurora.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changes in v2: - added description for the new function parameter. drivers/dma-buf/dma-fence.c | 16 +++++++++++++--- include/linux/dma-fence.h | 10 ++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index 4edb9fd..2aaa44e 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); @@ -541,6 +545,7 @@ struct default_wait_cb { /** * dma_fence_init - Initialize a custom fence. + * @module: [in] the module that calls this API * @fence: [in] the fence to initialize * @ops: [in] the dma_fence_ops for operations on this fence * @lock: [in] the irqsafe spinlock to use for locking this fence @@ -556,8 +561,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 +577,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); -- 1.9.1