-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
virt_mshv_vtl: Share common processing between poll_apic implementations #630
Open
smalis-msft
wants to merge
3
commits into
microsoft:main
Choose a base branch
from
smalis-msft:share-apic-poll
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#![cfg(guest_arch = "x86_64")] | ||
|
||
use super::LapicState; | ||
use super::UhRunVpError; | ||
use hcl::GuestVtl; | ||
use virt::vp::MpState; | ||
use virt_support_apic::ApicWork; | ||
|
||
pub(crate) trait ApicBacking { | ||
fn handle_init(&mut self, vtl: GuestVtl) -> Result<(), UhRunVpError>; | ||
fn handle_sipi(&mut self, vtl: GuestVtl, vector: u8) -> Result<(), UhRunVpError>; | ||
fn handle_nmi(&mut self, vtl: GuestVtl) -> Result<(), UhRunVpError>; | ||
fn handle_interrupt(&mut self, vtl: GuestVtl, vector: u8) -> Result<(), UhRunVpError>; | ||
fn handle_extint(&mut self, vtl: GuestVtl) -> Result<(), UhRunVpError>; | ||
} | ||
|
||
pub(crate) fn poll_apic_core<T: ApicBacking>( | ||
processor: &mut T, | ||
scan: impl Fn(&mut T) -> ApicWork, | ||
proxy_irr: impl Fn(&mut T) -> Option<[u32; 8]>, | ||
lapic_access: impl Fn(&mut T) -> &mut LapicState, | ||
vtl1_enabled: impl Fn(&mut T) -> bool, | ||
vtl: GuestVtl, | ||
) -> Result<(), UhRunVpError> { | ||
// Check for interrupt requests from the host and kernel offload. | ||
if vtl == GuestVtl::Vtl0 { | ||
if let Some(irr) = proxy_irr(processor) { | ||
// We can't put the interrupts directly into offload (where supported) because we might need | ||
// to clear the tmr state. This can happen if a vector was previously used for a level | ||
// triggered interrupt, and is now being used for an edge-triggered interrupt. | ||
lapic_access(processor).lapic.request_fixed_interrupts(irr); | ||
} | ||
} | ||
|
||
let ApicWork { | ||
init, | ||
extint, | ||
sipi, | ||
nmi, | ||
interrupt, | ||
} = scan(processor); | ||
|
||
// An INIT/SIPI targeted at a VP with more than one guest VTL enabled is ignored. | ||
// Check VTL enablement inside each block to avoid taking a lock on the hot path, | ||
// INIT and SIPI are quite cold. | ||
if init { | ||
if !vtl1_enabled(processor) { | ||
processor.handle_init(vtl)?; | ||
} | ||
} | ||
|
||
if let Some(vector) = sipi { | ||
if !vtl1_enabled(processor) { | ||
processor.handle_sipi(vtl, vector)?; | ||
} | ||
} | ||
|
||
// Interrupts are ignored while waiting for SIPI. | ||
let lapic = lapic_access(processor); | ||
if lapic.activity != MpState::WaitForSipi { | ||
if nmi || lapic.nmi_pending { | ||
lapic.nmi_pending = true; | ||
processor.handle_nmi(vtl)?; | ||
} | ||
|
||
if let Some(vector) = interrupt { | ||
processor.handle_interrupt(vtl, vector)?; | ||
} | ||
|
||
if extint { | ||
processor.handle_extint(vtl)?; | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
|
||
//! Processor support for SNP partitions. | ||
|
||
use super::apic::ApicBacking; | ||
use super::from_seg; | ||
use super::hardware_cvm; | ||
use super::private::BackingParams; | ||
|
@@ -52,7 +53,6 @@ use virt::Processor; | |
use virt::VpHaltReason; | ||
use virt::VpIndex; | ||
use virt_support_apic::ApicClient; | ||
use virt_support_apic::ApicWork; | ||
use virt_support_x86emu::emulate::emulate_io; | ||
use virt_support_x86emu::emulate::emulate_translate_gva; | ||
use virt_support_x86emu::emulate::EmulatorSupport as X86EmulatorSupport; | ||
|
@@ -392,61 +392,22 @@ impl BackingPrivate for SnpBacked { | |
vtl: GuestVtl, | ||
scan_irr: bool, | ||
) -> Result<(), UhRunVpError> { | ||
// Check for interrupt requests from the host. | ||
// TODO SNP GUEST VSM supporting VTL 1 proxy irrs requires kernel changes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment (and the corresponding one in TDX) are gone now, as John and I decided that we don't plan on implementing this in the near future. Just doesn't seem to be worthwhile. |
||
if vtl == GuestVtl::Vtl0 { | ||
if let Some(irr) = this.runner.proxy_irr() { | ||
// TODO SNP: filter proxy IRRs. | ||
this.backing.cvm.lapics[vtl] | ||
.lapic | ||
.request_fixed_interrupts(irr); | ||
} | ||
} | ||
|
||
// Clear any pending interrupt. | ||
this.runner.vmsa_mut(vtl).v_intr_cntrl_mut().set_irq(false); | ||
|
||
let ApicWork { | ||
init, | ||
extint, | ||
sipi, | ||
nmi, | ||
interrupt, | ||
} = this.backing.cvm.lapics[vtl] | ||
.lapic | ||
.scan(&mut this.vmtime, scan_irr); | ||
|
||
// An INIT/SIPI targeted at a VP with more than one guest VTL enabled is ignored. | ||
// Check VTL enablement inside each block to avoid taking a lock on the hot path, | ||
// INIT and SIPI are quite cold. | ||
if init { | ||
if !*this.inner.hcvm_vtl1_enabled.lock() { | ||
this.handle_init(vtl)?; | ||
} | ||
} | ||
|
||
if let Some(vector) = sipi { | ||
if !*this.inner.hcvm_vtl1_enabled.lock() { | ||
this.handle_sipi(vtl, vector)?; | ||
} | ||
} | ||
|
||
// Interrupts are ignored while waiting for SIPI. | ||
if this.backing.cvm.lapics[vtl].activity != MpState::WaitForSipi { | ||
if nmi { | ||
this.handle_nmi(vtl); | ||
} | ||
|
||
if let Some(vector) = interrupt { | ||
this.handle_interrupt(vtl, vector); | ||
} | ||
|
||
if extint { | ||
tracelimit::warn_ratelimited!("extint not supported"); | ||
} | ||
} | ||
|
||
Ok(()) | ||
// TODO SNP: filter proxy IRRs. | ||
super::apic::poll_apic_core( | ||
this, | ||
|this| { | ||
this.backing.cvm.lapics[vtl] | ||
.lapic | ||
.scan(&mut this.vmtime, scan_irr) | ||
}, | ||
|this| this.runner.proxy_irr(), | ||
|this| &mut this.backing.cvm.lapics[vtl], | ||
|this| *this.inner.hcvm_vtl1_enabled.lock(), | ||
vtl, | ||
) | ||
} | ||
|
||
fn request_extint_readiness(_this: &mut UhProcessor<'_, Self>) { | ||
|
@@ -773,17 +734,18 @@ impl<T> HypercallIo for GhcbEnlightenedHypercall<'_, '_, '_, T> { | |
} | ||
} | ||
|
||
impl UhProcessor<'_, SnpBacked> { | ||
fn handle_interrupt(&mut self, vtl: GuestVtl, vector: u8) { | ||
impl ApicBacking for UhProcessor<'_, SnpBacked> { | ||
fn handle_interrupt(&mut self, vtl: GuestVtl, vector: u8) -> Result<(), UhRunVpError> { | ||
let mut vmsa = self.runner.vmsa_mut(vtl); | ||
vmsa.v_intr_cntrl_mut().set_vector(vector); | ||
vmsa.v_intr_cntrl_mut().set_priority((vector >> 4).into()); | ||
vmsa.v_intr_cntrl_mut().set_ignore_tpr(false); | ||
vmsa.v_intr_cntrl_mut().set_irq(true); | ||
self.backing.cvm.lapics[vtl].activity = MpState::Running; | ||
Ok(()) | ||
} | ||
|
||
fn handle_nmi(&mut self, vtl: GuestVtl) { | ||
fn handle_nmi(&mut self, vtl: GuestVtl) -> Result<(), UhRunVpError> { | ||
// TODO SNP: support virtual NMI injection | ||
// For now, just inject an NMI and hope for the best. | ||
// Don't forget to update handle_cross_vtl_interrupts if this code changes. | ||
|
@@ -795,6 +757,7 @@ impl UhProcessor<'_, SnpBacked> { | |
.with_valid(true), | ||
); | ||
self.backing.cvm.lapics[vtl].activity = MpState::Running; | ||
Ok(()) | ||
} | ||
|
||
fn handle_init(&mut self, vtl: GuestVtl) -> Result<(), UhRunVpError> { | ||
|
@@ -822,6 +785,13 @@ impl UhProcessor<'_, SnpBacked> { | |
Ok(()) | ||
} | ||
|
||
fn handle_extint(&mut self, vtl: GuestVtl) -> Result<(), UhRunVpError> { | ||
tracelimit::warn_ratelimited!(?vtl, "extint not supported"); | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl UhProcessor<'_, SnpBacked> { | ||
fn handle_synic_deliverable_exit(&mut self) { | ||
let message = hvdef::HvX64SynicSintDeliverableMessage::ref_from_prefix( | ||
self.runner.exit_message().payload(), | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These closures could all move onto ApicBacking if we want, just creates a larger diff.