Skip to content

Commit

Permalink
Merge pull request #1206 from stlankes/mmio
Browse files Browse the repository at this point in the history
Fix device notification
  • Loading branch information
mkroening authored May 19, 2024
2 parents 47ea695 + a64cd52 commit bc20e42
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ jobs:
hermit-careful: 1
- arch: x86_64
packages: qemu-system-x86 libcap-ng-dev libseccomp-dev uftrace
flags: --features hermit/pci-ids
#flags: --features hermit/pci-ids
- arch: aarch64
packages: qemu-system-aarch64
flags: --features hermit/pci-ids
#flags: --features hermit/pci-ids
- arch: riscv64
packages: qemu-system-misc

Expand Down Expand Up @@ -200,6 +200,8 @@ jobs:
if: matrix.arch == 'x86_64'
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package httpd --features ci,hermit/dhcpv4 --netdev virtio-net-pci
if: matrix.arch != 'riscv64'
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package httpd --no-default-features --microvm --features ci,hermit/dhcpv4,hermit/tcp --netdev virtio-net-mmio
if: matrix.arch == 'x86_64'
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package httpd --features ci,hermit/dhcpv4 --netdev rtl8139 --features hermit/rtl8139
if: matrix.arch == 'x86_64'
- run: cargo xtask ci qemu --arch ${{ matrix.arch }} --profile ${{ matrix.profile }} ${{ matrix.flags }} --package testudp --features hermit/udp,hermit/dhcpv4 --netdev virtio-net-pci
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86_64/kernel/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const MAGIC_VALUE: u32 = 0x74726976;

pub const MMIO_START: usize = 0x00000000feb00000;
pub const MMIO_END: usize = 0x00000000feb0ffff;
const IRQ_NUMBER: u8 = 23;
const IRQ_NUMBER: u8 = 44 - 32;

static mut MMIO_DRIVERS: Vec<MmioDriver> = Vec::new();

Expand Down
6 changes: 4 additions & 2 deletions src/drivers/virtio/transport/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,12 @@ impl NotifCtrl {
ptr.write_volatile(notif_data[0..4].try_into().unwrap());
}
} else {
let ptr = self.notif_addr as *mut [u8; 2];
let mut data: [u8; 4] = [0, 0, 0, 0];
data[0..2].copy_from_slice(&notif_data[0..2]);
let ptr = self.notif_addr as *mut [u8; 4];

unsafe {
ptr.write_volatile(notif_data[0..2].try_into().unwrap());
ptr.write_volatile(data[0..4].try_into().unwrap());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ impl NotifCtrl {

pub fn notify_dev(&self, notif_data: &[u8]) {
// See Virtio specification v.1.1. - 4.1.5.2
// Depending in the feature negotiation, we write eitehr only the
// Depending in the feature negotiation, we write either only the
// virtqueue index or the index and the next position inside the queue.

fence(Ordering::Acquire);
Expand Down
8 changes: 6 additions & 2 deletions src/drivers/virtio/virtqueue/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl Virtq for SplitVq {
notif_cfg: &NotifCfg,
size: VqSize,
index: VqIndex,
_features: virtio_spec::F,
features: virtio_spec::F,
) -> Result<Self, VirtqError> {
// Get a handler to the queues configuration area.
let mut vq_handler = match com_cfg.select_vq(index.into()) {
Expand Down Expand Up @@ -493,12 +493,16 @@ impl Virtq for SplitVq {
used_ring_cell,
};

let notif_ctrl = NotifCtrl::new(ptr::with_exposed_provenance_mut(
let mut notif_ctrl = NotifCtrl::new(ptr::with_exposed_provenance_mut(
notif_cfg.base()
+ usize::from(vq_handler.notif_off())
+ usize::try_from(notif_cfg.multiplier()).unwrap(),
));

if features.contains(virtio_spec::F::NOTIFICATION_DATA) {
notif_ctrl.enable_notif_data();
}

// Initialize new memory pool.
let mem_pool = Rc::new(MemPool::new(size));

Expand Down
13 changes: 10 additions & 3 deletions xtask/src/ci/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct Qemu {
#[derive(ValueEnum, Clone, Copy)]
pub enum NetworkDevice {
VirtioNetPci,
VirtioNetMmio,
Rtl8139,
}

Expand Down Expand Up @@ -137,7 +138,7 @@ impl Qemu {
"microvm,x-option-roms=off,pit=off,pic=off,rtc=on,auto-kernel-cmdline=off,acpi=off"
.to_string(),
"-global".to_string(),
"virtio-mmio.force-legacy=on".to_string(),
"virtio-mmio.force-legacy=off".to_string(),
"-nodefaults".to_string(),
"-no-user-config".to_string(),
"-append".to_string(),
Expand Down Expand Up @@ -214,10 +215,10 @@ impl Qemu {
if self.build.cargo_build.artifact.profile() == "dev" {
memory *= 4;
}
memory *= self.smp;
if self.netdev.is_some() {
memory *= 4;
memory = memory.max(1024);
}
memory *= self.smp;
if self.build.cargo_build.artifact.arch == Arch::Aarch64 {
memory = memory.max(256);
}
Expand All @@ -237,6 +238,12 @@ impl Qemu {
"-device",
"virtio-net-pci,netdev=u1,disable-legacy=on"
],
Some(NetworkDevice::VirtioNetMmio) => &[
"-netdev",
"user,id=u1,hostfwd=tcp::9975-:9975,hostfwd=udp::9975-:9975,net=192.168.76.0/24,dhcpstart=192.168.76.9",
"-device",
"virtio-net-device,netdev=u1"
],
Some(NetworkDevice::Rtl8139) => &[
"-netdev",
"user,id=u1,hostfwd=tcp::9975-:9975,hostfwd=udp::9975-:9975,net=192.168.76.0/24,dhcpstart=192.168.76.9",
Expand Down

0 comments on commit bc20e42

Please sign in to comment.