Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp630133ybh; Wed, 18 Mar 2020 06:22:29 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvD8MBrgzl0tjxaHxspwI8dngvsI6MZA95sOCSq+2PCRC66vb4DfZuHAwiJvyrc9eP6a3RO X-Received: by 2002:a05:6808:4c2:: with SMTP id a2mr3020340oie.94.1584537748908; Wed, 18 Mar 2020 06:22:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584537748; cv=none; d=google.com; s=arc-20160816; b=L+4TRYAez1/E0CJYIVJGLvY2BDACOCXyEf63j6igqNl37qLabgz+OS3rD7CEaSE3qB chVmrGX4bSAuc9f7Npe3fW/x2efcoWekxbPYmSp3ELIYd1sjDei6SMy6HaLLCbekVB8N n4yhTRrCs9OU+ZxDAXf/i114/Bh4lIF2picrpAMZ/akIq3NQwAKkO9XOP7wK81ZLKimE n2O2fO0VW8qP8+vraldq323I0eOydLvdm3D41AgDR+XuBzL4/0h/ryrbiOAZt4dleNc/ 3tPakC5xz7gUZNBaOCaycHFDOoV/YOQvd1Xap8H7LDC2u5ys2OfHwR8oEopxBnPlnwLE 88Xw== 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=X1YjOE3fxVFEJgSmOYOcV5c39l0TZ8EjN2aD4R+NzFo=; b=jKW9Oxh2cDnq9OLQGK9Y5QocKq7dTznL4OjzyPb39vbetWS48DDlkKgD8fXm8FCE1N LO03NSXrq4fDV45BDVJm05rfsuzcaiNzHRmQGbZmFOn5YzsYlnY42jb1neXta2BjNvNg SoySrFj10/VcgCFWjTYT6IvLSndm1uPZ+jqza0T5kqlA9RJN5/Y0vxNYzvZOO6VKKzHU Aa4jDUdi/Ei13J0NCSMfEL05DDXQSaXk4qLy8TXap3eacss38CbIryNdGjKSqc5mRbcQ wcscnOFdbzp368EuFfeB3VYf1oS2Hg9JxC7ciiRiYWZItRfDJJwZq+M4MvKxBrGzHSsa eLyQ== 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 o1si3128197otk.154.2020.03.18.06.22.15; Wed, 18 Mar 2020 06:22:28 -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 S1727065AbgCRNVx (ORCPT + 99 others); Wed, 18 Mar 2020 09:21:53 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:44456 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726638AbgCRNVx (ORCPT ); Wed, 18 Mar 2020 09:21:53 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 8D2D229661B 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 , Ezequiel Garcia , Nicolas Dufresne Subject: [PATCH v2 1/8] v4l2-mem2mem: return CAPTURE buffer first Date: Wed, 18 Mar 2020 10:21:01 -0300 Message-Id: <20200318132108.21873-2-ezequiel@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200318132108.21873-1-ezequiel@collabora.com> References: <20200318132108.21873-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.25.0