Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1254095ybg; Tue, 2 Jun 2020 05:27:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr2Z+5ok+91hXQxQZEFyQgOnTYliHkgXmujB3rdFNkyq9FPIr7ahK+6vq/JC7DdUzmCLZR X-Received: by 2002:a17:906:6a92:: with SMTP id p18mr23018719ejr.233.1591100832106; Tue, 02 Jun 2020 05:27:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591100832; cv=none; d=google.com; s=arc-20160816; b=ULKVreKz5vXSNiSHl3nBAeYkVyUu2jahLqRrcYk2dJby8tE9HpTyL97yl2IOM8B+Sh ffa4WT/FYLar7RzSxoFduFMaQbmUEYxPc8HmaTnk34tKMX7qlCPhucnVdccC9vL3aDiV Lv26+AmO3BubIk4Mo2So8v+H1Qwd+4t2DPA6tycTcS4VXlyBzL+q1dCWaeWFoLL9uAtg C0W1rFRn/ikF39f5DtvdKZH7A99PEBlhMuU0l7DOOWv43WS2v2uq0XT4rUHiBQFzZfx9 vZ9oU8nU/tBVGUTYaQkL19islhaYVaoh7GrBjLaqTSpC4qrKjUVc75gwd4P6S1byFDAc 2Clg== 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 :in-reply-to:references:mime-version:dkim-signature; bh=A08j6fU+RlNfIhwI5UM24mjQznnwSgfTXAFxVissV48=; b=uIlx//VsP0EdogO6HDfLpryKOGm31x+mri09IT0pN7yS6gVc5yhHxed0CsGAleDP0W OBnZ2/ZxNecnxQxkIblTLKth8qDYc8RrgsomzzUW/QQAAcO0hrsKPbvQ0LGJ8Fhwmy9V eGe7hILrM9bD9FGdj/i/hx9OmJ5X+5La8uCeq6gbQtY2gStZU49AxX0z5whjpqJeEJCs 7PZBy7dDoXq2Ov2JeZcy2eXUZPN9sxrYvqpiN6O7bZvUtNEnV+4NlHw/35m46/D/Xkm5 XADgQ6SXA3kIyPTYF9LDX63gwiND2GWwZYY/SVvMDoXEnSpxo2dM1USdWRL6/sQSofK3 4xnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=JqAagGFB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f17si1459175edr.515.2020.06.02.05.26.49; Tue, 02 Jun 2020 05:27:12 -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=@chromium.org header.s=google header.b=JqAagGFB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727839AbgFBMWq (ORCPT + 99 others); Tue, 2 Jun 2020 08:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726217AbgFBMWp (ORCPT ); Tue, 2 Jun 2020 08:22:45 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29A4DC061A0E for ; Tue, 2 Jun 2020 05:22:45 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id o15so12504065ejm.12 for ; Tue, 02 Jun 2020 05:22:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=A08j6fU+RlNfIhwI5UM24mjQznnwSgfTXAFxVissV48=; b=JqAagGFBVhcjxJPeBl5cy+G9GwDLNghzA6eP0eUwsaQW5oBc2sm29vAYyo/systJBA lPocLTxup1vVlzpiDJdk2rLd5+9I4cXxz2Q1OnpETIGsAp69v8XqSvIi7Dxaa6qVLyra 1vWzF8dNJE2Qjv6i0Oa3d9mU2+GuB42bt1suc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=A08j6fU+RlNfIhwI5UM24mjQznnwSgfTXAFxVissV48=; b=HEkadrqr4XOGvCbA14GdAKXn5bUbU+Iu7Iq8nKhl6bHL/fvRK42brhoZnvFsX31O/R NMSEFKeglvfQ7bIhq+6tv91nYD+afX+wbTTxy/m47Swmwpc7Z2bCjlKF27CJhRosU51f Hg2ppjmi++hxzKIkEHeGu4Jg001iUBITV7m5CFBfac/ZR1kYg4MqGo8k0+psMhRvn9IC qhGLF7wSr03URsIEoAHH8I3NOsonR8vfuOh1F39QkO0OgoOrwpbEQMFzwABez8xWG7VR Y5pMuGVZmJUhFl0u1jx4PoN/tOPwU7jajGczs54YNjxSwCIdCyK+0HTo2JVWVSu4RMbb IZjw== X-Gm-Message-State: AOAM5311QFFOMIBxfHdI9/jvKTXLr/IOSJNrQg65A/AJzBdP4rZv1HGw bDdofz9AP8kCCqR6wYsOg4/dAg2GIvJFuw== X-Received: by 2002:a17:906:3d69:: with SMTP id r9mr22580442ejf.20.1591100563136; Tue, 02 Jun 2020 05:22:43 -0700 (PDT) Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com. [209.85.221.48]) by smtp.gmail.com with ESMTPSA id m21sm1522493edj.74.2020.06.02.05.22.41 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Jun 2020 05:22:42 -0700 (PDT) Received: by mail-wr1-f48.google.com with SMTP id x6so3150517wrm.13 for ; Tue, 02 Jun 2020 05:22:41 -0700 (PDT) X-Received: by 2002:a5d:6750:: with SMTP id l16mr26260746wrw.295.1591100561085; Tue, 02 Jun 2020 05:22:41 -0700 (PDT) MIME-Version: 1.0 References: <20200514160153.3646-1-sergey.senozhatsky@gmail.com> <20200514160153.3646-4-sergey.senozhatsky@gmail.com> In-Reply-To: From: Tomasz Figa Date: Tue, 2 Jun 2020 14:22:28 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 03/14] videobuf2: handle V4L2 buffer cache flags To: Hans Verkuil Cc: Sergey Senozhatsky , Hans Verkuil , Mauro Carvalho Chehab , Linux Media Mailing List , Linux Kernel Mailing List , Sergey Senozhatsky 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 Hans, On Tue, Jun 2, 2020 at 11:51 AM Hans Verkuil wrote: > > Hi Sergey, > > While doing final testing for this patch series (together with the v4l-utils patch) > I found one remaining issue: > > On 14/05/2020 18:01, Sergey Senozhatsky wrote: > > From: Sergey Senozhatsky > > > > Set video buffer cache management flags corresponding to V4L2 cache > > flags. > > > > Both ->prepare() and ->finish() cache management hints should be > > passed during this stage (buffer preparation), because there is > > no other way for user-space to tell V4L2 to avoid ->finish() cache > > flush. > > > > Signed-off-by: Sergey Senozhatsky > > --- > > .../media/common/videobuf2/videobuf2-v4l2.c | 48 +++++++++++++++++++ > > include/media/videobuf2-core.h | 11 +++++ > > 2 files changed, 59 insertions(+) > > > > diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c > > index eb5d5db96552..f13851212cc8 100644 > > --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > > +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c > > @@ -337,6 +337,53 @@ static int vb2_fill_vb2_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b > > return 0; > > } > > > > +static void set_buffer_cache_hints(struct vb2_queue *q, > > + struct vb2_buffer *vb, > > + struct v4l2_buffer *b) > > +{ > > + /* > > + * DMA exporter should take care of cache syncs, so we can avoid > > + * explicit ->prepare()/->finish() syncs. For other ->memory types > > + * we always need ->prepare() or/and ->finish() cache sync. > > + */ > > + if (q->memory == VB2_MEMORY_DMABUF) { > > + vb->need_cache_sync_on_finish = 0; > > + vb->need_cache_sync_on_prepare = 0; > > + return; > > + } > > + > > + /* > > + * Cache sync/invalidation flags are set by default in order to > > + * preserve existing behaviour for old apps/drivers. > > + */ > > + vb->need_cache_sync_on_prepare = 1; > > + vb->need_cache_sync_on_finish = 1; > > + > > + if (!vb2_queue_allows_cache_hints(q)) { > > + /* > > + * Clear buffer cache flags if queue does not support user > > + * space hints. That's to indicate to userspace that these > > + * flags won't work. > > + */ > > + b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_INVALIDATE; > > + b->flags &= ~V4L2_BUF_FLAG_NO_CACHE_CLEAN; > > + return; > > + } > > These two flags need to be cleared for VB2_MEMORY_DMABUF as well in the test above. > This bug is causing v4l2-compliance failures (use the test-media script in contrib/test > in v4l-utils: 'sudo test-media vim2m'). Would you be able to paste the failures, so that we know that we reproduce the same problems? Thanks! Best regards, Tomasz > > It's enough to post a v6.1 for this patch, everything else is fine. > > Regards, > > Hans > > > + > > + /* > > + * ->finish() cache sync can be avoided when queue direction is > > + * TO_DEVICE. > > + */ > > + if (q->dma_dir == DMA_TO_DEVICE) > > + vb->need_cache_sync_on_finish = 0; > > + > > + if (b->flags & V4L2_BUF_FLAG_NO_CACHE_INVALIDATE) > > + vb->need_cache_sync_on_finish = 0; > > + > > + if (b->flags & V4L2_BUF_FLAG_NO_CACHE_CLEAN) > > + vb->need_cache_sync_on_prepare = 0; > > +} > > + > > static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *mdev, > > struct v4l2_buffer *b, bool is_prepare, > > struct media_request **p_req) > > @@ -381,6 +428,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md > > } > > > > if (!vb->prepared) { > > + set_buffer_cache_hints(q, vb, b); > > /* Copy relevant information provided by the userspace */ > > memset(vbuf->planes, 0, > > sizeof(vbuf->planes[0]) * vb->num_planes); > > diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h > > index 7f39d9fffc8c..ccc5c498d3e3 100644 > > --- a/include/media/videobuf2-core.h > > +++ b/include/media/videobuf2-core.h > > @@ -635,6 +635,17 @@ struct vb2_queue { > > #endif > > }; > > > > +/** > > + * vb2_queue_allows_cache_hints() - Return true if the queue allows cache > > + * and memory consistency hints. > > + * > > + * @q: pointer to &struct vb2_queue with videobuf2 queue > > + */ > > +static inline bool vb2_queue_allows_cache_hints(struct vb2_queue *q) > > +{ > > + return q->allow_cache_hints && q->memory == VB2_MEMORY_MMAP; > > +} > > + > > /** > > * vb2_plane_vaddr() - Return a kernel virtual address of a given plane. > > * @vb: pointer to &struct vb2_buffer to which the plane in > > >