简体   繁体   中英

protection of pages in virtual memory

I read in a tutorial that although intel segmentation is not used in linux,there is the protection or mode information in code segment selector and data segment selector .And in virtual memory tutorial i read about protection of pages using page table depending on the modes they are running in.

I wanted to know how these two mechanisms are related?

At what stage protection information on pages is added into page table?Does CPU checks Code segment selector and depending on it page table flag is set?

Although segmentation is (almost) not used by Linux, because you can't turn it off on x86, segmentation is merely bypassed through a protected flat memory model .

Actually segmentation is mandatory, and you do have to setup the code and data segment selectors when crafting a kernel, just because those segment selectors setup the current privilege level of execution (the CPL): basically ring 0 (supervisor mode) or ring 3 (userland). The selectors (registers CS, DS, ...) host an offset into the GDT. Depending on the descriptor pointed by this offset, the system is running with a given level of privilege, see Intel manual 3A, chapter 3.2.2 for more information about using segments.

As you can see, with the protected flat memory model , there is no direct checks on attributes on access to the memory (neither for code or data). And you guessed it right! The MMU (I would rather say paging ) undertakes to check the access depending on the CPL of the system and the page's U/S attibute.

It is up to the kernel (therefore executing in ring 0 ) to setup the page directory, with relevant pages' attributes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM