Re: [PATCH v6 2/2] ARM hibernation / suspend-to-disk

2014-06-02 Thread Sebastian Capella
Want to log my new email with this thread in case any questions arise
later and people have trouble finding me.

sebc...@gmail.com

Thanks!

Sebastian Capella
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-05-07 Thread Sebastian Capella
Thanks Pavel!

I believe it's missed 3.15, so will need to verify again for 3.16.

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: linux-next: build warning after merge of the arm tree

2014-04-23 Thread Sebastian Capella
Hi Stephen, Russell,

Verified, thanks!  Please let me know if anything is needed from me for this.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-04-23 Thread Sebastian Capella
Hi Russell,

Ran this overnight and no failures on >1000 hibernations.

Looks good.
Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-04-22 Thread Sebastian Capella
Hi Russell,

Sorry for the delay.

I've merged the omap changes onto 3.15-rc2 and tested and it looks
like everything is working (so far 50 loops into/out of hibernation).

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: linux-next: build warning after merge of the arm tree

2014-04-21 Thread Sebastian Capella
Hi Stephen,

I'm not sure if this is helpful, but the virt_to_pfn macro added in
arch/arm/include/asm/memory.h:300 (I assume the 297 warning in yours),
in the hibernation patch:

#define virt_to_pfn(kaddr)  (__pa(kaddr) >> PAGE_SHIFT)

Should be removed as there is an improved version of virt_to_pfn for
arm in this commit: e26a9e00afc482b971afcaef1db8c9034d4d6d7c

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] PM / Hibernate: no kernel_power_off when pm_power_off NULL

2014-04-21 Thread Sebastian Capella
Reboot logic in kernel/reboot will avoid calling kernel_power_off
when pm_power_off is null, and instead uses kernel_halt.  Change
hibernate's power_down to follow the behavior in the reboot call.

Calling the notifier twice (once for SYS_POWER_OFF and again for
SYS_HALT) causes a panic during hibernation on Kirkwood
Openblocks A6 board.

Signed-off-by: Sebastian Capella 
Reported-by: Ezequiel Garcia 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
Cc: Russell King 
Cc: One Thousand Gnomes 

---
 kernel/power/hibernate.c |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index f4f2073..7642932 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -595,7 +595,8 @@ static void power_down(void)
case HIBERNATION_PLATFORM:
hibernation_platform_enter();
case HIBERNATION_SHUTDOWN:
-   kernel_power_off();
+   if (pm_power_off)
+   kernel_power_off();
break;
 #ifdef CONFIG_SUSPEND
case HIBERNATION_SUSPEND:
@@ -623,7 +624,8 @@ static void power_down(void)
 * corruption after resume.
 */
