Simpleator icon indicating copy to clipboard operation
Simpleator copied to clipboard

E_INVALID_ARG for WHvMapGpaRange

Open steffengy opened this issue 5 years ago • 1 comments

Building the binaries and starting simpleator.exe N:\path\to\testapp.exe yielded an E_INVALID_ARG in the debug console so I tried to look into it:

  1. It seems like the source address isn't aligned to a page boundary, as it should be, so WHvMapGpaRange yields that HRESULT.
  2. After fixing that and calling it manually small mappings work (roughly < 1<<36) when adding similar code as below directly after SemVmCreatePartition. For bigger sizes, we get E_INVALID_ARG again.

Any idea whats going on there? Are some kind of limits put onto the guest address space?

Running Win10 Pro 1903 x64, HyperV Platform and HyperV enabled.

MEM_ADDRESS_REQUIREMENTS addrReqs = { 0 };
addrReqs.Alignment = 65536; // align to page boundary, should be dwAllocationGranularity
MEM_EXTENDED_PARAMETER additional = { 0 };
additional.Type = MemExtendedParameterAddressRequirements;
additional.Pointer = &addrReqs;
auto addr = VirtualAlloc2(GetCurrentProcess(),
		NULL,
		4096,
		MEM_COMMIT | MEM_TOP_DOWN,
		PAGE_READWRITE,
		&additional,
		1);
// This works: WHV_GUEST_PHYSICAL_ADDRESS size = 0x0000000b40000000;
WHV_GUEST_PHYSICAL_ADDRESS size = 0x0000000b80000000;
auto ret = WHvMapGpaRange(semPartition->PartitionHandle,
		addr,
		4096,
		size, 
		WHvMapGpaRangeFlagRead | WHvMapGpaRangeFlagWrite);
// ret == E_INVALID_ARG
return 0;

steffengy avatar Jun 26 '19 22:06 steffengy

@steffengy @ionescu007 I had the same problem. I fixed it by adjusting s_TcbRegionAddress and s_Pml4PhysicalAddress to lower values according to the maximum RAM supported by my CPU model. I think the TCB boundary of 256Gb and PML4 boundary of 512Gb are the maximum values by the architect but the hypervisor limits them based on the actual CPU model installed on the system. for me the maximum value seems to be 64Gb on an intel-i7-3612qm (the maximum supported ram is 32Gb actually!)

but as soon as I run the simpleator I get the Unhandled Exit reason 4 which is WHvRunVpExitReasonUnrecoverableException. any idea why the testapp is not working?

danyhm avatar Oct 12 '21 13:10 danyhm