Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp662822imm; Fri, 22 Jun 2018 03:11:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJikZdRm3fxwyIKgYG4f5EC4xcfixVp4xlkaX1qaI4LZgWkjNjjpbhfBKu0YBCvbgcdMxcU X-Received: by 2002:a17:902:2f84:: with SMTP id t4-v6mr1040304plb.24.1529662315111; Fri, 22 Jun 2018 03:11:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529662315; cv=none; d=google.com; s=arc-20160816; b=UINWY5z7RDioo3tbHZHooKNcn5AK5N5Jbg99MJkHqJ8iNZE0GJSkkphbb2GU8TctBw lmOD5DAtSykjCCeVWLH/xFVb/3OMsbAKy/aJa7HtaI6qoMOMq33PWZumnWarW6P5EqnV 4CjlfwIdmJvlnLOeAxNslNdGYze2joBLk9SUUlXSNz53nuQ5zF30Zi45K86ZDsccUvyO ZEg7ZCrzx/HH2pg35CceapP674cEEVYM2JaypAbfNIR4Ay5dHlnL5F1E5wXarB3PHYjs SvtpqoaUz1ci9tMItLNP60LYgcu/z55mosU0E5e+KaXqupNW9x81deOIARsUX4vHZ3E7 vQMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version:arc-authentication-results; bh=zd3WSbY1XFPKvKtKAWhJkQgv2/vt6EEs+CrJqnytXa0=; b=ARTXqbP4daeJ3U4MdOKjVaewurVgAVa+HJ2u19/crXyo2jJnTGsFYTALu65Kp+BdNl RAB7HoK/LChSNmDhmwqvSh59GoizxNsOoFn95lnsUDX+BAcRwkh2pNjFG5ZOWCwVVIgp JDJhoVWmE85gTOTsg6iJ+GYVY2uvkEb9GZ66u/dxe+h4dUs/LoOsEYPxXoJCwyf1hukr +fNIh5HBUgxVWBgbnBGJNVm/lqInNJqFkTtS7uP3Loq2QefP4aQ6lOHjuf/9pHkjIeUU 1inZDkPi8KMpS1LMiTMBJ1DTX+ZWe1XauA4GXy8vP9IxIjnBxoAeSPAijJ2PuNwDZWUR ZaNg== ARC-Authentication-Results: i=1; mx.google.com; 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 q14-v6si6999169pll.324.2018.06.22.03.11.40; Fri, 22 Jun 2018 03:11:55 -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; 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 S1754545AbeFVKJF convert rfc822-to-8bit (ORCPT + 99 others); Fri, 22 Jun 2018 06:09:05 -0400 Received: from mail.fireflyinternet.com ([109.228.58.192]:56108 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754366AbeFVKJD (ORCPT ); Fri, 22 Jun 2018 06:09:03 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 12125909-1500050 for multiple; Fri, 22 Jun 2018 11:08:49 +0100 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: Gustavo Padovan , "Akhil P Oommen" , sumit.semwal@linaro.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 From: Chris Wilson In-Reply-To: <1529661856.7034.404.camel@padovan.org> Cc: linux-arm-msm@vger.kernel.org, smasetty@codeaurora.org References: <1529660407-6266-1-git-send-email-akhilpo@codeaurora.org> <1529661856.7034.404.camel@padovan.org> Message-ID: <152966212844.11773.6596589902326100250@mail.alporthouse.com> User-Agent: alot/0.3.6 Subject: Re: [PATCH v2] dma-buf/fence: Take refcount on the module that owns the fence Date: Fri, 22 Jun 2018 11:08:48 +0100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Gustavo Padovan (2018-06-22 11:04:16) > Hi Akhil, > > On Fri, 2018-06-22 at 15:10 +0530, Akhil P Oommen wrote: > > 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); > > Do we still need to export the symbol, it won't be called from outside > anymore? Other than that looks good to me: There's a big drawback in that a module reference is often insufficient, and that a reference on the driver (or whatever is required for the lifetime of the fence) will already hold the module reference. Considering that we want a few 100k fences in flight per second, is there no other way to only export a fence with a module reference? -Chris