Skip to content

Commit

Permalink
fix(virtio/pci): use volatile accesses for device features
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Apr 20, 2024
1 parent 8527d7c commit f745e02
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/drivers/virtio/transport/pci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,19 +528,19 @@ impl ComCfg {
// Indicate device to show high 32 bits in device_feature field.
// See Virtio specification v1.1. - 4.1.4.3
memory_barrier();
self.com_cfg.device_feature_select = 1;
unsafe { ptr::from_mut(&mut self.com_cfg.device_feature_select).write_volatile(1) };
memory_barrier();

// read high 32 bits of device features
let mut dev_feat = u64::from(self.com_cfg.device_feature) << 32;
let mut dev_feat = u64::from(unsafe { ptr::from_mut(&mut self.com_cfg.device_feature).read_volatile() }) << 32;

// Indicate device to show low 32 bits in device_feature field.
// See Virtio specification v1.1. - 4.1.4.3
self.com_cfg.device_feature_select = 0;
unsafe { ptr::from_mut(&mut self.com_cfg.device_feature_select).write_volatile(0) };
memory_barrier();

// read low 32 bits of device features
dev_feat |= u64::from(self.com_cfg.device_feature);
dev_feat |= u64::from(unsafe { ptr::from_mut(&mut self.com_cfg.device_feature).read_volatile() });

dev_feat
}
Expand Down

0 comments on commit f745e02

Please sign in to comment.