printk(KERN_CRIT "PM: Please power down manually\n");
-   while(1);
+   while (1)
+   cpu_relax();
 }
 
 /**
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC] PM / Hibernate: no kernel_power_off when pm_power_off NULL

2014-04-18 Thread Sebastian Capella
Thanks Russell, Alan!

So we're OK with the current patch + replacing while(1) after
kernel_halt at the end of power_down in hibernate.c with a while (1)
cpu_relax()?

Any other changes needed?

If not, I'll send a follow up patch with just these.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-04-17 Thread Sebastian Capella
Hi Russell,

It seems to work fine with your virt_to_phys on the 3.13 + OMAP
patches kernel, and I checked on the 3.15-rc1 kernel + hibernation and
it compiled and ran fine.  I tried a couple of hibernations on this
version as well and they worked (aside from the crash in kernel_halt
we're discussing separately).  I believe this just works by chance
though because the omap platform has no real hibernation support
there.

I'll try now to merge up the omap patches to 3.15-rc1.

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-04-16 Thread Sebastian Capella
On 16 April 2014 03:12, Russell King - ARM Linux  wrote:
> On Wed, Mar 05, 2014 at 02:50:05AM -0800, Sebastian Capella wrote:
>> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
>> index 8756e4b..d32adbb 100644
>> --- a/arch/arm/include/asm/memory.h
>> +++ b/arch/arm/include/asm/memory.h
>> @@ -291,6 +291,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 __pa_symbol(x)   __pa((unsigned long)(x))
>>  #define pfn_to_kaddr(pfn)__va((pfn) << PAGE_SHIFT)
>
> I don't see the appropriate version on the mailing list, so I'll comment
> here instead.  In 8011/1, you added here:
>
> +#define virt_to_pfn(kaddr)  (__pa(kaddr) >> PAGE_SHIFT)
>
> which conflicts with my solution (which fixes some rather horrid assembly
> code).  You can find my change as e26a9e00afc4 (ARM: Better virt_to_page()
> handling).  I can drop this from your patch, but it would be a good idea
> if you could re-validate against v3.15-rc1.

Hi Russell,

Thanks!  I'll validate it with e26a9e00afc4 added to my 3.13
hibernation branch, which includes the OMAP patches, and post the
results.  I can also verify against 3.15-rc1 + hibernation patches,
but there's not much to be done, other than compile test, as the
platform support is not there yet.  I can try rebasing the OMAP stuff
to v3.15-rc1, but I'm not sure what to expect out of that.

In any event, I'll let you know.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC] PM / Hibernate: no kernel_power_off when pm_power_off NULL

2014-04-16 Thread Sebastian Capella
On 15 April 2014 14:18, Pavel Machek  wrote:
> On Tue 2014-04-15 21:54:53, Russell King - ARM Linux wrote:
>> What I'm basically saying is that I see no reason for ARM to do something
>> different to what x86 does.
>>
>> What is pretty clear to me is that ARM is compatible with x86, which is
>> compatible with kernel/reboot.c, and it's the hibernate code which is
>> the odd one out.
>
> I'm pretty sure the original code did not return. Anyway, the best
> solution, given how many platforms are out there, would be to
>
> a) document that it should not return
>
> b) fix hibernation to handle the returning case, anyway.

Thanks Russell and Pavel!

This sounds fine to me.  Any objections?

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC] PM / Hibernate: no kernel_power_off when pm_power_off NULL

2014-04-15 Thread Sebastian Capella
Ping..

There appears to be disagreement on the correct path to take on this.

Pavel and Alan recommend that arm's machine_power_off shall never return

Russell suggests hibernation be modified to handle machine_power_off
returning; that x86 architecture (and others as well) can have
machine_power_off returning.

Discussions available at the links below:
https://lkml.org/lkml/2014/3/25/554  -- linux-arm discussion
https://lkml.org/lkml/2014/3/20/649  -- linux-pm discussion

Should I continue with the original hibernation patch from the
linux-pm discussion?

Does anyone have any response to Russel's commentsl?

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v9 1/2] ARM: avoid tracers in soft_restart

2014-04-14 Thread Sebastian Capella
Hi Will,

On 14 April 2014 03:53, Will Deacon  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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC] PM / Hibernate: no kernel_power_off when pm_power_off NULL

2014-03-26 Thread Sebastian Capella
> On 20 March 2014 14:35, One Thousand Gnomes  
> wrote:
>>>   if (pm_power_off)
>>> pm_power_off();
>>> ## It really should do while (1) here.
>> while(1)
>> cpu_relax();
>> or similar at minimum.

Hi Alan, Pavel,

I prepared the changes suggested for ARM, but Russell disagrees that
this code must block, and points to the kernel/reboot.c function from
which I'd taken the original change.

> On Mar 26, Russell King - ARM Linux wrote:
>> I don't see why we should make this change.  kernel/reboot.c handles
>> this function returning, so other places should do too.
>> Even on x86, this function can return:
>>
>> Therefore, I'd say... it's a bug in the hibernation code - or we probably
>> have many buggy architectures.  I'd suggest fixing the hibernation code
>> rather than stuffing some workaround like an endless loop into every
>> architecture.

In this case, the hibernation code would need to changed prevent
calling both sets of notifiers.

The discussions are very short, but the details are here:

https://lkml.org/lkml/2014/3/25/554  -- linux-arm discussion
https://lkml.org/lkml/2014/3/20/649  -- linux-pm discussion

It doesn't appear definitive that the machine_power_off should block,
since the reboot call is working around the possibility.

If we go the route Russell proposes, the change would basically be
this patch.  Are you ok with me trying to adjust the hibernation
handling here?  Do you have any further thoughts on this?

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-25 Thread Sebastian Capella
Hi Alexander,

Thanks for your comments.

I've posted a different solution for arm only here, that just causes a
while loop in machine_power_off in the event it's called but does not
halt.

https://lkml.org/lkml/2014/3/24/299

On 25 March 2014 11:38, Alexander Holler  wrote:
> Both states, power off and sys halt, do sound pretty final and I would
> assume something is broken, if power off is called before sys halt or vice
> versa. At least I would never expect that the reboot/poweroff/syshalt
> notifier may be called twice (and thats why the heartbeat-trigger may
> crash).
>
> But just in case, changing that behaviour in ledtrig-heartbeat.c would be
> pretty easy, just remove the heartbeat_reboot_notifier (which plays nice and
> deregisters the trigger on reboot) and use the panic_notifier (which doesn't
> unregister the trigger but just turns off the led) for reboot too. Another
> solution would be to unregister the reboot_notifier in the reboot_nofifier
> itself. I've just seen one watchdog driver (drivers/rtc/rtc-m41t80.c) which
> does that. But I still think such shouldn't be necessary (and I haven't had
> a look at other reboot_notifier users).

I hope this will all be handled by the loop in machine_power_off, so
maybe this will not be needed.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] ARM: machine_power_off should not return

2014-03-24 Thread Sebastian Capella
Add loop to prevent return from machine_power_off if
pm_power_off is null or does not halt the system.
This caused a panic during hibernation testing on Kirkwood
Openblocks A6 board.

Signed-off-by: Sebastian Capella 
Reported-by: Ezequiel Garcia 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
---
 arch/arm/kernel/process.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index f58b723..6ffdc2c 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -217,6 +217,8 @@ void machine_power_off(void)
 
if (pm_power_off)
pm_power_off();
+   while (1)
+   cpu_relax();
 }
 
 /*
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-24 Thread Sebastian Capella
Hi,

I have no further changes here..  I will submit a separate patch to
cover Ezequiel's concern.  Any final comments?  Otherwise, I'll submit
to Russell's system.

Thanks for the review!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC] PM / Hibernate: no kernel_power_off when pm_power_off NULL

2014-03-20 Thread Sebastian Capella
Thanks Pavel and Alan for your comments!

I'll rework and try again.

Sebastian

On 20 March 2014 14:35, One Thousand Gnomes  wrote:
>>   if (pm_power_off)
>> pm_power_off();
>> }
>>
>> ## It really should do while (1) here.
>
> while(1)
> cpu_relax();
>
> or similar at minimum.
>
> Alan
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC] PM / Hibernate: no kernel_power_off when pm_power_off NULL

2014-03-20 Thread Sebastian Capella
Reboot logic in kernel/reboot will avoid calling kernel_power_off
when pm_power_off is null, and instead uses kernel_halt.  Change
hibernate's power_down to follow the behavior in the reboot call.

Calling the notifier twice (once for SYS_POWER_OFF and again for
SYS_HALT) causes a panic during hibernation on Kirkwood
Openblocks A6 board.

Signed-off-by: Sebastian Capella 
Reported-by: Ezequiel Garcia 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 37170d4..6a278dc 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -595,7 +595,8 @@ static void power_down(void)
case HIBERNATION_PLATFORM:
hibernation_platform_enter();
case HIBERNATION_SHUTDOWN:
-   kernel_power_off();
+   if (pm_power_off)
+   kernel_power_off();
break;
 #ifdef CONFIG_SUSPEND
case HIBERNATION_SUSPEND:
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC 0/1] PM / Hibernate: no kernel_power_off when pm_power_off

2014-03-20 Thread Sebastian Capella
Patch to avoid calling kernel_power_off when pm_power_off is null.
When pm_power_off is null, the platform will not power off in
kernel_power_off.  Currently, hibernate will call kernel_power_off and
then move on to kernel_halt.  However, this calls the notifier chain
twice with a different parameter.  In kernel/reboot.c, this is avoided
by checking if pm_power_off is NULL and bypassing kernel_power_off.

Mostly, this is a check if anyone is dependent on having the reboot
notifier called 2x if pm_power_off is null.  There are some panics if
it's called this way in some drivers.

Tested this on omap beaglebone black, but have not tried on other
hardware.  Please let me know if you can test this on another platform
and the results.

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-20 Thread Sebastian Capella
Hi Tony,

I have not used the tux-on-ice solution.  The patchset I've sent is to
add initial support for swsusp based hibernation for ARM.

Can you please begin a new, separate thread for this?  Ie. separate
from the review for the swsusp hibernation patches I've submitted?
I'm not sure where the right list/forum is for this, perhaps someone
can make a recommendation, but I am not sure it should go on LKML.
Please copy me on your new thread.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 1/2] ARM: avoid tracers in soft_restart

2014-03-19 Thread Sebastian Capella
On 6 March 2014 15:45, Sebastian Capella  wrote:
> Quoting Sebastian Capella (2014-03-05 02:50:04)
>> Use of tracers in local_irq_disable is causes recursive aborts when
>> called with irqs disabled and using a temporary stack (hibernation).
>> Replace local_irq_disable with raw_local_irq_disable instead to
>> avoid tracers.

> I have not heard any feedback on this change, since V3 of the
> patchset.
> Is everyone ok with this as it is?
> Thomas, thanks for proposing this, is this looking ok to you?

ping

I haven't received any further communication / acks on this particular
patch, since Russell's ~approval below:

On 26 February 2014 15:37, Russell King - ARM Linux
 wrote:
> Great, I'm happy with this now.  I assume that the plan is to submit this
>  to my patch system when everyone's given their fill of acks?

Is this ok as it is?

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-19 Thread Sebastian Capella
On 19 March 2014 13:47, Sebastian Capella  wrote:
> diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
> index a5f702a..d96b910 100644
> --- a/kernel/power/hibernate.c
> +++ b/kernel/power/hibernate.c
> @@ -594,7 +594,8 @@ static void power_down(void)
> case HIBERNATION_PLATFORM:
> hibernation_platform_enter();
> case HIBERNATION_SHUTDOWN:
> -   kernel_power_off();
> +   if (pm_power_off)
> +   kernel_power_off();
> break;
>  #ifdef CONFIG_SUSPEND
> case HIBERNATION_SUSPEND:
>
>
> This follows the behavior in the reboot syscall which does it this way
> also.  I'm testing this now, and it seems work fine.  If this looks
> good, I can add it as an additional patch.

BTW, one thing I would point out is that kernel_power_off and
kernel_halt call the same notifier but with different parameters
(SYS_POWER_OFF and SYS_HALT).

If pm_power_down is null, I dont see why we'd want to notify
SYS_POWER_OFF before SYS_HALT.  With the previous change I'm assuming
there's no benefit, so please chime in if you know a reason.

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-19 Thread Sebastian Capella
On 19 March 2014 08:44, Ezequiel Garcia
 wrote:
> Tested-by: Ezequiel Garcia 
Thanks!
> On the other side, this board has no pm_power_off() support, which means
> kernel_halt() is called after kernel_power_off().
>
> I'm not sure if a NULL pm_power_off() is supported, but this makes my kernel
> crash in a reboot notifier that's called twice (first in kernel_power_off
> and then in kernel_halt):

The omap board I'm using has a null pm_power_off.  I added code to
bypass kernel_power_off in the event pm_power_off is null like this:


diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index a5f702a..d96b910 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -594,7 +594,8 @@ static void power_down(void)
case HIBERNATION_PLATFORM:
hibernation_platform_enter();
case HIBERNATION_SHUTDOWN:
-   kernel_power_off();
+   if (pm_power_off)
+   kernel_power_off();
break;
 #ifdef CONFIG_SUSPEND
case HIBERNATION_SUSPEND:


This follows the behavior in the reboot syscall which does it this way
also.  I'm testing this now, and it seems work fine.  If this looks
good, I can add it as an additional patch.

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v9 2/2] ARM hibernation / suspend-to-disk

2014-03-18 Thread Sebastian Capella
From: Russ Dill 

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 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Acked-by: Pavel Machek 
Reviewed-by: Lorenzo Pieralisi 
Cc: Russell King 
Cc: Len Brown 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
Cc: Stefano Stabellini 
Cc: Sricharan R 
Cc: Jiang Liu 
Cc: Laura Abbott 
---
 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 000..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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+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 kern

[PATCH v9 1/2] ARM: avoid tracers in soft_restart

2014-03-18 Thread Sebastian Capella
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 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Will Deacon 
Cc: Robin Holt 
Cc: Thomas Gleixner 
Cc: Konstantin Khlebnikov 
Cc: Steven Capper 
Cc: Stephen Warren 
Cc: Tejun Heo 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-17 Thread Sebastian Capella
On 17 March 2014 13:44, Ezequiel Garcia
 wrote:
> On Mar 17, Sebastian Capella wrote:
>> On 16 March 2014 00:09, Ezequiel Garcia
>>  wrote:
>> > On Mar 05, Sebastian Capella wrote:
>> > [..]
>> >> diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
>> >> index 1f8fed9..83707702 100644
>> >> --- a/arch/arm/mm/Kconfig
>> >> +++ b/arch/arm/mm/Kconfig
>> >> @@ -611,6 +611,11 @@ config CPU_USE_DOMAINS
>> >>  config IO_36
>> >>   bool
>> >>
>> >> +config ARCH_HIBERNATION_POSSIBLE
...
>> > Is there any reason why CPU_FEROCEON is not listed here? FWIW, I've just 
>> > built
>> > (but not really tested) a Kirkwood kernel with CONFIG_HIBERNATION=y.
...
> Sure, no problem. If you consider that build-test is enough, feel free to put
> CPU_FEROCEON on that list. We added suspend/resume to feroceon not long ago.
>> > And is there any reason to put this config in arch/arm/mm/Kconfig, instead 
>> > of
>> > in arch/arm/Kconfig, below ARCH_SUSPEND_POSSIBLE?
...
> I guess my question wasn't clear. I mean to ask: Are there any other
> requirements on an ARM platform to support hibernation, other than
> suspend/resume support?
>
> If this is the *only* requirement, it seems to me we could make our
> ARCH_SUSPEND_POSSIBLE also select ARCH_HIBERNATION_POSSIBLE.

Thanks, I've added it like this in arch/arm/Kconfig.  I'm sure you
know, but this way also takes care of the CPU_FEROCEON in the default
list since SUSPEND_POSSIBLE already contains it.

config ARCH_HIBERNATION_POSSIBLE
bool
depends on MMU
default y if ARCH_SUSPEND_POSSIBLE

Does this look ok?

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-17 Thread Sebastian Capella
Thanks Russell!

On 16 March 2014 02:46, Russell King - ARM Linux  wrote:
> On Mon, Mar 10, 2014 at 11:32:17AM -0700, Sebastian Capella wrote:
...
> Let's look at the implementations...
>
> #define __pa(x) __virt_to_phys((unsigned long)(x))
> static inline phys_addr_t __virt_to_phys(unsigned long x)
> {
> return (phys_addr_t)x - PAGE_OFFSET + PHYS_OFFSET;
> }
>
> So, __pa() returns a phys_addr_t (which may be either 32-bit or 64-bit).
>
> #define virt_to_pfn(kaddr)  (__pa(kaddr) >> PAGE_SHIFT)
>
> And that will do an appropriate shift to convert the phys_addr_t to a PFN,
> which will be fine to assign to an unsigned long variable.
>
> #define __phys_to_pfn(paddr)((unsigned long)((paddr) >> PAGE_SHIFT))
>
> This does the same thing, but has an explicit cast.
>
> So, the only difference between the two suggestions is that additional
> cast, which has no effect here.

Sounds good, thanks!

I was a little unsure about the page sizes that could affect all of
the implementations.

I'll make this change and repost, basically using virt_to_pfn in place
of the previous __pa_symbol, and remove unused declarations.

Thanks again!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-17 Thread Sebastian Capella
On 16 March 2014 00:09, Ezequiel Garcia
 wrote:
> On Mar 05, Sebastian Capella wrote:
> [..]
>> diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
>> index 1f8fed9..83707702 100644
>> --- a/arch/arm/mm/Kconfig
>> +++ b/arch/arm/mm/Kconfig
>> @@ -611,6 +611,11 @@ config CPU_USE_DOMAINS
>>  config IO_36
>>   bool
>>
>> +config ARCH_HIBERNATION_POSSIBLE
...
>> + default y if CPU_ARM920T || CPU_ARM926T || CPU_SA1100 || CPU_XSCALE || 
>> CPU_XSC3 || CPU_V6 || CPU_V6K || CPU_V7
...
> Is there any reason why CPU_FEROCEON is not listed here? FWIW, I've just built
> (but not really tested) a Kirkwood kernel with CONFIG_HIBERNATION=y.
No reason; I did not change this from the original patch I'd received.
 I didn't try to get a comprehensive list of supported hardware.  To
my understanding, the goal is to get the infrastructure in so that
people can start working on their platforms and add support for them.

> And is there any reason to put this config in arch/arm/mm/Kconfig, instead of
> in arch/arm/Kconfig, below ARCH_SUSPEND_POSSIBLE?
I don't have a reason.  Anyone else have a comment on this?
Otherwise, I'll move it.. thanks!

> I'm also puzzled about having two separate options for suspend and hibernate,
> maybe someone can explain me why a given CPU would support the former but not
> the latter?
It's part of having the generic hibernation implemented and available
but with architecture specific dependencies.  Where an architecture
may not have support for hibernation, it will prevent compilation of
the generic hibernation support.  For example, at the moment, ARM does
not support hibernation.  As a result, hibernation is not presented as
an option in menuconfig.  If you were to artificially enable it (by
hacking ARCH_HIBERNATION_POSSIBLE=y, and then turning
CONFIG_HIBERNATION=y) then you'd get linker errors due to the missing
architecture hibernation functions.  (basically what is being added by
this patch for ARM).  It's like this for other architectures as well
(mips, sh, etc..)

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v8 1/2] ARM: avoid tracers in soft_restart

2014-03-11 Thread Sebastian Capella
Use of tracers in local_irq_disable is causes recursive aborts when
called with irqs disabled and using a temporary stack (hibernation).
Replace local_irq_disable with raw_local_irq_disable instead to
avoid tracers.

Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
Cc: Lorenzo Pieralisi 
Cc: Konstantin Khlebnikov 
Cc: Steven Capper 
Cc: Stephen Warren 
Cc: Tejun Heo 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v8 0/2] hibernation support on ARM

2014-03-11 Thread Sebastian Capella

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-rc5 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 v8 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 v8 2/2] ARM hibernation / suspend-to-disk
 arch/arm/kernel/Makefile|1 +
 arch/arm/kernel/hibernate.c |  107 +++
 arch/arm/mm/Kconfig |5 ++
 include/linux/suspend.h |2 +
 4 files changed, 115 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
#108: 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
#186: 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 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  from Cc: list as
  emails are bouncing.

Thanks,

Sebastian Capella




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v8 2/2] ARM hibernation / suspend-to-disk

2014-03-11 Thread Sebastian Capella
From: Russ Dill 

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 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Acked-by: Pavel Machek 
Reviewed-by: Lorenzo Pieralisi 
Cc: Russell King 
Cc: Len Brown 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
Cc: Laura Abbott 
Cc: Jiang Liu 
Cc: Sricharan R 
Cc: Victor Kamensky 
Cc: Stefano Stabellini 
Cc: Ben Dooks 
---
 arch/arm/kernel/Makefile|1 +
 arch/arm/kernel/hibernate.c |  107 +++
 arch/arm/mm/Kconfig |5 ++
 include/linux/suspend.h |2 +
 4 files changed, 115 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

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 000..036293d
--- /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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn = __phys_to_pfn(__pa(&__nosave_begin));
+   unsigned long nosave_end_pfn = __phys_to_pfn(__pa(&__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_pb

Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-10 Thread Sebastian Capella
On 6 March 2014 20:42, Stephen Boyd  wrote:
> On 03/05, Sebastian Capella wrote:
>> diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
>> index 8756e4b..d32adbb 100644
>> --- a/arch/arm/include/asm/memory.h
>> +++ b/arch/arm/include/asm/memory.h
>> @@ -291,6 +291,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 __pa_symbol(x)   __pa((unsigned long)(x))
> Looking at this definition now it doesn't look right. Isn't
> &__nosave_begin a virtual address? Casting it to an unsigned long
> isn't going to give you a physical address. Why can't we use
> __pa()?

You're correct, sorry, I missed removing the cast, it's not needed.
I've removed the __pa_symbol define as I'm switching to the __pa
implementation you suggested below.

>> +extern const void __nosave_begin, __nosave_end;
>> +
>> +int pfn_is_nosave(unsigned long pfn)
>> +{
>> + unsigned long nosave_begin_pfn =
>> + __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
>> + unsigned long nosave_end_pfn =
>> + PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
>> +
>> + return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn);
>> +}
>
> Perhaps this code could be:
>
> unsigned long nosave_begin_pfn = virt_to_pfn(&__nosave_begin);
> unsigned long nosave_end_pfn = virt_to_pfn(&__nosave_end);
>
> return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
>
> or if virt_to_pfn() doesn't exist on ARM and we can't add it for
> some reason:
>
> unsigned long nosave_begin_pfn = __phys_to_pfn(__pa(&__nosave_begin));
> unsigned long nosave_end_pfn = __phys_to_pfn(__pa(&__nosave_end));
>
> return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
I've moved to this second implementation.  I don't think I understand
the ramifications enough to add the virt_to_pfn call for arm.

I've changed one thing.  __nosave_end is pointing at the first byte
not included in the nosave region.  I subtracted one from it so that
we make sure we're referring to the last pfn, and left the pfn
comparison as you'd suggested.

int pfn_is_nosave(unsigned long pfn)
{
unsigned long nosave_begin_pfn = __phys_to_pfn(__pa(&__nosave_begin));
unsigned long nosave_end_pfn = __phys_to_pfn(__pa(&__nosave_end - 1));

return (pfn >= nosave_begin_pfn) && (pfn <= nosave_end_pfn);
}

I'll test this and post it if everyone's ok with it.

Thanks for your review and comments Stephen!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-06 Thread Sebastian Capella
Sorry to those receiving repeated emails, I'm having an issue with some
of the special characters names.

Quoting Sebastian Capella (2014-03-05 02:50:05)
> From: Russ Dill 
> Enable hibernation for ARM architectures and provide ARM
> architecture specific calls used during hibernation.
...
Quoting Stephen Boyd (2014-02-27 18:19:49)
> On 02/27/14 17:47, Russ Dill wrote:
> > On 02/27/2014 04:09 PM, Stephen Boyd wrote:
> >> On 02/27/14 15:57, Sebastian Capella wrote:
> >>> diff --git a/arch/arm/include/asm/memory.h
> >>> b/arch/arm/include/asm/memory.h index 8756e4b..1079ea8
> >>> 100644 ---
> >>> a/arch/arm/include/asm/memory.h +++
> >>> b/arch/arm/include/asm/memory.h @@ -291,6 +291,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 __pa_symbol(x)
> >>> __pa(RELOC_HIDE((unsigned long)(x), 0))
> >> Just curious, is there a reason for the RELOC_HIDE() here?
> >> Or
> >> __pa_symbol() for that matter? It looks like only x86 uses
> >> this on
> >> the __nosave_{begin,end} symbol. Maybe it's copy-pasta?
> > From my understanding this needs to stick around so long as
> > gcc 3.x is
> > supported (did it get dropped yet?) on ARM Linux since it
> > doesn't
> > support -fno-strict-overflow.
>
> I don't think it's been dropped yet but I wonder if anyone has
> tried
> recent kernels with such a compiler?

Hi Stephen,

I was wondering if you had any objections or additional comments on
the current patch.

I've basically dropped the RELOC_HIDE.  It hasn't proven to be an issue
with the current compiler, and I was unable to revert back to 3.x
compiler on the cortex-v7 platforms I'm using.

Since this is being used on Hibernation, we would not be breaking any
existing functionality in any event, and it sounds like this is unlikely
to be an issue.

I spoke informally to a friend who works on toolchains at Linaro and
he suggested this may be related to the the strict-aliasing feature
which appears to be disabled by default in the kernel
(-fno-strict-aliasing) and generally not well liked.

Unless someone objects, I'll plan to add this to Russell's patch system.

Thanks,

Sebastian

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v7 1/2] ARM: avoid tracers in soft_restart

2014-03-06 Thread Sebastian Capella
Quoting Sebastian Capella (2014-03-05 02:50:04)
> Use of tracers in local_irq_disable is causes recursive aborts when
> called with irqs disabled and using a temporary stack (hibernation).
> Replace local_irq_disable with raw_local_irq_disable instead to
> avoid tracers.
> 
> Signed-off-by: Sebastian Capella 
> Cc: Russell King 
> Cc: Andrew Morton 
> Cc: Thomas Gleixner 
> Cc: Will Deacon 
> Cc: Robin Holt 
> Cc: Lorenzo Pieralisi 
> Cc: Konstantin Khlebnikov 
> Cc: Steven Capper 
> Cc: Stephen Warren 
> Cc: Tejun Heo 
> ---
>  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
Hi,

I have not heard any feedback on this change, since V3 of the
patchset.

Is everyone ok with this as it is?

Thomas, thanks for proposing this, is this looking ok to you?

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7 2/2] ARM hibernation / suspend-to-disk

2014-03-05 Thread Sebastian Capella
From: Russ Dill 

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 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Acked-by: Pavel Machek 
Reviewed-by: Lorenzo Pieralisi 
Cc: Russell King 
Cc: Len Brown 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
Cc: Laura Abbott 
Cc: Jiang Liu 
Cc: Sricharan R 
Cc: Victor Kamensky 
Cc: Stefano Stabellini 
Cc: Ben Dooks 
---
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  108 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 117 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4b..d32adbb 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -291,6 +291,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 __pa_symbol(x) __pa((unsigned long)(x))
 #define pfn_to_kaddr(pfn)  __va((pfn) << 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 000..656718a
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,108 @@
+/*
+ * 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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn =
+   __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+   unsigned long nosave_end_pfn =
+   PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+   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 

[PATCH v7 1/2] ARM: avoid tracers in soft_restart

2014-03-05 Thread Sebastian Capella
Use of tracers in local_irq_disable is causes recursive aborts when
called with irqs disabled and using a temporary stack (hibernation).
Replace local_irq_disable with raw_local_irq_disable instead to
avoid tracers.

Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
Cc: Lorenzo Pieralisi 
Cc: Konstantin Khlebnikov 
Cc: Steven Capper 
Cc: Stephen Warren 
Cc: Tejun Heo 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7 0/2] hibernation support on ARM

2014-03-05 Thread Sebastian Capella
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-rc5 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 v7 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 v7 2/2] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  108 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 117 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
#120: FILE: arch/arm/kernel/hibernate.c:24:
+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
#200: FILE: arch/arm/kernel/hibernate.c:104:
+   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 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  from Cc: list as 
  emails are bouncing.

Thanks,

Sebastian Capella


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v6 2/2] ARM hibernation / suspend-to-disk

2014-03-04 Thread Sebastian Capella
Quoting Sebastian Capella (2014-02-28 10:17:31)
> Quoting Russell King - ARM Linux (2014-02-28 02:20:18)
> > On Thu, Feb 27, 2014 at 06:19:49PM -0800, Stephen Boyd wrote:
> > > On 02/27/14 17:47, Russ Dill wrote:
> > > > On 02/27/2014 04:09 PM, Stephen Boyd wrote:
> > > >> On 02/27/14 15:57, Sebastian Capella wrote:
> > > >>> diff --git a/arch/arm/include/asm/memory.h
> > > >>> b/arch/arm/include/asm/memory.h index 8756e4b..1079ea8 100644 ---
> > > >>> a/arch/arm/include/asm/memory.h +++
> > > >>> b/arch/arm/include/asm/memory.h @@ -291,6 +291,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 __pa_symbol(x)
> > > >>> __pa(RELOC_HIDE((unsigned long)(x), 0))
> > > >> Just curious, is there a reason for the RELOC_HIDE() here? Or 
> > > >> __pa_symbol() for that matter? It looks like only x86 uses this on
> > > >> the __nosave_{begin,end} symbol. Maybe it's copy-pasta?
> > > > From my understanding this needs to stick around so long as gcc 3.x is
> > > > supported (did it get dropped yet?) on ARM Linux since it doesn't
> > > > support -fno-strict-overflow.
> > > 
> > > I don't think it's been dropped yet but I wonder if anyone has tried
> > > recent kernels with such a compiler?
> > > 
> > > Would the usage of &__pv_table_begin in arch/arm/mm/mmu.c also need the
> > > same treatment?
> > 
> > We've never had to play these kinds of games on ARM irrespective of
> > compiler version.
> 
> I am using gcc 4.6.3.  I can try removing it but I suspect it will just
> work without it.  Let me see if I can get an older compiler and try both
> ways.

Hi,

I've been struggling a bit to test 3.x compilers on this.

I'm running an armv7 board, but the 3.x compilers I'm trying
don't appear to suport armv7.

Anyone have any suggestions?  Is this a worthwhile effort?

Thanks!

Sebastian

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v6 2/2] ARM hibernation / suspend-to-disk

2014-03-04 Thread Sebastian Capella
Quoting Sebastian Capella (2014-02-28 15:38:54)
> Quoting Lorenzo Pieralisi (2014-02-28 14:49:33)
> > On Fri, Feb 28, 2014 at 08:15:57PM +, Sebastian Capella wrote:
> > > > 
> > > > This does not guarantee your stack is 8-byte aligned, that's not AAPCS
> > > > compliant and might buy you trouble.
> > > > 
> > > > Either you align the stack or you align the pointer you are passing.
> > > > 
> > > > Please have a look at kernel/process.c
> > > 
> > > I've added this for now, do you see any issues?
> > > 
> > > -static u8 resume_stack[PAGE_SIZE/2] __nosavedata;
> > > +static u64 resume_stack[PAGE_SIZE/2/sizeof(u64)] __nosavedata;
> > > -   resume_stack + sizeof(resume_stack));
> > > +   resume_stack + ARRAY_SIZE(resume_stack));
> > 
> > I do not see why the stack depends on the PAGE_SIZE. I would be surprised
> > if you need more than a few bytes (given that soft_restart switches stack
> > again...), go through it with a debugger, it is easy to check the stack
> > usage and allow for some extra buffer (but half a page is not needed).
> 
> I assuming this is becase the no-save region is one page anyway (we skip
> restoring the no-save region physical page).  So maybe 1/2 is a way to
> leave some room for whatever else may need to be here, but in any case
> the 4k is used for nosave.  I think you're right that it can be much less.

Hi Lorenzo,

Are you ok with this just being half a page?  Or do you want me to try
to reduce the stack size?  I am at Connect without my debugger, so in
that case it would have to wait until next week.

The change for alignment is in as discussed.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 0/2] hibernation support on ARM

2014-02-27 Thread Sebastian Capella
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.13 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 v6 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 v6 2/2] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  113 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 122 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
#116: FILE: arch/arm/kernel/hibernate.c:26:
+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
#199: FILE: arch/arm/kernel/hibernate.c:109:
+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 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  from Cc: list as 
  emails are bouncing.

Thanks,

Sebastian Capella

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 2/2] ARM hibernation / suspend-to-disk

2014-02-27 Thread Sebastian Capella
From: Russ Dill 

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 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Acked-by: Pavel Machek 
Cc: Russell King 
Cc: Len Brown 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
Cc: Lorenzo Pieralisi 
---
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  113 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 122 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4b..1079ea8 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -291,6 +291,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 __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 #define pfn_to_kaddr(pfn)  __va((pfn) << 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 000..a41e0e3
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,113 @@
+/*
+ * 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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn =
+   __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+   unsigned long nosave_end_pfn =
+   PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+   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 = swsu

[PATCH v6 1/2] ARM: avoid tracers in soft_restart

2014-02-27 Thread Sebastian Capella
Use of tracers in local_irq_disable is causes recursive aborts when
called with irqs disabled and using a temporary stack (hibernation).
Replace local_irq_disable with raw_local_irq_disable instead to
avoid tracers.

Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
Cc: Lorenzo Pieralisi 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 2/2] ARM hibernation / suspend-to-disk

2014-02-26 Thread Sebastian Capella
From: Russ Dill 

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 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
Cc: Lorenzo Pieralisi 
---
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  113 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 122 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4b..1079ea8 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -291,6 +291,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 __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 #define pfn_to_kaddr(pfn)  __va((pfn) << 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 000..0a84924
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,113 @@
+/*
+ * 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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn =
+   __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+   unsigned long nosave_end_pfn =
+   PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+   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 __swsusp_arch_save_image(unsigned long unused)
+{
+   int ret;
+
+   ret = swsu

[PATCH v5 0/2] hibernation support on ARM

2014-02-26 Thread Sebastian Capella
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.13 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 v5 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 v5 2/2] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  113 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 122 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
#116: FILE: arch/arm/kernel/hibernate.c:26:
+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
#191: FILE: arch/arm/kernel/hibernate.c:101:
+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 v5:
--
* 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  from Cc: list as 
  emails are bouncing.

Thanks,

Sebastian Capella

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 1/2] ARM: avoid tracers in soft_restart

2014-02-26 Thread Sebastian Capella
Use of tracers in local_irq_disable is causes recursive aborts when
called with irqs disabled and using a temporary stack (hibernation).
Replace local_irq_disable with raw_local_irq_disable instead to
avoid tracers.

Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
Cc: Lorenzo Pieralisi 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 1/2] ARM: avoid tracers in soft_restart

2014-02-26 Thread Sebastian Capella
Use of tracers in local_irq_disable is causes recursive aborts when
called with irqs disabled and using a temporary stack (hibernation).
Replace local_irq_disable with raw_local_irq_disable instead to
avoid tracers.

Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
Cc: Lorenzo Pieralisi 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 2/2] ARM hibernation / suspend-to-disk

2014-02-26 Thread Sebastian Capella
From: Russ Dill 

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.

Cc: Russ Dill 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
Cc: Lorenzo Pieralisi 
---
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  113 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 122 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4b..1079ea8 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -291,6 +291,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 __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 #define pfn_to_kaddr(pfn)  __va((pfn) << 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 000..70e17d2
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,113 @@
+/*
+ * 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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn =
+   __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+   unsigned long nosave_end_pfn =
+   PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+   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 __swsusp_arch_save_image(unsigned long unused)
+{
+   int ret;
+
+   ret = swsusp_save();
+  

[PATCH v4 0/2] hibernation support on ARM

2014-02-26 Thread Sebastian Capella
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.13 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 v4 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 v4 2/2] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  113 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 122 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
#116: FILE: arch/arm/kernel/hibernate.c:26:
+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
#191: FILE: arch/arm/kernel/hibernate.c:101:
+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 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  from Cc: list as 
  emails are bouncing.

Thanks,

Sebastian Capella

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 0/2] hibernation support on ARM

2014-02-26 Thread Sebastian Capella
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.13 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 v4 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 v4 2/2] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  113 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 122 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
#116: FILE: arch/arm/kernel/hibernate.c:26:
+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
#191: FILE: arch/arm/kernel/hibernate.c:101:
+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 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  from Cc: list as 
  emails are bouncing.

Thanks,

Sebastian Capella

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/3] Fix hibernation restore hang in freeze_processes

2014-02-25 Thread Sebastian Capella
During restore, pm_notifier chain are called with
PM_RESTORE_PREPARE.  The firmware_class driver handler
fw_pm_notify does not have a handler for this.  As a result,
it keeps a reader on the kmod.c umhelper_sem.  During
freeze_processes, the call to __usermodehelper_disable tries to
take a write lock on this semaphore and hangs waiting.

Signed-off-by: Sebastian Capella 
Acked-by: Ming Lei 
Cc: Russ Dill 
Cc: Greg Kroah-Hartman 
---
 drivers/base/firmware_class.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index eb8fb94..e2b51f8 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1541,6 +1541,7 @@ static int fw_pm_notify(struct notifier_block 
*notify_block,
switch (mode) {
case PM_HIBERNATION_PREPARE:
case PM_SUSPEND_PREPARE:
+   case PM_RESTORE_PREPARE:
kill_requests_without_uevent();
device_cache_fw_images();
break;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/3] hibernation support on ARM

2014-02-25 Thread Sebastian Capella
Patches adding support for hibernation on ARM
  - ARM hibernation / suspend-to-disk
  - Fix hang in freeze_processes during hibernation
  - Change soft_restart to use non-tracing raw_local_irq_disable

Patches based on v3.13 tag, verified hibernation on beaglebone black on a branch
based on 3.13 merged with initial omap support from Russ Dill which be found 
here:
http://git.linaro.org/git-ro/people/sebastian.capella/linux.git 
hibernation_3.13_russMerge
(includes v1 patchset)


[PATCH v3 1/3] Fix hibernation restore hang in freeze_processes
 drivers/base/firmware_class.c |1 +
 1 file changed, 1 insertion(+)

 Add handling for PM_RESTORE_PREPARE notifier (unchanged from v1)

[PATCH v3 2/3] 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.

[PATCH v3 3/3] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  106 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 115 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
#116: FILE: arch/arm/kernel/hibernate.c:26:
+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
#191: FILE: arch/arm/kernel/hibernate.c:101:
+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 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  from Cc: list as 
  emails are bouncing.

Thanks,

Sebastian Capella
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/3] ARM: avoid tracers in soft_restart

2014-02-25 Thread Sebastian Capella
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 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 3/3] ARM hibernation / suspend-to-disk

2014-02-25 Thread Sebastian Capella
From: Russ Dill 

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.

Cc: Russ Dill 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
---
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  106 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 115 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4b..1079ea8 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -291,6 +291,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 __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 #define pfn_to_kaddr(pfn)  __va((pfn) << 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 000..13dda00
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,106 @@
+/*
+ * 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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn =
+   __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+   unsigned long nosave_end_pfn =
+   PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+   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.
+ * soft_restart is not technically needed, but is used
+ * to get success returned from cpu_suspend.
+ * After resume, the hibernation snapshot is written out.
+ */
+static int notrace __swsusp_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, __swsusp_arch_save_image);
+}
+
+/*
+ * The fr

Re: [PATCH RFC v1 1/3] ARM: Add irq disabled version of soft_restart.

2014-02-25 Thread Sebastian Capella
Quoting Russ Dill (2014-02-25 09:15:33)
> On 02/25/2014 02:27 AM, Thomas Gleixner wrote:
> > If you want escape the tracer and in that case you really want it 
> > being on a different stack, use raw_local_irq_* which are not
> > traced.
> 
> So it might make sense to change soft_restart to use the
> raw_local_irq_* calls.

I've added this change.  So far it's working well.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 1/3] ARM: Add irq disabled version of soft_restart.

2014-02-24 Thread Sebastian Capella
From: Russ Dill 

This adds the ability to run soft_restart with local_irq/fiq_disable
already called. This is helpful for the hibernation code paths.

Signed-off-by: Russ Dill 
Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
---
 arch/arm/include/asm/system_misc.h |1 +
 arch/arm/kernel/process.c  |   15 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/arch/arm/include/asm/system_misc.h 
b/arch/arm/include/asm/system_misc.h
index a3d61ad..eca8dd4 100644
--- a/arch/arm/include/asm/system_misc.h
+++ b/arch/arm/include/asm/system_misc.h
@@ -10,6 +10,7 @@
 
 extern void cpu_init(void);
 
+void soft_restart_noirq(unsigned long);
 void soft_restart(unsigned long);
 extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 extern void (*arm_pm_idle)(void);
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 92f7b15..685bc4a 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -95,14 +95,10 @@ static void __soft_restart(void *addr)
BUG();
 }
 
-void soft_restart(unsigned long addr)
+void soft_restart_noirq(unsigned long addr)
 {
u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
 
-   /* Disable interrupts first */
-   local_irq_disable();
-   local_fiq_disable();
-
/* Disable the L2 if we're the last man standing. */
if (num_online_cpus() == 1)
outer_disable();
@@ -114,6 +110,15 @@ void soft_restart(unsigned long addr)
BUG();
 }
 
