win-pvdrivers

changeset 196:a3bf7c523a4f 0.8.4

Fixed race in xenvbd which would cause a BSoD
author James Harper <james.harper@bendigoit.com.au>
date Wed Feb 27 11:00:21 2008 +1100 (2008-02-27)
parents da58a35a8a31
children 62ff836f2d58
files common.inc xenpci/xenpci.c xenvbd/xenvbd.c xenvbd/xenvbd.h
line diff
     1.1 --- a/common.inc	Tue Feb 26 23:06:38 2008 +1100
     1.2 +++ b/common.inc	Wed Feb 27 11:00:21 2008 +1100
     1.3 @@ -1,4 +1,4 @@
     1.4 -VERSION=0.8.3.0
     1.5 +VERSION=0.8.4.0
     1.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     1.7  KMDF_VERSION=1
     1.8  !IF $(_NT_TOOLS_VERSION) > 0x700
     2.1 --- a/xenpci/xenpci.c	Tue Feb 26 23:06:38 2008 +1100
     2.2 +++ b/xenpci/xenpci.c	Wed Feb 27 11:00:21 2008 +1100
     2.3 @@ -923,6 +923,7 @@ XenBus_ShutdownHandler(char *Path, PVOID
     2.4      {
     2.5  #if 0
     2.6  // this won't work this way... 
     2.7 +// need to create a thread at PASSIVE_LEVEL, turn off xenbus, then go to DISPATCH_LEVEL on all CPU's
     2.8        if (!xpdd->suspending)
     2.9        {
    2.10          suspend_info = ExAllocatePoolWithTag(NonPagedPool, sizeof(SUSPEND_INFO), XENPCI_POOL_TAG);
     3.1 --- a/xenvbd/xenvbd.c	Tue Feb 26 23:06:38 2008 +1100
     3.2 +++ b/xenvbd/xenvbd.c	Wed Feb 27 11:00:21 2008 +1100
     3.3 @@ -265,7 +265,7 @@ if (DumpMode)
     3.4      for (j = 0; j < SCSI_TARGETS_PER_BUS; j++)
     3.5      {
     3.6        TargetData = &DeviceData->BusData[i].TargetData[j];
     3.7 -      if (TargetData->PendingInterrupt || (TargetData->Present && DumpMode))
     3.8 +      if (TargetData->Running && (TargetData->PendingInterrupt || (TargetData->Present && DumpMode)))
     3.9          XenVbd_HwScsiInterruptTarget(TargetData);
    3.10        TargetData->PendingInterrupt = FALSE;
    3.11      }
    3.12 @@ -468,6 +468,15 @@ XenVbd_BackEndStateHandler(char *Path, P
    3.13      TargetData->Geometry.TracksPerCylinder = 255;
    3.14      TargetData->Geometry.Cylinders.QuadPart = TargetData->TotalSectors / TargetData->Geometry.SectorsPerTrack / TargetData->Geometry.TracksPerCylinder;
    3.15      KdPrint((__DRIVER_NAME "     Geometry C/H/S = %d/%d/%d\n", TargetData->Geometry.Cylinders.LowPart, TargetData->Geometry.TracksPerCylinder, TargetData->Geometry.SectorsPerTrack));
    3.16 +
    3.17 +    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
    3.18 +    RtlStringCbCatA(TmpPath, 128, "/state");
    3.19 +    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateConnected);
    3.20 +
    3.21 +    KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
    3.22 +
    3.23 +    TargetData->Running = 1;
    3.24 +    KeMemoryBarrier();
    3.25      
    3.26      req = RING_GET_REQUEST(&TargetData->Ring, TargetData->Ring.req_prod_pvt);
    3.27      req->operation = 0xff;
    3.28 @@ -479,6 +488,7 @@ XenVbd_BackEndStateHandler(char *Path, P
    3.29        req->seg[i].last_sect = 0xff;
    3.30      }
    3.31      TargetData->Ring.req_prod_pvt++;
    3.32 +
    3.33      req = RING_GET_REQUEST(&TargetData->Ring, TargetData->Ring.req_prod_pvt);
    3.34      req->operation = 0xff;
    3.35      req->nr_segments = 0;
    3.36 @@ -489,17 +499,13 @@ XenVbd_BackEndStateHandler(char *Path, P
    3.37        req->seg[i].last_sect = 0xff;
    3.38      }
    3.39      TargetData->Ring.req_prod_pvt++;
    3.40 +
    3.41      RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&TargetData->Ring, notify);
    3.42      if (notify)
    3.43        DeviceData->XenDeviceData->XenInterface.EvtChn_Notify(
    3.44          DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context,
    3.45          TargetData->EventChannel);
    3.46  
    3.47 -    RtlStringCbCopyA(TmpPath, 128, TargetData->Path);
    3.48 -    RtlStringCbCatA(TmpPath, 128, "/state");
    3.49 -    DeviceData->XenDeviceData->XenInterface.XenBus_Printf(DeviceData->XenDeviceData->XenInterface.InterfaceHeader.Context, XBT_NIL, TmpPath, "%d", XenbusStateConnected);
    3.50 -
    3.51 -    KdPrint((__DRIVER_NAME "     Set Frontend state to Connected\n"));
    3.52      InterlockedIncrement(&DeviceData->EnumeratedDevices);
    3.53      KdPrint((__DRIVER_NAME "     Added a device\n"));  
    3.54  
    3.55 @@ -700,6 +706,7 @@ XenVbd_InitDeviceData(PXENVBD_DEVICE_DAT
    3.56      for (j = 0; j < SCSI_TARGETS_PER_BUS; j++)
    3.57      {
    3.58        DeviceData->BusData[i].TargetData[j].Present = 0;
    3.59 +      DeviceData->BusData[i].TargetData[j].Running = 0;
    3.60        DeviceData->BusData[i].TargetData[j].DeviceData = DeviceData;
    3.61      }
    3.62    }
    3.63 @@ -1021,7 +1028,7 @@ if (DumpMode)
    3.64  
    3.65    TargetData = &DeviceData->BusData[Srb->PathId].TargetData[Srb->TargetId];
    3.66  
    3.67 -  if (!TargetData->Present)
    3.68 +  if (!TargetData->Running)
    3.69    {
    3.70      Srb->SrbStatus = SRB_STATUS_NO_DEVICE;
    3.71      ScsiPortNotification(RequestComplete, DeviceExtension, Srb);
     4.1 --- a/xenvbd/xenvbd.h	Tue Feb 26 23:06:38 2008 +1100
     4.2 +++ b/xenvbd/xenvbd.h	Wed Feb 27 11:00:21 2008 +1100
     4.3 @@ -77,6 +77,7 @@ typedef enum {
     4.4  struct
     4.5  {
     4.6    int Present;
     4.7 +  int Running;
     4.8    BOOLEAN PendingInterrupt;
     4.9    PVOID DeviceData; // how can we create a forward definition for this???
    4.10    evtchn_port_t EventChannel;