Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp787236ybh; Wed, 11 Mar 2020 10:47:52 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs3GwxeEnAWhpmOeov52TwLmTZgqgDFsCOJJgMOTK80h6OM4CZXceQ67aWO6/+Ha1WZlc+7 X-Received: by 2002:a05:6830:1081:: with SMTP id y1mr3101631oto.367.1583948872155; Wed, 11 Mar 2020 10:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583948872; cv=none; d=google.com; s=arc-20160816; b=jS0+jrGC4Oo3cfK7Tybh+1z64GKKrV3smMx/3C5vjmMdz/+gm2q4oPwIUdaJ23YFWA 8wiX1SRD2CMq8gseGpEf0g324NNYoL567PfoTvi7F89IqxgcMrNGMdmEXRxPli1KWhXF JZS726zULrMrlRdf44kKWHVCu0xcqtQYTws9cyXjTGLcBrJL1FS207+nb609FVFwd8DF AmNegwfkVZJIgskMRMjWrM9gja8h5hHqaXELIQVa2jutGlsTvjAHxQQry6TAO0wfVa3X VdLytCoDqDXXlr5LvVBUJ0bc/GxMQgrLfRPOmjK8+VYe2fipwY7aSGfI97tI6LqAW0lC ORKw== 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=k9QpqmsQpqHW1sWbg4bnCNGpetPw8STMLAYOsD97J50=; b=j8byu1dFaW+P0CVxmUVS9ECWHzdP1WSd9oeE97Fb5/OhXyQ6GWy/lD4cy4USfMDSrt CtsNUtkO6Zw0rB3QR92uLg+qXm78R9+1ZYjHB42BV8O7ceLg+oVZK4lAQUy72I2r99th n4sOeQP2DwJ3eknsBfGIc05DD/BRNU4d5iSsmSVLvFf9adX7K/u8pLD+8Cd0fGl6swKd N+VdXWzs7OD6ttbDLJMV5/y64g99yk3gEyMR8Er7/vKMdxQxiwgjFmE1IgLR010cpJ+j tgtpzAPDasFGHTj7xAIa9pLhzy/JVE9T8N+Jz8b+eEUXp6bY4cjNgeWAuox7Fz4FFaoH wpWA== 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 x79si1377046oif.180.2020.03.11.10.47.40; Wed, 11 Mar 2020 10:47:52 -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 S1730658AbgCKRrP (ORCPT + 99 others); Wed, 11 Mar 2020 13:47:15 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33054 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730487AbgCKRrP (ORCPT ); Wed, 11 Mar 2020 13:47:15 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 639D72912DD 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 , Ezequiel Garcia Subject: [PATCH 1/6] v4l2-mem2mem: return CAPTURE buffer first Date: Wed, 11 Mar 2020 14:42:55 -0300 Message-Id: <20200311174300.19407-2-ezequiel@collabora.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200311174300.19407-1-ezequiel@collabora.com> References: <20200311174300.19407-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. 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