* [PATCH v9 0/2] hibernation support on ARM
@ 2014-03-18 21:40 Sebastian Capella
2014-03-18 21:40 ` [PATCH v9 1/2] ARM: avoid tracers in soft_restart Sebastian Capella
2014-03-18 21:40 ` [PATCH v9 2/2] ARM hibernation / suspend-to-disk Sebastian Capella
0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Capella @ 2014-03-18 21:40 UTC (permalink / raw)
To: linux-arm-kernel
Cc: Russ Dill <Russ.Dill@ti.com>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Stephen Warren <swarren@nvidia.com>
Cc: Len Brown <len.brown@intel.com>
Cc: Nicolas Pitre <nico@linaro.org>
Cc: Santosh Shilimkar <santosh.shilimkar@ti.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Jonathan Austin <jonathan.austin@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: "Uwe Kleine-K?nig" <u.kleine-koenig@pengutronix.de>
Cc: Stephen Boyd <sboyd@codeaurora.org>
Cc: Laura Abbott <lauraa@codeaurora.org>
Cc: Jiang Liu <liuj97@gmail.com>
Cc: Sricharan R <r.sricharan@ti.com>
Cc: Victor Kamensky <victor.kamensky@linaro.org>
Cc: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Ben Dooks <ben.dooks@codethink.co.uk>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Robin Holt <robin.m.holt@gmail.com>
Cc: Konstantin Khlebnikov <k.khlebnikov@samsung.com>
Cc: Steven Capper <steve.capper@linaro.org>
Cc: Tejun Heo <tj@kernel.org>
Patches adding support for hibernation on ARM
- ARM hibernation / suspend-to-disk
- Change soft_restart to use non-tracing raw_local_irq_disable
Patches based on v3.14-rc7 tag, verified hibernation on beaglebone black on a
branch based on 3.13 merged with initial omap support from Russ Dill which
can be found here (includes v1 patchset):
http://git.linaro.org/git-ro/people/sebastian.capella/linux.git hibernation_3.13_russMerge
[PATCH v9 1/2] ARM: avoid tracers in soft_restart
arch/arm/kernel/process.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Use raw_local_irq_disable in place of local_irq_disable to avoid
infinite abort recursion while tracing. (unchanged since v3)
[PATCH v9 2/2] ARM hibernation / suspend-to-disk
arch/arm/Kconfig | 5 ++
arch/arm/include/asm/memory.h | 1 +
arch/arm/kernel/Makefile | 1 +
arch/arm/kernel/hibernate.c | 107 +++++++++++++++++++++++++++++++++++++++++
include/linux/suspend.h | 2 +
5 files changed, 116 insertions(+)
Adds support for ARM based hibernation
Additional notes:
-----------------
There are two checkpatch warnings added by this patch. These follow
behavior in existing hibernation implementations on other platforms.
WARNING: externs should be avoided in .c files
#131: FILE: arch/arm/kernel/hibernate.c:25:
+extern const void __nosave_begin, __nosave_end;
This extern is picking up the linker nosave region definitions, only
used in hibernate. Follows same extern line used mips, powerpc, s390,
sh, sparc, x86 & unicore32
WARNING: externs should be avoided in .c files
#209: FILE: arch/arm/kernel/hibernate.c:103:
+ extern void call_with_stack(void (*fn)(void *), void *arg, void *sp);
This extern is used in the arch/arm/ in hibernate, process and bL_switcher
Changes in v9:
--------------
* replace pfn calculationwith virt_to_pfn
* automatically allow ARCH_HIBERNATION_POSSIBLE if SUSPEND permitted
* move handling of ARCH config flag to arch/arm/Kconfig
Changes in v8:
--------------
* remove definition and use of __pa_symbol
Changes in v7:
--------------
* remove use of RELOC_HIDE macro
* remove unused #includes
* fixup comment for arch_restore_image
* ensure alignment of resume stack on 8 byte boundary
Changes in v6:
--------------
* Simplify static variable names
Changes in v5:
--------------
* Fixed checkpatch warning on trailing whitespace
Changes in v4:
--------------
* updated comment for soft_restart with review feedback
* dropped freeze_processes patch which was queued separately
to 3.14 by Rafael Wysocki:
https://lkml.org/lkml/2014/2/25/683
Changes in v3:
--------------
* added comment to use of soft_restart
* drop irq disable soft_restart patch
* add patch to avoid tracers in soft_restart by using raw_local_irq_*
Changes in v2:
--------------
* Removed unneeded flush_thread, use of __naked and cpu_init.
* dropped Cyril Chemparathy <cyril@ti.com> from Cc: list as
emails are bouncing.
Thanks,
Sebastian Capella
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v9 1/2] ARM: avoid tracers in soft_restart 2014-03-18 21:40 [PATCH v9 0/2] hibernation support on ARM Sebastian Capella @ 2014-03-18 21:40 ` Sebastian Capella 2014-04-14 10:53 ` Will Deacon 2014-03-18 21:40 ` [PATCH v9 2/2] ARM hibernation / suspend-to-disk Sebastian Capella 1 sibling, 1 reply; 5+ messages in thread From: Sebastian Capella @ 2014-03-18 21:40 UTC (permalink / raw) To: linux-arm-kernel Use of tracers in local_irq_disable is causes abort loops when called with irqs disabled using a temporary stack. Replace local_irq_disable with raw_local_irq_disable instead to avoid tracers. Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org> Cc: Russell King <linux@arm.linux.org.uk> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Will Deacon <will.deacon@arm.com> Cc: Robin Holt <holt@sgi.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Konstantin Khlebnikov <k.khlebnikov@samsung.com> Cc: Steven Capper <steve.capper@linaro.org> Cc: Stephen Warren <swarren@nvidia.com> Cc: Tejun Heo <tj@kernel.org> --- arch/arm/kernel/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c index 92f7b15..f58b723 100644 --- a/arch/arm/kernel/process.c +++ b/arch/arm/kernel/process.c @@ -100,7 +100,7 @@ void soft_restart(unsigned long addr) u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack); /* Disable interrupts first */ - local_irq_disable(); + raw_local_irq_disable(); local_fiq_disable(); /* Disable the L2 if we're the last man standing. */ -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v9 1/2] ARM: avoid tracers in soft_restart 2014-03-18 21:40 ` [PATCH v9 1/2] ARM: avoid tracers in soft_restart Sebastian Capella @ 2014-04-14 10:53 ` Will Deacon 2014-04-14 22:37 ` Sebastian Capella 0 siblings, 1 reply; 5+ messages in thread From: Will Deacon @ 2014-04-14 10:53 UTC (permalink / raw) To: linux-arm-kernel Hi Sebastian, On Tue, Mar 18, 2014 at 09:40:57PM +0000, Sebastian Capella wrote: > Use of tracers in local_irq_disable is causes abort loops when called > with irqs disabled using a temporary stack. Replace local_irq_disable > with raw_local_irq_disable instead to avoid tracers. Do you have any more information about these aborts? At the time we call local_irq_disable, the stack is still intact, so if the issue is simply related to having any tracers active at the call_with_stack invocation, we'd be better off disabling tracing here altogether. Will > Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org> > Cc: Russell King <linux@arm.linux.org.uk> > Cc: Andrew Morton <akpm@linux-foundation.org> > Cc: Will Deacon <will.deacon@arm.com> > Cc: Robin Holt <holt@sgi.com> > Cc: Thomas Gleixner <tglx@linutronix.de> > Cc: Konstantin Khlebnikov <k.khlebnikov@samsung.com> > Cc: Steven Capper <steve.capper@linaro.org> > Cc: Stephen Warren <swarren@nvidia.com> > Cc: Tejun Heo <tj@kernel.org> > --- > arch/arm/kernel/process.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c > index 92f7b15..f58b723 100644 > --- a/arch/arm/kernel/process.c > +++ b/arch/arm/kernel/process.c > @@ -100,7 +100,7 @@ void soft_restart(unsigned long addr) > u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack); > > /* Disable interrupts first */ > - local_irq_disable(); > + raw_local_irq_disable(); > local_fiq_disable(); > > /* Disable the L2 if we're the last man standing. */ > -- > 1.7.9.5 > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v9 1/2] ARM: avoid tracers in soft_restart 2014-04-14 10:53 ` Will Deacon @ 2014-04-14 22:37 ` Sebastian Capella 0 siblings, 0 replies; 5+ messages in thread From: Sebastian Capella @ 2014-04-14 22:37 UTC (permalink / raw) To: linux-arm-kernel Hi Will, On 14 April 2014 03:53, Will Deacon <will.deacon@arm.com> wrote: > On Tue, Mar 18, 2014 at 09:40:57PM +0000, Sebastian Capella wrote: >> Use of tracers in local_irq_disable is causes abort loops when called >> with irqs disabled using a temporary stack. Replace local_irq_disable >> with raw_local_irq_disable instead to avoid tracers. > > Do you have any more information about these aborts? At the time we call > local_irq_disable, the stack is still intact, so if the issue is simply > related to having any tracers active at the call_with_stack invocation, we'd > be better off disabling tracing here altogether. This is specifically for when soft_restart is called in the hibernation path with tracers enabled. At that point, we've already switched to a temporary stack, and when we call local_irq_disable, we'll see this: In the local_irq_disable, it ends up calling trace_hardirqs_off (CONFIG_TRACE_IRQFLAGS_SUPPORT is enabled), which calls trace_hardirqs_off_caller which checks lockdep_recursion in the current task, but we've switched to a temporary stack with the call_with_stack, and get_current is returning NULL. This triggers a data abort, which calls trace_hardirqs_off again and so on. We originally had a patch which added a soft restart called soft_restart_noirq which avoided the irq disable. You can see the discussion here: https://patchwork.kernel.org/patch/3677591/ Thanks! Sebastian ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v9 2/2] ARM hibernation / suspend-to-disk 2014-03-18 21:40 [PATCH v9 0/2] hibernation support on ARM Sebastian Capella 2014-03-18 21:40 ` [PATCH v9 1/2] ARM: avoid tracers in soft_restart Sebastian Capella @ 2014-03-18 21:40 ` Sebastian Capella 1 sibling, 0 replies; 5+ messages in thread From: Sebastian Capella @ 2014-03-18 21:40 UTC (permalink / raw) To: linux-arm-kernel From: Russ Dill <Russ.Dill@ti.com> Enable hibernation for ARM architectures and provide ARM architecture specific calls used during hibernation. The swsusp hibernation framework depends on the platform first having functional suspend/resume. Then, in order to enable hibernation on a given platform, a platform_hibernation_ops structure may need to be registered with the system in order to save/restore any SoC-specific / cpu specific state needing (re)init over a suspend-to-disk/resume-from-disk cycle. For example: - "secure" SoCs that have different sets of control registers and/or different CR reg access patterns. - SoCs with L2 caches as the activation sequence there is SoC-dependent; a full off-on cycle for L2 is not done by the hibernation support code. - SoCs requiring steps on wakeup _before_ the "generic" parts done by cpu_suspend / cpu_resume can work correctly. - SoCs having persistent state which is maintained during suspend and resume, but will be lost during the power off cycle after suspend-to-disk. This is a rebase/rework of Frank Hofmann's v5 hibernation patchset. Acked-by: Russ Dill <Russ.Dill@ti.com> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net> Signed-off-by: Sebastian Capella <sebastian.capella@linaro.org> Acked-by: Pavel Machek <pavel@ucw.cz> Reviewed-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Len Brown <len.brown@intel.com> Cc: Nicolas Pitre <nico@linaro.org> Cc: Santosh Shilimkar <santosh.shilimkar@ti.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Jonathan Austin <jonathan.austin@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: "Uwe Kleine-K?nig" <u.kleine-koenig@pengutronix.de> Cc: Stephen Boyd <sboyd@codeaurora.org> Cc: Stefano Stabellini <stefano.stabellini at eu.citrix.com Cc: Victor Kamensky <victor.kamensky@linaro.org> Cc: Sricharan R <r.sricharan@ti.com> Cc: Jiang Liu <liuj97@gmail.com> Cc: Laura Abbott <lauraa@codeaurora.org> --- arch/arm/Kconfig | 5 ++ arch/arm/include/asm/memory.h | 1 + arch/arm/kernel/Makefile | 1 + arch/arm/kernel/hibernate.c | 107 +++++++++++++++++++++++++++++++++++++++++ include/linux/suspend.h | 2 + 5 files changed, 116 insertions(+) create mode 100644 arch/arm/kernel/hibernate.c diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 1594945..d204231 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -2279,6 +2279,11 @@ config ARCH_SUSPEND_POSSIBLE config ARM_CPU_SUSPEND def_bool PM_SLEEP +config ARCH_HIBERNATION_POSSIBLE + bool + depends on MMU + default y if ARCH_SUSPEND_POSSIBLE + endmenu source "net/Kconfig" diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h index 4afb376..47347dd 100644 --- a/arch/arm/include/asm/memory.h +++ b/arch/arm/include/asm/memory.h @@ -289,6 +289,7 @@ static inline void *phys_to_virt(phys_addr_t x) #define __pa(x) __virt_to_phys((unsigned long)(x)) #define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x))) #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) +#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) extern phys_addr_t (*arch_virt_to_idmap)(unsigned long x); diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile index a30fc9b..8afa848 100644 --- a/arch/arm/kernel/Makefile +++ b/arch/arm/kernel/Makefile @@ -39,6 +39,7 @@ obj-$(CONFIG_ARTHUR) += arthur.o obj-$(CONFIG_ISA_DMA) += dma-isa.o obj-$(CONFIG_PCI) += bios32.o isa.o obj-$(CONFIG_ARM_CPU_SUSPEND) += sleep.o suspend.o +obj-$(CONFIG_HIBERNATION) += hibernate.o obj-$(CONFIG_SMP) += smp.o ifdef CONFIG_MMU obj-$(CONFIG_SMP) += smp_tlb.o diff --git a/arch/arm/kernel/hibernate.c b/arch/arm/kernel/hibernate.c new file mode 100644 index 0000000..bb8b796 --- /dev/null +++ b/arch/arm/kernel/hibernate.c @@ -0,0 +1,107 @@ +/* + * Hibernation support specific for ARM + * + * Derived from work on ARM hibernation support by: + * + * Ubuntu project, hibernation support for mach-dove + * Copyright (C) 2010 Nokia Corporation (Hiroshi Doyu) + * Copyright (C) 2010 Texas Instruments, Inc. (Teerth Reddy et al.) + * https://lkml.org/lkml/2010/6/18/4 + * https://lists.linux-foundation.org/pipermail/linux-pm/2010-June/027422.html + * https://patchwork.kernel.org/patch/96442/ + * + * Copyright (C) 2006 Rafael J. Wysocki <rjw@sisk.pl> + * + * License terms: GNU General Public License (GPL) version 2 + */ + +#include <linux/mm.h> +#include <linux/suspend.h> +#include <asm/system_misc.h> +#include <asm/idmap.h> +#include <asm/suspend.h> +#include <asm/memory.h> + +extern const void __nosave_begin, __nosave_end; + +int pfn_is_nosave(unsigned long pfn) +{ + unsigned long nosave_begin_pfn = virt_to_pfn(&__nosave_begin); + unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end - 1); + + return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn); +} + +void notrace save_processor_state(void) +{ + WARN_ON(num_online_cpus() != 1); + local_fiq_disable(); +} + +void notrace restore_processor_state(void) +{ + local_fiq_enable(); +} + +/* + * Snapshot kernel memory and reset the system. + * + * swsusp_save() is executed in the suspend finisher so that the CPU + * context pointer and memory are part of the saved image, which is + * required by the resume kernel image to restart execution from + * swsusp_arch_suspend(). + * + * soft_restart is not technically needed, but is used to get success + * returned from cpu_suspend. + * + * When soft reboot completes, the hibernation snapshot is written out. + */ +static int notrace arch_save_image(unsigned long unused) +{ + int ret; + + ret = swsusp_save(); + if (ret == 0) + soft_restart(virt_to_phys(cpu_resume)); + return ret; +} + +/* + * Save the current CPU state before suspend / poweroff. + */ +int notrace swsusp_arch_suspend(void) +{ + return cpu_suspend(0, arch_save_image); +} + +/* + * Restore page contents for physical pages that were in use during loading + * hibernation image. Switch to idmap_pgd so the physical page tables + * are overwritten with the same contents. + */ +static void notrace arch_restore_image(void *unused) +{ + struct pbe *pbe; + + cpu_switch_mm(idmap_pgd, &init_mm); + for (pbe = restore_pblist; pbe; pbe = pbe->next) + copy_page(pbe->orig_address, pbe->address); + + soft_restart(virt_to_phys(cpu_resume)); +} + +static u64 resume_stack[PAGE_SIZE/2/sizeof(u64)] __nosavedata; + +/* + * Resume from the hibernation image. + * Due to the kernel heap / data restore, stack contents change underneath + * and that would make function calls impossible; switch to a temporary + * stack within the nosave region to avoid that problem. + */ +int swsusp_arch_resume(void) +{ + extern void call_with_stack(void (*fn)(void *), void *arg, void *sp); + call_with_stack(arch_restore_image, 0, + resume_stack + ARRAY_SIZE(resume_stack)); + return 0; +} diff --git a/include/linux/suspend.h b/include/linux/suspend.h index f73cabf..38bbf95 100644 --- a/include/linux/suspend.h +++ b/include/linux/suspend.h @@ -320,6 +320,8 @@ extern unsigned long get_safe_page(gfp_t gfp_mask); extern void hibernation_set_ops(const struct platform_hibernation_ops *ops); extern int hibernate(void); extern bool system_entering_hibernation(void); +asmlinkage int swsusp_save(void); +extern struct pbe *restore_pblist; #else /* CONFIG_HIBERNATION */ static inline void register_nosave_region(unsigned long b, unsigned long e) {} static inline void register_nosave_region_late(unsigned long b, unsigned long e) {} -- 1.7.9.5 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-04-14 22:37 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-03-18 21:40 [PATCH v9 0/2] hibernation support on ARM Sebastian Capella 2014-03-18 21:40 ` [PATCH v9 1/2] ARM: avoid tracers in soft_restart Sebastian Capella 2014-04-14 10:53 ` Will Deacon 2014-04-14 22:37 ` Sebastian Capella 2014-03-18 21:40 ` [PATCH v9 2/2] ARM hibernation / suspend-to-disk Sebastian Capella
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).