Skip to contentSkip to conversation

ibm_newemac: Fixes kernel crashes when speed of cable connected changes

PATCH Superseded Stefan Roese 3 participants 4 messages Jun 23, 2008 – Jun 27, 2008

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ibm_newemac: Fixes kernel crashes when speed of cable connected changes

From: Sathya Narayanan <[email protected]>

The descriptor pointers were not initialized to NIL values, so it was poiniting to some random addresses which was completely invalid. This fix takes care of initializing the descriptor to NIL values and clearing the valid descriptors on clean ring operation.

---
 drivers/net/ibm_newemac/core.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/net/ibm_newemac/core.c +5 -1
index 5d2108c..6dfc2c9 100644
@@ -1025,7 +1025,7 @@ static void emac_clean_tx_ring(struct emac_instance *dev)
 	int i;
 
 	for (i = 0; i < NUM_TX_BUFF; ++i) {
-		if (dev->tx_skb[i]) {
+		if (dev->tx_skb[i] && dev->tx_desc[i].data_ptr) {
 			dev_kfree_skb(dev->tx_skb[i]);
 			dev->tx_skb[i] = NULL;
 			if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY)
@@ -2719,6 +2719,10 @@ static int __devinit emac_probe(struct of_device *ofdev,
 	/* Clean rings */
 	memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct mal_descriptor));
 	memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct mal_descriptor));
+	for (i = 0; i <= NUM_TX_BUFF; i++)
+		dev->tx_skb[i] = NULL;
+	for (i = 0; i <= NUM_RX_BUFF; i++)
+		dev->rx_skb[i] = NULL;
 
 	/* Attach to ZMII, if needed */
 	if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII) &&
Signature · 1 line
1.5.6
#1 lore raw
Quoted 18 lines · Stefan Roese

From: Sathya Narayanan <[email protected]>

The descriptor pointers were not initialized to NIL values, so it was poiniting to some random addresses which was completely invalid. This fix takes care of initializing the descriptor to NIL values and clearing the valid descriptors on clean ring operation.

---
 drivers/net/ibm_newemac/core.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/net/ibm_newemac/core.c +0 -0
index 5d2108c..6dfc2c9 100644

drivers/net/ibm_newemac/core.c static void emac_clean_tx_ring(struct emac_instance *dev) · line 1028

Quoted 5 lines
drivers/net/ibm_newemac/core.c +1 -1
@@ -1025,7 +1025,7 @@ static void emac_clean_tx_ring(struct emac_instance *dev)
 	int i;
 
 	for (i = 0; i < NUM_TX_BUFF; ++i) {
-		if (dev->tx_skb[i]) {
+		if (dev->tx_skb[i] && dev->tx_desc[i].data_ptr) {

Why changing the test above ?

drivers/net/ibm_newemac/core.c static int __devinit emac_probe(struct of_device *ofdev, · line 2725

Quoted 11 lines
drivers/net/ibm_newemac/core.c +4 -0
 			dev_kfree_skb(dev->tx_skb[i]);
 			dev->tx_skb[i] = NULL;
 			if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY)
@@ -2719,6 +2719,10 @@ static int __devinit emac_probe(struct of_device *ofdev,
 	/* Clean rings */
 	memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct mal_descriptor));
 	memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct mal_descriptor));
+	for (i = 0; i <= NUM_TX_BUFF; i++)
+		dev->tx_skb[i] = NULL;
+	for (i = 0; i <= NUM_RX_BUFF; i++)
+		dev->rx_skb[i] = NULL;

Why not use memset here too ?

Quoted 2 lines
drivers/net/ibm_newemac/core.c +0 -0
 	/* Attach to ZMII, if needed */
 	if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII) &&
#2 lore raw

Hi benh,

Please find my comments inline.

Thanks and regards,
SathyaNarayanan

Quoted 21 lines · Benjamin Herrenschmidt
Quoted 7 lines · Stefan Roese

From: Sathya Narayanan <[email protected]>

The descriptor pointers were not initialized to NIL values, so it was poiniting to some random addresses which was completely invalid. This fix takes care of initializing the descriptor to NIL values and clearing the valid descriptors on clean ring operation.

Review

Quoted 7 lines
---
 drivers/net/ibm_newemac/core.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
(quoted diff) +0 -0

b/drivers/net/ibm_newemac/core.c

