Skip to contentSkip to conversation

net: ibm: emac: fix MR0 write in emac_rx_enable()

PATCH Superseded Rosen Penev 3 participants 5 messages Nov 5 – Nov 8

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ibm: emac: fix MR0 write in emac_rx_enable()

When an asynchronous RX disable is still in progress, emac_rx_enable() waits for MR0[RXI] with

	while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n)

which assigns only the RXI bit to r, as & binds tighter than =. The following write of r | EMAC_MR0_RXE then clears every other MR0 bit, including TXE, and TX stays stopped until the watchdog resets the EMAC.

This path is taken when RX is restarted after an RX descriptor error.

Tested on a Cisco Meraki MX60.

Fixes 1d3bb996481e ("Device tree aware EMAC driver")
---
 drivers/net/ethernet/ibm/emac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ibm/emac/core.c +1 -1
index 640618c0a09e..b676b286e339 100644
@@ -249,7 +249,7 @@ static void emac_rx_enable(struct emac_instance *dev)
 		if (unlikely(!(r & EMAC_MR0_RXI))) {
 			/* Wait if previous async disable is still in progress */
 			int n = dev->stop_timeout;
-			while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n) {
+			while (!((r = in_be32(&p->mr0)) & EMAC_MR0_RXI) && n) {
 				udelay(1);
 				--n;
 			}
Signature · 1 line
2.56.0
#1 lore raw
This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

Hi!

This is an automated message. This series looks like a fix, but its commit messages seem to be missing some information:

- How the issue was discovered, e.g. hit in production, hit during development, syzbot report, manual code inspection, LLM or static analysis tool scan.

- Whether the issue was actually triggered, or is only theoretical (e.g. found by code inspection). If it was triggered please include the symptoms, like the stack trace or error messages.

Please do not repost the series just to address the above. Instead, reply to this email with the missing information, so that reviewers can take it into account. If the series needs another revision for other reasons, please include the information in the commit messages then.

The evaluation is done by an LLM so it may be wrong, if you think that is the case please reply and explain.

#2 lore raw
In reply to Rosen Penev
Quoted 24 lines · Rosen Penev

When an asynchronous RX disable is still in progress, emac_rx_enable() waits for MR0[RXI] with

	while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n)

which assigns only the RXI bit to r, as & binds tighter than =. The following write of r | EMAC_MR0_RXE then clears every other MR0 bit, including TXE, and TX stays stopped until the watchdog resets the EMAC.

This path is taken when RX is restarted after an RX descriptor error.

Tested on a Cisco Meraki MX60.

Fixes 1d3bb996481e ("Device tree aware EMAC driver")
---
 drivers/net/ethernet/ibm/emac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ibm/emac/core.c +0 -0
index 640618c0a09e..b676b286e339 100644

drivers/net/ethernet/ibm/emac/core.c static void emac_rx_enable(struct emac_instance *dev) · line 254

Quoted 7 lines
drivers/net/ethernet/ibm/emac/core.c +1 -1
@@ -249,7 +249,7 @@ static void emac_rx_enable(struct emac_instance *dev)
 		if (unlikely(!(r & EMAC_MR0_RXI))) {
 			/* Wait if previous async disable is still in progress */
 			int n = dev->stop_timeout;
-			while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n) {
+			while (!((r = in_be32(&p->mr0)) & EMAC_MR0_RXI) && n) {
 				udelay(1);
 				--n;

This sort of code should really make use of iopoll.h

Andrew

#3 lore raw
Quoted 21 lines · Andrew Lunn
Quoted 19 lines · Rosen Penev

When an asynchronous RX disable is still in progress, emac_rx_enable() waits for MR0[RXI] with

      while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n)

which assigns only the RXI bit to r, as & binds tighter than =. The following write of r | EMAC_MR0_RXE then clears every other MR0 bit, including TXE, and TX stays stopped until the watchdog resets the EMAC.

This path is taken when RX is restarted after an RX descriptor error.

Tested on a Cisco Meraki MX60.

Fixes 1d3bb996481e ("Device tree aware EMAC driver")
---
 drivers/net/ethernet/ibm/emac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/net/ethernet/ibm/emac/core.c static void emac_rx_enable(struct emac_instance *dev) · line 254

Quoted 12 lines
drivers/net/ethernet/ibm/emac/core.c +1 -1
index 640618c0a09e..b676b286e339 100644
@@ -249,7 +249,7 @@ static void emac_rx_enable(struct emac_instance *dev)
              if (unlikely(!(r & EMAC_MR0_RXI))) {
                      /* Wait if previous async disable is still in progress */
                      int n = dev->stop_timeout;
-                     while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n) {
+                     while (!((r = in_be32(&p->mr0)) & EMAC_MR0_RXI) && n) {
                              udelay(1);
                              --n;

This sort of code should really make use of iopoll.h

I agree. Is it appropriate for net?

Quoted 2 lines

Andrew

#4 lore raw
Quoted 36 lines · Rosen Penev
Quoted 21 lines · Andrew Lunn
Quoted 19 lines · Rosen Penev

When an asynchronous RX disable is still in progress, emac_rx_enable() waits for MR0[RXI] with

      while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n)

which assigns only the RXI bit to r, as & binds tighter than =. The following write of r | EMAC_MR0_RXE then clears every other MR0 bit, including TXE, and TX stays stopped until the watchdog resets the EMAC.

This path is taken when RX is restarted after an RX descriptor error.

Tested on a Cisco Meraki MX60.

Fixes 1d3bb996481e ("Device tree aware EMAC driver")
---
 drivers/net/ethernet/ibm/emac/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines

drivers/net/ethernet/ibm/emac/core.c static void emac_rx_enable(struct emac_instance *dev) · line 254

Quoted 12 lines
drivers/net/ethernet/ibm/emac/core.c +1 -1
index 640618c0a09e..b676b286e339 100644
@@ -249,7 +249,7 @@ static void emac_rx_enable(struct emac_instance *dev)
              if (unlikely(!(r & EMAC_MR0_RXI))) {
                      /* Wait if previous async disable is still in progress */
                      int n = dev->stop_timeout;
-                     while (!(r = in_be32(&p->mr0) & EMAC_MR0_RXI) && n) {
+                     while (!((r = in_be32(&p->mr0)) & EMAC_MR0_RXI) && n) {
                              udelay(1);
                              --n;

This sort of code should really make use of iopoll.h

Quoted 1 line

I agree. Is it appropriate for net?

Yes, that is fine.

Andrew