x86 ACPI: normalize segment descriptor register on resume
Subsystems (3)
PATCH 1/1 x86 ACPI: normalize segment descriptor register on resume
Hi,
The patch below fixes the regression described at
http://bugzilla.kernel.org/show_bug.cgi?id=10927
which is caused by the fact that some BIOSes call the kernel's resume code with post-protected mode garbage in segment registers.
Apart from Dell laptops referred to in the chagelog it has a potential to fix some other systems on which resume from suspend to RAM fails in a mysterious way and the probability of it breaking things is rather small, so IMO it would be nice to have in 2.6.26.
Thanks,
Rafael
---
From: H. Peter Anvin <[email protected]>
x86 ACPI: normalize segment descriptor register on resume
Some Dell laptops enter resume with apparent garbage in the segment descriptor registers (almost certainly the result of a botched transition from protected to real mode.) The only way to clean that up is to enter protected mode ourselves and clean out the descriptor registers.
This fixes resume on Dell XPS M1210 and Dell D620.
Reference: http://bugzilla.kernel.org/show_bug.cgi?id=10927
--- arch/x86/kernel/acpi/realmode/wakeup.S | 38 ++++++++++++++++++++++++++++++++- arch/x86/kernel/acpi/realmode/wakeup.h | 5 ++++ arch/x86/kernel/acpi/sleep.c | 16 +++++++++++++ drivers/acpi/sleep/main.c | 5 +--- 4 files changed, 59 insertions(+), 5 deletions(-)
arch/x86/kernel/acpi/realmode/wakeup.S +37 -1
@@ -5,6 +5,7 @@ #include <asm/msr-index.h> #include <asm/page.h> #include <asm/pgtable.h> +#include <asm/processor-flags.h> .code16 .section ".header", "a"
@@ -24,6 +25,11 @@ pmode_gdt: .quad 0 realmode_flags: .long 0 real_magic: .long 0 trampoline_segment: .word 0 +_pad1: .byte 0 +wakeup_jmp: .byte 0xea /* ljmpw */ +wakeup_jmp_off: .word 3f +wakeup_jmp_seg: .word 0 +wakeup_gdt: .quad 0, 0, 0 signature: .long 0x51ee1111 .text
@@ -34,11 +40,34 @@ _start: cli cld + /* Apparently some dimwit BIOS programmers don't know how to + program a PM to RM transition, and we might end up here with + junk in the data segment descriptor registers. The only way + to repair that is to go into PM and fix it ourselves... */ + movw $16, %cx + lgdtl %cs:wakeup_gdt + movl %cr0, %eax + orb $X86_CR0_PE, %al + movl %eax, %cr0 + jmp 1f +1: ljmpw $8, $2f +2: + movw %cx, %ds + movw %cx, %es + movw %cx, %ss + movw %cx, %fs + movw %cx, %gs + + andb $~X86_CR0_PE, %al + movl %eax, %cr0 + jmp wakeup_jmp +3: /* Set up segments */ movw %cs, %ax movw %ax, %ds movw %ax, %es movw %ax, %ss + lidtl wakeup_idt movl $wakeup_stack_end, %esp
@@ -98,7 +127,14 @@ bogus_real_magic: jmp 1b .data - .balign 4 + .balign 8 + + /* This is the standard real-mode IDT */ +wakeup_idt: + .word 0xffff /* limit */ + .long 0 /* address */ + .word 0 + .globl HEAP, heap_end HEAP: .long wakeup_heap
arch/x86/kernel/acpi/realmode/wakeup.h +5 -0
@@ -24,6 +24,11 @@ struct wakeup_header {u32 realmode_flags;u32 real_magic;u16 trampoline_segment;/* segment with trampoline code, 64-bit only */ +u8 _pad1; +u8 wakeup_jmp; +u16 wakeup_jmp_off; +u16 wakeup_jmp_seg; +u64 wakeup_gdt[3 ];u32 signature;/* To check we have correct structure */ } __attribute__((__packed__));
arch/x86/kernel/acpi/sleep.c +15 -1
@@ -50,6 +50,20 @@ int acpi_save_state_mem(void) header->video_mode = saved_video_mode; + header->wakeup_jmp_seg = acpi_wakeup_address >>4 ; +/* GDT[0]: GDT self-pointer */ + header->wakeup_gdt[0 ] = + (u64)(sizeof (header->wakeup_gdt) -1 ) + + ((u64)(acpi_wakeup_address + + ((char *)&header->wakeup_gdt - (char *)acpi_realmode)) + <<16 ); +/* GDT[1]: real-mode-like code segment */ + header->wakeup_gdt[1 ] = (0x009bULL <<40 ) + + ((u64 )acpi_wakeup_address <<16 ) +0xffff ; +/* GDT[2]: real-mode-like data segment */ + header->wakeup_gdt[2 ] = (0x0093ULL <<40 ) + + ((u64 )acpi_wakeup_address <<16 ) +0xffff ; +#ifndef CONFIG_64BIT store_gdt ((struct desc_ptr *)&header->pmode_gdt);
@@ -111,7 +125,7 @@ void __init acpi_reserve_bootmem(void)return ; } - acpi_wakeup_address = acpi_realmode; + acpi_wakeup_address =virt_to_phys ((void *)acpi_realmode); }
drivers/acpi/sleep/main.c +2 -3
@@ -32,9 +32,8 @@ static int acpi_sleep_prepare(u32 acpi_sif (!acpi_wakeup_address) {return -EFAULT ; } -acpi_set_firmware_waking_vector ((acpi_physical_address ) -virt_to_phys ((void *) - acpi_wakeup_address)); +acpi_set_firmware_waking_vector ( + (acpi_physical_address )acpi_wakeup_address); }ACPI_FLUSH_CPU_CACHE ();
Hi!
Quoted 10 lines
From: H. Peter Anvin <[email protected]>
x86 ACPI: normalize segment descriptor register on resume
Some Dell laptops enter resume with apparent garbage in the segment descriptor registers (almost certainly the result of a botched transition from protected to real mode.) The only way to clean that up is to enter protected mode ourselves and clean out the descriptor registers.
Quoted 7 lines
This fixes resume on Dell XPS M1210 and Dell D620.
Reference: http://bugzilla.kernel.org/show_bug.cgi?id=10927
Signed-off-by H. Peter Anvin <[email protected]>Tested-by Kirill A. Shutemov <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>
Thanks for great work.
I still consider this one slightly risky, and would like to get it as much testing as possible, but all the risks are hypothetical and regression from 2.6.25 is real, so...
If this could be sneaked into Ingo's tree for some automated testing, that would be good.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-test
was upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND && PM_DEBUG && RTC_LIB=y
and even then it needs certain other config options related to RTC_LIB to actually work during bootup.
As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
Ingo
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-test
was upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND && PM_DEBUG && RTC_LIB=y
and even then it needs certain other config options related to RTC_LIB to actually work during bootup.
As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
Ingo
Quoted 35 lines · Ingo Molnar
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-testwas upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config
PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND &&PM_DEBUG&& RTC_LIB=yand even then it needs certain other config options related to
RTC_LIBto actually work during bootup.As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
Quoted 7 lines
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
I thought it was in linux-next, wasn't it?
Rafael
Quoted 41 lines · On Wed, 25 Jun 2008 22:17:26 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 40 lines · Ingo Molnar
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-testwas upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config
PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND &&PM_DEBUG&& RTC_LIB=yand even then it needs certain other config options related to
RTC_LIBto actually work during bootup.As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
Quoted 5 lines
Quoted 2 lines
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
I thought it was in linux-next, wasn't it?
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
Thanks.
Quoted 41 lines · On Wed, 25 Jun 2008 22:17:26 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 40 lines · Ingo Molnar
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-testwas upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config
PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND &&PM_DEBUG&& RTC_LIB=yand even then it needs certain other config options related to
RTC_LIBto actually work during bootup.As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
Quoted 5 lines
Quoted 2 lines
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
I thought it was in linux-next, wasn't it?
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
Thanks.
Quoted 4 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
( my kernel test-setup does in excess of 100,000 random kernel bootups
per year and me not having to hit the keyboard or close+open the lid a hundred thousand times, day and night, to find the occasional suspend+resume regression is a not to be under-estimated plus. )
Ingo
Quoted 4 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
( my kernel test-setup does in excess of 100,000 random kernel bootups
per year and me not having to hit the keyboard or close+open the lid a hundred thousand times, day and night, to find the occasional suspend+resume regression is a not to be under-estimated plus. )
Ingo
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Quoted 7 lines
Quoted 1 line
Is it so?
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
Does it mean that the $subject patch doesn't break your test box after all?
Rafael
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Ingo Molnar
Quoted 4 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
Quoted 8 lines
Quoted 5 lines
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
Does it mean that the $subject patch doesn't break your test box after all?
it doesnt break it - i get the same suspend+resume breakage without that patch as well, if i do it manually.
Ingo
Quoted 9 lines · Rafael J. Wysocki
Quoted 8 lines · Ingo Molnar
Quoted 4 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
Quoted 8 lines
Quoted 5 lines
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
Does it mean that the $subject patch doesn't break your test box after all?
it doesnt break it - i get the same suspend+resume breakage without that patch as well, if i do it manually.
Ingo
Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Ingo Molnar
Quoted 4 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
Quoted 5 lines
Quoted 2 lines
Does it mean that the $subject patch doesn't break your test box after all?
it doesnt break it - i get the same suspend+resume breakage without that patch as well, if i do it manually.
Okay, so I think the $subject patch is good to go, then.
Thanks,
Rafael
Quoted 18 lines · Ingo Molnar
Quoted 15 lines · Rafael J. Wysocki
Quoted 13 lines · Ingo Molnar
Quoted 4 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
Quoted 5 lines
Quoted 2 lines
Does it mean that the $subject patch doesn't break your test box after all?
it doesnt break it - i get the same suspend+resume breakage without that patch as well, if i do it manually.
Okay, so I think the $subject patch is good to go, then.
Thanks,
Rafael
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Andrew Morton
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Quoted 7 lines
Quoted 1 line
Is it so?
No! :-)
it found a pre-existing suspend+resume breakage on a testbox. (I.e. the debug patch worked as i'd expect it to work. Every good debug patch starts its lifetime with a sharp spike of breakages it finds.)
Does it mean that the $subject patch doesn't break your test box after all?
Rafael
Quoted 46 lines · Andrew Morton
Quoted 44 lines · On Wed, 25 Jun 2008 22:17:26 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 42 lines · Ingo Molnar
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-testwas upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config
PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND &&PM_DEBUG&& RTC_LIB=yand even then it needs certain other config options related to
RTC_LIBto actually work during bootup.As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
Quoted 7 lines
Quoted 2 lines
I thought it was in linux-next, wasn't it?
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
Yes, it is.
The box is apparently broken, but we've been unable to reproduce the breakage on other very similar boxes, so far. Investigation continues.
Thanks,
Rafael
Quoted 46 lines · Andrew Morton
Quoted 44 lines · On Wed, 25 Jun 2008 22:17:26 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
Quoted 42 lines · Ingo Molnar
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-testwas upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config
PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND &&PM_DEBUG&& RTC_LIB=yand even then it needs certain other config options related to
RTC_LIBto actually work during bootup.As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
Quoted 7 lines
Quoted 2 lines
I thought it was in linux-next, wasn't it?
Len seems to think that Rafael seems to think that Ingo seems to think that this patch broke one of his boxes.
Is it so?
Yes, it is.
The box is apparently broken, but we've been unable to reproduce the breakage on other very similar boxes, so far. Investigation continues.
Thanks,
Rafael
Quoted 35 lines · Ingo Molnar
Quoted 4 lines · Pavel Machek
Acked-by Pavel Machek <[email protected]>If this could be sneaked into Ingo's tree for some automated testing, that would be good.
sure - i have applied it to tip/out-of-tree. I'm equally nervous about this change - it affects every suspend+resume cycle that people do on those boxes which are working just fine currently.
btw., it would get a lot more coverage on my test-systems if this commit in tip/out-of-tree:
| commit 01259383c345d13b70efcc549439927ae64dc66d | Author: David Brownell <[email protected]> | Date: Fri May 16 10:12:36 2008 +0200 | | sleepy linux self-testwas upstream and if it was enabled more prominently, instead of hidden behind the rather obscure condition of:
config
PM_TEST_SUSPEND
bool "Test suspend/resume and wakealarm during bootup" depends on SUSPEND &&PM_DEBUG&& RTC_LIB=yand even then it needs certain other config options related to
RTC_LIBto actually work during bootup.As a result of all this obstruction, the automated testing i do, which builds and boots more than 1 random kernel per minute, will only run this self-test once every hour or so.
Quoted 7 lines
I dont mind if this option breaks boxes (that its purpose: it does the same thing that a real suspend+resume does and suspend+resume frequently breaks boxes), but right now it's all obscured so heavily which makes automated testing a lot harder than it should be.
it would be wonderful if this excellent suspend+resume self-test was upstream and was more prominent! :-)
I thought it was in linux-next, wasn't it?
Rafael
Hi!
Quoted 10 lines
From: H. Peter Anvin <[email protected]>
x86 ACPI: normalize segment descriptor register on resume
Some Dell laptops enter resume with apparent garbage in the segment descriptor registers (almost certainly the result of a botched transition from protected to real mode.) The only way to clean that up is to enter protected mode ourselves and clean out the descriptor registers.
Quoted 7 lines
This fixes resume on Dell XPS M1210 and Dell D620.
Reference: http://bugzilla.kernel.org/show_bug.cgi?id=10927
Signed-off-by H. Peter Anvin <[email protected]>Tested-by Kirill A. Shutemov <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>
Thanks for great work.
I still consider this one slightly risky, and would like to get it as much testing as possible, but all the risks are hypothetical and regression from 2.6.25 is real, so...
If this could be sneaked into Ingo's tree for some automated testing, that would be good.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Applied.
thanks,
-Len
Quoted 183 lines · Rafael J. Wysocki
Hi,
The patch below fixes the regression described at
http://bugzilla.kernel.org/show_bug.cgi?id=10927
which is caused by the fact that some BIOSes call the kernel's resume code with post-protected mode garbage in segment registers.Apart from Dell laptops referred to in the chagelog it has a potential to fix some other systems on which resume from suspend to RAM fails in a mysterious way and the probability of it breaking things is rather small, so IMO it would be nice to have in 2.6.26.
Thanks,
Rafael---
From: H. Peter Anvin <[email protected]>x86 ACPI: normalize segment descriptor register on resume
Some Dell laptops enter resume with apparent garbage in the segment descriptor registers (almost certainly the result of a botched transition from protected to real mode.) The only way to clean that up is to enter protected mode ourselves and clean out the descriptor registers.
This fixes resume on Dell XPS M1210 and Dell D620.
Reference: http://bugzilla.kernel.org/show_bug.cgi?id=10927
Signed-off-by H. Peter Anvin <[email protected]>Tested-by Kirill A. Shutemov <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- arch/x86/kernel/acpi/realmode/wakeup.S | 38 ++++++++++++++++++++++++++++++++- arch/x86/kernel/acpi/realmode/wakeup.h | 5 ++++ arch/x86/kernel/acpi/sleep.c | 16 +++++++++++++ drivers/acpi/sleep/main.c | 5 +--- 4 files changed, 59 insertions(+), 5 deletions(-)Index:
linux-2.6/arch/x86/kernel/acpi/realmode/wakeup.S
===================================================================arch/x86/kernel/acpi/realmode/wakeup.S +37
-1@@ -5,6 +5,7 @@ #include <asm/msr-index.h> #include <asm/page.h> #include <asm/pgtable.h> +#include <asm/processor-flags.h> .code16 .section ".header", "a"@@ -24,6 +25,11 @@ pmode_gdt: .quad 0 realmode_flags: .long 0 real_magic: .long 0 trampoline_segment: .word 0 +_pad1: .byte 0 +wakeup_jmp: .byte 0xea /* ljmpw */ +wakeup_jmp_off: .word 3f +wakeup_jmp_seg: .word 0 +wakeup_gdt: .quad 0, 0, 0 signature: .long 0x51ee1111 .text@@ -34,11 +40,34 @@ _start: cli cld + /* Apparently some dimwit BIOS programmers don't know how to + program a PM to RM transition, and we might end up here with + junk in the data segment descriptor registers. The only way + to repair that is to go into PM and fix it ourselves... */ + movw $16, %cx + lgdtl %cs:wakeup_gdt + movl %cr0, %eax + orb $X86_CR0_PE, %al + movl %eax, %cr0 + jmp 1f +1: ljmpw $8, $2f +2: + movw %cx, %ds + movw %cx, %es + movw %cx, %ss + movw %cx, %fs + movw %cx, %gs + + andb $~X86_CR0_PE, %al + movl %eax, %cr0 + jmp wakeup_jmp +3: /* Set up segments */ movw %cs, %ax movw %ax, %ds movw %ax, %es movw %ax, %ss + lidtl wakeup_idt movl $wakeup_stack_end, %esp@@ -98,7 +127,14 @@ bogus_real_magic: jmp 1b .data - .balign 4 + .balign 8 + + /* This is the standard real-mode IDT */ +wakeup_idt: + .word 0xffff /* limit */ + .long 0 /* address */ + .word 0 + .globl HEAP, heap_end HEAP: .long wakeup_heapIndex:
linux-2.6/arch/x86/kernel/acpi/realmode/wakeup.h
===================================================================arch/x86/kernel/acpi/realmode/wakeup.h +5
-0@@ -24,6 +24,11 @@ struct wakeup_header {u32 realmode_flags;u32 real_magic;u16 trampoline_segment;/* segment with trampoline code, 64-bit only */ +u8 _pad1; +u8 wakeup_jmp; +u16 wakeup_jmp_off; +u16 wakeup_jmp_seg; +u64 wakeup_gdt[3 ];u32 signature;/* To check we have correct structure */ } __attribute__((__packed__));Index:
linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================arch/x86/kernel/acpi/sleep.c +15
-1@@ -50,6 +50,20 @@ int acpi_save_state_mem(void) header->video_mode = saved_video_mode; + header->wakeup_jmp_seg = acpi_wakeup_address >>4 ; +/* GDT[0]: GDT self-pointer */ + header->wakeup_gdt[0 ] = + (u64)(sizeof (header->wakeup_gdt) -1 ) + + ((u64)(acpi_wakeup_address + + ((char *)&header->wakeup_gdt - (char *)acpi_realmode)) + <<16 ); +/* GDT[1]: real-mode-like code segment */ + header->wakeup_gdt[1 ] = (0x009bULL <<40 ) + + ((u64 )acpi_wakeup_address <<16 ) +0xffff ; +/* GDT[2]: real-mode-like data segment */ + header->wakeup_gdt[2 ] = (0x0093ULL <<40 ) + + ((u64 )acpi_wakeup_address <<16 ) +0xffff ; +#ifndef CONFIG_64BIT store_gdt ((struct desc_ptr *)&header->pmode_gdt);@@ -111,7 +125,7 @@ void __init acpi_reserve_bootmem(void)return ; } - acpi_wakeup_address = acpi_realmode; + acpi_wakeup_address =virt_to_phys ((void *)acpi_realmode); }Index:
linux-2.6/drivers/acpi/sleep/main.c
===================================================================drivers/acpi/sleep/main.c +2
-3@@ -32,9 +32,8 @@ static int acpi_sleep_prepare(u32 acpi_sif (!acpi_wakeup_address) {return -EFAULT ; } -acpi_set_firmware_waking_vector ((acpi_physical_address ) -virt_to_phys ((void *) - acpi_wakeup_address)); +acpi_set_firmware_waking_vector ( + (acpi_physical_address )acpi_wakeup_address); }ACPI_FLUSH_CPU_CACHE ();
Applied.
thanks,
-Len
Quoted 183 lines · Rafael J. Wysocki
Hi,
The patch below fixes the regression described at
http://bugzilla.kernel.org/show_bug.cgi?id=10927
which is caused by the fact that some BIOSes call the kernel's resume code with post-protected mode garbage in segment registers.Apart from Dell laptops referred to in the chagelog it has a potential to fix some other systems on which resume from suspend to RAM fails in a mysterious way and the probability of it breaking things is rather small, so IMO it would be nice to have in 2.6.26.
Thanks,
Rafael---
From: H. Peter Anvin <[email protected]>x86 ACPI: normalize segment descriptor register on resume
Some Dell laptops enter resume with apparent garbage in the segment descriptor registers (almost certainly the result of a botched transition from protected to real mode.) The only way to clean that up is to enter protected mode ourselves and clean out the descriptor registers.
This fixes resume on Dell XPS M1210 and Dell D620.
Reference: http://bugzilla.kernel.org/show_bug.cgi?id=10927
Signed-off-by H. Peter Anvin <[email protected]>Tested-by Kirill A. Shutemov <[email protected]>Signed-off-by Rafael J. Wysocki <[email protected]>--- arch/x86/kernel/acpi/realmode/wakeup.S | 38 ++++++++++++++++++++++++++++++++- arch/x86/kernel/acpi/realmode/wakeup.h | 5 ++++ arch/x86/kernel/acpi/sleep.c | 16 +++++++++++++ drivers/acpi/sleep/main.c | 5 +--- 4 files changed, 59 insertions(+), 5 deletions(-)Index:
linux-2.6/arch/x86/kernel/acpi/realmode/wakeup.S
===================================================================arch/x86/kernel/acpi/realmode/wakeup.S +37
-1@@ -5,6 +5,7 @@ #include <asm/msr-index.h> #include <asm/page.h> #include <asm/pgtable.h> +#include <asm/processor-flags.h> .code16 .section ".header", "a"@@ -24,6 +25,11 @@ pmode_gdt: .quad 0 realmode_flags: .long 0 real_magic: .long 0 trampoline_segment: .word 0 +_pad1: .byte 0 +wakeup_jmp: .byte 0xea /* ljmpw */ +wakeup_jmp_off: .word 3f +wakeup_jmp_seg: .word 0 +wakeup_gdt: .quad 0, 0, 0 signature: .long 0x51ee1111 .text@@ -34,11 +40,34 @@ _start: cli cld + /* Apparently some dimwit BIOS programmers don't know how to + program a PM to RM transition, and we might end up here with + junk in the data segment descriptor registers. The only way + to repair that is to go into PM and fix it ourselves... */ + movw $16, %cx + lgdtl %cs:wakeup_gdt + movl %cr0, %eax + orb $X86_CR0_PE, %al + movl %eax, %cr0 + jmp 1f +1: ljmpw $8, $2f +2: + movw %cx, %ds + movw %cx, %es + movw %cx, %ss + movw %cx, %fs + movw %cx, %gs + + andb $~X86_CR0_PE, %al + movl %eax, %cr0 + jmp wakeup_jmp +3: /* Set up segments */ movw %cs, %ax movw %ax, %ds movw %ax, %es movw %ax, %ss + lidtl wakeup_idt movl $wakeup_stack_end, %esp@@ -98,7 +127,14 @@ bogus_real_magic: jmp 1b .data - .balign 4 + .balign 8 + + /* This is the standard real-mode IDT */ +wakeup_idt: + .word 0xffff /* limit */ + .long 0 /* address */ + .word 0 + .globl HEAP, heap_end HEAP: .long wakeup_heapIndex:
linux-2.6/arch/x86/kernel/acpi/realmode/wakeup.h
===================================================================arch/x86/kernel/acpi/realmode/wakeup.h +5
-0@@ -24,6 +24,11 @@ struct wakeup_header {u32 realmode_flags;u32 real_magic;u16 trampoline_segment;/* segment with trampoline code, 64-bit only */ +u8 _pad1; +u8 wakeup_jmp; +u16 wakeup_jmp_off; +u16 wakeup_jmp_seg; +u64 wakeup_gdt[3 ];u32 signature;/* To check we have correct structure */ } __attribute__((__packed__));Index:
linux-2.6/arch/x86/kernel/acpi/sleep.c
===================================================================arch/x86/kernel/acpi/sleep.c +15
-1@@ -50,6 +50,20 @@ int acpi_save_state_mem(void) header->video_mode = saved_video_mode; + header->wakeup_jmp_seg = acpi_wakeup_address >>4 ; +/* GDT[0]: GDT self-pointer */ + header->wakeup_gdt[0 ] = + (u64)(sizeof (header->wakeup_gdt) -1 ) + + ((u64)(acpi_wakeup_address + + ((char *)&header->wakeup_gdt - (char *)acpi_realmode)) + <<16 ); +/* GDT[1]: real-mode-like code segment */ + header->wakeup_gdt[1 ] = (0x009bULL <<40 ) + + ((u64 )acpi_wakeup_address <<16 ) +0xffff ; +/* GDT[2]: real-mode-like data segment */ + header->wakeup_gdt[2 ] = (0x0093ULL <<40 ) + + ((u64 )acpi_wakeup_address <<16 ) +0xffff ; +#ifndef CONFIG_64BIT store_gdt ((struct desc_ptr *)&header->pmode_gdt);@@ -111,7 +125,7 @@ void __init acpi_reserve_bootmem(void)return ; } - acpi_wakeup_address = acpi_realmode; + acpi_wakeup_address =virt_to_phys ((void *)acpi_realmode); }Index:
linux-2.6/drivers/acpi/sleep/main.c
===================================================================drivers/acpi/sleep/main.c +2
-3@@ -32,9 +32,8 @@ static int acpi_sleep_prepare(u32 acpi_sif (!acpi_wakeup_address) {return -EFAULT ; } -acpi_set_firmware_waking_vector ((acpi_physical_address ) -virt_to_phys ((void *) - acpi_wakeup_address)); +acpi_set_firmware_waking_vector ( + (acpi_physical_address )acpi_wakeup_address); }ACPI_FLUSH_CPU_CACHE ();