+void soft_restart(unsigned long addr)
+{
+   /* Disable interrupts first */
+   local_irq_disable();
+   local_fiq_disable();
+
+   soft_restart_noirq(addr);
+}
+
 static void null_restart(enum reboot_mode reboot_mode, const char *cmd)
 {
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 2/3] Fix hibernation restore hang in freeze_processes

2014-02-24 Thread Sebastian Capella
During restore, pm_notifier chain are called with
PM_RESTORE_PREPARE.  The firmware_class driver handler
fw_pm_notify does not have a handler for this.  As a result,
it keeps a reader on the kmod.c umhelper_sem.  During
freeze_processes, the call to __usermodehelper_disable tries to
take a write lock on this semaphore and hangs waiting.

Signed-off-by: Sebastian Capella 
Acked-by: Ming Lei 
Cc: Russ Dill 
Cc: Greg Kroah-Hartman 
---
 drivers/base/firmware_class.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index eb8fb94..e2b51f8 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1541,6 +1541,7 @@ static int fw_pm_notify(struct notifier_block 
*notify_block,
switch (mode) {
case PM_HIBERNATION_PREPARE:
case PM_SUSPEND_PREPARE:
+   case PM_RESTORE_PREPARE:
kill_requests_without_uevent();
device_cache_fw_images();
break;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 0/3] hibernation support on ARM

2014-02-24 Thread Sebastian Capella
Patches adding support for hibernation on ARM
  - ARM hibernation / suspend-to-disk
  - Fix hang in freeze_processes during hibernation
  - add an irq disabled version of soft_restart

Patches based on v3.13 tag, verified hibernation on beaglebone black on a branch
based on 3.13 merged with initial omap support from Russ Dill which be found 
here:
http://git.linaro.org/git-ro/people/sebastian.capella/linux.git 
hibernation_3.13_russMerge
(includes v1 patchset)

[PATCH v2 1/3] ARM: Add irq disabled version of soft_restart.

 arch/arm/include/asm/system_misc.h |1 +
 arch/arm/kernel/process.c  |   15 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

 Adds the ability to run soft restart with local_irq/fiq_disable
 Useful in hibernation code paths (unchanged from v1)

[PATCH v2 2/3] Fix hibernation restore hang in freeze_processes
 drivers/base/firmware_class.c |1 +
 1 file changed, 1 insertion(+)

 Add handling for PM_RESTORE_PREPARE notifier (unchanged from v1)

[PATCH v2 3/3] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  104 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 113 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
#116: FILE: arch/arm/kernel/hibernate.c:26:
+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
#191: FILE: arch/arm/kernel/hibernate.c:101:
+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 v2:
--
* Removed unneeded flush_thread, use of __naked and cpu_init.
* dropped Cyril Chemparathy  from Cc: list as 
  emails are bouncing.




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 3/3] ARM hibernation / suspend-to-disk

