Skip to contentSkip to conversation

Double free fixes and NULL pointer checks

PATCH In review Shinas Rasheed 2 participants 14 messages Nov 13, 2024 – Nov 16, 2024

Subsystems (4)
lore
Share & tools
lore

Shinas Rasheed

author maintainer
#0 lore raw

v4 cover Double free fixes and NULL pointer checks

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/[email protected]/
- Added back "fixes" to the Changes listed

V2: https://lore.kernel.org/all/[email protected]/
- Added more context in commit messages and split patches for each commit fix

V1: https://lore.kernel.org/all/[email protected]/

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(-)
Signature · 1 line
2.25.1
author maintainer
#1 lore raw

PATCH v4 1/7 octeon_ep: Add checks to fix double free crashes

From: Vimlesh Kumar <[email protected]>

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")

---
V4:
- Removed unnecessary protective code. Added fast return from octep_free_irqs()
- Improved commit message

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- No changes

V1: https://lore.kernel.org/all/[email protected]/

 .../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(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +10 -4
index 549436efc204..29796544feb6 100644
@@ -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);
 	}
 }
 
drivers/net/ethernet/marvell/octeon_ep/octep_tx.c +2 -0
index 06851b78aa28..157bf489ae19 100644
@@ -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);
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes

Quoted 43 lines · Shinas Rasheed

From: Vimlesh Kumar <[email protected]>

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")

---
V4:
- Removed unnecessary protective code. Added fast return from octep_free_irqs()
- Improved commit message

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- No changes

V1: https://lore.kernel.org/all/[email protected]/

  .../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(-)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +3 -0
index 549436efc204..29796544feb6 100644
@@ -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);

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_free_irqs(struct octep_device *oct) · line 511

Quoted 5 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +1 -1
@@ -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...

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_napi_delete(struct octep_device *oct) · line 644

Quoted 13 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +4 -2
  	}
  	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.

drivers/net/ethernet/marvell/octeon_ep/octep_main.c static void octep_napi_disable(struct octep_device *oct) · line 675

Quoted 10 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +2 -1
  	}
  }
 
@@ -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.

Quoted 16 lines
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +0 -0
  	}
  }
 
drivers/net/ethernet/marvell/octeon_ep/octep_tx.c +2 -0
index 06851b78aa28..157bf489ae19 100644
@@ -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);
#3 lore raw

Re: [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes

In reply to Shinas Rasheed
Quoted 6 lines · Shinas Rasheed

From: Vimlesh Kumar <[email protected]>

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?

author maintainer
#4 lore raw

RE: [EXTERNAL] Re: [PATCH net v4 1/7] octeon_ep: Add checks to fix double free crashes

Hi Vadim,

Quoted 8 lines · Shinas Rasheed
Quoted 6 lines

From: Vimlesh Kumar <[email protected]>

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.

Quoted 6 lines

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

author maintainer
#5 lore raw

PATCH v4 2/7 octeon_ep: Fix null dereferences to IQ/OQ pointers

In reply to Shinas Rasheed

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")

---
V4:
- No change

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split from earlier patch into a separate patch
- Added more context

V2: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/marvell/octeon_ep/octep_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/marvell/octeon_ep/octep_main.c +3 -0
index 29796544feb6..3cea7811e48d 100644
@@ -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;
Signature · 1 line
2.25.1
author maintainer
#6 lore raw

PATCH v4 3/7 octeon_ep: add protective null checks in napi callbacks for cn9k cards

In reply to Shinas Rasheed

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")

---
V4:
- No changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +8 -1
index b5805969404f..b87336b2e4b9 100644
@@ -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;
Signature · 1 line
2.25.1
#7 lore raw

Re: [PATCH net v4 3/7] octeon_ep: add protective null checks in napi callbacks for cn9k cards

Quoted 27 lines · Shinas Rasheed

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")

---
V4:
- No changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

  drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +0 -0
index b5805969404f..b87336b2e4b9 100644

drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c static irqreturn_t octep_rsvd_intr_handler_cn93_pf(void *dev) · line 623

Quoted 8 lines
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +4 -1
@@ -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.

Quoted 7 lines
drivers/net/ethernet/marvell/octeon_ep/octep_cn9k_pf.c +4 -0
+	oq = vector->oq;
+
+	if (!oq || !(oq->napi))
+		return IRQ_HANDLED;
 
  	napi_schedule_irqoff(oq->napi);
  	return IRQ_HANDLED;
author maintainer
#8 lore raw

PATCH v4 4/7 octeon_ep: add protective null checks in napi callbacks for cnxk cards

In reply to Shinas Rasheed

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")

---
V4:
- No Changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c +8 -1
index 5de0b5ecbc5f..65a8dc1d492b 100644
@@ -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;
Signature · 1 line
2.25.1
#9 lore raw

Re: [PATCH net v4 4/7] octeon_ep: add protective null checks in napi callbacks for cnxk cards

Quoted 27 lines · Shinas Rasheed

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")

---
V4:
- No Changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

  drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c +0 -0
index 5de0b5ecbc5f..65a8dc1d492b 100644

drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c static irqreturn_t octep_rsvd_intr_handler_cnxk_pf(void *dev) · line 644

Quoted 8 lines
drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c +4 -1
@@ -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

Quoted 7 lines
drivers/net/ethernet/marvell/octeon_ep/octep_cnxk_pf.c +4 -0
+	oq = vector->oq;
+
+	if (!oq || !(oq->napi))
+		return IRQ_HANDLED;
 
  	napi_schedule_irqoff(oq->napi);
  	return IRQ_HANDLED;
author maintainer
#10 lore raw

PATCH v4 5/7 octeon_ep_vf: Fix null dereferences to IQ/OQ pointers

In reply to Shinas Rasheed

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")

---
V4:
- No Changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_main.c +3 -0
index 7e6771c9cdbb..79d9ffd593eb 100644
@@ -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;
Signature · 1 line
2.25.1
author maintainer
#11 lore raw

PATCH v4 6/7 octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards

In reply to Shinas Rasheed

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")

---
V4:
- No changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

 drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +7 -1
index 88937fce75f1..f1b7eda3fa42 100644
@@ -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));
Signature · 1 line
2.25.1
#12 lore raw

Re: [PATCH net v4 6/7] octeon_ep_vf: add protective null checks in napi callbacks for cn9k cards

Quoted 27 lines · Shinas Rasheed

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")

---
V4:
- No changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

  drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +0 -0
index 88937fce75f1..f1b7eda3fa42 100644

drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c static irqreturn_t octep_vf_ioq_intr_handler_cn93(void *data) · line 277

Quoted 6 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +2 -1
@@ -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.

Quoted 9 lines
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cn9k.c +5 -0
+
  	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));
author maintainer
#13 lore raw

PATCH v4 7/7 octeon_ep_vf: add protective null checks in napi callbacks for cnxk cards

In reply to Shinas Rasheed

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")

---
V4:
- No Changes

V3: https://lore.kernel.org/all/[email protected]/
- Added back "Fixes" to the changelist

V2: https://lore.kernel.org/all/[email protected]/
- Split into a separate patch
- Added more context

V1: https://lore.kernel.org/all/[email protected]/

 .../ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c    | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeon_ep_vf/octep_vf_cnxk.c +11 -1
index 1f79dfad42c6..31c0d7c0492a 100644
@@ -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;
 }
Signature · 1 line
2.25.1