Received: by 10.223.176.5 with SMTP id f5csp1049068wra; Wed, 31 Jan 2018 00:12:54 -0800 (PST) X-Google-Smtp-Source: AH8x227uVCp3qyamDT9bqPDEHnGGyHFT8hVZnXVE+1xapHXp9I3kcBSYtPvoUZbA6e599geEe0UN X-Received: by 2002:a17:902:42a3:: with SMTP id h32-v6mr27199249pld.56.1517386374189; Wed, 31 Jan 2018 00:12:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517386374; cv=none; d=google.com; s=arc-20160816; b=Qzlqkmbj3MqBOJdLoS+kjlIoE/xXAfZIuDFLiGBKDxylj7SzdQjS0qU17LHdr1R3mk zlJSHzJ00guYrtRc38e7fCi5elTm3qekFyeSRYsO6ooS542yETj2Q2gBk/hH/cQuS14t 3E0sJ0lklxZ+WkZZVrkgy4ymQyJGxQyla5RoHA6OqOtJQMROc0sqQvy3yKAVup300DRB TW1pfl7hbujax5+B8Siey7KoWHppJ8OnAVEnE6JckxaTghczTmbiQqczG23c5NGgQiF4 R2dowwEoeLgBeFYaIcnQLzKlKSTUI41y2qHYNKthc5Tjl+PEnTbI6RbeKqFMfK9d6pYl hMiQ== 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=OpWfluFlqrHxaZwAVvthIQBbqWE8mPOQDfzH9ngs5i8=; b=bgGMD56Tk74ldA25GZ5YI3LIQyJPSMrlSEdo2rmQDexcxFHNE5x+bh2lZICriuluVI Pih7dIBLigh7J+JuochnlneivdCnYodlAWyKtmGgCfJFDlpEEsSB9N2ENGv63z9vCq+A yy5W21vHFfoUgAmIP7/WAFHixVeahiBc8C7P1b+OfbGjAsBGPE/ZCitJtsXxQM/csDLr KfkSLpG1RS6O/G11yLWu2EKznGC+pd3H95fhQ7qK5IYP2E8LlGr+FOkJjUZ1E/k/axVv I+rw8qy3/vce2ZhKzwul91BkwkCpeKZE7khuUt8kJvTjEOma1ESPDAI2z3Pt5Pz2s5hP Xpgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=VF4TLpw+; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3-v6si3722381pld.148.2018.01.31.00.12.39; Wed, 31 Jan 2018 00:12:54 -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; dkim=pass header.i=@chromium.org header.s=google header.b=VF4TLpw+; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753379AbeAaIK3 (ORCPT + 99 others); Wed, 31 Jan 2018 03:10:29 -0500 Received: from mail-vk0-f49.google.com ([209.85.213.49]:38184 "EHLO mail-vk0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753243AbeAaIK1 (ORCPT ); Wed, 31 Jan 2018 03:10:27 -0500 Received: by mail-vk0-f49.google.com with SMTP id z9so8498106vkd.5 for ; Wed, 31 Jan 2018 00:10:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=OpWfluFlqrHxaZwAVvthIQBbqWE8mPOQDfzH9ngs5i8=; b=VF4TLpw+Aza3+HHPjeOOjXTjtuMJGR+zLZomDj25TjL4LM3wtwLaVwDl+m+Kx11n3u 249/wpraEzTJSrvYGVdpmvCtWR4iojZgUhTZ81xvmZETsamyzkUsX+6u+/LWF3o0cD9I cMkJ9YGeyAdEhqmE6+Y/xHxd8YF23FtTyw9cA= 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=OpWfluFlqrHxaZwAVvthIQBbqWE8mPOQDfzH9ngs5i8=; b=f7EOQylL4ewi1W31YQQjvezCodsBqJ4e94dS0DNVAFySmBovT8FxDPhxe3HVWWaM/W CsrLmYrdJOLBpEAQp608CONrEx1GvW7/EWnyM/BdoCnyHGToIUEMo5sGaewocN0goV4D hLxuScXGaynarw0WZbDlFuRKegcpgqDVqmh3SYgbcT49Ey8rqEzRQeXKskQwayI2b3Xi BkVnlr9lKjWpFyC20x99hj6sSwxcTE3Y+cs0j7N+jbmr3X3zb22swL/rnP3xUbG1NkBQ e/68xATOiYjI3C7hWNnT43zev5BHwM6Qo3sWriAnKfeQA2lNfFTSJctbsOT1roHux/M0 D0Gw== X-Gm-Message-State: AKwxytexqEiE6L1UM+nowWnqi3cUnLPrWqRq1k3ys9KQzEYdReerxk4s vmw/pAUUX98YAu7snlGlMyGDmPgCouo= X-Received: by 10.31.94.207 with SMTP id s198mr24142832vkb.23.1517386226877; Wed, 31 Jan 2018 00:10:26 -0800 (PST) Received: from mail-vk0-f53.google.com (mail-vk0-f53.google.com. [209.85.213.53]) by smtp.gmail.com with ESMTPSA id o8sm2656354vke.26.2018.01.31.00.10.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jan 2018 00:10:25 -0800 (PST) Received: by mail-vk0-f53.google.com with SMTP id q62so8484723vkb.11 for ; Wed, 31 Jan 2018 00:10:25 -0800 (PST) X-Received: by 10.31.95.84 with SMTP id t81mr24195131vkb.173.1517386224710; Wed, 31 Jan 2018 00:10:24 -0800 (PST) MIME-Version: 1.0 Received: by 10.159.45.142 with HTTP; Wed, 31 Jan 2018 00:10:04 -0800 (PST) In-Reply-To: <307f58dd-ce7e-b6f5-092a-f8679349be73@xs4all.nl> References: <20180126060216.147918-1-acourbot@chromium.org> <307f58dd-ce7e-b6f5-092a-f8679349be73@xs4all.nl> From: Tomasz Figa Date: Wed, 31 Jan 2018 17:10:04 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [RFC PATCH 0/8] [media] Request API, take three To: Hans Verkuil Cc: Alexandre Courbot , Mauro Carvalho Chehab , Laurent Pinchart , Pawel Osciak , Marek Szyprowski , Sakari Ailus , Gustavo Padovan , Linux Media Mailing List , linux-kernel@vger.kernel.org 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, Sorry for joining the party late. On Wed, Jan 31, 2018 at 4:50 PM, Hans Verkuil wrote: > On 01/30/2018 07:31 AM, Alexandre Courbot wrote: >> Hi Hans, >> >> On Mon, Jan 29, 2018 at 8:21 PM, Hans Verkuil wrote: >>> On 01/26/2018 07:02 AM, Alexandre Courbot wrote: >>>> Howdy. Here is your bi-weekly request API redesign! ;) >>>> >>>> Again, this is a simple version that only implements the flow of requests, >>>> without applying controls. The intent is to get an agreement on a base to work >>>> on, since the previous versions went straight back to the redesign board. >>>> >>>> Highlights of this version: >>>> >>>> * As requested by Hans, request-bound buffers are now passed earlier to drivers, >>>> as early as the request itself is submitted. Doing it earlier is not be useful >>>> since the driver would not know the state of the request, and thus cannot do >>>> anything with the buffer. Drivers are now responsible for applying request >>>> parameters themselves. >>>> >>>> * As a consequence, there is no such thing as a "request queue" anymore. The >>>> flow of buffers decides the order in which requests are processed. Individual >>>> devices of the same pipeline can implement synchronization if needed, but this >>>> is beyond this first version. >>>> >>>> * VB2 code is still a bit shady. Some of it will interfere with the fences >>>> series, so I am waiting for the latter to land to do it properly. >>>> >>>> * Requests that are not yet submitted effectively act as fences on the buffers >>>> they own, resulting in the buffer queue being blocked until the request is >>>> submitted. An alternate design would be to only block the >>>> not-submitted-request's buffer and let further buffers pass before it, but since >>>> buffer order is becoming increasingly important I have decided to just block the >>>> queue. This is open to discussion though. >>> >>> I don't think we should mess with the order. >> >> Agreed, let's keep it that way then. >> I'm not sure I'm following here. Does it mean (quoting Alex): a) "Requests that are not yet submitted effectively act as fences on the buffers they own, resulting in the buffer queue being blocked until the request is submitted." b) "block the not-submitted-request's buffer and let further buffers pass before it" or neither? Hans, could you clarify what you think is the right behavior here? >>>> * For the codec usecase, I have experimented a bit marking CAPTURE buffers with >>>> the request FD that produced them (vim2m acts that way). This seems to work >>>> well, however FDs are process-local and could be closed before the CAPTURE >>>> buffer is dequeued, rendering that information less meaningful, if not >>>> dangerous. >>> >>> I don't follow this. Once the fd is passed to the kernel its refcount should be >>> increased so the data it represents won't be released if userspace closes the fd. >> >> The refcount of the request is increased. The refcount of the FD is >> not, since it is only a userspace reference to the request. > > I don't think that's right. Looking at how dma-buf does this (dma_buf_get in > dma-buf.c) it calls fget(fd) which increases the fd refcount. In fact, as far as > I can see the struct dma_buf doesn't have a refcount, it is solely refcounted > through the fd. That's probably the model you want to follow. As far as I can see from the code, fget() on an fd increases a reference count on the struct file backing the fd. I don't think there is another level of reference counting of fds themselves - that's why dup(fd) gives you another fd and you can't call close(fd) on the same fd two times. > >> >>> >>> Obviously if userspace closes the fd it cannot do anything with it anymore, but >>> it shouldn't be 'dangerous' AFAICT. >> >> It userspace later gets that closed FD back from a DQBUF call, and >> decides to use it again, then we would have a problem. I agree that it >> is userspace responsibility to be careful here, but making things >> foolproof never hurts. > > I think all the issues will go away if you refcount the fd instead of the > request. It worked well for dma-buf for years. I'm confused here. The kernel never returns the same FD for the same DMA-buf twice. Every time an ioctl is called, which returns a DMA-buf FD, it creates a new FD. Best regards, Tomasz