drivers/net/ibm_newemac/core.c static void emac_clean_tx_ring(struct emac_instance

Quoted 4 lines

index 5d2108c..6dfc2c9 100644

drivers/net/ibm_newemac/core.c +0 -0
@@ -1025,7 +1025,7 @@ static void emac_clean_tx_ring(struct emac_instance

*dev)

Quoted 7 lines

drivers/net/ibm_newemac/core.c static void emac_clean_tx_ring(struct emac_instance *dev) · line 1028

Quoted 5 lines
drivers/net/ibm_newemac/core.c +1 -1
      int i;
 
      for (i = 0; i < NUM_TX_BUFF; ++i) {
-             if (dev->tx_skb[i]) {
+             if (dev->tx_skb[i] && dev->tx_desc[i].data_ptr) {

Why changing the test above ?

The reason for changing this condition is , In any of the case if the
dev->tx_skb is not containing valid address, Then while clearing it you may be resulted in "address voilations". This additional condition ensures that we are clearing the valid skbs.
Further this condition is not in general data flow, So this additional condition should not have any impact on performance.

Quoted 10 lines

drivers/net/ibm_newemac/core.c static int __devinit emac_probe(struct of_device

Quoted 6 lines
drivers/net/ibm_newemac/core.c +0 -0
                      dev_kfree_skb(dev->tx_skb[i]);
                      dev->tx_skb[i] = NULL;
                      if (dev->tx_desc[i].ctrl & MAL_TX_CTRL_READY)
@@ -2719,6 +2719,10 @@ static int __devinit emac_probe(struct of_device

*ofdev,

drivers/net/ibm_newemac/core.c static int __devinit emac_probe(struct of_device · line 2720

Quoted 2 lines
drivers/net/ibm_newemac/core.c +0 -0
      /* Clean rings */
      memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct

mal_descriptor));

Quoted 8 lines

drivers/net/ibm_newemac/core.c static int __devinit emac_probe(struct of_device · line 2721

Quoted 1 line
drivers/net/ibm_newemac/core.c +0 -0
      memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct

mal_descriptor));

drivers/net/ibm_newemac/core.c static int __devinit emac_probe(struct of_device *ofdev, · line 2725

Quoted 4 lines
drivers/net/ibm_newemac/core.c +4 -0
+     for (i = 0; i <= NUM_TX_BUFF; i++)
+             dev->tx_skb[i] = NULL;
+     for (i = 0; i <= NUM_RX_BUFF; i++)
+             dev->rx_skb[i] = NULL;

Why not use memset here too ?

Yes, It was valid to use memset here. I can send the modified patch for
it.

Quoted 6 lines

drivers/net/ibm_newemac/core.c static int __devinit emac_probe(struct of_device *ofdev, · line 2728

Quoted 4 lines
drivers/net/ibm_newemac/core.c +0 -0
      /* Attach to ZMII, if needed */
      if (emac_has_feature(dev, EMAC_FTR_HAS_ZMII) &&

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/linuxppc-dev

#3 lore raw
Quoted 10 lines
        
        >       for (i = 0; i < NUM_TX_BUFF; ++i) {
        > -             if (dev->tx_skb[i]) {
        > +             if (dev->tx_skb[i] &&
        dev->tx_desc[i].data_ptr) {
        
        
        Why changing the test above ?
Quoted 6 lines

The reason for changing this condition is , In any of the case if
the dev->tx_skb is not containing valid address, Then while clearing it you may be resulted in "address voilations". This additional condition ensures that we are clearing the valid skbs. Further this condition is not in general data flow, So this additional condition should not have any impact on performance.

Do you see -any- case where tx_skb[i] and dev->tx_desc[i].data_ptr would be out of sync ? If that's the case, shouldn't we cleanup instead of leaving some kind of stale entry in the ring ?

In addition, in pure theory, data_ptr == 0 is a valid DMA address :-) So I think that part of the patch shouldn't be there.

Quoted 20 lines
        
        >                       dev_kfree_skb(dev->tx_skb[i]);
        >                       dev->tx_skb[i] = NULL;
        >                       if (dev->tx_desc[i].ctrl &
        MAL_TX_CTRL_READY)
        > @@ -2719,6 +2719,10 @@ static int __devinit
        emac_probe(struct of_device *ofdev,
        >       /* Clean rings */
        >       memset(dev->tx_desc, 0, NUM_TX_BUFF * sizeof(struct
        mal_descriptor));
        >       memset(dev->rx_desc, 0, NUM_RX_BUFF * sizeof(struct
        mal_descriptor));
        > +     for (i = 0; i <= NUM_TX_BUFF; i++)
        > +             dev->tx_skb[i] = NULL;
        > +     for (i = 0; i <= NUM_RX_BUFF; i++)
        > +             dev->rx_skb[i] = NULL;
        
        
        Why not use memset here too ?
    Yes, It was valid to use memset here. I can send the modified
Quoted 1 line

patch for it.

Please do, thanks.

Cheers,
Ben.