From 886ce28516f9e3e5940840d1ae64ec3e9c8875fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E4=BF=8A?= <110876916+ZZJJWarth@users.noreply.github.com> Date: Fri, 6 Sep 2024 19:56:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(virtio):=E4=BF=AE=E5=A4=8D=E4=BA=86?= =?UTF-8?q?=E7=89=B9=E5=AE=9Avirtio=E8=AE=BE=E5=A4=87=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E4=B8=8B=E4=B8=AD=E6=96=AD=E5=8F=B7=E9=87=8D=E5=A4=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=8C=E4=BB=A5=E5=8F=8A=E5=BC=80=E6=9C=BA=E5=86=85?= =?UTF-8?q?=E6=A0=B8panic=E7=9A=84bug=20(#881)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/src/driver/virtio/transport_pci.rs | 8 ++++++-- tools/run-qemu.sh | 11 +++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kernel/src/driver/virtio/transport_pci.rs b/kernel/src/driver/virtio/transport_pci.rs index 88f4fcab..07b687ba 100644 --- a/kernel/src/driver/virtio/transport_pci.rs +++ b/kernel/src/driver/virtio/transport_pci.rs @@ -115,6 +115,7 @@ impl PciTransport { /// - `device` - The PCI device structure for the VirtIO device. /// - `irq_handler` - An optional handler for the device's interrupt. If `None`, a default /// 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)] pub fn new( device: &mut PciDeviceStructureGeneralDevice, @@ -140,8 +141,8 @@ impl PciTransport { let irq_vector = standard_device.irq_vector_mut().unwrap(); irq_vector.push(irq); standard_device - .irq_init(IRQ::PCI_IRQ_MSIX) - .expect("IRQ init failed"); + .irq_init(IRQ::PCI_IRQ_MSIX | IRQ::PCI_IRQ_MSI) + .ok_or(VirtioPciError::UnableToInitIrq)?; // 中断相关信息 let msg = PciIrqMsg { 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 /// of 2. InvalidNotifyOffMultiplier(u32), + /// Unable to find capability such as MSIX or MSI. + UnableToInitIrq, /// No valid `VIRTIO_PCI_CAP_ISR_CFG` capability was found. MissingIsrConfig, /// 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}.", vendor_id, VIRTIO_VENDOR_ID ), + Self::UnableToInitIrq => write!(f, "Unable to find capability such as MSIX or MSI."), Self::MissingCommonConfig => write!( f, "No valid `VIRTIO_PCI_CAP_COMMON_CFG` capability was found." diff --git a/tools/run-qemu.sh b/tools/run-qemu.sh index f4efd086..ae65aa67 100644 --- a/tools/run-qemu.sh +++ b/tools/run-qemu.sh @@ -77,7 +77,8 @@ QEMU_DRIVE="id=disk,file=${QEMU_DISK_IMAGE},if=none" QEMU_ACCELARATE="" QEMU_ARGUMENT="" QEMU_DEVICES="" - +#这个变量为true则使用virtio磁盘 +VIRTIO_BLK_DEVICE=false # 如果qemu_accel不为空 if [ -n "${qemu_accel}" ]; then 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_CPU_FEATURES+="-cpu IvyBridge,apic,x2apic,+fpu,check,+vmx,${allflags}" 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 QEMU_MACHINE=" -machine virt,memory-backend=${QEMU_MEMORY_BACKEND} -cpu sifive-u54 " QEMU_DEVICES_DISK="-device virtio-blk-device,drive=disk "