2014-02-24 Thread Sebastian Capella
From: Russ Dill 

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.

Cc: Russ Dill 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
---
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  104 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 113 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4b..1079ea8 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -291,6 +291,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 __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 #define pfn_to_kaddr(pfn)  __va((pfn) << 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 000..74bfa8b
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,104 @@
+/*
+ * 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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn =
+   __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+   unsigned long nosave_end_pfn =
+   PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+   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.
+ * After resume, the hibernation snapshot is written out.
+ */
+static int notrace __swsusp_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, __swsusp_arch_save_image);
+}
+
+/*
+ * The framework loads the hibernation image into a linked list anchored
+ * at restore_pblist, for swsusp_ar

Re: [PATCH RFC v1 3/3] ARM hibernation / suspend-to-disk

2014-02-23 Thread Sebastian Capella
Quoting Lorenzo Pieralisi (2014-02-22 04:09:10)
> On Sat, Feb 22, 2014 at 10:38:40AM +, Russell King - ARM Linux wrote:
> > On Wed, Feb 19, 2014 at 04:12:54PM +, Lorenzo Pieralisi wrote:
> > > On Wed, Feb 19, 2014 at 01:52:09AM +, Sebastian Capella wrote:
> > > > +/*
> > > > + * Snapshot kernel memory and reset the system.
> > > > + * After resume, the hibernation snapshot is written out.
> > > > + */
> > > > +static int notrace __swsusp_arch_save_image(unsigned long unused)
> > > > +{
> > > > + int ret;
> > > > +
> > > > + ret = swsusp_save();
> > > > + if (ret == 0)
> > > > + soft_restart(virt_to_phys(cpu_resume));
> > > 
> > > By the time the suspend finisher (ie this function) is run, the
> > > processor state has been saved and I think that's all you have to do,
> > > function can just return after calling swsusp_save(), unless I am missing
> > > something.
> > > 
> > > I do not understand why a soft_restart is required here. On a side note,
> > > finisher is called with irqs disabled so, since you added a function for
> > > soft restart noirq, it should be used, if needed, but I have to understand
> > > why in the first place.
> > 
> > It's required because you can't just return from the finisher.  A normal
> > return from the finisher will always be interpreted as an abort rather
> > than success (because the state has to be unwound.)
> > 
> > This is the only way to get a zero return from cpu_suspend().
> 
> Yes, that's the only reason why this code is jumping to cpu_resume, since
> all it is needed is to snapshot the CPU context and by the time the
> finisher is called that's done. Wanted to say that soft reboot is not
> useful (cache flushing and resume with MMU off), but what you are saying
> is correct. We might be saving swsusp_save return value in a global
> variable and just return from the finisher, but that's horrible and
> given the amount of time it takes to snapshot the image to disk the
> cost of this soft reboot will be dwarfed by that.
> 
> I wanted to ask and clarify why the code was written like this though, given
> its complexity.

We could also return a constant > 1.  __cpu_suspend code will replace
a 0 return with 1 for paths exiting suspend, but will not change return
values != 0.  

cpu_suspend_abort:
ldmia   sp!, {r1 - r3}  @ pop phys pgd, virt SP, phys
resume fn
teq r0, #0
moveq   r0, #1  @ force non-zero value
mov sp, r2
ldmfd   sp!, {r4 - r11, pc}

We could take advantage of that if we wanted, but Lorenzo pointed out
also that the relative benefit is very low since the cost of
resuming is >> soft_restart. 

I'll go with leaving the soft_restart as is unless someone feels
strongly against.

Thanks!

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH RFC v1 3/3] ARM hibernation / suspend-to-disk

2014-02-23 Thread Sebastian Capella
Quoting Lorenzo Pieralisi (2014-02-22 04:09:10)
> On Sat, Feb 22, 2014 at 10:38:40AM +, Russell King - ARM Linux wrote:
> > On Wed, Feb 19, 2014 at 04:12:54PM +, Lorenzo Pieralisi wrote:
> > > > + cpu_switch_mm(idmap_pgd, &init_mm);
> >
> > You need the idmap_pgd in place to call cpu_resume at it's physical
> > address.  Other page tables just won't do here.  It's well established
> > that this page table must be in place for the resume paths to work.
> 
> Well, we do not need idmap page tables for copying the restore_pblist,
> but we do need a set of tables that won't be corrupted by the copy and
> idmap does the trick (I was confused because 1:1 mappings are not needed
> for the copy itself).
> 
> The switch to idmap is done for us in soft_reboot anyway before jumping to
> cpu_resume and that's required, as you said.

Ok, so I'll leave the cpu_switch_mm as is for the next patchset.

Thanks Lorenzo, Russ and Russell!

Sebastian


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC v1 2/3] Fix hibernation restore hang in freeze_processes

2014-02-18 Thread Sebastian Capella
During restore, pm_notifier chain are called with
PM_RESTORE_PREPARE.  The firmware_class driver handler
fw_pm_notify does not have a handler for this.  As a result,
it keeps a reader on the kmod.c umhelper_sem.  During
freeze_processes, the call to __usermodehelper_disable tries to
take a write lock on this semaphore and hangs waiting.

Signed-off-by: Sebastian Capella 
Cc: Russ Dill 
Cc: Ming Lei 
Cc: Greg Kroah-Hartman 
---
 drivers/base/firmware_class.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index eb8fb94..e2b51f8 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1541,6 +1541,7 @@ static int fw_pm_notify(struct notifier_block 
*notify_block,
switch (mode) {
case PM_HIBERNATION_PREPARE:
case PM_SUSPEND_PREPARE:
+   case PM_RESTORE_PREPARE:
kill_requests_without_uevent();
device_cache_fw_images();
break;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC v1 3/3] ARM hibernation / suspend-to-disk

2014-02-18 Thread Sebastian Capella
From: Russ Dill 

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.

Cc: Russ Dill 
Cc: "Rafael J. Wysocki" 
Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: Nicolas Pitre 
Cc: Santosh Shilimkar 
Cc: Will Deacon 
Cc: Cyril Chemparathy 
Cc: Jonathan Austin 
Cc: Catalin Marinas 
Cc: "Uwe Kleine-König" 
Cc: Stephen Boyd 
---
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  106 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 115 insertions(+)
 create mode 100644 arch/arm/kernel/hibernate.c

diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 8756e4b..1079ea8 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -291,6 +291,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 __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0))
 #define pfn_to_kaddr(pfn)  __va((pfn) << 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 000..16f406f
