Page Tables
Similar to hw1, pull the latest code from https://github.com/sysec-uic/xv6-public/, and switch to hw2.
git pull origin
git checkout hw2
You can also check what has been added in hw2 using this link: https://github.com/sysec-uic/xv6-public/compare/master...hw2
Step 1: Understand the meaning of PTEs (2 pt)
To help you understand x86_64 page tables, your first task is to explain the page table for a user process.
Run make qemu-nox and run the user program vmprint. The newly added vmprint system call prints out the page-table entries for the first 10 virtual pages of the vmprint process. The output looks as follows:
$ vmprint
[u] Calling vmprint syscall to print the first 10 pages in the
current process's virtual address space:
[k] First 10 pages of process PID 3 (vmprint) page table:
VA 0000000000000000: PTE 0000000000000000, flags 00000000
VA 0000000000001000: PTE 000000000dfcc027, flags 00000027
VA 0000000000002000: PTE 000000000dfc8003, flags 00000003
VA 0000000000003000: PTE 000000000dfc7067, flags 00000067
VA 0000000000004000: PTE 0000000000000000, flags 00000000
... ...
For the page table entries in the output, explain what they logically contain and what their permission bits are. Write your answer on Gradescope.
Note: Figure 2-1 in the xv6 book might be helpful, although note that the figure shows a page table for x86-32 while our code is on an x86-64 kernel. Note that xv6 doesn't place the virtual pages consecutively in physical memory.
Step 2: Explain what happens if we allocate pages on heap (2 pt)
Inside the xv6 OS, run the command vmprint heap. This command allocates two pages of heap memory using malloc().
Observe how the process’s virtual memory layout changes as a result.
Explain the differences you see in the printed output compared to running vmprint without the heap argument.
Why do these changes occur? Write your answer on Gradescope.
Step 3: Print a page table (4 pt)
To help you visualize x86-64 4-level page tables, and perhaps to aid future debugging, your next task is to write a function that prints the contents of a page table.
We added a system call sys_vmprint(), which takes a parameter mode from the userspace. When the mode is 0, it prints the first 10 virtual pages (Step 1). When the mode is 1, it prints a page table hierarchy. Your task is to print that page table (mode 1) in the format described below.
$ vmprint
[u] Calling vmprint syscall to print the first 10 pages in the
current process's virtual address space:
[k] First 10 pages of process PID 3 (vmprint) page table:
VA 0000000000000000: PTE 0000000000000000, flags 00000000
VA 0000000000001000: PTE 000000000dfcc027, flags 00000027
... ...
[u] Calling vmprint syscall to print the full page table:
[k] Full page table of process PID 3 (vmprint):
page table pml4 va 0xffff80000dfcd000 (pa 0x0dfcd000)
0x0000000000000000: pte 0x000000000dfcb027 pa 0x0dfcb000
..0x0000000000000000: pte 0x000000000dfca027 pa 0x0dfca000
.. ..0x0000000000000000: pte 0x000000000dfc9027 pa 0x0dfc9000
.. .. ..0x0000000000001000: pte 0x000000000dfcc027 pa 0x0dfcc000
.. .. ..0x0000000000002000: pte 0x000000000dfc8003 pa 0x0dfc8000
.. .. ..0x0000000000003000: pte 0x000000000dfc7067 pa 0x0dfc7000
0xffff800000000000: pte 0x000000000dffe023 pa 0x0dffe000
..0xffff800000000000: pte 0x00000000000000e3 pa 0x00000000
..0xffff8000c0000000: pte 0x00000000c00000fb pa 0xc0000000
After you finish the implementation, feel free to check your code with vmprint heap.
Submission
Please follow instructions on Gradescope to submit your solution.