What is the difference between kernel space and user space?
Short answer: Kernel space runs in the CPU's privileged mode (EL1 on ARM64, ring 0 on x86) with full access to hardware and all memory. User space runs unprivileged (EL0, ring 3) in isolated virtual address spaces, one per process. User programs enter the kernel only through system calls, exceptions (page faults) and interrupts. A bug in a user process kills that process; a bug in kernel code can crash or corrupt the whole system.
| User space | Kernel space | |
|---|---|---|
| CPU mode | EL0 / ring 3 | EL1 / ring 0 |
| Memory | own virtual address space, protected | all memory, shared by all kernel code |
| Hardware access | only via the kernel (or mapped regions like UIO/VFIO) | direct |
| Failure impact | process crashes (SIGSEGV) | oops/panic, whole system |
| Libraries | libc and anything | no libc; kernel APIs only, no floating point by default |
| Stack | large, grows | small, fixed (16 KB on ARM64/x86-64) |
How a system call works (ARM64): user code puts the syscall number in x8 and arguments in x0–x5, executes svc #0, the CPU switches to EL1 and jumps to the exception vector, the kernel saves registers, looks up sys_call_table[x8], runs the handler, puts the return value in x0 and returns with eret. On x86-64 it is the syscall instruction with the number in rax.
Address-space layout: on ARM64 the kernel uses the upper half (TTBR1) and user space the lower half (TTBR0), so system calls do not need to switch page tables; KPTI (Meltdown mitigation) changes this on affected CPUs.
Follow-ups: why the kernel cannot use floating point freely (FP state is not saved on kernel entry; use kernel_neon_begin/end), and why the kernel stack is small (one per thread; deep recursion and large locals are bugs).