--- /dev/null
+++ b/arch/arm/kernel/hibernate.c
@@ -0,0 +1,106 @@
+/*
+ * 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 
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+extern const void __nosave_begin, __nosave_end;
+
+int pfn_is_nosave(unsigned long pfn)
+{
+   unsigned long nosave_begin_pfn =
+   __pa_symbol(&__nosave_begin) >> PAGE_SHIFT;
+   unsigned long nosave_end_pfn =
+   PAGE_ALIGN(__pa_symbol(&__nosave_end)) >> PAGE_SHIFT;
+
+   return (pfn >= nosave_begin_pfn) && (pfn < nosave_end_pfn);
+}
+
+void notrace save_processor_state(void)
+{
+   WARN_ON(num_online_cpus() != 1);
+   flush_thread();
+   local_fiq_disable();
+}
+
+void notrace restore_processor_state(void)
+{
+   local_fiq_enable();
+}
+
+/*
+ * Snapshot kernel memory and reset the system.
+ * After resume, the hibernation snapshot is written out.
+ */
+static int notrace __swsusp_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, __swsusp_arch_save_image);
+}
+
+/*
+ * The framework loads the hibernation image into a linked lis

[PATCH RFC v1 1/3] ARM: Add irq disabled version of soft_restart.

2014-02-18 Thread Sebastian Capella
From: Russ Dill 

This adds the ability to run soft_restart with local_irq/fiq_disable
already called. This is helpful for the hibernation code paths.

Signed-off-by: Russ Dill 
Signed-off-by: Sebastian Capella 
Cc: Russell King 
Cc: Andrew Morton 
Cc: Thomas Gleixner 
Cc: Will Deacon 
Cc: Robin Holt 
---
 arch/arm/include/asm/system_misc.h |1 +
 arch/arm/kernel/process.c  |   15 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/arch/arm/include/asm/system_misc.h 
b/arch/arm/include/asm/system_misc.h
index a3d61ad..eca8dd4 100644
--- a/arch/arm/include/asm/system_misc.h
+++ b/arch/arm/include/asm/system_misc.h
@@ -10,6 +10,7 @@
 
 extern void cpu_init(void);
 
+void soft_restart_noirq(unsigned long);
 void soft_restart(unsigned long);
 extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd);
 extern void (*arm_pm_idle)(void);
diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
index 92f7b15..685bc4a 100644
--- a/arch/arm/kernel/process.c
+++ b/arch/arm/kernel/process.c
@@ -95,14 +95,10 @@ static void __soft_restart(void *addr)
BUG();
 }
 
-void soft_restart(unsigned long addr)
+void soft_restart_noirq(unsigned long addr)
 {
u64 *stack = soft_restart_stack + ARRAY_SIZE(soft_restart_stack);
 
-   /* Disable interrupts first */
-   local_irq_disable();
-   local_fiq_disable();
-
/* Disable the L2 if we're the last man standing. */
if (num_online_cpus() == 1)
outer_disable();
@@ -114,6 +110,15 @@ void soft_restart(unsigned long addr)
BUG();
 }
 
+void soft_restart(unsigned long addr)
+{
+   /* Disable interrupts first */
+   local_irq_disable();
+   local_fiq_disable();
+
+   soft_restart_noirq(addr);
+}
+
 static void null_restart(enum reboot_mode reboot_mode, const char *cmd)
 {
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC v1 0/3] hibernation support on ARM

2014-02-18 Thread Sebastian Capella
Patches adding support for hibernation on ARM
  - ARM hibernation / suspend-to-disk
  - Fix hang in freeze_processes during hibernation
  - add an irq disabled version of soft_restart

Patches based on v3.13 tag, verified hibernation on beaglebone black on a branch
based on 3.13 merged with initial omap support from Russ Dill which be found 
here:
http://git.linaro.org/git-ro/people/sebastian.capella/linux.git 
hibernation_3.13_russMerge

[PATCH RFC v1 1/3] ARM: Add irq disabled version of soft_restart.
 arch/arm/include/asm/system_misc.h |1 +
 arch/arm/kernel/process.c  |   15 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

 Adds the ability to run soft restart with local_irq/fiq_disable
 Useful in hibernation code paths

[PATCH RFC v1 2/3] Fix hibernation restore hang in freeze_processes
 drivers/base/firmware_class.c |1 +
 1 file changed, 1 insertion(+)

 Add handling for PM_RESTORE_PREPARE notifier

[PATCH RFC v1 3/3] ARM hibernation / suspend-to-disk
 arch/arm/include/asm/memory.h |1 +
 arch/arm/kernel/Makefile  |1 +
 arch/arm/kernel/hibernate.c   |  106 +
 arch/arm/mm/Kconfig   |5 ++
 include/linux/suspend.h   |2 +
 5 files changed, 115 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
#116: FILE: arch/arm/kernel/hibernate.c:26:
+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
#191: FILE: arch/arm/kernel/hibernate.c:101:
+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





--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [v2] backlight: Convert from Legacy pm ops to dev_pm_ops

2014-02-18 Thread sebastian . capella
Shuah Khan  wrote:

> Convert drivers/video/backlight/class to use dev_pm_ops for power
> management and remove Legacy PM ops hooks. With this change, rtc class
> registers suspend/resume callbacks via class->pm (dev_pm_ops) instead of
> Legacy class->suspend/resume. When __device_suspend() runs call-backs,
> it will find class->pm ops for the backlight class.
>
> Signed-off-by: Shuah Khan 
> Cc: Shuah Khan 
>
> ---
> v2: Updated changelog to correct device class.
>
>  drivers/video/backlight/backlight.c |8 +---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/video/backlight/backlight.c 
> b/drivers/video/backlight/backlight.c
> index c74e7aa..0ffb251 100644
> --- a/drivers/video/backlight/backlight.c
> +++ b/drivers/video/backlight/backlight.c
> @@ -208,7 +208,7 @@ static ssize_t backlight_show_actual_brightness(struct 
> device *dev,
>  
>  static struct class *backlight_class;
>  
> -static int backlight_suspend(struct device *dev, pm_message_t state)
> +static int backlight_suspend(struct device *dev)
>  {
>   struct backlight_device *bd = to_backlight_device(dev);
>  
> @@ -236,6 +236,9 @@ static int backlight_resume(struct device *dev)
>   return 0;
>  }
>  
> +static SIMPLE_DEV_PM_OPS(backlight_class_dev_pm_ops, backlight_suspend,
> +  backlight_resume);
> +
>  static void bl_device_release(struct device *dev)
>  {
>   struct backlight_device *bd = to_backlight_device(dev);
> @@ -414,8 +417,7 @@ static int __init backlight_class_init(void)
>   }
>  
>   backlight_class->dev_attrs = bl_device_attributes;
> - backlight_class->suspend = backlight_suspend;
> - backlight_class->resume = backlight_resume;
> + backlight_class->pm = &backlight_class_dev_pm_ops;
>   return 0;
>  }
>  --
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v9] PM / Hibernate: use name_to_dev_t to parse resume

2014-02-14 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 0121dab..a5f702a 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -972,16 +972,20 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
+   int len = n;
+   char *name;
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (len && buf[len-1] == '\n')
+   len--;
+   name = kstrndup(buf, len, GFP_KERNEL);
+   if (!name)
+   return -ENOMEM;
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(name);
+   kfree(name);
+   if (!res)
+   return -EINVAL;
 
lock_system_sleep();
swsusp_resume_device = res;
@@ -989,9 +993,7 @@ static ssize_t resume_store(struct kobject *kobj, struct 
kobj_attribute *attr,
printk(KERN_INFO "PM: Starting manual resume from disk\n");
noresume = 0;
software_resume();
-   ret = n;
- out:
-   return ret;
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v9 0/1] hibernation related patches

2014-02-14 Thread Sebastian Capella
Patchset related to hibernation resume:
  - enhancement to make the use of an existing resume file more general

  Patch is based on the 3.13 tag.  This was tested on a Beaglebone black
  with partial hibernation support, also compiled for x86_64.

[PATCH v9 1/1] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   22 --
  1 file changed, 12 insertions(+), 10 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v9:
--
* Dropped util changes based on feedback
* Reverted to handling newlines in resume_store

Changes in v8:
--
* Dropped cleanup checkpatch warnings in hibernate.c file
* Review comments for more compact checking in hibernate.c

Changes in v7:
--
* Switch to trim only one trailing newline if present using kstrdup_trimnl
* remove kstrimdup patch
* add kstrdup_trimnl patch
* Add clean up patch for kernel/power/hibernate.c checkpatch warnings

Changes in v6:
--
* Revert tricky / confusing while loop indexing

Changes in v5:
--
* Change kstrimdup to minimize allocated memory.  Now allocates only
  the memory needed for the string instead of using strim.

Changes in v4:
--
* Dropped name_to_dev_t rework in favor of adding kstrimdup
* adjusted resume_store

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v9] PM / Hibernate: use name_to_dev_t to parse resume

2014-02-14 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 0121dab..a5f702a 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -972,16 +972,20 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
+   int len = n;
+   char *name;
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (len && buf[len-1] == '\n')
+   len--;
+   name = kstrndup(buf, len, GFP_KERNEL);
+   if (!name)
+   return -ENOMEM;
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(name);
+   kfree(name);
+   if (!res)
+   return -EINVAL;
 
lock_system_sleep();
swsusp_resume_device = res;
@@ -989,9 +993,7 @@ static ssize_t resume_store(struct kobject *kobj, struct 
kobj_attribute *attr,
printk(KERN_INFO "PM: Starting manual resume from disk\n");
noresume = 0;
software_resume();
-   ret = n;
- out:
-   return ret;
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v9 0/1] hibernation related patches

2014-02-14 Thread Sebastian Capella
Patchset related to hibernation resume:
  - enhancement to make the use of an existing resume file more general

  Patch is based on the 3.13 tag.  This was tested on a Beaglebone black
  with partial hibernation support, also compiled for x86_64.

[PATCH v9 1/1] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   22 --
  1 file changed, 12 insertions(+), 10 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v9:
--
* Dropped util changes based on feedback
* Reverted to special newline handling in resume_store

Changes in v8:
--
* Dropped cleanup checkpatch warnings in hibernate.c file
* Review comments for more compact checking in hibernate.c

Changes in v7:
--
* Switch to trim only one trailing newline if present using kstrdup_trimnl
* remove kstrimdup patch
* add kstrdup_trimnl patch
* Add clean up patch for kernel/power/hibernate.c checkpatch warnings

Changes in v6:
--
* Revert tricky / confusing while loop indexing

Changes in v5:
--
* Change kstrimdup to minimize allocated memory.  Now allocates only
  the memory needed for the string instead of using strim.

Changes in v4:
--
* Dropped name_to_dev_t rework in favor of adding kstrimdup
* adjusted resume_store

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7 0/3] hibernation related patches

2014-02-04 Thread Sebastian Capella
Patchset related to hibernation resume:
  - enhancement to make the use of an existing resume file more general
  - add kstrdup_trimnl function which duplicates and trims a single
trailing newline off of a string
  - cleanup checkpatch warnings in hibernate.c file

  All patches are based on the 3.13 tag.  This was tested on a
  Beaglebone black with partial hibernation support, and compiled for
  x86_64.

[PATCH v7 1/3] mm: add kstrdup_trimnl function
  include/linux/string.h |1 +
  mm/util.c  |   29 +
  2 files changed, 30 insertions(+)

  Adds the kstrdup_trimnl function to duplicate and trim
  at most one trailing newline from a string.
  This is useful for working with user input to sysfs.

[PATCH v7 2/3] trivial: PM / Hibernate: clean up checkpatch in
  kernel/power/hibernate.c |   62 --
  1 file changed, 32 insertions(+), 30 deletions(-)

  Cleanup checkpatch warnings in kernel/power/hibernate.c

[PATCH v7 3/3] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   33 +
  1 file changed, 17 insertions(+), 16 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.


Changes in v7:
--
* Switch to trim only one trailing newline if present using kstrdup_trimnl
* remove kstrimdup patch
* add kstrdup_trimnl patch
* Add clean up patch for kernel/power/hibernate.c checkpatch warnings

Changes in v6:
--
* Revert tricky / confusing while loop indexing

Changes in v5:
--
* Change kstrimdup to minimize allocated memory.  Now allocates only
  the memory needed for the string instead of using strim.

Changes in v4:
--
* Dropped name_to_dev_t rework in favor of adding kstrimdup
* adjusted resume_store

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7 3/3] PM / Hibernate: use name_to_dev_t to parse resume

2014-02-04 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Cc: Pavel Machek 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index cd1e30c..3abd192 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -970,26 +970,27 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
+   char *name = kstrdup_trimnl(buf, GFP_KERNEL);
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (name == NULL)
+   return -ENOMEM;
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(name);
 
-   lock_system_sleep();
-   swsusp_resume_device = res;
-   unlock_system_sleep();
-   pr_info("PM: Starting manual resume from disk\n");
-   noresume = 0;
-   software_resume();
-   ret = n;
- out:
-   return ret;
+   if (res != 0) {
+   lock_system_sleep();
+   swsusp_resume_device = res;
+   unlock_system_sleep();
+   pr_info("PM: Starting manual resume from disk\n");
+   noresume = 0;
+   software_resume();
+   } else {
+   n = -EINVAL;
+   }
+
+   kfree(name);
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v7 2/3] trivial: PM / Hibernate: clean up checkpatch in hibernate.c

2014-02-04 Thread Sebastian Capella
Checkpatch reports several warnings in hibernate.c
printk use removed, long lines wrapped, whitespace cleanup,
extend short msleeps, while loops on two lines.

Signed-off-by: Sebastian Capella 
Cc: Pavel Machek 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   62 --
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 0121dab..cd1e30c 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -94,7 +94,7 @@ EXPORT_SYMBOL(system_entering_hibernation);
 #ifdef CONFIG_PM_DEBUG
 static void hibernation_debug_sleep(void)
 {
-   printk(KERN_INFO "hibernation debug: Waiting for 5 seconds.\n");
+   pr_info("hibernation debug: Waiting for 5 seconds.\n");
mdelay(5000);
 }
 
