linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space
@ 2013-06-09  5:22 Wang Dongsheng
  2013-06-09  6:43 ` Benjamin Herrenschmidt
  2013-06-09 11:31 ` Wang Dongsheng-B40534
  0 siblings, 2 replies; 6+ messages in thread
From: Wang Dongsheng @ 2013-06-09  5:22 UTC (permalink / raw)
  To: benh, johannes, anton; +Cc: scottwood, linuxppc-dev, Wang Dongsheng

If PID is used in the TLB, after hibernation resume, the user
threads will access to kernel space.

We must restore PID register, because TLB will use PID. The
hibernation suspend flow is trapped from user space to kernel
space, the PID register is user thread pid.

The hibernation resume is begin in kernel start flow, the PID
alway 0. After the kernel thread back to user thread, there is
not have context switch and the pid can not update, because the
kernel thread is trapped form user space. So if we did't restore
PID the user space of thread will be addressing in the kernel
space.

There are two ways to restore PID:
1/ In swsusp_arch_suspend/swsusp_arch_resume, save/resotre PID register.
2/ Form restore_processor_state to restore. this function will
   do context switch.
   switch_mmu_context(current->active_mm, current->active_mm)

PPC32 Using the second method. For consistency reason, PPC64 using
the same way.

Signed-off-by: Wang Dongsheng <dongsheng.wang@freescale.com>
---
 arch/powerpc/kernel/swsusp.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/powerpc/kernel/swsusp.c b/arch/powerpc/kernel/swsusp.c
