fix(virtio):修复了特定virtio设备环境下中断号重复错误,以及开机内核panic的bug (#881)

This commit is contained in:
曾俊 2024-09-06 19:56:49 +08:00 committed by GitHub
parent 2b7818e80e
commit 886ce28516
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 4 deletions

View File

@ -115,6 +115,7 @@ impl PciTransport {
/// - `device` - The PCI device structure for the VirtIO device. /// - `device` - The PCI device structure for the VirtIO device.
/// - `irq_handler` - An optional handler for the device's interrupt. If `None`, a default /// - `irq_handler` - An optional handler for the device's interrupt. If `None`, a default
/// handler `DefaultVirtioIrqHandler` will be used. /// handler `DefaultVirtioIrqHandler` will be used.
/// - `irq_number_offset` - Currently, this parameter is just simple make a offset to the irq number, cause it's not be allowed to have the same irq number within different device
#[allow(clippy::extra_unused_type_parameters)] #[allow(clippy::extra_unused_type_parameters)]
pub fn new<H: Hal>( pub fn new<H: Hal>(
device: &mut PciDeviceStructureGeneralDevice, device: &mut PciDeviceStructureGeneralDevice,
@ -140,8 +141,8 @@ impl PciTransport {
let irq_vector = standard_device.irq_vector_mut().unwrap(); let irq_vector = standard_device.irq_vector_mut().unwrap();
irq_vector.push(irq); irq_vector.push(irq);
standard_device standard_device
.irq_init(IRQ::PCI_IRQ_MSIX) .irq_init(IRQ::PCI_IRQ_MSIX | IRQ::PCI_IRQ_MSI)
.expect("IRQ init failed"); .ok_or(VirtioPciError::UnableToInitIrq)?;
// 中断相关信息 // 中断相关信息
let msg = PciIrqMsg { let msg = PciIrqMsg {
irq_common_message: IrqCommonMsg::init_from( irq_common_message: IrqCommonMsg::init_from(
@ -445,6 +446,8 @@ pub enum VirtioPciError {
/// `VIRTIO_PCI_CAP_NOTIFY_CFG` capability has a `notify_off_multiplier` that is not a multiple /// `VIRTIO_PCI_CAP_NOTIFY_CFG` capability has a `notify_off_multiplier` that is not a multiple
/// of 2. /// of 2.
InvalidNotifyOffMultiplier(u32), InvalidNotifyOffMultiplier(u32),
/// Unable to find capability such as MSIX or MSI.
UnableToInitIrq,
/// No valid `VIRTIO_PCI_CAP_ISR_CFG` capability was found. /// No valid `VIRTIO_PCI_CAP_ISR_CFG` capability was found.
MissingIsrConfig, MissingIsrConfig,
/// An IO BAR was provided rather than a memory BAR. /// An IO BAR was provided rather than a memory BAR.
@ -474,6 +477,7 @@ impl Display for VirtioPciError {
"PCI device vender ID {:#06x} was not the VirtIO vendor ID {:#06x}.", "PCI device vender ID {:#06x} was not the VirtIO vendor ID {:#06x}.",
vendor_id, VIRTIO_VENDOR_ID vendor_id, VIRTIO_VENDOR_ID
), ),
Self::UnableToInitIrq => write!(f, "Unable to find capability such as MSIX or MSI."),
Self::MissingCommonConfig => write!( Self::MissingCommonConfig => write!(
f, f,
"No valid `VIRTIO_PCI_CAP_COMMON_CFG` capability was found." "No valid `VIRTIO_PCI_CAP_COMMON_CFG` capability was found."

View File

@ -77,7 +77,8 @@ QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none"
QEMU_ACCELARATE="" QEMU_ACCELARATE=""
QEMU_ARGUMENT="" QEMU_ARGUMENT=""
QEMU_DEVICES="" QEMU_DEVICES=""
#这个变量为true则使用virtio磁盘
VIRTIO_BLK_DEVICE=false
# 如果qemu_accel不为空 # 如果qemu_accel不为空
if [ -n "${qemu_accel}" ]; then if [ -n "${qemu_accel}" ]; then
QEMU_ACCELARATE="-machine accel=${qemu_accel} -enable-kvm " QEMU_ACCELARATE="-machine accel=${qemu_accel} -enable-kvm "
@ -87,7 +88,13 @@ if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
QEMU_MACHINE=" -machine q35,memory-backend=${QEMU_MEMORY_BACKEND} " QEMU_MACHINE=" -machine q35,memory-backend=${QEMU_MEMORY_BACKEND} "
QEMU_CPU_FEATURES+="-cpu IvyBridge,apic,x2apic,+fpu,check,+vmx,${allflags}" QEMU_CPU_FEATURES+="-cpu IvyBridge,apic,x2apic,+fpu,check,+vmx,${allflags}"
QEMU_RTC_CLOCK+=" -rtc clock=host,base=localtime" QEMU_RTC_CLOCK+=" -rtc clock=host,base=localtime"
QEMU_DEVICES_DISK="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 " if [ ${VIRTIO_BLK_DEVICE} == false ]; then
QEMU_DEVICES_DISK+="-device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0 "
else
QEMU_DEVICES_DISK="-device virtio-blk-pci,drive=disk -device pci-bridge,chassis_nr=1,id=pci.1 -device pcie-root-port "
fi
else else
QEMU_MACHINE=" -machine virt,memory-backend=${QEMU_MEMORY_BACKEND} -cpu sifive-u54 " QEMU_MACHINE=" -machine virt,memory-backend=${QEMU_MEMORY_BACKEND} -cpu sifive-u54 "
QEMU_DEVICES_DISK="-device virtio-blk-device,drive=disk " QEMU_DEVICES_DISK="-device virtio-blk-device,drive=disk "