Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1819631imm; Tue, 22 May 2018 09:49:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr5ov7OaJcmKrhxT7M1YCMeoSZiXF6/yV3HY7AIEmZkv5yoQ6SFAKHoIvNQEv1XtXW+fzb7 X-Received: by 2002:a17:902:bb92:: with SMTP id m18-v6mr25766022pls.46.1527007793327; Tue, 22 May 2018 09:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527007793; cv=none; d=google.com; s=arc-20160816; b=mn5HJ8YLG7UAxk/EsZP0HChs+HkDidvcZ+KsJXfotDSCHn9gIrX9miAlNExao6whl2 DW7mLNC3jVV3HX7rH2Ylr2+KezOaCQXy34/YUIWQFezygFt2X0/kRr6lrYD4QaAc/k1j zSwg72JLmKfpf+AJHsON1Fe/Tm6Uqs+PBRXXPlSV77+Uc1uQRpjkpu6pWFTYI1eL99Z5 lUOvQbURQhOqJialee1inkpDfx4pfh/nWY8j7L14ar9OQmv/7uVb2uUCZlI/llGIKgSr PM+nvspUwd2Q7Pa0y0UtdjAyESmMoUIinUhSJe6dt39tD7vBxb6wI1dOFMwxZvNyh9V9 B+mw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=bPZ6qwL9VwcDBRSMjlApXbrgNf33ZCfGjEteiHKOsLE=; b=CL4ilhv6nGnA24wx7s2pXOcyAs5VnJyhTKUI8GJC5OdklxWtpygUN0/DLbwooUzmQw HAOpstOiAMa5VPZRtlHPBTbOPb8dyPR8M+NSxgPUD65J+2R6pIqCGV/3sTQSI3sh9BDp O2r5mKXl1n7/rsTKAPcGApniHmuMyleciXpiNceOcEydEIib9U8+/mKSyFHutJQVFV4e Fl/aSHurfhoceGcVJ6Rwgiegm+hMYrpSQeuOzVNgJkvzX7fTZo2jNCLH3wzOk+CHgbir spAi6KYilOqxNylOH+1/i4+9NjRPe8M/qieO2wekF9SdWqMs08GpwRC3R+Lc33xApwQS lEFA== 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 q80-v6si16862105pfi.109.2018.05.22.09.49.38; Tue, 22 May 2018 09:49:53 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751412AbeEVQsT (ORCPT + 99 others); Tue, 22 May 2018 12:48:19 -0400 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]:48648 "EHLO lb3-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751196AbeEVQsS (ORCPT ); Tue, 22 May 2018 12:48:18 -0400 Received: from [IPv6:2001:983:e9a7:1:6dcf:7d19:725:579d] ([IPv6:2001:983:e9a7:1:6dcf:7d19:725:579d]) by smtp-cloud7.xs4all.net with ESMTPA id LASNfjwBS8U07LASOfrKJr; Tue, 22 May 2018 18:48:16 +0200 Subject: Re: [PATCH v10 12/16] vb2: add in-fence support to QBUF To: Ezequiel Garcia , 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 References: <20180521165946.11778-1-ezequiel@collabora.com> <20180521165946.11778-13-ezequiel@collabora.com> <7462919b-ad6f-eb8c-7389-ef0ff6e9d1a2@xs4all.nl> <062e8128491e63927f4669ad08c40d29dfbb4141.camel@collabora.com> From: Hans Verkuil Message-ID: <8848cdb3-73cf-2122-4c50-a57fcd83e151@xs4all.nl> Date: Tue, 22 May 2018 18:48:15 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <062e8128491e63927f4669ad08c40d29dfbb4141.camel@collabora.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfDB6XVyB+Eakn8YN8QDAih+/rFGhG+RlEcd6nYpYTZICHwR1H60ncVvnCSToyd0N5lrsEtsWt7BMu+hj0WOtvTCOZsHxnpys9tmtNvAAQAimBQ/pWph7 APdj8GUfjNd6RTGrY4DidGalb34n8mVx7C5PSE6PC4ztH1jUXjlqVMQp7nEOBsVNybpAq7bixNBLUHHaDfAMCjw/8j9bjo19ILTFmOUlN0DatDdsugcynJM1 eYpehRkLF0GdpU3LlDVtucR4o+0yCR92PcQmvQyFwEJ/HohdInY1vz89iiCEYBfvFeuDbcZHzSv8Fk7/vG8zx7DhUA+QHFsdhXa/HiMajPeqWEHYbc7gwRB5 FnsF0wdlfUiAqu7gJgRjkR5QKVwkDUi6DvTSs77iuFeMgn6CpEwyQbX2a5EjSsfgBUlATsP7oqdAVnGyboFz51Ik65YVrdztQdUnhKOjAoqVRLCu3mJSdkQR bgVPTThJByAxJVzfRQ4pM1ApqRq3S/z6kQMQQJTwA1JE6bOyryQ+4h67H04ZfLUgGyjGGpAMaGWkKLHFsPrSMES4w1EWJZHS61cseQw/OhFYauaMD4e7XUny gwlyASYdugYy53SzEu6vvOay Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22/05/18 18:22, Ezequiel Garcia wrote: >>> @@ -1615,7 +1762,12 @@ static void __vb2_dqbuf(struct vb2_buffer *vb) >>> return; >>> >>> vb->state = VB2_BUF_STATE_DEQUEUED; >>> - >>> + if (vb->in_fence) { >>> + if (dma_fence_remove_callback(vb->in_fence, &vb->fence_cb)) >>> + __vb2_buffer_put(vb); >>> + dma_fence_put(vb->in_fence); >>> + vb->in_fence = NULL; >>> + } >>> /* unmap DMABUF buffer */ >>> if (q->memory == VB2_MEMORY_DMABUF) >>> for (i = 0; i < vb->num_planes; ++i) { >>> @@ -1653,7 +1805,7 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb, >>> if (pindex) >>> *pindex = vb->index; >>> >>> - /* Fill buffer information for the userspace */ >>> + /* Fill buffer information for userspace */ >>> if (pb) >>> call_void_bufop(q, fill_user_buffer, vb, pb); >>> >>> @@ -1700,8 +1852,8 @@ static void __vb2_queue_cancel(struct vb2_queue *q) >>> if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { >>> for (i = 0; i < q->num_buffers; ++i) >>> if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE) { >>> - pr_warn("driver bug: stop_streaming operation is leaving buf %p in active state\n", >>> - q->bufs[i]); >>> + pr_warn("driver bug: stop_streaming operation is leaving buf[%d] 0x%p in active >>> state\n", >>> + q->bufs[i]->index, q->bufs[i]); >>> vb2_buffer_done(q->bufs[i], VB2_BUF_STATE_ERROR); >>> } >> >> Shouldn't any pending fences be canceled here? >> > > No, we don't have to flush -- that's the reason of the refcount :) > The qbuf_work won't do anything if all the buffers are returned > by the driver (with error or done state), and if !streaming. > > Also, note that's why qbuf_work checks for the queued state, and not > for the error state. > >> I feel uncomfortable with the refcounting of buffers, I'd rather that when we >> cancel the queue all fences for buffers are removed/canceled/whatever. >> >> Is there any reason for refcounting if we cancel all pending fences here? >> >> Note that besides canceling fences you also need to cancel/flush __qbuf_work. >> >> > > Like I said above, I'm trying to avoid cancel/flushing the workqueue. > Currently, I believe it works fine without any flushing, provided we refcount > the buffers. > > The problem with cancelling the workqueue, is that you need to unlock the queue > lock, to avoid a deadlock. It seemed to me that having a refcount is more natural. > > Thoughts? > I'll take another look tomorrow morning. Do you have a public git tree containing this series that I can browse? Regards, Hans