@@ -239,7 +239,7 @@ void swsusp_show_speed(struct timeval *start, struct 
timeval *stop,
centisecs = 1;  /* avoid div-by-zero */
k = nr_pages * (PAGE_SIZE / 1024);
kps = (k * 100) / centisecs;
-   printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
+   pr_info("PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
msg, k,
centisecs / 100, centisecs % 100,
kps / 1000, (kps % 1000) / 10);
@@ -260,8 +260,7 @@ static int create_image(int platform_mode)
 
error = dpm_suspend_end(PMSG_FREEZE);
if (error) {
-   printk(KERN_ERR "PM: Some devices failed to power down, "
-   "aborting hibernation\n");
+   pr_err("PM: Some devices failed to power down, aborting 
hibernation\n");
return error;
}
 
@@ -277,8 +276,7 @@ static int create_image(int platform_mode)
 
error = syscore_suspend();
if (error) {
-   printk(KERN_ERR "PM: Some system devices failed to power down, "
-   "aborting hibernation\n");
+   pr_err("PM: Some system devices failed to power down, aborting 
hibernation\n");
goto Enable_irqs;
}
 
@@ -289,8 +287,7 @@ static int create_image(int platform_mode)
save_processor_state();
error = swsusp_arch_suspend();
if (error)
-   printk(KERN_ERR "PM: Error %d creating hibernation image\n",
-   error);
+   pr_err("PM: Error %d creating hibernation image\n", error);
/* Restore control flow magically appears here */
restore_processor_state();
if (!in_suspend) {
@@ -413,8 +410,7 @@ static int resume_target_kernel(bool platform_mode)
 
error = dpm_suspend_end(PMSG_QUIESCE);
if (error) {
-   printk(KERN_ERR "PM: Some devices failed to power down, "
-   "aborting resume\n");
+   pr_err("PM: Some devices failed to power down, aborting 
resume\n");
return error;
}
 
@@ -550,7 +546,8 @@ int hibernation_platform_enter(void)
 
hibernation_ops->enter();
/* We should never get here */
-   while (1);
+   while (1)
+   ;
 
  Power_up:
syscore_resume();
@@ -611,8 +608,7 @@ static void power_down(void)
 */
error = swsusp_unmark();
if (error)
-   printk(KERN_ERR "PM: Swap will be unusable! "
-   "Try swapon -a.\n");
+   pr_err("PM: Swap will be unusable! Try swapon -a.\n");
return;
 #endif
}
@@ -621,8 +617,9 @@ static void power_down(void)
 * Valid image is on the disk, if we continue we risk serious data
 * corruption after resume.
 */
-   printk(KERN_CRIT "PM: Please power down manually\n");
-   while(1);
+   pr_crit("PM: Please power down manually\n");
+   while (1)
+   ;
 }
 
 /**
@@ -644,9 +641,9 @@ int hibernate(void)
if (error)
goto Exit;
 
-   printk(KERN_INFO "PM: Syncing filesystems ... ");
+   pr_info("PM: Syncing filesystems ... ");
sys_sync();
-   printk("done.\n");
+   pr_cont("done.\n");
 
error = freeze_processes();
if (error)
@@ -670,7 +667,7 @@ int hibernate(void)
if (nocompress)
flags |= SF_NOCOMPRESS_MODE;
else
-   flags |= SF_CRC32_MODE;
+   flags |= SF_CRC32_MODE;
 
pr_debug("PM: writing image.\n");
error = swsusp_write(flags);
@@ -750,7 +747,7 @@ static int software_resume(void)
pr_debug("PM: Checking hiberna

[PATCH v7 1/3] mm: add kstrdup_trimnl function

2014-02-04 Thread Sebastian Capella
kstrdup_trimnl creates a duplicate of the passed in
null-terminated string.  If a trailing newline is found, it
is removed before duplicating.  This is useful for strings
coming from sysfs that often include trailing whitespace due to
user input.

Signed-off-by: Sebastian Capella 
Cc: Andrew Morton 
Cc: Rik van Riel  (commit_signer:5/10=50%)
Cc: Michel Lespinasse 
Cc: Shaohua Li 
Cc: Jerome Marchand 
Cc: Mikulas Patocka 
Cc: Joonsoo Kim 
Cc: Joe Perches 
Cc: David Rientjes 
Cc: Alexey Dobriyan 
---
 include/linux/string.h |1 +
 mm/util.c  |   29 +
 2 files changed, 30 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index ac889c5..e7ec8c0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, size_t n);
 
 extern char *kstrdup(const char *s, gfp_t gfp);
 extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
+extern char *kstrdup_trimnl(const char *s, gfp_t gfp);
 extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
 
 extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
diff --git a/mm/util.c b/mm/util.c
index 808f375..0bab867 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1,6 +1,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -63,6 +64,34 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp)
 EXPORT_SYMBOL(kstrndup);
 
 /**
+ * kstrdup_trimnl - Copy a %NUL terminated string, removing one trailing
+ * newline if present.
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ *
+ * Returns an address, which the caller must kfree, containing
+ * a duplicate of the passed string with a single trailing newline
+ * removed if present.
+ */
+char *kstrdup_trimnl(const char *s, gfp_t gfp)
+{
+   char *buf;
+   size_t len = strlen(s);
+   if (len >= 1 && s[len - 1] == '\n')
+   len--;
+
+   buf = kmalloc_track_caller(len + 1, gfp);
+   if (!buf)
+   return NULL;
+
+   memcpy(buf, s, len);
+   buf[len] = '\0';
+
+   return buf;
+}
+EXPORT_SYMBOL(kstrdup_trimnl);
+
+/**
  * kmemdup - duplicate region of memory
  *
  * @src: memory region to duplicate
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: + mm-utilc-add-kstrimdup.patch added to -mm tree

2014-02-03 Thread Sebastian Capella
Quoting David Rientjes (2014-02-03 17:05:04)
> The last we heard, I think Sebastian is looking to redo this series and 
> this patch is no longer needed.  Sebastian?
Hi David, Alexey,

I am in the process of reworking the patches.  I'm not sure if Andrew
was just interested in having the kstrimdup utility function available.

Isn't it too late to impose userspace trimming of newlines for sysfs?
It seems already fairly common and expected for the kernel to eat the
trailing whitespace, or at least ignore it.  If we change this won't we
be breaking userspace / tools / instructions / etc?

I'll try to post the new patches soon.

Thanks,

Sebastian

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 1/2] mm: add kstrimdup function

2014-01-31 Thread Sebastian Capella
Quoting Pavel Machek (2014-01-31 04:24:21)
> Well, your /sys/power/resume patch would be nice cleanup, but it
> changs behaviour, too... which is unnice. Stripping trailing "\n" is
> probably neccessary, because we did it before. (It probably was a
> mistake). But kernel is not right place to second-guess what the user
> meant. Just return -EINVAL. This is kernel ABI, after all, not user
> facing shell.

Thanks guys!  I hadn't thought of these cases.

It sounds like we're really back to stripping one trailing \n to match
the sysfs behavior to which people have become accustomed, and leave
the rest of the string untouched in case the whitespace is intentional.

Should a user intentionally have input ending in a newline, then they
should add an additional newline, expecting it to be stripped, but
otherwise, their string is taken as entered.

Does this sound right?

Meanwhile, I'll try a test to see how name_to_dev_t handles files with
spaces in them.

Thanks,

Sebastian

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 1/2] mm: add kstrimdup function

2014-01-30 Thread Sebastian Capella
kstrimdup creates a whitespace-trimmed duplicate of the passed
in null-terminated string.  This is useful for strings coming
from sysfs that often include trailing whitespace due to user
input.

Thanks to Joe Perches for this implementation.

Signed-off-by: Sebastian Capella 
Cc: Andrew Morton 
Cc: Joe Perches 
Cc: Mikulas Patocka 
Cc: David Rientjes 
Cc: Rik van Riel  (commit_signer:5/10=50%)
Cc: Michel Lespinasse 
Cc: Shaohua Li 
Cc: Jerome Marchand 
Cc: Mikulas Patocka 
Cc: Joonsoo Kim 
---
 include/linux/string.h |1 +
 mm/util.c  |   30 ++
 2 files changed, 31 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index ac889c5..f29f9a0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, size_t n);
 
 extern char *kstrdup(const char *s, gfp_t gfp);
 extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
+extern char *kstrimdup(const char *s, gfp_t gfp);
 extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
 
 extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
diff --git a/mm/util.c b/mm/util.c
index 808f375..a8b731c 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1,6 +1,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -63,6 +64,35 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp)
 EXPORT_SYMBOL(kstrndup);
 
 /**
+ * kstrimdup - Trim and copy a %NUL terminated string.
+ * @s: the string to trim and duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ *
+ * Returns an address, which the caller must kfree, containing
+ * a duplicate of the passed string with leading and/or trailing
+ * whitespace (as defined by isspace) removed.
+ */
+char *kstrimdup(const char *s, gfp_t gfp)
+{
+   char *buf;
+   char *begin = skip_spaces(s);
+   size_t len = strlen(begin);
+
+   while (len && isspace(begin[len - 1]))
+   len--;
+
+   buf = kmalloc_track_caller(len + 1, gfp);
+   if (!buf)
+   return NULL;
+
+   memcpy(buf, begin, len);
+   buf[len] = '\0';
+
+   return buf;
+}
+EXPORT_SYMBOL(kstrimdup);
+
+/**
  * kmemdup - duplicate region of memory
  *
  * @src: memory region to duplicate
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 0/2] hibernation related patches

2014-01-30 Thread Sebastian Capella
Patchset related to hibernation resume:
  - enhancement to make the use of an existing resume file more general
  - add kstrimdup function which trims and duplicates a string

  Both patches are based on the 3.13 tag.  This was tested on a
  Beaglebone black with partial hibernation support, and compiled for
  x86_64.

[PATCH v6 1/2] mm: add kstrimdup function
  include/linux/string.h |1 +
  mm/util.c  |   30 ++
  2 files changed, 31 insertions(+)

  Adds the kstrimdup function to duplicate and trim whitespace
  from a string.  This is useful for working with user input to
  sysfs.

[PATCH v6 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   33 +
  1 file changed, 17 insertions(+), 16 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v6:
--
* Revert tricky / confusing while loop indexing

Changes in v5:
--
* Change kstrimdup to minimize allocated memory.  Now allocates only
  the memory needed for the string instead of using strim.

Changes in v4:
--
* Dropped name_to_dev_t rework in favor of adding kstrimdup
* adjusted resume_store

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 2/2] PM / Hibernate: use name_to_dev_t to parse resume

2014-01-30 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Acked-by: Pavel Machek 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 0121dab..49d7a37 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -972,26 +972,27 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
+   char *name = kstrimdup(buf, GFP_KERNEL);
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (name == NULL)
+   return -ENOMEM;
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(name);
 
-   lock_system_sleep();
-   swsusp_resume_device = res;
-   unlock_system_sleep();
-   printk(KERN_INFO "PM: Starting manual resume from disk\n");
-   noresume = 0;
-   software_resume();
-   ret = n;
- out:
-   return ret;
+   if (res != 0) {
+   lock_system_sleep();
+   swsusp_resume_device = res;
+   unlock_system_sleep();
+   printk(KERN_INFO "PM: Starting manual resume from disk\n");
+   noresume = 0;
+   software_resume();
+   } else {
+   n = -EINVAL;
+   }
+
+   kfree(name);
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[no subject]

2014-01-30 Thread Sebastian Capella
Patchset related to hibernation resume:
  - enhancement to make the use of an existing resume file more general
  - add kstrimdup function which trims and duplicates a string

  Both patches are based on the 3.13 tag.  This was tested on a
  Beaglebone black with partial hibernation support, and compiled for
  x86_64.

[PATCH v5 1/2] mm: add kstrimdup function
  include/linux/string.h |1 +
  mm/util.c  |   30 ++
  2 files changed, 31 insertions(+)

  Adds the kstrimdup function to duplicate and trim whitespace
  from a string.  This is useful for working with user input to
  sysfs.

[PATCH v5 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   33
  +
  1 file changed, 17 insertions(+), 16 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v5:
--
* Change kstrimdup to minimize allocated memory.  Now allocates only
  the memory needed for the string instead of using strim.

Changes in v4:
--
* Dropped name_to_dev_t rework in favor of adding kstrimdup
* adjusted resume_store

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 1/2] mm: add kstrimdup function

2014-01-30 Thread Sebastian Capella
kstrimdup will duplicate and trim spaces from the passed in
null terminated string.  This is useful for strings coming from
sysfs that often include trailing whitespace due to user input.

Signed-off-by: Sebastian Capella 
Cc: Andrew Morton 
Cc: Joe Perches 
Cc: Mikulas Patocka 
Cc: Rik van Riel  (commit_signer:5/10=50%)
Cc: Michel Lespinasse 
Cc: Shaohua Li 
Cc: Jerome Marchand 
Cc: Mikulas Patocka 
Cc: Joonsoo Kim 
---
 include/linux/string.h |1 +
 mm/util.c  |   30 ++
 2 files changed, 31 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index ac889c5..f29f9a0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, size_t n);
 
 extern char *kstrdup(const char *s, gfp_t gfp);
 extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
+extern char *kstrimdup(const char *s, gfp_t gfp);
 extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
 
 extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
diff --git a/mm/util.c b/mm/util.c
index 808f375..2066b33 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1,6 +1,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -63,6 +64,35 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp)
 EXPORT_SYMBOL(kstrndup);
 
 /**
+ * kstrimdup - Trim and copy a %NUL terminated string.
+ * @s: the string to trim and duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ *
+ * Returns an address, which the caller must kfree, containing
+ * a duplicate of the passed string with leading and/or trailing
+ * whitespace (as defined by isspace) removed.
+ */
+char *kstrimdup(const char *s, gfp_t gfp)
+{
+   char *buf;
+   char *begin = skip_spaces(s);
+   size_t len = strlen(begin);
+
+   while (len > 1 && isspace(begin[len - 1]))
+   len--;
+
+   buf = kmalloc_track_caller(len + 1, gfp);
+   if (!buf)
+   return NULL;
+
+   memcpy(buf, begin, len);
+   buf[len] = '\0';
+
+   return buf;
+}
+EXPORT_SYMBOL(kstrimdup);
+
+/**
  * kmemdup - duplicate region of memory
  *
  * @src: memory region to duplicate
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v5 2/2] PM / Hibernate: use name_to_dev_t to parse resume

2014-01-30 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Acked-by: Pavel Machek 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 0121dab..49d7a37 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -972,26 +972,27 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
+   char *name = kstrimdup(buf, GFP_KERNEL);
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (name == NULL)
+   return -ENOMEM;
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(name);
 
-   lock_system_sleep();
-   swsusp_resume_device = res;
-   unlock_system_sleep();
-   printk(KERN_INFO "PM: Starting manual resume from disk\n");
-   noresume = 0;
-   software_resume();
-   ret = n;
- out:
-   return ret;
+   if (res != 0) {
+   lock_system_sleep();
+   swsusp_resume_device = res;
+   unlock_system_sleep();
+   printk(KERN_INFO "PM: Starting manual resume from disk\n");
+   noresume = 0;
+   software_resume();
+   } else {
+   n = -EINVAL;
+   }
+
+   kfree(name);
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v4 1/2] mm: add kstrimdup function

2014-01-29 Thread Sebastian Capella
Quoting Joe Perches (2014-01-29 17:24:28)
> Why not minimize the malloc length too?
> 
> maybe something like:
> 
> char *kstrimdup(const char *s, gfp_t gfp)
> {
> char *buf;
> const char *begin = skip_spaces(s);
> size_t len = strlen(begin);
> 
> while (len && isspace(begin[len - 1]))
> len--;
> 
> buf = kmalloc_track_caller(len + 1, gfp);
> if (!buf)
> return NULL;
> 
> memcpy(buf, begin, len);
> buf[len] = 0;
> 
> return buf;
> }

I figured it would be mostly for small trimming, but it seems like
it could be and advantage and used more generally this way.

I have a couple of small changes to return NULL in empty string/all ws
cases and fix a buffer underrun.

How does this look?

Thanks,

Sebastian


char *kstrimdup(const char *s, gfp_t gfp)
{   
 
char *buf;  
 
const char *begin = skip_spaces(s); 
 
size_t len = strlen(begin); 
 

if (len == 0)   
 
return NULL;
 

 
while (len > 1 && isspace(begin[len - 1]))  
 
len--;  
 

 
buf = kmalloc_track_caller(len + 1, gfp);   
 
if (!buf)   
 
return NULL;
 

 
memcpy(buf, begin, len);
 
buf[len] = '\0';


 
return buf; 
 
}



--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume

2014-01-29 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Cc: Pavel Machek 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 37170d4..b4a3e0b 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -973,26 +973,27 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
+   char *name = kstrimdup(buf, GFP_KERNEL);
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (name == NULL)
+   return -ENOMEM;
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(name);
 
-   lock_system_sleep();
-   swsusp_resume_device = res;
-   unlock_system_sleep();
-   printk(KERN_INFO "PM: Starting manual resume from disk\n");
-   noresume = 0;
-   software_resume();
-   ret = n;
- out:
-   return ret;
+   if (res != 0) {
+   lock_system_sleep();
+   swsusp_resume_device = res;
+   unlock_system_sleep();
+   printk(KERN_INFO "PM: Starting manual resume from disk\n");
+   noresume = 0;
+   software_resume();
+   } else {
+   n = -EINVAL;
+   }
+
+   kfree(name);
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 1/2] mm: add kstrimdup function

2014-01-29 Thread Sebastian Capella
kstrimdup will duplicate and trim spaces from the passed in
null terminated string.  This is useful for strings coming from
sysfs that often include trailing whitespace due to user input.

Signed-off-by: Sebastian Capella 
Cc: Andrew Morton 
Cc: Rik van Riel  (commit_signer:5/10=50%)
Cc: Michel Lespinasse 
Cc: Shaohua Li 
Cc: Jerome Marchand 
Cc: Mikulas Patocka 
Cc: Joonsoo Kim 
---
 include/linux/string.h |1 +
 mm/util.c  |   19 +++
 2 files changed, 20 insertions(+)

diff --git a/include/linux/string.h b/include/linux/string.h
index ac889c5..f29f9a0 100644
--- a/include/linux/string.h
+++ b/include/linux/string.h
@@ -114,6 +114,7 @@ void *memchr_inv(const void *s, int c, size_t n);
 
 extern char *kstrdup(const char *s, gfp_t gfp);
 extern char *kstrndup(const char *s, size_t len, gfp_t gfp);
+extern char *kstrimdup(const char *s, gfp_t gfp);
 extern void *kmemdup(const void *src, size_t len, gfp_t gfp);
 
 extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
diff --git a/mm/util.c b/mm/util.c
index a24aa22..da17de5 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -63,6 +63,25 @@ char *kstrndup(const char *s, size_t max, gfp_t gfp)
 EXPORT_SYMBOL(kstrndup);
 
 /**
+ * kstrimdup - Trim and copy a %NUL terminated string.
+ * @s: the string to trim and duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ *
+ * Returns an address, which the caller must kfree, containing
+ * a duplicate of the passed string with leading and/or trailing
+ * whitespace (as defined by isspace) removed.
+ */
+char *kstrimdup(const char *s, gfp_t gfp)
+{
+   char *ret = kstrdup(skip_spaces(s), gfp);
+
+   if (ret)
+   strim(ret);
+   return ret;
+}
+EXPORT_SYMBOL(kstrimdup);
+
+/**
  * kmemdup - duplicate region of memory
  *
  * @src: memory region to duplicate
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v4 0/2] PM / Hibernate: sysfs resume

2014-01-29 Thread Sebastian Capella
Patchset related to hibernation resume:
  - enhancement to make the use of an existing resume file more general
  - add kstrimdup function which trims and duplicates a string

  Both patches are based on the 3.13 tag.  This was tested on a
  Beaglebone black with partial hibernation support, and compiled for
  x86_64.

[PATCH v4 1/2] mm: add kstrimdup function
  include/linux/string.h |1 +
  mm/util.c  |   19 +++
  2 files changed, 20 insertions(+)

  Adds the kstrimdup function to duplicate and trim whitespace
  from a string.  This is useful for working with user input to
  sysfs.

[PATCH v4 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   33
  +
  1 file changed, 17 insertions(+), 16 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v4:
--
* Dropped name_to_dev_t rework in favor of adding kstrimdup
* adjusted resume_store

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 4/4] PM / devfreq: Consider hibernation in pm notifier

2013-11-19 Thread Sebastian Capella
Quoting Bartlomiej Zolnierkiewicz (2013-11-19 06:50:05)
> Hi,
> 
> Are you planning to add hibernation support to ARM?
> 
> If so then this should be stated somewhere in the patch description.
> 
> OTOH if you are not going to add hibernation support to ARM I see
> a little sense in adding hibernation support to ARM-only drivers..

FYI, we at Linaro and a few others have been working on adding
hibernation support for ARM.  I have not coordinated with Jonghwan
however.

Apoligies for the earlier toppost.

Thanks,

Sebastian Capella
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t

2013-10-03 Thread Sebastian Capella
Enhance name_to_dev_t to handle trailing newline characters
on device paths.  Some inputs to name_to_dev_t may come from
userspace where oftentimes a '\n' is appended to the path.
Added const to the name buffer in both the function
declaration and the prototype to reflect input buffer
handling.

By handling trailing newlines in name_to_dev_t, userspace
buffers may be directly passed to name_to_dev_t without
modification.

Signed-off-by: Sebastian Capella 
Reviewed-by: Pavel Machek 
Cc: "Eric W. Biederman" 
Cc: Serge Hallyn 
Cc: Andrew Morton 
Cc: Stephen Warren 
Cc: Jens Axboe 
Cc: Greg Kroah-Hartman 
Cc: Al Viro 
---
 include/linux/mount.h |2 +-
 init/do_mounts.c  |   25 +++--
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/include/linux/mount.h b/include/linux/mount.h
index 38cd98f..fdbb3e6 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -77,6 +77,6 @@ extern struct vfsmount *vfs_kern_mount(struct 
file_system_type *type,
 extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head 
*expiry_list);
 extern void mark_mounts_for_expiry(struct list_head *mounts);
 
-extern dev_t name_to_dev_t(char *name);
+extern dev_t name_to_dev_t(const char *name);
 
 #endif /* _LINUX_MOUNT_H */
diff --git a/init/do_mounts.c b/init/do_mounts.c
index a51cddc..69d74ff 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -145,6 +145,13 @@ static dev_t devt_from_partuuid(const char *uuid_str)
clear_root_wait = true;
goto done;
}
+   if (uuid_str[cmp.len - 1] == '\n') {
+   cmp.len--;
+   if (!cmp.len) {
+   clear_root_wait = true;
+   goto done;
+   }
+   }
 
dev = class_find_device(&block_class, NULL, &cmp,
&match_dev_by_uuid);
@@ -204,12 +211,13 @@ done:
  * bangs.
  */
 
-dev_t name_to_dev_t(char *name)
+dev_t name_to_dev_t(const char *name)
 {
char s[32];
char *p;
dev_t res = 0;
int part;
+   int n;
 
 #ifdef CONFIG_BLOCK
if (strncmp(name, "PARTUUID=", 9) == 0) {
@@ -230,7 +238,7 @@ dev_t name_to_dev_t(char *name)
goto fail;
} else {
res = new_decode_dev(simple_strtoul(name, &p, 16));
-   if (*p)
+   if (*p && *p != '\n')
goto fail;
}
goto done;
@@ -238,15 +246,20 @@ dev_t name_to_dev_t(char *name)
 
name += 5;
res = Root_NFS;
-   if (strcmp(name, "nfs") == 0)
+   if (strncmp(name, "nfs", 3) == 0)
goto done;
res = Root_RAM0;
-   if (strcmp(name, "ram") == 0)
+   if (strncmp(name, "ram", 3) == 0)
goto done;
 
-   if (strlen(name) > 31)
+   n = strlen(name);
+   if (n != 0 && name[n - 1] == '\n')
+   n--;
+   if (n > 31)
goto fail;
-   strcpy(s, name);
+   strncpy(s, name, n);
+   s[n] = '\0';
+
for (p = s; *p; p++)
if (*p == '/')
*p = '!';
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 2/2] PM / Hibernate: use name_to_dev_t to parse resume

2013-10-03 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Acked-by: Pavel Machek 
Cc: Len Brown 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   15 ---
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index c9c759d..a29d2a7 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -972,16 +972,11 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
-
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(buf);
+   if (res == 0)
+   return -EINVAL;
 
lock_system_sleep();
swsusp_resume_device = res;
@@ -989,9 +984,7 @@ static ssize_t resume_store(struct kobject *kobj, struct 
kobj_attribute *attr,
printk(KERN_INFO "PM: Starting manual resume from disk\n");
noresume = 0;
software_resume();
-   ret = n;
- out:
-   return ret;
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 0/2] PM / Hibernate: sysfs resume

2013-10-03 Thread Sebastian Capella
Patchsets related to hibernation resume:
  - enhancement to make the use of an existing resume file more general
  - enhance name_to_dev_t to ignore trailing newlines coming from userspace.

Both patches are based on the 3.12-rc3 tag.  This was tested on a
Pandaboard with partial hibernation support, and compiled for x86.

[PATCH 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t
  init/do_mounts.c |   23 ++-
  1 file changed, 18 insertions(+), 5 deletions(-)

  Changes name_to_dev_t to handle a trailing newline in the
  input buffer, which will allow name_to_dev_t to be used
  directly with user buffers without requiring a copy.
  Also adds a const to the name parameter which reflects
  how name_to_dev_t is treating the input buffer currently.
  This also allows direct use of user buffers
  (from resume_store for example).

[PATCH 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   15 ---
  1 file changed, 4 insertions(+), 11 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c

Thanks,

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 RFT 2/2] PM / Hibernate: use name_to_dev_t to parse resume

2013-09-18 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   15 ---
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index b26f5f1..8b253c2 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -971,16 +971,11 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
-   int ret = -EINVAL;
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
-
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
-   goto out;
+   res = name_to_dev_t(buf);
+   if (res == 0)
+   return -EINVAL;
 
lock_system_sleep();
swsusp_resume_device = res;
@@ -988,9 +983,7 @@ static ssize_t resume_store(struct kobject *kobj, struct 
kobj_attribute *attr,
printk(KERN_INFO "PM: Starting manual resume from disk\n");
noresume = 0;
software_resume();
-   ret = n;
- out:
-   return ret;
+   return n;
 }
 
 power_attr(resume);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 RFT 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t

2013-09-18 Thread Sebastian Capella
Enhance name_to_dev_t to handle trailing newline characters
on device paths.  Some inputs to name_to_dev_t may come from
userspace where oftentimes a '\n' is appended to the path.
Added const to the name buffer in both the function
declaration and the prototype to reflect input buffer
handling.

By handling trailing newlines in name_to_dev_t, userspace
buffers may be directly passed to name_to_dev_t without
modification.

Signed-off-by: Sebastian Capella 
Cc: Pavel Machek 
Cc: "Eric W. Biederman" 
Cc: Serge Hallyn 
Cc: Andrew Morton 
Cc: Stephen Warren 
Cc: Jens Axboe 
Cc: Greg Kroah-Hartman 
Cc: Al Viro 
---
 include/linux/mount.h |2 +-
 init/do_mounts.c  |   25 +++--
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/include/linux/mount.h b/include/linux/mount.h
index 73005f9..b024d5c 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -76,6 +76,6 @@ extern struct vfsmount *vfs_kern_mount(struct 
file_system_type *type,
 extern void mnt_set_expiry(struct vfsmount *mnt, struct list_head 
*expiry_list);
 extern void mark_mounts_for_expiry(struct list_head *mounts);
 
-extern dev_t name_to_dev_t(char *name);
+extern dev_t name_to_dev_t(const char *name);
 
 #endif /* _LINUX_MOUNT_H */
diff --git a/init/do_mounts.c b/init/do_mounts.c
index 816014c..5a031de 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -143,6 +143,13 @@ static dev_t devt_from_partuuid(const char *uuid_str)
clear_root_wait = true;
goto done;
}
+   if (uuid_str[cmp.len - 1] == '\n') {
+   cmp.len--;
+   if (!cmp.len) {
+   clear_root_wait = true;
+   goto done;
+   }
+   }
 
dev = class_find_device(&block_class, NULL, &cmp,
&match_dev_by_uuid);
@@ -202,12 +209,13 @@ done:
  * bangs.
  */
 
-dev_t name_to_dev_t(char *name)
+dev_t name_to_dev_t(const char *name)
 {
char s[32];
char *p;
dev_t res = 0;
int part;
+   int n;
 
 #ifdef CONFIG_BLOCK
if (strncmp(name, "PARTUUID=", 9) == 0) {
@@ -228,7 +236,7 @@ dev_t name_to_dev_t(char *name)
goto fail;
} else {
res = new_decode_dev(simple_strtoul(name, &p, 16));
-   if (*p)
+   if (*p && *p != '\n')
goto fail;
}
goto done;
@@ -236,15 +244,20 @@ dev_t name_to_dev_t(char *name)
 
name += 5;
res = Root_NFS;
-   if (strcmp(name, "nfs") == 0)
+   if (strncmp(name, "nfs", 3) == 0)
goto done;
res = Root_RAM0;
-   if (strcmp(name, "ram") == 0)
+   if (strncmp(name, "ram", 3) == 0)
goto done;
 
-   if (strlen(name) > 31)
+   n = strlen(name);
+   if (n != 0 && name[n - 1] == '\n')
+   n--;
+   if (n > 31)
goto fail;
-   strcpy(s, name);
+   strncpy(s, name, n);
+   s[n] = '\0';
+
for (p = s; *p; p++)
if (*p == '/')
*p = '!';
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v3 RFT 0/2] PM / Hibernate: sysfs resume

2013-09-18 Thread Sebastian Capella
Patchset related to hibernation resume: one enhancement to make the use
of an existing resume file more general and one enhances name_to_dev_t
to ignore the trailing newlines coming from userspace.

Both patches are based on the 3.11 tag.  This was tested on a
Pandaboard with partial hibernation support, and compiled for x86.

Further testing is needed on other platforms.  Please let me know if
you're able to verify this on any other systems.

[PATCH 1/2] init/do_mounts.c: ignore final \n in name_to_dev_t
  init/do_mounts.c |   23 ++-
  1 file changed, 18 insertions(+), 5 deletions(-)

  Changes name_to_dev_t to handle a trailing newline in the
  input buffer, which will allow name_to_dev_t to be used
  directly with user buffers without requiring a copy.
  Also adds a const to the name parameter which reflects
  how name_to_dev_t is treating the input buffer currently.
  This also allows direct use of user buffers
  (from resume_store for example).

[PATCH 2/2] PM / Hibernate: use name_to_dev_t to parse resume
  kernel/power/hibernate.c |   15 ---
  1 file changed, 4 insertions(+), 11 deletions(-)

  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

Changes in v3:
--
* Dropped documentation patch as it went in through trivial
* Added patch for name_to_dev_t to support directly parsing userspace
  buffer

Changes in v2:
--
* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] init/do_mounts.c: add maj:min syntax comment

2013-09-12 Thread Sebastian Capella
Quoting Sebastian Capella (2013-09-12 13:54:54)
> The name_to_dev_t function has a comment block which lists the
> supported syntaxes for the device name.  Add a bullet for
> the : syntax, which is already supported in the code
> 
> Signed-off-by: Sebastian Capella 
> Cc: Andrew Morton 
> Cc: Stephen Warren 
> Cc: Jens Axboe 
> Cc: Greg Kroah-Hartman 
> Cc: Al Viro 
> ---
>  init/do_mounts.c |2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/init/do_mounts.c b/init/do_mounts.c
> index 816014c..89dc3a6 100644
> --- a/init/do_mounts.c
> +++ b/init/do_mounts.c
> @@ -195,6 +195,8 @@ done:
>   *is a zero-filled hex representation of the 1-based partition 
> number.
>   * 7) PARTUUID=/PARTNROFF= to select a partition in relation 
> to
>   *a partition with a known unique id.
> + * 8) : major and minor number of the device separated by
> + *a colon.
>   *
>   * If name doesn't have fall into the categories above, we return (0,0).
>   * block_class is used to check if something is a disk name. If the disk
> -- 
> 1.7.9.5

