Skip to contentSkip to conversation

i2c: xiic: Don't try to handle more interrupt events after error

PATCH Applied Robert Hancock 3 participants 9 messages Jun 6, 2023 – Jul 6, 2023

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

PATCH 1/1 i2c: xiic: Don't try to handle more interrupt events after error

In xiic_process, it is possible that error events such as arbitration lost or TX error can be raised in conjunction with other interrupt flags such as TX FIFO empty or bus not busy. Error events result in the controller being reset and the error returned to the calling request, but the function could potentially try to keep handling the other events, such as by writing more messages into the TX FIFO. Since the transaction has already failed, this is not helpful and will just cause issues.

This problem has been present ever since:

commit 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

which allowed non-error events to be handled after errors, but became more obvious after:

commit 743e227a8959 ("i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process()")

which reworked the code to add a WARN_ON which triggers if both the xfer_more and wakeup_req flags were set, since this combination is not supposed to happen, but was occurring in this scenario.

Skip further interrupt handling after error flags are detected to avoid this problem.

Fixes 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")
---
 drivers/i2c/busses/i2c-xiic.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-xiic.c +2 -0
index 8a3d9817cb41..ee6edc963dea 100644
@@ -721,6 +721,8 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
 			wakeup_req = 1;
 			wakeup_code = STATE_ERROR;
 		}
+		/* don't try to handle other events */
+		goto out;
 	}
 	if (pend & XIIC_INTR_RX_FULL_MASK) {
 		/* Receive register/FIFO is full */
Signature · 7 lines
2.40.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer
#1 lore raw

Hi Robert,

Quoted 8 lines · Robert Hancock

In xiic_process, it is possible that error events such as arbitration lost or TX error can be raised in conjunction with other interrupt flags such as TX FIFO empty or bus not busy. Error events result in the controller being reset and the error returned to the calling request, but the function could potentially try to keep handling the other events, such as by writing more messages into the TX FIFO. Since the transaction has already failed, this is not helpful and will just cause issues.

what kind of issues?

Quoted 14 lines

This problem has been present ever since:

commit 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

which allowed non-error events to be handled after errors, but became more obvious after:

commit 743e227a8959 ("i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process()")

which reworked the code to add a WARN_ON which triggers if both the xfer_more and wakeup_req flags were set, since this combination is not supposed to happen, but was occurring in this scenario.

Quoted 5 lines

Skip further interrupt handling after error flags are detected to avoid this problem.

Fixes 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

please add:

Cc <[email protected]> # v4.3+
Quoted 9 lines
---
 drivers/i2c/busses/i2c-xiic.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/i2c/busses/i2c-xiic.c +0 -0
index 8a3d9817cb41..ee6edc963dea 100644

drivers/i2c/busses/i2c-xiic.c static irqreturn_t xiic_process(int irq, void *dev_id) · line 725

Quoted 5 lines
drivers/i2c/busses/i2c-xiic.c +2 -0
@@ -721,6 +721,8 @@ static irqreturn_t xiic_process(int irq, void *dev_id)
 			wakeup_req = 1;
 			wakeup_code = STATE_ERROR;
 		}
+		/* don't try to handle other events */
+		goto out;

why don't we have goto's after every irq evaluation but only here? Do the issues you mentioned happen olny in this particular error case?

Thanks,
Andi

