Tyrel Datwyler a264cf5e81 scsi: ibmvfc: Fix command state accounting and stale response detection
Prior to commit 1f4a4a19508d ("scsi: ibmvfc: Complete commands outside the
host/queue lock") responses to commands were completed sequentially with
the host lock held such that a command had a basic binary state of active
or free. It was therefore a simple affair of ensuring the assocaiated
ibmvfc_event to a VIOS response was valid by testing that it was not
already free. The lock relexation work to complete commands outside the
lock inadverdently made it a trinary command state such that a command is
either in flight, received and being completed, or completed and now
free. This breaks the stale command detection logic as a command may be
still marked active and been placed on the delayed completion list when a
second stale response for the same command arrives. This can lead to double
completions and list corruption. This issue was exposed by a recent VIOS
regression were a missing memory barrier could occasionally result in the
ibmvfc client receiving a duplicate response for the same command.

Fix the issue by introducing the atomic ibmvfc_event.active to track the
trinary state of a command. The state is explicitly set to 1 when a command
is successfully sent. The CRQ response handlers use
atomic_dec_if_positive() to test for stale responses and correctly
transition to the completion state when a active command is received.
Finally, atomic_dec_and_test() is used to sanity check transistions when
commands are freed as a result of a completion, or moved to the purge list
as a result of error handling or adapter reset.

Link: https://lore.kernel.org/r/20210716205220.1101150-1-tyreld@linux.ibm.com
Fixes: 1f4a4a19508d ("scsi: ibmvfc: Complete commands outside the host/queue lock")
Cc: stable@vger.kernel.org
Signed-off-by: Tyrel Datwyler <tyreld@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2021-07-29 21:58:35 -04:00
..
2021-07-07 13:30:01 -07:00
2021-07-10 09:22:44 -07:00
2021-06-30 15:51:09 -07:00
2021-07-09 12:05:33 -07:00
2021-07-10 09:46:20 -07:00
2021-06-30 15:34:19 -06:00
2021-07-10 09:22:44 -07:00
2021-07-10 09:22:44 -07:00
2021-06-17 17:37:18 -07:00
2021-06-29 10:53:48 -07:00
2021-07-05 13:51:41 -07:00
2021-07-10 09:46:20 -07:00
2021-07-05 12:10:34 -07:00
2021-07-08 12:28:15 -07:00
2021-07-10 11:53:06 -07:00
2021-07-03 11:13:22 -07:00
2021-07-10 09:46:20 -07:00
2021-07-05 14:08:24 -07:00
2021-07-09 15:35:13 +02:00
2021-07-05 14:08:24 -07:00
2021-07-05 13:51:41 -07:00
2021-06-30 12:12:56 -07:00
2021-07-05 13:51:41 -07:00
2021-07-05 14:08:24 -07:00
2021-07-09 12:05:33 -07:00
2021-07-10 09:22:44 -07:00
2021-07-04 11:55:13 -07:00
2021-07-09 12:05:33 -07:00
2021-07-03 10:54:08 -07:00
2021-07-10 11:57:57 -07:00
2021-07-05 13:51:41 -07:00
2021-07-05 12:10:34 -07:00
2021-07-07 10:50:03 -07:00
2021-07-10 09:46:20 -07:00
2021-07-10 16:19:10 -07:00
2021-07-10 09:46:20 -07:00
2021-07-05 14:08:24 -07:00
2021-07-03 11:49:33 -07:00
2021-07-09 11:06:29 -07:00
2021-07-07 12:57:46 -07:00
2021-07-07 11:07:13 -07:00
2021-06-29 11:21:35 -07:00