[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH xenbus 3/3] Stop using BAR space to host Xen data structures



Currently XENBUS makes use of the memory BAR of the PCI device to which it
binds as a source of unpopulated GFNs to host Xen data structures, such as
the shared info and grant table.

There is a problem with doing this, which is that Windows (unsurprisingly)
sets up a non-cached MTRR for the page range covering PCI BARs so accesses
to BAR space (and hence the Xen data structures) should be non-cached.
However, Xen itself contains a work-around to avoid the slow access times
that would ordinarily result from the this; it ignores the MTRRs if no
real devices are passed through to the guest so accesses are actually
cached. Thus, in the normal case, there is no penalty to pay... but as soon
as hardware is passed through to a guest, the work-around no longer applies
and there is a noticeable drop in PV driver performance. (E.g. network
throughput can drop by ~30-40%).

This patch modifies XENBUS to allocate a 2MB area of RAM (which will always
fall into a cached MTRR), use a decrease_reservation hypercall to
de-populate the area, and then use that as a source of GFNs instead of the
BAR. Hence, the work-around in Xen no longer has any baring on accessing of
Xen data structures and thus there is no longer any performance penalty
when hardware is passed through to a guest.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenbus/fdo.c         | 317 ++++++++++++++++++++++++++++++++---------------
 src/xenbus/fdo.h         |  13 +-
 src/xenbus/gnttab.c      | 100 ++++++---------
 src/xenbus/shared_info.c |  44 +++----
 4 files changed, 276 insertions(+), 198 deletions(-)

diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c
index 25a6cfc..7f67b61 100644
--- a/src/xenbus/fdo.c
+++ b/src/xenbus/fdo.c
@@ -138,7 +138,9 @@ struct _XENBUS_FDO {
     XENBUS_RANGE_SET_INTERFACE      RangeSetInterface;
     XENBUS_BALLOON_INTERFACE        BalloonInterface;
 
-    PXENBUS_RANGE_SET               IoRangeSet;
+    PUCHAR                          Buffer;
+    PMDL                            Mdl;
+    PXENBUS_RANGE_SET               RangeSet;
     LIST_ENTRY                      InterruptList;
 
     PXENBUS_EVTCHN_CHANNEL          Channel;
@@ -2841,62 +2843,63 @@ FdoSuspendCallbackLate(
 }
 
 static NTSTATUS
-FdoCreateIoSpace(
-    IN  PXENBUS_FDO                 Fdo
+FdoCreateHole(
+    IN  PXENBUS_FDO Fdo
     )
 {
-    ULONG                           Index;
-    PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated;
-    PHYSICAL_ADDRESS                End;
-    NTSTATUS                        status;
-
-    for (Index = 0; Index < Fdo->TranslatedResourceList->Count; Index++) {
-        Translated = &Fdo->TranslatedResourceList->PartialDescriptors[Index];
-
-        if (Translated->Type == CmResourceTypeMemory)
-            goto found;
-    }
-
-    status = STATUS_OBJECT_NAME_NOT_FOUND;
-    goto fail1;
+    PMDL            Mdl;
+    PFN_NUMBER      Pfn;
+    LONGLONG        Start;
+    ULONG           Count;
+    NTSTATUS        status;
 
-found:
     status = XENBUS_RANGE_SET(Create,
                               &Fdo->RangeSetInterface,
-                              "io_space",
-                              &Fdo->IoRangeSet);
+                              "hole",
+                              &Fdo->RangeSet);
     if (!NT_SUCCESS(status))
-        goto fail2;
+        goto fail1;
+
+    Mdl = Fdo->Mdl;
+
+    Pfn = MmGetMdlPfnArray(Mdl)[0];
+
+    Start = Pfn;
+    Count = BYTES_TO_PAGES(Mdl->ByteCount);
 
     status = XENBUS_RANGE_SET(Put,
                               &Fdo->RangeSetInterface,
-                              Fdo->IoRangeSet,
-                              Translated->u.Memory.Start.QuadPart,
-                              Translated->u.Memory.Length);
+                              Fdo->RangeSet,
+                              Start,
+                              Count);
     if (!NT_SUCCESS(status))
-        goto fail3;
+        goto fail2;
 
-    End.QuadPart = Translated->u.Memory.Start.QuadPart + 
Translated->u.Memory.Length - 1;
+    status = STATUS_UNSUCCESSFUL;
+    if (MemoryDecreaseReservation(PAGE_ORDER_2M, 1, &Pfn) != 1)
+        goto fail3;
 
-    Info("%08x.%08x - %08x.%08x\n",
-         Translated->u.Memory.Start.HighPart,
-         Translated->u.Memory.Start.LowPart,
-         End.HighPart,
-         End.LowPart);
+    Trace("%08x - %08x\n", Start, Start + Count - 1);
 
     return STATUS_SUCCESS;
 
 fail3:
     Error("fail3\n");
 
-    XENBUS_RANGE_SET(Destroy,
+    XENBUS_RANGE_SET(Get,
                      &Fdo->RangeSetInterface,
-                     Fdo->IoRangeSet);
-    Fdo->IoRangeSet = NULL;
+                     Fdo->RangeSet,
+                     Start,
+                     Count);
 
 fail2:
     Error("fail2\n");
 
+    XENBUS_RANGE_SET(Destroy,
+                     &Fdo->RangeSetInterface,
+                     Fdo->RangeSet);
+    Fdo->RangeSet = NULL;
+
 fail1:
     Error("fail1 (%08x)\n", status);
 
@@ -2904,25 +2907,40 @@ fail1:
 }
 
 NTSTATUS
