* [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver
@ 2018-02-14 0:23 Thomas Falcon
2018-02-14 0:23 ` [PATCH net 1/4] ibmvnic: Fix login buffer memory leaks Thomas Falcon
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Thomas Falcon @ 2018-02-14 0:23 UTC (permalink / raw)
To: netdev; +Cc: jallen, nfont, Thomas Falcon
This patch set is pretty self-explanatory. It includes
a number of patches that fix memory leaks found with
kmemleak in the ibmvnic driver.
Thomas Falcon (4):
ibmvnic: Fix login buffer memory leak
ibmvnic: Fix NAPI structures memory leak
ibmvnic: Free RX socket buffer in case of adapter error
ibmvnic: Clean RX pool buffers during device close
drivers/net/ethernet/ibm/ibmvnic.c | 50 +++++++++++++++++++++++++++++++++++++-
1 file changed, 49 insertions(+), 1 deletion(-)
--
2.7.5
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net 1/4] ibmvnic: Fix login buffer memory leaks
2018-02-14 0:23 [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver Thomas Falcon
@ 2018-02-14 0:23 ` Thomas Falcon
2018-02-14 0:23 ` [PATCH net 2/4] ibmvnic: Fix NAPI structures memory leak Thomas Falcon
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Falcon @ 2018-02-14 0:23 UTC (permalink / raw)
To: netdev; +Cc: jallen, nfont, Thomas Falcon
During device bringup, the driver exchanges login buffers with
firmware. These buffers contain information such number of TX
and RX queues alloted to the device, RX buffer size, etc. These
buffers weren't being properly freed on device reset or close.
We can free the buffer we send to firmware as soon as we get
a response. There is information in the response buffer that
the driver needs for normal operation so retain it until the
next reset or removal.
Signed-off-by: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
---
drivers/net/ethernet/ibm/ibmvnic.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 1a2d8d6..8625f5e 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -791,6 +791,18 @@ static int ibmvnic_login(struct net_device *netdev)
return 0;
}
+static void release_login_buffer(struct ibmvnic_adapter *adapter)
+{
+ kfree(adapter->login_buf);
+ adapter->login_buf = NULL;
+}
+
+static void release_login_rsp_buffer(struct ibmvnic_adapter *adapter)
+{
+ kfree(adapter->login_rsp_buf);
+ adapter->login_rsp_buf = NULL;
+}
+
static void release_resources(struct ibmvnic_adapter *adapter)
{
int i;
@@ -813,6 +825,8 @@ static void release_resources(struct ibmvnic_adapter *adapter)
}
}
}
+
+ release_login_rsp_buffer(adapter);
}
static int set_link_state(struct ibmvnic_adapter *adapter, u8 link_state)
@@ -3013,6 +3027,7 @@ static void send_login(struct ibmvnic_adapter *adapter)
struct vnic_login_client_data *vlcd;
int i;
+ release_login_rsp_buffer(adapter);
client_data_len = vnic_client_data_len(adapter);
buffer_size =
@@ -3708,6 +3723,7 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq,
dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz,
DMA_BIDIRECTIONAL);
+ release_login_buffer(adapter);
dma_unmap_single(dev, adapter->login_rsp_buf_token,
adapter->login_rsp_buf_sz, DMA_BIDIRECTIONAL);
--
2.7.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net 2/4] ibmvnic: Fix NAPI structures memory leak
2018-02-14 0:23 [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver Thomas Falcon
2018-02-14 0:23 ` [PATCH net 1/4] ibmvnic: Fix login buffer memory leaks Thomas Falcon
@ 2018-02-14 0:23 ` Thomas Falcon
2018-02-14 0:23 ` [PATCH net 3/4] ibmvnic: Free RX socket buffer in case of adapter error Thomas Falcon
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Falcon @ 2018-02-14 0:23 UTC (permalink / raw)
To: netdev; +Cc: jallen, nfont, Thomas Falcon
This memory is allocated during initialization but never freed,
so do that now.
Signed-off-by: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
---
drivers/net/ethernet/ibm/ibmvnic.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 8625f5e..23e0b42 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -825,6 +825,8 @@ static void release_resources(struct ibmvnic_adapter *adapter)
}
}
}
+ kfree(adapter->napi);
+ adapter->napi = NULL;
release_login_rsp_buffer(adapter);
}
--
2.7.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net 3/4] ibmvnic: Free RX socket buffer in case of adapter error
2018-02-14 0:23 [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver Thomas Falcon
2018-02-14 0:23 ` [PATCH net 1/4] ibmvnic: Fix login buffer memory leaks Thomas Falcon
2018-02-14 0:23 ` [PATCH net 2/4] ibmvnic: Fix NAPI structures memory leak Thomas Falcon
@ 2018-02-14 0:23 ` Thomas Falcon
2018-02-14 0:23 ` [PATCH net 4/4] ibmvnic: Clean RX pool buffers during device close Thomas Falcon
2018-02-14 19:39 ` [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver David Miller
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Falcon @ 2018-02-14 0:23 UTC (permalink / raw)
To: netdev; +Cc: jallen, nfont, Thomas Falcon
If a RX buffer is returned to the client driver with an error, free the
corresponding socket buffer before continuing.
Signed-off-by: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
---
drivers/net/ethernet/ibm/ibmvnic.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index 23e0b42..bc93fa2 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -1869,6 +1869,7 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget)
be16_to_cpu(next->rx_comp.rc));
/* free the entry */
next->rx_comp.first = 0;
+ dev_kfree_skb_any(rx_buff->skb);
remove_buff_from_pool(adapter, rx_buff);
continue;
}
--
2.7.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH net 4/4] ibmvnic: Clean RX pool buffers during device close
2018-02-14 0:23 [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver Thomas Falcon
` (2 preceding siblings ...)
2018-02-14 0:23 ` [PATCH net 3/4] ibmvnic: Free RX socket buffer in case of adapter error Thomas Falcon
@ 2018-02-14 0:23 ` Thomas Falcon
2018-02-14 19:39 ` [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver David Miller
4 siblings, 0 replies; 6+ messages in thread
From: Thomas Falcon @ 2018-02-14 0:23 UTC (permalink / raw)
To: netdev; +Cc: jallen, nfont, Thomas Falcon
During device close or reset, there were some cases of outstanding
RX socket buffers not being freed. Include a function similar to the
one that already exists to clean TX socket buffers in this case.
Signed-off-by: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
---
drivers/net/ethernet/ibm/ibmvnic.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c
index bc93fa2..996f475 100644
--- a/drivers/net/ethernet/ibm/ibmvnic.c
+++ b/drivers/net/ethernet/ibm/ibmvnic.c
@@ -1073,6 +1073,35 @@ static int ibmvnic_open(struct net_device *netdev)
return rc;
}
+static void clean_rx_pools(struct ibmvnic_adapter *adapter)
+{
+ struct ibmvnic_rx_pool *rx_pool;
+ u64 rx_entries;
+ int rx_scrqs;
+ int i, j;
+
+ if (!adapter->rx_pool)
+ return;
+
+ rx_scrqs = be32_to_cpu(adapter->login_rsp_buf->num_rxadd_subcrqs);
+ rx_entries = adapter->req_rx_add_entries_per_subcrq;
+
+ /* Free any remaining skbs in the rx buffer pools */
+ for (i = 0; i < rx_scrqs; i++) {
+ rx_pool = &adapter->rx_pool[i];
+ if (!rx_pool)
+ continue;
+
+ netdev_dbg(adapter->netdev, "Cleaning rx_pool[%d]\n", i);
+ for (j = 0; j < rx_entries; j++) {
+ if (rx_pool->rx_buff[j].skb) {
+ dev_kfree_skb_any(rx_pool->rx_buff[j].skb);
+ rx_pool->rx_buff[j].skb = NULL;
+ }
+ }
+ }
+}
+
static void clean_tx_pools(struct ibmvnic_adapter *adapter)
{
struct ibmvnic_tx_pool *tx_pool;
@@ -1150,7 +1179,7 @@ static int __ibmvnic_close(struct net_device *netdev)
}
}
}
-
+ clean_rx_pools(adapter);
clean_tx_pools(adapter);
adapter->state = VNIC_CLOSED;
return rc;
--
2.7.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver
2018-02-14 0:23 [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver Thomas Falcon
` (3 preceding siblings ...)
2018-02-14 0:23 ` [PATCH net 4/4] ibmvnic: Clean RX pool buffers during device close Thomas Falcon
@ 2018-02-14 19:39 ` David Miller
4 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2018-02-14 19:39 UTC (permalink / raw)
To: tlfalcon; +Cc: netdev, jallen, nfont
From: Thomas Falcon <tlfalcon@linux.vnet.ibm.com>
Date: Tue, 13 Feb 2018 18:23:39 -0600
> This patch set is pretty self-explanatory. It includes
> a number of patches that fix memory leaks found with
> kmemleak in the ibmvnic driver.
Series applied, thanks Thomas.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2018-02-14 19:39 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-14 0:23 [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver Thomas Falcon
2018-02-14 0:23 ` [PATCH net 1/4] ibmvnic: Fix login buffer memory leaks Thomas Falcon
2018-02-14 0:23 ` [PATCH net 2/4] ibmvnic: Fix NAPI structures memory leak Thomas Falcon
2018-02-14 0:23 ` [PATCH net 3/4] ibmvnic: Free RX socket buffer in case of adapter error Thomas Falcon
2018-02-14 0:23 ` [PATCH net 4/4] ibmvnic: Clean RX pool buffers during device close Thomas Falcon
2018-02-14 19:39 ` [PATCH net 0/4] ibmvnic: Fix memory leaks in the driver David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).