Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1191171pxv; Fri, 23 Jul 2021 02:05:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/aKx7dfHht0JENSfOGj39IRreowD7uZHyXTnhXSFiBCbEjX3OHOCltixjluoL515ZzXbI X-Received: by 2002:a05:6402:b88:: with SMTP id cf8mr4420242edb.6.1627031151719; Fri, 23 Jul 2021 02:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627031151; cv=none; d=google.com; s=arc-20160816; b=lhi+JvgI1NMDl8Pp8Ty4SqPd2GCdyF46sZMCuUJ23Xa4eQ/tC4Iw3zIPhnF8pRvea1 Fou48xw+29PvdaWAQmp+IvyJLp0QmShK/6y5TPobxiF34xYzeA2l7Ez62iQkraLw2U9u NgIRfMPeJnFIaWdeRl8KqBYV5osP7IiwXJSurRN3oz4imZlAlML+eggNThqdvugvsnK7 nWZd0+RpDtOpvcl3t/RH2KtGeN4O34J8ffG9yQ8LCom8W4s7y1EMXyg/JmQtlIuKPDQr DjugYAH/W5FP2lHtMDlH82K+eYr1NSdE59VZAIP8sCDq7MAZWtRAvp09EIpM8tqMFAwa /E4w== 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=H20rashoP0PI/4mcAWWqkgsc6ouNdbHg+NJZNqP1JDM=; b=MUb/C6m8jsyumuUz2VxnEgLnkUiX1AMGoo68bHh3FdMT6UbT2I72RFir9HI1G+nYTa NbdbBGO56wZQOry1GJL6AVGTqcSQLdrySJiFmJUMhq8j5B7TWzoZBfl8LVSETS4lJRqW UnJBz/JPORJOkVtwqZmvcVJfX4W53WkEVo0FrTM/XUq3VEoCgr02P91HliI0KMovtRpl dYf3mUTUM0eTXsHPFbM0zvXi3lf3f0reH0mMXO/kEhMrkyfkASyhue7r7NuHHsdO96Dg yz2jWRbCjEx8eAb1GCohZG1n8s3UI1Dv40/pPTiJbVsrBeulItgeSxZKc04jd3w2OMJU Cevw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b="lVm33/5j"; 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 eo9si30134144ejc.108.2021.07.23.02.05.27; Fri, 23 Jul 2021 02:05:51 -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="lVm33/5j"; 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 S233096AbhGWIVb (ORCPT + 99 others); Fri, 23 Jul 2021 04:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229771AbhGWIVa (ORCPT ); Fri, 23 Jul 2021 04:21:30 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E4E8C061575 for ; Fri, 23 Jul 2021 02:02:04 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id b7so870620edu.3 for ; Fri, 23 Jul 2021 02:02:04 -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=H20rashoP0PI/4mcAWWqkgsc6ouNdbHg+NJZNqP1JDM=; b=lVm33/5j21ACNJPF/VGWVWV868PDs09n4VxTQvOBtV2a914nW69TcdhZ5QAkSUAYpU bgqR6uSdVVWgsSW/mR+NM835LaGlbzXkhz6KuLuevVTdwKB1Zy7LJlCfaNIrjIhywHZF IGZ2DRjnhEcZKePaCZRBaDMn2c0KwZuSEDY98= 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=H20rashoP0PI/4mcAWWqkgsc6ouNdbHg+NJZNqP1JDM=; b=qghWOrbuBqgNqJvSNnlEui2Q9jFX45HSMaG+aADl8BXgzaG3OwN/J/K4rkfO3aiObi Cjlb7QwEQDNJlcABexxYETO4hJTQUrQJa2bdoufdVQcob09bV7atodcocaLqsnEQsNNb 9VM0ROTQC43M3VZpxiV8Mv0oRb6Zowlpunk+OifF/KDE0u2zyTe3MBrrUwINh9mJK+Jh LNZw6Y8ftnZP1yJY6pPLmuplyLHXFaHIAzRfILmMEkkukrN/vJtHSd3K1a+35lRG27vB /uZznqWTs30tU0ckvPlJ7frAGDxXIgJq5GeODDo1B7Kfujl6dAUD711hW8AZX993rPhF gHUA== X-Gm-Message-State: AOAM530WXZAB88sDs2638iQXi1MUrzo04HADYgPHGY73/2XfAEAQa79z iYFxNtpVDonCoQ4TGMj62tcynA== X-Received: by 2002:aa7:c907:: with SMTP id b7mr4334018edt.148.1627030922700; Fri, 23 Jul 2021 02:02:02 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id b25sm13846456edv.9.2021.07.23.02.02.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jul 2021 02:02:02 -0700 (PDT) Date: Fri, 23 Jul 2021 11:02:00 +0200 From: Daniel Vetter To: Michel =?iso-8859-1?Q?D=E4nzer?= Cc: Christian =?iso-8859-1?Q?K=F6nig?= , linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org Subject: Re: [PATCH] dma-buf/poll: Get a file reference for outstanding fence callbacks Message-ID: Mail-Followup-To: Michel =?iso-8859-1?Q?D=E4nzer?= , Christian =?iso-8859-1?Q?K=F6nig?= , linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org References: <20210723075857.4065-1-michel@daenzer.net> <4cf94f59-f953-f5d7-9901-cfe5fd63bfbc@daenzer.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4cf94f59-f953-f5d7-9901-cfe5fd63bfbc@daenzer.net> 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 10:19:49AM +0200, Michel D?nzer wrote: > On 2021-07-23 10:04 a.m., Christian K?nig wrote: > > Am 23.07.21 um 09:58 schrieb Michel D?nzer: > >> From: Michel D?nzer > >> > >> This makes sure we don't hit the > >> > >> ????BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active); > >> > >> in dma_buf_release, which could be triggered by user space closing the > >> dma-buf file description while there are outstanding fence callbacks > >> from dma_buf_poll. > > > > I was also wondering the same thing while working on this, but then thought that the poll interface would take care of this. > > I was able to hit the BUG_ON with https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1880 . igt test would be really lovely. Maybe base something off the import/export igts from Jason? -Daniel > > > >> Cc: stable@vger.kernel.org > >> Signed-off-by: Michel D?nzer > >> --- > >> ? drivers/dma-buf/dma-buf.c | 18 ++++++++++++------ > >> ? 1 file changed, 12 insertions(+), 6 deletions(-) > >> > >> diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c > >> index 6c520c9bd93c..ec25498a971f 100644 > >> --- a/drivers/dma-buf/dma-buf.c > >> +++ b/drivers/dma-buf/dma-buf.c > >> @@ -65,12 +65,9 @@ static void dma_buf_release(struct dentry *dentry) > >> ????? BUG_ON(dmabuf->vmapping_counter); > >> ? ????? /* > >> -???? * Any fences that a dma-buf poll can wait on should be signaled > >> -???? * before releasing dma-buf. This is the responsibility of each > >> -???? * driver that uses the reservation objects. > >> -???? * > >> -???? * If you hit this BUG() it means someone dropped their ref to the > >> -???? * dma-buf while still having pending operation to the buffer. > >> +???? * If you hit this BUG() it could mean: > >> +???? * * There's a file reference imbalance in dma_buf_poll / dma_buf_poll_cb or somewhere else > >> +???? * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback > >> ?????? */ > >> ????? BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active); > >> ? @@ -196,6 +193,7 @@ static loff_t dma_buf_llseek(struct file *file, loff_t offset, int whence) > >> ? static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb) > >> ? { > >> ????? struct dma_buf_poll_cb_t *dcb = (struct dma_buf_poll_cb_t *)cb; > >> +??? struct dma_buf *dmabuf = container_of(dcb->poll, struct dma_buf, poll); > >> ????? unsigned long flags; > >> ? ????? spin_lock_irqsave(&dcb->poll->lock, flags); > >> @@ -203,6 +201,8 @@ static void dma_buf_poll_cb(struct dma_fence *fence, struct dma_fence_cb *cb) > >> ????? dcb->active = 0; > >> ????? spin_unlock_irqrestore(&dcb->poll->lock, flags); > >> ????? dma_fence_put(fence); > >> +??? /* Paired with get_file in dma_buf_poll */ > >> +??? fput(dmabuf->file); > > > > Is calling fput() in interrupt context ok? IIRC that could potentially sleep. > > Looks fine AFAICT: It has > > if (likely(!in_interrupt() && !(task->flags & PF_KTHREAD))) { > > and as a fallback for that, it adds the file to a lock-less delayed_fput_list which is processed by a workqueue. > > > -- > Earthling Michel D?nzer | https://redhat.com > Libre software enthusiast | Mesa and X developer -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch