Access permissions of /dev/mem

前端 未结 2 1271
傲寒
傲寒 2021-02-05 08:21

I have a set of questions regarding /dev/mem:

  1. Many articles on the net, seem to refer /dev/mem as the gateway to \"Physical RAM\

2条回答
  •  渐次进展
    2021-02-05 08:48

    1. Yes, you're right, /dev/mem allows you to map any physical address, including non-RAM memory mapped IO. This can can be useful for a quick and dirty hack to access some hardware device without writing a kernel driver.

    2. CONFIG_STRICT_DEVMEM makes the kernel check addresses in /dev/mem with devmem_is_allowed() in arch/x86/mm/init.c, and the comment there explains:

      * On x86, access has to be given to the first megabyte of ram because that area
      * contains bios code and data regions used by X and dosemu and similar apps.
      * Access has to be given to non-kernel-ram areas as well, these contain the PCI
      * mmio resources as well as potential bios/acpi data regions.
      

      your address 0xFFFF0000 is quite likely to be non-RAM, since BIOSes typically put IO memory just below 4GB, so that's why you're able to map it even with STRICT_DEVMEM.

提交回复
热议问题