Correct trivial address
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] init/do_mounts.c: add maj:min syntax comment

2013-09-12 Thread Sebastian Capella
The name_to_dev_t function has a comment block which lists the
supported syntaxes for the device name.  Add a bullet for
the : syntax, which is already supported in the code

Signed-off-by: Sebastian Capella 
Cc: Andrew Morton 
Cc: Stephen Warren 
Cc: Jens Axboe 
Cc: Greg Kroah-Hartman 
Cc: Al Viro 
---
 init/do_mounts.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/init/do_mounts.c b/init/do_mounts.c
index 816014c..89dc3a6 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -195,6 +195,8 @@ done:
  *is a zero-filled hex representation of the 1-based partition number.
  * 7) PARTUUID=/PARTNROFF= to select a partition in relation to
  *a partition with a known unique id.
+ * 8) : major and minor number of the device separated by
+ *a colon.
  *
  * If name doesn't have fall into the categories above, we return (0,0).
  * block_class is used to check if something is a disk name. If the disk
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 RFT 1/2] PM / Hibernate: use name_to_dev_t to parse resume

2013-08-27 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
---
 kernel/power/hibernate.c |   18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index b26f5f1..8ba8719 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -971,15 +971,23 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
int ret = -EINVAL;
+   int len = n;
+   char *devcpy;
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (buf[len-1] == '\n')
+   len--;
+
+   devcpy = kstrndup(buf, len, GFP_KERNEL);
+
+   if (devcpy == NULL)
+   return -ENOMEM;
+
+   res = name_to_dev_t(devcpy);
+   kfree(devcpy);
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
+   if (res == 0)
goto out;
 
