Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4099686ybz; Tue, 28 Apr 2020 05:52:37 -0700 (PDT) X-Google-Smtp-Source: APiQypIsEhrYRLrEE9WZYVwRVZKfbNDacyxcL0+VIveqwaR0p6EHxb83gPQfcWP4a/OQgpltRYFa X-Received: by 2002:aa7:daca:: with SMTP id x10mr21444896eds.59.1588078357406; Tue, 28 Apr 2020 05:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588078357; cv=none; d=google.com; s=arc-20160816; b=Qh8rCFl50hd93dsijcNg9UlCpdpB+skENtseXz3dYcI8hdnCR+jb3zrFD38Gf9gF2N SYjUZDeuZg2VDtkaOms2FSYzHv1qzURh9z5fcb5cSNKQV6yv25k/cb+FGgdIzR0mm/Hh R+lwOlVIMjf2fcMtkA49DrPoCRzlHZ7Ix37wRA509bruaJS6Q15y6zbBOSVKVilq0esO cfp7InkeUPorOET52fiFLVJYgeWUN+g6/55sAEx7HXBCHEzyMbNlGs8MrTnvtE/b6ThY DyevoHx+atgdvBUh0VASBB99YAUwjJ2T6uJSVflvqcQiCu0tn+Y0yo1wOMu2m5aQhUEU nFGw== 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 :dkim-signature; bh=IJwZdm/27BG35A63f5QLfwSuwxh6v7svpz8baWGJ+rE=; b=k0cWYtRi+zvnPiSVDN8NM2zn6rBMBFvZtrcBxd6Ed0ujCOmzIY56D+0yqB+7nQjLx0 PuvppHgeQTCy+0PQDwxrvt34wGN8vtJPQn1zHUVqv3XVJvMuFgfBzPfsBXZIOp3uStF0 Y1mZ1Bvdr43c0jk/bRCdVRALtVEYc0XdnwF8Ic8Uma4oQd5HWrYdWi8ToRCr8BWQ0TYM TYpFyRepaKaLkv6Qz0vyV358FJ85uSs5bKgXWM3U0wpKvOD9LpLUINgjUvfkU3YuOYBd miBm55TIJ8u8xSbCZTK3Sz0C6UFYc0uDDDRxGibcvSbSMwdk306tuBX6bOVE9pxwouko 6x2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=b0KZlUDC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d60si1483492edc.337.2020.04.28.05.52.14; Tue, 28 Apr 2020 05:52:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=b0KZlUDC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727025AbgD1Muu (ORCPT + 99 others); Tue, 28 Apr 2020 08:50:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726930AbgD1Mus (ORCPT ); Tue, 28 Apr 2020 08:50:48 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43117C03C1A9 for ; Tue, 28 Apr 2020 05:50:48 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id x4so2623426wmj.1 for ; Tue, 28 Apr 2020 05:50:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IJwZdm/27BG35A63f5QLfwSuwxh6v7svpz8baWGJ+rE=; b=b0KZlUDCbPr3AGniEFxQ2PAfeUZ9+O09I7oVG1Y0/2PmPOuUg+IOA5fzL7hjognD46 mF5I8HnLNtnVp/Xwt9M3ow9HxqOG8lPKqx+nqKLEsWdJBEtL674YPRZmqLSth8OQbRgS 3atuukLZLleeVou50Xsd1VS1b3N7bjGdyGguJGj5q1AI2oT6IKAlwR2iFDW0gk7CBB7G eYPqfDjjSto7GqeeUj8Bgmic6SuD4IpNMuHYcO20edQc/XlJB2zjPmHuhNxD4HkulThZ r7IGiWPDVdjIsvulhCtc314fTKTMG/6DTE8SeG5D3Fu5hMeMrCbNdFPx9W5e2CPB8Mrx AlWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IJwZdm/27BG35A63f5QLfwSuwxh6v7svpz8baWGJ+rE=; b=tDrjaNx5Tvva2G/J7ioBOC6tYani4ZHwC0Q7UmCBFQ75yTfpc/PkGrINwhQS/g/VLT vmuPRU2N02rUdF4In2jlfvUNCwxbI6Bx6bYU2wz9kqKZLWu9Zfs+zm16GSROCFawHdAW YtpTDKhb0xVSLId6gdf3ckWbKIsNwZDN2uwOjjZnQ3X/gcBWVXjWFdUFo7wMGJLqp6DB Csrz/j3UV1f/p3JjGCHLe4kg/AEOVriHjVcnAzpZFRlxvh0PtDlKhQxXDi81WFKnepdW 8bPbmKFCavtFj2PuJ5AqXWD0O1lBK77/cODRD1Ij1sdmQZJ4jVjLVeBJRNqCveANYLDr CDTQ== X-Gm-Message-State: AGi0PuZhdLGheFgypq3Ms2ivQPu+m3rvO0tE0mQoudEHDA2SgNTdTc3g agGpe4Rve6Jw+6a/0ZFZtxtCHD9leB5elg== X-Received: by 2002:a05:600c:1109:: with SMTP id b9mr4408443wma.116.1588078246765; Tue, 28 Apr 2020 05:50:46 -0700 (PDT) Received: from localhost.localdomain ([2a01:e35:2ec0:82b0:4460:3fd3:382:4a71]) by smtp.gmail.com with ESMTPSA id q184sm3246115wma.25.2020.04.28.05.50.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Apr 2020 05:50:46 -0700 (PDT) From: Neil Armstrong To: linux-media@vger.kernel.org, hverkuil-cisco@xs4all.nl Cc: linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxime Jourdan , Neil Armstrong Subject: [PATCH 2/3] media: meson: vdec: fix another case of VP9 buffer shortage Date: Tue, 28 Apr 2020 14:50:35 +0200 Message-Id: <20200428125036.9401-3-narmstrong@baylibre.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20200428125036.9401-1-narmstrong@baylibre.com> References: <20200428125036.9401-1-narmstrong@baylibre.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 From: Maxime Jourdan - Redo the logic where VP9 gets fresh CAPTURE buffers. The previous code could lead to a hardlock. - Reserve 4 margin buffers instead of 3, as apparently there are corner cases where 3 is not enough. Fixes: e9a3eb4819ca ("media: meson: vdec: add VP9 input support") Fixes: 00c43088aa68 ("media: meson: vdec: add VP9 decoder support") Signed-off-by: Maxime Jourdan Signed-off-by: Neil Armstrong --- drivers/staging/media/meson/vdec/codec_vp9.c | 41 +++++++++++++------- drivers/staging/media/meson/vdec/esparser.c | 24 ++++++------ 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/drivers/staging/media/meson/vdec/codec_vp9.c b/drivers/staging/media/meson/vdec/codec_vp9.c index 897f5d7a6aad..28a7e62e7371 100644 --- a/drivers/staging/media/meson/vdec/codec_vp9.c +++ b/drivers/staging/media/meson/vdec/codec_vp9.c @@ -1185,6 +1185,29 @@ static void codec_vp9_set_mc(struct amvdec_session *sess, amvdec_write_dos(core, VP9D_MPP_REF_SCALE_ENBL, scale); } +/* + * Get a free VB2 buffer that isn't currently used. + * VP9 references are held sometimes for so long that it's not really an option + * to hold them until they're no longer referenced, as it would delay the + * CAPTURE queue too much + */ +static struct vb2_v4l2_buffer *get_free_vbuf(struct amvdec_session *sess) +{ + struct codec_vp9 *vp9 = sess->priv; + struct vb2_v4l2_buffer *vbuf = v4l2_m2m_dst_buf_remove(sess->m2m_ctx); + struct vb2_v4l2_buffer *vbuf2; + + if (!vbuf) + return NULL; + + if (!codec_vp9_get_frame_by_idx(vp9, vbuf->vb2_buf.index)) + return vbuf; + + vbuf2 = get_free_vbuf(sess); + v4l2_m2m_buf_queue(sess->m2m_ctx, vbuf); + return vbuf2; +} + static struct vp9_frame *codec_vp9_get_new_frame(struct amvdec_session *sess) { struct codec_vp9 *vp9 = sess->priv; @@ -1196,25 +1219,13 @@ static struct vp9_frame *codec_vp9_get_new_frame(struct amvdec_session *sess) if (!new_frame) return NULL; - vbuf = v4l2_m2m_dst_buf_remove(sess->m2m_ctx); + vbuf = get_free_vbuf(sess); if (!vbuf) { dev_err(sess->core->dev, "No dst buffer available\n"); kfree(new_frame); return NULL; } - while (codec_vp9_get_frame_by_idx(vp9, vbuf->vb2_buf.index)) { - struct vb2_v4l2_buffer *old_vbuf = vbuf; - - vbuf = v4l2_m2m_dst_buf_remove(sess->m2m_ctx); - v4l2_m2m_buf_queue(sess->m2m_ctx, old_vbuf); - if (!vbuf) { - dev_err(sess->core->dev, "No dst buffer available\n"); - kfree(new_frame); - return NULL; - } - } - new_frame->vbuf = vbuf; new_frame->index = vbuf->vb2_buf.index; new_frame->intra_only = param->p.intra_only; @@ -1267,8 +1278,10 @@ static void codec_vp9_process_frame(struct amvdec_session *sess) codec_vp9_rm_noshow_frame(sess); vp9->cur_frame = codec_vp9_get_new_frame(sess); - if (!vp9->cur_frame) + if (!vp9->cur_frame) { + amvdec_abort(sess); return; + } pr_debug("frame %d: type: %08X; show_exist: %u; show: %u, intra_only: %u\n", vp9->cur_frame->index, diff --git a/drivers/staging/media/meson/vdec/esparser.c b/drivers/staging/media/meson/vdec/esparser.c index db7022707ff8..814bb0587e3b 100644 --- a/drivers/staging/media/meson/vdec/esparser.c +++ b/drivers/staging/media/meson/vdec/esparser.c @@ -301,21 +301,19 @@ esparser_queue(struct amvdec_session *sess, struct vb2_v4l2_buffer *vbuf) u32 offset; u32 pad_size; - /* - * When max ref frame is held by VP9, this should be -= 3 to prevent a - * shortage of CAPTURE buffers on the decoder side. - * For the future, a good enhancement of the way this is handled could - * be to notify new capture buffers to the decoding modules, so that - * they could pause when there is no capture buffer available and - * resume on this notification. - */ - if (sess->fmt_out->pixfmt == V4L2_PIX_FMT_VP9) { - if (codec_ops->num_pending_bufs) - num_dst_bufs = codec_ops->num_pending_bufs(sess); - + if (codec_ops->num_pending_bufs) { + num_dst_bufs = codec_ops->num_pending_bufs(sess); num_dst_bufs += v4l2_m2m_num_dst_bufs_ready(sess->m2m_ctx); + /* + * When max ref frame is held by VP9, this should be -= 4 + * to prevent a shortage of CAPTURE buffers on the decoder side. + * For the future, a good enhancement of the way this is handled + * could be to notify new capture buffers to the decoding + * modules, so that they could pause when there is no capture + * buffer available and resume on this notification. + */ if (sess->fmt_out->pixfmt == V4L2_PIX_FMT_VP9) - num_dst_bufs -= 3; + num_dst_bufs -= 4; if (esparser_vififo_get_free_space(sess) < payload_size || atomic_read(&sess->esparser_queued_bufs) >= num_dst_bufs) -- 2.22.0