AOS - Lecture Notes Summary
01 - HARDWARE INSIGHTS I
Lecture Info
BAKERY/bakery.c
Modern Architectures
Scheduling
Speculation
Synchronization
Parallelism
Program Flow Speed
Pipeline
Logical Stages
Speedup Factor
Breaks
RE: Pipeline Test
02 - HARDWARE INSIGHTS II
Lecture Info
Pipeline Conflicts
x86 History
Intel 8086 (iAPX 86)
Intel 80486 (i486)
Intel Pentium Pro (1995)
OoOE Concepts
Imprecise Exceptions
Tomasulo's algorithm
Conflicts to manage
Algorithmic ideas
Register Renaming
Reservation Stations
OoOE Architecture
OoOE Example
Hyper-Threading
Misc
Microarchitecture
CPUID
03 - HARDWARE INSIGHTS III
Lecture Info
Interrupts and OoOE
Exceptions and OoOE
Exceptions Types
Exception Handling
x86 Details
Data Transfer
Linear Addressing
Meltdown
How it works?
Why it works?
PoC
Cache Latency
Side Channels
Possible Fixes
Branch Prediction
1-bit Predictors
04 - HARDWARE INSIGHTS IV
Lecture Info
Branch Prediction
2-Bit Predictors
Beyond 2-Bit
Indirect Branches
Spectre
PoC
RE: SIDE-CHANNEL-MEMORY-READS
Cross-Context Attacks
Possible Fixes
Loop Unrolling
Power Wall
Distributed Architectures
NUMA
05 - HARDWARE INSIGHTS V
Lecture Info
Cache Coherency
Definition
CC Protocols Basics
CC Protocols Families
Bus snooping
MSI
MESI
False Cache Sharing
RE: FALSE-CACHE-SHARING
ASM Inline
FLUSH+RELOAD
RDTSC
CFLUSH
RE 1: FLUSH-AND-RELOAD
RE 2: FLUSH-AND-RELOAD
Do we need RDTSC?
Cache Inclusiveness
06 - HARDWARE INSIGHTS VI
Lecture Info
Memory Consistency
Terminology
Sequential Consistency
Total Store Order
Store Bypass
x86 Memory Synch
Memory Fences
Serializing Instructions
RMW Instructions
gcc built-ins
Trylock via CMPXCHG
Active-Wait Barrier
Scalability
Linearizability
07 - HARDWARE INSIGHTS VII
Lecture Info
Scalability
Linearizability
Locks vs RMW
Non-Blocking Algorithms
Lock-Freedom
Linked List
Wait-Freedom
ARC
Buffer re-usage
RCU
Operations
Kernel Space
User Space
RE: RCU
Vettorizzazione
Processor Scheme
Vectorization in x86
C Intrinsics for SEE
Memory Alignment
RE: SSE
08 - KERNEL PROGRAMMING BASICS I
Lecture Info
Processori di Sistema
Schemi di Indirizzamento
Indirizzamento lineare
Segmentazione
Segmentazione in uno spazio lineare
Indirizzamento nei sistemi moderni
x86 example
X86 Memory Access Modes
Real mode (286)
Protected mode (80386)
Long mode (x86-64)
x86 Segment Tables
Segmentation vs Paging
The x86-64 revision
Ring Model
Types of GATEs
Ring Model in x86
09 - KERNEL PROGRAMMING BASICS II
Lecture Info
Segment Selectors in x86
x86 GDT Entries
Accessing GDT entries
GDT-AND-SEGMENTS/gdt.c
Linux GDT on x86
Access Scheme
GDT-AND-SEGMENTS/segments.c
Segment Selectors Update Rules
10 - KERNEL PROGRAMMING BASICS III
Lecture Info
Task State Segment (TSS)
GDT Replication
Per-CPU Memory
Thread Local Storage (TLS)
GDT-AND-SEGMENTS/thread-segment-management.c
x86-64 Control Registers
Interrupts and Traps
x86 Control Flow Variations
GATE Details for x86
Trap-Based On-Demand Kernel Access
Conventional Method
System Call Table
Modificare la system call table
11 - KERNEL PROGRAMMING BASICS IV
Lecture Info
Linux Versions
System call (software) Components
System Call Formats
System Call Numerical Codes
Macros to Trigger System Calls
Manage Return Value of Syscalls
Stub for Syscall with 6 Parameters
Calling Conventions
ABI vs reality
i386 stack allignment
x86-64 stack allignment
Running Examples
SYS-CALL/asm-terminal-echo.c
SYS-CALL/sys-call-macro.c
Homework #1: TLS
Requirements
Solution
12 - KERNEL PROGRAMMING BASICS V
Lecture Info
INT 0x80 performance
Fast System Call Path
sysenter/syscall
sysexit/sysret
Model Specific Registers
The syscall() Construct
SYS-CALL/sys-call-function.c
The System Call Table
Limitations
Structure (in i386)
Add a New System Call
User Side
Kernel Side
BASELINE-SYS-CALL-TABLE-HACKING/sys_call_table_hacker.c
Utilizzo della System Map
Codice kernel
Compilazione
Nota su kASLR
Nota su write_cr0()
Codice user
13 - KERNEL PROGRAMMING BASICS VI
Lecture Info
Homework #2: SCTD
Requirements
Solution
Syscall Dispatcher
Dispatcher for int 0x80 (kernel 2.4)
Dispatcher for syscall (kernel 2.4)
swapgs instruction
Dispatcher (kernel 4.17)
SYSCALL_DEFINE macros
PTI
Virtual Dynamic Shared Object (VDSO)
Addr of VDSO
SYS-CALL/vdso.c
SYS-CALL/fast-vs-slow-syscall.c
DUAL-SYSCALL-TABLE-HACKING/sys_call_table_hacker.c
Kernel Software Organization
Kernel Compilation
Configuring the Kernel
Compilation steps
Role of initrd
System Map
14 - KERNEL MEMORY-MANAGEMENT I
Lecture Info
Startup Tasks
BIOS e UEFI
BIOS e MBR in x86
UEFI
Kernel Start-Up Process
Multi-Core Startup Process
head.S
__init Functions
Botmem
Memblock
Addr Resolution
Modern RAM Organization
numactl
Structure for Steady-State Memory Management
Directly Mapped Memory Pages
15 - KERNEL MEMORY-MANAGEMENT II
Lecture Info
Paging in x86 protected mode
Page Table Structure in i386
Linux Paging vs i386
Page Table Data Structures
Table Entries in i386
i386 PDE entries
i386 PTE entries
Granularity and Procetion Bits
Bit Masking in Linux
Order of Flag Checking by Firmware
Runtime Detection of Current Page Size
Kernel Page Table Expansion (Kernel 2.4/i386)
pagetable_init()
16 - KERNEL MEMORY-MANAGEMENT III
Lecture Info
Physical Address Extension (PAE)
x86-64 Architectures
Canonical Addresses
Linux Address Space on x86-64
48-bit Addessing in x86-64
PAGE-TABLE-AUDITOR/page-table-auditor.c
Huge Pages for Users
L1 Terminal Fault (L1TF)
L1TF and Virtualization
Hardware Supported "virtual memory" Virtualization
Core Map
17 - KERNEL MEMORY-MANAGEMENT IV
Lecture Info
Homework #3: VTPMO
Memory Management at Steady State
Memory Organization in UMA Architectures
Free Lists
Buddy Allocator System
Dealing With NUMA machines
Releasing Boot Memory
Memory Allocation Contexts
Buddy-System API
Mem-Policy
Mem-Policy API
NUMA/numa-test.c
18 - KERNEL MEMORY-MANAGEMENT V
Lecture Info
Quicklists
Quicklist Implementation
Quicklist API
Logical to Physical Addr Translation
BUDDY-VS-PER-CPU-QUICK-LIST/allocators.c
SLUB Allocator
Kernel Page and TLB State
Types of TLB Events
TLB Flush Costs
Linux TLB Flush APIs
19 - CROSS RING DATA MOVE I
Lecture Info
User/Kernel Interactions
Flexisble Segmentation
Constrained Segmentation
Per-Thread Memory Limits
User/Kernel Data Move API
copy_to_user() timeline
Service Redundancy
Constrained Supervisor Mode
Kernel Masked Segfaults
RUNNING EXAMPLES
message-exchange-service
message-exchange-service-intermediate-buffering
20 - LINUX MODULES I
Lecture Info
Linux Module Basics
Requirements
Who is Responsible?
Kernel Modules APIs
Module Struct
API for kernel <= 2.4
API for kernel >= 2.6
Common Parts
Module Parameters
Pseudo-files Interface
Array as Module Parameter
Loading/Unloading Modules
Building A Kernel Object (.ko)
Module Headings
Management of usage_count
Kernel Exported Symbols
Dynamic Symbol Querying
PARAMETRIC-MESSAGE-EXCHANGE-SERVICE
21 - LINUX MODULES II
Lecture Info
Kernel Probing
kprobe Data Structure
Kprobe Mechanism
Pre-handler
Post-handler
Kprobe API
Denial of Probing
Useful Macros
dmesg
printk()
Message Priority Levels
Message Priority Treatment
syslog()
Kernel Panic
RUNNING EXAMPLES
RUNNING EXAMPLE #1
KPROBE-USAGE-EXAMPLE
KERNEL-FUNCTION-POINTER-EXHIBITION
STDIN-KPROBE-INTERCEPTOR
22 - KERNEL TASK MANAGEMENT I
Lecture Info
Homework #4
Homework #5
Tasks vs Processes/Threads
Time-Sharing With Work Deferring
Reconciliation Points
Top/Bottom Half Programminng
Implementation in Linux
Task Queues
Pre-Defined Task Queues
Task Queue Data Structure
Task Queues API
Reconciliation Points
Limitations
SoftIRQ Architecture
Tasklets
23 - KERNEL TASK MANAGEMENT II
Lecture Info
SoftIRQ (Kernels > 2.5)
SoftIRQ Entries
SoftIRQ Workers
Tasklet
Tasklet API
tasklet_init()
Work Queues
Original Work Queues API
Work Queue Issues
Concurrency Managed Work Queues
container_of() macro
Running Examples
RE: TASKLET
RE: WORK-QUEUS
24 - KERNEL TASK MANAGEMENT III
Lecture Info
Timer Interrupts
Timer Interrupts and CPU Reschedules
Disable Timer Interrupts on Demand
Kernel Execution and Busy-Waiting
How Time is Measured in x86
LAPIC-T Timer Interrupts
old-style (task queus)
new-style (softIRQ)
High Resolution (HR) Timers
usleep()
HR-Timer Kernel API
Preemption Request
Preemption API
Per-CPU Variables
Thread Control Block (TCB)
CPU-Dispatchability
Runqueue and Waitqueues
Sleep/Wait Kernel Services
25 - KERNEL TASK MANAGEMENT IV
Lecture Info
Thread Control Block (TCB)
TCB Structure
TCB Allocation
TCB in kernel < 2.6
TCB in 2.6 <= kernel <= 4.8
Current Macro
Thread States
Virtually Mapped Stacks
Run Queue (kernel 2.4)
Wait Queues (kernel 2.4)
Wait Queues APIs
Thundering Herd Effect
Wait Queues and TCB Linkage Dynamics
Wait Event Queues (5.x style)
Scheme for Interruptible Waits
RUNNING EXAMPLES
CPU-POSITIONING-SWITCHING-SERVICE
module #1
module #2
SLEEP-WAKEUP-QUEUE
sys_goto_sleep()
sys_awake()
26 - KERNEL TASK MANAGEMENT V
Lecture Info
TCB and Memory Management
vm_area_struct
Threads Identification
PID Namespaces Scheme
Namespace Visibility
Namespace Implementation
PID to task_struct Mapping
find_task_by_pid (old way)
find_task_by_vpid (new way)
Creation of Processes/Threads
clone()
do_fork()
RUNNING EXAMPLES
O1-SLEEP-WAKEUP-QUEUE
USLEEP
VM-CHECKER
VIRTUAL-PIDS
NAMESPACES
27 - KERNEL TASK MANAGEMENT VI
Lecture Info
Thread Syncronization
Semaphore API
Spinlock API
Read/Write Locks API
Linux Scheduler Logic
Schedule Baseline Aspect
POSIX Priority Scheme
Lists Macro Facilities
Scheduler #1: Perfect Load Sharing
scheduler()
Goodness Value
mm and active_mm
Formula Used
Epochs Management
Overview
Scheduler #2: Load Balancing
Main Characteristics
Implementation Scheme
Calcolo dei Ticks
Static and Dynamic Priorities
CPU-Scheduling API
Explicit Stack Refresh
Runqueue Structure
28 - KERNEL TASK MANAGEMENT VII
Lecture Info
Scheduer #3: Completely Fair Scheduling
Basic Concepts
VCPU Advacement
Kernel Threads
arch_kernel_thread()
Kernel Thread APIs
KT-STARTUP-SERVICE
29 - TRAP/INTERRUPT ARCHITECTURE I
Lecture Info
Single-Core Concepts
Issues with Multi-Core
Inter Process Interrupt (IPI)
Advanced Programmable Interrupt Controller (APIC)
IRQ vs INT
I/O APIC
Interrupt Descriptor Table (IDT)
IDT Entries Usage in Linux
Spurious Interrupts
IDT Entries
x86 protected mode
x86-64
IDT APIs
Trap/Interrupts Handlers
Page Table Isolation
Top-Level Interrupts Handlers
30 - TRAP/INTERRUPT ARCHITECTURE II
Lecture Info
IPI Usage
IPI in Linux
IPI API
Sequentialization of IPIs
Preemption Effects of IPIs
RUNNING EXAMPLES
IDT-NEW-TRAP-INSTALLATION
TRAP-BASED-CONTEXT-SWITCH
IDT-NEW-TRAP-INSTALLATION-ON-SPURIOUS
MASTER-SLAVE-SYNCH-AND-KERNEL-PATCHING
31 - VIRTUAL FILE SYSTEM I
Lecture Info
File System Basics
Virtual File System
Example: True files
Block Drivers and Char Drivers
superblock_read()
VFS Startup in LINUX
struct file_system_type
Linking RootFS
Data Structures for VFS
struct vfsmount
struct super_block
struct dentry
struct inode
Randomize Layout in Structs
Initializing the RootFS instance
Process Working Directory and Root Directory
FS Mounting and Namespaces
32 - VIRTUAL FILE SYSTEM II
Lecture Info
Threads e VFS
Isolamento a grana fine
struct fs_struct
File Descriptor Table
VFS API Layering
Example #1: Path-based API
Example #2: Data-structure based API
Device-Drivers Table
Major Numbers
Drivers a Istanza Multipla
Minor Numbers
Oggetti di I/O
mknod() system call
Device Numbers in x86
Block-device drivers
Char-device drivers
MAJOR-MINOR-MANAGEMENT/baseline-char-dev.c
33 - VIRTUAL FILE SYSTEM III
Lecture Info
DRIVER-CONCURRENCY/driver-concurrency.c
dev_open()
dev_release()
dev_write()
dev_read()
init_module()
cleanup_module()
Esecuzione e Testing
BROADCAST-DEV/broadcast.c
Homework: PC
Note generali
__register_chrdev()
34 VIRTUAL FILE SYSTEM IV
Lecture Info
ioctl()
Final Part of Boot
RamFS /proc and /sys
/proc
Struttura di /proc
Registrazione di /proc
proc API
/sys
/sys API
/proc vs /sys