Skip to content

Commit

Permalink
Merge pull request #229 from joergroedel/gdt-tss-fix
Browse files Browse the repository at this point in the history
SVSM/cpu/gdt: Fix boot issue around TSS loading in release builds
  • Loading branch information
joergroedel authored Jan 26, 2024
2 parents c6bd164 + 45389df commit 393c5f4
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/cpu/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,27 @@ impl GDT {
}
}

fn set_tss_entry(&mut self, desc0: GDTEntry, desc1: GDTEntry) {
unsafe fn set_tss_entry(&mut self, desc0: GDTEntry, desc1: GDTEntry) {
let idx = (SVSM_TSS / 8) as usize;

self.entries[idx] = desc0;
self.entries[idx + 1] = desc1;
}
let tss_entries = &self.entries[idx..idx + 1].as_mut_ptr();

fn clear_tss_entry(&mut self) {
let idx = (SVSM_TSS / 8) as usize;
tss_entries.add(0).write_volatile(desc0);
tss_entries.add(1).write_volatile(desc1);
}

self.entries[idx] = GDTEntry::null();
self.entries[idx + 1] = GDTEntry::null();
unsafe fn clear_tss_entry(&mut self) {
self.set_tss_entry(GDTEntry::null(), GDTEntry::null());
}

pub fn load_tss(&mut self, tss: &X86Tss) {
let (desc0, desc1) = tss.to_gdt_entry();

self.set_tss_entry(desc0, desc1);
unsafe {
self.set_tss_entry(desc0, desc1);
asm!("ltr %ax", in("ax") SVSM_TSS, options(att_syntax));
self.clear_tss_entry()
}
self.clear_tss_entry()
}
}

Expand Down

0 comments on commit 393c5f4

Please sign in to comment.