Skip to content

kpatch-syscall.h: don't redefine SC_ARM64_REGS_TO_ARGS - #1539

Open
usebeforefree wants to merge 1 commit into
dynup:masterfrom
usebeforefree:arm-macro-redef-fix
Open

usebeforefree wants to merge 1 commit into
dynup:masterfrom
usebeforefree:arm-macro-redef-fix

Conversation

@usebeforefree

Copy link
Copy Markdown
Contributor

This PR currently includes usebeforefree/integration-rhel10.4 commits as well, because this issue is raised only for rhel10.4 for now. But if the issue is fixed by the latest commit in this PR, it would make sense to merge it only.

Upstream kernel commit 5a87e8c7f370 ("arm64: syscall: Pass 'orig_x0' as
first argument to native system call") changed the kernel's
SC_ARM64_REGS_TO_ARGS() macro.

kpatch-syscall.h defines its own copy of the macro. Until now both
copies were identical, so the second definition was harmless. Now that
they differ, any file that includes kpatch-macros.h fails to build on
arm64 kernels that have this change:

        kpatch-syscall.h:216:9: error: "SC_ARM64_REGS_TO_ARGS" redefined

This fix makes sure the macro is defined only if it's not defined
already, so it should work with both kernels pre and post 5a87e8c7f370

Signed-off-by: Marko Kostić <mkostic@redhat.com>

@usebeforefree

usebeforefree commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

The tests pass, the only thing left is to confirm the bug occurs in these integration tests:

  1. Original failures (kpatch-tier2): https://artifacts.osci.redhat.com/testing-farm/6dc555f6-a8dd-4ed6-86f8-86b9c7787486/
    https://artifacts.osci.redhat.com/testing-farm/50ac30d5-4ecc-4173-b276-429f0f74c9be/

  2. Integration test run that should fail: https://artifacts.osci.redhat.com/testing-farm/d72fa67a-ecda-4b48-b3ac-f5876745a941

Called 2. with this command:

testing-farm request \
    --no-wait \
    --compose RHEL-10.4-Nightly \
    --pool beaker \
    --arch aarch64 \
    --git-url https://gitlab.com/redhat/centos-stream/tests/kernel/test-plans.git \
    --plan 'kpatch/kpatch-integration-rhel/kernel$' \
    --environment KPATCH_GIT=https://github.com/usebeforefree/kpatch.git \
    --environment KPATCH_REV=integration-rhel10.4 \
    --environment KPATCH_UNIT=0 \
    --timeout 1440 \
    --environment TMT_REBOOT_TIMEOUT=1200 \
    --environment TMT_SSH_ConnectionAttempts=20 \
    --environment TMT_SSH_ServerAliveCountMax=180 \
    --environment MAX_REBOOT_TIME=0 \
    --tmt-discover '--how=fmf --insert --url=https://gitlab.com/redhat/centos-stream/tests/kernel/test-plans.git --test=/misc/machineinfo --order 1' \
    --hardware 'memory=>= 50 GB' \
    --hardware 'cpu.processors=>= 20'

Below is the successful run with the commit on top of integration-rhel10.4, where the bug should be triggered otherwise:
https://artifacts.osci.redhat.com/testing-farm/5dab7092-1bff-43b8-8c3a-501b415c28e0/

@joe-lawrence

Copy link
Copy Markdown
Contributor

Does this more closely align with how the file handles these API changes? The original design was to facilitate using a diff tool against the kernel counterpart for each respective "version". (Completely untested :)

diff --git a/kmod/patch/kpatch-syscall.h b/kmod/patch/kpatch-syscall.h
index 16c5a0de3de8..3e2e910a8739 100644
--- a/kmod/patch/kpatch-syscall.h
+++ b/kmod/patch/kpatch-syscall.h
@@ -211,12 +211,33 @@
 
 #elif defined(CONFIG_ARM64)
 
+# if defined(RHEL_RELEASE_CODE)
+#  if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(10, 4)
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V2
+#  else
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V1
+#  endif
+# else
+#  if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 2, 0)
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V2
+#  else
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V1
+#  endif
+# endif
+diff --git a/kmod/patch/kpatch-syscall.h b/kmod/patch/kpatch-syscall.h
index 16c5a0de3de8..3e2e910a8739 100644
--- a/kmod/patch/kpatch-syscall.h
+++ b/kmod/patch/kpatch-syscall.h
@@ -211,12 +211,33 @@
 
 #elif defined(CONFIG_ARM64)
 
+# if defined(RHEL_RELEASE_CODE)
+#  if RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(10, 4)
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V2
+#  else
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V1
+#  endif
+# else
+#  if LINUX_VERSION_CODE >= KERNEL_VERSION(7, 2, 0)
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V2
+#  else
+#   define KPATCH_SC_ARM64_REGS_TO_ARGS_V1
+#  endif
+# endif
+
 /* arm64/include/asm/syscall_wrapper.h versions */
 
-#define SC_ARM64_REGS_TO_ARGS(x, ...)       \
-  __MAP(x,__SC_ARGS         \
-        ,,regs->regs[0],,regs->regs[1],,regs->regs[2] \
-        ,,regs->regs[3],,regs->regs[4],,regs->regs[5])
+#if KPATCH_SC_ARM64_REGS_TO_ARGS_V1
+#define SC_ARM64_REGS_TO_ARGS(x, ...)				\
+	__MAP(x,__SC_ARGS					\
+	      ,,regs->regs[0],,regs->regs[1],,regs->regs[2]	\
+	      ,,regs->regs[3],,regs->regs[4],,regs->regs[5])
+#else
+#define SC_ARM64_REGS_TO_ARGS(x, ...)				\
+	__MAP(x,__SC_ARGS					\
+	      ,,regs->orig_x0,,regs->regs[1],,regs->regs[2]	\
+	      ,,regs->regs[3],,regs->regs[4],,regs->regs[5])
+#endif
 
 #define __KPATCH_SYSCALL_DEFINEx(x, name, ...)           \
   asmlinkage long __arm64_sys##name(const struct pt_regs *regs);    \
 /* arm64/include/asm/syscall_wrapper.h versions */
 
-#define SC_ARM64_REGS_TO_ARGS(x, ...)       \
-  __MAP(x,__SC_ARGS         \
-        ,,regs->regs[0],,regs->regs[1],,regs->regs[2] \
-        ,,regs->regs[3],,regs->regs[4],,regs->regs[5])
+#if KPATCH_SC_ARM64_REGS_TO_ARGS_V1
+#define SC_ARM64_REGS_TO_ARGS(x, ...)				\
+	__MAP(x,__SC_ARGS					\
+	      ,,regs->regs[0],,regs->regs[1],,regs->regs[2]	\
+	      ,,regs->regs[3],,regs->regs[4],,regs->regs[5])
+#else
+#define SC_ARM64_REGS_TO_ARGS(x, ...)				\
+	__MAP(x,__SC_ARGS					\
+	      ,,regs->orig_x0,,regs->regs[1],,regs->regs[2]	\
+	      ,,regs->regs[3],,regs->regs[4],,regs->regs[5])
+#endif
 
 #define __KPATCH_SYSCALL_DEFINEx(x, name, ...)           \
   asmlinkage long __arm64_sys##name(const struct pt_regs *regs);    \

Upstream kernel commit 5a87e8c7f370 ("arm64: syscall: Pass 'orig_x0' as
first argument to native system call") changed the kernel's
SC_ARM64_REGS_TO_ARGS() macro.

kpatch-syscall.h defines its own copy of the macro. Until now both
copies were identical, so the second definition was harmless. Now that
they differ, any file that includes kpatch-macros.h fails to build on
arm64 kernels that have this change:

	kpatch-syscall.h:216:9: error: "SC_ARM64_REGS_TO_ARGS" redefined

This fix removes the macro, since it's already defined elsewhere. All
other arches do this in the first place anyways. Works on both kernels
pre and post 5a87e8c7f370.

Signed-off-by: Marko Kostić <mkostic@redhat.com>

@joe-lawrence joe-lawrence left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and tracks with how other SC_<ARCH>_REGS_TO_ARGS macros are omitted from the header file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants