Skip to content

Commit

Permalink
amd64: Restore segmentation tables and registers also for boot CPU
Browse files Browse the repository at this point in the history
After resume from system suspend, the kernel idle thread ended up with
an incorrect code segment selector, 0x18 (LONG_CS from tramp-realmode.h)
instead of 0x08 (GDT_CODE_KERNEL).

Change-Id: I177d120c73ac090acda7ea5f523e9fe6ec931041
  • Loading branch information
gkotheim authored and kk-infra committed May 22, 2024
1 parent 2f0f81e commit b0bb083
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 31 deletions.
25 changes: 12 additions & 13 deletions src/kern/ia32/cpu-ia32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,20 +1610,19 @@ PUBLIC FIASCO_INIT_AND_PM
void
Cpu::pm_resume()
{
set_gdt();
set_ldt(0);

set_ds(Gdt::data_segment());
set_es(Gdt::data_segment());
set_ss(Gdt::gdt_data_kernel | Gdt::Selector_kernel);
set_fs(Gdt::gdt_data_user | Gdt::Selector_user);
set_gs(Gdt::gdt_data_user | Gdt::Selector_user);
set_cs();

// the boot CPU restores TSS in asm already
if (id() != Cpu_number::boot_cpu())
{
// the boot CPU restores some state in asm already
set_gdt();
set_ldt(0);
set_ds(Gdt::data_segment());
set_es(Gdt::data_segment());
set_ss(Gdt::gdt_data_kernel | Gdt::Selector_kernel);
set_fs(Gdt::gdt_data_user | Gdt::Selector_user);
set_gs(Gdt::gdt_data_user | Gdt::Selector_user);
set_cs();

set_tss();
}
set_tss();

if (_vendor == Vendor_intel)
Ia32_intel_microcode::load();
Expand Down
18 changes: 0 additions & 18 deletions src/kern/ia32/tramp-acpi.S
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,6 @@ _tramp_acpi_wakeup:
lidt _idt
lldt _ldt

#if 0
movw _fs, %ax
movw %ax, %fs
movw _gs, %ax
movw %ax, %gs
#endif

/* restore general purpose registers */
#ifdef CONFIG_AMD64
mov _sp, %rsp
Expand Down Expand Up @@ -136,10 +129,6 @@ _idt: .quad 0
.quad 0
_ldt: .quad 0
.quad 0
#if 0
_fs: .word 0
_gs: .word 0
#endif

_tr: .quad 0 /* task register */
.quad 0
Expand Down Expand Up @@ -192,13 +181,6 @@ acpi_save_cpu_and_suspend:
mov %cr4, %BX
mov %BX, _cr4

#if 0
movw %fs, %bx
movw %bx, _fs
movw %gs, %bx
movw %bx, _gs
#endif

str _tr
/* save descriptor table (registers) */
sgdt _gdt
Expand Down

0 comments on commit b0bb083

Please sign in to comment.