You are right.quirck wrote:That quote effectively allows UEFI to make any mappings of EfiConventionalMemory (readonly, no-execute, etc), it may even not map it at all. So the first thing to do after ExitBootServices is to switch to known good page tables.
Consider loaders written prior to introduction of 5-level paging. They might just construct PML4 and point CR3 to that, unaware that CPU can treat it as PML5. This isn't going to work, that code needs to be rewritten. Even if an OS isn't going to support 57-bit linear addresses, it still needs to be aware of it.
You cannot disable paging in long mode. So I am not sure what your scenario is here.quirck wrote:Consider another approach when we just want to disable paging altogether. "MOV to CR0 causes a general-protection exception if it would clear CR0.PG to 0 while CR4.PCIDE = 1", for example.
If history is any lesson, I think it is pretty safe to assume that no UEFI will enable 5-level paging by default. Otherwise it would indeed break existing bootloaders / kernels. This is the reason why the processor starts without 5-level paging enabled: backward compatibility. So if your bootloader is not aware of PML5, things continue working. If it is, it can setup a PML5 if desired.quirck wrote:Again, if we know about this bit, we can clear it in advance and disable paging afterwards. But how should we handle bits that are reserved now? Is there a safe path if at some time in future our code reads them as 1?
But this has nothing to do with UEFI: the same problem would exist with any firmware that runs in long mode. If anything, UEFI got it right by being non-specific about what the mapping is so that you don't assume anything about it. Backward compatibility is then in the end of manufacturers and that gives them maximum flexibility.