Skip to content

Commit

Permalink
cpu: process pending #HV events when enabling interrupts
Browse files Browse the repository at this point in the history
Interrupts delivered via #HV are ignored when EFLAGS.IF=0.  When
enabling interrupts, the #HV doorbell page must be checked for pending
events that were suppressed while interrupts were disabled so that they
do not remain pending indefinitely.

Signed-off-by: Jon Lange <[email protected]>
  • Loading branch information
msft-jlange committed Sep 27, 2024
1 parent 5e08626 commit d1fa0d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions kernel/src/cpu/irq_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//
// Author: Joerg Roedel <[email protected]>

use crate::cpu::percpu::this_cpu;
use crate::cpu::{irqs_disable, irqs_enable};
use core::arch::asm;
use core::marker::PhantomData;
Expand Down Expand Up @@ -32,6 +33,12 @@ pub unsafe fn raw_irqs_disable() {
#[inline(always)]
pub unsafe fn raw_irqs_enable() {
asm!("sti", options(att_syntax, preserves_flags, nomem));

// Now that interrupts are enabled, process any #HV events that may be
// pending.
if let Some(doorbell) = this_cpu().hv_doorbell() {
doorbell.process_if_required();
}
}

/// Query IRQ state on current CPU
Expand Down
7 changes: 7 additions & 0 deletions kernel/src/sev/hv_doorbell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ impl HVDoorbell {
// is performed.
}

pub fn process_if_required(&self) {
let flags = HVDoorbellFlags::from(self.flags.load(Ordering::Relaxed));
if flags.no_further_signal() {
self.process_pending_events();
}
}

pub fn no_eoi_required(&self) -> bool {
// Check to see if the "no EOI required" flag is set to determine
// whether an explicit EOI can be avoided.
Expand Down

0 comments on commit d1fa0d3

Please sign in to comment.