index eae33e1..1930e44 100644
--- a/arch/powerpc/kernel/swsusp.c
+++ b/arch/powerpc/kernel/swsusp.c
@@ -32,7 +32,5 @@ void save_processor_state(void)
 
 void restore_processor_state(void)
 {
-#ifdef CONFIG_PPC32
 	switch_mmu_context(current->active_mm, current->active_mm);
-#endif
 }
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space
  2013-06-09  5:22 [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space Wang Dongsheng
@ 2013-06-09  6:43 ` Benjamin Herrenschmidt
  2013-06-09  7:44   ` Wang Dongsheng-B40534
  2013-06-09 11:31 ` Wang Dongsheng-B40534
  1 sibling, 1 reply; 6+ messages in thread
From: Benjamin Herrenschmidt @ 2013-06-09  6:43 UTC (permalink / raw)
  To: Wang Dongsheng; +Cc: scottwood, johannes, anton, linuxppc-dev

On Sun, 2013-06-09 at 13:22 +0800, Wang Dongsheng wrote:
> If PID is used in the TLB, after hibernation resume, the user
> threads will access to kernel space.

 .../...

I think the explanation is way more convoluted and confusing
here than anything else.

Simply say that upon resume from hibernation, the MMU context
needs to be restored (this includes the PID register today
it might include more if we decided to pre-set some MAS for example
etc...) and be done with it.

Note that switch_mmu_context() used the way you do is quite "full on",
it will do a whole pile of stuff that are probably completely
unnecessary, and in addition might still miss the need to completely
flush the TLB anyway.

I would suggest that instead, somebody adds the necessary routine
to tlb_nohash.c, something like restore_mmu_context() which will
do that.

Cheers,
Ben.

> Signed-off-by: Wang Dongsheng <dongsheng.wang@freescale.com>
> ---
>  arch/powerpc/kernel/swsusp.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/swsusp.c b/arch/powerpc/kernel/swsusp.c
> index eae33e1..1930e44 100644
> --- a/arch/powerpc/kernel/swsusp.c
> +++ b/arch/powerpc/kernel/swsusp.c
> @@ -32,7 +32,5 @@ void save_processor_state(void)
>  
>  void restore_processor_state(void)
>  {
> -#ifdef CONFIG_PPC32
>  	switch_mmu_context(current->active_mm, current->active_mm);
> -#endif
>  }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space
  2013-06-09  6:43 ` Benjamin Herrenschmidt
@ 2013-06-09  7:44   ` Wang Dongsheng-B40534
  2013-06-09  7:45     ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 6+ messages in thread
From: Wang Dongsheng-B40534 @ 2013-06-09  7:44 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: Wood Sc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flat|nested] 6+ messages in thread

* Re: [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space
  2013-06-09  7:44   ` Wang Dongsheng-B40534
@ 2013-06-09  7:45     ` Benjamin Herrenschmidt
  2013-06-09  7:57       ` Wang Dongsheng-B40534
  0 siblings, 1 reply; 6+ messages in thread
From: Benjamin Herrenschmidt @ 2013-06-09  7:45 UTC (permalink / raw)
  To: Wang Dongsheng-B40534; +Cc: Wood Scott-B07421, johannes, anton, linuxppc-dev

On Sun, 2013-06-09 at 07:44 +0000, Wang Dongsheng-B40534 wrote:
> So we just need set set_context() in restore_mmu_context().
> 
> void restore_mmu_context(struct mm_struct *next) {
>         set_context(next->context.id, next->pgd);
> }

We probably also want to flush the TLB, just in case the boot kernel has
left "something" there (though I wouldn't expect it to have run
userspace it's not completely impossible).

Cheers,
Ben.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space
  2013-06-09  7:45     ` Benjamin Herrenschmidt
@ 2013-06-09  7:57       ` Wang Dongsheng-B40534
  0 siblings, 0 replies; 6+ messages in thread
From: Wang Dongsheng-B40534 @ 2013-06-09  7:57 UTC (permalink / raw)
  To: Benjamin Herrenschmidt; +Cc: Wood Scott-B07421, johannes, anton, linuxppc-dev

DQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogQmVuamFtaW4gSGVycmVu
c2NobWlkdCBbbWFpbHRvOmJlbmhAa2VybmVsLmNyYXNoaW5nLm9yZ10NCj4gU2VudDogU3VuZGF5
LCBKdW5lIDA5LCAyMDEzIDM6NDYgUE0NCj4gVG86IFdhbmcgRG9uZ3NoZW5nLUI0MDUzNA0KPiBD
Yzogam9oYW5uZXNAc2lwc29sdXRpb25zLm5ldDsgYW50b25AZW5vbXNnLm9yZzsgV29vZCBTY290
dC1CMDc0MjE7DQo+IGdhbGFrQGtlcm5lbC5jcmFzaGluZy5vcmc7IGxpbnV4cHBjLWRldkBsaXN0
cy5vemxhYnMub3JnDQo+IFN1YmplY3Q6IFJlOiBbUEFUQ0ggdjIgMi8yXSBwb3dlcnBjL2hpYmVy
bmF0ZTogUFBDNjQgZml4IHVzZXIgdGhyZWFkcw0KPiBhY2Nlc3MgdG8ga2VybmVsIHNwYWNlDQo+
IA0KPiBPbiBTdW4sIDIwMTMtMDYtMDkgYXQgMDc6NDQgKzAwMDAsIFdhbmcgRG9uZ3NoZW5nLUI0
MDUzNCB3cm90ZToNCj4gPiBTbyB3ZSBqdXN0IG5lZWQgc2V0IHNldF9jb250ZXh0KCkgaW4gcmVz
dG9yZV9tbXVfY29udGV4dCgpLg0KPiA+DQo+ID4gdm9pZCByZXN0b3JlX21tdV9jb250ZXh0KHN0
cnVjdCBtbV9zdHJ1Y3QgKm5leHQpIHsNCj4gPiAgICAgICAgIHNldF9jb250ZXh0KG5leHQtPmNv
bnRleHQuaWQsIG5leHQtPnBnZCk7IH0NCj4gDQo+IFdlIHByb2JhYmx5IGFsc28gd2FudCB0byBm
bHVzaCB0aGUgVExCLCBqdXN0IGluIGNhc2UgdGhlIGJvb3Qga2VybmVsIGhhcw0KPiBsZWZ0ICJz
b21ldGhpbmciIHRoZXJlICh0aG91Z2ggSSB3b3VsZG4ndCBleHBlY3QgaXQgdG8gaGF2ZSBydW4g
dXNlcnNwYWNlDQo+IGl0J3Mgbm90IGNvbXBsZXRlbHkgaW1wb3NzaWJsZSkuDQo+IA0KWWVzLCBi
dXQgVExCIGhhcyBhbHJlYWR5IGludmFsaWRhdGVkLg0KU2VlIG15IG90aGVyIHBhdGNoOg0KaHR0
cDovL3BhdGNod29yay5vemxhYnMub3JnL3BhdGNoLzI1MDAwNi8NCg0KPiBDaGVlcnMsDQo+IEJl
bi4NCj4gDQo+IA0KDQo=

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space
  2013-06-09  5:22 [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space Wang Dongsheng
  2013-06-09  6:43 ` Benjamin Herrenschmidt
@ 2013-06-09 11:31 ` Wang Dongsheng-B40534
  1 sibling, 0 replies; 6+ messages in thread
From: Wang Dongsheng-B40534 @ 2013-06-09 11:31 UTC (permalink / raw)
  To: Wang Dongsheng-B40534, benh, johannes, anton
  Cc: Wood Scott-B07421, linuxppc-dev

Sorry, Please ignore this patch.
This is replaced.
Replace by: http://patchwork.ozlabs.org/patch/250033/

- dongsheng

> -----Original Message-----
> From: Wang Dongsheng-B40534
> Sent: Sunday, June 09, 2013 1:23 PM
> To: benh@kernel.crashing.org; johannes@sipsolutions.net; anton@enomsg.org
> Cc: Wood Scott-B07421; galak@kernel.crashing.org; linuxppc-
> dev@lists.ozlabs.org; Wang Dongsheng-B40534
> Subject: [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access
> to kernel space
>=20
> If PID is used in the TLB, after hibernation resume, the user
> threads will access to kernel space.
>=20
> We must restore PID register, because TLB will use PID. The
> hibernation suspend flow is trapped from user space to kernel
> space, the PID register is user thread pid.
>=20
> The hibernation resume is begin in kernel start flow, the PID
> alway 0. After the kernel thread back to user thread, there is
> not have context switch and the pid can not update, because the
> kernel thread is trapped form user space. So if we did't restore
> PID the user space of thread will be addressing in the kernel
> space.
>=20
> There are two ways to restore PID:
> 1/ In swsusp_arch_suspend/swsusp_arch_resume, save/resotre PID register.
> 2/ Form restore_processor_state to restore. this function will
>    do context switch.
>    switch_mmu_context(current->active_mm, current->active_mm)
>=20
> PPC32 Using the second method. For consistency reason, PPC64 using
> the same way.
>=20
> Signed-off-by: Wang Dongsheng <dongsheng.wang@freescale.com>
> ---
>  arch/powerpc/kernel/swsusp.c | 2 --
>  1 file changed, 2 deletions(-)
>=20
> diff --git a/arch/powerpc/kernel/swsusp.c b/arch/powerpc/kernel/swsusp.c
> index eae33e1..1930e44 100644
> --- a/arch/powerpc/kernel/swsusp.c
> +++ b/arch/powerpc/kernel/swsusp.c
> @@ -32,7 +32,5 @@ void save_processor_state(void)
>=20
>  void restore_processor_state(void)
>  {
> -#ifdef CONFIG_PPC32
>  	switch_mmu_context(current->active_mm, current->active_mm);
> -#endif
>  }
> --
> 1.8.0

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-06-09 11:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-09  5:22 [PATCH v2 2/2] powerpc/hibernate: PPC64 fix user threads access to kernel space Wang Dongsheng
2013-06-09  6:43 ` Benjamin Herrenschmidt
2013-06-09  7:44   ` Wang Dongsheng-B40534
2013-06-09  7:45     ` Benjamin Herrenschmidt
2013-06-09  7:57       ` Wang Dongsheng-B40534
2013-06-09 11:31 ` Wang Dongsheng-B40534

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).