mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-08 22:05:20 +00:00
vmm: interrupts: adjust set_gsi_routes
There is no point in manually dropping the lock for gsi_msi_routes then instantly grabbing it again in set_gsi_routes. Make set_gsi_routes take a reference to the routing hashmap instead. No functional change intended. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
4913acc05e
commit
7e130a65ba
@ -82,8 +82,8 @@ pub struct MsiInterruptGroup<E> {
|
|||||||
irq_routes: HashMap<InterruptIndex, InterruptRoute>,
|
irq_routes: HashMap<InterruptIndex, InterruptRoute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MsiInterruptGroupOps {
|
pub trait MsiInterruptGroupOps<E> {
|
||||||
fn set_gsi_routes(&self) -> Result<()>;
|
fn set_gsi_routes(&self, routes: &HashMap<u32, RoutingEntry<E>>) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait RoutingEntryExt {
|
pub trait RoutingEntryExt {
|
||||||
@ -112,7 +112,7 @@ impl<E> InterruptSourceGroup for MsiInterruptGroup<E>
|
|||||||
where
|
where
|
||||||
E: Send + Sync,
|
E: Send + Sync,
|
||||||
RoutingEntry<E>: RoutingEntryExt,
|
RoutingEntry<E>: RoutingEntryExt,
|
||||||
MsiInterruptGroup<E>: MsiInterruptGroupOps,
|
MsiInterruptGroup<E>: MsiInterruptGroupOps<E>,
|
||||||
{
|
{
|
||||||
fn enable(&self) -> Result<()> {
|
fn enable(&self) -> Result<()> {
|
||||||
for (_, route) in self.irq_routes.iter() {
|
for (_, route) in self.irq_routes.iter() {
|
||||||
@ -152,12 +152,9 @@ where
|
|||||||
fn update(&self, index: InterruptIndex, config: InterruptSourceConfig) -> Result<()> {
|
fn update(&self, index: InterruptIndex, config: InterruptSourceConfig) -> Result<()> {
|
||||||
if let Some(route) = self.irq_routes.get(&index) {
|
if let Some(route) = self.irq_routes.get(&index) {
|
||||||
let entry = RoutingEntry::<_>::make_entry(&self.vm, route.gsi, &config)?;
|
let entry = RoutingEntry::<_>::make_entry(&self.vm, route.gsi, &config)?;
|
||||||
self.gsi_msi_routes
|
let mut routes = self.gsi_msi_routes.lock().unwrap();
|
||||||
.lock()
|
routes.insert(route.gsi, *entry);
|
||||||
.unwrap()
|
return self.set_gsi_routes(&routes);
|
||||||
.insert(route.gsi, *entry);
|
|
||||||
|
|
||||||
return self.set_gsi_routes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(io::Error::new(
|
Err(io::Error::new(
|
||||||
@ -168,8 +165,8 @@ where
|
|||||||
|
|
||||||
fn mask(&self, index: InterruptIndex) -> Result<()> {
|
fn mask(&self, index: InterruptIndex) -> Result<()> {
|
||||||
if let Some(route) = self.irq_routes.get(&index) {
|
if let Some(route) = self.irq_routes.get(&index) {
|
||||||
let mut gsi_msi_routes = self.gsi_msi_routes.lock().unwrap();
|
let mut routes = self.gsi_msi_routes.lock().unwrap();
|
||||||
if let Some(entry) = gsi_msi_routes.get_mut(&route.gsi) {
|
if let Some(entry) = routes.get_mut(&route.gsi) {
|
||||||
entry.masked = true;
|
entry.masked = true;
|
||||||
} else {
|
} else {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
@ -177,9 +174,7 @@ where
|
|||||||
format!("mask: No existing route for interrupt index {}", index),
|
format!("mask: No existing route for interrupt index {}", index),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Drop the guard because set_gsi_routes will try to take the lock again.
|
self.set_gsi_routes(&routes)?;
|
||||||
drop(gsi_msi_routes);
|
|
||||||
self.set_gsi_routes()?;
|
|
||||||
return route.disable(&self.vm);
|
return route.disable(&self.vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +186,8 @@ where
|
|||||||
|
|
||||||
fn unmask(&self, index: InterruptIndex) -> Result<()> {
|
fn unmask(&self, index: InterruptIndex) -> Result<()> {
|
||||||
if let Some(route) = self.irq_routes.get(&index) {
|
if let Some(route) = self.irq_routes.get(&index) {
|
||||||
let mut gsi_msi_routes = self.gsi_msi_routes.lock().unwrap();
|
let mut routes = self.gsi_msi_routes.lock().unwrap();
|
||||||
if let Some(entry) = gsi_msi_routes.get_mut(&route.gsi) {
|
if let Some(entry) = routes.get_mut(&route.gsi) {
|
||||||
entry.masked = false;
|
entry.masked = false;
|
||||||
} else {
|
} else {
|
||||||
return Err(io::Error::new(
|
return Err(io::Error::new(
|
||||||
@ -200,9 +195,7 @@ where
|
|||||||
format!("mask: No existing route for interrupt index {}", index),
|
format!("mask: No existing route for interrupt index {}", index),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
// Drop the guard because set_gsi_routes will try to take the lock again.
|
self.set_gsi_routes(&routes)?;
|
||||||
drop(gsi_msi_routes);
|
|
||||||
self.set_gsi_routes()?;
|
|
||||||
return route.enable(&self.vm);
|
return route.enable(&self.vm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -297,7 +290,7 @@ impl<E> InterruptManager for MsiInterruptManager<E>
|
|||||||
where
|
where
|
||||||
E: Send + Sync + 'static,
|
E: Send + Sync + 'static,
|
||||||
RoutingEntry<E>: RoutingEntryExt,
|
RoutingEntry<E>: RoutingEntryExt,
|
||||||
MsiInterruptGroup<E>: MsiInterruptGroupOps,
|
MsiInterruptGroup<E>: MsiInterruptGroupOps<E>,
|
||||||
{
|
{
|
||||||
type GroupConfig = MsiIrqGroupConfig;
|
type GroupConfig = MsiIrqGroupConfig;
|
||||||
|
|
||||||
@ -370,11 +363,13 @@ pub mod kvm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MsiInterruptGroupOps for KvmMsiInterruptGroup {
|
impl MsiInterruptGroupOps<kvm_irq_routing_entry> for KvmMsiInterruptGroup {
|
||||||
fn set_gsi_routes(&self) -> Result<()> {
|
fn set_gsi_routes(
|
||||||
let gsi_msi_routes = self.gsi_msi_routes.lock().unwrap();
|
&self,
|
||||||
|
routes: &HashMap<u32, RoutingEntry<kvm_irq_routing_entry>>,
|
||||||
|
) -> Result<()> {
|
||||||
let mut entry_vec: Vec<kvm_irq_routing_entry> = Vec::new();
|
let mut entry_vec: Vec<kvm_irq_routing_entry> = Vec::new();
|
||||||
for (_, entry) in gsi_msi_routes.iter() {
|
for (_, entry) in routes.iter() {
|
||||||
if entry.masked {
|
if entry.masked {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user