-FdoAllocateIoSpace(
+FdoAllocateHole(
     IN  PXENBUS_FDO         Fdo,
-    IN  ULONG               Size,
-    OUT PPHYSICAL_ADDRESS   Address
+    IN  ULONG               Count,
+    OUT PVOID               *VirtualAddress OPTIONAL,
+    OUT PPHYSICAL_ADDRESS   PhysicalAddress
     )
 {
+    LONGLONG                Start;
     NTSTATUS                status;
 
-    ASSERT3U(Size & (PAGE_SIZE - 1), ==, 0);
-
     status = XENBUS_RANGE_SET(Pop,
                               &Fdo->RangeSetInterface,
-                              Fdo->IoRangeSet,
-                              Size,
-                              &Address->QuadPart);
+                              Fdo->RangeSet,
+                              Count,
+                              &Start);
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    ASSERT3U(Address->QuadPart & (PAGE_SIZE - 1), ==, 0);
+    Trace("%08x - %08x\n", Start, Start + Count - 1);
+
+    if (VirtualAddress != NULL) {
+        PUCHAR  StartVa = Fdo->Buffer;
+        PMDL    Mdl = Fdo->Mdl;
+        ULONG   Index;
+        ULONG   ByteOffset;
+
+        Index = (ULONG)((PFN_NUMBER)Start - MmGetMdlPfnArray(Mdl)[0]);
+        ByteOffset = Index * PAGE_SIZE;
+        ASSERT3U(ByteOffset, <=, Mdl->ByteCount);
+
+        *VirtualAddress = StartVa + ByteOffset;
+    }
+
+    PhysicalAddress->QuadPart = Start << PAGE_SHIFT;
 
     return STATUS_SUCCESS;;
 
@@ -2933,56 +2951,62 @@ fail1:
 }
 
 VOID
