1. 23 6月, 2015 2 次提交
    • D
      module: add per-module param_lock · b51d23e4
      Dan Streetman 提交于
      Add a "param_lock" mutex to each module, and update params.c to use
      the correct built-in or module mutex while locking kernel params.
      Remove the kparam_block_sysfs_r/w() macros, replace them with direct
      calls to kernel_param_[un]lock(module).
      
      The kernel param code currently uses a single mutex to protect
      modification of any and all kernel params.  While this generally works,
      there is one specific problem with it; a module callback function
      cannot safely load another module, i.e. with request_module() or even
      with indirect calls such as crypto_has_alg().  If the module to be
      loaded has any of its params configured (e.g. with a /etc/modprobe.d/*
      config file), then the attempt will result in a deadlock between the
      first module param callback waiting for modprobe, and modprobe trying to
      lock the single kernel param mutex to set the new module's param.
      
      This fixes that by using per-module mutexes, so that each individual module
      is protected against concurrent changes in its own kernel params, but is
      not blocked by changes to other module params.  All built-in modules
      continue to use the built-in mutex, since they will always be loaded at
      runtime and references (e.g. request_module(), crypto_has_alg()) to them
      will never cause load-time param changing.
      
      This also simplifies the interface used by modules to block sysfs access
      to their params; while there are currently functions to block and unblock
      sysfs param access which are split up by read and write and expect a single
      kernel param to be passed, their actual operation is identical and applies
      to all params, not just the one passed to them; they simply lock and unlock
      the global param mutex.  They are replaced with direct calls to
      kernel_param_[un]lock(THIS_MODULE), which locks THIS_MODULE's param_lock, or
      if the module is built-in, it locks the built-in mutex.
      Suggested-by: NRusty Russell <rusty@rustcorp.com.au>
      Signed-off-by: NDan Streetman <ddstreet@ieee.org>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      b51d23e4
    • D
      module: make perm const · 5104b7d7
      Dan Streetman 提交于
      Change the struct kernel_param.perm field to a const, as it should never
      be changed.
      Signed-off-by: NDan Streetman <ddstreet@ieee.org>
      Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (cut from larger patch)
      5104b7d7
  2. 28 5月, 2015 2 次提交
    • L
      kernel/params.c: generalize bool_enable_only · d19f05d8
      Luis R. Rodriguez 提交于
      This takes out the bool_enable_only implementation from
      the module loading code and generalizes it so that others
      can make use of it.
      
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: Jani Nikula <jani.nikula@intel.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: linux-kernel@vger.kernel.org
      Cc: cocci@systeme.lip6.fr
      Signed-off-by: NLuis R. Rodriguez <mcgrof@suse.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      d19f05d8
    • L
      kernel/params: constify struct kernel_param_ops uses · 9c27847d
      Luis R. Rodriguez 提交于
      Most code already uses consts for the struct kernel_param_ops,
      sweep the kernel for the last offending stragglers. Other than
      include/linux/moduleparam.h and kernel/params.c all other changes
      were generated with the following Coccinelle SmPL patch. Merge
      conflicts between trees can be handled with Coccinelle.
      
      In the future git could get Coccinelle merge support to deal with
      patch --> fail --> grammar --> Coccinelle --> new patch conflicts
      automatically for us on patches where the grammar is available and
      the patch is of high confidence. Consider this a feature request.
      
      Test compiled on x86_64 against:
      
      	* allnoconfig
      	* allmodconfig
      	* allyesconfig
      
      @ const_found @
      identifier ops;
      @@
      
      const struct kernel_param_ops ops = {
      };
      
      @ const_not_found depends on !const_found @
      identifier ops;
      @@
      
      -struct kernel_param_ops ops = {
      +const struct kernel_param_ops ops = {
      };
      
      Generated-by: Coccinelle SmPL
      Cc: Rusty Russell <rusty@rustcorp.com.au>
      Cc: Junio C Hamano <gitster@pobox.com>
      Cc: Andrew Morton <akpm@linux-foundation.org>
      Cc: Kees Cook <keescook@chromium.org>
      Cc: Tejun Heo <tj@kernel.org>
      Cc: Ingo Molnar <mingo@kernel.org>
      Cc: cocci@systeme.lip6.fr
      Cc: linux-kernel@vger.kernel.org
      Signed-off-by: NLuis R. Rodriguez <mcgrof@suse.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      9c27847d
  3. 14 10月, 2014 1 次提交
  4. 11 9月, 2014 1 次提交
    • M
      moduleparam: Resolve missing-field-initializer warning · 184c3fc3
      Mark Rustad 提交于
      Resolve a missing-field-initializer warning, that is produced
      by every reference to module_param_call, by using designated
      initialization for the first field. That is enough to silence
      the complaint.
      
      The message is only seen when doing a W=2 build. I happened to be using gcc
      4.8.3, but I think most versions would produce the warning when it is
      enabled. It can either be silenced by using even a single designated
      initializer as I did here, or providing values for all of the fields. Because
      of the number of references to the macro, this change silences many warnings
      in W=2 builds.
      
      One instance of the full warning message looks like this:
      
      /home/share/git/nn-mdr/include/linux/moduleparam.h:198:16: warning: missing
      initializer for field ‘free’ of ‘struct kernel_param_ops’
      [-Wmissing-field-initializers]
        static struct kernel_param_ops __param_ops_##name =  \
      		  ^
      /home/share/git/nn-mdr/fs/fuse/inode.c:35:1: note: in expansion of macro
      ‘module_param_call’
       module_param_call(max_user_bgreq, set_global_limit, param_get_uint,
       ^
      /home/share/git/nn-mdr/include/linux/moduleparam.h:56:9: note: ‘free’
      declared here
        void (*free)(void *arg);
      Signed-off-by: NMark Rustad <mark.d.rustad@intel.com>
      Signed-off-by: NJeff Kirsher <jeffrey.t.kirsher@intel.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      184c3fc3
  5. 27 8月, 2014 4 次提交
  6. 18 7月, 2014 1 次提交
  7. 28 4月, 2014 1 次提交
    • R
      param: hand arguments after -- straight to init · 51e158c1
      Rusty Russell 提交于
      The kernel passes any args it doesn't need through to init, except it
      assumes anything containing '.' belongs to the kernel (for a module).
      This change means all users can clearly distinguish which arguments
      are for init.
      
      For example, the kernel uses debug ("dee-bug") to mean log everything to
      the console, where systemd uses the debug from the Scandinavian "day-boog"
      meaning "fail to boot".  If a future versions uses argv[] instead of
      reading /proc/cmdline, this confusion will be avoided.
      
      eg: test 'FOO="this is --foo"' -- 'systemd.debug="true true true"'
      
      Gives:
      argv[0] = '/debug-init'
      argv[1] = 'test'
      argv[2] = 'systemd.debug=true true true'
      envp[0] = 'HOME=/'
      envp[1] = 'TERM=linux'
      envp[2] = 'FOO=this is --foo'
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      51e158c1
  8. 24 3月, 2014 1 次提交
  9. 17 3月, 2014 1 次提交
    • M
      module: LLVMLinux: Remove unused function warning from __param_check macro · 0283f9a5
      Mark Charlebois 提交于
      This code makes a compile time type check that is optimized away. Clang
      complains that it generates an unused function:
      
      linux/kernel/panic.c:471:1: warning: unused function '__check_panic'
            [-Wunused-function]
      core_param(panic, panic_timeout, int, 0644);
      ^
      linux/moduleparam.h:283:2: note: expanded from macro
            'core_param'
              param_check_##type(name, &(var));                               \
              ^
      <scratch space>:87:1: note: expanded from here
      param_check_int
      ^
      linux/moduleparam.h:369:34: note: expanded from macro
            'param_check_int'
      #define param_check_int(name, p) __param_check(name, p, int)
                                       ^
      linux/moduleparam.h:349:22: note: expanded from macro
            '__param_check'
              static inline type *__check_##name(void) { return(p); }
                                  ^
      <scratch space>:88:1: note: expanded from here
      __check_panic
      
      GCC won't complain for a static inline function but would if it was just
      a static function.
      
      Adding the unused attribute to the function declaration removes the warning.
      Per request from Rusty Russell it is marked as __always_unused as the code
      is meant to be optimized away.
      
      This code works for both GCC and clang.
      Signed-off-by: NMark Charlebois <charlebm@gmail.com>
      Signed-off-by: NBehan Webster <behanw@converseincode.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      0283f9a5
  10. 20 8月, 2013 1 次提交
    • S
      module: Add flag to allow mod params to have no arguments · ab013c5f
      Steven Rostedt 提交于
      Currently the params.c code allows only two "set" functions to have
      no arguments. If a parameter does not have an argument, then it
      looks at the set function and tests if it is either param_set_bool()
      or param_set_bint(). If it is not one of these functions, then it
      fails the loading of the module.
      
      But there may be module parameters that have different set functions
      and still allow no arguments. But unless each of these cases adds
      their function to the if statement, it wont be allowed to have no
      arguments. This method gets rather messing and does not scale.
      
      Instead, introduce a flags field to the kernel_param_ops, where if
      the flag KERNEL_PARAM_FL_NOARG is set, the parameter will not fail
      if it does not contain an argument. It will be expected that the
      corresponding set function can handle a NULL pointer as "val".
      Signed-off-by: NSteven Rostedt <rostedt@goodmis.org>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      ab013c5f
  11. 02 7月, 2013 1 次提交
  12. 14 12月, 2012 1 次提交
  13. 08 6月, 2012 1 次提交
    • R
      module_param: stop double-calling parameters. · ae82fdb1
      Rusty Russell 提交于
      Commit 026cee00 "params:
      <level>_initcall-like kernel parameters" set old-style module
      parameters to level 0.  And we call those level 0 calls where we used
      to, early in start_kernel().
      
      We also loop through the initcall levels and call the levelled
      module_params before the corresponding initcall.  Unfortunately level
      0 is early_init(), so we call the standard module_param calls twice.
      
      (Turns out most things don't care, but at least ubi.mtd does).
      
      Change the level to -1 for standard module_param calls.
      Reported-by: NBenoît Thébaudeau <benoit.thebaudeau@advansee.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: stable@kernel.org
      ae82fdb1
  14. 01 5月, 2012 1 次提交
    • J
      params: add 3rd arg to option handler callback signature · 9fb48c74
      Jim Cromie 提交于
      Add a 3rd arg, named "doing", to unknown-options callbacks invoked
      from parse_args(). The arg is passed as:
      
        "Booting kernel" from start_kernel(),
        initcall_level_names[i] from do_initcall_level(),
        mod->name from load_module(), via parse_args(), parse_one()
      
      parse_args() already has the "name" parameter, which is renamed to
      "doing" to better reflect current uses 1,2 above.  parse_args() passes
      it to an altered parse_one(), which now passes it down into the
      unknown option handler callbacks.
      
      The mod->name will be needed to handle dyndbg for loadable modules,
      since params passed by modprobe are not qualified (they do not have a
      "$modname." prefix), and by the time the unknown-param callback is
      called, the module name is not otherwise available.
      
      Minor tweaks:
      
      Add param-name to parse_one's pr_debug(), current message doesnt
      identify the param being handled, add it.
      
      Add a pr_info to print current level and level_name of the initcall,
      and number of registered initcalls at that level.  This adds 7 lines
      to dmesg output, like:
      
         initlevel:6=device, 172 registered initcalls
      
      Drop "parameters" from initcall_level_names[], its unhelpful in the
      pr_info() added above.  This array is passed into parse_args() by
      do_initcall_level().
      
      CC: Rusty Russell <rusty@rustcorp.com.au>
      Signed-off-by: NJim Cromie <jim.cromie@gmail.com>
      Acked-by: NJason Baron <jbaron@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9fb48c74
  15. 26 3月, 2012 2 次提交
  16. 13 1月, 2012 3 次提交
    • R
      module_param: check that bool parameters really are bool. · 72db395f
      Rusty Russell 提交于
      module_param(bool) used to counter-intuitively take an int.  In
      fddd5201 (mid-2009) we allowed bool or int/unsigned int using a messy
      trick.
      
      This tightens the check (you'll get a warning about incompatible
      return type) but still allows it.  Next kernel version, we'll remove
      it.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      72db395f
    • R
      module_param: avoid bool abuse, add bint for special cases. · 69116f27
      Rusty Russell 提交于
      For historical reasons, we allow module_param(bool) to take an int (or
      an unsigned int).  That's going away.
      
      A few drivers really want an int: they set it to -1 and a parameter
      will set it to 0 or 1.  This sucks: reading them from sysfs will give
      'Y' for both -1 and 1, but if we change it to an int, then the users
      might be broken (if they did "param" instead of "param=1").
      
      Use a new 'bint' parser for them.
      
      (ntfs has a different problem: it needs an int for debug_msgs because
      it's also exposed via sysctl.)
      
      Cc: Steve Glendinning <steve.glendinning@smsc.com>
      Cc: Jean Delvare <khali@linux-fr.org>
      Cc: Guenter Roeck <guenter.roeck@ericsson.com>
      Cc: Hoang-Nam Nguyen <hnguyen@de.ibm.com>
      Cc: Christoph Raisch <raisch@de.ibm.com>
      Cc: Roland Dreier <roland@kernel.org>
      Cc: Sean Hefty <sean.hefty@intel.com>
      Cc: Hal Rosenstock <hal.rosenstock@gmail.com>
      Cc: linux390@de.ibm.com
      Cc: Anton Altaparmakov <anton@tuxera.com>
      Cc: Jaroslav Kysela <perex@perex.cz>
      Cc: Takashi Iwai <tiwai@suse.de>
      Cc: lm-sensors@lm-sensors.org
      Cc: linux-rdma@vger.kernel.org
      Cc: linux-s390@vger.kernel.org
      Cc: linux-ntfs-dev@lists.sourceforge.net
      Cc: alsa-devel@alsa-project.org
      Acked-by: Takashi Iwai <tiwai@suse.de> (For the sound part)
      Acked-by: Guenter Roeck <guenter.roeck@ericsson.com> (For the hwmon driver)
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      69116f27
    • R
      module_param: check type correctness for module_param_array · bafeafea
      Rusty Russell 提交于
      module_param_array(), unlike its non-array cousins, didn't check the type
      of the variable.  Fixing this found two bugs.
      
      Cc: Luca Risolia <luca.risolia@studio.unibo.it>
      Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
      Cc: Eric Piel <eric.piel@tremplin-utc.net>
      Cc: linux-media@vger.kernel.org
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      bafeafea
  17. 31 10月, 2011 1 次提交
  18. 26 10月, 2011 1 次提交
  19. 19 5月, 2011 1 次提交
  20. 24 1月, 2011 1 次提交
  21. 27 10月, 2010 1 次提交
  22. 11 8月, 2010 6 次提交
  23. 29 10月, 2009 1 次提交
    • R
      param: fix lots of bugs with writing charp params from sysfs, by leaking mem. · 65afac7d
      Rusty Russell 提交于
      e180a6b7 "param: fix charp parameters set via sysfs" fixed the case
      where charp parameters written via sysfs were freed, leaving drivers
      accessing random memory.
      
      Unfortunately, storing a flag in the kparam struct was a bad idea: it's
      rodata so setting it causes an oops on some archs.  But that's not all:
      
      1) module_param_array() on charp doesn't work reliably, since we use an
         uninitialized temporary struct kernel_param.
      2) there's a fundamental race if a module uses this parameter and then
         it's changed: they will still access the old, freed, memory.
      
      The simplest fix (ie. for 2.6.32) is to never free the memory.  This
      prevents all these problems, at cost of a memory leak.  In practice, there
      are only 18 places where a charp is writable via sysfs, and all are
      root-only writable.
      Reported-by: NTakashi Iwai <tiwai@suse.de>
      Cc: Sitsofe Wheeler <sitsofe@yahoo.com>
      Cc: Frederic Weisbecker <fweisbec@gmail.com>
      Cc: Christof Schmitt <christof.schmitt@de.ibm.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: stable@kernel.org
      65afac7d
  24. 12 6月, 2009 3 次提交
  25. 31 3月, 2009 1 次提交