Skip to content

Commit

Permalink
task: create new tasks with interrupts disabled
Browse files Browse the repository at this point in the history
The scheduler assumes that every new task initially executes with
interrupts disabled.  Thus, every new task needs to have its initial
stack frame created with interrupts disabled.  In addition, the initial
state of every new task should be consistent and not related to the
current flags disposition at the time the task is created, so the
initial task creation should use a constant flags value instead of the
current flags.

Signed-off-by: Jon Lange <[email protected]>
  • Loading branch information
msft-jlange committed Oct 12, 2024
1 parent 0242978 commit bf964e2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions kernel/src/task/tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use core::sync::atomic::{AtomicU32, Ordering};

use crate::address::{Address, VirtAddr};
use crate::cpu::idt::svsm::return_new_task;
use crate::cpu::msr::read_flags;
use crate::cpu::percpu::PerCpu;
use crate::cpu::X86ExceptionContext;
use crate::cpu::{irqs_enable, X86GeneralRegs};
Expand Down Expand Up @@ -351,8 +350,11 @@ impl Task {
.try_into()
.unwrap();
let task_context = stack_ptr.offset(-tc_offset).cast::<TaskContext>();
// flags
(*task_context).flags = read_flags();
// The processor flags must always be in a default state, unrelated
// to the flags of the caller. In particular, interrupts must be
// disabled because the task switch code expects to execute a new
// task with interrupts disabled.
(*task_context).flags = 2;
// ret_addr
(*task_context).regs.rdi = entry as *const () as usize;
(*task_context).ret_addr = run_kernel_task as *const () as u64;
Expand Down

0 comments on commit bf964e2

Please sign in to comment.