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

[PATCH] Change AllocatePage to use ExAllocatePoolWithTag


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Martin Harvey <Martin.Harvey@xxxxxxxxxx>
  • Date: Wed, 7 Jul 2021 09:54:55 +0100
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Owen Smith <owen.smith@xxxxxxxxxx>, "Ben . Chalmers" <ben.chalmers@xxxxxxxxxx>, Martin Harvey <martin.harvey@xxxxxxxxxx>
  • Delivery-date: Wed, 07 Jul 2021 08:55:32 +0000
  • Ironport-hdrordr: A9a23:yDtlZqFmQQg/E6LCpLqE0seALOsnbusQ8zAXP0AYc31om6uj5r mTdZUgpGTJYVkqKRIdcLy7V5VoBEmskaKdgrNhW4tKPjOW2ldARbsKheCJrlHd8m/Fh4lgPM 9bAtBD4bbLbWSS4/yV3ODBKadE/OW6
  • Ironport-sdr: N0sW1GfFYZ5c+k9sqJZgosAR1pLNy8Kh09lVhNTZn4nQkW12okwS9PZ21uiA4tKzUPdU2OMqGG nDVpDoWjNbKS9jvw3Kf7bLcp4ccGd/EGfQGrMk3vz+j7mUldYC2LmxpGe298VhB0wZcus/75VH q6nrcA0tEoYjQnLcLdd9bvxdEh2RA5f8+rGrswwNNk0TkqJmALt1bn9/2VjTf4RnRM8TClZi30 fcwt7MX9hbPBXCRgm9lMsMBKHL9yKCJNiV6kbySqAxbdxjEbh0aCNpWmzIpTxpC0HDcNowCs4o FSo=
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

From: Owen Smith <owen.smith@xxxxxxxxxx>

Windows appears to have an edge case bug in which zeroing
memory using MmAllocatePAgesForMdlEx (which in Win 10 1803
happens even if you specify MM_DONT_ZERO_ALLOCATION) can cause
a BSOD 139 1e.

__AllocatePages is left unchanged (as we don't want
to allocate multiple contiguous pages).  This issue
has not been seen outside of xenvif calls to
__AllocatePage and we expect a fix to the underlying
Windows problem in the near future

Signed-off-by: Ben.Chalmers <ben.chalmers@xxxxxxxxxx>

Signed-Off-By: Martin Harvey <martin.harvey@xxxxxxxxxx>

Ported-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/common/util.h | 72 +++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 70 insertions(+), 2 deletions(-)

diff --git a/src/common/util.h b/src/common/util.h
index eddad4a..93875b3 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -39,6 +39,8 @@
 #define        P2ROUNDUP(_x, _a)   \
         (-(-(_x) & -(_a)))
 
+#define XENBUS_SINGLEPAGE_TAG 'PSUB'
+
 static FORCEINLINE LONG
 __ffs(
     IN  unsigned long long  mask
@@ -236,7 +238,57 @@ fail1:
     return NULL;
 }
 
-#define __AllocatePage()    __AllocatePages(1)
+static FORCEINLINE PMDL
+__AllocatePage()
+{
+    PMDL                Mdl;
+    PUCHAR              MdlMappedSystemVa;
+    NTSTATUS            status;
+
+    ASSERT3U(KeGetCurrentIrql(), <=, DISPATCH_LEVEL);
+
+    MdlMappedSystemVa = __AllocatePoolWithTag(NonPagedPool,
+                                              PAGE_SIZE,
+                                              XENBUS_SINGLEPAGE_TAG);
+
+    status = STATUS_NO_MEMORY;
+    if (MdlMappedSystemVa == NULL)
+        goto fail1;
+
+    status = STATUS_INTERNAL_ERROR;
+    if (((ULONG_PTR)MdlMappedSystemVa) & (PAGE_SIZE - 1))
+        goto fail2;
+
+    Mdl = IoAllocateMdl(MdlMappedSystemVa,
+                        (ULONG)PAGE_SIZE,
+                        FALSE,
+                        FALSE,
+                        NULL);
+    if (Mdl == NULL)
+        goto fail3;
+
+    MmBuildMdlForNonPagedPool(Mdl);
+
+    ASSERT3U(Mdl->ByteOffset, ==, 0);
+    ASSERT3P(Mdl->StartVa, ==, MdlMappedSystemVa);
+    ASSERT3P(Mdl->MappedSystemVa, ==, MdlMappedSystemVa);
+
+    RtlZeroMemory(MdlMappedSystemVa, Mdl->ByteCount);
+
+    return Mdl;
+
+fail3:
+    Error("fail3\n");
+
+fail2:
+    Error("fail2\n");
+
+    __FreePoolWithTag(MdlMappedSystemVa, XENBUS_SINGLEPAGE_TAG);
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return NULL;
+}
 
 static FORCEINLINE VOID
 __FreePages(
@@ -254,7 +306,23 @@ __FreePages(
     ExFreePool(Mdl);
 }
 
-#define __FreePage(_Mdl)    __FreePages(_Mdl)
+static FORCEINLINE VOID
+__FreePage(
+    IN  PMDL    Mdl
+    )
+{
+    PUCHAR  MdlMappedSystemVa;
+
+    ASSERT(Mdl->MdlFlags &
+            (MDL_MAPPED_TO_SYSTEM_VA |
+             MDL_SOURCE_IS_NONPAGED_POOL));
+
+    MdlMappedSystemVa = Mdl->MappedSystemVa;
+
+    IoFreeMdl(Mdl);
+
+    __FreePoolWithTag(MdlMappedSystemVa, XENBUS_SINGLEPAGE_TAG);
+}
 
 static FORCEINLINE PCHAR
 __strtok_r(
-- 
2.30.1.windows.1




 


Rackspace

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