From b911737918fbb53b994ef1c46e7fda0e92648371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 30 May 2024 16:41:30 +0200 Subject: [PATCH 1/2] fix(virtio-net): enable notification data feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QEMU does not support it, but we do. Signed-off-by: Martin Kröning --- src/drivers/net/virtio_net.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/drivers/net/virtio_net.rs b/src/drivers/net/virtio_net.rs index 2525b2277d..15be659e5e 100644 --- a/src/drivers/net/virtio_net.rs +++ b/src/drivers/net/virtio_net.rs @@ -716,6 +716,7 @@ impl VirtioNetDriver { | virtio_spec::net::F::INDIRECT_DESC // Packed Vq can be used | virtio_spec::net::F::RING_PACKED + | virtio_spec::net::F::NOTIFICATION_DATA // Host should avoid the creation of checksums | virtio_spec::net::F::CSUM // Guest avoids the creation of checksums From 83f3ca3ec89593c211834d159f97659257d05d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 30 May 2024 16:51:32 +0200 Subject: [PATCH 2/2] fix(virtqueue): `next_off` must not be shifted MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Kröning --- src/drivers/virtio/virtqueue/packed.rs | 9 +++------ src/drivers/virtio/virtqueue/split.rs | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/drivers/virtio/virtqueue/packed.rs b/src/drivers/virtio/virtqueue/packed.rs index 4273f60e88..3952af7a77 100644 --- a/src/drivers/virtio/virtqueue/packed.rs +++ b/src/drivers/virtio/virtqueue/packed.rs @@ -971,8 +971,7 @@ impl Virtq for PackedVq { if self.dev_event.is_notif() | self.dev_event.is_notif_specfic(next_off, next_wrap) { let index = self.index.0.to_le_bytes(); let mut index = index.iter(); - // Even on 64bit systems this is fine, as we have a queue_size < 2^15! - let det_notif_data: u16 = (next_off as u16) >> 1; + let det_notif_data: u16 = (next_off as u16) & !(1 << 15); let flags = (det_notif_data | (u16::from(next_wrap) << 15)).to_le_bytes(); let mut flags = flags.iter(); let mut notif_data: [u8; 4] = [0, 0, 0, 0]; @@ -1014,8 +1013,7 @@ impl Virtq for PackedVq { if self.dev_event.is_notif() { let index = self.index.0.to_le_bytes(); let mut index = index.iter(); - // Even on 64bit systems this is fine, as we have a queue_size < 2^15! - let det_notif_data: u16 = (next_off as u16) >> 1; + let det_notif_data: u16 = (next_off as u16) & !(1 << 15); let flags = (det_notif_data | (u16::from(next_wrap) << 15)).to_le_bytes(); let mut flags = flags.iter(); let mut notif_data: [u8; 4] = [0, 0, 0, 0]; @@ -1044,8 +1042,7 @@ impl Virtq for PackedVq { if self.dev_event.is_notif() { let index = self.index.0.to_le_bytes(); let mut index = index.iter(); - // Even on 64bit systems this is fine, as we have a queue_size < 2^15! - let det_notif_data: u16 = (next_off as u16) >> 1; + let det_notif_data: u16 = (next_off as u16) & !(1 << 15); let flags = (det_notif_data | (u16::from(next_wrap) << 15)).to_le_bytes(); let mut flags = flags.iter(); let mut notif_data: [u8; 4] = [0, 0, 0, 0]; diff --git a/src/drivers/virtio/virtqueue/split.rs b/src/drivers/virtio/virtqueue/split.rs index 80a0a11648..02aa2c5e92 100644 --- a/src/drivers/virtio/virtqueue/split.rs +++ b/src/drivers/virtio/virtqueue/split.rs @@ -380,8 +380,7 @@ impl Virtq for SplitVq { if self.ring.borrow().dev_is_notif() { let index = self.index.0.to_le_bytes(); let mut index = index.iter(); - // Even on 64bit systems this is fine, as we have a queue_size < 2^15! - let det_notif_data: u16 = next_off >> 1; + let det_notif_data: u16 = next_off & !(1 << 15); let flags = (det_notif_data | (next_wrap << 15)).to_le_bytes(); let mut flags = flags.iter(); let mut notif_data: [u8; 4] = [0, 0, 0, 0];