Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1759593imm; Tue, 22 May 2018 08:54:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrjasodtayT7rheSEw5ryckMRN+7qmB4zUCMcjKCAHvjITs/u6tp93c9OkH/lY2nRGrMs1K X-Received: by 2002:a63:91c4:: with SMTP id l187-v6mr19503886pge.261.1527004448633; Tue, 22 May 2018 08:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527004448; cv=none; d=google.com; s=arc-20160816; b=Fbu0Dbz+X35vfU3YlI/3CEVlEfnBDMU0wE6NsHPJcF9FmxUZlAAU9Usri7G10JDDcA ROJG9q/4lxOzxPcIrzlWq/VCRQ5ozkfuzGiatnQJxMr1GqFeayb6jxmp3b/SeXS6YoMf qG5v1R32KqTVJHzGFuJ1b8561kl1fN8Ti5BbFKOI/95k+xFDSEzQC0H1YtNzkRSOYj1L Je7NS5UoZHztQxHpAG6n5hDP/aa/ANW1LSgYAeb+pEeAc1XjlotRR1oS9Q8vE4pUekeq 3rzcwqo+NiUIwPsIkSfedAQiTGagvpwaSgUBLIyM+638ZptDuIdN9YtYc3wIzg75XVyD +GcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:date:cc:to:from:subject :message-id:arc-authentication-results; bh=C2ukVK/tWKG3sz4KpwtgDZ1W/av/5OXcZAM5s1soKJg=; b=ktRhwhCfgZUCv4oB0SY3z48F56fwATPHljjhvN09QTVZxDLKUeKNzN8rdAniih4ONI dya06ZGeTIxJFjuKqaqFpzjxN3CbZMFBBtpi+JkDB0GBgRjmJsBalAQIm6zeQAabn8tH 5vk2wfNNUiAP5PBUegEZPcuqkInzbzYvxiMRUTkyMDBIe7GERygXY3bWqeQezvxqw4ho DDcL7+QRrMI6kI0P/k0ZlTZTjjmGj8H9VC+d+HHWrpmARphKHQK0WGFUjEgK9DYy2e4v zekb0XZKzoo6qg1jHCU8HS88Vx4vyDJ0pJuS4zPXA+dcgSZ4snKNOX2rKURsd2sIz79z XkmQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r87-v6si17052801pfg.305.2018.05.22.08.53.54; Tue, 22 May 2018 08:54:08 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751741AbeEVPx1 (ORCPT + 99 others); Tue, 22 May 2018 11:53:27 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33404 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751701AbeEVPxW (ORCPT ); Tue, 22 May 2018 11:53:22 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 4D996263B02 Message-ID: <8f6f585f4076e3a2de76ca6a4a0e99c0c6f29584.camel@collabora.com> Subject: Re: [PATCH v10 11/16] vb2: add explicit fence user API From: Ezequiel Garcia To: Hans Verkuil , linux-media@vger.kernel.org Cc: kernel@collabora.com, Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Alexandre Courbot , Sakari Ailus , Brian Starkey , linux-kernel@vger.kernel.org, Gustavo Padovan Date: Tue, 22 May 2018 12:51:54 -0300 In-Reply-To: <9a7d4128-571e-468c-8c03-9f35f610a87f@xs4all.nl> References: <20180521165946.11778-1-ezequiel@collabora.com> <20180521165946.11778-12-ezequiel@collabora.com> <9a7d4128-571e-468c-8c03-9f35f610a87f@xs4all.nl> Organization: Collabora Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-05-22 at 14:05 +0200, Hans Verkuil wrote: > On 21/05/18 18:59, Ezequiel Garcia wrote: > > From: Gustavo Padovan > > > > Turn the reserved2 field into fence_fd that we will use to send > > an in-fence to the kernel or return an out-fence from the kernel to > > userspace. > > > > Two new flags were added, V4L2_BUF_FLAG_IN_FENCE, that should be used > > when sending an in-fence to the kernel to be waited on, and > > V4L2_BUF_FLAG_OUT_FENCE, to ask the kernel to give back an out-fence. > > > > v8: return -1 if new flags are set. > > v7: minor fixes on the Documentation (Hans Verkuil) > > > > v6: big improvement on doc (Hans Verkuil) > > > > v5: - keep using reserved2 field for cpia2 > > - set fence_fd to 0 for now, for compat with userspace(Mauro) > > > > v4: make it a union with reserved2 and fence_fd (Hans Verkuil) > > > > v3: make the out_fence refer to the current buffer (Hans Verkuil) > > > > v2: add documentation > > > > Signed-off-by: Gustavo Padovan > > --- > > Documentation/media/uapi/v4l/buffer.rst | 48 ++++++++++++++++++++++--- > > drivers/media/common/videobuf2/videobuf2-v4l2.c | 6 +++- > > drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 +-- > > include/uapi/linux/videodev2.h | 8 ++++- > > 4 files changed, 58 insertions(+), 8 deletions(-) > > > > diff --git a/Documentation/media/uapi/v4l/buffer.rst b/Documentation/media/uapi/v4l/buffer.rst > > index e2c85ddc990b..971b7453040c 100644 > > --- a/Documentation/media/uapi/v4l/buffer.rst > > +++ b/Documentation/media/uapi/v4l/buffer.rst > > @@ -300,11 +300,23 @@ struct v4l2_buffer > > multi-planar API the application sets this to the number of > > elements in the ``planes`` array. The driver will fill in the > > actual number of valid elements in that array. > > - * - __u32 > > - - ``reserved2`` > > + * - __s32 > > + - ``fence_fd`` > > - > > - - A place holder for future extensions. Drivers and applications > > - must set this to 0. > > + - Used to communicate a fence file descriptor from userspace to kernel > > + and vice-versa. On :ref:`VIDIOC_QBUF ` when sending > > + an in-fence for V4L2 to wait on, the ``V4L2_BUF_FLAG_IN_FENCE`` flag must > > + be used and this field set to the fence file descriptor of the in-fence. > > + If the in-fence is not valid ` VIDIOC_QBUF`` returns an error. > > + > > + To get an out-fence back from V4L2 the ``V4L2_BUF_FLAG_OUT_FENCE`` > > + must be set, the kernel will return the out-fence file descriptor in > > + this field. If it fails to create the out-fence ``VIDIOC_QBUF` returns > > + an error. > > + > > + For all other ioctls V4L2 sets this field to -1 if > > + ``V4L2_BUF_FLAG_IN_FENCE`` and/or ``V4L2_BUF_FLAG_OUT_FENCE`` are set, > > + otherwise this field is set to 0 for backward compatibility. > > * - __u32 > > - ``reserved`` > > - > > @@ -648,6 +660,34 @@ Buffer Flags > > - Start Of Exposure. The buffer timestamp has been taken when the > > exposure of the frame has begun. This is only valid for the > > ``V4L2_BUF_TYPE_VIDEO_CAPTURE`` buffer type. > > + * .. _`V4L2-BUF-FLAG-IN-FENCE`: > > + > > + - ``V4L2_BUF_FLAG_IN_FENCE`` > > + - 0x00200000 > > + - Ask V4L2 to wait on the fence passed in the ``fence_fd`` field. The > > + buffer won't be queued to the driver until the fence signals. The order > > + in which buffers are queued is guaranteed to be preserved, so any > > + buffers queued after this buffer will also be blocked until this fence > > + signals. This flag must be set before calling ``VIDIOC_QBUF``. For > > + other ioctls the driver just reports the value of the flag. > > + > > + If the fence signals the flag is cleared and not reported anymore. > > + If the fence is not valid ``VIDIOC_QBUF`` returns an error. > > + * .. _`V4L2-BUF-FLAG-OUT-FENCE`: > > + > > + - ``V4L2_BUF_FLAG_OUT_FENCE`` > > + - 0x00400000 > > + - Request for a fence to be attached to the buffer. The driver will fill > > + in the out-fence fd in the ``fence_fd`` field when :ref:`VIDIOC_QBUF > > + ` returns. This flag must be set before calling > > + ``VIDIOC_QBUF``. This flag is only an input, and is not set by the kernel. > > + > > + If the creation of the out-fence fails ``VIDIOC_QBUF`` returns an > > + error. > > + > > + Note that it is valid to set both ``V4L2_BUF_FLAG_IN_FENCE`` and > > + `V4L2_BUF_FLAG_OUT_FENCE`` flags. In such case, the ``fence_fd`` > > + field is used to both set the in-fence and return the out-fence. > > > > > > > > diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c > > index 64503615d00b..8312f61adfa6 100644 > > --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c > > +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c > > @@ -203,9 +203,13 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) > > b->timestamp = ns_to_timeval(vb->timestamp); > > b->timecode = vbuf->timecode; > > b->sequence = vbuf->sequence; > > - b->reserved2 = 0; > > b->reserved = 0; > > > > + if (b->flags & (V4L2_BUF_FLAG_IN_FENCE | V4L2_BUF_FLAG_OUT_FENCE)) > > + b->fence_fd = -1; > > + else > > + b->fence_fd = 0; > > I don't see why we can't just always set fence_fd to -1. > > There is no need for backwards compatibility that I can see. > > I thought we were trying to not break any users expecting reserved2 to be zeroed. Unless that's silly?