-FdoFreeIoSpace(
+FdoFreeHole(
     IN  PXENBUS_FDO         Fdo,
-    IN  PHYSICAL_ADDRESS    Address,
-    IN  ULONG               Size
+    IN  PHYSICAL_ADDRESS    PhysicalAddress,
+    IN  ULONG               Count
     )
 {
+    LONGLONG                Start;
     NTSTATUS                status;
 
-    ASSERT3U(Address.QuadPart & (PAGE_SIZE - 1), ==, 0);
-    ASSERT3U(Size & (PAGE_SIZE - 1), ==, 0);
+    ASSERT3U(PhysicalAddress.QuadPart & (PAGE_SIZE - 1), ==, 0);
+    Start = PhysicalAddress.QuadPart >> PAGE_SHIFT;
+
+    Trace("%08x - %08x\n", Start, Start + Count - 1);
 
     status = XENBUS_RANGE_SET(Put,
                               &Fdo->RangeSetInterface,
-                              Fdo->IoRangeSet,
-                              Address.QuadPart,
-                              Size);
+                              Fdo->RangeSet,
+                              Start,
+                              Count);
     ASSERT(NT_SUCCESS(status));
 }
 
 static VOID
-FdoDestroyIoSpace(
-    IN  PXENBUS_FDO                 Fdo
+FdoDestroyHole(
+    IN  PXENBUS_FDO Fdo
     )
 {
-    ULONG                           Index;
-    PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated;
-    NTSTATUS                        status;
+    PMDL            Mdl;
+    PFN_NUMBER      Pfn;
+    LONGLONG        Start;
+    ULONG           Count;
+    NTSTATUS        status;
 
-    for (Index = 0; Index < Fdo->TranslatedResourceList->Count; Index++) {
-        Translated = &Fdo->TranslatedResourceList->PartialDescriptors[Index];
+    Mdl = Fdo->Mdl;
 
-        if (Translated->Type == CmResourceTypeMemory)
-            goto found;
-    }
+    Pfn = MmGetMdlPfnArray(Mdl)[0];
 
-    ASSERT(FALSE);
-    return;
+    Start = Pfn;
+    Count = BYTES_TO_PAGES(Mdl->ByteCount);
+
+    Trace("%08x - %08x\n", Start, Start + Count - 1);
+
+    if (MemoryPopulatePhysmap(PAGE_ORDER_2M, 1, &Pfn) != 1)
+        BUG("FAILED TO RE-POPULATE HOLE");
 
-found:
     status = XENBUS_RANGE_SET(Get,
                               &Fdo->RangeSetInterface,
-                              Fdo->IoRangeSet,
-                              Translated->u.Memory.Start.QuadPart,
-                              Translated->u.Memory.Length);
+                              Fdo->RangeSet,
+                              Start,
+                              Count);
     ASSERT(NT_SUCCESS(status));
 
     XENBUS_RANGE_SET(Destroy,
                      &Fdo->RangeSetInterface,
-                     Fdo->IoRangeSet);
-    Fdo->IoRangeSet = NULL;
+                     Fdo->RangeSet);
+    Fdo->RangeSet = NULL;
 }
 
 // This function must not touch pageable code or data
