public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [RFC] Save/restore MISC_ENABLE register
@ 2010-06-07 16:14 Ondrej Zary
  2010-06-07 17:27 ` H. Peter Anvin
  0 siblings, 1 reply; 8+ messages in thread
From: Ondrej Zary @ 2010-06-07 16:14 UTC (permalink / raw)
  To: Linux-pm mailing list
  Cc: Kernel development list, Alan Stern, H. Peter Anvin, Len Brown,
	Pavel Machek, Rafael J. Wysocki

Save/restore MISC_ENABLE register on suspend/resume.
This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM, which
wakes up with MWAIT disabled.

Is this a correct thing to do? Is it OK on x86_64?

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>

diff -urp linux-2.6.35-rc1-git2-orig/arch/x86/include/asm/suspend_32.h linux-2.6.35-rc1-git2/arch/x86/include/asm/suspend_32.h
--- linux-2.6.35-rc1-git2-orig/arch/x86/include/asm/suspend_32.h	2010-05-30 22:21:02.000000000 +0200
+++ linux-2.6.35-rc1-git2/arch/x86/include/asm/suspend_32.h	2010-06-04 23:52:22.000000000 +0200
@@ -15,6 +15,7 @@ static inline int arch_prepare_suspend(v
 struct saved_context {
 	u16 es, fs, gs, ss;
 	unsigned long cr0, cr2, cr3, cr4;
+	unsigned long misc_enable;
 	struct desc_ptr gdt;
 	struct desc_ptr idt;
 	u16 ldt;
diff -urp linux-2.6.35-rc1-git2-orig/arch/x86/include/asm/suspend_64.h linux-2.6.35-rc1-git2/arch/x86/include/asm/suspend_64.h
--- linux-2.6.35-rc1-git2-orig/arch/x86/include/asm/suspend_64.h	2010-05-30 22:21:02.000000000 +0200
+++ linux-2.6.35-rc1-git2/arch/x86/include/asm/suspend_64.h	2010-06-04 23:52:21.000000000 +0200
@@ -27,6 +27,7 @@ struct saved_context {
 	u16 ds, es, fs, gs, ss;
 	unsigned long gs_base, gs_kernel_base, fs_base;
 	unsigned long cr0, cr2, cr3, cr4, cr8;
+	unsigned long misc_enable;
 	unsigned long efer;
 	u16 gdt_pad;
 	u16 gdt_limit;
diff -urp linux-2.6.35-rc1-git2-orig/arch/x86/power/cpu.c linux-2.6.35-rc1-git2/arch/x86/power/cpu.c
--- linux-2.6.35-rc1-git2-orig/arch/x86/power/cpu.c	2010-05-30 22:21:02.000000000 +0200
+++ linux-2.6.35-rc1-git2/arch/x86/power/cpu.c	2010-06-04 23:50:52.000000000 +0200
@@ -105,6 +105,7 @@ static void __save_processor_state(struc
 	ctxt->cr4 = read_cr4();
 	ctxt->cr8 = read_cr8();
 #endif
+	rdmsrl(MSR_IA32_MISC_ENABLE, ctxt->misc_enable);
 }
 
 /* Needed by apm.c */
@@ -152,6 +153,7 @@ static void fix_processor_context(void)
  */
 static void __restore_processor_state(struct saved_context *ctxt)
 {
+	wrmsrl(MSR_IA32_MISC_ENABLE, ctxt->misc_enable);
 	/*
 	 * control registers
 	 */

-- 
Ondrej Zary

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

* Re: [PATCH] [RFC] Save/restore MISC_ENABLE register
  2010-06-07 16:14 [PATCH] [RFC] Save/restore MISC_ENABLE register Ondrej Zary
@ 2010-06-07 17:27 ` H. Peter Anvin
  2010-06-07 18:51   ` Ondrej Zary
  0 siblings, 1 reply; 8+ messages in thread
From: H. Peter Anvin @ 2010-06-07 17:27 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Linux-pm mailing list, Kernel development list, Alan Stern,
	Len Brown, Pavel Machek, Rafael J. Wysocki

On 06/07/2010 09:14 AM, Ondrej Zary wrote:
> Save/restore MISC_ENABLE register on suspend/resume.
> This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM, which
> wakes up with MWAIT disabled.
> 
> Is this a correct thing to do? Is it OK on x86_64?

This MSR isn't available on all processors, and thus cannot be saved and
restored unconditionally like this.  On the save path, one can use
rdmsr_safe(); on the wakeup path it's not clear to me it is safe to do
so, so it would be better to save a presence flag on the save path and
conditionalize the write.

	-hpa

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

* Re: [PATCH] [RFC] Save/restore MISC_ENABLE register
  2010-06-07 17:27 ` H. Peter Anvin
@ 2010-06-07 18:51   ` Ondrej Zary
  2010-06-07 18:53     ` H. Peter Anvin
  0 siblings, 1 reply; 8+ messages in thread
From: Ondrej Zary @ 2010-06-07 18:51 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Linux-pm mailing list, Kernel development list, Alan Stern,
	Len Brown, Pavel Machek, Rafael J. Wysocki

