Skip to content

Commit

Permalink
Merge pull request #1240 from hermit-os/notification-data
Browse files Browse the repository at this point in the history
fix(virtqueue): `next_off` must not be shifted for notification data
  • Loading branch information
mkroening authored May 31, 2024
2 parents 1fe0476 + 83f3ca3 commit b5243ed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/drivers/net/virtio_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions src/drivers/virtio/virtqueue/packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions src/drivers/virtio/virtqueue/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit b5243ed

Please sign in to comment.