From patchwork Fri Apr 12 18:16:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13628229 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91AEC14D70E for ; Fri, 12 Apr 2024 18:16:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712945800; cv=none; b=t9wwek9RfRZxjRjjQebu3V4HlXwN1yvW0HzLXMvZzTAO9ikRDvsnhc/e7f2NDN3Ie6ZOhZwXFGqKHUliMmDROcHae5TTdc27GnIbXNlWPwqIV46y0Xm6EhAz6fC0On9H8/YZ1FzQxdRUk9GL9kAjtT42iM2VnX/qWm9WJ/vIRBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712945800; c=relaxed/simple; bh=SVNaYR3dzHXVQV/G5Ed7sNUY5mYXdizIlHKqrkijVbE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=UJ2xBcuINUl/L0B75LP4KToT8HBggDEau5FvOlp6jVTh03fEW576CyVk9U2bMoD8TSUhEcXS0745NkSiExf+VnyUuQWj03h43M/2zf+fs36+2pHMOxgUblP+1qyYuDoyIdc79B5D7N1igUkkvqX7jxBhL7OtN5wRLdtIuFZ15dA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b=SOGOCTZb; arc=none smtp.client-ip=209.85.219.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="SOGOCTZb" Received: by mail-qv1-f53.google.com with SMTP id 6a1803df08f44-6962e6fbf60so9207466d6.1 for ; Fri, 12 Apr 2024 11:16:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1712945797; x=1713550597; darn=vger.kernel.org; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=e6Yqh55BDJbEAhV39C84P1rDmlh9typ31HrHe4uFSK4=; b=SOGOCTZbra8tu2jbYjVwmWV9QJhDWPJ7MzO5Zx6VZESLwyB0mi/F1CVjxNsD3k2MGh Zms18SPKJACYoskBAmJoZvEuaWyLKzgkJrPPiJ7ZiNYzUczD6K9Kbspw7+a8agsxhjOP OIQup753C7gltVnAgKMUe9pO9HAWqEgxySjAk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712945797; x=1713550597; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=e6Yqh55BDJbEAhV39C84P1rDmlh9typ31HrHe4uFSK4=; b=ns1tBB8s/4EG9Rg+9icubLA3VdvOgno/mzcrOe4aEXM5l48TNyxIvwkJVFQ90vvZ3F hVSCec47lQTJjG4cRNLOFNTq7VJygFuWyHIJnOwhZMa+O3bgPN+qyMkhijaldnztNISU isKf2Yc9Ixr85hGodpdnvN9MOq0oljbruVC+mBW1V2imCNwuISiP0vQ3ntw8vLmVFYXu lkRCCgRjqIJ0T3tjDsjpQEhzM0jQT6CMaekc2106svpHXTO1u1uyZEMSMWranLpxYQWh DH+ibdPJC7enyGGOxej6tUr20i302FvOjwWPJVQyLav96YV5cqA421A8R18H/ENjRlob kmxw== X-Gm-Message-State: AOJu0YzyMNImCZXKbwvv/QOrKUagp+Qgfx04emk1z9o/tKte5MU0ufM8 xrTITUcWz6iXtg81GUVSu2ugTn3hSel/uhPmhOMVpdJmQVwY28kg8zO6tnPmtzcpB926L3WL39P 08BIqOlsMQ3hvtDjEhRdY3FO7TmpRB51lHgIn2k2PdeSffqmlrydcNETsEMgEnv+zYfLiTa0lZT wcgP9hkmrRiG+eHBWOTPuBld6u23H8ngu1/XrI/jU= X-Google-Smtp-Source: AGHT+IEgB2Sddo3XpH1ARQCO/FiveNZkextRNMmMjprfWcjVubFk4cJtu4MxV1xx7FhHl8hVs7rqWw== X-Received: by 2002:a05:6214:888:b0:690:d000:c819 with SMTP id cz8-20020a056214088800b00690d000c819mr3916384qvb.60.1712945797275; Fri, 12 Apr 2024 11:16:37 -0700 (PDT) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id eb18-20020ad44e52000000b0069b57c83f32sm1174202qvb.26.2024.04.12.11.16.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 11:16:36 -0700 (PDT) From: Justin Chen To: netdev@vger.kernel.org Cc: Justin Chen , Florian Fainelli , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , bcm-kernel-feedback-list@broadcom.com (open list:BROADCOM ASP 2.0 ETHERNET DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH net] net: bcmasp: fix memory leak when bringing down if Date: Fri, 12 Apr 2024 11:16:31 -0700 Message-Id: <20240412181631.3488324-1-justin.chen@broadcom.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org When bringing down the TX rings we flush the rings but forget to reclaimed the flushed packets. This lead to a memory leak since we do not free the dma mapped buffers. This also leads to tx control block corruption when bringing down the interface for power management. Fixes: 490cb412007d ("net: bcmasp: Add support for ASP2.0 Ethernet controller") Signed-off-by: Justin Chen Acked-by: Florian Fainelli --- .../net/ethernet/broadcom/asp2/bcmasp_intf.c | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c index 72ea97c5d5d4..82768b0e9026 100644 --- a/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp_intf.c @@ -436,10 +436,8 @@ static void umac_init(struct bcmasp_intf *intf) umac_wl(intf, 0x800, UMC_RX_MAX_PKT_SZ); } -static int bcmasp_tx_poll(struct napi_struct *napi, int budget) +static int bcmasp_tx_reclaim(struct bcmasp_intf *intf) { - struct bcmasp_intf *intf = - container_of(napi, struct bcmasp_intf, tx_napi); struct bcmasp_intf_stats64 *stats = &intf->stats64; struct device *kdev = &intf->parent->pdev->dev; unsigned long read, released = 0; @@ -482,10 +480,16 @@ static int bcmasp_tx_poll(struct napi_struct *napi, int budget) DESC_RING_COUNT); } - /* Ensure all descriptors have been written to DRAM for the hardware - * to see updated contents. - */ - wmb(); + return released; +} + +static int bcmasp_tx_poll(struct napi_struct *napi, int budget) +{ + struct bcmasp_intf *intf = + container_of(napi, struct bcmasp_intf, tx_napi); + int released = 0; + + released = bcmasp_tx_reclaim(intf); napi_complete(&intf->tx_napi); @@ -797,6 +801,7 @@ static void bcmasp_init_tx(struct bcmasp_intf *intf) intf->tx_spb_dma_read = intf->tx_spb_dma_addr; intf->tx_spb_index = 0; intf->tx_spb_clean_index = 0; + memset(intf->tx_cbs, 0, sizeof(struct bcmasp_tx_cb) * DESC_RING_COUNT); /* Make sure channels are disabled */ tx_spb_ctrl_wl(intf, 0x0, TX_SPB_CTRL_ENABLE); @@ -885,6 +890,8 @@ static void bcmasp_netif_deinit(struct net_device *dev) } while (timeout-- > 0); tx_spb_dma_wl(intf, 0x0, TX_SPB_DMA_FIFO_CTRL); + bcmasp_tx_reclaim(intf); + umac_enable_set(intf, UMC_CMD_TX_EN, 0); phy_stop(dev->phydev);