Received: by 2002:a05:6a10:83d0:0:0:0:0 with SMTP id o16csp52402pxh; Thu, 7 Apr 2022 13:43:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbdn66zTuAaItTnD0ovzckCj3dLy48/n0bXPOJ7nmq8UCfVGDDq0Mf6hqaUbcydjDy6QCn X-Received: by 2002:a17:90b:4acc:b0:1c7:f18:1141 with SMTP id mh12-20020a17090b4acc00b001c70f181141mr17768242pjb.31.1649364193422; Thu, 07 Apr 2022 13:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649364193; cv=none; d=google.com; s=arc-20160816; b=DfqPdBt+ER2fwfBxDUh+ufPBJID0Cm3z8l3Tz9svRAFkLli+brnAPqKnp5Ukku+Oqi L7y02HvC8CLacE4xKwybJBZmzALq3Di+86Xaf3kagP69s2EhW7TgSP87fImSi4AscFHy zS/RdNR6Qa7LCBSw+qivfhY65U0UruDVUX4vbpr3KKCL8Mldxaf+7BzTOlqVFcM+Qx6C 5wJA2AIjFEPARf3ML/pzHEzW0JALT0QnlpjyHv8QAO1lqGVLnWWH5YrnYNHrRXrDKvhN 4StpqFeaCKMES4mM5rjAK7Tl+RhcQCAkWaFL8eMkNbI0jFDMFw2LJU/7DHqKDdIM1g1q 591Q== 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 :user-agent:references:in-reply-to:date:to:from:subject:message-id; bh=wlM2uTH2WMz4Pe4jRhMIkyLQlFFisIpjH7Xekl23HFA=; b=cGhMz0C5MQodUJPYyxtvA9tqMvwkNBtErGQ2Ij0sCrGgUHdBTgQScFBj/gItaVGMSX +H+RnHc6YYfj4PZh2pF1VwTuEpGc2MiQPUlcdisW9Qh1chme6MQjCNm8k6CRMYygJGbm ORII58dPlTSvdLfOGqBE+KaygGqPxSgOvDrv/t2m5DU0sH3sMUSTpLU9AzwAp6bxL6ZV bvV06kf34BNcR30wNMzUSN0UDmjRGzJU7/guG5d9dBdTD1NwmTs6WuHv+DdbHc31uElA lbE1VYDhIYOBLnlTD45kdj30S4VSdWW3wO0LlvhwFGeW32/cNPEotLJqJac1/4W/TsKW WP9A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m3-20020a170902c44300b001549d3bcb48si496708plm.582.2022.04.07.13.43.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 13:43:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9C8863C6503; Thu, 7 Apr 2022 12:52:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244165AbiDGKVL (ORCPT + 99 others); Thu, 7 Apr 2022 06:21:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237328AbiDGKVK (ORCPT ); Thu, 7 Apr 2022 06:21:10 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5EA523E3FF for ; Thu, 7 Apr 2022 03:19:10 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ncPEA-0004DC-QT; Thu, 07 Apr 2022 12:18:58 +0200 Message-ID: <0316d3b81dda8f1de97238483758566becbbb9fc.camel@pengutronix.de> Subject: Re: [PATCH] dmaengine: imx-sdma: fix regression with uart scripts From: Lucas Stach To: Kevin Groeneveld , Vinod Koul , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Robin Gong , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Thu, 07 Apr 2022 12:18:57 +0200 In-Reply-To: <20220406224809.29197-1-kgroeneveld@lenbrook.com> References: <20220406224809.29197-1-kgroeneveld@lenbrook.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Am Mittwoch, dem 06.04.2022 um 18:48 -0400 schrieb Kevin Groeneveld: > 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. > > Fixes: b98ce2f4e32b ("dmaengine: imx-sdma: add uart rom script") > Signed-off-by: Kevin Groeneveld I clearly didn't think about this case when reviewing the breaking change. The solution in this patch looks fine to me. Reviewed-by: Lucas Stach > --- > 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)