Skip to content

Commit

Permalink
fix(virtqueue): next_off must not be shifted
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed May 30, 2024
1 parent b911737 commit 83f3ca3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
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 83f3ca3

Please sign in to comment.