mirror of
https://github.com/google/alioth.git
synced 2024-11-28 09:26:21 +00:00
feat(kvm/aarch64)!: assign a DevID to MsiSender
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
This commit is contained in:
parent
3160823378
commit
6ca2e25b89
5 changed files with 35 additions and 6 deletions
|
@ -266,7 +266,10 @@ pub trait Vm {
|
||||||
type IoeventFdRegistry: IoeventFdRegistry;
|
type IoeventFdRegistry: IoeventFdRegistry;
|
||||||
fn create_vcpu(&self, id: u32) -> Result<Self::Vcpu, Error>;
|
fn create_vcpu(&self, id: u32) -> Result<Self::Vcpu, Error>;
|
||||||
fn create_irq_sender(&self, pin: u8) -> Result<Self::IrqSender, Error>;
|
fn create_irq_sender(&self, pin: u8) -> Result<Self::IrqSender, Error>;
|
||||||
fn create_msi_sender(&self) -> Result<Self::MsiSender>;
|
fn create_msi_sender(
|
||||||
|
&self,
|
||||||
|
#[cfg(target_arch = "aarch64")] devid: u32,
|
||||||
|
) -> Result<Self::MsiSender>;
|
||||||
fn create_vm_memory(&mut self) -> Result<Self::Memory, Error>;
|
fn create_vm_memory(&mut self) -> Result<Self::Memory, Error>;
|
||||||
fn create_ioeventfd_registry(&self) -> Result<Self::IoeventFdRegistry>;
|
fn create_ioeventfd_registry(&self) -> Result<Self::IoeventFdRegistry>;
|
||||||
fn stop_vcpu<T>(id: u32, handle: &JoinHandle<T>) -> Result<(), Error>;
|
fn stop_vcpu<T>(id: u32, handle: &JoinHandle<T>) -> Result<(), Error>;
|
||||||
|
|
|
@ -236,7 +236,7 @@ impl Vm for HvfVm {
|
||||||
fn create_ioeventfd_registry(&self) -> Result<Self::IoeventFdRegistry> {
|
fn create_ioeventfd_registry(&self) -> Result<Self::IoeventFdRegistry> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn create_msi_sender(&self) -> Result<Self::MsiSender> {
|
fn create_msi_sender(&self, _devid: u32) -> Result<Self::MsiSender> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
fn create_vcpu(&self, id: u32) -> Result<Self::Vcpu> {
|
fn create_vcpu(&self, id: u32) -> Result<Self::Vcpu> {
|
||||||
|
|
|
@ -428,13 +428,22 @@ impl<const N: usize> Debug for KvmIrqRouting<N> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct KvmMsiFlag: u32 {
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
const VALID_DEVID = 1 << 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug, Copy, Clone, Default)]
|
#[derive(Debug, Copy, Clone, Default)]
|
||||||
pub struct KvmMsi {
|
pub struct KvmMsi {
|
||||||
pub address_lo: u32,
|
pub address_lo: u32,
|
||||||
pub address_hi: u32,
|
pub address_hi: u32,
|
||||||
pub data: u32,
|
pub data: u32,
|
||||||
pub flags: u32,
|
pub flags: KvmMsiFlag,
|
||||||
pub devid: u32,
|
pub devid: u32,
|
||||||
pub pad: [u8; 12usize],
|
pub pad: [u8; 12usize],
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ use snafu::ResultExt;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use crate::arch::sev::{SnpPageType, SnpPolicy};
|
use crate::arch::sev::{SnpPageType, SnpPolicy};
|
||||||
use crate::ffi;
|
use crate::ffi;
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
use crate::hv::kvm::bindings::KvmMsiFlag;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use crate::hv::kvm::bindings::KVM_IRQCHIP_IOAPIC;
|
use crate::hv::kvm::bindings::KVM_IRQCHIP_IOAPIC;
|
||||||
use crate::hv::kvm::bindings::{
|
use crate::hv::kvm::bindings::{
|
||||||
|
@ -419,6 +421,8 @@ const MAX_GSI_ROUTES: usize = 256;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct KvmMsiSender {
|
pub struct KvmMsiSender {
|
||||||
vm: Arc<VmInner>,
|
vm: Arc<VmInner>,
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
devid: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MsiSender for KvmMsiSender {
|
impl MsiSender for KvmMsiSender {
|
||||||
|
@ -429,6 +433,10 @@ impl MsiSender for KvmMsiSender {
|
||||||
address_lo: addr as u32,
|
address_lo: addr as u32,
|
||||||
address_hi: (addr >> 32) as u32,
|
address_hi: (addr >> 32) as u32,
|
||||||
data,
|
data,
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
devid: self.devid,
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
flags: KvmMsiFlag::VALID_DEVID,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
unsafe { kvm_signal_msi(&self.vm, &kvm_msi) }.context(error::SendInterrupt)?;
|
unsafe { kvm_signal_msi(&self.vm, &kvm_msi) }.context(error::SendInterrupt)?;
|
||||||
|
@ -599,7 +607,10 @@ impl Vm for KvmVm {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_msi_sender(&self) -> Result<Self::MsiSender> {
|
fn create_msi_sender(
|
||||||
|
&self,
|
||||||
|
#[cfg(target_arch = "aarch64")] devid: u32,
|
||||||
|
) -> Result<Self::MsiSender> {
|
||||||
if self.vm.check_extension(KvmCap::SIGNAL_MSI)? == 0 {
|
if self.vm.check_extension(KvmCap::SIGNAL_MSI)? == 0 {
|
||||||
return error::Capability {
|
return error::Capability {
|
||||||
cap: "KVM_CAP_SIGNAL_MSI",
|
cap: "KVM_CAP_SIGNAL_MSI",
|
||||||
|
@ -608,6 +619,8 @@ impl Vm for KvmVm {
|
||||||
}
|
}
|
||||||
Ok(KvmMsiSender {
|
Ok(KvmMsiSender {
|
||||||
vm: self.vm.clone(),
|
vm: self.vm.clone(),
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
devid,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,6 +211,7 @@ where
|
||||||
D: Virtio,
|
D: Virtio,
|
||||||
{
|
{
|
||||||
let name = Arc::new(name);
|
let name = Arc::new(name);
|
||||||
|
let bdf = self.board.pci_bus.reserve(None, name.clone()).unwrap();
|
||||||
let dev = param.build(name.clone())?;
|
let dev = param.build(name.clone())?;
|
||||||
let registry = self.board.vm.create_ioeventfd_registry()?;
|
let registry = self.board.vm.create_ioeventfd_registry()?;
|
||||||
let virtio_dev = VirtioDevice::new(
|
let virtio_dev = VirtioDevice::new(
|
||||||
|
@ -220,11 +221,14 @@ where
|
||||||
®istry,
|
®istry,
|
||||||
self.board.config.coco.is_some(),
|
self.board.config.coco.is_some(),
|
||||||
)?;
|
)?;
|
||||||
let msi_sender = self.board.vm.create_msi_sender()?;
|
let msi_sender = self.board.vm.create_msi_sender(
|
||||||
|
#[cfg(target_arch = "aarch64")]
|
||||||
|
u32::from(bdf.0),
|
||||||
|
)?;
|
||||||
let dev = VirtioPciDevice::new(virtio_dev, msi_sender, registry)?;
|
let dev = VirtioPciDevice::new(virtio_dev, msi_sender, registry)?;
|
||||||
let dev = Arc::new(dev);
|
let dev = Arc::new(dev);
|
||||||
let pci_dev = PciDevice::new(name.clone(), dev.clone());
|
let pci_dev = PciDevice::new(name.clone(), dev.clone());
|
||||||
self.add_pci_dev(None, pci_dev)?;
|
self.add_pci_dev(Some(bdf), pci_dev)?;
|
||||||
Ok(dev)
|
Ok(dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue