win-pvdrivers

changeset 130:1c286bc336b0

xennet: don't free pages if EndAccess fails; use "if_cxt" local var to shorten long lines with InterfaceHeader.Context
author Andy Grover <andy.grover@oracle.com>
date Thu Jan 17 12:20:28 2008 -0800 (2008-01-17)
parents cf3c845b4ae4
children 415597314479
files xennet/xennet.c
line diff
     1.1 --- a/xennet/xennet.c	Thu Jan 17 12:03:47 2008 -0800
     1.2 +++ b/xennet/xennet.c	Thu Jan 17 12:20:28 2008 -0800
     1.3 @@ -1596,6 +1596,7 @@ XenNet_Halt(
     1.4  {
     1.5    struct xennet_info *xi = MiniportAdapterContext;
     1.6    CHAR TmpPath[MAX_XENBUS_STR_LEN];
     1.7 +  PVOID if_cxt = xi->XenInterface.InterfaceHeader.Context;
     1.8  
     1.9    KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    1.10    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    1.11 @@ -1606,23 +1607,23 @@ XenNet_Halt(
    1.12    // set frontend state to 'closing'
    1.13    xi->state = XenbusStateClosing;
    1.14    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
    1.15 -  xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
    1.16 -    XBT_NIL, TmpPath, "%d", xi->state);
    1.17 +  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
    1.18  
    1.19    // wait for backend to set 'Closing' state
    1.20  
    1.21    while (xi->backend_state != XenbusStateClosing)
    1.22 -    KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, NULL);
    1.23 +    KeWaitForSingleObject(&xi->backend_state_change_event, Executive,
    1.24 +      KernelMode, FALSE, NULL);
    1.25  
    1.26    // set frontend state to 'closed'
    1.27    xi->state = XenbusStateClosed;
    1.28    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->pdo_data->Path);
    1.29 -  xi->XenInterface.XenBus_Printf(xi->XenInterface.InterfaceHeader.Context,
    1.30 -    XBT_NIL, TmpPath, "%d", xi->state);
    1.31 +  xi->XenInterface.XenBus_Printf(if_cxt, XBT_NIL, TmpPath, "%d", xi->state);
    1.32  
    1.33    // wait for backend to set 'Closed' state
    1.34    while (xi->backend_state != XenbusStateClosed)
    1.35 -    KeWaitForSingleObject(&xi->backend_state_change_event, Executive, KernelMode, FALSE, NULL);
    1.36 +    KeWaitForSingleObject(&xi->backend_state_change_event, Executive,
    1.37 +      KernelMode, FALSE, NULL);
    1.38  
    1.39    xi->connected = FALSE;
    1.40  
    1.41 @@ -1634,25 +1635,29 @@ XenNet_Halt(
    1.42    // TODO: remove event channel xenbus entry (how?)
    1.43  
    1.44    /* free TX resources */
    1.45 -  xi->XenInterface.GntTbl_EndAccess(xi->XenInterface.InterfaceHeader.Context,
    1.46 -    xi->tx_ring_ref);
    1.47 -  xi->tx_ring_ref = GRANT_INVALID_REF;
    1.48 -  FreePages(xi->tx_mdl);
    1.49 +  if (xi->XenInterface.GntTbl_EndAccess(if_cxt, xi->tx_ring_ref))
    1.50 +  {
    1.51 +    xi->tx_ring_ref = GRANT_INVALID_REF;
    1.52 +    FreePages(xi->tx_mdl);
    1.53 +  }
    1.54 +  /* if EndAccess fails then tx/rx ring pages LEAKED -- it's not safe to reuse
    1.55 +     pages Dom0 still has access to */
    1.56    xi->tx_pgs = NULL;
    1.57    XenNet_TxBufferFree(xi);
    1.58  
    1.59    /* free RX resources */
    1.60 -  xi->XenInterface.GntTbl_EndAccess(xi->XenInterface.InterfaceHeader.Context,
    1.61 -    xi->rx_ring_ref);
    1.62 -  xi->rx_ring_ref = GRANT_INVALID_REF;
    1.63 -  FreePages(xi->rx_mdl);
    1.64 +  if (xi->XenInterface.GntTbl_EndAccess(if_cxt, xi->rx_ring_ref))
    1.65 +  {
    1.66 +    xi->rx_ring_ref = GRANT_INVALID_REF;
    1.67 +    FreePages(xi->rx_mdl);
    1.68 +  }
    1.69    xi->rx_pgs = NULL;
    1.70    XenNet_RxBufferFree(MiniportAdapterContext);
    1.71  
    1.72    /* Remove watch on backend state */
    1.73    RtlStringCbPrintfA(TmpPath, ARRAY_SIZE(TmpPath), "%s/state", xi->backend_path);
    1.74 -  xi->XenInterface.XenBus_RemWatch(xi->XenInterface.InterfaceHeader.Context,
    1.75 -      XBT_NIL, TmpPath, XenNet_BackEndStateHandler, xi);
    1.76 +  xi->XenInterface.XenBus_RemWatch(if_cxt, XBT_NIL, TmpPath,
    1.77 +    XenNet_BackEndStateHandler, xi);
    1.78  
    1.79    xi->XenInterface.InterfaceHeader.InterfaceDereference(NULL);
    1.80