Quoted 6 lines
drivers/i2c/busses/i2c-xiic.c +0 -0
 	}
 	if (pend & XIIC_INTR_RX_FULL_MASK) {
 		/* Receive register/FIFO is full */
Signature · 1 line
2.40.1
#2 lore raw
Quoted 17 lines · Andi Shyti

Hi Robert,

Quoted 5 lines · Robert Hancock

In xiic_process, it is possible that error events such as arbitration
lost or TX error can be raised in conjunction with other interrupt flags
such as TX FIFO empty or bus not busy. Error events result in the

Quoted 8 lines

controller being reset and the error returned to the calling request,
but the function could potentially try to keep handling the other events, such as by writing more messages into the TX FIFO. Since the
transaction has already failed, this is not helpful and will just cause
issues.

Quoted 2 lines

what kind of issues?

The one I ran into is what I alluded to further down, where that WARN_ON was triggering repeatedly, which ended up flooding the kernel log and causing the device's watchdog timer to timeout. I'm not sure what other forms of havoc might ensue, other than "nothing good"..

Quoted 19 lines
Quoted 19 lines

This problem has been present ever since:

commit 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

which allowed non-error events to be handled after errors, but became
more obvious after:

commit 743e227a8959 ("i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process()")

which reworked the code to add a WARN_ON which triggers if both the xfer_more and wakeup_req flags were set, since this combination is not supposed to happen, but was occurring in this scenario.

Skip further interrupt handling after error flags are detected to avoid
this problem.

Quoted 7 lines
Quoted 2 lines
Fixes 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

please add:

Cc <[email protected]> # v4.3+

Can add for a v2 - although with the Fixes tag it would most likely be picked up for stable anyway..

Quoted 4 lines
Quoted 4 lines

---
 drivers/i2c/busses/i2c-xiic.c | 2 ++

 1 file changed, 2 insertions(+)
Quoted 17 lines

drivers/i2c/busses/i2c-xiic.c static irqreturn_t xiic_process(int irq, void · line 726

Quoted 12 lines
drivers/i2c/busses/i2c-xiic.c +2 -0
index 8a3d9817cb41..ee6edc963dea 100644
@@ -721,6 +721,8 @@ static irqreturn_t xiic_process(int irq, void
 *dev_id)
                       wakeup_req = 1;
                       wakeup_code = STATE_ERROR;
               }
+             /* don't try to handle other events */
+             goto out;

why don't we have goto's after every irq evaluation but only here? Do the issues you mentioned happen olny in this particular error case?

As far as I can tell, yes. For example you could legitimately have XIIC_INTR_TX_EMPTY_MASK and XIIC_INTR_BNB_MASK both being handled. The error case is special as we end up resetting the controller, so it doesn't make sense to try to continue with the rest of the transaction while also completing it with an error.

Quoted 9 lines

Thanks,
Andi

Quoted 6 lines
drivers/i2c/busses/i2c-xiic.c +0 -0
       }
       if (pend & XIIC_INTR_RX_FULL_MASK) {

              /* Receive register/FIFO is full */
--
2.40.1

Signature · 5 lines
Robert Hancock <[email protected]>
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Acked-by
#3 lore raw

Hi Robert,

Quoted 48 lines · Robert Hancock
Quoted 17 lines · Andi Shyti

Hi Robert,

Quoted 5 lines · Robert Hancock

In xiic_process, it is possible that error events such as arbitration
lost or TX error can be raised in conjunction with other interrupt flags
such as TX FIFO empty or bus not busy. Error events result in the

Quoted 8 lines

controller being reset and the error returned to the calling request,
but the function could potentially try to keep handling the other events, such as by writing more messages into the TX FIFO. Since the
transaction has already failed, this is not helpful and will just cause
issues.

Quoted 2 lines

what kind of issues?

The one I ran into is what I alluded to further down, where that WARN_ON was triggering repeatedly, which ended up flooding the kernel log and causing the device's watchdog timer to timeout. I'm not sure what other forms of havoc might ensue, other than "nothing good"..

Quoted 22 lines
Quoted 21 lines

This problem has been present ever since:

commit 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

which allowed non-error events to be handled after errors, but became
more obvious after:

commit 743e227a8959 ("i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process()")

which reworked the code to add a WARN_ON which triggers if both the xfer_more and wakeup_req flags were set, since this combination is not supposed to happen, but was occurring in this scenario.

Skip further interrupt handling after error flags are detected to avoid
this problem.

Fixes 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")
Quoted 7 lines
Quoted 4 lines

please add:

Cc <[email protected]> # v4.3+

Can add for a v2 - although with the Fixes tag it would most likely be picked up for stable anyway..

It's just a courtesy to stable maintainers :)

Quoted 22 lines
Quoted 4 lines
Quoted 4 lines

---
 drivers/i2c/busses/i2c-xiic.c | 2 ++

 1 file changed, 2 insertions(+)
Quoted 17 lines

drivers/i2c/busses/i2c-xiic.c static irqreturn_t xiic_process(int irq, void · line 726

Quoted 12 lines
drivers/i2c/busses/i2c-xiic.c +2 -0
index 8a3d9817cb41..ee6edc963dea 100644
@@ -721,6 +721,8 @@ static irqreturn_t xiic_process(int irq, void
 *dev_id)
                       wakeup_req = 1;
                       wakeup_code = STATE_ERROR;
               }
+             /* don't try to handle other events */
+             goto out;

why don't we have goto's after every irq evaluation but only here? Do the issues you mentioned happen olny in this particular error case?

Quoted 5 lines

As far as I can tell, yes. For example you could legitimately have XIIC_INTR_TX_EMPTY_MASK and XIIC_INTR_BNB_MASK both being handled. The error case is special as we end up resetting the controller, so it doesn't make sense to try to continue with the rest of the transaction while also completing it with an error.

I think the patch is correct and I will ack it:

I think, though, that this needs a proper fix and testing, in order to cover all the possible combinations. The scenario you highlighted is indeed one, but not only, potential situation that could arise.

Can I just ask you to write a bit more in the comment to highlight the possible failure?

Thanks a lot,
Andi

Quoted 12 lines
Quoted 9 lines

Thanks,
Andi

Quoted 6 lines
drivers/i2c/busses/i2c-xiic.c +0 -0
       }
       if (pend & XIIC_INTR_RX_FULL_MASK) {

              /* Receive register/FIFO is full */
--
2.40.1

Signature · 1 line
Robert Hancock <[email protected]>
#4 lore raw
Quoted 5 lines

I think the patch is correct and I will ack it:

Quoted 7 lines

I think, though, that this needs a proper fix and testing, in order to cover all the possible combinations. The scenario you highlighted is indeed one, but not only, potential situation that could arise.

Can I just ask you to write a bit more in the comment to highlight the possible failure?

I tend to apply it to for-current because it improves the situation. Further improvements could be made incrementally? D'accord everyone?

maintainer
#5 lore raw

Hi Wolfram,

Quoted 10 lines · On Fri, Jun 09, 2023 at 05:32:42PM +0200, [email protected] wrote:
Quoted 10 lines

I think the patch is correct and I will ack it:

I think, though, that this needs a proper fix and testing, in order to cover all the possible combinations. The scenario you highlighted is indeed one, but not only, potential situation that could arise.

Quoted 6 lines
Quoted 2 lines

Can I just ask you to write a bit more in the comment to highlight the possible failure?

I tend to apply it to for-current because it improves the situation. Further improvements could be made incrementally? D'accord everyone?

OK with that!

Thanks,
Andi

#6 lore raw
Quoted 22 lines · Andi Shyti

Hi Wolfram,

Quoted 10 lines · On Fri, Jun 09, 2023 at 05:32:42PM +0200, [email protected] wrote:
Quoted 10 lines

I think the patch is correct and I will ack it:

I think, though, that this needs a proper fix and testing, in order to cover all the possible combinations. The scenario you highlighted is indeed one, but not only, potential situation that could arise.

Quoted 8 lines
Quoted 2 lines

Can I just ask you to write a bit more in the comment to highlight the possible failure?

I tend to apply it to for-current because it improves the situation.
Further improvements could be made incrementally? D'accord everyone?

Quoted 4 lines

OK with that!

Thanks,
Andi

Just checking on this patch, was it merged? It shows accepted in Patchwork, but I'm not seeing it in the Git tree.

Signature · 1 line
Robert Hancock <[email protected]>
#7 lore raw
Quoted 3 lines

Just checking on this patch, was it merged? It shows accepted in Patchwork, but I'm not seeing it in the Git tree.

Sorry, it seems I forgot to apply it? I will make sure it will go in this merge window now.

Applied
#8 lore raw
In reply to Robert Hancock
Quoted 23 lines · Robert Hancock

In xiic_process, it is possible that error events such as arbitration lost or TX error can be raised in conjunction with other interrupt flags such as TX FIFO empty or bus not busy. Error events result in the controller being reset and the error returned to the calling request, but the function could potentially try to keep handling the other events, such as by writing more messages into the TX FIFO. Since the transaction has already failed, this is not helpful and will just cause issues.

This problem has been present ever since:

commit 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

which allowed non-error events to be handled after errors, but became more obvious after:

commit 743e227a8959 ("i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process()")

which reworked the code to add a WARN_ON which triggers if both the xfer_more and wakeup_req flags were set, since this combination is not supposed to happen, but was occurring in this scenario.

Quoted 5 lines

Skip further interrupt handling after error flags are detected to avoid this problem.

Fixes 7f9906bd7f72 ("i2c: xiic: Service all interrupts in isr")

Applied to for-current, thanks!