1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Kernel Configuration</title>
<link rel="stylesheet" href="style.css">
<style>
code {
color: #505050;
font-size: 10px;
border: 1px solid grey;
border-radius: 3px;
padding: 1.75px;
}
</style>
</head>
<body>
<h2>Kernel Configuration Pseudo Guide</h2>
<h4>Current base: <a href="https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/log/?h=linux-6.7.y">Linux 6.7.y</a></h4>
This aims to be a guide for configuring a Linux kernel for a modern
x86_64 machine containing hardware commonly found in laptops, desktops,
and other consumer computers. Note, this guide will sway more minimally,
meaning some features that are not strictly required will not be enabled.
All features will be built directly into kernel, no modules. This article
will not attempt to cover all possible configuration options, as it omits
entire sections that are not relevant on such systems, as well as some
hardware-specific configuration. Please also refer to the kernel's help text
for further information on respective options. I am not a kernel developer
and nothing here is guaranteed to be functionally accurate. If you feel
anything mentioned is wrong or should be switched around, please contact
me. This article assumes some prior knowledge of your system (eg. lspci,
lscpu, lsusb, dmidecode, <code>/proc/devices</code>, etc.) and general
kernel configuration/installation, such as obtaining source, generating and
maintaining <code>.config</code>, methods of configuration, compilation,
and installation. Throughout, the following acronyms will be used
<ul>
<li>STD: recommended/standard feature that generally should be enabled</li>
<li>DEV: useful for kernel development/debugging. not for general user</li>
<li>VIRT: virtulalisation related options (vhost/vguest)</li>
<li>OLD: modern systems generally won't need these options</li>
<li>SEC: security related options that either implicate or strengthen system security</li>
</ul>
<a href="#general_setup">general setup</a><br>
<a href="#processor_type_feat">processor type and features</a><br>
<div id="general_setup">
<h3>General setup</h3>
<ul>
<li>Compile also drivers which will not load (<code>CONFIG_COMPILE_TEST</code>): N, DEV</li>
<li>Compile the kernel with warnings as errors (<code>CONFIG_WERROR</code>): Y, STD</li>
<li>Local version - append to kernel release (<code>CONFIG_LOCALVERSION</code>): empty, useful for <a href="https://git-scm.com/docs/git-bisect">git bisect</a></li>
<li>Automatically append version information (<code>CONFIG_LOCALVERSION_AUTO</code>): N, DEV</li>
<li>Build ID Salt (<code>CONFIG_BUILD_SALT</code>): empty, SEC</li>
<li>Kernel compression mode: ZSTD or Gzip for compatibility</li>
<li>Default init path (<code>CONFIG_DEFAULT_INIT</code>): empty, EMB</li>
<li>Default hostname (<code>CONFIG_DEFAULT_HOSTNAME</code>): empty, entre your machine's name if you'd like</li>
<li>System V IPC (<code>CONFIG_SYSVIPC</code>): Y, STD</li>
<li>POSIX Message Queues (<code>CONFIG_POSIX_MQUEUE</code>): N, not strictly necessary</li>
<li>General notification queue (<code>CONFIG_WATCH_QUEUE</code>): N, not strictly necessary</li>
<li>Enable process_vm_readv/writev syscalls (<code>CONFIG_CROSS_MEMORY_ATTACH</code>): N, not strictly necessary</li>
<li>uselib syscall (<code>CONFIG_USELIB</code>): N, OLD</li>
<li>Auditing support (<code>CONFIG_AUDIT</code>): N, not strictly necessary</li>
<li>
Timers subsystem
<ul>
<li>Timer tick handling: Idle dynticks system (tickless idle)</li>
<li>Old Idle dynticks config (<code>CONFIG_NO_HZ</code>): N, OLD</li>
<li>High Resolution Timer Support (<code>CONFIG_HIGH_RES_TIMERS</code>): Y, STD</li>
<li>Clocksource watchdog maximum allowable skew (<code>CONFIG_CLOCKSOURCE_WATCHDOG_MAX_SKEW_US</code>): 100</li>
</ul>
</li>
<li>
BPF subsystem
<ul>
<li>Enable bpf() system call (<code>CONFIG_BPF_SYSCALL</code>): N, not necessary if you do not have any programs that utilise</li>
</ul>
</li>
<li>Preemption Model: Preemptible Kernel (Low-Latency Desktop)</li>
<li>Preemption behaviour defined on boot (<code>CONFIG_PREEMPT_DYNAMIC</code>): N</li>
<li>Core Scheduling for SMT (<code>CONFIG_SCHED_CORE</code>): Y, STD</li>
<li>
CPU/Task time and stats accounting
<ul>
<li>Cputime accounting: Simple tick based cputime accounting</li>
<li>Fine granularity task level IRQ time accounting (<code>CONFIG_IRQ_TIME_ACCOUNTING</code>): N, DEV</li>
<li>BSD Process Accounting (<code>CONFIG_BSD_PROCESS_ACCT</code>): N</li>
<li>Export task/process statistics through netlink (<code>CONFIG_TASKSTATS</code>): N</li>
<li>Pressure stall information tracking (<code>CONFIG_PSI</code>): N</li>
</ul>
</li>
<li>CPU isolation (<code>CONFIG_CPU_ISOLATION</code>): N, EMB</li>
<li>
RCU subsystem
<ul>
<li>Make expert-level adjustments to RCU configuration (<code>CONFIG_RCU_EXPERT</code>): N, DEV</li>
</ul>
</li>
<li>Kernel .config support (<code>CONFIG_IKCONFIG</code>): Y, STD</li>
<li>Enable access to .config through /proc/config.gz (<code>CONFIG_IKCONFIG_PROC</code>): Y, STD</li>
<li>Enable kernel headers through /sys/kernel/kheaders.tar.xz (<code>CONFIG_IKHEADERS</code>): N</li>
<li>Kernel log buffer size (<code>CONFIG_LOG_BUF_SHIFT</code>): 18</li>
<li>CPU kernel log buffer size contribution (<code>CONFIG_LOG_CPU_MAX_BUF_SHIFT</code>): 12</li>
<li>
Scheduler features
<ul>
<li>Enable utilization clamping for RT/FAIR tasks (<code>CONFIG_UCLAMP_TASK</code>): N, DEV</li>
</ul>
</li>
<li>
Control Group support (<code>CONFIG_CGROUPS</code>): Y, STD
<ul>
<li>Favor dynamic modification latency reduction (<code>CONFIG_CGROUP_FAVOR_DYNMODS</code>): N</li>
<li>Memory controller (<code>CONFIG_MEMCG</code>): Y, STD</li>
<li>IO controller (<code>CONFIG_BLK_CGROUP</code>): Y, STD</li>
<li>
CPU controller (<code>CONFIG_CGROUP_SCHED</code>): Y, STD
<ul>
<li>Group scheduling for SCHED_OTHER (<code>FAIR_GROUP_SCHED</code>): Y, STD</li>
<li>CPU bandwidth provisioning for FAIR_GROUP_SCHED (<code>CONFIG_CFS_BANDWIDTH</code>): N</li>
<li>Group scheduling for SCHED_RR/FIFO (<code>CONFIG_RT_GROUP_SCHED</code>): N</li>
</ul>
</li>
<li>PIDs controller (<code>CONFIG_CGROUP_PIDS</code>): N</li>
<li>RDMA controller (<code>CONFIG_CGROUP_RDMA</code>): N</li>
<li>Freezer controller (<code>CONFIG_CGROUP_FREEZER</code>): N</li>
<li>Cpuset controller (<code>CONFIG_CPUSETS</code>): N, only useful on NUMA machine</li>
<li>Device Controller (<code>CONFIG_CGROUP_DEVICE</code>): N</li>
<li>Simple CPU accounting controller (<code>CONFIG_CGROUP_CPUACCT</code>): Y, STD</li>
<li>Perf controller (<code>CONFIG_CGROUP_PERF</code>): N</li>
<li>Misc resource controller (<code>CONFIG_CGROUP_MISC</code>): Y</li>
<li>Debug controller (<code>CONFIG_CGROUP_DEBUG</code>): N, DEV</li>
</ul>
</li>
<li>
Namespaces support (<code>CONFIG_NAMESPACES</code>): Y, STD, used heavily by web browsers
<ul>
<li>UTS namespace (<code>CONFIG_UTS_NS</code>): Y</li>
<li>TIME namespace (<code>CONFIG_TIME_NS</code>): Y</li>
<li>IPC namespace (<code>CONFIG_IPC_NS</code>): Y</li>
<li>User namespace (<code>CONFIG_USER_NS</code>): Y</li>
<li>PID Namespaces (<code>CONFIG_PID_NS</code>): Y</li>
<li>Network namespace (<code>CONFIG_NET_NS</code>): Y</li>
</ul>
</li>
<li>Checkpoint/restore support (<code>CONFIG_CHECKPOINT_RESTORE</code>): N, VIRT</li>
<li>Automatic process group scheduling (<code>CONFIG_SCHED_AUTOGROUP</code>): N, OLD, Systemd/OpenRC handle this</li>
<li>Kernel -> userspace relay support (<code>CONFIG_RELAY</code>): Y, STD</li>
<li>Initial RAM filesystem and RAM disk (<code>CONFIG_BLK_DEV_INITRD</code>): N, not strictly necessary</li>
<li>Boot config support (<code>CONFIG_BOOT_CONFIG</code>): N, EMB</li>
<li>Preserve cpio archive mtimes in initramfs (<code>CONFIG_INITRAMFS_PRESERVE_MTIME</code>): N, without initramfs...</li>
<li>Compiler optimization level: Optimize for performance (-O2)</li>
<li>Configure standard kernel features (<code>CONFIG_EXPERT</code>): N, DEV/EMB, mostly syscalls</li>
<li>Enable kcmp() system call (<code>CONFIG_KCMP</code>): Y</li>
<li>Enable rseq() system call (<code>CONFIG_RSEQ</code>): Y</li>
<li>Enable cachestat() system call (<code>CONFIG_CACHESTAT_SYSCALL</code>): Y</li>
<li>Enabled debugging of rseq() system call (<code>CONFIG_DEBUG_RSEQ</code>): N, DEV</li>
<li>PC/104 support (<code>CONFIG_PC104</code>): N, EMB</li>
<li>
Kernel Performance Events and Counters
<ul>
<li>Kernel Performance events and counters (<code>CONFIG_PERF_EVENTS</code>): Y, STD</li>
<li>Debug: use vmalloc to back perf mmap() buffers (<code>CONFIG_DEBUG_PERF_USE_VMALLOC</code>): N, DEV</li>
</ul>
</li>
<li>Profiling support (<code>CONFIG_PROFILING</code>): N, DEV</li>
<li>Kexec and crash features: None</li>
</ul>
</div>
<div id="processor_type_feat">
<h3>Processor type and features</h3>
<ul>
<li>Symmetric multi-processing support (<code>CONFIG_SMP</code>): Y, STD, all modern CPUs are multi-core</li>
<li>Enable MPS table (<code>CONFIG_X86_MPARSE</code>): N, OLD </li>
<li>x86 CPU resource control support (<code>CONFIG_X86_CPU_RESCTRL</code>): N, VIRT</li>
<li>Support for extended (non-PC) x86 platforms (<code>CONFIG_X86_EXTENDED_PLATFORM</code>): N, EMB</li>
<li>Intel Low Power Subsystem Support (<code>CONFIG_X86_INTEL_LPSS</code>): Y, if you have Haswell and later CPU</li>
<li>AMD ACPI2Platform devices support (<code>CONFIG_X86_AMD_PLATFORM_DEVICE</code>): N</li>
<li>Intel SoC IOSF Sideband support (<code>CONFIG_IOSF_MBI</code>): Y, STD</li>
<li>Single-depth WCHAN output (<code>CONFIG_SCHED_OMIT_FRAME_POINTER</code>): Y, STD</li>
<li>Linux guest support (<code>CONFIG_HYPERVISOR_GUEST</code>): N, VIRT</li>
<li>Processor family: Core 2/newer Xeon (or Generic-x86-64 if unsure)</li>
<li>Supported processor vendors (<code>CONFIG_PROCESSOR_SELECT</code>): N, EMB</li>
<li>Enable DMI scanning (<code>CONFIG_DMI</code>): Y, STD</li>
<li>Old AMD GART IOMMU support (<code>CONFIG_GART_IOMMU</code>): N, OLD</li>
<li>Enable Maximum number of SMP Processors and NUMA Nodes (<code>CONFIG_MAXSMP</code>): N, DEV</li>
<li>Maximum number of CPUs (<code>CONFIG_NR_CPUS</code>): sockets * cores * threads</li>
<li>Cluster scheduler support (<code>CONFIG_SCHED_CLUSTER</code>): Y, STD</li>
<li>Multi-core scheduler support (<code>CONFIG_SCHED_MC</code>): Y, STD</li>
<li>CPU core priorities scheduler support (<code>CONFIG_SCHED_MC_PRIO</code>): Y, STD</li>
<li>Reroute for broken boot IRQs (<code>CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS</code>): N, OLD</li>
<li>Machine Check / overheating reporting (<code>CONFIG_X86_MCE</code>): Y, STD</li>
<li>Support for deprecated /dev/mcelog character device (<code>CONFIG_X86_MCELOG_LEGACY</code>): N, OLD</li>
<li>Intel/AMD MCE features (<code>CONFIG_X86_MCE_INTEL/AMD</code>): Y, STD, choose based on your processor</li>
<li>
Performance monitoring
<ul>
<li>Intel uncore performance events (<code>CONFIG_PERF_EVENTS_INTEL_UNCORE</code>): Y, STD, for Intel</li>
<li>Intel/AMD rapl performance events (<code>CONFIG_PERF_EVENTS_INTEL_RAPL</code>): Y, STD</li>
<li>Intel cstate performance events (<code>CONFIG_PERF_EVENTS_INTEL_CSTATE</code>): Y, STD, for Intel</li>
<li>AMD Processor Power Reporting Mechanism (<code>CONFIG_PERF_EVENTS_AMD_POWER</code>): Y, STD, for AMD</li>
<li>AMD Uncore performance events (<code>CONFIG_PERF_EVENTS_AMD_POWER</code>): Y, STD, for AMD</li>
</ul>
</li>
<li>Enable vsyscall emulation (<code>CONFIG_X86_VSYSCALL_EMULATION</code>): N</li>
<li>IOPERM and IOPL Emulation (<code>CONFIG_X86_IOPL_IOPERM</code>): N, SEC, not strictly necessary</li>
<li>Late microcode loading (<code>CONFIG_MICROCODE_LATE_LOADING</code>): N</li>
<li>/dev/cpu/*/msr - Model-specific register support (<code>CONFIG_X86_MSR</code>): Y, STD</li>
<li>/dev/cpu/*/cpuid - CPU information support (<code>CONFIG_X86_CPUID</code>): Y, STD</li>
<li>Enable 5-level page tables support (<code>CONFIG_X86_5LEVEL</code>): N, for machines with large (TBs) amounts of memory</li>
<li>AMD Secure Memory Encryption (SME) support (<code>CONFIG_AMD_MEM_ENCRYPT</code>): Y, for AMD</li>
<li>NUMA Memory Allocation and Scheduler Support (<code>CONFIG_NUMA</code>): N, unless you have multi socket CPU</li>
<li>Check for low memory corruption (<code>CONFIG_X86_CHECK_BIOS_CORRUPTION</code>): N</li>
<li>MTRR (Memory Type Range Register) support (<code>CONFIG_MTRR</code>): Y, STD</li>
<li>MTRR cleanup support (<code>CONFIG_MTRR_SANITIZER</code>): Y, STD</li>
<li>MTRR cleanup enable value (0-1) (<code>CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT</code>): 1, for true</li>
<li>MTRR cleanup spare reg num (0-7) (<code>CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT</code>): 1</li>
<li>x86 PAT support (<code>CONFIG_X86_PAT</code>): Y, STD</li>
<li>User Mode Instruction Prevention (<code>CONFIG_X86_UMIP</code>): Y</li>
<li>Indirect Branch Tracking (<code>CONFIG_X86_KERNEL_IBT</code>): N, SEC</li>
<li>Memory Protection Keys (<code>CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS</code>): Y, STD</li>
<li>TSX enable mode: auto</li>
<li>X86 userspace shadow stack (<code>CONFIG_X86_USER_SHADOW_STACK</code>): N, SEC</li>
<li>EFI runtime service support (<code>CONFIG_EFI</code>): Y, STD</li>
<li>EFI stub support (<code>CONFIG_EFI_STUB</code>): N, only if you boot kernel directly</li>
<li>EFI handover protocol (<code>CONFIG_EFI_HANDOVER_PROTOCOL</code>): N, OLD</li>
<li>EFI mixed-mode support (<code>CONFIG_EFI_MIXED</code>): N, only relevant (but still unneeded) on Apple hardware</li>
<li>Enable EFI fake memory map (<code>CONFIG_EFI_FAKE_MEMMAP</code>): N</li>
<li>Export EFI runtime maps to sysfs (<code>CONFIG_EFI_RUNTIME_MAP</code>): N</li>
<li>Timer frequency: 100 HZ for server, 300 HZ for laptop, 1000 HZ for low-latency requirements</li>
<li>Physical address where the kernel is loaded (<code>CONFIG_PHYSICAL_START</code>): 0x1000000</li>
<li>Build a relocatable kernel (<code>CONFIG_RELOCATABLE</code>): Y, STD</li>
<li>Randomize the address of the kernel image (KASLR) (<code>CONFIG_RANDOMIZE_BASE</code>): Y, SEC</li>
<li>Alignment value to which the kernel should be aligned (<code>CONFIG_PHYSICAL_ALIGN</code>): 0x200000</li>
<li>Randomize the kernel memory sections (<code>CONFIG_RANDOMIZE_BASE</code>): Y, SEC</li>
<li>Physcial memory mapping padding (<code>CONFIG_RANDOMIZE_MEMORY_PHYSICAL_PADDING</code>): 0x00</li>
<li>Linear Address Masking support (<code>CONFIG_ADDRESS_MASKING</code>): N</li>
<li>vsyscall table for legacy applications: None</li>
<li>Built-in kernel command line (<code>CONFIG_CMDLINE_BOOL</code>): N, unless booting kernel directly</li>
<li>Enable the LDT (local descriptor table) (<code>CONFIG_MODIFY_LDT_SYSCALL</code>): N, EMB</li>
<li>Enforce strict size checking for sigalstack (<code>CONFIG_STRICT_SIGALSTACK_SIZE</code>): N, DEV</li>
</ul>
</div>
This is a WIP...
</body>
</html>
|