1. 05 8月, 2010 16 次提交
    • R
      module: pass load_info into other functions · 49668688
      Rusty Russell 提交于
      Pass the struct load_info into all the other functions in module
      loading.  This neatens things and makes them more consistent.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      49668688
    • R
      module: fix sysfs cleanup for !CONFIG_SYSFS · 36b0360d
      Rusty Russell 提交于
      Restore the stub module_remove_modinfo_attrs, remove the now-unused
      !CONFIG_SYSFS module_sysfs_init.
      
      Also, rename mod_kobject_remove() to mod_sysfs_teardown() as
      it is the logical counterpart to mod_sysfs_setup now.
      Reported-by: NRandy Dunlap <randy.dunlap@oracle.com>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      36b0360d
    • R
      module: sysfs cleanup · 8f6d0378
      Rusty Russell 提交于
      We change the sysfs functions to take struct load_info, and call
      them all in mod_sysfs_setup().
      
      We also clean up the #ifdefs a little.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      8f6d0378
    • R
      module: layout_and_allocate · d913188c
      Rusty Russell 提交于
      layout_and_allocate() does everything up to and including the final
      struct module placement inside the allocated module memory.  We have
      to store the symbol layout information in our struct load_info though.
      
      This avoids the nasty code we had before where 'mod' pointed first
      to the version inside the temporary allocation containing the entire
      file, then later was moved to point to the real struct module: now
      the main code only ever sees the final module address.
      
      (Includes fix for the Tony Luck-found Linus-diagnosed failure path
       error).
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      d913188c
    • R
      module: fix crash in get_ksymbol() when oopsing in module init · 511ca6ae
      Rusty Russell 提交于
      Andrew had the sole pleasure of tickling this bug in linux-next; when we set
      up "info->strtab" it's pointing into the temporary copy of the module.  For
      most uses that is fine, but kallsyms keeps a pointer around during module
      load (inside mod->strtab).
      
      If we oops for some reason inside a module's init function, kallsyms will use
      the mod->strtab pointer into the now-freed temporary module copy.
      
      (Later oopses work fine: after init we overwrite mod->strtab to point to a
       compacted core-only strtab).
      Reported-by: NAndrew "Grumpy" Morton <akpm@linux-foundation.org>
      Signed-off-by: NRusty "Buggy" Russell <rusty@rustcorp.com.au>
      Tested-by: NAndrew "Happy" Morton <akpm@linux-foundation.org>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      511ca6ae
    • R
      module: kallsyms functions take struct load_info · eded41c1
      Rusty Russell 提交于
      Simple refactor causes us to lift struct definition to top of file.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      eded41c1
    • R
      module: refactor out section header rewriting: FIX modversions · d6df72a0
      Rusty Russell 提交于
      We can't do the find_sec after removing the SHF_ALLOC flags; it won't
      find the sections.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      d6df72a0
    • R
      module: refactor out section header rewriting · 8b5f61a7
      Rusty Russell 提交于
      Put all the "rewrite and check section headers" in one place.  This
      adds another iteration over the sections, but it's far clearer.  We
      iterate once for every find_section() so we already iterate over many
      times.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      8b5f61a7
    • L
      module: add load_info · 3264d3f9
      Linus Torvalds 提交于
      Btw, here's a patch that _looks_ large, but it really pretty trivial, and
      sets things up so that it would be way easier to split off pieces of the
      module loading.
      
      The reason it looks large is that it creates a "module_info" structure
      that contains all the module state that we're building up while loading,
      instead of having individual variables for all the indices etc.
      
      So the patch ends up being large, because every "symindex" access instead
      becomes "info.index.sym" etc. That may be a few characters longer, but it
      then means that we can just pass a pointer to that "info" structure
      around. and let all the pieces fill it in very naturally.
      
      As an example of that, the patch also moves the initialization of all
      those convenience variables into a "setup_module_info()" function. And at
      this point it really does become very natural to start to peel off some of
      the error labels and move them into the helper functions - now the
      "truncated" case is gone, and is handled inside that setup function
      instead.
      
      So maybe you don't like this approach, and it does make the variable
      accesses a bit longer, but I don't think unreadably so. And the patch
      really does look big and scary, but there really should be absolutely no
      semantic changes - most of it was a trivial and mindless rename.
      
      In fact, it was so mindless that I on purpose kept the existing helper
      functions looking like this:
      
      -       err = check_modinfo(mod, sechdrs, infoindex, versindex);
      +       err = check_modinfo(mod, info.sechdrs, info.index.info, info.index.vers);
      
      rather than changing them to just take the "info" pointer. IOW, a second
      phase (if you think the approach is ok) would change that calling
      convention to just do
      
      	err = check_modinfo(mod, &info);
      
      (and same for "layout_sections()", "layout_symtabs()" etc.) Similarly,
      while right now it makes things _look_ bigger, with things like this:
      
      	versindex = find_sec(hdr, sechdrs, secstrings, "__versions");
      
      becoming
      
      	info->index.vers = find_sec(info->hdr, info->sechdrs, info->secstrings, "__versions");
      
      in the new "setup_module_info()" function, that's again just a result of
      it being a search-and-replace patch. By using the 'info' pointer, we could
      just change the 'find_sec()' interface so that it ends up being
      
      	info->index.vers = find_sec(info, "__versions");
      
      instead, and then we'd actually have a shorter and more readable line. So
      for a lot of those mindless variable name expansions there's would be room
      for separate cleanups.
      
      I didn't move quite everything in there - if we do this to layout_symtabs,
      for example, we'd want to move the percpu, symoffs, stroffs, *strmap
      variables to be fields in that module_info structure too. But that's a
      much smaller patch, I moved just the really core stuff that is currently
      being set up and used in various parts.
      
      But even in this rough form, it removes close to 70 lines from that
      function (but adds 22 lines overall, of course - the structure definition,
      the helper function declarations and call-sites etc etc).
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      3264d3f9
    • L
      module: reduce stack usage for each_symbol() · 44032e63
      Linus Torvalds 提交于
      And now that I'm looking at that call-chain (to see if it would make sense
      to use some other more specific lock - doesn't look like it: all the
      readers are using RCU and this is the only writer), I also give you this
      trivial one-liner. It changes each_symbol() to not put that constant array
      on the stack, resulting in changing
      
              movq    $C.388.31095, %rsi      #, tmp85
              subq    $376, %rsp      #,
              movq    %rdi, %rbx      # fn, fn
              leaq    -208(%rbp), %rdi        #, tmp84
              movq    %rbx, %rdx      # fn,
              rep movsl
              xorl    %esi, %esi      #
              leaq    -208(%rbp), %rdi        #, tmp87
              movq    %r12, %rcx      # data,
              call    each_symbol_in_section.clone.0  #
      
      into
      
              xorl    %esi, %esi      #
              subq    $216, %rsp      #,
              movq    %rdi, %rbx      # fn, fn
              movq    $arr.31078, %rdi        #,
              call    each_symbol_in_section.clone.0  #
      
      which is not so much about being obviously shorter and simpler because we
      don't unnecessarily copy that constant array around onto the stack, but
      also about having a much smaller stack footprint (376 vs 216 bytes - see
      the update of 'rsp').
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      44032e63
    • R
      module: refactor load_module part 5 · 22e268eb
      Rusty Russell 提交于
      1) Extract out the relocation loop into apply_relocations
      2) Extract license and version checks into check_module_license_and_versions
      3) Extract icache flushing into flush_module_icache
      4) Move __obsparm warning into find_module_sections
      5) Move license setting into check_modinfo.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      22e268eb
    • R
      module: refactor load_module part 4 · 9f85a4bb
      Rusty Russell 提交于
      Allocate references inside module_unload_init(), clean up inside
      module_unload_free().
      
      This version fixed to do allocation before __this_cpu_write, thanks to
      bug reports from linux-next from Dave Young <hidave.darkstar@gmail.com>
      and Stephen Rothwell <sfr@canb.auug.org.au>.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      9f85a4bb
    • R
      module: refactor load_module part 3 · 40dd2560
      Rusty Russell 提交于
      Extract out the allocation and copying in from userspace, and the
      first set of modinfo checks.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      40dd2560
    • L
      module: refactor load_module part 2 · 65b8a9b4
      Linus Torvalds 提交于
      Here's a second one. It's slightly less trivial - since we now have error
      cases - and equally untested so it may well be totally broken. But it also
      cleans up a bit more, and avoids one of the goto targets, because the
      "move_module()" helper now does both allocations or none.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      65b8a9b4
    • L
      module: refactor load_module · f91a13bb
      Linus Torvalds 提交于
      I'd start from the trivial stuff. There's a fair amount of straight-line
      code that just makes the function hard to read just because you have to
      page up and down so far. Some of it is trivial to just create a helper
      function for.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      f91a13bb
    • E
      module: module_unload_init() cleanup · 2409e742
      Eric Dumazet 提交于
      No need to clear mod->refptr in module_unload_init(), since
      alloc_percpu() already clears allocated chunks.
      Signed-off-by: NEric Dumazet <eric.dumazet@gmail.com>
      Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (removed unused var)
      2409e742
  2. 28 7月, 2010 1 次提交
  3. 05 7月, 2010 1 次提交
  4. 05 6月, 2010 8 次提交
    • R
      module: fix bne2 "gave up waiting for init of module libcrc32c" · 9bea7f23
      Rusty Russell 提交于
      Problem: it's hard to avoid an init routine stumbling over a
      request_module these days.  And it's not clear it's always a bad idea:
      for example, a module like kvm with dynamic dependencies on kvm-intel
      or kvm-amd would be neater if it could simply request_module the right
      one.
      
      In this particular case, it's libcrc32c:
      
      	libcrc32c_mod_init
      	 crypto_alloc_shash
      	  crypto_alloc_tfm
      	   crypto_find_alg
      	    crypto_alg_mod_lookup
      	     crypto_larval_lookup
      	      request_module
      
      If another module is waiting inside resolve_symbol() for libcrc32c to
      finish initializing (ie. bne2 depends on libcrc32c) then it does so
      holding the module lock, and our request_module() can't make progress
      until that is released.
      
      Waiting inside resolve_symbol() without the lock isn't all that hard:
      we just need to pass the -EBUSY up the call chain so we can sleep
      where we don't hold the lock.  Error reporting is a bit trickier: we
      need to copy the name of the unfinished module before releasing the
      lock.
      
      Other notes:
      1) This also fixes a theoretical issue where a weak dependency would allow
         symbol version mismatches to be ignored.
      2) We rename use_module to ref_module to make life easier for the only
         external user (the out-of-tree ksplice patches).
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Cc: Tim Abbot <tabbott@ksplice.com>
      Tested-by: NBrandon Philips <bphilips@suse.de>
      9bea7f23
    • R
      module: verify_export_symbols under the lock · be593f4c
      Rusty Russell 提交于
      It disabled preempt so it was "safe", but nothing stops another module
      slipping in before this module is added to the global list now we don't
      hold the lock the whole time.
      
      So we check this just after we check for duplicate modules, and just
      before we put the module in the global list.
      
      (find_symbol finds symbols in coming and going modules, too).
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      be593f4c
    • L
      module: move find_module check to end · 3bafeb62
      Linus Torvalds 提交于
      I think Rusty may have made the lock a bit _too_ finegrained there, and
      didn't add it to some places that needed it. It looks, for example, like
      PATCH 1/2 actually drops the lock in places where it's needed
      ("find_module()" is documented to need it, but now load_module() didn't
      hold it at all when it did the find_module()).
      
      Rather than adding a new "module_loading" list, I think we should be able
      to just use the existing "modules" list, and just fix up the locking a
      bit.
      
      In fact, maybe we could just move the "look up existing module" a bit
      later - optimistically assuming that the module doesn't exist, and then
      just undoing the work if it turns out that we were wrong, just before
      adding ourselves to the list.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      3bafeb62
    • R
      module: make locking more fine-grained. · 75676500
      Rusty Russell 提交于
      Kay Sievers <kay.sievers@vrfy.org> reports that we still have some
      contention over module loading which is slowing boot.
      
      Linus also disliked a previous "drop lock and regrab" patch to fix the
      bne2 "gave up waiting for init of module libcrc32c" message.
      
      This is more ambitious: we only grab the lock where we need it.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Brandon Philips <brandon@ifup.org>
      Cc: Kay Sievers <kay.sievers@vrfy.org>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      75676500
    • R
      module: Make module sysfs functions private. · 6407ebb2
      Rusty Russell 提交于
      These were placed in the header in ef665c1a to get the various
      SYSFS/MODULE config combintations to compile.
      
      That may have been necessary then, but it's not now.  These functions
      are all local to module.c.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Randy Dunlap <randy.dunlap@oracle.com>
      6407ebb2
    • R
      module: move sysfs exposure to end of load_module · 80a3d1bb
      Rusty Russell 提交于
      This means a little extra work, but is more logical: we don't put
      anything in sysfs until we're about to put the module into the
      global list an parse its parameters.
      
      This also gives us a logical place to put duplicate module detection
      in the next patch.
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      80a3d1bb
    • R
      module: fix kdb's illicit use of struct module_use. · c8e21ced
      Rusty Russell 提交于
      Linus changed the structure, and luckily this didn't compile any more.
      Reported-by: NStephen Rothwell <sfr@canb.auug.org.au>
      Signed-off-by: NRusty Russell <rusty@rustcorp.com.au>
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: Martin Hicks <mort@sgi.com>
      c8e21ced
    • L
      module: Make the 'usage' lists be two-way · 2c02dfe7
      Linus Torvalds 提交于
      When adding a module that depends on another one, we used to create a
      one-way list of "modules_which_use_me", so that module unloading could
      see who needs a module.
      
      It's actually quite simple to make that list go both ways: so that we
      not only can see "who uses me", but also see a list of modules that are
      "used by me".
      
      In fact, we always wanted that list in "module_unload_free()": when we
      unload a module, we want to also release all the other modules that are
      used by that module.  But because we didn't have that list, we used to
      first iterate over all modules, and then iterate over each "used by me"
      list of that module.
      
      By making the list two-way, we simplify module_unload_free(), and it
      allows for some trivial fixes later too.
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (cleaned & rebased)
      2c02dfe7
  5. 01 6月, 2010 1 次提交
  6. 26 5月, 2010 1 次提交
  7. 25 5月, 2010 1 次提交
  8. 22 5月, 2010 1 次提交
  9. 21 5月, 2010 1 次提交
  10. 19 5月, 2010 1 次提交
  11. 07 5月, 2010 1 次提交
    • T
      stop_machine: reimplement using cpu_stop · 3fc1f1e2
      Tejun Heo 提交于
      Reimplement stop_machine using cpu_stop.  As cpu stoppers are
      guaranteed to be available for all online cpus,
      stop_machine_create/destroy() are no longer necessary and removed.
      
      With resource management and synchronization handled by cpu_stop, the
      new implementation is much simpler.  Asking the cpu_stop to execute
      the stop_cpu() state machine on all online cpus with cpu hotplug
      disabled is enough.
      
      stop_machine itself doesn't need to manage any global resources
      anymore, so all per-instance information is rolled into struct
      stop_machine_data and the mutex and all static data variables are
      removed.
      
      The previous implementation created and destroyed RT workqueues as
      necessary which made stop_machine() calls highly expensive on very
      large machines.  According to Dimitri Sivanich, preventing the dynamic
      creation/destruction makes booting faster more than twice on very
      large machines.  cpu_stop resources are preallocated for all online
      cpus and should have the same effect.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Acked-by: NRusty Russell <rusty@rustcorp.com.au>
      Acked-by: NPeter Zijlstra <peterz@infradead.org>
      Cc: Oleg Nesterov <oleg@redhat.com>
      Cc: Dimitri Sivanich <sivanich@sgi.com>
      3fc1f1e2
  12. 06 4月, 2010 1 次提交
    • N
      Fix up possibly racy module refcounting · 5fbfb18d
      Nick Piggin 提交于
      Module refcounting is implemented with a per-cpu counter for speed.
      However there is a race when tallying the counter where a reference may
      be taken by one CPU and released by another.  Reference count summation
      may then see the decrement without having seen the previous increment,
      leading to lower than expected count.  A module which never has its
      actual reference drop below 1 may return a reference count of 0 due to
      this race.
      
      Module removal generally runs under stop_machine, which prevents this
      race causing bugs due to removal of in-use modules.  However there are
      other real bugs in module.c code and driver code (module_refcount is
      exported) where the callers do not run under stop_machine.
      
      Fix this by maintaining running per-cpu counters for the number of
      module refcount increments and the number of refcount decrements.  The
      increments are tallied after the decrements, so any decrement seen will
      always have its corresponding increment counted.  The final refcount is
      the difference of the total increments and decrements, preventing a
      low-refcount from being returned.
      Signed-off-by: NNick Piggin <npiggin@suse.de>
      Acked-by: NRusty Russell <rusty@rustcorp.com.au>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      5fbfb18d
  13. 01 4月, 2010 2 次提交
  14. 29 3月, 2010 2 次提交
  15. 08 3月, 2010 1 次提交
  16. 03 3月, 2010 1 次提交