Skip to content

Commit

Permalink
cpu: implement inter-processor interrupts
Browse files Browse the repository at this point in the history
This change provides routines that enable one processor to send a
message to one or other processors to perform work.

Signed-off-by: Jon Lange <[email protected]>
  • Loading branch information
msft-jlange committed Dec 21, 2024
1 parent 80629ec commit 5d94146
Show file tree
Hide file tree
Showing 8 changed files with 708 additions and 10 deletions.
6 changes: 3 additions & 3 deletions kernel/src/cpu/apic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const APIC_REGISTER_ICR: u64 = 0x830;
const APIC_REGISTER_SELF_IPI: u64 = 0x83F;

#[derive(Debug, PartialEq)]
enum IcrDestFmt {
pub enum IcrDestFmt {
Dest = 0,
OnlySelf = 1,
AllWithSelf = 2,
Expand All @@ -55,7 +55,7 @@ impl IcrDestFmt {
}

#[derive(Debug, PartialEq)]
enum IcrMessageType {
pub enum IcrMessageType {
Fixed = 0,
Unknown = 3,
Nmi = 4,
Expand All @@ -81,7 +81,7 @@ impl IcrMessageType {
}

#[bitfield(u64)]
struct ApicIcr {
pub struct ApicIcr {
pub vector: u8,
#[bits(3)]
pub message_type: IcrMessageType,
Expand Down
1 change: 1 addition & 0 deletions kernel/src/cpu/idt/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub const VC_VECTOR: usize = 29;
pub const SX_VECTOR: usize = 30;

pub const INT_INJ_VECTOR: usize = 0x50;
pub const IPI_VECTOR: usize = 0xE0;

bitflags::bitflags! {
/// Page fault error code flags.
Expand Down
3 changes: 3 additions & 0 deletions kernel/src/cpu/idt/entry.S
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,7 @@ default_entry_no_ist name=int80 handler=system_call error_code=0 vector=0x80
// Interrupt injection vector
irq_entry name=int_inj vector=0x50

// IPI vector.
irq_entry name=ipi vector=0xE0

.popsection
19 changes: 13 additions & 6 deletions kernel/src/cpu/idt/svsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use super::super::tss::IST_DF;
use super::super::vc::handle_vc_exception;
use super::common::{
idt_mut, user_mode, IdtEntry, IdtEventType, PageFaultError, AC_VECTOR, BP_VECTOR, BR_VECTOR,
CP_VECTOR, DB_VECTOR, DE_VECTOR, DF_VECTOR, GP_VECTOR, HV_VECTOR, INT_INJ_VECTOR, MCE_VECTOR,
MF_VECTOR, NMI_VECTOR, NM_VECTOR, NP_VECTOR, OF_VECTOR, PF_VECTOR, SS_VECTOR, SX_VECTOR,
TS_VECTOR, UD_VECTOR, VC_VECTOR, XF_VECTOR,
CP_VECTOR, DB_VECTOR, DE_VECTOR, DF_VECTOR, GP_VECTOR, HV_VECTOR, INT_INJ_VECTOR, IPI_VECTOR,
MCE_VECTOR, MF_VECTOR, NMI_VECTOR, NM_VECTOR, NP_VECTOR, OF_VECTOR, PF_VECTOR, SS_VECTOR,
SX_VECTOR, TS_VECTOR, UD_VECTOR, VC_VECTOR, XF_VECTOR,
};
use crate::address::VirtAddr;
use crate::cpu::irq_state::{raw_get_tpr, raw_set_tpr, tpr_from_vector};
Expand Down Expand Up @@ -56,6 +56,7 @@ extern "C" {
fn asm_entry_sx();
fn asm_entry_int80();
fn asm_entry_irq_int_inj();
fn asm_entry_irq_ipi();

pub static mut HV_DOORBELL_ADDR: usize;
}
Expand Down Expand Up @@ -92,6 +93,7 @@ pub fn early_idt_init() {

// Interupts
idt.set_entry(0x80, IdtEntry::user_entry(asm_entry_int80));
idt.set_entry(IPI_VECTOR, IdtEntry::entry(asm_entry_irq_ipi));

// Load IDT
idt.load();
Expand Down Expand Up @@ -363,9 +365,14 @@ pub fn common_isr_handler(vector: usize) {
let cpu = this_cpu();
cpu.irqs_enable();

// Treat any unhandled interrupt as a spurious interrupt. Interrupt
// injection requests currently require no processing; they occur simply
// to ensure an exit from the guest.
// Process the requested interrupt vector.
match vector {
IPI_VECTOR => this_cpu().handle_ipi_interrupt(),
_ => {
// Ignore all unrecognized interrupt vectors and treat them as
// spurious interrupts.
}
}

// Disable interrupts before restoring TPR.
cpu.irqs_disable();
Expand Down
Loading

0 comments on commit 5d94146

Please sign in to comment.