1. 13 9月, 2016 1 次提交
  2. 16 7月, 2016 1 次提交
    • R
      x86 / hibernate: Use hlt_play_dead() when resuming from hibernation · 406f992e
      Rafael J. Wysocki 提交于
      On Intel hardware, native_play_dead() uses mwait_play_dead() by
      default and only falls back to the other methods if that fails.
      That also happens during resume from hibernation, when the restore
      (boot) kernel runs disable_nonboot_cpus() to take all of the CPUs
      except for the boot one offline.
      
      However, that is problematic, because the address passed to
      __monitor() in mwait_play_dead() is likely to be written to in the
      last phase of hibernate image restoration and that causes the "dead"
      CPU to start executing instructions again.  Unfortunately, the page
      containing the address in that CPU's instruction pointer may not be
      valid any more at that point.
      
      First, that page may have been overwritten with image kernel memory
      contents already, so the instructions the CPU attempts to execute may
      simply be invalid.  Second, the page tables previously used by that
      CPU may have been overwritten by image kernel memory contents, so the
      address in its instruction pointer is impossible to resolve then.
      
      A report from Varun Koyyalagunta and investigation carried out by
      Chen Yu show that the latter sometimes happens in practice.
      
      To prevent it from happening, temporarily change the smp_ops.play_dead
      pointer during resume from hibernation so that it points to a special
      "play dead" routine which uses hlt_play_dead() and avoids the
      inadvertent "revivals" of "dead" CPUs this way.
      
      A slightly unpleasant consequence of this change is that if the
      system is hibernated with one or more CPUs offline, it will generally
      draw more power after resume than it did before hibernation, because
      the physical state entered by CPUs via hlt_play_dead() is higher-power
      than the mwait_play_dead() one in the majority of cases.  It is
      possible to work around this, but it is unclear how much of a problem
      that's going to be in practice, so the workaround will be implemented
      later if it turns out to be necessary.
      
      Link: https://bugzilla.kernel.org/show_bug.cgi?id=106371Reported-by: NVarun Koyyalagunta <cpudebug@centtech.com>
      Original-by: NChen Yu <yu.c.chen@intel.com>
      Tested-by: NChen Yu <yu.c.chen@intel.com>
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      Acked-by: NIngo Molnar <mingo@kernel.org>
      406f992e
  3. 10 7月, 2016 1 次提交
    • R
      PM / hibernate: Image data protection during restoration · 4c0b6c10
      Rafael J. Wysocki 提交于
      Make it possible to protect all pages holding image data during
      hibernate image restoration by setting them read-only (so as to
      catch attempts to write to those pages after image data have been
      stored in them).
      
      This adds overhead to image restoration code (it may cause large
      page mappings to be split as a result of page flags changes) and
      the errors it protects against should never happen in theory, so
      the feature is only active after passing hibernate=protect_image
      to the command line of the restore kernel.
      
      Also it only is built if CONFIG_DEBUG_RODATA is set.
      Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
      4c0b6c10
  4. 28 6月, 2016 1 次提交
  5. 05 1月, 2016 1 次提交
  6. 19 5月, 2015 1 次提交
  7. 03 11月, 2014 1 次提交
  8. 03 9月, 2014 1 次提交
  9. 21 7月, 2014 1 次提交
  10. 26 5月, 2014 2 次提交
  11. 08 4月, 2014 1 次提交
  12. 01 3月, 2014 1 次提交
  13. 01 7月, 2012 1 次提交
  14. 02 5月, 2012 2 次提交
    • R
      PM / Sleep: Add user space interface for manipulating wakeup sources, v3 · b86ff982
      Rafael J. Wysocki 提交于
      Android allows user space to manipulate wakelocks using two
      sysfs file located in /sys/power/, wake_lock and wake_unlock.
      Writing a wakelock name and optionally a timeout to the wake_lock
      file causes the wakelock whose name was written to be acquired (it
      is created before is necessary), optionally with the given timeout.
      Writing the name of a wakelock to wake_unlock causes that wakelock
      to be released.
      
      Implement an analogous interface for user space using wakeup sources.
      Add the /sys/power/wake_lock and /sys/power/wake_unlock files
      allowing user space to create, activate and deactivate wakeup
      sources, such that writing a name and optionally a timeout to
      wake_lock causes the wakeup source of that name to be activated,
      optionally with the given timeout.  If that wakeup source doesn't
      exist, it will be created and then activated.  Writing a name to
      wake_unlock causes the wakeup source of that name, if there is one,
      to be deactivated.  Wakeup sources created with the help of
      wake_lock that haven't been used for more than 5 minutes are garbage
      collected and destroyed.  Moreover, there can be only WL_NUMBER_LIMIT
      wakeup sources created with the help of wake_lock present at a time.
      
      The data type used to track wakeup sources created by user space is
      called "struct wakelock" to indicate the origins of this feature.
      
      This version of the patch includes an rbtree manipulation fix from John Stultz.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NNeilBrown <neilb@suse.de>
      b86ff982
    • R
      PM / Sleep: Implement opportunistic sleep, v2 · 7483b4a4
      Rafael J. Wysocki 提交于
      Introduce a mechanism by which the kernel can trigger global
      transitions to a sleep state chosen by user space if there are no
      active wakeup sources.
      
      It consists of a new sysfs attribute, /sys/power/autosleep, that
      can be written one of the strings returned by reads from
      /sys/power/state, an ordered workqueue and a work item carrying out
      the "suspend" operations.  If a string representing the system's
      sleep state is written to /sys/power/autosleep, the work item
      triggering transitions to that state is queued up and it requeues
      itself after every execution until user space writes "off" to
      /sys/power/autosleep.
      
      That work item enables the detection of wakeup events using the
      functions already defined in drivers/base/power/wakeup.c (with one
      small modification) and calls either pm_suspend(), or hibernate() to
      put the system into a sleep state.  If a wakeup event is reported
      while the transition is in progress, it will abort the transition and
      the "system suspend" work item will be queued up again.
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      Acked-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Reviewed-by: NNeilBrown <neilb@suse.de>
      7483b4a4
  15. 18 2月, 2012 1 次提交
  16. 13 2月, 2012 1 次提交
  17. 05 2月, 2012 1 次提交
    • S
      PM / Freezer: Thaw only kernel threads if freezing of kernel threads fails · 379e0be8
      Srivatsa S. Bhat 提交于
      If freezing of kernel threads fails, we are expected to automatically
      thaw tasks in the error recovery path. However, at times, we encounter
      situations in which we would like the automatic error recovery path
      to thaw only the kernel threads, because we want to be able to do
      some more cleanup before we thaw userspace. Something like:
      
      error = freeze_kernel_threads();
      if (error) {
      	/* Do some cleanup */
      
      	/* Only then thaw userspace tasks*/
      	thaw_processes();
      }
      
      An example of such a situation is where we freeze/thaw filesystems
      during suspend/hibernation. There, if freezing of kernel threads
      fails, we would like to thaw the frozen filesystems before thawing
      the userspace tasks.
      
      So, modify freeze_kernel_threads() to thaw only kernel threads in
      case of freezing failure. And change suspend_freeze_processes()
      accordingly. (At the same time, let us also get rid of the rather
      cryptic usage of the conditional operator (:?) in that function.)
      
      [rjw: In fact, this patch fixes a regression introduced during the
       3.3 merge window, because without it thaw_processes() may be called
       before swsusp_free() in some situations and that may lead to massive
       memory allocation failures.]
      Signed-off-by: NSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
      Acked-by: NTejun Heo <tj@kernel.org>
      Acked-by: NNigel Cunningham <nigel@tuxonice.net>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      379e0be8
  18. 07 12月, 2011 1 次提交
    • S
      PM / Hibernate: Thaw processes in SNAPSHOT_CREATE_IMAGE ioctl test path · 97819a26
      Srivatsa S. Bhat 提交于
      Commit 2aede851 (PM / Hibernate: Freeze
      kernel threads after preallocating memory) moved the freezing of kernel
      threads to hibernation_snapshot() function.
      
      So now, if the call to hibernation_snapshot() returns early due to a
      successful hibernation test, the caller has to thaw processes to ensure
      that the system gets back to its original state.
      
      But in SNAPSHOT_CREATE_IMAGE hibernation ioctl, the caller does not thaw
      processes in case hibernation_snapshot() returned due to a successful
      freezer test. Fix this issue. But note we still send the value of 'in_suspend'
      (which is now 0) to userspace, because we are not in an error path per-se,
      and moreover, the value of in_suspend correctly depicts the situation here.
      Signed-off-by: NSrivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      97819a26
  19. 17 10月, 2011 2 次提交
    • B
      PM / Hibernate: Improve performance of LZO/plain hibernation, checksum image · 081a9d04
      Bojan Smojver 提交于
      Use threads for LZO compression/decompression on hibernate/thaw.
      Improve buffering on hibernate/thaw.
      Calculate/verify CRC32 of the image pages on hibernate/thaw.
      
      In my testing, this improved write/read speed by a factor of about two.
      Signed-off-by: NBojan Smojver <bojan@rexursive.com>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      081a9d04
    • R
      PM / Hibernate: Freeze kernel threads after preallocating memory · 2aede851
      Rafael J. Wysocki 提交于
      There is a problem with the current ordering of hibernate code which
      leads to deadlocks in some filesystems' memory shrinkers.  Namely,
      some filesystems use freezable kernel threads that are inactive when
      the hibernate memory preallocation is carried out.  Those same
      filesystems use memory shrinkers that may be triggered by the
      hibernate memory preallocation.  If those memory shrinkers wait for
      the frozen kernel threads, the hibernate process deadlocks (this
      happens with XFS, for one example).
      
      Apparently, it is not technically viable to redesign the filesystems
      in question to avoid the situation described above, so the only
      possible solution of this issue is to defer the freezing of kernel
      threads until the hibernate memory preallocation is done, which is
      implemented by this change.
      
      Unfortunately, this requires the memory preallocation to be done
      before the "prepare" stage of device freeze, so after this change the
      only way drivers can allocate additional memory for their freeze
      routines in a clean way is to use PM notifiers.
      Reported-by: NChristoph <cr2005@u-club.de>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      2aede851
  20. 18 5月, 2011 1 次提交
    • R
      PM / Hibernate: Add sysfs knob to control size of memory for drivers · ddeb6487
      Rafael J. Wysocki 提交于
      Martin reports that on his system hibernation occasionally fails due
      to the lack of memory, because the radeon driver apparently allocates
      too much of it during the device freeze stage.  It turns out that the
      amount of memory allocated by radeon during hibernation (and
      presumably during system suspend too) depends on the utilization of
      the GPU (e.g. hibernating while there are two KDE 4 sessions with
      compositing enabled causes radeon to allocate more memory than for
      one KDE 4 session).
      
      In principle it should be possible to use image_size to make the
      memory preallocation mechanism free enough memory for the radeon
      driver, but in practice it is not easy to guess the right value
      because of the way the preallocation code uses image_size.  For this
      reason, it seems reasonable to allow users to control the amount of
      memory reserved for driver allocations made after the hibernate
      preallocation, which currently is constant and amounts to 1 MB.
      
      Introduce a new sysfs file, /sys/power/reserved_size, whose value
      will be used as the amount of memory to reserve for the
      post-preallocation reservations made by device drivers, in bytes.
      For backwards compatibility, set its default (and initial) value to
      the currently used number (1 MB).
      
      References: https://bugzilla.kernel.org/show_bug.cgi?id=34102Reported-and-tested-by: NMartin Steigerwald <Martin@Lichtvoll.de>
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      ddeb6487
  21. 17 10月, 2010 2 次提交
  22. 11 5月, 2010 2 次提交
  23. 15 9月, 2009 1 次提交
    • R
      PM/Hibernate: Do not release preallocated memory unnecessarily (rev. 2) · 64a473cb
      Rafael J. Wysocki 提交于
      Since the hibernation code is now going to use allocations of memory
      to make enough room for the image, it can also use the page frames
      allocated at this stage as image page frames.  The low-level
      hibernation code needs to be rearranged for this purpose, but it
      allows us to avoid freeing a great number of pages and allocating
      these same pages once again later, so it generally is worth doing.
      
      [rev. 2: Take highmem into account correctly.]
      Signed-off-by: NRafael J. Wysocki <rjw@sisk.pl>
      64a473cb
  24. 13 6月, 2009 3 次提交
  25. 21 10月, 2008 1 次提交
  26. 27 7月, 2008 1 次提交
    • H
      kexec jump: save/restore device state · 89081d17
      Huang Ying 提交于
      This patch implements devices state save/restore before after kexec.
      
      This patch together with features in kexec_jump patch can be used for
      following:
      
      - A simple hibernation implementation without ACPI support.  You can kexec a
        hibernating kernel, save the memory image of original system and shutdown
        the system.  When resuming, you restore the memory image of original system
        via ordinary kexec load then jump back.
      
      - Kernel/system debug through making system snapshot.  You can make system
        snapshot, jump back, do some thing and make another system snapshot.
      
      - Cooperative multi-kernel/system.  With kexec jump, you can switch between
        several kernels/systems quickly without boot process except the first time.
        This appears like swap a whole kernel/system out/in.
      
      - A general method to call program in physical mode (paging turning
        off). This can be used to invoke BIOS code under Linux.
      
      The following user-space tools can be used with kexec jump:
      
      - kexec-tools needs to be patched to support kexec jump. The patches
        and the precompiled kexec can be download from the following URL:
             source: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-src_git_kh10.tar.bz2
             patches: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec-tools-patches_git_kh10.tar.bz2
             binary: http://khibernation.sourceforge.net/download/release_v10/kexec-tools/kexec_git_kh10
      
      - makedumpfile with patches are used as memory image saving tool, it
        can exclude free pages from original kernel memory image file. The
        patches and the precompiled makedumpfile can be download from the
        following URL:
             source: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-src_cvs_kh10.tar.bz2
             patches: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile-patches_cvs_kh10.tar.bz2
             binary: http://khibernation.sourceforge.net/download/release_v10/makedumpfile/makedumpfile_cvs_kh10
      
      - An initramfs image can be used as the root file system of kexeced
        kernel. An initramfs image built with "BuildRoot" can be downloaded
        from the following URL:
             initramfs image: http://khibernation.sourceforge.net/download/release_v10/initramfs/rootfs_cvs_kh10.gz
        All user space tools above are included in the initramfs image.
      
      Usage example of simple hibernation:
      
      1. Compile and install patched kernel with following options selected:
      
      CONFIG_X86_32=y
      CONFIG_RELOCATABLE=y
      CONFIG_KEXEC=y
      CONFIG_CRASH_DUMP=y
      CONFIG_PM=y
      CONFIG_HIBERNATION=y
      CONFIG_KEXEC_JUMP=y
      
      2. Build an initramfs image contains kexec-tool and makedumpfile, or
         download the pre-built initramfs image, called rootfs.gz in
         following text.
      
      3. Prepare a partition to save memory image of original kernel, called
         hibernating partition in following text.
      
      4. Boot kernel compiled in step 1 (kernel A).
      
      5. In the kernel A, load kernel compiled in step 1 (kernel B) with
         /sbin/kexec. The shell command line can be as follow:
      
         /sbin/kexec --load-preserve-context /boot/bzImage --mem-min=0x100000
           --mem-max=0xffffff --initrd=rootfs.gz
      
      6. Boot the kernel B with following shell command line:
      
         /sbin/kexec -e
      
      7. The kernel B will boot as normal kexec. In kernel B the memory
         image of kernel A can be saved into hibernating partition as
         follow:
      
         jump_back_entry=`cat /proc/cmdline | tr ' ' '\n' | grep kexec_jump_back_entry | cut -d '='`
         echo $jump_back_entry > kexec_jump_back_entry
         cp /proc/vmcore dump.elf
      
         Then you can shutdown the machine as normal.
      
      8. Boot kernel compiled in step 1 (kernel C). Use the rootfs.gz as
         root file system.
      
      9. In kernel C, load the memory image of kernel A as follow:
      
         /sbin/kexec -l --args-none --entry=`cat kexec_jump_back_entry` dump.elf
      
      10. Jump back to the kernel A as follow:
      
         /sbin/kexec -e
      
         Then, kernel A is resumed.
      
      Implementation point:
      
      To support jumping between two kernels, before jumping to (executing)
      the new kernel and jumping back to the original kernel, the devices
      are put into quiescent state, and the state of devices and CPU is
      saved. After jumping back from kexeced kernel and jumping to the new
      kernel, the state of devices and CPU are restored accordingly. The
      devices/CPU state save/restore code of software suspend is called to
      implement corresponding function.
      
      Known issues:
      
      - Because the segment number supported by sys_kexec_load is limited,
        hibernation image with many segments may not be load. This is
        planned to be eliminated by adding a new flag to sys_kexec_load to
        make a image can be loaded with multiple sys_kexec_load invoking.
      
      Now, only the i386 architecture is supported.
      Signed-off-by: NHuang Ying <ying.huang@intel.com>
      Acked-by: NVivek Goyal <vgoyal@redhat.com>
      Cc: "Eric W. Biederman" <ebiederm@xmission.com>
      Cc: Pavel Machek <pavel@ucw.cz>
      Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
      Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
      Cc: Ingo Molnar <mingo@elte.hu>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      89081d17
  27. 02 2月, 2008 7 次提交