Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3127665imm; Thu, 24 May 2018 23:42:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZopnbWwqdKSpWebUEjwTMaWLVM4NkzpJQii+o/1h3dFEvbuJk7T1Zi0m65EFK4Y2Ba9SZps X-Received: by 2002:a65:665a:: with SMTP id z26-v6mr961995pgv.302.1527230574119; Thu, 24 May 2018 23:42:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527230574; cv=none; d=google.com; s=arc-20160816; b=k1EknHFNmEh0FtSYFIqFFTr7lJRDHPJJgN/Gb9BiPMNj4gSm2JIk1GBI5gzBozd4SB atNclwfJxMrqku1tUwZWC9SXYlJGZQVWEOHXZbrxSKubUAs7OJbcCp/5gSg0wc4WaovI ivQuHwvrbJAWckD+2KKClJeLmpJ02MYhm9uZ5a/lyDtrpow549i8yAIcpKa8skuoGhzv 8QcDaiAElw2HLynd4gOC288H1Nc3soBYi1WPifFZAp40xTs3c7DAHWfvdcyfC29i1AGe 4jW0ck5XMhGwDNBympjk0z96BS4tHn/WnM9ONPlo0Aq9p8N11wAZXG5WE2Tqbma3FpUr T+rg== 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=1tpiz0Mve7LBwIrk6C4CDT8+cQrxvmmsnOoAMx2Hiog=; b=PX/tzfBV8X/fxkR0m62Qb31xh8aJWkY5venxzKnf4Y29erZ1B0XZL0vpaeRDESgjPO KiykDpbbG4fi9roDABtySqkPqEM0TIQZjAblxE4hXqsQQz02OJTqVKxTvxEjfDgqcVoJ E0eMZdftNwq8z8Ic9BoRqeYnHv6FG0DP8zNQPME6/al1cjCXMqjJ2TqNG9oHlYuozrfR yCZmochqB8jshH4PrPTH1lJqCTmHVlxY/PUzT56dla+i3exAhbgIph15igYn3Z4R8DmL 6jyxcAHGlgjIXXVeVBYfdC54sKPnKcovYXmCf+Yj/jWQTMNWyvjLqRa+1bGETpeDfU0i AdEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=gBhSuBRX; 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 z23-v6si23620972plo.492.2018.05.24.23.42.39; Thu, 24 May 2018 23:42:54 -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=gBhSuBRX; 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 S935695AbeEYGl4 (ORCPT + 99 others); Fri, 25 May 2018 02:41:56 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:54857 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935385AbeEYGly (ORCPT ); Fri, 25 May 2018 02:41:54 -0400 Received: by mail-wm0-f68.google.com with SMTP id f6-v6so11346305wmc.4; Thu, 24 May 2018 23:41:53 -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=1tpiz0Mve7LBwIrk6C4CDT8+cQrxvmmsnOoAMx2Hiog=; b=gBhSuBRX8WM+17F72CpDmIt+oklx9KB8iPPeae0zMFC/sNHT1E1ZvQz6Zrli+j0Kbv nunBAEW78nUSAy/lr9cRMgu9fslMviVlOF47emmBRWSYt3vOfMMPA+wZuIgpyvJHQu0u lY0J1lmgbfbYiOoVb6+2avRZH6NqcKlu2KWgz7XuSUIh7vBBIgnio1N8Qy7bkl62NBt3 kILbHTUClcWedJ8GUi7hNJFR4p+z7O2q2kgjrcSlG7xxZYIeb0yh3ZVvhjKWwc5J1gwA +E50ePXSig1CxrNjbxZYh2cmw0UzD1a8wy+0wKKaIilAENJtj0yYGij3fzMShxIVXCJC m2VQ== 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=1tpiz0Mve7LBwIrk6C4CDT8+cQrxvmmsnOoAMx2Hiog=; b=eeQQX7WJl70FNwVZ6IV8uBicWFDXbAyolcnXO5N2m4i1QNLSUk5E63BLQAX8VjVFxa 3NXO7Rk4pqspz6vQsOssdC+DpW6pp3b29gvBW7tCNneQGPPj6T4iQ9sw3PnFaCGgkFCc EbVPuKEM7U24pTfxrHJVypXuIC3nPh1c+fWVRrWgWxQal/bsnA4qXeDV91rKb8GaUO5K psZrFhbff6KQEl1yq75CZBbIfLdstVAVMzcoxgwaYL1gWfq2dN+5U1CxOKyro9NNuVe+ exZ32i0jRdNQu78vNFkUjTPB23XrlqD0rZCOLqgWyvccriQefpUFMZOGvI8yb0bvbuFF S+kg== X-Gm-Message-State: ALKqPweY4YqBQPK8Z8wkWPUARQVYHWdXfniAT0HaAbh1VgeyrPK7rHid 6t/Vsa/nG1opCe4+Vn3GtJiFW2lVed+DVIcTULM= X-Received: by 2002:a2e:2286:: with SMTP id i128-v6mr679638lji.47.1527230512564; Thu, 24 May 2018 23:41:52 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a2e:8703:0:0:0:0:0 with HTTP; Thu, 24 May 2018 23:41:52 -0700 (PDT) In-Reply-To: <20180521165946.11778-2-ezequiel@collabora.com> References: <20180521165946.11778-1-ezequiel@collabora.com> <20180521165946.11778-2-ezequiel@collabora.com> From: sathyam panda Date: Fri, 25 May 2018 12:11:52 +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 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. > Signed-off-by: Ezequiel Garcia > --- > drivers/media/common/videobuf2/videobuf2-core.c | 27 > ++++++++++++++++++++++--- > include/media/videobuf2-core.h | 7 +++++-- > 2 files changed, 29 insertions(+), 5 deletions(-) > > diff --git a/drivers/media/common/videobuf2/videobuf2-core.c > b/drivers/media/common/videobuf2/videobuf2-core.c > index d3f7bb33a54d..f1feb45c1e37 100644 > --- a/drivers/media/common/videobuf2/videobuf2-core.c > +++ b/drivers/media/common/videobuf2/videobuf2-core.c > @@ -190,6 +190,26 @@ module_param(debug, int, 0644); > static void __vb2_queue_cancel(struct vb2_queue *q); > static void __enqueue_in_driver(struct vb2_buffer *vb); > > +static void __vb2_buffer_free(struct kref *kref) > +{ > + struct vb2_buffer *vb = > + container_of(kref, struct vb2_buffer, refcount); > + kfree(vb); > +} > + > +static void __vb2_buffer_put(struct vb2_buffer *vb) > +{ > + if (vb) > + kref_put(&vb->refcount, __vb2_buffer_free); > +} > + > +static struct vb2_buffer *__vb2_buffer_get(struct vb2_buffer *vb) > +{ > + if (vb) > + kref_get(&vb->refcount); > + return vb; > +} > + > /* > * __vb2_buf_mem_alloc() - allocate video memory for the given buffer > */ > @@ -346,6 +366,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum > vb2_memory memory, > break; > } > > + kref_init(&vb->refcount); > vb->state = VB2_BUF_STATE_DEQUEUED; > vb->vb2_queue = q; > vb->num_planes = num_planes; > @@ -365,7 +386,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum > vb2_memory memory, > dprintk(1, "failed allocating memory for buffer %d\n", > buffer); > q->bufs[vb->index] = NULL; > - kfree(vb); > + __vb2_buffer_put(vb); > break; > } > __setup_offsets(vb); > @@ -380,7 +401,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum > vb2_memory memory, > buffer, vb); > __vb2_buf_mem_free(vb); > q->bufs[vb->index] = NULL; > - kfree(vb); > + __vb2_buffer_put(vb); > break; > } > } > @@ -520,7 +541,7 @@ static int __vb2_queue_free(struct vb2_queue *q, > unsigned int buffers) > /* Free videobuf buffers */ > for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; > ++buffer) { > - kfree(q->bufs[buffer]); > + __vb2_buffer_put(q->bufs[buffer]); > q->bufs[buffer] = NULL; > } > > diff --git a/include/media/videobuf2-core.h > b/include/media/videobuf2-core.h > index f6818f732f34..baa4632c7e59 100644 > --- a/include/media/videobuf2-core.h > +++ b/include/media/videobuf2-core.h > @@ -12,11 +12,12 @@ > #ifndef _MEDIA_VIDEOBUF2_CORE_H > #define _MEDIA_VIDEOBUF2_CORE_H > > +#include > +#include > +#include > #include > #include > #include > -#include > -#include > > #define VB2_MAX_FRAME (32) > #define VB2_MAX_PLANES (8) > @@ -249,6 +250,7 @@ struct vb2_buffer { > > /* private: internal use only > * > + * refcount: refcount for this buffer > * state: current buffer state; do not change > * queued_entry: entry on the queued buffers list, which holds > * all buffers queued from userspace > @@ -256,6 +258,7 @@ struct vb2_buffer { > * to be dequeued to userspace > * vb2_plane: per-plane information; do not change > */ > + struct kref refcount; > enum vb2_buffer_state state; > > struct vb2_plane planes[VB2_MAX_PLANES]; > Regards, Sathyam