Merge tag 'sysctl-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 26 May 2022 23:57:20 +0000 (16:57 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 26 May 2022 23:57:20 +0000 (16:57 -0700)
Pull sysctl updates from Luis Chamberlain:
 "For two kernel releases now kernel/sysctl.c has been being cleaned up
  slowly, since the tables were grossly long, sprinkled with tons of
  #ifdefs and all this caused merge conflicts with one susbystem or
  another.

  This tree was put together to help try to avoid conflicts with these
  cleanups going on different trees at time. So nothing exciting on this
  pull request, just cleanups.

  Thanks a lot to the Uniontech and Huawei folks for doing some of this
  nasty work"

* tag 'sysctl-5.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux: (28 commits)
  sched: Fix build warning without CONFIG_SYSCTL
  reboot: Fix build warning without CONFIG_SYSCTL
  kernel/kexec_core: move kexec_core sysctls into its own file
  sysctl: minor cleanup in new_dir()
  ftrace: fix building with SYSCTL=y but DYNAMIC_FTRACE=n
  fs/proc: Introduce list_for_each_table_entry for proc sysctl
  mm: fix unused variable kernel warning when SYSCTL=n
  latencytop: move sysctl to its own file
  ftrace: fix building with SYSCTL=n but DYNAMIC_FTRACE=y
  ftrace: Fix build warning
  ftrace: move sysctl_ftrace_enabled to ftrace.c
  kernel/do_mount_initrd: move real_root_dev sysctls to its own file
  kernel/delayacct: move delayacct sysctls to its own file
  kernel/acct: move acct sysctls to its own file
  kernel/panic: move panic sysctls to its own file
  kernel/lockdep: move lockdep sysctls to its own file
  mm: move page-writeback sysctls to their own file
  mm: move oom_kill sysctls to their own file
  kernel/reboot: move reboot sysctls to its own file
  sched: Move energy_aware sysctls to topology.c
  ...

17 files changed:
1  2 
fs/proc/proc_sysctl.c
include/linux/ftrace.h
include/linux/writeback.h
kernel/kexec_core.c
kernel/locking/lockdep.c
kernel/panic.c
kernel/rcu/rcu.h
kernel/reboot.c
kernel/sched/core.c
kernel/sched/deadline.c
kernel/sched/fair.c
kernel/sched/rt.c
kernel/sched/sched.h
kernel/sysctl.c
kernel/trace/ftrace.c
mm/oom_kill.c
mm/page-writeback.c

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc kernel/panic.c
Simple merge
Simple merge
diff --cc kernel/reboot.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc kernel/sysctl.c
Simple merge
@@@ -7909,120 -7872,118 +7872,180 @@@ int unregister_ftrace_function(struct f
  }
  EXPORT_SYMBOL_GPL(unregister_ftrace_function);
  
- static bool is_permanent_ops_registered(void)
- {
-       struct ftrace_ops *op;
-       do_for_each_ftrace_op(op, ftrace_ops_list) {
-               if (op->flags & FTRACE_OPS_FL_PERMANENT)
-                       return true;
-       } while_for_each_ftrace_op(op);
-       return false;
- }
- int
- ftrace_enable_sysctl(struct ctl_table *table, int write,
-                    void *buffer, size_t *lenp, loff_t *ppos)
- {
-       int ret = -ENODEV;
-       mutex_lock(&ftrace_lock);
-       if (unlikely(ftrace_disabled))
-               goto out;
-       ret = proc_dointvec(table, write, buffer, lenp, ppos);
-       if (ret || !write || (last_ftrace_enabled == !!ftrace_enabled))
-               goto out;
-       if (ftrace_enabled) {
-               /* we are starting ftrace again */
-               if (rcu_dereference_protected(ftrace_ops_list,
-                       lockdep_is_held(&ftrace_lock)) != &ftrace_list_end)
-                       update_ftrace_function();
-               ftrace_startup_sysctl();
-       } else {
-               if (is_permanent_ops_registered()) {
-                       ftrace_enabled = true;
-                       ret = -EBUSY;
-                       goto out;
-               }
-               /* stopping ftrace calls (just send to ftrace_stub) */
-               ftrace_trace_function = ftrace_stub;
-               ftrace_shutdown_sysctl();
-       }
-       last_ftrace_enabled = !!ftrace_enabled;
-  out:
-       mutex_unlock(&ftrace_lock);
-       return ret;
- }
 +static int symbols_cmp(const void *a, const void *b)
 +{
 +      const char **str_a = (const char **) a;
 +      const char **str_b = (const char **) b;
 +
 +      return strcmp(*str_a, *str_b);
 +}
 +
 +struct kallsyms_data {
 +      unsigned long *addrs;
 +      const char **syms;
 +      size_t cnt;
 +      size_t found;
 +};
 +
 +static int kallsyms_callback(void *data, const char *name,
 +                           struct module *mod, unsigned long addr)
 +{
 +      struct kallsyms_data *args = data;
 +
 +      if (!bsearch(&name, args->syms, args->cnt, sizeof(*args->syms), symbols_cmp))
 +              return 0;
 +
 +      addr = ftrace_location(addr);
 +      if (!addr)
 +              return 0;
 +
 +      args->addrs[args->found++] = addr;
 +      return args->found == args->cnt ? 1 : 0;
 +}
 +
 +/**
 + * ftrace_lookup_symbols - Lookup addresses for array of symbols
 + *
 + * @sorted_syms: array of symbols pointers symbols to resolve,
 + * must be alphabetically sorted
 + * @cnt: number of symbols/addresses in @syms/@addrs arrays
 + * @addrs: array for storing resulting addresses
 + *
 + * This function looks up addresses for array of symbols provided in
 + * @syms array (must be alphabetically sorted) and stores them in
 + * @addrs array, which needs to be big enough to store at least @cnt
 + * addresses.
 + *
 + * This function returns 0 if all provided symbols are found,
 + * -ESRCH otherwise.
 + */
 +int ftrace_lookup_symbols(const char **sorted_syms, size_t cnt, unsigned long *addrs)
 +{
 +      struct kallsyms_data args;
 +      int err;
 +
 +      args.addrs = addrs;
 +      args.syms = sorted_syms;
 +      args.cnt = cnt;
 +      args.found = 0;
 +      err = kallsyms_on_each_symbol(kallsyms_callback, &args);
 +      if (err < 0)
 +              return err;
 +      return args.found == args.cnt ? 0 : -ESRCH;
 +}
