Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp695844ybb; Wed, 8 Apr 2020 08:13:26 -0700 (PDT) X-Google-Smtp-Source: APiQypKuSPLkSjw48Aa/1Zz2OfQJQazAPfjfVsqZTfr5sJ9pyK8lX2QSCKaT6Q40ada3LKOanJ4v X-Received: by 2002:a9d:5e92:: with SMTP id f18mr5841110otl.78.1586358806342; Wed, 08 Apr 2020 08:13:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586358806; cv=none; d=google.com; s=arc-20160816; b=El7XbYo37eFL+m/YEWR3VSw452jDx5xETo41887L89UC6y033RB7uoZ6Zy11QQXk+v 4SdfsWsxjoX+5wt3TckQYv7mBkMJl01DuC/T3WLmbEhq33Sg49F8AD4DZMjHZpbzsoge MQha5kvDm9z6hKMwbUCYOGlQh3uDhbUb1LVlQnvRGLmCD3kAGThrLvrk8YvmghHXzQNb YBIAH+pIXmZBxuojM/7+AxA9BpPbgQaOlG7J9fUoaikhQGxNFlm9TusKXUe5d6iLSDn8 5eQCxXUdcP7dRQx8vEQb7cibBnattL56NFr1wlPx6ncqk7ARtdgEvdq6M+qpS0YzBNI4 5T6Q== 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 :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=s2A5nQax9rCXrmmoE7W7w7hQ8ObJqH45C4l2hVSSNe4=; b=OViRYIGCLmoeiOYCevhdCPBe2gYBUsxMkd9fnXN58fmmKr7yHfMKlZIpVqJsg1ECyz hIZDbO1Cq8t8XZ5j0y1HQ+gMDqG5tDdQhQI7fBDord/jZsoeql0GdVezjEJ3xXnsYWk9 GtWXsfP07RbboPZ1vk/AtGvE87DGxxb8akN43U/OqHu8Xwba8oCGP6jLfyunvFzBohZE pUpEK1w7pdiD6on6wOYb9kmeqpB35YRLskUwWvNMMZ0JtNbNwaXowDXhGgTvrglB9JXN W+ke012xQ8mDiTB4O6a0InQolq+n0ocPLfMY1/TEu6MZ+mE8y9og5pcw3MFe2oirmoyb KaKA== 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 s5si2650216ood.66.2020.04.08.08.13.13; Wed, 08 Apr 2020 08:13:26 -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 S1727963AbgDHOE2 (ORCPT + 99 others); Wed, 8 Apr 2020 10:04:28 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:53758 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727226AbgDHOE2 (ORCPT ); Wed, 8 Apr 2020 10:04:28 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: ezequiel) with ESMTPSA id 9024929117E Message-ID: Subject: Re: [PATCH v8 4/5] media: rkvdec: Add the rkvdec driver From: Ezequiel Garcia To: Nicolas Dufresne Cc: DVB_Linux_Media , "open list:ARM/Rockchip SoC..." , Linux Kernel Mailing List , Tomasz Figa , kernel@collabora.com, Jonas Karlman , Heiko Stuebner , Hans Verkuil , Alexandre Courbot , Jeffrey Kardatzke , Boris Brezillon Date: Wed, 08 Apr 2020 11:04:10 -0300 In-Reply-To: References: <20200403221345.16702-1-ezequiel@collabora.com> <20200403221345.16702-5-ezequiel@collabora.com> <5c417620e1baeed7ec4ac750ab481366df2aa590.camel@collabora.com> Organization: Collabora Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.0-1 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 On Tue, 2020-04-07 at 15:36 -0400, Nicolas Dufresne wrote: > Le mardi 07 avril 2020 à 11:35 -0300, Ezequiel Garcia a écrit : > > On Mon, 2020-04-06 at 16:27 -0400, Nicolas Dufresne wrote: > > > Le ven. 3 avr. 2020 à 18:14, Ezequiel Garcia a écrit : > > > > From: Boris Brezillon > > > > > > > > The rockchip vdec block is a stateless decoder that's able to decode > > > > H264, HEVC and VP9 content. This commit adds the core infrastructure > > > > and the H264 backend. Support for VP9 and HEVS will be added later on. > > > > > > > > Signed-off-by: Boris Brezillon > > > > Signed-off-by: Ezequiel Garcia > > > > > > Sorry for the late feedback (got a comment lower) ... > > > > > > Tested-by: Nicolas Dufresne > > > > > > > Nice, thank you. > > > > > > -- > > > > v8: > > > > * Fix kfree and style changes, as suggested by Andriy. > > > > v7: > > > > * hverkuil-cisco@xs4all.nl: replaced VFL_TYPE_GRABBER by _VIDEO > > > > * Use macros and ARRAY_SIZE instead of magic numbers, > > > > as suggested by Mauro. > > > > * Renamed M_N macro, suggested by Mauro. > > > > * Use v4l2_m2m_buf_done_and_job_finish. > > > > * Set buffers' zeroth plane payload in .buf_prepare > > > > * Refactor try/s_fmt for spec compliance. > > > > --- > > > > MAINTAINERS | 7 + > > > > drivers/staging/media/Kconfig | 2 + > > > > drivers/staging/media/Makefile | 1 + > > > > drivers/staging/media/rkvdec/Kconfig | 15 + > > > > drivers/staging/media/rkvdec/Makefile | 3 + > > > > drivers/staging/media/rkvdec/TODO | 11 + > > > > drivers/staging/media/rkvdec/rkvdec-h264.c | 1156 ++++++++++++++++++++ > > > > drivers/staging/media/rkvdec/rkvdec-regs.h | 223 ++++ > > > > drivers/staging/media/rkvdec/rkvdec.c | 1103 +++++++++++++++++++ > > > > drivers/staging/media/rkvdec/rkvdec.h | 121 ++ > > > > 10 files changed, 2642 insertions(+) > > > > create mode 100644 drivers/staging/media/rkvdec/Kconfig > > > > create mode 100644 drivers/staging/media/rkvdec/Makefile > > > > create mode 100644 drivers/staging/media/rkvdec/TODO > > > > create mode 100644 drivers/staging/media/rkvdec/rkvdec-h264.c > > > > create mode 100644 drivers/staging/media/rkvdec/rkvdec-regs.h > > > > create mode 100644 drivers/staging/media/rkvdec/rkvdec.c > > > > create mode 100644 drivers/staging/media/rkvdec/rkvdec.h > > > > > > [..] > > > > + > > > > +static void set_ps_field(u32 *buf, struct rkvdec_ps_field field, u32 value) > > > > +{ > > > > + u8 bit = field.offset % 32, word = field.offset / 32; > > > > + u64 mask = GENMASK_ULL(bit + field.len - 1, bit); > > > > + u64 val = ((u64)value << bit) & mask; > > > > + > > > > + buf[word] &= ~mask; > > > > + buf[word] |= val; > > > > + if (bit + field.len > 32) { > > > > + buf[word + 1] &= ~(mask >> 32); > > > > + buf[word + 1] |= val >> 32; > > > > + } > > > > +} > > > > + > > > > +static void assemble_hw_pps(struct rkvdec_ctx *ctx, > > > > + struct rkvdec_h264_run *run) > > > > +{ > > > > + struct rkvdec_h264_ctx *h264_ctx = ctx->priv; > > > > + const struct v4l2_ctrl_h264_sps *sps = run->sps; > > > > + const struct v4l2_ctrl_h264_pps *pps = run->pps; > > > > + const struct v4l2_ctrl_h264_decode_params *dec_params = run->decode_params; > > > > + const struct v4l2_h264_dpb_entry *dpb = dec_params->dpb; > > > > + struct rkvdec_h264_priv_tbl *priv_tbl = h264_ctx->priv_tbl.cpu; > > > > + struct rkvdec_sps_pps_packet *hw_ps; > > > > + dma_addr_t scaling_list_address; > > > > + u32 scaling_distance; > > > > + u32 i; > > > > + > > > > + /* > > > > + * HW read the SPS/PPS information from PPS packet index by PPS id. > > > > + * offset from the base can be calculated by PPS_id * 32 (size per PPS > > > > + * packet unit). so the driver copy SPS/PPS information to the exact PPS > > > > + * packet unit for HW accessing. > > > > + */ > > > > + hw_ps = &priv_tbl->param_set[pps->pic_parameter_set_id]; > > > > + memset(hw_ps, 0, sizeof(*hw_ps)); > > > > + > > > > +#define WRITE_PPS(value, field) set_ps_field(hw_ps->info, field, value) > > > > + /* write sps */ > > > > + WRITE_PPS(0xf, SEQ_PARAMETER_SET_ID); > > > > + WRITE_PPS(0xff, PROFILE_IDC); > > > > + WRITE_PPS(1, CONSTRAINT_SET3_FLAG); > > > > > > At first I found that part rather interesting, but I see this > > > hardcoding matches what Rockchip do. > > > > > > https://github.com/rockchip-linux/mpp/blob/release/mpp/hal/rkdec/h264d/hal_h264d_rkv_reg.c#L266 > > > > > > > + WRITE_PPS(sps->chroma_format_idc, CHROMA_FORMAT_IDC); > > > > > > But here's it's not so great. This driver does not implement any kind > > > of validation. In fact, if I pass 3 > > > here (YCbCr 4:4:4) it will accept it, and kind of decode some frames, > > > but eventually with crash and > > > reboot is needed. We should (as defined in the Statelss CODEC spec) > > > validate the SPS and refuse if > > > an unsupported profile idc, chroma idc, luma/chroma depth or coded > > > size is requested. > > > > Perhaps we could validate that at request_validate time, > > or maybe ops.try_ctrl is better. > > > > > > > > > Validating the > > > S_FMT is not sufficient as one can trick the driver in allocating > > > buffers that are too small. > > > > > > > I am not sure I follow you: how do you think the driver > > can be tricked like this? > > What I see is that there is no cross validation between the SPS > register configuration and the frame allocations done through S_FMT. So > if I cheat in S_FMT, and then pass an SPS that is larger then > announced, the HW could potentially overrun buffers. That entirely > depends on how much robustness there is in the HW implementation iself > (and if we have a register to pass the buffer size). > > This is of course a gut feeling, I haven't found time to test this yet, > but it came to my mind after I notice that passing a 4:4:4 choma_idc > stream causes driver failure (no visible memory corruption or overrun > though, the driver just stops working). So the resulting issues might > not be that bad, but you endup loosing the decoder. > Note that this driver (as well as Hantro) programs the hardware using the negotiated resolution, and ignores what the SPS says about it. It shouldn't be possible to trick the driver this way. OTOH, both drivers should have additional checks for other SPS fields such as chroma_format_idc and luma_bit_depth, as you pointed out. I'll add this to my TODO list. I think it's doable as follow-up patches. Thank, Ezequiel > > > What I suspect is that we need to be careful with this HW, as it seems > > > to be a bit half backed, which > > > means it might be supporting more features then supported by the TRM > > > or reference code, and we > > > must disable this with software. > > > > > > (p.s. I can provide a stream to reproduce the 4:4:4 driver failure) > > > > > > > Thanks, > > Ezequiel > > > >