[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH] Change AllocatePage to use ExAllocatePoolWithTag
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
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |