ionescu007/SimpleVisor

Question:ShvVmxMtrrAdjustEffectiveMemoryType Wrong?

Thor-Heimdallr opened this issue · 1 comments

This judgment can guarantee 2M space is within the scope of it?
if (((LargePageAddress + _2MB) >= VpData->MtrrData[i].PhysicalAddressMin) &&
(LargePageAddress <= VpData->MtrrData[i].PhysicalAddressMax))
I think It should be:
if (((LargePageAddress + _2MB) <= VpData->MtrrData[i].PhysicalAddressMax) &&
(LargePageAddress >= VpData->MtrrData[i].PhysicalAddressMin))

The goal is not to check if the page is fully enclosed within the MTRR, but
if any piece of the region touches the MTRR.

Consider:

        Xs          Xe
              Rs            Re

Where X is the virtual region, and R is the 2MB MTRR space.

Your check would fail because Xs >= Rs is FALSE.

Best regards,
Alex Ionescu