From patchwork Thu Apr 18 18:05:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13635210 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) (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 6939C17A932 for ; Thu, 18 Apr 2024 18:05:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713463555; cv=none; b=FrUk3PJ3s+fXLRisX6KvAPdg+lxtRbALxVldoEgirwLT4SNKPNBrW4n68bx+39/jvRfvKu3DIJE22jsz5K9p7KV/sPOaTeXLDsOUOoomfFuvi5/llig41YHQ640ybUXk9kYuIEJZrHFHYARevlp6xEBg0CcWb67jnHsp45lj35w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713463555; c=relaxed/simple; bh=sNi+MeqLrrelS0oYhQXOwnmp0bqOb/whkSX+x3iVf0s=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=GE27BI2g4Cbpw8rwlKtKQ2UR2RMwt2nv2lGIUEHxDqDSD6cde7fLGPLLwzOxdIvd0Qtb6hmq29all+2kSVVGbQ3YxFjYMqJ3lPlxraqmLACAV7AXlQpNhSvh3ieyhOkOW3XD7V00SIkKr4CB6+g8da1GOrgIeD8pik+9oBKOVxk= 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=TyvkUyJ2; arc=none smtp.client-ip=209.85.222.178 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="TyvkUyJ2" Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78f02c96c52so69003185a.1 for ; Thu, 18 Apr 2024 11:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1713463552; x=1714068352; darn=vger.kernel.org; h=mime-version:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to; bh=nhCj5JwH6TcJvOF+C19nx7hxF6m+Qef42+bgcz5YShI=; b=TyvkUyJ2/F4r1tTTQFhbhbnWO+P6vtwDRK8GxzgPn7o8qiiAJrUJMeQpXLwSPKnG6N 9EvTJXVVTLQ6ozI56v4r3pDddWJfTkCj7xDCDYRLtYLjHOwkQuQfqKj/jPYDl4NSbeF5 00Uu8WEOeoo+Ky3o/FTPGoQh7gO1OEFqJrMNM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713463552; x=1714068352; h=mime-version:message-id:date:subject:cc:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nhCj5JwH6TcJvOF+C19nx7hxF6m+Qef42+bgcz5YShI=; b=voqwgPuzntTP720L4x/LEPamP8AiC+zm04fKjyTGZOvILBC/B7kuG0+1B4DLm1yyzW wXtOwUcGYR3Z7sbx5CQHiPeZof+69Ue/HZVl+79IUwCBYcFxQGkPLAkns4GimAQycfKb k1UXuEJuLWv/Vw1v820aXLoIYaFFotCyJpbEvc3YqjgjZ7DnLlVEUUJB/201YkZcCxQk 4lbZcyGu1/WTar+KQOZKTsNw6EKN+Aq9MYH+F5+Mza493+XuUhS8+zcJ+VfXYb3H2QXP jQY3O3tCj2GFETD6zBrOOw6WnEuXKsgH60BT2FyQ00lDE1eKx/A5QTVMGkJYwBS0pA3E OA6A== X-Gm-Message-State: AOJu0YzwlfBfIKpX+EfRYKrFu6P7ZYrwMzhaJ/XldSmElpuugrqQXceF ZkSFFF0L61kL72nFW0n9FPtrO+ZqvdH7VmjPsiF9DqoYg1Yh8sTmsoPq7ol7Cmkpo5IBqjXHXq8 uyyxJQp7amH3FiRxHnDRT+ewGVJFo0LCRyqP/cvFWUvyPqSAovZdtOugCLU8Mh4sDTmGqOgiO6z HuVxRfodgV1HeWZDtXAzupNk+rOHMBVxOncWp2QzY= X-Google-Smtp-Source: AGHT+IEO3ktHmfS++fqvGPXtZ9mF8Dh+R9qBoJYBFnG9l1JhSRE1Ehif4zkKNcMsdM72kOk2Io1ewA== X-Received: by 2002:a05:620a:13f5:b0:78d:5065:c5df with SMTP id h21-20020a05620a13f500b0078d5065c5dfmr3649137qkl.18.1713463551831; Thu, 18 Apr 2024 11:05:51 -0700 (PDT) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id x24-20020a05620a0ed800b0078d54363075sm842503qkm.40.2024.04.18.11.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 11:05:51 -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 v2] net: bcmasp: fix memory leak when bringing down interface Date: Thu, 18 Apr 2024 11:05:41 -0700 Message-Id: <20240418180541.2271719-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 leads 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 Reviewed-by: Simon Horman --- v2 - Fix typo and changed "if" -> interface .../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);