Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3496094imm; Tue, 29 May 2018 08:12:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr3cH8SQdWuIjOYYseFjDEyI161j87Ysgi/yuALXCPh0I4Ccx3t4zJpUQ5breTbRHr9sF7e X-Received: by 2002:a63:43c6:: with SMTP id q189-v6mr14579773pga.123.1527606751053; Tue, 29 May 2018 08:12:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527606751; cv=none; d=google.com; s=arc-20160816; b=R8ANCmVgMy1BvFCJ01tZDHN7kBHXAIRzwJ96V5/xK0hrZPmwC1qQix5NkWaR0MXr99 +r/5uD2c0aSZbyF+8ueGfqTFdHRIuy5TuHeSK1JARuQRI1Xs5BFOTRMw/Igc+BOcqQum OY+RZS4AZ2pFSh4Ait1eNGGpENWAeDy/JyxWAt4Py+GS9F8jg6UVPyvsxgNUWGV/Hk4I CYbflSwBKPmPE8I/M9sqbf4BUKw25I1nmp4HIU7/Igz+VdgortIMMZW6s43jHl2v/evJ sSPWDEbA0K1Ka9DkBxw9n8G5xUlJpkO+ZuBKyHp3oJ8rAK4rbGUNT0RcD3iE0l48szqv Vqtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=TQxQ1amA1k3Rjdgn4It2TBKBGuSIDL4uBcI9s6xmvpM=; b=YX3+J7OqC5JO9dDjSABjhbCni9qECdcqCAqEWv9oHia3c5RenTX+trFjwHdX79LSN6 xEhAgjt2Y773FBh1NZwf14ttjmEnZkIwWVvMEapYnlW7P7Dabu1fTCnVBlCTwuqCCrNU sfbiv/K3XgP/vchn9ctzqY/2v+8dvWOMMY2stbkfgM2f83TcZc8sBGKWmKXB5fenxk9e h63CRqWd8w0F9RrHxmIk+VQnaYYcc0hOanW2L+jLvfEAnzva2eNLu+zIir/dwT+QSHMj S6gkf2fyCxsj4JNJl/lW7nDRF67VzvD0UhaPtRQkrC6JmIEu7Iai3fGI3swpnmFgPcz/ 7DuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AEQONRwt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b63-v6si32895748plb.566.2018.05.29.08.12.16; Tue, 29 May 2018 08:12:31 -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=@gmail.com header.s=20161025 header.b=AEQONRwt; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936593AbeE2PLz (ORCPT + 99 others); Tue, 29 May 2018 11:11:55 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:43608 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935828AbeE2PLu (ORCPT ); Tue, 29 May 2018 11:11:50 -0400 Received: by mail-wr0-f193.google.com with SMTP id d2-v6so10687584wrm.10; Tue, 29 May 2018 08:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=TQxQ1amA1k3Rjdgn4It2TBKBGuSIDL4uBcI9s6xmvpM=; b=AEQONRwt0u/4cC8XjRv393VhdnxEpFrRaIfltQ8C9OPvtZ9pMTKa+CbLlks5XeAzVr X89JY3e4upE/6VjDHCklDmoQqD1r3I6foz+hGawRcUzxQYlbfmnVAMIS2EXht0Cc6B3h 6U1ZZuEqZ4cIg9d0hsQEjQRQWz1i4eFQWEVfc6FQdGkxByAyDLGgRB/iwrUtnOZXWNzz mW5VdulUaKwWN4JJX6bHvod4SwFpZxHUOqM5jcWH0NcReG68MFEc8O/t/JgtYXpWWYJ/ 0XqapAw8QK6G6kLck/C2cFSR53MDCpDSaTxDP+qwV8LXOyGpw2Uf7IIpERr9ufP5hA/u qp4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=TQxQ1amA1k3Rjdgn4It2TBKBGuSIDL4uBcI9s6xmvpM=; b=dxumm1VtbSa52p34jG4UYY1t8d8YqRlFbsXEVpoL0Jp08U5NBmjLef+TZ4Nivx0aE7 wwd196onDibibs/bBi6Eupmbo/lBz/Rjut4Yz4AdC00MSyMHaixix4mLUnGTbWzhF+A0 FEEpuSw5TCRyKl38N2kKe272trCd8kyFWj7Z1K9eskCSJCnUCiawh3kXmMXKvGyw0WZ/ Z5nrGEJOrmQakervTgp/mTwpjGrqvl7EDgTq/wxmvv5BJsvZMI1BfTgp0uwoNHxwAie6 Sc+uFOl9U9zruB1eb3GCzGWRvaFyEvro3Zb8+NdCor4/4BJ+e5dHh/SqTpeFQsxIJcg1 Y4oA== X-Gm-Message-State: ALKqPwdKKB4vG04pmdXbarnqD6mY+ayIJsxYIjpdndFk0YLKjKrsZZyM jH5QV0jdBZFuGi6TB0/Y8L4qYySp/q7ivb8YUzw= X-Received: by 2002:a19:4dc5:: with SMTP id a188-v6mr9362520lfb.99.1527606708779; Tue, 29 May 2018 08:11:48 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:8703:0:0:0:0:0 with HTTP; Tue, 29 May 2018 08:11:48 -0700 (PDT) In-Reply-To: References: <20180521165946.11778-1-ezequiel@collabora.com> <20180521165946.11778-2-ezequiel@collabora.com> From: sathyam panda Date: Tue, 29 May 2018 20:41:48 +0530 Message-ID: Subject: Re: [PATCH v10 01/16] videobuf2: Make struct vb2_buffer refcounted To: Ezequiel Garcia Cc: linux-media@vger.kernel.org, kernel@collabora.com, Hans Verkuil , Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Ezequiel, On 5/29/18, Ezequiel Garcia wrote: > On Fri, 2018-05-25 at 12:11 +0530, sathyam panda wrote: >> Hello, >> >> On 5/21/18, Ezequiel Garcia wrote: >> > The in-fence implementation involves having a per-buffer fence >> > callback, >> > that triggers on the fence signal. The fence callback is called >> > asynchronously >> > and needs a valid reference to the associated ideobuf2 buffer. >> > >> > Allow this by making the vb2_buffer refcounted, so it can be passed >> > to other contexts. >> > >> >> -Is it really required, because when a queued buffer with an in_fence >> is deallocated, firstly queue is cancelled. >> -And __vb2_dqbuf is called which calls dma_fence_remove_callback. >> -So if fence callback has been called -__vb2_dqbuf will wait to >> acquire fence lock. >> -So during execution of fence callback, buffers and queue are still >> valid. >> -And if __vb2_dqbuf remove callback first ,then dma_fence_signal will >> wait for lock >> - so there won't be any fence callback to call for that buffer when >> dma_fence_signal resumes. >> > > Hi Sathyam, > > Thanks for your review! The refcount is definitely required, > as the fence callback only schedules a workqueue, which is > completely asynchronous with respect to the rest of the > ioctls. > > In particular, the workqueue is not synchronized with > vb2_core_queue_release. > > Also, another subtle detail, dma_fence_remove_callback > can fail to remove the callback. > > Thanks, > Eze > - Sorry, I didn't pay attention to the use of workqueue, thanks for bringing that into my notice. Now it make sense. - I have a doubt about the queue since many driver specific structures have queues which they release with kfree() after calling vb2_queue_release(). - And since vb2_core_queue_release decrements the buffer refcount only once if fence is already signalled, so buffer is still valid, but queue isn't as the memory is deallocated. - So is it safe to access queue in the __qbuf_work. Please correct me if I am wrong. Regards, Sathyam