virtio-scsi: fix various bad behavior on aborted requests

Even though the virtio-scsi spec guarantees that all requests related
to the TMF will have been completed by the time the TMF itself completes,
the request queue's callback might not have run yet. This causes requests
to be completed more than once, and as a result triggers a variety of
BUGs or oopses.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Venkatesh Srinivas <venkateshs@google.com>
Cc: stable@vger.kernel.org
Signed-off-by: Christoph Hellwig <hch@lst.de>

authored by Paolo Bonzini and committed by Christoph Hellwig 8faeb529 cdda0e5a

Changed files
+22
drivers
+22
drivers/scsi/virtio_scsi.c
··· 237 237 virtscsi_vq_done(vscsi, req_vq, virtscsi_complete_cmd); 238 238 }; 239 239 240 + static void virtscsi_poll_requests(struct virtio_scsi *vscsi) 241 + { 242 + int i, num_vqs; 243 + 244 + num_vqs = vscsi->num_queues; 245 + for (i = 0; i < num_vqs; i++) 246 + virtscsi_vq_done(vscsi, &vscsi->req_vqs[i], 247 + virtscsi_complete_cmd); 248 + } 249 + 240 250 static void virtscsi_complete_free(struct virtio_scsi *vscsi, void *buf) 241 251 { 242 252 struct virtio_scsi_cmd *cmd = buf; ··· 600 590 if (cmd->resp.tmf.response == VIRTIO_SCSI_S_OK || 601 591 cmd->resp.tmf.response == VIRTIO_SCSI_S_FUNCTION_SUCCEEDED) 602 592 ret = SUCCESS; 593 + 594 + /* 595 + * The spec guarantees that all requests related to the TMF have 596 + * been completed, but the callback might not have run yet if 597 + * we're using independent interrupts (e.g. MSI). Poll the 598 + * virtqueues once. 599 + * 600 + * In the abort case, sc->scsi_done will do nothing, because 601 + * the block layer must have detected a timeout and as a result 602 + * REQ_ATOM_COMPLETE has been set. 603 + */ 604 + virtscsi_poll_requests(vscsi); 603 605 604 606 out: 605 607 mempool_free(cmd, virtscsi_cmd_pool);