Overview
In lecture, we discuss virtual memory.
Full lecture notes on kernel — Textbook readings
Protecting the castle
- Goals: Kernel isolation and process isolation
- Kernel always retains full privilege over machine operations
- Process interactions restricted by operating system policy
- Why does kernel isolation require an instruction like
syscall
?
Memory protection
- Must prevent processes from jumping to arbitrary locations in the kernel
- Must prevent processes from accessing or modifying kernel memory
- Modification would allow controlling kernel code
- Access could be used to steal secrets
Invisibility cloak
- What if we could tell the processor that some of memory did not exist?
Exercise: Tradeoffs
- How would you implement a processor feature that hid some memory from unprivileged processes?
- Assume the processor has a register that indicates privilege
- On x86-64, the lower 2 bits of
%cs
represent privilege: 0 means privileged, 3 means unprivileged
- On x86-64, the lower 2 bits of
Virtual memory
- Processor accesses memory through a layer of indirection called virtual memory
- Virtual memory mapping function
- The addresses used by instructions are virtual addresses in VA
- The contents of memory chips are addressed by physical addresses in PA
- When an instruction accesses virtual address , the processor accesses physical address
Invisibility cloak via virtual memory
- Start with an identity mapping
- Change it to fault if an unprivileged process accesses kernel memory
Virtual memory performance
- How would you represent a mapping function?
- Constraint: Every memory access uses the mapping function
- Performance sensitive!
- Speed up lookups by through caching
- The results of one lookup should apply to nearby addresses too
Paged virtual memory: Look up once per block
- Divide virtual and physical memory into aligned pages
- x86-64: size 212 = 0x1000 = 4096
- Every address within a page is looked up the same way
- Let be a page address (a multiple of 212), and
- Then
- If fault, then both fault the same way