Why does the PAT disable mmaping /dev/mem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nxtv2
Posts: 3
Joined: Sat Feb 10, 2024 8:23 pm

Why does the PAT disable mmaping /dev/mem

Post 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?
nullplan
Member
Member
Posts: 1789
Joined: Wed Aug 30, 2017 8:24 am

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

Post 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.
Carpe diem!
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

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

Post 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.
Post Reply