* [PATCH net v4 0/7] Double free fixes and NULL pointer checks
@ 2024-11-13 11:13 Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes Shinas Rasheed
` (6 more replies)
0 siblings, 7 replies; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed
Fix double frees which happen on reset scenarios, and add
NULL pointer checks for when rare cases might trigger
dereferences of such.
Changes:
V4:
- Removed unnecessary protective code from octep_disable_msix() and
improved commit message
V3: https://lore.kernel.org/all/20241108074543.1123036-1-srasheed@marvell.com/
- Added back "fixes" to the Changes listed
V2: https://lore.kernel.org/all/20241107132846.1118835-1-srasheed@marvell.com/
- Added more context in commit messages and split patches for each
commit fix
V1: https://lore.kernel.org/all/20241101103416.1064930-1-srasheed@marvell.com/
Shinas Rasheed (6):
octeon_ep: Fix null dereferences to IQ/OQ pointers
octeon_ep: add protective null checks in napi callbacks for cn9k cards
octeon_ep: add protective null checks in napi callbacks for cnxk cards
octeon_ep_vf: Fix null dereferences to IQ/OQ pointers
octeon_ep_vf: add protective null checks in napi callbacks for cn9k
cards
octeon_ep_vf: add protective null checks in napi callbacks for cnxk
cards
Vimlesh Kumar (1):
octeon_ep: Add checks to fix double free crashes
.../ethernet/marvell/octeon_ep/octep_cn9k_pf.c | 9 ++++++++-
.../ethernet/marvell/octeon_ep/octep_cnxk_pf.c | 9 ++++++++-
.../net/ethernet/marvell/octeon_ep/octep_main.c | 17 +++++++++++++----
.../net/ethernet/marvell/octeon_ep/octep_tx.c | 2 ++
.../marvell/octeon_ep_vf/octep_vf_cn9k.c | 8 +++++++-
.../marvell/octeon_ep_vf/octep_vf_cnxk.c | 12 +++++++++++-
.../marvell/octeon_ep_vf/octep_vf_main.c | 3 +++
7 files changed, 52 insertions(+), 8 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
@ 2024-11-13 11:13 ` Shinas Rasheed
2024-11-13 14:59 ` Vadim Fedorenko
2024-11-13 22:38 ` Vadim Fedorenko
2024-11-13 11:13 ` [PATCH net v4 2/7] octeon_ep: Fix null dereferences to IQ/OQ pointers Shinas Rasheed
` (5 subsequent siblings)
6 siblings, 2 replies; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed, Veerasenareddy Burru,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Abhijit Ayarekar, Satananda Burla
From: Vimlesh Kumar <vimleshk@marvell.com>
Add required checks to avoid double free. Crashes were
observed due to the same on reset scenarios, when reset
was tried multiple times, and the first reset had torn
down resources already.
Fixes: 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")
Signed-off-by: Vimlesh Kumar <vimleshk@marvell.com>
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
V4:
- Removed unnecessary protective code. Added fast return from
octep_free_irqs()
- Improved commit message
V3: https://lore.kernel.org/all/20241108074543.1123036-2-srasheed@marvell.com/
- Added back "Fixes" to the changelist
V2: https://lore.kernel.org/all/20241107132846.1118835-2-srasheed@marvell.com/
- No changes
V1: https://lore.kernel.org/all/20241101103416.1064930-2-srasheed@marvell.com/
.../net/ethernet/marvell/octeon_ep/octep_main.c | 14 ++++++++++----
drivers/net/ethernet/marvell/octeon_ep/octep_tx.c | 2 ++
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
index 549436efc204..29796544feb6 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
@@ -496,6 +496,9 @@ static void octep_free_irqs(struct octep_device *oct)
{
int i;
+ if (!oct->msix_entries)
+ return;
+
/* First few MSI-X interrupts are non queue interrupts; free them */
for (i = 0; i < CFG_GET_NON_IOQ_MSIX(oct->conf); i++)
free_irq(oct->msix_entries[i].vector, oct);
@@ -505,7 +508,7 @@ static void octep_free_irqs(struct octep_device *oct)
for (i = CFG_GET_NON_IOQ_MSIX(oct->conf); i < oct->num_irqs; i++) {
irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
free_irq(oct->msix_entries[i].vector,
- oct->ioq_vector[i - CFG_GET_NON_IOQ_MSIX(oct->conf)]);
+ oct->ioq_vector[i - CFG_GET_NON_IOQ_MSIX(oct->conf)]);
}
netdev_info(oct->netdev, "IRQs freed\n");
}
@@ -635,8 +638,10 @@ static void octep_napi_delete(struct octep_device *oct)
for (i = 0; i < oct->num_oqs; i++) {
netdev_dbg(oct->netdev, "Deleting NAPI on Q-%d\n", i);
- netif_napi_del(&oct->ioq_vector[i]->napi);
- oct->oq[i]->napi = NULL;
+ if (oct->oq[i]->napi) {
+ netif_napi_del(&oct->ioq_vector[i]->napi);
+ oct->oq[i]->napi = NULL;
+ }
}
}
@@ -666,7 +671,8 @@ static void octep_napi_disable(struct octep_device *oct)
for (i = 0; i < oct->num_oqs; i++) {
netdev_dbg(oct->netdev, "Disabling NAPI on Q-%d\n", i);
- napi_disable(&oct->ioq_vector[i]->napi);
+ if (oct->oq[i]->napi)
+ napi_disable(&oct->ioq_vector[i]->napi);
}
}
diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c
index 06851b78aa28..157bf489ae19 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c
@@ -323,6 +323,8 @@ void octep_free_iqs(struct octep_device *oct)
int i;
for (i = 0; i < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); i++) {
+ if (!oct->iq[i])
+ continue;
octep_free_iq(oct->iq[i]);
dev_dbg(&oct->pdev->dev,
"Successfully destroyed IQ(TxQ)-%d.\n", i);
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net v4 2/7] octeon_ep: Fix null dereferences to IQ/OQ pointers
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes Shinas Rasheed
@ 2024-11-13 11:13 ` Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 3/7] octeon_ep: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
` (4 subsequent siblings)
6 siblings, 0 replies; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed, Veerasenareddy Burru,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Abhijit Ayarekar, Satananda Burla
During unload, sometimes race scenarios are seen wherein
the get stats callback proceeds to retrieve the IQ/OQ stats,
but by then the IQ/OQ might have been already freed.
Protect against such conditions by defensively checking if
the IQ/OQ pointers are null before dereference.
Fixes: 6a610a46bad1 ("octeon_ep: add support for ndo ops")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
V4:
- No change
V3: https://lore.kernel.org/all/20241108074543.1123036-3-srasheed@marvell.com/
- Added back "Fixes" to the changelist
V2: https://lore.kernel.org/all/20241107132846.1118835-3-srasheed@marvell.com/
- Split from earlier patch into a separate patch
- Added more context
V2: https://lore.kernel.org/all/20241101103416.1064930-3-srasheed@marvell.com/
drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
index 29796544feb6..3cea7811e48d 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
@@ -1015,6 +1015,9 @@ static void octep_get_stats64(struct net_device *netdev,
struct octep_iq *iq = oct->iq[q];
struct octep_oq *oq = oct->oq[q];
+ if (!iq || !oq)
+ return;
+
tx_packets += iq->stats.instr_completed;
tx_bytes += iq->stats.bytes_sent;
rx_packets += oq->stats.packets;
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net v4 3/7] octeon_ep: add protective null checks in napi callbacks for cn9k cards
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 2/7] octeon_ep: Fix null dereferences to IQ/OQ pointers Shinas Rasheed
@ 2024-11-13 11:13 ` Shinas Rasheed
2024-11-13 17:59 ` Vadim Fedorenko
2024-11-13 11:13 ` [PATCH net v4 4/7] octeon_ep: add protective null checks in napi callbacks for cnxk cards Shinas Rasheed
` (3 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed, Veerasenareddy Burru,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Satananda Burla, Abhijit Ayarekar
During unload, at times the OQ parsed in the napi callbacks
have been observed to be null, causing system crash.
Add protective checks to avoid the same, for cn9k cards.
Fixes: 1f2c2d0cee02 ("octeon_ep: add hardware configuration APIs")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
V4:
- No changes
V3: https://lore.kernel.org/all/20241108074543.1123036-4-srasheed@marvell.com/
- Added back "Fixes" to the changelist
V2: https://lore.kernel.org/all/20241107132846.1118835-4-srasheed@marvell.com/
- Split into a separate patch
- Added more context
V1: https://lore.kernel.org/all/20241101103416.1064930-3-srasheed@marvell.com/
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c b/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c
index b5805969404f..b87336b2e4b9 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c
@@ -617,7 +617,14 @@ static irqreturn_t octep_rsvd_intr_handler_cn93_pf(void *dev)
static irqreturn_t octep_ioq_intr_handler_cn93_pf(void *data)
{
struct octep_ioq_vector *vector = (struct octep_ioq_vector *)data;
- struct octep_oq *oq = vector->oq;
+ struct octep_oq *oq;
+
+ if (!vector)
+ return IRQ_HANDLED;
+ oq = vector->oq;
+
+ if (!oq || !(oq->napi))
+ return IRQ_HANDLED;
napi_schedule_irqoff(oq->napi);
return IRQ_HANDLED;
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net v4 4/7] octeon_ep: add protective null checks in napi callbacks for cnxk cards
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
` (2 preceding siblings ...)
2024-11-13 11:13 ` [PATCH net v4 3/7] octeon_ep: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
@ 2024-11-13 11:13 ` Shinas Rasheed
2024-11-13 18:01 ` Vadim Fedorenko
2024-11-13 11:13 ` [PATCH net v4 5/7] octeon_ep_vf: Fix null dereferences to IQ/OQ pointers Shinas Rasheed
` (2 subsequent siblings)
6 siblings, 1 reply; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed, Veerasenareddy Burru,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
During unload, at times the OQ parsed in the napi callbacks
have been observed to be null, causing system crash.
Add protective checks to avoid the same, for cnxk cards.
Fixes: 0807dc76f3bf ("octeon_ep: support Octeon CN10K devices")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
V4:
- No Changes
V3: https://lore.kernel.org/all/20241108074543.1123036-5-srasheed@marvell.com/
- Added back "Fixes" to the changelist
V2: https://lore.kernel.org/all/20241107132846.1118835-5-srasheed@marvell.com/
- Split into a separate patch
- Added more context
V1: https://lore.kernel.org/all/20241101103416.1064930-3-srasheed@marvell.com/
drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c b/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c
index 5de0b5ecbc5f..65a8dc1d492b 100644
--- a/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c
+++ b/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c
@@ -638,7 +638,14 @@ static irqreturn_t octep_rsvd_intr_handler_cnxk_pf(void *dev)
static irqreturn_t octep_ioq_intr_handler_cnxk_pf(void *data)
{
struct octep_ioq_vector *vector = (struct octep_ioq_vector *)data;
- struct octep_oq *oq = vector->oq;
+ struct octep_oq *oq;
+
+ if (!vector)
+ return IRQ_HANDLED;
+ oq = vector->oq;
+
+ if (!oq || !(oq->napi))
+ return IRQ_HANDLED;
napi_schedule_irqoff(oq->napi);
return IRQ_HANDLED;
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net v4 5/7] octeon_ep_vf: Fix null dereferences to IQ/OQ pointers
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
` (3 preceding siblings ...)
2024-11-13 11:13 ` [PATCH net v4 4/7] octeon_ep: add protective null checks in napi callbacks for cnxk cards Shinas Rasheed
@ 2024-11-13 11:13 ` Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 6/7] octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 7/7] octeon_ep_vf: add protective null checks in napi callbacks for cnxk cards Shinas Rasheed
6 siblings, 0 replies; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed, Veerasenareddy Burru,
Satananda Burla, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
During unload, sometimes race scenarios are seen wherein
the get stats callback proceeds to retrieve the IQ/OQ stats,
but by then the IQ/OQ might have been already freed.
Protect against such conditions by defensively checking if
the IQ/OQ pointers are null before dereference.
Fixes: cb7dd712189f ("octeon_ep_vf: Add driver framework and device initialization")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
V4:
- No Changes
V3: https://lore.kernel.org/all/20241108074543.1123036-6-srasheed@marvell.com/
- Added back "Fixes" to the changelist
V2: https://lore.kernel.org/all/20241107132846.1118835-6-srasheed@marvell.com/
- Split into a separate patch
- Added more context
V1: https://lore.kernel.org/all/20241101103416.1064930-4-srasheed@marvell.com/
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c
index 7e6771c9cdbb..79d9ffd593eb 100644
--- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c
+++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c
@@ -790,6 +790,9 @@ static void octep_vf_get_stats64(struct net_device *netdev,
struct octep_vf_iq *iq = oct->iq[q];
struct octep_vf_oq *oq = oct->oq[q];
+ if (!iq || !oq)
+ return;
+
tx_packets += iq->stats.instr_completed;
tx_bytes += iq->stats.bytes_sent;
rx_packets += oq->stats.packets;
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net v4 6/7] octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
` (4 preceding siblings ...)
2024-11-13 11:13 ` [PATCH net v4 5/7] octeon_ep_vf: Fix null dereferences to IQ/OQ pointers Shinas Rasheed
@ 2024-11-13 11:13 ` Shinas Rasheed
2024-11-13 18:02 ` Vadim Fedorenko
2024-11-13 11:13 ` [PATCH net v4 7/7] octeon_ep_vf: add protective null checks in napi callbacks for cnxk cards Shinas Rasheed
6 siblings, 1 reply; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed, Veerasenareddy Burru,
Satananda Burla, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
During unload, at times the OQ parsed in the napi callbacks
have been observed to be null, causing system crash.
Add protective checks to avoid the same, for cn9k cards.
Fixes: cb7dd712189f ("octeon_ep_vf: Add driver framework and device initialization")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
V4:
- No changes
V3: https://lore.kernel.org/all/20241108074543.1123036-7-srasheed@marvell.com/
- Added back "Fixes" to the changelist
V2: https://lore.kernel.org/all/20241107132846.1118835-7-srasheed@marvell.com/
- Split into a separate patch
- Added more context
V1: https://lore.kernel.org/all/20241101103416.1064930-4-srasheed@marvell.com/
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c
index 88937fce75f1..f1b7eda3fa42 100644
--- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c
+++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c
@@ -273,8 +273,14 @@ static irqreturn_t octep_vf_ioq_intr_handler_cn93(void *data)
struct octep_vf_oq *oq;
u64 reg_val;
- oct = vector->octep_vf_dev;
+ if (!vector)
+ return IRQ_HANDLED;
+
oq = vector->oq;
+ if (!oq)
+ return IRQ_HANDLED;
+
+ oct = vector->octep_vf_dev;
/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */
if (oq->q_no == 0) {
reg_val = octep_vf_read_csr64(oct, CN93_VF_SDP_R_MBOX_PF_VF_INT(0));
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH net v4 7/7] octeon_ep_vf: add protective null checks in napi callbacks for cnxk cards
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
` (5 preceding siblings ...)
2024-11-13 11:13 ` [PATCH net v4 6/7] octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
@ 2024-11-13 11:13 ` Shinas Rasheed
6 siblings, 0 replies; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-13 11:13 UTC (permalink / raw)
To: netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Shinas Rasheed, Veerasenareddy Burru,
Satananda Burla, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni
During unload, at times the OQ parsed in the napi callbacks
have been observed to be null, causing system crash.
Add protective checks to avoid the same, for cnxk cards.
Fixes: cb7dd712189f ("octeon_ep_vf: Add driver framework and device initialization")
Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
---
V4:
- No Changes
V3: https://lore.kernel.org/all/20241108074543.1123036-8-srasheed@marvell.com/
- Added back "Fixes" to the changelist
V2: https://lore.kernel.org/all/20241107132846.1118835-8-srasheed@marvell.com/
- Split into a separate patch
- Added more context
V1: https://lore.kernel.org/all/20241101103416.1064930-4-srasheed@marvell.com/
.../ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c
index 1f79dfad42c6..31c0d7c0492a 100644
--- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c
+++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c
@@ -284,8 +284,14 @@ static irqreturn_t octep_vf_ioq_intr_handler_cnxk(void *data)
struct octep_vf_oq *oq;
u64 reg_val;
- oct = vector->octep_vf_dev;
+ if (!vector)
+ return IRQ_HANDLED;
+
oq = vector->oq;
+ if (!oq)
+ return IRQ_HANDLED;
+
+ oct = vector->octep_vf_dev;
/* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */
if (oq->q_no == 0) {
reg_val = octep_vf_read_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0));
@@ -294,6 +300,10 @@ static irqreturn_t octep_vf_ioq_intr_handler_cnxk(void *data)
octep_vf_write_csr64(oct, CNXK_VF_SDP_R_MBOX_PF_VF_INT(0), reg_val);
}
}
+
+ if (!(oq->napi))
+ return IRQ_HANDLED;
+
napi_schedule_irqoff(oq->napi);
return IRQ_HANDLED;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes
2024-11-13 11:13 ` [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes Shinas Rasheed
@ 2024-11-13 14:59 ` Vadim Fedorenko
2024-11-13 22:38 ` Vadim Fedorenko
1 sibling, 0 replies; 14+ messages in thread
From: Vadim Fedorenko @ 2024-11-13 14:59 UTC (permalink / raw)
To: Shinas Rasheed, netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Veerasenareddy Burru, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Abhijit Ayarekar, Satananda Burla
On 13/11/2024 11:13, Shinas Rasheed wrote:
> From: Vimlesh Kumar <vimleshk@marvell.com>
>
> Add required checks to avoid double free. Crashes were
> observed due to the same on reset scenarios, when reset
> was tried multiple times, and the first reset had torn
> down resources already.
>
> Fixes: 37d79d059606 ("octeon_ep: add Tx/Rx processing and interrupt support")
> Signed-off-by: Vimlesh Kumar <vimleshk@marvell.com>
> Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
> ---
> V4:
> - Removed unnecessary protective code. Added fast return from
> octep_free_irqs()
> - Improved commit message
>
> V3: https://lore.kernel.org/all/20241108074543.1123036-2-srasheed@marvell.com/
> - Added back "Fixes" to the changelist
>
> V2: https://lore.kernel.org/all/20241107132846.1118835-2-srasheed@marvell.com/
> - No changes
>
> V1: https://lore.kernel.org/all/20241101103416.1064930-2-srasheed@marvell.com/
>
> .../net/ethernet/marvell/octeon_ep/octep_main.c | 14 ++++++++++----
> drivers/net/ethernet/marvell/octeon_ep/octep_tx.c | 2 ++
> 2 files changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> index 549436efc204..29796544feb6 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_main.c
> @@ -496,6 +496,9 @@ static void octep_free_irqs(struct octep_device *oct)
> {
> int i;
>
> + if (!oct->msix_entries)
> + return;
> +
> /* First few MSI-X interrupts are non queue interrupts; free them */
> for (i = 0; i < CFG_GET_NON_IOQ_MSIX(oct->conf); i++)
> free_irq(oct->msix_entries[i].vector, oct);
> @@ -505,7 +508,7 @@ static void octep_free_irqs(struct octep_device *oct)
> for (i = CFG_GET_NON_IOQ_MSIX(oct->conf); i < oct->num_irqs; i++) {
> irq_set_affinity_hint(oct->msix_entries[i].vector, NULL);
> free_irq(oct->msix_entries[i].vector,
> - oct->ioq_vector[i - CFG_GET_NON_IOQ_MSIX(oct->conf)]);
> + oct->ioq_vector[i - CFG_GET_NON_IOQ_MSIX(oct->conf)]);
Looks like this chunk was unintended, it was perfectly aligned before...
> }
> netdev_info(oct->netdev, "IRQs freed\n");
> }
> @@ -635,8 +638,10 @@ static void octep_napi_delete(struct octep_device *oct)
>
> for (i = 0; i < oct->num_oqs; i++) {
> netdev_dbg(oct->netdev, "Deleting NAPI on Q-%d\n", i);
> - netif_napi_del(&oct->ioq_vector[i]->napi);
> - oct->oq[i]->napi = NULL;
> + if (oct->oq[i]->napi) {
> + netif_napi_del(&oct->ioq_vector[i]->napi);
> + oct->oq[i]->napi = NULL;
> + }
I would just add
if (!oct->oq[i]->napi)
continue
as the first line within the loop. Otherwise debug message could be
misleading - deleting NAPI on queue which doesn't exist.
> }
> }
>
> @@ -666,7 +671,8 @@ static void octep_napi_disable(struct octep_device *oct)
>
> for (i = 0; i < oct->num_oqs; i++) {
> netdev_dbg(oct->netdev, "Disabling NAPI on Q-%d\n", i);
> - napi_disable(&oct->ioq_vector[i]->napi);
> + if (oct->oq[i]->napi)
> + napi_disable(&oct->ioq_vector[i]->napi);
And here again, the same pattern.
> }
> }
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c b/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c
> index 06851b78aa28..157bf489ae19 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_tx.c
> @@ -323,6 +323,8 @@ void octep_free_iqs(struct octep_device *oct)
> int i;
>
> for (i = 0; i < CFG_GET_PORTS_ACTIVE_IO_RINGS(oct->conf); i++) {
> + if (!oct->iq[i])
> + continue;
> octep_free_iq(oct->iq[i]);
> dev_dbg(&oct->pdev->dev,
> "Successfully destroyed IQ(TxQ)-%d.\n", i);
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net v4 3/7] octeon_ep: add protective null checks in napi callbacks for cn9k cards
2024-11-13 11:13 ` [PATCH net v4 3/7] octeon_ep: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
@ 2024-11-13 17:59 ` Vadim Fedorenko
0 siblings, 0 replies; 14+ messages in thread
From: Vadim Fedorenko @ 2024-11-13 17:59 UTC (permalink / raw)
To: Shinas Rasheed, netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Veerasenareddy Burru, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Satananda Burla, Abhijit Ayarekar
On 13/11/2024 11:13, Shinas Rasheed wrote:
> During unload, at times the OQ parsed in the napi callbacks
> have been observed to be null, causing system crash.
> Add protective checks to avoid the same, for cn9k cards.
>
> Fixes: 1f2c2d0cee02 ("octeon_ep: add hardware configuration APIs")
> Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
> ---
> V4:
> - No changes
>
> V3: https://lore.kernel.org/all/20241108074543.1123036-4-srasheed@marvell.com/
> - Added back "Fixes" to the changelist
>
> V2: https://lore.kernel.org/all/20241107132846.1118835-4-srasheed@marvell.com/
> - Split into a separate patch
> - Added more context
>
> V1: https://lore.kernel.org/all/20241101103416.1064930-3-srasheed@marvell.com/
>
> drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c b/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c
> index b5805969404f..b87336b2e4b9 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c
> @@ -617,7 +617,14 @@ static irqreturn_t octep_rsvd_intr_handler_cn93_pf(void *dev)
> static irqreturn_t octep_ioq_intr_handler_cn93_pf(void *data)
> {
> struct octep_ioq_vector *vector = (struct octep_ioq_vector *)data;
> - struct octep_oq *oq = vector->oq;
> + struct octep_oq *oq;
> +
> + if (!vector)
> + return IRQ_HANDLED;
Sorry for not flagging in previous review, but the question is again the
same - how that can happen? This function is irq handler, which is
called from octep_ioq_intr_handler() only if ioq_vector was properly
resolved. This check makes no sense here.
> + oq = vector->oq;
> +
> + if (!oq || !(oq->napi))
> + return IRQ_HANDLED;
>
> napi_schedule_irqoff(oq->napi);
> return IRQ_HANDLED;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net v4 4/7] octeon_ep: add protective null checks in napi callbacks for cnxk cards
2024-11-13 11:13 ` [PATCH net v4 4/7] octeon_ep: add protective null checks in napi callbacks for cnxk cards Shinas Rasheed
@ 2024-11-13 18:01 ` Vadim Fedorenko
0 siblings, 0 replies; 14+ messages in thread
From: Vadim Fedorenko @ 2024-11-13 18:01 UTC (permalink / raw)
To: Shinas Rasheed, netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Veerasenareddy Burru, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
On 13/11/2024 11:13, Shinas Rasheed wrote:
> During unload, at times the OQ parsed in the napi callbacks
> have been observed to be null, causing system crash.
> Add protective checks to avoid the same, for cnxk cards.
>
> Fixes: 0807dc76f3bf ("octeon_ep: support Octeon CN10K devices")
> Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
> ---
> V4:
> - No Changes
>
> V3: https://lore.kernel.org/all/20241108074543.1123036-5-srasheed@marvell.com/
> - Added back "Fixes" to the changelist
>
> V2: https://lore.kernel.org/all/20241107132846.1118835-5-srasheed@marvell.com/
> - Split into a separate patch
> - Added more context
>
> V1: https://lore.kernel.org/all/20241101103416.1064930-3-srasheed@marvell.com/
>
> drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c b/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c
> index 5de0b5ecbc5f..65a8dc1d492b 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c
> @@ -638,7 +638,14 @@ static irqreturn_t octep_rsvd_intr_handler_cnxk_pf(void *dev)
> static irqreturn_t octep_ioq_intr_handler_cnxk_pf(void *data)
> {
> struct octep_ioq_vector *vector = (struct octep_ioq_vector *)data;
> - struct octep_oq *oq = vector->oq;
> + struct octep_oq *oq;
> +
> + if (!vector)
> + return IRQ_HANDLED;
The same comment as for the previous patch - this can never happen, the
check is meaningless
> + oq = vector->oq;
> +
> + if (!oq || !(oq->napi))
> + return IRQ_HANDLED;
>
> napi_schedule_irqoff(oq->napi);
> return IRQ_HANDLED;
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net v4 6/7] octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards
2024-11-13 11:13 ` [PATCH net v4 6/7] octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
@ 2024-11-13 18:02 ` Vadim Fedorenko
0 siblings, 0 replies; 14+ messages in thread
From: Vadim Fedorenko @ 2024-11-13 18:02 UTC (permalink / raw)
To: Shinas Rasheed, netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Veerasenareddy Burru, Satananda Burla,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
On 13/11/2024 11:13, Shinas Rasheed wrote:
> During unload, at times the OQ parsed in the napi callbacks
> have been observed to be null, causing system crash.
> Add protective checks to avoid the same, for cn9k cards.
>
> Fixes: cb7dd712189f ("octeon_ep_vf: Add driver framework and device initialization")
> Signed-off-by: Shinas Rasheed <srasheed@marvell.com>
> ---
> V4:
> - No changes
>
> V3: https://lore.kernel.org/all/20241108074543.1123036-7-srasheed@marvell.com/
> - Added back "Fixes" to the changelist
>
> V2: https://lore.kernel.org/all/20241107132846.1118835-7-srasheed@marvell.com/
> - Split into a separate patch
> - Added more context
>
> V1: https://lore.kernel.org/all/20241101103416.1064930-4-srasheed@marvell.com/
>
> drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c
> index 88937fce75f1..f1b7eda3fa42 100644
> --- a/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c
> +++ b/drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c
> @@ -273,8 +273,14 @@ static irqreturn_t octep_vf_ioq_intr_handler_cn93(void *data)
> struct octep_vf_oq *oq;
> u64 reg_val;
>
> - oct = vector->octep_vf_dev;
> + if (!vector)
> + return IRQ_HANDLED;
And again, this function is irq handler, which is
called from octep_vf_ioq_intr_handler() only if ioq_vector was properly
resolved. This check makes no sense here.
The same goes to the next patch.
> +
> oq = vector->oq;
> + if (!oq)
> + return IRQ_HANDLED;
> +
> + oct = vector->octep_vf_dev;
> /* Mailbox interrupt arrives along with interrupt of tx/rx ring pair 0 */
> if (oq->q_no == 0) {
> reg_val = octep_vf_read_csr64(oct, CN93_VF_SDP_R_MBOX_PF_VF_INT(0));
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes
2024-11-13 11:13 ` [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes Shinas Rasheed
2024-11-13 14:59 ` Vadim Fedorenko
@ 2024-11-13 22:38 ` Vadim Fedorenko
2024-11-16 17:25 ` [EXTERNAL] " Shinas Rasheed
1 sibling, 1 reply; 14+ messages in thread
From: Vadim Fedorenko @ 2024-11-13 22:38 UTC (permalink / raw)
To: Shinas Rasheed, netdev, linux-kernel
Cc: hgani, sedara, vimleshk, thaller, wizhao, kheib, egallen,
konguyen, horms, Veerasenareddy Burru, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Abhijit Ayarekar, Satananda Burla
On 13/11/2024 11:13, Shinas Rasheed wrote:
> From: Vimlesh Kumar <vimleshk@marvell.com>
>
> Add required checks to avoid double free. Crashes were
> observed due to the same on reset scenarios, when reset
> was tried multiple times, and the first reset had torn
> down resources already.
I'm looking at the whole series and it feels like we have to deal
with the root cause rather than add protective code left and right.
The driver may potentially have some locks missing which will cause
missing resources, and to fix the root cause these locks have to be
added. WDYT?
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [EXTERNAL] Re: [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes
2024-11-13 22:38 ` Vadim Fedorenko
@ 2024-11-16 17:25 ` Shinas Rasheed
0 siblings, 0 replies; 14+ messages in thread
From: Shinas Rasheed @ 2024-11-16 17:25 UTC (permalink / raw)
To: Vadim Fedorenko, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: Haseeb Gani, Sathesh B Edara, Vimlesh Kumar, thaller@redhat.com,
wizhao@redhat.com, kheib@redhat.com, egallen@redhat.com,
konguyen@redhat.com, horms@kernel.org, Veerasenareddy Burru,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Abhijit Ayarekar, Satananda Burla
Hi Vadim,
> On 13/11/2024 11:13, Shinas Rasheed wrote:
> > From: Vimlesh Kumar <vimleshk@marvell.com>
> >
> > Add required checks to avoid double free. Crashes were
> > observed due to the same on reset scenarios, when reset
> > was tried multiple times, and the first reset had torn
> > down resources already.
>
> I'm looking at the whole series and it feels like we have to deal
> with the root cause rather than add protective code left and right.
>
> The driver may potentially have some locks missing which will cause
> missing resources, and to fix the root cause these locks have to be
> added. WDYT?
I will rework this patch series. I think some of the patchsets need not be present upstream
as they have come from some customer crashes which only occur in conjunction with other
proprietary modules and features present. I will rework this one to only include changes pertinent
to code upstream.
Thanks a lot for your comments
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2024-11-16 17:26 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-13 11:13 [PATCH net v4 0/7] Double free fixes and NULL pointer checks Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes Shinas Rasheed
2024-11-13 14:59 ` Vadim Fedorenko
2024-11-13 22:38 ` Vadim Fedorenko
2024-11-16 17:25 ` [EXTERNAL] " Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 2/7] octeon_ep: Fix null dereferences to IQ/OQ pointers Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 3/7] octeon_ep: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
2024-11-13 17:59 ` Vadim Fedorenko
2024-11-13 11:13 ` [PATCH net v4 4/7] octeon_ep: add protective null checks in napi callbacks for cnxk cards Shinas Rasheed
2024-11-13 18:01 ` Vadim Fedorenko
2024-11-13 11:13 ` [PATCH net v4 5/7] octeon_ep_vf: Fix null dereferences to IQ/OQ pointers Shinas Rasheed
2024-11-13 11:13 ` [PATCH net v4 6/7] octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards Shinas Rasheed
2024-11-13 18:02 ` Vadim Fedorenko
2024-11-13 11:13 ` [PATCH net v4 7/7] octeon_ep_vf: add protective null checks in napi callbacks for cnxk cards Shinas Rasheed
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).