++
+ #ifdef CONFIG_SYSCTL
+ #ifdef CONFIG_DYNAMIC_FTRACE
+ static void ftrace_startup_sysctl(void)
+ {
+       int command;
+       if (unlikely(ftrace_disabled))
+               return;
+       /* Force update next time */
+       saved_ftrace_func = NULL;
+       /* ftrace_start_up is true if we want ftrace running */
+       if (ftrace_start_up) {
+               command = FTRACE_UPDATE_CALLS;
+               if (ftrace_graph_active)
+                       command |= FTRACE_START_FUNC_RET;
+               ftrace_startup_enable(command);
+       }
+ }
+ static void ftrace_shutdown_sysctl(void)
+ {
+       int command;
+       if (unlikely(ftrace_disabled))
+               return;
+       /* ftrace_start_up is true if ftrace is running */
+       if (ftrace_start_up) {
+               command = FTRACE_DISABLE_CALLS;
+               if (ftrace_graph_active)
+                       command |= FTRACE_STOP_FUNC_RET;
+               ftrace_run_update_code(command);
+       }
+ }
+ #else
+ # define ftrace_startup_sysctl()       do { } while (0)
+ # define ftrace_shutdown_sysctl()      do { } while (0)
+ #endif /* CONFIG_DYNAMIC_FTRACE */
+ static bool is_permanent_ops_registered(void)
+ {
+       struct ftrace_ops *op;
+       do_for_each_ftrace_op(op, ftrace_ops_list) {
+               if (op->flags & FTRACE_OPS_FL_PERMANENT)
+                       return true;
+       } while_for_each_ftrace_op(op);
+       return false;
+ }
+ static int
+ ftrace_enable_sysctl(struct ctl_table *table, int write,
+                    void *buffer, size_t *lenp, loff_t *ppos)
+ {
+       int ret = -ENODEV;
+       mutex_lock(&ftrace_lock);
+       if (unlikely(ftrace_disabled))
+               goto out;
+       ret = proc_dointvec(table, write, buffer, lenp, ppos);
+       if (ret || !write || (last_ftrace_enabled == !!ftrace_enabled))
+               goto out;
+       if (ftrace_enabled) {
+               /* we are starting ftrace again */
+               if (rcu_dereference_protected(ftrace_ops_list,
+                       lockdep_is_held(&ftrace_lock)) != &ftrace_list_end)
+                       update_ftrace_function();
+               ftrace_startup_sysctl();
+       } else {
+               if (is_permanent_ops_registered()) {
+                       ftrace_enabled = true;
+                       ret = -EBUSY;
+                       goto out;
+               }
+               /* stopping ftrace calls (just send to ftrace_stub) */
+               ftrace_trace_function = ftrace_stub;
+               ftrace_shutdown_sysctl();
+       }
+       last_ftrace_enabled = !!ftrace_enabled;
+  out:
+       mutex_unlock(&ftrace_lock);
+       return ret;
+ }
+ static struct ctl_table ftrace_sysctls[] = {
+       {
+               .procname       = "ftrace_enabled",
+               .data           = &ftrace_enabled,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = ftrace_enable_sysctl,
+       },
+       {}
+ };
+ static int __init ftrace_sysctl_init(void)
+ {
+       register_sysctl_init("kernel", ftrace_sysctls);
+       return 0;
+ }
+ late_initcall(ftrace_sysctl_init);
+ #endif
diff --cc mm/oom_kill.c
Simple merge
Simple merge