Message ID | 20230628054111.8967-1-xiaoyong.lu@mediatek.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8766386vqr; Wed, 28 Jun 2023 01:42:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mCkioyhI+ESYtu0TBtmId3EF/ufGh7xshajYM9wSPaLfuDM12yIBbgmJPGk6wXypUuO6C X-Received: by 2002:a17:906:749a:b0:974:5480:6270 with SMTP id e26-20020a170906749a00b0097454806270mr3247779ejl.0.1687941735155; Wed, 28 Jun 2023 01:42:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687941735; cv=none; d=google.com; s=arc-20160816; b=uuTMLnaRSD7o5Qi4F2E7jj2oW5fnTHc1t/ttbs6QkXiVlNCwFGCyiF/9hrBH8MEtn+ oY9jI190eljP/AMT+lRCChWZ9/lnYDUkx+na+98Viep5M3FfWXwCjDJD6H/AUmxdwp6Z v8dFjhxx63BJusENe1AqpY8GoVSJ/pQ0kWJikREM7bjmlEqEhfG2Lch2j+e4fhEdCGP2 /MiumtfPNzQSY6Hg/ImCS66VKhmQ5ULXHRQ/5gNM6r7vbiedAXLET7651uhML2k6sEJt YNt1gyiPTpMYDzp2bWJkY6rXGbaS0vtj3fsVrziG55znwKXbkgm5Dekps/IvjX3ge93T ZavA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zfjx6R+EMpgD1vYrYarvFtRq2IEGDT6k/qkqHHuoJnM=; fh=jn5vo92qDT55/S6UQjwMOp+3xFWqJyTlsFJvFOtuRPo=; b=0Qi7xxRhW1IE+fD8WbGsl8Hdq5pA8Y97SvUeGtIRxiZsqVtzgtTqONT71EOFgywi+8 Vdv0FJ9ylf60OOfhXE8JdFxzmEgEhkqK1LsGPLsAxNkeflUWP1z0yDYHW9KjnZmm0TYF ysP2+3jxYAMpL9WI4zHEHAlqcSLNRufmPldvfKXQEfXHGENIqC5mcE+xSpUNX+Lzcog8 gCSfNBjeY0wtEvIUOtoPvrLsc5g/3n8Qo8mJNrPaBOC/8nD5qwPPVidcZrgK+n7BCetG 7VHIpC1jzcUIQyjGSTpfJxRwcXDufAKxbbi+O1/LkasXoDCLbmugJ9JMBCrM+6owQzlX 2jKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=dVo9yTNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f21-20020a170906561500b00988b290f02esi5522235ejq.592.2023.06.28.01.41.51; Wed, 28 Jun 2023 01:42:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=dVo9yTNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232620AbjF1H7T (ORCPT <rfc822;ivan.orlov0322@gmail.com> + 99 others); Wed, 28 Jun 2023 03:59:19 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:45800 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231899AbjF1H4t (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 28 Jun 2023 03:56:49 -0400 X-UUID: 6ba3b39e157611ee9cb5633481061a41-20230628 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=zfjx6R+EMpgD1vYrYarvFtRq2IEGDT6k/qkqHHuoJnM=; b=dVo9yTNCHeooYKtBZ8b6WYGtHecw4qUKNBg3pMT0i4vdkG8+DH4e7UAobMgI1Apa3NsJqXew+m4lFbEhezRfNH4FMPit6pHcRO7rexFH4y/KdzqXSUE9RFwJs4Lusmf4xaLuU2wzHOunarHQhc/whMMBi2uqzy6ue9Mhk6f8O+M=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.27,REQID:81396fbb-e3f9-4e48-83b4-2eb5c11a3597,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:75 X-CID-INFO: VERSION:1.1.27,REQID:81396fbb-e3f9-4e48-83b4-2eb5c11a3597,IP:0,URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:100,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACT ION:quarantine,TS:75 X-CID-META: VersionHash:01c9525,CLOUDID:8c4b4d0d-26a8-467f-b838-f99719a9c083,B ulkID:230628134126CNQCJ4IB,BulkQuantity:0,Recheck:0,SF:28|17|19|48|38|29,T C:nil,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR,TF_CID_SPAM_SDM,TF_CID_SPAM_ASC,TF_CID_SPAM_FAS, TF_CID_SPAM_FSD,TF_CID_SPAM_ULN X-UUID: 6ba3b39e157611ee9cb5633481061a41-20230628 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from <xiaoyong.lu@mediatek.com>) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1460076881; Wed, 28 Jun 2023 13:41:25 +0800 Received: from mtkmbs11n2.mediatek.inc (172.21.101.187) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Wed, 28 Jun 2023 13:41:23 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Wed, 28 Jun 2023 13:41:22 +0800 From: Xiaoyong Lu <xiaoyong.lu@mediatek.com> To: Yunfei Dong <yunfei.dong@mediatek.com>, Alexandre Courbot <acourbot@chromium.org>, Nicolas Dufresne <nicolas@ndufresne.ca>, Hans Verkuil <hverkuil-cisco@xs4all.nl>, AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>, Benjamin Gaignard <benjamin.gaignard@collabora.com>, Tiffany Lin <tiffany.lin@mediatek.com>, Andrew-CT Chen <andrew-ct.chen@mediatek.com>, Mauro Carvalho Chehab <mchehab@kernel.org>, Rob Herring <robh+dt@kernel.org>, Matthias Brugger <matthias.bgg@gmail.com>, Tomasz Figa <tfiga@google.com> CC: George Sun <george.sun@mediatek.com>, Xiaoyong Lu <xiaoyong.lu@mediatek.com>, Hsin-Yi Wang <hsinyi@chromium.org>, Fritz Koenig <frkoenig@chromium.org>, Daniel Vetter <daniel@ffwll.ch>, dri-devel <dri-devel@lists.freedesktop.org>, Irui Wang <irui.wang@mediatek.com>, Steve Cho <stevecho@chromium.org>, <linux-media@vger.kernel.org>, <devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <linux-arm-kernel@lists.infradead.org>, <linux-mediatek@lists.infradead.org>, <Project_Global_Chrome_Upstream_Group@mediatek.com> Subject: media: mediatek: vcodec: fix AV1 decode fail for 36bit iova Date: Wed, 28 Jun 2023 13:41:11 +0800 Message-ID: <20230628054111.8967-1-xiaoyong.lu@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769935193070370805?= X-GMAIL-MSGID: =?utf-8?q?1769935193070370805?= |
Series |
media: mediatek: vcodec: fix AV1 decode fail for 36bit iova
|
|
Commit Message
Xiaoyong Lu
June 28, 2023, 5:41 a.m. UTC
Decoder hardware will access incorrect iova address when tile buffer is
36bit, leading to iommu fault when hardware access dram data.
Fixes: 2f5d0aef37c6 ("media: mediatek: vcodec: support stateless AV1 decoder")
Signed-off-by: Xiaoyong Lu<xiaoyong.lu@mediatek.com>
---
- Test ok: mt8195 32bit and mt8188 36bit iova.
---
.../platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
Hi, Le mercredi 28 juin 2023 à 13:41 +0800, Xiaoyong Lu a écrit : > Decoder hardware will access incorrect iova address when tile buffer is > 36bit, leading to iommu fault when hardware access dram data. > > Fixes: 2f5d0aef37c6 ("media: mediatek: vcodec: support stateless AV1 decoder") > Signed-off-by: Xiaoyong Lu<xiaoyong.lu@mediatek.com> > --- > - Test ok: mt8195 32bit and mt8188 36bit iova. > --- > .../platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c > index 404a1a23fd40..420222c8a56d 100644 > --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c > +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c > @@ -1658,9 +1658,9 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins > u32 allow_update_cdf = 0; > u32 sb_boundary_x_m1 = 0, sb_boundary_y_m1 = 0; > int tile_info_base; > - u32 tile_buf_pa; > + u64 tile_buf_pa; > u32 *tile_info_buf = instance->tile.va; > - u32 pa = (u32)bs->dma_addr; > + u64 pa = (u64)bs->dma_addr; > > if (uh->disable_cdf_update == 0) > allow_update_cdf = 1; > @@ -1673,7 +1673,8 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins > tile_info_buf[tile_info_base + 0] = (tile_group->tile_size[tile_num] << 3); > tile_buf_pa = pa + tile_group->tile_start_offset[tile_num]; > > - tile_info_buf[tile_info_base + 1] = (tile_buf_pa >> 4) << 4; > + tile_info_buf[tile_info_base + 1] = (unsigned int)(tile_buf_pa >> 4) << 4 + > + ((unsigned int)(tile_buf_pa >> 32) & 0xf); I'm not clear on how this works. In the original code, it was a complicated way to ignore the 4 least significant bits. Something like this would avoid the cast and clarify it: tile_info_buf[tile_info_base + 1] = tile_buf_pa & 0xFFFFFFFFFFFFFF00ull; But in the updated code, if you have 36 bit, you store these 2 bits in the lower part, which was originally cleared. Can you confirm this is exactly what you wanted ? And if so add a comment ? It could also be written has (but this is just me considering this more readable, I also prefer | (or) rather then +, and hates casting): tile_info_buf[tile_info_base + 1] = (tile_buf_pa & 0xFFFFFFFFFFFFFF00ull) | (tile_buf_pa & 0x0000000F00000000ull) >> 32; > tile_info_buf[tile_info_base + 2] = (tile_buf_pa % 16) << 3; Is this the same as ? tile_info_buf[tile_info_base + 2] = (tile_buf_pa & 0x00FFull) << 3; > > > sb_boundary_x_m1 =
Hi Xiaoyong, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20230627] [cannot apply to media-tree/master v6.4 v6.4-rc7 v6.4-rc6 linus/master v6.4] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Xiaoyong-Lu/media-mediatek-vcodec-fix-AV1-decode-fail-for-36bit-iova/20230628-134327 base: next-20230627 patch link: https://lore.kernel.org/r/20230628054111.8967-1-xiaoyong.lu%40mediatek.com patch subject: media: mediatek: vcodec: fix AV1 decode fail for 36bit iova config: arm-allmodconfig (https://download.01.org/0day-ci/archive/20230629/202306291250.o5AmGFiC-lkp@intel.com/config) compiler: arm-linux-gnueabi-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230629/202306291250.o5AmGFiC-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202306291250.o5AmGFiC-lkp@intel.com/ All warnings (new ones prefixed by >>): drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c: In function 'vdec_av1_slice_setup_tile_buffer': >> drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:1676:91: warning: suggest parentheses around '+' inside '<<' [-Wparentheses] 1676 | tile_info_buf[tile_info_base + 1] = (unsigned int)(tile_buf_pa >> 4) << 4 + | ~~^ 1677 | ((unsigned int)(tile_buf_pa >> 32) & 0xf); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Kconfig warnings: (for reference only) WARNING: unmet direct dependencies detected for SM_GCC_8350 Depends on [n]: COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] && (ARM64 || COMPILE_TEST [=n]) Selected by [m]: - SM_VIDEOCC_8350 [=m] && COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] WARNING: unmet direct dependencies detected for SM_GCC_8450 Depends on [n]: COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] && (ARM64 || COMPILE_TEST [=n]) Selected by [m]: - SM_GPUCC_8450 [=m] && COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] - SM_VIDEOCC_8450 [=m] && COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] WARNING: unmet direct dependencies detected for SM_GCC_8550 Depends on [n]: COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] && (ARM64 || COMPILE_TEST [=n]) Selected by [m]: - SM_GPUCC_8550 [=m] && COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] - SM_VIDEOCC_8550 [=m] && COMMON_CLK [=y] && COMMON_CLK_QCOM [=m] vim +1676 drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c 1649 1650 static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *instance, 1651 struct vdec_av1_slice_vsi *vsi, 1652 struct mtk_vcodec_mem *bs) 1653 { 1654 struct vdec_av1_slice_tile_group *tile_group = &instance->tile_group; 1655 struct vdec_av1_slice_uncompressed_header *uh = &vsi->frame.uh; 1656 struct vdec_av1_slice_tile *tile = &uh->tile; 1657 u32 tile_num, tile_row, tile_col; 1658 u32 allow_update_cdf = 0; 1659 u32 sb_boundary_x_m1 = 0, sb_boundary_y_m1 = 0; 1660 int tile_info_base; 1661 u64 tile_buf_pa; 1662 u32 *tile_info_buf = instance->tile.va; 1663 u64 pa = (u64)bs->dma_addr; 1664 1665 if (uh->disable_cdf_update == 0) 1666 allow_update_cdf = 1; 1667 1668 for (tile_num = 0; tile_num < tile_group->num_tiles; tile_num++) { 1669 /* each uint32 takes place of 4 bytes */ 1670 tile_info_base = (AV1_TILE_BUF_SIZE * tile_num) >> 2; 1671 tile_row = tile_num / tile->tile_cols; 1672 tile_col = tile_num % tile->tile_cols; 1673 tile_info_buf[tile_info_base + 0] = (tile_group->tile_size[tile_num] << 3); 1674 tile_buf_pa = pa + tile_group->tile_start_offset[tile_num]; 1675 > 1676 tile_info_buf[tile_info_base + 1] = (unsigned int)(tile_buf_pa >> 4) << 4 + 1677 ((unsigned int)(tile_buf_pa >> 32) & 0xf); 1678 tile_info_buf[tile_info_base + 2] = (tile_buf_pa % 16) << 3; 1679 1680 sb_boundary_x_m1 = 1681 (tile->mi_col_starts[tile_col + 1] - tile->mi_col_starts[tile_col] - 1) & 1682 0x3f; 1683 sb_boundary_y_m1 = 1684 (tile->mi_row_starts[tile_row + 1] - tile->mi_row_starts[tile_row] - 1) & 1685 0x1ff; 1686 1687 tile_info_buf[tile_info_base + 3] = (sb_boundary_y_m1 << 7) | sb_boundary_x_m1; 1688 tile_info_buf[tile_info_base + 4] = ((allow_update_cdf << 18) | (1 << 16)); 1689 1690 if (tile_num == tile->context_update_tile_id && 1691 uh->disable_frame_end_update_cdf == 0) 1692 tile_info_buf[tile_info_base + 4] |= (1 << 17); 1693 1694 mtk_vcodec_debug(instance, "// tile buf %d pos(%dx%d) offset 0x%x\n", 1695 tile_num, tile_row, tile_col, tile_info_base); 1696 mtk_vcodec_debug(instance, "// %08x %08x %08x %08x\n", 1697 tile_info_buf[tile_info_base + 0], 1698 tile_info_buf[tile_info_base + 1], 1699 tile_info_buf[tile_info_base + 2], 1700 tile_info_buf[tile_info_base + 3]); 1701 mtk_vcodec_debug(instance, "// %08x %08x %08x %08x\n", 1702 tile_info_buf[tile_info_base + 4], 1703 tile_info_buf[tile_info_base + 5], 1704 tile_info_buf[tile_info_base + 6], 1705 tile_info_buf[tile_info_base + 7]); 1706 } 1707 } 1708
diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c index 404a1a23fd40..420222c8a56d 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c @@ -1658,9 +1658,9 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins u32 allow_update_cdf = 0; u32 sb_boundary_x_m1 = 0, sb_boundary_y_m1 = 0; int tile_info_base; - u32 tile_buf_pa; + u64 tile_buf_pa; u32 *tile_info_buf = instance->tile.va; - u32 pa = (u32)bs->dma_addr; + u64 pa = (u64)bs->dma_addr; if (uh->disable_cdf_update == 0) allow_update_cdf = 1; @@ -1673,7 +1673,8 @@ static void vdec_av1_slice_setup_tile_buffer(struct vdec_av1_slice_instance *ins tile_info_buf[tile_info_base + 0] = (tile_group->tile_size[tile_num] << 3); tile_buf_pa = pa + tile_group->tile_start_offset[tile_num]; - tile_info_buf[tile_info_base + 1] = (tile_buf_pa >> 4) << 4; + tile_info_buf[tile_info_base + 1] = (unsigned int)(tile_buf_pa >> 4) << 4 + + ((unsigned int)(tile_buf_pa >> 32) & 0xf); tile_info_buf[tile_info_base + 2] = (tile_buf_pa % 16) << 3; sb_boundary_x_m1 =