[PATCH v2 10/10] esp: recreate ESPState current_req after migration

Mark Cave-Ayland posted 10 patches 3 years, 11 months ago
Maintainers: Laurent Vivier <laurent@vivier.eu>, Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>
There is a newer version of this series
[PATCH v2 10/10] esp: recreate ESPState current_req after migration
Posted by Mark Cave-Ayland 3 years, 11 months ago
Since PDMA reads/writes are driven by the guest, it is possible that migration
can occur whilst a SCSIRequest is still active. Fortunately active SCSIRequests
are already included in the migration stream and restarted post migration but
this still leaves the reference in ESPState uninitialised.

Implement the SCSIBusInfo .load_request callback to obtain a reference to the
currently active SCSIRequest and use it to recreate ESPState current_req
after migration.

Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/scsi/esp.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
index 32926834bc..824c345ceb 100644
--- a/hw/scsi/esp.c
+++ b/hw/scsi/esp.c
@@ -1341,6 +1341,15 @@ static uint64_t sysbus_esp_pdma_read(void *opaque, hwaddr addr,
     return val;
 }
 
+static void *esp_load_request(QEMUFile *f, SCSIRequest *req)
+{
+    ESPState *s = container_of(req->bus, ESPState, bus);
+
+    scsi_req_ref(req);
+    s->current_req = req;
+    return s;
+}
+
 static const MemoryRegionOps sysbus_esp_pdma_ops = {
     .read = sysbus_esp_pdma_read,
     .write = sysbus_esp_pdma_write,
@@ -1356,6 +1365,7 @@ static const struct SCSIBusInfo esp_scsi_info = {
     .max_target = ESP_MAX_DEVS,
     .max_lun = 7,
 
+    .load_request = esp_load_request,
     .transfer_data = esp_transfer_data,
     .complete = esp_command_complete,
     .cancel = esp_request_cancelled
-- 
2.20.1
Re: [PATCH v2 10/10] esp: recreate ESPState current_req after migration
Posted by Laurent Vivier 3 years, 11 months ago
Le 02/03/2022 à 22:27, Mark Cave-Ayland a écrit :
> Since PDMA reads/writes are driven by the guest, it is possible that migration
> can occur whilst a SCSIRequest is still active. Fortunately active SCSIRequests
> are already included in the migration stream and restarted post migration but
> this still leaves the reference in ESPState uninitialised.
> 
> Implement the SCSIBusInfo .load_request callback to obtain a reference to the
> currently active SCSIRequest and use it to recreate ESPState current_req
> after migration.
> 
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>   hw/scsi/esp.c | 10 ++++++++++
>   1 file changed, 10 insertions(+)
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>