lock_system_sleep();
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 RFT 2/2] PM / Hibernate: add section for resume options

2013-08-27 Thread Sebastian Capella
Expand the existing documentation to explicitly list the options for
resuming a hibernation image, including the manual resume option which
can be used from the initrd or initramfs and the kernel init resume.

Signed-off-by: Sebastian Capella 
Cc: Rob Landley 
Cc: Len Brown 
Cc: Pavel Machek 
Cc: "Rafael J. Wysocki" 
---
 Documentation/power/swsusp.txt |   15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/Documentation/power/swsusp.txt b/Documentation/power/swsusp.txt
index 0b4b63e..079160e 100644
--- a/Documentation/power/swsusp.txt
+++ b/Documentation/power/swsusp.txt
@@ -50,6 +50,19 @@ echo N > /sys/power/image_size
 
 before suspend (it is limited to 500 MB by default).
 
+. The resume process checks for the presence of the resume device,
+if found, it then checks the contents for the hibernation image signature.
+If both are found, it resumes the hibernation image.
+
+. The resume process may be triggered in two ways:
+  1) During lateinit:  If resume=/dev/your_swap_partition is specified on
+ the kernel command line, lateinit runs the resume process.  If the
+ resume device has not been probed yet, the resume process fails and
+ bootup continues.
+  2) Manually from an initrd or initramfs:  May be run from
+ the init script by using the /sys/power/resume file.  It is vital
+ that this be done prior to remounting any filesystems (even as
+ read-only) otherwise data may be corrupted.
 
 Article about goals and implementation of Software Suspend for Linux
 
@@ -326,7 +339,7 @@ Q: How can distributions ship a swsusp-supporting kernel 
with modular
 disk drivers (especially SATA)?
 
 A: Well, it can be done, load the drivers, then do echo into
-/sys/power/disk/resume file from initrd. Be sure not to mount
+/sys/power/resume file from initrd. Be sure not to mount
 anything, not even read-only mount, or you are going to lose your
 data.
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 RFT 0/2] PM / Hibernate: sysfs resume

2013-08-27 Thread Sebastian Capella
Patchset related to hibernation resume: one enhancement to make the use
of an existing file more general and one documentation update.

Both patches are based on the 3.11-rc6 tag.  This was tested on a
Pandaboard with partial hibernation support, and compiled on x86.

Further testing is needed on other platforms.  Please let me know if
you're able to verify this on any other systems.

[PATCH 1/2] PM / Hibernate: use name_to_dev_t to parse resume
  Use name_to_dev_t to parse the /sys/power/resume file making the
  syntax more flexible.  It supports the previous use syntax
  and additionally can support other formats such as
  /dev/devicenode and UUID= formats.

  By changing /sys/debug/resume to accept the same syntax as
  the resume=device parameter, we can parse the resume=device
  in the initrd init script and use the resume device directly
  from the kernel command line.

  kernel/power/hibernate.c |   18 +-
  1 file changed, 13 insertions(+), 5 deletions(-)

[PATCH 2/2] PM / Hibernate: add section for resume options
  This adds a small section to the swsusp.txt file to address the
  options for resuming.  This comments on the manual resume
  option which is used when resorting to an initrd or initramfs
  for resuming.  Resuming from late init is discussed later in
  the document, but it seemed appropriate to list them together.

  Documentation/power/swsusp.txt |   15 ++-
  1 file changed, 14 insertions(+), 1 deletion(-)

Changes in v2:
--

* Added check for null return of kstrndup in hibernate.c


Thanks,

Sebastian

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[no subject]

2013-08-21 Thread sebastian . capella
From: Sebastian Capella 
Subject: [PATCH RFC 2/2] PM / Hibernate: add section for resume options

Expand the existing documentation to explicitly list the options for
resuming a hibernation image, including the manual resume option which
can be used from the initrd or initramfs and the kernel init resume.

Signed-off-by: Sebastian Capella 
---
 Documentation/power/swsusp.txt |   15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/Documentation/power/swsusp.txt b/Documentation/power/swsusp.txt
index 0b4b63e..079160e 100644
--- a/Documentation/power/swsusp.txt
+++ b/Documentation/power/swsusp.txt
@@ -50,6 +50,19 @@ echo N > /sys/power/image_size
 
 before suspend (it is limited to 500 MB by default).
 
+. The resume process checks for the presence of the resume device,
+if found, it then checks the contents for the hibernation image signature.
+If both are found, it resumes the hibernation image.
+
+. The resume process may be triggered in two ways:
+  1) During lateinit:  If resume=/dev/your_swap_partition is specified on
+ the kernel command line, lateinit runs the resume process.  If the
+ resume device has not been probed yet, the resume process fails and
+ bootup continues.
+  2) Manually from an initrd or initramfs:  May be run from
+ the init script by using the /sys/power/resume file.  It is vital
+ that this be done prior to remounting any filesystems (even as
+ read-only) otherwise data may be corrupted.
 
 Article about goals and implementation of Software Suspend for Linux
 
@@ -326,7 +339,7 @@ Q: How can distributions ship a swsusp-supporting kernel 
with modular
 disk drivers (especially SATA)?
 
 A: Well, it can be done, load the drivers, then do echo into
-/sys/power/disk/resume file from initrd. Be sure not to mount
+/sys/power/resume file from initrd. Be sure not to mount
 anything, not even read-only mount, or you are going to lose your
 data.
 
-- 
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH RFC 1/2] PM / Hibernate: use name_to_dev_t to parse resume

2013-08-21 Thread Sebastian Capella
Use the name_to_dev_t call to parse the device name echo'd to
to /sys/power/resume.  This imitates the method used in hibernate.c
in software_resume, and allows the resume partition to be specified
using other equivalent device formats as well.  By allowing
/sys/debug/resume to accept the same syntax as the resume=device
parameter, we can parse the resume=device in the init script and
use the resume device directly from the kernel command line.

Signed-off-by: Sebastian Capella 
---
 kernel/power/hibernate.c |   14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index b26f5f1..51d4c29 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -971,15 +971,19 @@ static ssize_t resume_show(struct kobject *kobj, struct 
kobj_attribute *attr,
 static ssize_t resume_store(struct kobject *kobj, struct kobj_attribute *attr,
const char *buf, size_t n)
 {
-   unsigned int maj, min;
dev_t res;
int ret = -EINVAL;
+   int len = n;
+   char *devcpy;
 
-   if (sscanf(buf, "%u:%u", &maj, &min) != 2)
-   goto out;
+   if (buf[len-1] == '\n')
+   len--;
+
+   devcpy = kstrndup(buf, len, GFP_KERNEL);
+   res = name_to_dev_t(devcpy);
+   kfree(devcpy);
 
-   res = MKDEV(maj,min);
-   if (maj != MAJOR(res) || min != MINOR(res))
+   if (res == 0)
goto out;
 
lock_system_sleep();
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


  1   2   >