Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1541407pxb; Tue, 8 Feb 2022 21:39:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzE++qqrRGAGCktoDcOFIEwBk7VTLl75wzisPhS8MonotKK5I2GVqTd10RF0LKwysDReBNA X-Received: by 2002:a65:4c08:: with SMTP id u8mr651513pgq.90.1644385192316; Tue, 08 Feb 2022 21:39:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644385192; cv=none; d=google.com; s=arc-20160816; b=K87qgaQ3FIg+ENMIlr37pTl1MeVo09OHOPjCk3FoUD75sZVYyLGJrtIrG4Dr7ymKIV nTAMRPEZJO6OqxodEpSdLn64eonzB5LP6iUlAIui6bMiuZWpjWT3eElj7+slYbE9/rqO UxbLqCf1+IDyei7IJOxNj93beEicu3F2aPS222Y8liUQ861IN8bpWUEGA59F811pQCGa T/2xaF9SLhFsyaq6qq9XM2R5oN/0ue25007FVLEx5S2mqhVj2ae0Gw5BwY31FLxzH4ER r6xX79zHf2106aUHGpuhal5MN77F6qvBYnym4ABAVKiqmmZNHctzbwhoiMqvHB3pvk9p hecg== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=pexdXtzpLVLXFFSXXakha4YY8Wteyz3B7A3aqFuhNRE=; b=E8C7/cy91QteDWDgmcah1CMfsuQ8+e+IxSnCI2qMmSflSfahvPor+YK8MwNVAk+3u0 DnefbOHsnJ66u5GkmV3fwz9yxs558gE+gLIVGVbvUVaiYsoGH+hjKcH+BnJh3NxHoN/a feEPVMgxwqAS7ehePv0QF/fu09PC3/VhCp1RxDRfR+mlXyz/essIvgx4LosmFfF+USah H0M0x6B0xmlLEXXEn7Bv8+8WUE76uf+NT+n7x/PSjXadJnNmRezb2hDqeemA/R6Jwdbh jOaLGM5fvpigNUrrgwSYprYZk+nooaUwBkpXXHBPSSwGsayi6Hq89y+irdDecNL2nqDG wbBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MPUrc+p0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h23si14943455pgb.402.2022.02.08.21.39.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 21:39:52 -0800 (PST) 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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MPUrc+p0; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B7C7C0364A2; Tue, 8 Feb 2022 21:37:19 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382515AbiBGL3U (ORCPT + 99 others); Mon, 7 Feb 2022 06:29:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383456AbiBGLWb (ORCPT ); Mon, 7 Feb 2022 06:22:31 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91AE7C043181; Mon, 7 Feb 2022 03:22:30 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 4E7F5B81028; Mon, 7 Feb 2022 11:22:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 962DBC004E1; Mon, 7 Feb 2022 11:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232948; bh=QP1HDIGI0Be4fyhFaed9ZyP3A+9v1iuwVzIVMxGZcVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MPUrc+p0jivb4MwTAeJc1qp5unB1R2M/uOgCeAl/BgokpCA8X1MkrHtJp1uDDQidK ojaR0LuESs4rqs3a5QZ/oXvmveAZUFeG3e8tJP0eP1059eUXSmB32gA4WPhlmBp3vU 45wbBOjZUGAfrN7RnLjx2KnSKm1zEq6gFGMZN2qc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Camel Guo , Jakub Kicinski Subject: [PATCH 5.10 42/74] net: stmmac: dump gmac4 DMA registers correctly Date: Mon, 7 Feb 2022 12:06:40 +0100 Message-Id: <20220207103758.603272932@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.232676988@linuxfoundation.org> References: <20220207103757.232676988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Camel Guo commit 7af037c39b600bac2c716dd1228e8ddbe149573f upstream. Unlike gmac100, gmac1000, gmac4 has 27 DMA registers and they are located at DMA_CHAN_BASE_ADDR (0x1100). In order for ethtool to dump gmac4 DMA registers correctly, this commit checks if a net_device has gmac4 and uses different logic to dump its DMA registers. This fixes the following KASAN warning, which can normally be triggered by a command similar like "ethtool -d eth0": BUG: KASAN: vmalloc-out-of-bounds in dwmac4_dump_dma_regs+0x6d4/0xb30 Write of size 4 at addr ffffffc010177100 by task ethtool/1839 kasan_report+0x200/0x21c __asan_report_store4_noabort+0x34/0x60 dwmac4_dump_dma_regs+0x6d4/0xb30 stmmac_ethtool_gregs+0x110/0x204 ethtool_get_regs+0x200/0x4b0 dev_ethtool+0x1dac/0x3800 dev_ioctl+0x7c0/0xb50 sock_ioctl+0x298/0x6c4 ... Fixes: fbf68229ffe7 ("net: stmmac: unify registers dumps methods") Signed-off-by: Camel Guo Link: https://lore.kernel.org/r/20220131083841.3346801-1-camel.guo@axis.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac_dma.h @@ -130,6 +130,7 @@ #define NUM_DWMAC100_DMA_REGS 9 #define NUM_DWMAC1000_DMA_REGS 23 +#define NUM_DWMAC4_DMA_REGS 27 void dwmac_enable_dma_transmission(void __iomem *ioaddr); void dwmac_enable_dma_irq(void __iomem *ioaddr, u32 chan, bool rx, bool tx); --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -21,10 +21,18 @@ #include "dwxgmac2.h" #define REG_SPACE_SIZE 0x1060 +#define GMAC4_REG_SPACE_SIZE 0x116C #define MAC100_ETHTOOL_NAME "st_mac100" #define GMAC_ETHTOOL_NAME "st_gmac" #define XGMAC_ETHTOOL_NAME "st_xgmac" +/* Same as DMA_CHAN_BASE_ADDR defined in dwmac4_dma.h + * + * It is here because dwmac_dma.h and dwmac4_dam.h can not be included at the + * same time due to the conflicting macro names. + */ +#define GMAC4_DMA_CHAN_BASE_ADDR 0x00001100 + #define ETHTOOL_DMA_OFFSET 55 struct stmmac_stats { @@ -413,6 +421,8 @@ static int stmmac_ethtool_get_regs_len(s if (priv->plat->has_xgmac) return XGMAC_REGSIZE * 4; + else if (priv->plat->has_gmac4) + return GMAC4_REG_SPACE_SIZE; return REG_SPACE_SIZE; } @@ -425,8 +435,13 @@ static void stmmac_ethtool_gregs(struct stmmac_dump_mac_regs(priv, priv->hw, reg_space); stmmac_dump_dma_regs(priv, priv->ioaddr, reg_space); - if (!priv->plat->has_xgmac) { - /* Copy DMA registers to where ethtool expects them */ + /* Copy DMA registers to where ethtool expects them */ + if (priv->plat->has_gmac4) { + /* GMAC4 dumps its DMA registers at its DMA_CHAN_BASE_ADDR */ + memcpy(®_space[ETHTOOL_DMA_OFFSET], + ®_space[GMAC4_DMA_CHAN_BASE_ADDR / 4], + NUM_DWMAC4_DMA_REGS * 4); + } else if (!priv->plat->has_xgmac) { memcpy(®_space[ETHTOOL_DMA_OFFSET], ®_space[DMA_BUS_MODE / 4], NUM_DWMAC1000_DMA_REGS * 4);