Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1687396pxb; Wed, 9 Feb 2022 02:12:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzj7LnNHF5vnjTvw6Wri9KxlgmPPoSRbsbX2xFdk/PmInr1jxMh2rnBEedGiOt4p/eUJFWB X-Received: by 2002:a63:81c8:: with SMTP id t191mr1285670pgd.321.1644401540123; Wed, 09 Feb 2022 02:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644401540; cv=none; d=google.com; s=arc-20160816; b=ME9nxgVBSOzLKBj9Xv/ngzOIwQg4Z1LkuqYOi/pi6fa+BjW+fF5oMcztqXw+wgbObW Wl/++En1GMLKbQm+MZCCU9AUagccqy8qjt/m6O+OOKS01z8ThmjdgbQp1AIXIesH9Sw4 mktwNo+ziSbIYIbrRQjm3iwESSWbXcqdSJuEtwKuTBcZdFaHLqy/wnx6CvUxgCqpaLka QmhCaGAilgTdWy6TtZSg+AubVkdbpFs1S3qxEDYnky5hhHh0fMUxQN8y2Cf0zjEY28KV uR7pDHbzqzntcH2Q1CW8Eu8EovDGdNdfeVyQQW4F1q8OiUhi+9gOlFvD3sv0qAIjSfb5 KZLw== 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=xezb4DxrqSddjfXleAmKAC5AswqMoygL04oPutL4Sug=; b=WpZ0xwKupX+aHx32kgoee4Enzw26RtMCct9ugptug8Swl8RclzuS5BMSpdmoyhK9mB bM408HSQh2si5Sr9dnFa30je3nosNjTK9ceSNDz5s0uQHp99WOWGpWTx3h0owG1HjX4W iPx/EysdI3ab7dBfgg3ff9hoNq6QFgV2WMQITd8xF4tisbOt0tO0lHOiOolA6G/bnhbG KnKm3885Vbaq+j5rXn8NNNHuSIlwJFG36AhaXWj/MHz0iE1fbEJnRL6r8XP+rgt7Zr/D N2bc3swwbchJMGh9qY6IV0Ucz7IM7iigLxicWRuaRDlhDLfYe/UAtStzfJKliMRa1rAM oY7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y27jjh47; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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. [23.128.96.19]) by mx.google.com with ESMTPS id kk17si5805608pjb.176.2022.02.09.02.12.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 02:12:20 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Y27jjh47; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 446C8E088FB3; Wed, 9 Feb 2022 01:15:50 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1387927AbiBGLmQ (ORCPT + 99 others); Mon, 7 Feb 2022 06:42:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1384616AbiBGL31 (ORCPT ); Mon, 7 Feb 2022 06:29:27 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7DBCC02B5DC; Mon, 7 Feb 2022 03:27:37 -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 095BCB811AF; Mon, 7 Feb 2022 11:27:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DD8AC340F0; Mon, 7 Feb 2022 11:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644233254; bh=EtbOZiAqtWbT4t6/B/vsUfgMMXkYyFMWs8SFTUx3QU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y27jjh47+CUty3MmNRBpQYy+RFfSBWzegOX3K4GVYcsgzCtgNjnuZGe/J75zqcYau WHnHaTRGX5uA+fT2gHQX22udortkTOae5d3QMg6HVR/PRk7hdmZRg1aP4yTa3f22WA 4IQch0bNJuL7/snPAx44rhM49IAGSFZIFqHLODhM= 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.15 066/110] net: stmmac: dump gmac4 DMA registers correctly Date: Mon, 7 Feb 2022 12:06:39 +0100 Message-Id: <20220207103804.510645202@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103802.280120990@linuxfoundation.org> References: <20220207103802.280120990@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 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 @@ -150,6 +150,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 { @@ -435,6 +443,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; } @@ -447,8 +457,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);