Skip to content

Commit

Permalink
via-cuda: Avoid TREQ race condition
Browse files Browse the repository at this point in the history
When a read transaction completes, one of several things will happen:
a new transfer is started by the driver, a new transfer request
is raised by the Cuda (i.e. TREQ asserted), or both happen at once.

When both happen at once, there is a race condition between the TREQ test
in the read_done state and the same test in cuda_start(). Moreover, the
former test uses a stale TREQ value.

Theoretically, this can result in the undesirable outcome that the
interrupt handler completes with the state machine 'idle' when it should
instead start the next transaction.

Avoid this race by calling cuda_start() first and then confirming that it
succeeded. If not, test the current TREQ value before entering the
'reading' state.

Tested-by: Stan Johnson <userm57@yahoo.com>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Finn Thain authored and Michael Ellerman committed Feb 7, 2017
1 parent cfbf998 commit a646624
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions drivers/macintosh/via-cuda.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,12 +605,11 @@ cuda_interrupt(int irq, void *arg)
memcpy(ibuf, cuda_rbuf, ibuf_len);
}
reply_ptr = cuda_rbuf;
if (TREQ_asserted(status)) {
cuda_state = idle;
cuda_start();
if (cuda_state == idle && TREQ_asserted(in_8(&via[B]))) {
assert_TIP();
cuda_state = reading;
} else {
cuda_state = idle;
cuda_start();
}
break;

Expand Down

0 comments on commit a646624

Please sign in to comment.