Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp518586pxw; Fri, 8 Apr 2022 13:36:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwO54J9zGWS3g42CuNs5SdjjjiaPnpqZyA/nC66edcsJKuaBlPHWKh0nJHY9hHFgcmRxhKM X-Received: by 2002:a63:2d47:0:b0:399:53e3:5b4c with SMTP id t68-20020a632d47000000b0039953e35b4cmr17170320pgt.165.1649450203487; Fri, 08 Apr 2022 13:36:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649450203; cv=none; d=google.com; s=arc-20160816; b=drgvRY+NEI1ju0fZQNtqWFmPgLsYZR0K0dGecrJ4NesMWslMci7IabNzq64TspHwvm 3PM4339UlZV3DKMeG5rqsOjcRrbjUf220wFrOMpgzPlkOvLpcp6j1L1MrZa2nCHXe2hQ JWKXwQBAB10e998AYwUzjyi38PUvm+i7+oiUl6tdKFPJMfM6WuJ/BgwTOui+1nUxMsRP /HWp6KdKPcuyCHHSVTxjWCKk++V6tepbb2zVH07PvoEzAzR0CcDSnrg71SBujuNrFBkI F/2YznTFXNGC1/fir00Gcop1q7Urd0WgHFw5+cL4/M38I4znwAeulDwwXGBsLUI/4Ff/ KJ6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ldIWKr4mW3da5Fg6rpgSNgwd6PBnMgGVZDBhPs53YBE=; b=zxTOHlg92fehDyoU9qxF0I1uFpQg8C4EbL9/iN23BLwoBSYBwPIhAEOV+fmBauRA+T SerlDMjNswZ92w8wAOrKYqx74ZmsJlenmr9DgbBiCOtx+VlYQ2KSkjEa0LqJWsCs0smf lUszN7euaf+ef8/v0C9fFut3ov2AJMguUgzr3TbBC1g1NAGDNcZwahHcaPJBNT9XtksT 8r/+FcprfBztJPurKaMVg/6foNkFh7pT6uGyWZ0O6PApkF2222nM33JtivfAp0A2ncmo 1sVFcP5rD4Z6SXNI8esx+aCILNwWHdJqR++MyvJGfCHbI+Ci5MDymSP886Ealty3aguN lFJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JvU4Z2WM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t71-20020a63784a000000b00381cbf13898si2307598pgc.373.2022.04.08.13.36.27; Fri, 08 Apr 2022 13:36:43 -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=@kernel.org header.s=k20201202 header.b=JvU4Z2WM; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238250AbiDHRlZ (ORCPT + 99 others); Fri, 8 Apr 2022 13:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238241AbiDHRlX (ORCPT ); Fri, 8 Apr 2022 13:41:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3ACB7DE22; Fri, 8 Apr 2022 10:39:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 50A70621AF; Fri, 8 Apr 2022 17:39:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3EC5C385A3; Fri, 8 Apr 2022 17:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1649439558; bh=fjDvDzKQXH+2sFBYV36rZ198m6vn8t2q+ypSTCZ4aME=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JvU4Z2WMU3WoPbly6wMJrkt5PXY/SJ+eZIPSfgdrwg4qTAediv2I9luAlRDxhNIcv jv0LPCiKKQ+/17WNyoyioViRu36JIF+yOCN4tch7QW1u+OztYBF28hgjClKUFgwtPZ 9KsvkE9Gu9rBQHTvLrOs2MU4QzKF8EBh7aAyFjK1rKAVudvDiYgHi78P1RT2BkFBlq 1rfq/yD/hwiaJZ1qbcm54CL+Ui8I8WJYG/NcHZgnWbOp3peJ7M7NFp3Yd3yQZmEGFA y0dHFQG+tdwxf2ZvTZ0YJo0wjC5iPmGeWO02uS5JrpA5kt4i1Bj9h0pW1tI5hPlLpG 2+DQvByP+Sa4g== Date: Fri, 8 Apr 2022 23:09:14 +0530 From: Vinod Koul To: Kevin Groeneveld Cc: Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Lucas Stach , Robin Gong , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] dmaengine: imx-sdma: fix regression with uart scripts Message-ID: References: <20220406224809.29197-1-kgroeneveld@lenbrook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220406224809.29197-1-kgroeneveld@lenbrook.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 06-04-22, 18:48, Kevin Groeneveld wrote: > Commit b98ce2f4e32b ("dmaengine: imx-sdma: add uart rom script") broke > uart rx on imx5 when using sdma firmware from older Freescale 2.6.35 > kernel. In this case reading addr->uartXX_2_mcu_addr was going out of > bounds of the firmware memory and corrupting the uart script addresses. > > Simply adding a bounds check before accessing addr->uartXX_2_mcu_addr > does not work as the uartXX_2_mcu_addr members are now beyond the size > of the older firmware and the uart addresses would never be populated > in that case. There are other ways to fix this but overall the logic > seems clearer to me to revert the uartXX_2_mcu_ram_addr structure > entries back to uartXX_2_mcu_addr, change the newer entries to > uartXX_2_mcu_rom_addr and update the logic accordingly. 1. Patch title should reflect the change introduced, so the title is not apt, pls revise 2. Is this in response to rmk's report, if so, please add reported-by 3. Lastly, I would like to see some tested by for this patch.. > > Fixes: b98ce2f4e32b ("dmaengine: imx-sdma: add uart rom script") cc: stable ? > Signed-off-by: Kevin Groeneveld > --- > drivers/dma/imx-sdma.c | 28 ++++++++++++++-------------- > 1 file changed, 14 insertions(+), 14 deletions(-) > > diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c > index 70c0aa931ddf..b708d029b6e9 100644 > --- a/drivers/dma/imx-sdma.c > +++ b/drivers/dma/imx-sdma.c > @@ -198,12 +198,12 @@ struct sdma_script_start_addrs { > s32 per_2_firi_addr; > s32 mcu_2_firi_addr; > s32 uart_2_per_addr; > - s32 uart_2_mcu_ram_addr; > + s32 uart_2_mcu_addr; > s32 per_2_app_addr; > s32 mcu_2_app_addr; > s32 per_2_per_addr; > s32 uartsh_2_per_addr; > - s32 uartsh_2_mcu_ram_addr; > + s32 uartsh_2_mcu_addr; > s32 per_2_shp_addr; > s32 mcu_2_shp_addr; > s32 ata_2_mcu_addr; > @@ -232,8 +232,8 @@ struct sdma_script_start_addrs { > s32 mcu_2_ecspi_addr; > s32 mcu_2_sai_addr; > s32 sai_2_mcu_addr; > - s32 uart_2_mcu_addr; > - s32 uartsh_2_mcu_addr; > + s32 uart_2_mcu_rom_addr; > + s32 uartsh_2_mcu_rom_addr; > /* End of v3 array */ > s32 mcu_2_zqspi_addr; > /* End of v4 array */ > @@ -1796,17 +1796,17 @@ static void sdma_add_scripts(struct sdma_engine *sdma, > saddr_arr[i] = addr_arr[i]; > > /* > - * get uart_2_mcu_addr/uartsh_2_mcu_addr rom script specially because > - * they are now replaced by uart_2_mcu_ram_addr/uartsh_2_mcu_ram_addr > - * to be compatible with legacy freescale/nxp sdma firmware, and they > - * are located in the bottom part of sdma_script_start_addrs which are > - * beyond the SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1. > + * For compatibility with NXP internal legacy kernel before 4.19 which > + * is based on uart ram script and mainline kernel based on uart rom > + * script, both uart ram/rom scripts are present in newer sdma > + * firmware. Use the rom versions if they are present (V3 or newer). > */ > - if (addr->uart_2_mcu_addr) > - sdma->script_addrs->uart_2_mcu_addr = addr->uart_2_mcu_addr; > - if (addr->uartsh_2_mcu_addr) > - sdma->script_addrs->uartsh_2_mcu_addr = addr->uartsh_2_mcu_addr; > - > + if (sdma->script_number >= SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V3) { > + if (addr->uart_2_mcu_rom_addr) > + sdma->script_addrs->uart_2_mcu_addr = addr->uart_2_mcu_rom_addr; > + if (addr->uartsh_2_mcu_rom_addr) > + sdma->script_addrs->uartsh_2_mcu_addr = addr->uartsh_2_mcu_rom_addr; > + } > } > > static void sdma_load_firmware(const struct firmware *fw, void *context) > -- > 2.17.1 -- ~Vinod