From patchwork Sat Mar 17 15:28:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 10290871 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A7990601BE for ; Sat, 17 Mar 2018 15:30:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97BCD28F75 for ; Sat, 17 Mar 2018 15:30:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8906929118; Sat, 17 Mar 2018 15:30:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23CDD28F75 for ; Sat, 17 Mar 2018 15:30:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753674AbeCQP3t (ORCPT ); Sat, 17 Mar 2018 11:29:49 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:44203 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752662AbeCQP2e (ORCPT ); Sat, 17 Mar 2018 11:28:34 -0400 Received: by mail-lf0-f68.google.com with SMTP id g203-v6so5033467lfg.11; Sat, 17 Mar 2018 08:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Zag04GIuCD8rceL13jPvgnGk1DziElqYsz+jTted3y8=; b=c2IP2BN1ff+EI75Dlwb4rVsoTL37zxZ+sTCAFVqjGFnlpbblnYwkZ7jqebVMwaEhTm 967JO2xxb5hW/v7+Ggq1atSZFctVx8rkN4tHpyt8kt/4sdsTvl3ERp65VCH/T5r5cvOV lUUaNNnnqLrKZftYLHppNYFkj/VeRq/JqZfYqcHrvdM2Qitiv6UDVxuss7oMR7MVZlsy z505yArrImknJdIE4f+bosNq6DGAGowhEW0PWZIdd1KXYVKyteb7J35+L2Rjmc2bz4WW yhGnMp9w59gTYQIdhPRCJomZeg4032RG3Q/TgLFJQUN801JQdaxKPmM7Eq5pRq/k3tbP 1Gjg== 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:in-reply-to:references; bh=Zag04GIuCD8rceL13jPvgnGk1DziElqYsz+jTted3y8=; b=o9iJoLi9b6AsK/UQ7lKh9XblPuX+qQa9Eq/r7hLkGgExbLECe+oD8a/94/Yn+k0Yb0 0gDheDJPFlTFAk5h6417rga5NJoCR1rtZw4DL4ka4vgSJektOu9M7VKYYtDDu1t5Wr+x MvBZZ2BcvY7xWh6TN1f0tr+tiYPZhBzR28vr6I+9X6e0kyHayq0kVYXFRAOQPCqBlNpw 1Oe/QhTqU9WCosbfLYJusPYczEqko5DTiImDjui6nWoXwuBRwXNm0OYFqIoG5JrbWBOS F7wkI9KLGoXAdCGDHBWyN9RKomFoXE/xQ2B4ylhtXFpUI+UgzT+Pn4Gxg8P/pRm5dtz1 1AJg== X-Gm-Message-State: AElRT7EAoIPtnrAxnx+MPyCSYEhUOMNQAivmbtFohR3hqhX38wopyJDS WC9A0fO4NHUZkFb1qTMdmDA= X-Google-Smtp-Source: AG47ELsxZog7nc+oj9l0zJwvEf6PsBxOwUQd4U+cpespNubF15J5foN2O4BWUqiCxQNTgw7WsmKcvQ== X-Received: by 10.46.144.208 with SMTP id o16mr3893594ljg.107.1521300512870; Sat, 17 Mar 2018 08:28:32 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-55-234.pppoe.spdop.ru. [109.252.55.234]) by smtp.gmail.com with ESMTPSA id a142-v6sm2388276lfb.11.2018.03.17.08.28.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 08:28:32 -0700 (PDT) From: Dmitry Osipenko To: Mauro Carvalho Chehab , Hans Verkuil Cc: Greg Kroah-Hartman , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/5] media: staging: tegra-vde: Align bitstream size to 16K Date: Sat, 17 Mar 2018 18:28:11 +0300 Message-Id: <8b159c6ccf8ea2e052222ffc498cc9f782ac8d49.1521300358.git.digetx@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I've noticed that decoding fails sometime if size of bitstream buffer isn't aligned to 16K, probably because HW fetches data from memory in a 16K granularity and if the last chunk of data isn't aligned, HW reads garbage data beyond the dmabuf and tries to parse it. Signed-off-by: Dmitry Osipenko --- drivers/staging/media/tegra-vde/tegra-vde.c | 40 ++++++++++++----------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/drivers/staging/media/tegra-vde/tegra-vde.c b/drivers/staging/media/tegra-vde/tegra-vde.c index c47659e96089..c2ff2071b23c 100644 --- a/drivers/staging/media/tegra-vde/tegra-vde.c +++ b/drivers/staging/media/tegra-vde/tegra-vde.c @@ -440,7 +440,7 @@ static int tegra_vde_setup_hw_context(struct tegra_vde *vde, VDE_WR(value, vde->sxe + 0x4C); value = 0x03800000; - value |= min_t(size_t, bitstream_data_size, SZ_1M); + value |= bitstream_data_size & GENMASK(19, 15); VDE_WR(value, vde->sxe + 0x68); @@ -522,7 +522,8 @@ static void tegra_vde_detach_and_put_dmabuf(struct dma_buf_attachment *a, static int tegra_vde_attach_dmabuf(struct device *dev, int fd, unsigned long offset, - unsigned int min_size, + size_t min_size, + size_t align_size, struct dma_buf_attachment **a, dma_addr_t *addr, struct sg_table **s, @@ -540,9 +541,16 @@ static int tegra_vde_attach_dmabuf(struct device *dev, return PTR_ERR(dmabuf); } + if (dmabuf->size & (align_size - 1)) { + dev_err(dev, "Unaligned dmabuf 0x%zX, " + "should be aligned to 0x%zX\n", + dmabuf->size, align_size); + return -EINVAL; + } + if ((u64)offset + min_size > dmabuf->size) { dev_err(dev, "Too small dmabuf size %zu @0x%lX, " - "should be at least %d\n", + "should be at least %zu\n", dmabuf->size, offset, min_size); return -EINVAL; } @@ -596,7 +604,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, int err; err = tegra_vde_attach_dmabuf(dev, src->y_fd, - src->y_offset, csize * 4, + src->y_offset, csize * 4, SZ_256, &frame->y_dmabuf_attachment, &frame->y_addr, &frame->y_sgt, @@ -605,7 +613,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, return err; err = tegra_vde_attach_dmabuf(dev, src->cb_fd, - src->cb_offset, csize, + src->cb_offset, csize, SZ_256, &frame->cb_dmabuf_attachment, &frame->cb_addr, &frame->cb_sgt, @@ -614,7 +622,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, goto err_release_y; err = tegra_vde_attach_dmabuf(dev, src->cr_fd, - src->cr_offset, csize, + src->cr_offset, csize, SZ_256, &frame->cr_dmabuf_attachment, &frame->cr_addr, &frame->cr_sgt, @@ -628,7 +636,7 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, } err = tegra_vde_attach_dmabuf(dev, src->aux_fd, - src->aux_offset, csize, + src->aux_offset, csize, SZ_256, &frame->aux_dmabuf_attachment, &frame->aux_addr, &frame->aux_sgt, @@ -677,21 +685,6 @@ static int tegra_vde_validate_frame(struct device *dev, return -EINVAL; } - if (frame->y_offset & 0xFF) { - dev_err(dev, "Bad y_offset 0x%X\n", frame->y_offset); - return -EINVAL; - } - - if (frame->cb_offset & 0xFF) { - dev_err(dev, "Bad cb_offset 0x%X\n", frame->cb_offset); - return -EINVAL; - } - - if (frame->cr_offset & 0xFF) { - dev_err(dev, "Bad cr_offset 0x%X\n", frame->cr_offset); - return -EINVAL; - } - return 0; } @@ -792,7 +785,8 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, return ret; ret = tegra_vde_attach_dmabuf(dev, ctx.bitstream_data_fd, - ctx.bitstream_data_offset, 0, + ctx.bitstream_data_offset, + SZ_16K, SZ_16K, &bitstream_data_dmabuf_attachment, &bitstream_data_addr, &bitstream_sgt,