On Monday 07 June 2010 19:27:23 H. Peter Anvin wrote:
> On 06/07/2010 09:14 AM, Ondrej Zary wrote:
> > Save/restore MISC_ENABLE register on suspend/resume.
> > This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM,
> > which wakes up with MWAIT disabled.
> >
> > Is this a correct thing to do? Is it OK on x86_64?
>
> This MSR isn't available on all processors, and thus cannot be saved and
> restored unconditionally like this.  On the save path, one can use
> rdmsr_safe(); on the wakeup path it's not clear to me it is safe to do
> so, so it would be better to save a presence flag on the save path and
> conditionalize the write.

Something like this?

Save/restore MISC_ENABLE register on suspend/resume.
This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM, which
wakes up with MWAIT disabled.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>

diff -urp linux-2.6.35-rc1-git2-orig/arch/x86//include/asm/suspend_32.h linux-2.6.35-rc1-git2/arch/x86//include/asm/suspend_32.h
--- linux-2.6.35-rc1-git2-orig/arch/x86//include/asm/suspend_32.h	2010-05-30 22:21:02.000000000 +0200
+++ linux-2.6.35-rc1-git2/arch/x86//include/asm/suspend_32.h	2010-06-07 20:41:44.000000000 +0200
@@ -15,6 +15,8 @@ static inline int arch_prepare_suspend(v
 struct saved_context {
 	u16 es, fs, gs, ss;
 	unsigned long cr0, cr2, cr3, cr4;
+	u64 misc_enable;
+	bool misc_enable_saved;
 	struct desc_ptr gdt;
 	struct desc_ptr idt;
 	u16 ldt;
diff -urp linux-2.6.35-rc1-git2-orig/arch/x86//include/asm/suspend_64.h linux-2.6.35-rc1-git2/arch/x86//include/asm/suspend_64.h
--- linux-2.6.35-rc1-git2-orig/arch/x86//include/asm/suspend_64.h	2010-05-30 22:21:02.000000000 +0200
+++ linux-2.6.35-rc1-git2/arch/x86//include/asm/suspend_64.h	2010-06-07 20:38:42.000000000 +0200
@@ -27,6 +27,8 @@ struct saved_context {
 	u16 ds, es, fs, gs, ss;
 	unsigned long gs_base, gs_kernel_base, fs_base;
 	unsigned long cr0, cr2, cr3, cr4, cr8;
+	u64 misc_enable;
+	bool misc_enable_saved;
 	unsigned long efer;
 	u16 gdt_pad;
 	u16 gdt_limit;
diff -urp linux-2.6.35-rc1-git2-orig/arch/x86//power/cpu.c linux-2.6.35-rc1-git2/arch/x86//power/cpu.c
--- linux-2.6.35-rc1-git2-orig/arch/x86//power/cpu.c	2010-05-30 22:21:02.000000000 +0200
+++ linux-2.6.35-rc1-git2/arch/x86//power/cpu.c	2010-06-07 20:41:13.000000000 +0200
@@ -105,6 +105,8 @@ static void __save_processor_state(struc
 	ctxt->cr4 = read_cr4();
 	ctxt->cr8 = read_cr8();
 #endif
+	ctxt->misc_enable_saved = !rdmsrl_safe(MSR_IA32_MISC_ENABLE,
+					       &ctxt->misc_enable);
 }
 
 /* Needed by apm.c */
@@ -152,6 +154,8 @@ static void fix_processor_context(void)
  */
 static void __restore_processor_state(struct saved_context *ctxt)
 {
+	if (ctxt->misc_enable_saved)
+		wrmsrl(MSR_IA32_MISC_ENABLE, ctxt->misc_enable);
 	/*
 	 * control registers
 	 */



-- 
Ondrej Zary

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

* Re: [PATCH] [RFC] Save/restore MISC_ENABLE register
  2010-06-07 18:51   ` Ondrej Zary
@ 2010-06-07 18:53     ` H. Peter Anvin
  2010-06-07 19:02       ` Ondrej Zary
  2010-06-07 21:05       ` Rafael J. Wysocki
  0 siblings, 2 replies; 8+ messages in thread
From: H. Peter Anvin @ 2010-06-07 18:53 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: Linux-pm mailing list, Kernel development list, Alan Stern,
	Len Brown, Pavel Machek, Rafael J. Wysocki

On 06/07/2010 11:51 AM, Ondrej Zary wrote:
> 
> Something like this?
> 
> Save/restore MISC_ENABLE register on suspend/resume.
> This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM, which
> wakes up with MWAIT disabled.
> 
> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> 

Yes, that's a lot better.

I presume you have tested it.  Rafael, do you want to take this or should I?

	-hpa

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

* Re: [PATCH] [RFC] Save/restore MISC_ENABLE register
  2010-06-07 18:53     ` H. Peter Anvin
@ 2010-06-07 19:02       ` Ondrej Zary
  2010-06-07 21:05       ` Rafael J. Wysocki
  1 sibling, 0 replies; 8+ messages in thread
From: Ondrej Zary @ 2010-06-07 19:02 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Linux-pm mailing list, Kernel development list, Alan Stern,
	Len Brown, Pavel Machek, Rafael J. Wysocki

On Monday 07 June 2010 20:53:38 H. Peter Anvin wrote:
> On 06/07/2010 11:51 AM, Ondrej Zary wrote:
> > Something like this?
> >
> > Save/restore MISC_ENABLE register on suspend/resume.
> > This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM,
> > which wakes up with MWAIT disabled.
> >
> > Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
>
> Yes, that's a lot better.
>
> I presume you have tested it.  Rafael, do you want to take this or should
> I?

Yes, it works on the P4P800-VM. Don't have any x86_64 machine to test.

-- 
Ondrej Zary

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

* Re: [PATCH] [RFC] Save/restore MISC_ENABLE register
  2010-06-07 18:53     ` H. Peter Anvin
  2010-06-07 19:02       ` Ondrej Zary
@ 2010-06-07 21:05       ` Rafael J. Wysocki
  2010-06-07 21:06         ` H. Peter Anvin
  2010-06-07 21:09         ` Alan Stern
  1 sibling, 2 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2010-06-07 21:05 UTC (permalink / raw)
  To: H. Peter Anvin
  Cc: Ondrej Zary, Linux-pm mailing list, Kernel development list,
	Alan Stern, Len Brown, Pavel Machek

On Monday 07 June 2010, H. Peter Anvin wrote:
> On 06/07/2010 11:51 AM, Ondrej Zary wrote:
> > 
> > Something like this?
> > 
> > Save/restore MISC_ENABLE register on suspend/resume.
> > This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM, which
> > wakes up with MWAIT disabled.
> > 
> > Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> > 
> 
> Yes, that's a lot better.
> 
> I presume you have tested it.  Rafael, do you want to take this or should I?

I can take it.  Is it OK to add your ACK?

Rafael

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

* Re: [PATCH] [RFC] Save/restore MISC_ENABLE register
  2010-06-07 21:05       ` Rafael J. Wysocki
@ 2010-06-07 21:06         ` H. Peter Anvin
  2010-06-07 21:09         ` Alan Stern
  1 sibling, 0 replies; 8+ messages in thread
From: H. Peter Anvin @ 2010-06-07 21:06 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Ondrej Zary, Linux-pm mailing list, Kernel development list,
	Alan Stern, Len Brown, Pavel Machek

On 06/07/2010 02:05 PM, Rafael J. Wysocki wrote:
> On Monday 07 June 2010, H. Peter Anvin wrote:
>> On 06/07/2010 11:51 AM, Ondrej Zary wrote:
>>>
>>> Something like this?
>>>
>>> Save/restore MISC_ENABLE register on suspend/resume.
>>> This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM, which
>>> wakes up with MWAIT disabled.
>>>
>>> Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
>>>
>>
>> Yes, that's a lot better.
>>
>> I presume you have tested it.  Rafael, do you want to take this or should I?
> 
> I can take it.  Is it OK to add your ACK?
> 

Yes.

Acked-by: H. Peter Anvin <hpa@linux.intel.com>

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

* Re: [PATCH] [RFC] Save/restore MISC_ENABLE register
  2010-06-07 21:05       ` Rafael J. Wysocki
  2010-06-07 21:06         ` H. Peter Anvin
@ 2010-06-07 21:09         ` Alan Stern
  1 sibling, 0 replies; 8+ messages in thread
From: Alan Stern @ 2010-06-07 21:09 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: H. Peter Anvin, Ondrej Zary, Linux-pm mailing list,
	Kernel development list, Len Brown, Pavel Machek

On Mon, 7 Jun 2010, Rafael J. Wysocki wrote:

> On Monday 07 June 2010, H. Peter Anvin wrote:
> > On 06/07/2010 11:51 AM, Ondrej Zary wrote:
> > > 
> > > Something like this?
> > > 
> > > Save/restore MISC_ENABLE register on suspend/resume.
> > > This fixes OOPS (invalid opcode) on resume from STR on Asus P4P800-VM, which
> > > wakes up with MWAIT disabled.
> > > 
> > > Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
> > > 
> > 
> > Yes, that's a lot better.
> > 
> > I presume you have tested it.  Rafael, do you want to take this or should I?
> 
> I can take it.  Is it OK to add your ACK?

You might in addition want to note that this patch fixes Bugzilla 
#15385.

Alan Stern


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

end of thread, other threads:[~2010-06-07 21:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-07 16:14 [PATCH] [RFC] Save/restore MISC_ENABLE register Ondrej Zary
2010-06-07 17:27 ` H. Peter Anvin
2010-06-07 18:51   ` Ondrej Zary
2010-06-07 18:53     ` H. Peter Anvin
2010-06-07 19:02       ` Ondrej Zary
2010-06-07 21:05       ` Rafael J. Wysocki
2010-06-07 21:06         ` H. Peter Anvin
2010-06-07 21:09         ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox