Received: by 10.223.176.46 with SMTP id f43csp1015265wra; Fri, 19 Jan 2018 05:44:35 -0800 (PST) X-Google-Smtp-Source: ACJfBot3Sh29W54QpeadS2Oj3xQJG8VSe3ztyQazb/HLC+m2hT610qHrmuF4L9iCr8efr4WVoUUp X-Received: by 10.99.122.15 with SMTP id v15mr32753119pgc.175.1516369475534; Fri, 19 Jan 2018 05:44:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516369475; cv=none; d=google.com; s=arc-20160816; b=IuqTVkwB2lsjWodzoGIipvyP9fABLzDBE2ZN8vvoGizDLYmWrfN6vZPuaRyVonSKLb dB06+gEa8bqwdZ3CVupMTf2LnyCZypNcCZaV840Zqi9x4vmY+OTr4pBqL2yZZXBL6cvO wMTPEcCgWmZumNzPYK2uakuNxkl1cjytGTcMUOAicIQW593VGxiHRuZpKZGANx8IG4bX Au21HqrGsjZfITJmURvjv3Uqb6Q+jtk1gh2Ydp5M+ZXGry40QghSKvzSuFsl81HWRLox tRWU7VUOhI+BPk6mBdnSE4287QMy0wfxRq5OcBS/2035253CaNuwETLADdzhsf6YdBVq iQjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=JUzewLOKb8FgtbL9dCMmM7AJJqzuSh6jDZkiXmvqql0=; b=mCVYZr/fr67HmcP3Vvv3xRg8+PeyVo+iKA7NibFVyEKqdzVjgGFdt4AUgYUr44Z72c SMFe0LOXP/VBXuwCfulOimugDosVfs8PH4doTRbnrdBo8+5vRibW4uXL+Hi5elHJoWl9 zL3ZIMBCkWaM+VSxtc9vYwEG3I2MirmM1+0bFkT27iMqwMfYRQOJUgVVPjIV6CE7P1lW Q8PTXYjugT+jMF/2jfLArDad7ZKKqDNedtrKGZqpqhQDIlLC5uBveMs6VIuRzeN5uF1R R+rZV7EAwAksOZtpqi5RgBmKQS1G3oUanazgryOiBmP6VPDItfj0JpY/YPdBL+4NejmE oW0Q== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f12si8402635pga.22.2018.01.19.05.44.20; Fri, 19 Jan 2018 05:44:35 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754964AbeASNnj (ORCPT + 99 others); Fri, 19 Jan 2018 08:43:39 -0500 Received: from mail-qt0-f196.google.com ([209.85.216.196]:45762 "EHLO mail-qt0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753332AbeASNnc (ORCPT ); Fri, 19 Jan 2018 08:43:32 -0500 Received: by mail-qt0-f196.google.com with SMTP id x27so3823877qtm.12; Fri, 19 Jan 2018 05:43:32 -0800 (PST) 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=JUzewLOKb8FgtbL9dCMmM7AJJqzuSh6jDZkiXmvqql0=; b=oEWXUVq/IK8UYvPmhicoYBFR5PBzGN4hlw/50GafDvmTJv0fK0F0y2uq4hoY0AZQb2 hEjZzOwTCBwNf/SybRJH0lle8pqLUTYH3HuFvY47+2JgvRIHSJ+TFVXjfM1SHIeZc/12 T+O5C7JVyHEGI5jt9voGt7/0uY1RC8roUrcaND2YMWe2pn31CMpLMqVCc+lwWPf/iAHl RJngghDEI/WPWqhZFhrthm78l7asJqximyiZgtGM6EQb0whZhSmR7w9I9EwHzgPNrTHe 9md72VAoqLAkfiwEqtdqgwEMgaiurI8PAAubMYH0/R+t3Z2mViHFIF4rGoY+3s5dPc2h 2D2g== X-Gm-Message-State: AKwxytdMvWDlGXWAA0FSzreipbnqrq8uEPaoRCSRqa2eY04xr1CNNa8l ldb1TB0gZKkS8bxDXkuTaxw= X-Received: by 10.55.76.17 with SMTP id z17mr12600901qka.145.1516369411491; Fri, 19 Jan 2018 05:43:31 -0800 (PST) Received: from jade ([189.6.17.74]) by smtp.gmail.com with ESMTPSA id o5sm6667311qtc.72.2018.01.19.05.43.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Jan 2018 05:43:30 -0800 (PST) Date: Fri, 19 Jan 2018 11:43:13 -0200 From: Gustavo Padovan To: Alexandre Courbot Cc: Linux Media Mailing List , Hans Verkuil , Mauro Carvalho Chehab , Shuah Khan , Pawel Osciak , Sakari Ailus , Brian Starkey , Thierry Escande , linux-kernel@vger.kernel.org, Gustavo Padovan Subject: Re: [PATCH v7 5/6] [media] vb2: add out-fence support to QBUF Message-ID: <20180119134313.GE9598@jade> References: <20180110160732.7722-1-gustavo@padovan.org> <20180110160732.7722-6-gustavo@padovan.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-01-15 Alexandre Courbot : > On Thu, Jan 11, 2018 at 1:07 AM, Gustavo Padovan wrote: > > /* > > * vb2_start_streaming() - Attempt to start streaming. > > * @q: videobuf2 queue > > @@ -1489,18 +1562,16 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, > > if (vb->in_fence) { > > ret = dma_fence_add_callback(vb->in_fence, &vb->fence_cb, > > vb2_qbuf_fence_cb); > > - if (ret == -EINVAL) { > > + /* is the fence signaled? */ > > + if (ret == -ENOENT) { > > + dma_fence_put(vb->in_fence); > > + vb->in_fence = NULL; > > + } else if (ret) { > > spin_unlock_irqrestore(&vb->fence_cb_lock, flags); > > goto err; > > - } else if (!ret) { > > - goto fill; > > } > > - > > - dma_fence_put(vb->in_fence); > > - vb->in_fence = NULL; > > This chunk seems to deal with input fences, shouldn't it be part of > the previous patch instead of this one? > > > > > - if ((b->fence_fd != 0 && b->fence_fd != -1) && > > - !(b->flags & V4L2_BUF_FLAG_IN_FENCE)) { > > + if (b->fence_fd > 0 && !(b->flags & V4L2_BUF_FLAG_IN_FENCE)) { > > dprintk(1, "%s: fence_fd set without IN_FENCE flag\n", opname); > > return -EINVAL; > > } > > > > + if (b->fence_fd == -1 && (b->flags & V4L2_BUF_FLAG_IN_FENCE)) { > > + dprintk(1, "%s: IN_FENCE flag set but no fence_fd\n", opname); > > + return -EINVAL; > > + } > > + > > Same here? > > > return __verify_planes_array(q->bufs[b->index], b); > > } > > > > @@ -212,7 +216,12 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) > > b->sequence = vbuf->sequence; > > b->reserved = 0; > > > > - b->fence_fd = 0; > > + if (b->flags & V4L2_BUF_FLAG_OUT_FENCE) { > > + b->fence_fd = vb->out_fence_fd; > > + } else { > > + b->fence_fd = 0; > > + } > > Sorry if this has already been discussed, but I don't remember the > outcome if it has. > > I wonder if doing this here could not make out_fence_fd leak in > situations where we don't need/want it to. Let's take for instance a > multi-process user program. One process queues a buffer with an > OUT_FENCE and gets a valid fd in fence_fd upon return. Then the other > process performs a QUERYBUF and gets the same fence_fd - which is > invalid in its context. Would it not be preferable fill the out fence > information only when queuing buffers, since it is the only time where > we are guaranteed it will be usable by the caller? > > Similarly, when a buffer is processed and user-space performs a DQBUF, > the V4L2_BUF_FLAG_OUT_FENCE will be set but fence_fd will be 0. Again, > limiting the return of out fence information to QBUF would prevent > this. Right. So in summary as this is something Hans commented on another e-mail in this thread. Your proposal is to only return the out_fence fd number on QBUF, right? And DQBUF and QUERYBUF would only return -1 in the fence_fd field. What I understood from Hans comment is that he is okay with sharing the fd in such cases and v4l2 already does that for dmabuf fds. I believe sharing is okay, as it will be either the same process or a process we gave the device fd in the first place. I'm not invested in any particular approach here. Thoughts? > > If we go that route, out_fence_fd could maybe become a local variable > of vb2_qbuf() instead of being a member of vb2_buffer, and would be > returned by vb2_setup_out_fence(). This would guarantee it does not > leak anywhere else. Gustavo