0

I'm reading about linux kernel logical/virtual address, and high/low memory. As I understand, kernel logical space are the portion of memory that are directly 1:1 mapped to physical memory. For example on a 32-bit system with small ram (e.g. 512MB), virtual space 3GB ~ 3GB + 512MB are kernel logical space 1:1 mapped to all 512 MB physical memory continuously (in this case no high memory).

My confusion is: does it mean that kernel claims the whole 512MB RAM?

If kernel logical address 3GB ~ 3GB + 512MB must use this fixed 1:1 mapping to physical memory, as I understand these 512MB physical memory then cannot be shared with others, is it correct?

For example, If kernel wants to access logical address 3GB + 0x10000, which is directly mapped to physical address 0x10000, but what if this physical frame has already been taken (e.g. by a user process), what would happen?

Or somewhere I totally understand wrong?

hangyuan
  • 182
  • 10
  • Physical memory pages can be mapped to different virtual addresses by more than one page table at a time. – Ian Abbott Mar 01 '22 at 12:24
  • Related re: why Linux direct-maps all of physical RAM: [What is the rationality of Linux kernel's mapping as much RAM as possible in direct-mapping(linear mapping) area?](https://stackoverflow.com/q/27370435) – Peter Cordes Oct 29 '22 at 22:00

1 Answers1

0

I will explain it properly

[i] Yes kernel page directory is mapped with all physical pages of memory.Means kernel have access to all pages.It need to access everything to manage them.

[ii] If on physical memory there is something/any process data or code whether kernel or user it is never overwritten until process is used so that physical memory will not be allocated to others.

Privelage is checked with doing all this access and CPL,DPl,RPL,IOPL resides in segment register[CPL,RPL] and segment descriptor[Dpl] and Eflag resister[IOPl] IOPL makes sures that i/o instruction can be done only by kernel not by user and for all this CPL is neccessary.

CPl(Current previlage level) is put into hidden part of segment register by processor that is always equal to descriptor(an entry in gdt that tell about memory region and access permission a part of segmentation level of protection)it points.

After bios gives control to bootloader of kernel and than kernel takes control that time kernel do all neccessory things for protection and make processor jump into user process by setting segment registers with user_gdt_descriptor and CPL=3 and only come out when interrupt occur(in intel term interrupt is not just any interrupt but protection mode control transfer) interrupt is required as these process not have any access to physical resource only kernel have and interrupt that software do is called system call.

[iii] If kernel wants to access memory region that is of user process kernel can access as CPL(0) is more than previlage_level_of_that_user_page(3). But user process cant do same for kernel when kernel is mapped into user virtual memory kernel pages are set with kernel level permission in page directory entry.They cant just go and access it it will produce protection fault.

OSdev
  • 107
  • 6