Add architecture compatibility checking during module initialization
to ensure kstackwatch operates only on supported platforms.

Currently supported architectures:
- x86_64: Full hardware breakpoint support with arch_reinstall_hw_breakpoint()

Signed-off-by: Jinchao Wang <[email protected]>
---
 mm/kstackwatch/kernel.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/mm/kstackwatch/kernel.c b/mm/kstackwatch/kernel.c
index b6366808e891..9f01e0222210 100644
--- a/mm/kstackwatch/kernel.c
+++ b/mm/kstackwatch/kernel.c
@@ -189,8 +189,31 @@ static const struct proc_ops kstackwatch_proc_ops = {
        .proc_release = single_release,
 };
 
+static int is_ksw_supported(void)
+{
+       static const char *const supported_archs[] = { "x86_64", NULL };
+
+       const char *current_arch = utsname()->machine;
+       int i;
+
+       for (i = 0; supported_archs[i] != NULL; i++) {
+               if (strcmp(current_arch, supported_archs[i]) == 0) {
+                       pr_info("KSW: Architecture %s supports hardware 
breakpoints\n",
+                               current_arch);
+                       return 1;
+               }
+       }
+
+       pr_warn("KSW: Architecture %s may not support hardware breakpoints\n",
+               current_arch);
+       return 1;
+}
+
 static int __init kstackwatch_init(void)
 {
+       if (!is_ksw_supported())
+               return -EOPNOTSUPP;
+
        ksw_config = kmalloc(sizeof(*ksw_config), GFP_KERNEL);
        if (!ksw_config)
                return -ENOMEM;
-- 
2.43.0


Reply via email to