Page 1 of 1

Why does the PAT disable mmaping /dev/mem

Posted: Tue Jul 23, 2024 7:10 am
by nxtv2
Linux has a check for mmap, if the PAT is enabled, then mmaping /dev/mem may fail.
In the source it says "This check is needed to avoid cache aliasing when PAT is enabled"
https://elixir.bootlin.com/linux/v6.10/ ... ype.c#L799

My questions is why would mapping /dev/mem cause aliasing, how is it different than any other map into the userspace process?

Re: Why does the PAT disable mmaping /dev/mem

Posted: Tue Jul 23, 2024 11:37 am
by nullplan
While I don't know for sure, my guess would be that all mappings of the same physical memory must have the same memory type, and the /dev/mem driver is not capable of mapping anything with a memtype other than the default WB. So if the mapping intersects something already mapped differently, this would violate the spec, and so they disallow it.

Re: Why does the PAT disable mmaping /dev/mem

Posted: Tue Jul 23, 2024 2:44 pm
by Octocontrabass
Intel SDM volume 3A section 12.12.4 wrote:The PAT allows any memory type to be specified in the page tables, and therefore it is possible to have a single physical page mapped to two or more different linear addresses, each with different memory types. Intel does not support this practice because it may lead to undefined operations that can result in a system failure.