Skip to contentSkip to conversation

net: mvpp2: clear BM pool before initialization

PATCH Applied Jenishkumar Maheshbhai Patel 3 participants 5 messages Jan 19, 2024 – Jan 24, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 net: mvpp2: clear BM pool before initialization

Register value persist after booting the kernel using kexec which results in kernel panic. Thus clear the BM pool registers before initialisation to fix the issue.

Fixes 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375 network unit")

---
v1-v2:
-Move comments outside the loop
-remove unrequired brances.
v2-v3:
-improve readability
-correct register read API
v3-v4:
-optimize the code
-improve readability

 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +26 -1
index 820b1fabe297..23adf53c2aa1 100644
@@ -614,12 +614,38 @@ static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
 	mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
 }
 
+/* Cleanup pool before actual initialization in the OS */
+static void mvpp2_bm_pool_cleanup(struct mvpp2 *priv, int pool_id)
+{
+	unsigned int thread = mvpp2_cpu_to_thread(priv, get_cpu());
+	u32 val;
+	int i;
+
+	/* Drain the BM from all possible residues left by firmware */
+	for (i = 0; i < MVPP2_BM_POOL_SIZE_MAX; i++)
+		mvpp2_thread_read(priv, thread, MVPP2_BM_PHY_ALLOC_REG(pool_id));
+
+	put_cpu();
+
+	/* Stop the BM pool */
+	val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(pool_id));
+	val |= MVPP2_BM_STOP_MASK;
+	mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(pool_id), val);
+}
+
 static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 {
 	enum dma_data_direction dma_dir = DMA_FROM_DEVICE;
 	int i, err, poolnum = MVPP2_BM_POOLS_NUM;
 	struct mvpp2_port *port;
 
+	if (priv->percpu_pools)
+		poolnum = mvpp2_get_nrxqs(priv) * 2;
+
+	/* Clean up the pool state in case it contains stale state */
+	for (i = 0; i < poolnum; i++)
+		mvpp2_bm_pool_cleanup(priv, i);
+
 	if (priv->percpu_pools) {
 		for (i = 0; i < priv->port_count; i++) {
 			port = priv->port_list[i];
@@ -629,7 +655,6 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 			}
 		}
 
-		poolnum = mvpp2_get_nrxqs(priv) * 2;
 		for (i = 0; i < poolnum; i++) {
 			/* the pool in use */
 			int pn = i / (poolnum / 2);
Signature · 1 line
2.25.1
#1 lore raw

Hello,

Quoted 14 lines · On Thu, 18 Jan 2024 19:59:14 -0800 Jenishkumar Maheshbhai Patel…

Register value persist after booting the kernel using kexec which results in kernel panic. Thus clear the BM pool registers before initialisation to fix the issue.

Fixes 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375 network unit")

---
v1-v2:

(quoted diff) +0 -2
-Move comments outside the loop
-remove unrequired brances.

v2-v3:

(quoted diff) +0 -2
-improve readability
-correct register read API

v3-v4:

Review

Quoted 2 lines
(quoted diff) +0 -2
-optimize the code
-improve readability

Thanks for taking the reviews into account, however ...

Quoted 11 lines
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +0 -0
index 820b1fabe297..23adf53c2aa1 100644
@@ -614,12 +614,38 @@ static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
 	mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
 }
 

drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv) · line 626

Quoted 10 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +10 -0
+/* Cleanup pool before actual initialization in the OS */
+static void mvpp2_bm_pool_cleanup(struct mvpp2 *priv, int pool_id)
+{
+	unsigned int thread = mvpp2_cpu_to_thread(priv, get_cpu());
+	u32 val;
+	int i;
+
+	/* Drain the BM from all possible residues left by firmware */
+	for (i = 0; i < MVPP2_BM_POOL_SIZE_MAX; i++)
+		mvpp2_thread_read(priv, thread, MVPP2_BM_PHY_ALLOC_REG(pool_id));

... I think you didn't answer Antoine's comment on that loop from the V2, regarding what this does exactly. From the other sites this is used, it seems to perform an allocation from the pool, can you clarify how safe it is to do so here, if for example the BM was never configured by the firmware beforehand and is therefore already in a Stopped state ?

And are we not risking any leak if there was something in the pool that we don't release ?

Thanks,

Maxime

#2 lore raw

-----Original Message-----
From: Maxime Chevallier <[email protected]>
Sent: Friday, January 19, 2024 7:35 PM
To: Jenishkumar Patel [C] <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Antoine Tenart <[email protected]>
Subject: [EXT] Re: [net v4 PATCH 1/1] net: mvpp2: clear BM pool before initialization

External Email

----------------------------------------------------------------------
Hello,

Quoted 15 lines · On Thu, 18 Jan 2024 19:59:14 -0800 Jenishkumar Maheshbhai Patel…

Register value persist after booting the kernel using kexec which results in kernel panic. Thus clear the BM pool registers before initialisation to fix the issue.

Fixes 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375

network unit")

---
v1-v2:

(quoted diff) +0 -2
-Move comments outside the loop
-remove unrequired brances.

v2-v3:

(quoted diff) +0 -2
-improve readability
-correct register read API

v3-v4:

Review

Quoted 2 lines
(quoted diff) +0 -2
-optimize the code
-improve readability

Thanks for taking the reviews into account, however ...

Quoted 10 lines
 .../net/ethernet/marvell/mvpp2/mvpp2_main.c   | 27 ++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +0 -0
index 820b1fabe297..23adf53c2aa1 100644
@@ -614,12 +614,38 @@ static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
 	mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);  }

drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv) · line 624

Quoted 10 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +9 -0
 
+/* Cleanup pool before actual initialization in the OS */ static void 
+mvpp2_bm_pool_cleanup(struct mvpp2 *priv, int pool_id) {
+	unsigned int thread = mvpp2_cpu_to_thread(priv, get_cpu());
+	u32 val;
+	int i;
+
+	/* Drain the BM from all possible residues left by firmware */
+	for (i = 0; i < MVPP2_BM_POOL_SIZE_MAX; i++)
+		mvpp2_thread_read(priv, thread, MVPP2_BM_PHY_ALLOC_REG(pool_id));

... I think you didn't answer Antoine's comment on that loop from the V2, regarding what this does exactly. From the other sites this is used, it seems to perform an allocation from the pool, can you clarify how safe it is to do so here, if for example the BM was never configured by the firmware beforehand and is therefore already in a Stopped state ?

Reading the register provides a pointer to buffer that is already allocated during BM initialization. When multiple reading is done on the register, it will drain all the pointers that are stored by previous firmware. Also reading this register does not perform any allocation as it is only performing register read operation, thus when the BM is not configured earlier then it will not lead to any stop state.

And are we not risking any leak if there was something in the pool that we don't release ?

The data on the pointer given by register read is written after the read operation is preformed, which means the pointer does not contain any data, thus there is no leak.

Thanks,

Maxime

Reviewed-by
#3 lore raw

Hi,

Quoted 12 lines · On Mon, 22 Jan 2024 06:02:07 +0000 "Jenishkumar Patel [C]"…
Quoted 11 lines

drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv) · line 626

Quoted 9 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +9 -0
+/* Cleanup pool before actual initialization in the OS */ static void 
+mvpp2_bm_pool_cleanup(struct mvpp2 *priv, int pool_id) {
+	unsigned int thread = mvpp2_cpu_to_thread(priv, get_cpu());
+	u32 val;
+	int i;
+
+	/* Drain the BM from all possible residues left by firmware */
+	for (i = 0; i < MVPP2_BM_POOL_SIZE_MAX; i++)
+		mvpp2_thread_read(priv, thread, MVPP2_BM_PHY_ALLOC_REG(pool_id));  

... I think you didn't answer Antoine's comment on that loop from the V2, regarding what this does exactly. From the other sites this is used, it seems to perform an allocation from the pool, can you clarify how safe it is to do so here, if for example the BM was never configured by the firmware beforehand and is therefore already in a Stopped state ?

Quoted 5 lines

Reading the register provides a pointer to buffer that is already allocated during BM initialization. When multiple reading is done on the register, it will drain all the pointers that are stored by previous firmware. Also reading this register does not perform any allocation as it is only performing register read operation, thus when the BM is not configured earlier then it will not lead to any stop state.

Quoted 1 line

And are we not risking any leak if there was something in the pool that we don't release ?

The data on the pointer given by register read is written after the read operation is preformed, which means the pointer does not contain any data, thus there is no leak.

Thanks for your answers, I think that's clear to me then.

Maxime

#4 lore raw
In reply to Jenishkumar Maheshbhai Patel
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Thu, 18 Jan 2024 19:59:14 -0800 you wrote:

Register value persist after booting the kernel using kexec which results in kernel panic. Thus clear the BM pool registers before initialisation to fix the issue.

Fixes 3f518509dedc ("ethernet: Add new driver for Marvell Armada 375 network unit")

[...]

Here is the summary with links:
- [net,v4,1/1] net: mvpp2: clear BM pool before initialization

    https://git.kernel.org/netdev/net/c/9f538b415db8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html