@@ -3019,7 +3043,7 @@ FdoD3ToD0(
         goto fail3;
 
     // Subsequent interfaces require use of BAR space
-    status = FdoCreateIoSpace(Fdo);
+    status = FdoCreateHole(Fdo);
     if (!NT_SUCCESS(status))
         goto fail4;
 
@@ -3112,7 +3136,7 @@ fail6:
 fail5:
     Error("fail5\n");
 
-    FdoDestroyIoSpace(Fdo);
+    FdoDestroyHole(Fdo);
 
 fail4:
     Error("fail4\n");
@@ -3227,7 +3251,7 @@ FdoD0ToD3(
 
     XENBUS_EVTCHN(Release, &Fdo->EvtchnInterface);
 
-    FdoDestroyIoSpace(Fdo);
+    FdoDestroyHole(Fdo);
 
     XENBUS_RANGE_SET(Release, &Fdo->RangeSetInterface);
 
@@ -5032,6 +5056,82 @@ fail1:
                       (_Size),                                                 
         \
                       (_Optional))
 
+
+#define FDO_HOLE_SIZE   (2ull << 20)
+
+static FORCEINLINE NTSTATUS
+__FdoAllocateBuffer(
+    IN  PXENBUS_FDO     Fdo
+    )
+{
+    ULONG               Size;
+    PHYSICAL_ADDRESS    Low;
+    PHYSICAL_ADDRESS    High;
+    PHYSICAL_ADDRESS    Align;
+    PVOID               Buffer;
+    PMDL                Mdl;
+    NTSTATUS            status;
+
+    Size = 2 << 20;
+
+    Low.QuadPart = 0;
+    High = SystemMaximumPhysicalAddress();
+    Align.QuadPart = Size;
+
+    Buffer = MmAllocateContiguousNodeMemory((SIZE_T)Size,
+                                            Low,
+                                            High,
+                                            Align,
+                                            PAGE_READWRITE,
+                                            MM_ANY_NODE_OK);
+
+    status = STATUS_NO_MEMORY;
+    if (Buffer == NULL)
+        goto fail1;
+
+    Mdl = IoAllocateMdl(Buffer,
+                        Size,
+                        FALSE,
+                        FALSE,
+                        NULL);
+
+    status = STATUS_NO_MEMORY;
+    if (Mdl == NULL)
+        goto fail2;
+
+    MmBuildMdlForNonPagedPool(Mdl);
+
+    ASSERT3U(Mdl->ByteOffset, ==, 0);
+    ASSERT3U(Mdl->ByteCount, ==, Size);
+
+    Fdo->Buffer = MmGetSystemAddressForMdlSafe(Mdl, NormalPagePriority);
+    Fdo->Mdl = Mdl;
+
+    return STATUS_SUCCESS;
+
+fail2:
+    Error("fail2\n");
+
+    MmFreeContiguousMemory(Buffer);
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
+}
+
+static FORCEINLINE VOID
+__FdoFreeBuffer(
+    IN  PXENBUS_FDO Fdo
+    )
+{
+    ExFreePool(Fdo->Mdl);
+    Fdo->Mdl = NULL;
+
+    MmFreeContiguousMemory(Fdo->Buffer);
+    Fdo->Buffer = NULL;
+}
+
 static BOOLEAN
 FdoIsBalloonEnabled(
     IN  PXENBUS_FDO Fdo
@@ -5138,50 +5238,54 @@ FdoCreate(
     if (!__FdoIsActive(Fdo))
         goto done;
 
-    status = DebugInitialize(Fdo, &Fdo->DebugContext);
+    status = __FdoAllocateBuffer(Fdo);
     if (!NT_SUCCESS(status))
         goto fail9;
 
-    status = SuspendInitialize(Fdo, &Fdo->SuspendContext);
+    status = DebugInitialize(Fdo, &Fdo->DebugContext);
     if (!NT_SUCCESS(status))
         goto fail10;
 
-    status = SharedInfoInitialize(Fdo, &Fdo->SharedInfoContext);
+    status = SuspendInitialize(Fdo, &Fdo->SuspendContext);
     if (!NT_SUCCESS(status))
         goto fail11;
 
-    status = EvtchnInitialize(Fdo, &Fdo->EvtchnContext);
+    status = SharedInfoInitialize(Fdo, &Fdo->SharedInfoContext);
     if (!NT_SUCCESS(status))
         goto fail12;
 
-    status = RangeSetInitialize(Fdo, &Fdo->RangeSetContext);
+    status = EvtchnInitialize(Fdo, &Fdo->EvtchnContext);
     if (!NT_SUCCESS(status))
         goto fail13;
 
-    status = CacheInitialize(Fdo, &Fdo->CacheContext);
+    status = RangeSetInitialize(Fdo, &Fdo->RangeSetContext);
     if (!NT_SUCCESS(status))
         goto fail14;
 
-    status = GnttabInitialize(Fdo, &Fdo->GnttabContext);
+    status = CacheInitialize(Fdo, &Fdo->CacheContext);
     if (!NT_SUCCESS(status))
         goto fail15;
 
-    status = StoreInitialize(Fdo, &Fdo->StoreContext);
+    status = GnttabInitialize(Fdo, &Fdo->GnttabContext);
     if (!NT_SUCCESS(status))
         goto fail16;
 
-    status = ConsoleInitialize(Fdo, &Fdo->ConsoleContext);
+    status = StoreInitialize(Fdo, &Fdo->StoreContext);
     if (!NT_SUCCESS(status))
         goto fail17;
 
-    status = UnplugInitialize(Fdo, &Fdo->UnplugContext);
+    status = ConsoleInitialize(Fdo, &Fdo->ConsoleContext);
     if (!NT_SUCCESS(status))
         goto fail18;
 
+    status = UnplugInitialize(Fdo, &Fdo->UnplugContext);
+    if (!NT_SUCCESS(status))
+        goto fail19;
+
     if (FdoIsBalloonEnabled(Fdo)) {
         status = BalloonInitialize(Fdo, &Fdo->BalloonContext);
         if (!NT_SUCCESS(status))
-            goto fail19;
+            goto fail20;
     }
 
     status = DebugGetInterface(__FdoGetDebugContext(Fdo),
@@ -5251,66 +5355,71 @@ done:
 
     return STATUS_SUCCESS;
 
-fail19:
-    Error("fail19\n");
+fail20:
+    Error("fail20\n");
 
     UnplugTeardown(Fdo->UnplugContext);
     Fdo->UnplugContext = NULL;
 
-fail18:
-    Error("fail18\n");
+fail19:
+    Error("fail19\n");
 
     ConsoleTeardown(Fdo->ConsoleContext);
     Fdo->ConsoleContext = NULL;
 
-fail17:
-    Error("fail17\n");
+fail18:
+    Error("fail18\n");
 
     StoreTeardown(Fdo->StoreContext);
     Fdo->StoreContext = NULL;
 
-fail16:
-    Error("fail16\n");
+fail17:
+    Error("fail17\n");
 
     GnttabTeardown(Fdo->GnttabContext);
     Fdo->GnttabContext = NULL;
 
-fail15:
-    Error("fail15\n");
+fail16:
+    Error("fail16\n");
 
     CacheTeardown(Fdo->CacheContext);
     Fdo->CacheContext = NULL;
 
-fail14:
-    Error("fail14\n");
+fail15:
+    Error("fail15\n");
 
     RangeSetTeardown(Fdo->RangeSetContext);
     Fdo->RangeSetContext = NULL;
 
-fail13:
-    Error("fail13\n");
+fail14:
+    Error("fail14\n");
 
     EvtchnTeardown(Fdo->EvtchnContext);
     Fdo->EvtchnContext = NULL;
 
-fail12:
-    Error("fail12\n");
+fail13:
+    Error("fail13\n");
 
     SharedInfoTeardown(Fdo->SharedInfoContext);
     Fdo->SharedInfoContext = NULL;
 
-fail11:
-    Error("fail11\n");
+fail12:
+    Error("fail12\n");
 
     SuspendTeardown(Fdo->SuspendContext);
     Fdo->SuspendContext = NULL;
 
-fail10:
-    Error("fail10\n");
+fail11:
+    Error("fail11\n");
 
     DebugTeardown(Fdo->DebugContext);
     Fdo->DebugContext = NULL;
 
+fail10:
+    Error("fail10\n");
+
+    __FdoFreeBuffer(Fdo);
+
 fail9:
     Error("fail9\n");
 
@@ -5453,6 +5562,8 @@ FdoDestroy(
         DebugTeardown(Fdo->DebugContext);
         Fdo->DebugContext = NULL;
 
+        __FdoFreeBuffer(Fdo);
+
         FdoClearActive(Fdo);
     }
 
diff --git a/src/xenbus/fdo.h b/src/xenbus/fdo.h
index 90f81ac..d84f02d 100644
--- a/src/xenbus/fdo.h
+++ b/src/xenbus/fdo.h
@@ -132,17 +132,18 @@ FdoGetName(
     );
 
 extern NTSTATUS
-FdoAllocateIoSpace(
+FdoAllocateHole(
     IN  PXENBUS_FDO         Fdo,
-    IN  ULONG               Size,
-    OUT PPHYSICAL_ADDRESS   Address
+    IN  ULONG               Count,
+    OUT PVOID               *VirtualAddress OPTIONAL,
+    OUT PPHYSICAL_ADDRESS   PhysicalAddress
     );
 
 extern VOID
-FdoFreeIoSpace(
+FdoFreeHole(
     IN  PXENBUS_FDO         Fdo,
-    IN  PHYSICAL_ADDRESS    Address,
-    IN  ULONG               Size
+    IN  PHYSICAL_ADDRESS    PhysicalAddress,
+    IN  ULONG               Count
     );
 
 // Disable erroneous SAL warnings around use of interrupt locks
diff --git a/src/xenbus/gnttab.c b/src/xenbus/gnttab.c
index 335d306..ca60a48 100644
--- a/src/xenbus/gnttab.c
+++ b/src/xenbus/gnttab.c
@@ -590,9 +590,10 @@ GnttabMapForeignPages(
     PXENBUS_GNTTAB_MAP_ENTRY    MapEntry;
     NTSTATUS                    status;
 
-    status = FdoAllocateIoSpace(Context->Fdo,
-                                NumberPages * PAGE_SIZE,
-                                Address);
+    status = FdoAllocateHole(Context->Fdo,
+                             NumberPages,
+                             NULL,
+                             Address);
     if (!NT_SUCCESS(status))
         goto fail1;
 
@@ -644,7 +645,7 @@ fail3:
 fail2:
     Error("fail2\n");
 
-    FdoFreeIoSpace(Context->Fdo, *Address, NumberPages * PAGE_SIZE);
+    FdoFreeHole(Context->Fdo, *Address, NumberPages);
 
 fail1:
     Error("fail1: (%08x)\n", status);
@@ -685,9 +686,9 @@ GnttabUnmapForeignPages(
         PageAddress.QuadPart += PAGE_SIZE;
     }
 
-    FdoFreeIoSpace(Context->Fdo,
-                   Address,
-                   MapEntry->NumberPages * PAGE_SIZE);
+    FdoFreeHole(Context->Fdo,
+                Address,
+                MapEntry->NumberPages);
 
     __GnttabFree(MapEntry);
 
@@ -742,7 +743,6 @@ GnttabAcquire(
     PXENBUS_GNTTAB_CONTEXT  Context = Interface->Context;
     PXENBUS_FDO             Fdo = Context->Fdo;
     KIRQL                   Irql;
-    ULONG                   Size;
     NTSTATUS                status;
 
     KeAcquireSpinLock(&Context->Lock, &Irql);
@@ -760,41 +760,33 @@ GnttabAcquire(
               "GNTTAB: MAX FRAMES = %u\n",
               Context->MaximumFrameCount);
 
-    Size = Context->MaximumFrameCount * PAGE_SIZE;
-
-    status = FdoAllocateIoSpace(Fdo,
-                                Size,
-                                &Context->Address);
+    status = FdoAllocateHole(Fdo,
+                             Context->MaximumFrameCount,
+                             &Context->Table,
+                             &Context->Address);
     if (!NT_SUCCESS(status))
         goto fail2;
 
-    Context->Table = (grant_entry_v1_t *)MmMapIoSpace(Context->Address,
-                                                      Size,
-                                                      MmCached);
-    status = STATUS_UNSUCCESSFUL;
-    if (Context->Table == NULL)
-        goto fail3;
-
     Context->FrameIndex = -1;
 
     status = XENBUS_RANGE_SET(Acquire, &Context->RangeSetInterface);
     if (!NT_SUCCESS(status))
-        goto fail4;
+        goto fail3;
 
     status = XENBUS_RANGE_SET(Create,
                               &Context->RangeSetInterface,
                               "gnttab",
                               &Context->RangeSet);
     if (!NT_SUCCESS(status))
-        goto fail5;
+        goto fail4;
 
     status = XENBUS_CACHE(Acquire, &Context->CacheInterface);
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail5;
     
     status = XENBUS_SUSPEND(Acquire, &Context->SuspendInterface);
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail6;
 
     status = XENBUS_SUSPEND(Register,
                             &Context->SuspendInterface,
@@ -803,11 +795,11 @@ GnttabAcquire(
                             Context,
                             &Context->SuspendCallbackEarly);
     if (!NT_SUCCESS(status))
-        goto fail8;
+        goto fail7;
 
     status = XENBUS_DEBUG(Acquire, &Context->DebugInterface);
     if (!NT_SUCCESS(status))
-        goto fail9;
+        goto fail8;
 
     status = XENBUS_DEBUG(Register,
                           &Context->DebugInterface,
@@ -816,12 +808,12 @@ GnttabAcquire(
                           Context,
                           &Context->DebugCallback);
     if (!NT_SUCCESS(status))
-        goto fail10;
+        goto fail9;
 
     /* Make sure at least the reserved refrences are present */
     status = GnttabExpand(Context);
     if (!NT_SUCCESS(status))
-        goto fail11;
+        goto fail10;
 
     Trace("<====\n");
 
@@ -830,40 +822,40 @@ done:
 
     return STATUS_SUCCESS;
 
-fail11:
-    Error("fail11\n");
+fail10:
+    Error("fail10\n");
 
     XENBUS_DEBUG(Deregister,
                  &Context->DebugInterface,
                  Context->DebugCallback);
     Context->DebugCallback = NULL;
 
-fail10:
-    Error("fail10\n");
+fail9:
+    Error("fail9\n");
 
     XENBUS_DEBUG(Release, &Context->DebugInterface);
 
-fail9:
-    Error("fail9\n");
+fail8:
+    Error("fail8\n");
 
     XENBUS_SUSPEND(Deregister,
                    &Context->SuspendInterface,
                    Context->SuspendCallbackEarly);
     Context->SuspendCallbackEarly = NULL;
 
-fail8:
-    Error("fail8\n");
-
-    XENBUS_SUSPEND(Release, &Context->SuspendInterface);
-
 fail7:
     Error("fail7\n");
 
-    XENBUS_CACHE(Release, &Context->CacheInterface);
+    XENBUS_SUSPEND(Release, &Context->SuspendInterface);
 
 fail6:
     Error("fail6\n");
 
+    XENBUS_CACHE(Release, &Context->CacheInterface);
+
+fail5:
+    Error("fail5\n");
+
     GnttabContract(Context);
     ASSERT3S(Context->FrameIndex, ==, -1);
 
@@ -874,24 +866,19 @@ fail6:
 
     Context->FrameIndex = 0;
 
-fail5:
-    Error("fail5\n");
-
-    XENBUS_RANGE_SET(Release, &Context->RangeSetInterface);
-
 fail4:
     Error("fail4\n");
 
-    MmUnmapIoSpace(Context->Table, Size);
-    Context->Table = NULL;
+    XENBUS_RANGE_SET(Release, &Context->RangeSetInterface);
 
 fail3:
     Error("fail3\n");
 
-    FdoFreeIoSpace(Fdo,
-                   Context->Address,
-                   Size);
+    FdoFreeHole(Fdo,
+                Context->Address,
+                Context->MaximumFrameCount);
     Context->Address.QuadPart = 0;
+    Context->Table = NULL;
 
 fail2:
     Error("fail2\n");
@@ -916,7 +903,6 @@ GnttabRelease(
     PXENBUS_GNTTAB_CONTEXT  Context = Interface->Context;
     PXENBUS_FDO             Fdo = Context->Fdo;
     KIRQL                   Irql;
-    ULONG                   Size;
 
     KeAcquireSpinLock(&Context->Lock, &Irql);
 
@@ -956,15 +942,11 @@ GnttabRelease(
 
     XENBUS_RANGE_SET(Release, &Context->RangeSetInterface);
 
-    Size = Context->MaximumFrameCount * PAGE_SIZE;
-
-    MmUnmapIoSpace(Context->Table, Size);
-    Context->Table = NULL;
-
-    FdoFreeIoSpace(Fdo,
-                   Context->Address,
-                   Size);
+    FdoFreeHole(Fdo,
+                Context->Address,
+                Context->MaximumFrameCount);
     Context->Address.QuadPart = 0;
+    Context->Table = NULL;
 
     Context->MaximumFrameCount = 0;
 
diff --git a/src/xenbus/shared_info.c b/src/xenbus/shared_info.c
index 1e36a92..adae7ff 100644
--- a/src/xenbus/shared_info.c
+++ b/src/xenbus/shared_info.c
@@ -542,25 +542,16 @@ SharedInfoAcquire(
 
     Trace("====>\n");
 
-    status = FdoAllocateIoSpace(Fdo, PAGE_SIZE, &Context->Address);
+    status = FdoAllocateHole(Fdo, 1, &Context->Shared, &Context->Address);
     if (!NT_SUCCESS(status))
         goto fail1;
 
     SharedInfoMap(Context);
-
-    Context->Shared = (shared_info_t *)MmMapIoSpace(Context->Address,
-                                                    PAGE_SIZE,
-                                                    MmCached);
-
-    status = STATUS_UNSUCCESSFUL;
-    if (Context->Shared == NULL)
-        goto fail2;
-
     SharedInfoEvtchnMaskAll(Context);
 
     status = XENBUS_SUSPEND(Acquire, &Context->SuspendInterface);
     if (!NT_SUCCESS(status))
-        goto fail3;   
+        goto fail2;
 
     status = XENBUS_SUSPEND(Register,
                             &Context->SuspendInterface,
@@ -569,11 +560,11 @@ SharedInfoAcquire(
                             Context,
                             &Context->SuspendCallbackEarly);
     if (!NT_SUCCESS(status))
-        goto fail4;
+        goto fail3;
 
     status = XENBUS_DEBUG(Acquire, &Context->DebugInterface);
     if (!NT_SUCCESS(status))
-        goto fail5;
+        goto fail4;
 
     status = XENBUS_DEBUG(Register,
                           &Context->DebugInterface,
@@ -582,7 +573,7 @@ SharedInfoAcquire(
                           Context,
                           &Context->DebugCallback);
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail5;
 
     Trace("<====\n");
 
@@ -591,37 +582,32 @@ done:
 
     return STATUS_SUCCESS;
 
-fail6:
-    Error("fail6\n");
+fail5:
+    Error("fail5\n");
 
     XENBUS_DEBUG(Release, &Context->DebugInterface);
 
-fail5:
-    Error("fail5\n");
+fail4:
+    Error("fail4\n");
 
     XENBUS_SUSPEND(Deregister,
                    &Context->SuspendInterface,
                    Context->SuspendCallbackEarly);
     Context->SuspendCallbackEarly = NULL;
 
-fail4:
-    Error("fail4\n");
-
-    XENBUS_SUSPEND(Release, &Context->SuspendInterface);
-
 fail3:
     Error("fail3\n");
 
-    MmUnmapIoSpace(Context->Shared, PAGE_SIZE);
-    Context->Shared = NULL;
+    XENBUS_SUSPEND(Release, &Context->SuspendInterface);
 
 fail2:
     Error("fail2\n");
 
     SharedInfoUnmap(Context);
 
-    FdoFreeIoSpace(Fdo, Context->Address, PAGE_SIZE);
+    FdoFreeHole(Fdo, Context->Address, 1);
     Context->Address.QuadPart = 0;
+    Context->Shared = NULL;
 
 fail1:
     Error("fail1 (%08x)\n", status);
@@ -665,13 +651,11 @@ SharedInfoRelease (
 
     XENBUS_SUSPEND(Release, &Context->SuspendInterface);
 
-    MmUnmapIoSpace(Context->Shared, PAGE_SIZE);
-    Context->Shared = NULL;
-
     SharedInfoUnmap(Context);
 
-    FdoFreeIoSpace(Fdo, Context->Address, PAGE_SIZE);
+    FdoFreeHole(Fdo, Context->Address, 1);
     Context->Address.QuadPart = 0;
+    Context->Shared = NULL;
 
     Trace("<====\n");
 
-- 
2.5.3


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.