1. 17 8月, 2012 8 次提交
    • M
      firmware loader: fix device lifetime · 0cfc1e1e
      Ming Lei 提交于
      Callers of request_firmware* must hold the reference count of
      @device, otherwise it is easy to trigger oops since the firmware
      loader device is the child of @device.
      
      This patch adds comments about the usage. In fact, most of drivers
      call request_firmware* in its probe() or open(), so the constraint
      should be reasonable and can be satisfied.
      
      Also this patch holds the reference count of @device before
      schedule_work() in request_firmware_nowait() to avoid that
      the @device is released after request_firmware_nowait returns
      and before the worker function is scheduled.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0cfc1e1e
    • M
      firmware loader: introduce cache_firmware and uncache_firmware · 2887b395
      Ming Lei 提交于
      This patches introduce two kernel APIs of cache_firmware and
      uncache_firmware, both of which take the firmware file name
      as the only parameter.
      
      So any drivers can call cache_firmware to cache the specified
      firmware file into kernel memory, and can use the cached firmware
      in situations which can't request firmware from user space.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2887b395
    • M
      firmware loader: always let firmware_buf own the pages buffer · 1f2b7959
      Ming Lei 提交于
      This patch always let firmware_buf own the pages buffer allocated
      inside firmware_data_write, and add all instances of firmware_buf
      into the firmware cache global list. Also introduce one private field
      in 'struct firmware', so release_firmware will see the instance of
      firmware_buf associated with the current firmware instance, then just
      'free' the instance of firmware_buf.
      
      The firmware_buf instance represents one pages buffer for one
      firmware image, so lots of firmware loading requests can share
      the same firmware_buf instance if they request the same firmware
      image file.
      
      This patch will make implementation of the following cache_firmware/
      uncache_firmware very easy and simple.
      
      In fact, the patch improves request_formware/release_firmware:
      
              - only request userspace to write firmware image once if
      	several devices share one same firmware image and its drivers
      	call request_firmware concurrently.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1f2b7959
    • M
      firmware loader: introduce firmware_buf · 1244691c
      Ming Lei 提交于
      This patch introduces struct firmware_buf to describe the buffer
      which holds the firmware data, which will make the following
      cache_firmware/uncache_firmware implemented easily.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1244691c
    • M
      firmware loader: fix creation failure of fw loader device · 99c2aa72
      Ming Lei 提交于
      If one device driver calls request_firmware_nowait() to request
      several different firmwares' loading, device_add() will return
      failure since all firmware loader device use same name of the
      device who is requesting firmware.
      
      This patch always use the name of firmware image as the firmware
      loader device name to fix the problem since the following patches
      for caching firmware will make sure only one loading for same
      firmware is alllowd at the same time.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      99c2aa72
    • M
      firmware loader: remove unnecessary wmb() · 0c25a850
      Ming Lei 提交于
      The wmb() inside fw_load_abort is not necessary, since
      complete() and wait_on_completion() has implied one pair
      of memory barrier.
      
      Also wmb() isn't a correct usage, so just remove it.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      0c25a850
    • M
      firmware loader: fix races during loading firmware · 28eefa75
      Ming Lei 提交于
      This patch fixes two races in loading firmware:
      
      1, FW_STATUS_DONE should be set before waking up the task waitting
      on _request_firmware_load, otherwise FW_STATUS_ABORT may be
      thought as DONE mistakenly.
      
      2, Inside _request_firmware_load(), there is a small window between
      wait_for_completion() and mutex_lock(&fw_lock), and 'echo 1 > loading'
      still may happen during the period, so this patch checks FW_STATUS_DONE
      to prevent pages' buffer completed from being freed in firmware_loading_store.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      28eefa75
    • M
      firmware loader: simplify pages ownership transfer · 65710cb6
      Ming Lei 提交于
      This patch doesn't transfer ownership of pages' buffer to the
      instance of firmware until the firmware loading is completed,
      which will simplify firmware_loading_store a lot, so help
      to introduce the following cache_firmware and uncache_firmware
      mechanism during system suspend-resume cycle.
      
      In fact, this patch fixes one bug: if writing data into
      firmware loader device is bypassed between writting 1 and 0 to
      'loading', OOPS will be triggered without the patch.
      
      Also handle the vmap failure case, and add some comments to make
      code more readable.
      Signed-off-by: NMing Lei <ming.lei@canonical.com>
      Cc: Linus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      65710cb6
  2. 17 7月, 2012 1 次提交
  3. 29 3月, 2012 5 次提交
  4. 24 1月, 2012 1 次提交
  5. 05 1月, 2012 1 次提交
    • N
      firmware: Fix an oops on reading fw_priv->fw in sysfs loading file · eea915bb
      Neil Horman 提交于
      This oops was reported recently:
      firmware_loading_store+0xf9/0x17b
      dev_attr_store+0x20/0x22
      sysfs_write_file+0x101/0x134
      vfs_write+0xac/0xf3
      sys_write+0x4a/0x6e
      system_call_fastpath+0x16/0x1b
      
      The complete backtrace was unfortunately not captured, but details can be found
      here:
      https://bugzilla.redhat.com/show_bug.cgi?id=769920
      
      The cause is fairly clear.
      
      Its caused by the fact that firmware_loading_store has a case 0 in its
      switch statement that reads and writes the fw_priv->fw poniter without the
      protection of the fw_lock mutex.  since there is a window between the time that
      _request_firmware sets fw_priv->fw to NULL and the time the corresponding sysfs
      file is unregistered, its possible for a user space application to race in, and
      write a zero to the loading file, causing a NULL dereference in
      firmware_loading_store.  Fix it by extending the protection of the fw_lock mutex
      to cover all of the firware_loading_store function.
      Signed-off-by: NNeil Horman <nhorman@tuxdriver.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      eea915bb
  6. 10 12月, 2011 1 次提交
    • S
      PM / Sleep: Fix freezer failures due to racy usermodehelper_is_disabled() · b298d289
      Srivatsa S. Bhat 提交于
      Commit a144c6a6 (PM: Print a warning if firmware is requested when tasks
      are frozen) introduced usermodehelper_is_disabled() to warn and exit
      immediately if firmware is requested when usermodehelpers are disabled.
      
      However, it is racy. Consider the following scenario, currently used in
      drivers/base/firmware_class.c:
      
      ...
      if (usermodehelper_is_disabled())
              goto out;
      
      /* Do actual work */
      ...
      
      out:
              return err;
      
      Nothing prevents someone from disabling usermodehelpers just after the check
      in the 'if' condition, which means that it is quite possible to try doing the
      "actual work" with usermodehelpers disabled, leading to undesirable
      consequences.
      
      In particular, this race condition in _request_firmware() causes task freezing
      failures whenever suspend/hibernation is in progress because, it wrongly waits
      to get the firmware/microcode image from userspace when actually the
      usermodehelpers are disabled or userspace has been frozen.
      Some of the example scenarios that cause freezing failures due to this race
      are those that depend on userspace via request_firmware(), such as x86
      microcode module initialization and microcode image reload.
      
      Previous discussions about this issue can be found at:
      http://thread.gmane.org/gmane.linux.kernel/1198291/focus=1200591
      
      This patch adds proper synchronization to fix this issue.
      
      It is to be noted that this patchset fixes the freezing failures but doesn't
      remove the warnings. IOW, it does not attempt to add explicit synchronization
      to x86 microcode driver to avoid requesting microcode image at inopportune
      moments. Because, the warnings were introduced to highlight such cases, in the
      first place. And we need not silence the warnings, since we take care of the
      *real* problem (freezing failure) and hence, after that, the warnings are
      pretty harmless anyway.
      Signed-off-by: NSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      b298d289
  7. 25 8月, 2011 1 次提交
  8. 18 5月, 2011 1 次提交
  9. 04 2月, 2011 1 次提交
  10. 24 8月, 2010 1 次提交
  11. 06 8月, 2010 2 次提交
  12. 22 5月, 2010 7 次提交
  13. 30 3月, 2010 1 次提交
    • T
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking... · 5a0e3ad6
      Tejun Heo 提交于
      include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
      
      percpu.h is included by sched.h and module.h and thus ends up being
      included when building most .c files.  percpu.h includes slab.h which
      in turn includes gfp.h making everything defined by the two files
      universally available and complicating inclusion dependencies.
      
      percpu.h -> slab.h dependency is about to be removed.  Prepare for
      this change by updating users of gfp and slab facilities include those
      headers directly instead of assuming availability.  As this conversion
      needs to touch large number of source files, the following script is
      used as the basis of conversion.
      
        http://userweb.kernel.org/~tj/misc/slabh-sweep.py
      
      The script does the followings.
      
      * Scan files for gfp and slab usages and update includes such that
        only the necessary includes are there.  ie. if only gfp is used,
        gfp.h, if slab is used, slab.h.
      
      * When the script inserts a new include, it looks at the include
        blocks and try to put the new include such that its order conforms
        to its surrounding.  It's put in the include block which contains
        core kernel includes, in the same order that the rest are ordered -
        alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
        doesn't seem to be any matching order.
      
      * If the script can't find a place to put a new include (mostly
        because the file doesn't have fitting include block), it prints out
        an error message indicating which .h file needs to be added to the
        file.
      
      The conversion was done in the following steps.
      
      1. The initial automatic conversion of all .c files updated slightly
         over 4000 files, deleting around 700 includes and adding ~480 gfp.h
         and ~3000 slab.h inclusions.  The script emitted errors for ~400
         files.
      
      2. Each error was manually checked.  Some didn't need the inclusion,
         some needed manual addition while adding it to implementation .h or
         embedding .c file was more appropriate for others.  This step added
         inclusions to around 150 files.
      
      3. The script was run again and the output was compared to the edits
         from #2 to make sure no file was left behind.
      
      4. Several build tests were done and a couple of problems were fixed.
         e.g. lib/decompress_*.c used malloc/free() wrappers around slab
         APIs requiring slab.h to be added manually.
      
      5. The script was run on all .h files but without automatically
         editing them as sprinkling gfp.h and slab.h inclusions around .h
         files could easily lead to inclusion dependency hell.  Most gfp.h
         inclusion directives were ignored as stuff from gfp.h was usually
         wildly available and often used in preprocessor macros.  Each
         slab.h inclusion directive was examined and added manually as
         necessary.
      
      6. percpu.h was updated not to include slab.h.
      
      7. Build test were done on the following configurations and failures
         were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
         distributed build env didn't work with gcov compiles) and a few
         more options had to be turned off depending on archs to make things
         build (like ipr on powerpc/64 which failed due to missing writeq).
      
         * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
         * powerpc and powerpc64 SMP allmodconfig
         * sparc and sparc64 SMP allmodconfig
         * ia64 SMP allmodconfig
         * s390 SMP allmodconfig
         * alpha SMP allmodconfig
         * um on x86_64 SMP allmodconfig
      
      8. percpu.h modifications were reverted so that it could be applied as
         a separate patch and serve as bisection point.
      
      Given the fact that I had only a couple of failures from tests on step
      6, I'm fairly confident about the coverage of this conversion patch.
      If there is a breakage, it's likely to be something in one of the arch
      headers which should be easily discoverable easily on most builds of
      the specific arch.
      Signed-off-by: NTejun Heo <tj@kernel.org>
      Guess-its-ok-by: NChristoph Lameter <cl@linux-foundation.org>
      Cc: Ingo Molnar <mingo@redhat.com>
      Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
      5a0e3ad6
  14. 19 3月, 2010 2 次提交
    • R
      driver-core: fix missing kernel-doc in firmware_class · e59817bf
      Randy Dunlap 提交于
      Fix kernel-doc warning in firmware_class.c:
      
      Warning(drivers/base/firmware_class.c:94): No description found for parameter 'attr'
      Signed-off-by: NRandy Dunlap <randy.dunlap@oracle.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      e59817bf
    • J
      sysfs: use sysfs_bin_attr_init in firmware class driver · e1955ca0
      Jiri Kosina 提交于
      Annotate dynamic sysfs attribute in fw_setup_device(). This gets
      rid of the following lockdep warning:
      
      bnx2 0000:08:00.0: firmware: requesting bnx2/bnx2-mips-06-5.0.0.j6.fw
      BUG: key ffff880008293470 not in .data!
      ------------[ cut here ]------------
      WARNING: at kernel/lockdep.c:2706 lockdep_init_map+0x562/0x620()
      Modules linked in: bnx2(+) sg tpm_bios floppy rtc_lib usb_storage i2c_piix4 joydev button container shpchp i2c_core sr_mod cdrom pci_hotplug usbhid hid ohci_hcd ehci_hcd sd_mod usbcore edd ext3 mbcache jbd fan ata_generic sata_svw pata_serverworks libata scsi_mod thermal processor
      Pid: 1915, comm: work_for_cpu Not tainted 2.6.34-rc1-default #81
      Call Trace:
       [<ffffffff8107c1d2>] ? lockdep_init_map+0x562/0x620
       [<ffffffff81049fd8>] warn_slowpath_common+0x78/0xd0
       [<ffffffff8104a03f>] warn_slowpath_null+0xf/0x20
       [<ffffffff8107c1d2>] lockdep_init_map+0x562/0x620
       [<ffffffff8117a236>] ? sysfs_new_dirent+0x76/0x120
       [<ffffffff8126edb2>] ? put_device+0x12/0x20
       [<ffffffff811797cc>] sysfs_add_file_mode+0x6c/0xd0
       [<ffffffff8117983c>] sysfs_add_file+0xc/0x10
       [<ffffffff8117bf61>] sysfs_create_bin_file+0x21/0x30
       [<ffffffff81279c61>] _request_firmware+0x2f1/0x650
       [<ffffffff8127a04e>] request_firmware+0xe/0x10
       [<ffffffffa01ec19e>] bnx2_init_one+0x8f5/0x177e [bnx2]
       [<ffffffff81389eab>] ? _raw_spin_unlock_irq+0x2b/0x40
       [<ffffffff81040ed9>] ? finish_task_switch+0x69/0x100
       [<ffffffff81040e70>] ? finish_task_switch+0x0/0x100
       [<ffffffff81064b40>] ? do_work_for_cpu+0x0/0x30
       [<ffffffff811e6302>] local_pci_probe+0x12/0x20
       [<ffffffff81064b53>] do_work_for_cpu+0x13/0x30
       [<ffffffff81064b40>] ? do_work_for_cpu+0x0/0x30
       [<ffffffff81068c56>] kthread+0x96/0xa0
       [<ffffffff81003e64>] kernel_thread_helper+0x4/0x10
       [<ffffffff8138a350>] ? restore_args+0x0/0x30
       [<ffffffff81068bc0>] ? kthread+0x0/0xa0
       [<ffffffff81003e60>] ? kernel_thread_helper+0x0/0x10
      ---[ end trace a2ecee9c9602d195 ]---
      
      Cc: Eric W. Biederman <ebiederm@xmission.com>
      Cc: Greg Kroah-Hartman <gregkh@suse.de>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      
      e1955ca0
  15. 08 3月, 2010 3 次提交
  16. 12 12月, 2009 1 次提交
    • J
      firmware_class: make request_firmware_nowait more useful · 9ebfbd45
      Johannes Berg 提交于
      Unfortunately, one cannot hold on to the struct firmware
      that request_firmware_nowait() hands off, which is needed
      in some cases. Allow this by requiring the callback to
      free it (via release_firmware).
      
      Additionally, give it a gfp_t parameter -- all the current
      users call it from a GFP_KERNEL context so the GFP_ATOMIC
      isn't necessary. This also marks an API break which is
      useful in a sense, although that is obviously not the
      primary purpose of this change.
      Signed-off-by: NJohannes Berg <johannes@sipsolutions.net>
      Acked-by: NMarcel Holtmann <marcel@holtmann.org>
      Cc: Ming Lei <tom.leiming@gmail.com>
      Cc: Catalin Marinas <catalin.marinas@arm.com>
      Cc: David Woodhouse <David.Woodhouse@intel.com>
      Cc: Pavel Roskin <proski@gnu.org>
      Cc: Abhay Salunke <abhay_salunke@dell.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
      9ebfbd45
  17. 29 7月, 2009 1 次提交
  18. 13 7月, 2009 1 次提交
  19. 09 7月, 2009 1 次提交