Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1043277ybb; Wed, 25 Mar 2020 14:35:49 -0700 (PDT) X-Google-Smtp-Source: ADFU+vsPRvMpDe3rp0Hy/GNbHBeH1jlNfN/b+R6lbFsmWh8J0QoIuL0cBbqhTf+QJSzzrK0Lkm0F X-Received: by 2002:a4a:bf19:: with SMTP id r25mr2907052oop.3.1585172149532; Wed, 25 Mar 2020 14:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585172149; cv=none; d=google.com; s=arc-20160816; b=pvbhWshtTPfhZOwf5LRZg+ncMbqxNmrKYydEhErRNbV0nZZPXuX7mHpGMGXGIF/6Ma bwquoi4B3qwSflWp11uo0FgaP24/uiasffaKJWFuoKu2PXoJje4+mJ6pVoLM2iKw0HyU ayjNhEnWOP2vL1rfwgyev0IxEku9l2ovhrXeD3xOzDdopyIMK/ikuPinBDzah1c0uUQ/ pkeTM/7grFoiKLj1oHfc4j09yTs3QGEnhBJXQz27eoLTH5kcHzhndswTwhv4NZoFvjHK ISdiKAK/vSQzDfOv83bK4ZOuuFLayIogJwA+fYGZ/oAQ3X1PDuAZE2vuObUcnbaL9uXC 9CUw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=QSkUcy5RtQzVPjtjNEQHwnodWPLKTDjWPAhQcruw4fk=; b=rmriDZYsxeWokSGiRwRmmvRdE2+L61b4iKUBONTSMmaNRkhiy2Lmu+d4XJav349GSM do7vD9TpfAHBGyO1eJ3mF0cwYJkukdXAyd+rfwJv0ZPKP+oEZXrdL0Iu6j1w5RCQdcab R2Vaa6lgo6pxvhfZLja2cs1YH0GxHSfgnkxEiTG5YBuZP4PfyKcFvWS5SFE0b4KtAcW+ 26JRSRXyAODs8x1CQrkqJEAmyj05NNRuoePNTkWV30A9+v1mdt6lCLLgm+xbVV6l9Byb ViiHdTO1XEnsLotyJk/dsmWOS237xNi+AERbADixf+oatukdIwsHLkd8iZ3sW9HoRORo VX/Q== 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 l13si165926otb.102.2020.03.25.14.35.36; Wed, 25 Mar 2020 14:35:49 -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 S1727530AbgCYVfC (ORCPT + 99 others); Wed, 25 Mar 2020 17:35:02 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:39834 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbgCYVfC (ORCPT ); Wed, 25 Mar 2020 17:35:02 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 63A5B293EA9 From: Ezequiel Garcia To: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Tomasz Figa , Nicolas Dufresne , kernel@collabora.com, Jonas Karlman , Heiko Stuebner , Hans Verkuil , Alexandre Courbot , Jeffrey Kardatzke , Rob Herring , Mark Rutland , devicetree@vger.kernel.org, Ezequiel Garcia , Nicolas Dufresne Subject: [PATCH v3 1/7] v4l2-mem2mem: return CAPTURE buffer first Date: Wed, 25 Mar 2020 18:34:32 -0300 Message-Id: <20200325213439.16509-2-ezequiel@collabora.com> X-Mailer: git-send-email 2.26.0.rc2 In-Reply-To: <20200325213439.16509-1-ezequiel@collabora.com> References: <20200325213439.16509-1-ezequiel@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the request API is used, typically an OUTPUT (src) buffer will be part of a request. A userspace process will be typically blocked, waiting on the request file descriptor. Returning the OUTPUT (src) buffer will wake-up such processes, who will immediately attempt to dequeue the CAPTURE buffer, only to find it's still unavailable. Therefore, change v4l2_m2m_buf_done_and_job_finish returning the CAPTURE (dst) buffer first, to avoid signalling the request file descriptor prematurely, i.e. before the CAPTURE buffer is done. When the request API is not used, this change should have no impact. Tested-by: Nicolas Dufresne Signed-off-by: Ezequiel Garcia --- drivers/media/v4l2-core/v4l2-mem2mem.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 8986c31176e9..62ac9424c92a 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -504,12 +504,21 @@ void v4l2_m2m_buf_done_and_job_finish(struct v4l2_m2m_dev *m2m_dev, if (WARN_ON(!src_buf || !dst_buf)) goto unlock; - v4l2_m2m_buf_done(src_buf, state); dst_buf->is_held = src_buf->flags & V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF; if (!dst_buf->is_held) { v4l2_m2m_dst_buf_remove(m2m_ctx); v4l2_m2m_buf_done(dst_buf, state); } + /* + * If the request API is being used, returning the OUTPUT + * (src) buffer will wake-up any process waiting on the + * request file descriptor. + * + * Therefore, return the CAPTURE (dst) buffer first, + * to avoid signalling the request file descriptor + * before the CAPTURE buffer is done. + */ + v4l2_m2m_buf_done(src_buf, state); schedule_next = _v4l2_m2m_job_finish(m2m_dev, m2m_ctx); unlock: spin_unlock_irqrestore(&m2m_dev->job_spinlock, flags); -- 2.26.0.rc2