Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1423545pxv; Fri, 23 Jul 2021 08:02:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK+ww9DtaA7Lk1WJDsOc1kuCB/svM3LokouMVJqu87cqP4YRpj9gfSEnFAuv6RYjr5dxqz X-Received: by 2002:a92:c503:: with SMTP id r3mr3861678ilg.148.1627052548449; Fri, 23 Jul 2021 08:02:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627052548; cv=none; d=google.com; s=arc-20160816; b=gqBi+p/uRpmktu4mTwpFBnJSwS0k2dCi7FYAJWpTBQ9aEDC5lhK63VaH4VTIp4JNUp Y6K4cQRqIeLqr1EyG0do7cda9FTX982a9iGcqi8JKrLsBgG5GY28fWyjaTJTdhpO+5LA 2jFyfCBqnotiKYyidBb7/SU7ULEIratQV6z5S+TPa39BVXxZXKl/xUd8lVXGE+jxMIgY V8CHqIL5A2fSdireTIojQ+dq01SO1JJZzaVVgBxM+1FmObBpG15iozeohdw36Jkr/elO c5eU/oDWWJmVgtYMpweciOx6tJqA2zc7jFLi/vpANvhninJP8cVA2I1TUKZq2cdLVH6H NagA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=w9v+4s7/P2Cg+QjJMoNBlGX2Ekj8q+TMc1efLZ/J8+4=; b=LxCmKlCCEcunrMP1SeA1/NZ2ZDaKbmWlj/BYaxUe7mLv/UZ2wk8rn3dsXUuTnI2csu 91mtfLUHycOfzuZj5Q3xipijbUWW17j6ginYJ3kRdIPtLKjivZqifzQooSB/f/0WpvGK kXq2Y80Rcb5KHqPX0GdFIeG0aq6e7y6ystCZn0Kz44waPVRD7+zKQFMDuqTO8MqOfRbV CWBmaPnz2pN34frVyJyJwsaA+R+EFTozPlhrk30hhYTWH9leeqMVLUgzXPHF4HYZAYGG Avqg652Sfud0a0ztMAGJVU088WgTJy5T5MOtDj3/rLO/3k3TrkQ5LFj1rx//2uVi89C7 NhYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=fj7JYwQb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m19si17223438jat.15.2021.07.23.08.02.12; Fri, 23 Jul 2021 08:02:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=fj7JYwQb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235472AbhGWOUt (ORCPT + 99 others); Fri, 23 Jul 2021 10:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235437AbhGWOUs (ORCPT ); Fri, 23 Jul 2021 10:20:48 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB483C061575 for ; Fri, 23 Jul 2021 08:01:20 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 9-20020a05600c26c9b02901e44e9caa2aso1793592wmv.4 for ; Fri, 23 Jul 2021 08:01:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=w9v+4s7/P2Cg+QjJMoNBlGX2Ekj8q+TMc1efLZ/J8+4=; b=fj7JYwQb2WhybJAUx4rfOc25+s+QNn44GNfoxzaxvvv+Pb3suvS7pBkfDBusZwXXlf m2ohNk1UieUIgdG4WzCnhOgYhZQUxbWqMI912foPZDh3S/Xyz1xqNn42hbT6j9xpiyaK YtEu8H9SIRKgSAtAIMM9wzpHYJE1pq6x0zKXs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :content-transfer-encoding:in-reply-to; bh=w9v+4s7/P2Cg+QjJMoNBlGX2Ekj8q+TMc1efLZ/J8+4=; b=fakTSJkkTP2ZCK3ivt2yaD3YiAwndkIPf8iPl8iUZNoZvwS/b8YF4a1bjTnrPKXcXm LMgE2L8vef8VH7QF3QIsMVQedWIJYu8IOARa8dVSuA2SjUWVethAETAiM/On2oLeYj+K vrEsezrmFmvIJI4PZsY571T4j+wwgBP1wea+jRMcOKWfixl97IO2JZNvKLe7ttmDoM9X ScEkgIwjZhyIcvfrYs5CdO4ADqljrCwu+hAzQWYrJUWcu5xCMk9JWI9ENZP44txfzc4S UHFstKl+SgDUGZGzNgR1qu3lR3sx6HD4GtM9ksGngja6FW2V/X022q4HjjPQVTT4+fiv cy0g== X-Gm-Message-State: AOAM531Mpu+/INP6PU8kRYL80ivWuC50zPtiDi9PU0tgI9FN1tupTb71 jFnvidfCRrmvGP6+l4Keu+Rk8Q== X-Received: by 2002:a05:600c:21cd:: with SMTP id x13mr5151839wmj.12.1627052479277; Fri, 23 Jul 2021 08:01:19 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id b6sm5468873wmj.34.2021.07.23.08.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 08:01:18 -0700 (PDT) Date: Fri, 23 Jul 2021 17:01:16 +0200 From: Daniel Vetter To: Christian =?iso-8859-1?Q?K=F6nig?= Cc: Charan Teja Reddy , sumit.semwal@linaro.org, linaro-mm-sig@lists.linaro.org, vinmenon@codeaurora.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org Subject: Re: [PATCH] dma-buf: WARN on dmabuf release with pending attachments Message-ID: Mail-Followup-To: Christian =?iso-8859-1?Q?K=F6nig?= , Charan Teja Reddy , sumit.semwal@linaro.org, linaro-mm-sig@lists.linaro.org, vinmenon@codeaurora.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org References: <1627043468-16381-1-git-send-email-charante@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Operating-System: Linux phenom 5.10.0-7-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 23, 2021 at 02:34:13PM +0200, Christian K?nig wrote: > Am 23.07.21 um 14:31 schrieb Charan Teja Reddy: > > It is expected from the clients to follow the below steps on an imported > > dmabuf fd: > > a) dmabuf = dma_buf_get(fd) // Get the dmabuf from fd > > b) dma_buf_attach(dmabuf); // Clients attach to the dmabuf > > o Here the kernel does some slab allocations, say for > > dma_buf_attachment and may be some other slab allocation in the > > dmabuf->ops->attach(). > > c) Client may need to do dma_buf_map_attachment(). > > d) Accordingly dma_buf_unmap_attachment() should be called. > > e) dma_buf_detach () // Clients detach to the dmabuf. > > o Here the slab allocations made in b) are freed. > > f) dma_buf_put(dmabuf) // Can free the dmabuf if it is the last > > reference. > > > > Now say an erroneous client failed at step c) above thus it directly > > called dma_buf_put(), step f) above. Considering that it may be the last > > reference to the dmabuf, buffer will be freed with pending attachments > > left to the dmabuf which can show up as the 'memory leak'. This should > > at least be reported as the WARN(). > > > > Signed-off-by: Charan Teja Reddy > > Good idea. I would expect a crash immediately, but from such a backtrace it > is quite hard to tell what the problem is. > > Patch is Reviewed-by: Christian K?nig and I'm > going to push this to drm-misc-next on Monday if nobody objects. The boom only happens a lot later when the offending import uses the attachment again. This here has a good chance to catch that early drm_buf_put(), so I think it's a good improvement. We'll still Oops later on ofc, but meh. Acked-by: Daniel Vetter > > Thanks, > Christian. > > > --- > > drivers/dma-buf/dma-buf.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c > > index 511fe0d..733c8b1 100644 > > --- a/drivers/dma-buf/dma-buf.c > > +++ b/drivers/dma-buf/dma-buf.c > > @@ -79,6 +79,7 @@ static void dma_buf_release(struct dentry *dentry) > > if (dmabuf->resv == (struct dma_resv *)&dmabuf[1]) > > dma_resv_fini(dmabuf->resv); > > + WARN_ON(!list_empty(&dmabuf->attachments)); > > module_put(dmabuf->owner); > > kfree(dmabuf->name); > > kfree(dmabuf); > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch