Skip to content

Commit 3d44f1b

Browse files
author
George Guo
committed
kpatch/LoongArch: fix kernel panic with -fPIC for same-compilation-unit symbol references
Add architecture-specific -fPIC compiler flag for LoongArch64 to prevent kernel panics when applying livepatches containing references to symbols defined in the same compilation unit. Root cause: In the kpatch workflow, when a function is livepatched, it's extracted from the original object file and compiled into a separate kernel module. When the patched function references symbols defined in the same compilation unit (like 'uts_sem' in kernel/sys.c), these references break if not compiled as position-independent code. On LoongArch64, without -fPIC, references to same-compilation-unit symbols use absolute addressing that assumes fixed memory locations. When the function is relocated into the livepatch module, these absolute addresses become invalid, causing kernel panics. Example failure case: - SYSCALL_DEFINE1(newuname) references the same-compilation-unit symbol 'uts_sem' - When kpatch extracts this function into a module, the reference to 'uts_sem' must be properly relocated - Without -fPIC, the absolute address reference causes invalid memory access and kernel panic Solution: Force -fPIC compilation for all LoongArch64 kpatch builds. This ensures that references to same-compilation-unit symbols use position-independent addressing, allowing proper relocation by the kernel module loader and preventing kernel panics in livepatch scenarios. Co-developed-by: Kexin Liu <liukexin@kylinos.cn> Singed-off-by: Kexin Liu <liukexin@kylinos.cn> Signed-off-by: George Guo <guodongtai@kylinos.cn>
1 parent 57d1458 commit 3d44f1b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kpatch-build/kpatch-build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,10 @@ if [[ "$ARCH" = "s390x" ]]; then
12881288
! kernel_version_gte 6.10.0 && ARCH_KCFLAGS+=" -fPIE"
12891289
fi
12901290

1291+
if [[ "$ARCH" = "loongarch64" ]]; then
1292+
ARCH_KCFLAGS="-fPIC"
1293+
fi
1294+
12911295
export KCFLAGS="-I$DATADIR/patch -ffunction-sections -fdata-sections \
12921296
$ARCH_KCFLAGS $DEBUG_KCFLAGS"
12931297

0 commit comments

Comments
 (0)