Skip to content

Commit d87366f

Browse files
committed
scripts/check-config: fix kernel version checks
Looking at the code, I found out that kernel_lt function was actually doing le ("less than or equal") rather than lt ("less than") operation. Let's fix this and do exactly what the name says. A bigger issue is, the function use was not consistent (some uses implied "less than or equal"). To fix the usage, find out all relevant kernel commits and kernel versions that have them (the latter is done using "git describe --contains $sha"), and fix the wrong cases. While at it, add references to all these kernel commits for the future generations of check-config.sh hackers. Also, add kernel_ge function which is the opposite of kernel_lt, and document both. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 7f65cc7 commit d87366f

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

script/check-config.sh

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,19 @@ kernelMajor="${kernelVersion%%.*}"
2929
kernelMinor="${kernelVersion#"$kernelMajor".}"
3030
kernelMinor="${kernelMinor%%.*}"
3131

32+
# Usage: to check if kernel version is < 4.8, use
33+
# kernel_lt 4 8
34+
# (here "lt" stands for "less than").
3235
kernel_lt() {
3336
[ "$kernelMajor" -lt "$1" ] && return
34-
[ "$kernelMajor" -eq "$1" ] && [ "$kernelMinor" -le "$2" ]
37+
[ "$kernelMajor" -eq "$1" ] && [ "$kernelMinor" -lt "$2" ]
38+
}
39+
40+
# Usage: to check if kernel version is >= 6.1, use
41+
# kernel_ge 6 1
42+
# (here "ge" stands for "greater or equal").
43+
kernel_ge() {
44+
! kernel_lt "$1" "$2"
3545
}
3646

3747
is_set() {
@@ -234,16 +244,17 @@ flags=(
234244
)
235245
check_flags "${flags[@]}"
236246

237-
if ! kernel_lt 4 14; then
238-
if [ $cgroup = "v2" ]; then
239-
check_flags CGROUP_BPF
240-
fi
247+
# Linux kernel commit 3007098494be.
248+
if kernel_ge 4 10 && [ $cgroup = "v2" ]; then
249+
check_flags CGROUP_BPF
241250
fi
242251

252+
# Linux kernel commit 3bf195ae6037.
243253
if kernel_lt 5 1; then
244254
check_flags NF_NAT_IPV4
245255
fi
246256

257+
# Linux kernel commit 4806e975729f99c7.
247258
if kernel_lt 5 2; then
248259
check_flags NF_NAT_NEEDED
249260
fi
@@ -259,9 +270,11 @@ echo 'Optional Features:'
259270
check_flags SECCOMP_FILTER
260271
check_flags CGROUP_PIDS
261272

273+
# Linux kernel commit e55b9f96860f.
262274
if kernel_lt 6 1; then
263275
check_flags MEMCG_SWAP
264276
fi
277+
# Linux kernel commit 2d1c498072de.
265278
if kernel_lt 5 8; then
266279
check_flags MEMCG_SWAP_ENABLED
267280
if is_set MEMCG_SWAP && ! is_set MEMCG_SWAP_ENABLED; then
@@ -270,20 +283,24 @@ echo 'Optional Features:'
270283
fi
271284
}
272285

286+
# Linux kernel commit d886f4e483ce.
273287
if kernel_lt 4 5; then
274288
check_flags MEMCG_KMEM
275289
fi
276290

277-
if kernel_lt 3 18; then
291+
# Linux kernel commit 5b1efc027c0b.
292+
if kernel_lt 3 19; then
278293
check_flags RESOURCE_COUNTERS
279294
fi
280295

281-
if kernel_lt 3 13; then
296+
# Linux kernel commit 86f8515f9721.
297+
if kernel_lt 3 14; then
282298
netprio=NETPRIO_CGROUP
283299
else
284300
netprio=CGROUP_NET_PRIO
285301
fi
286302

303+
# Linux kernel commit f382fb0bcef4.
287304
if kernel_lt 5 0; then
288305
check_flags IOSCHED_CFQ CFQ_GROUP_IOSCHED
289306
fi

0 commit comments

Comments
 (0)