Skip to content

Commit 1e56416

Browse files
committed
fix(virtio/pci): use volatile accesses for device features
Signed-off-by: Martin Kröning <[email protected]>
1 parent 8527d7c commit 1e56416

File tree

1 file changed

+6
-4
lines changed
  • src/drivers/virtio/transport

1 file changed

+6
-4
lines changed

src/drivers/virtio/transport/pci.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,22 +525,24 @@ impl ComCfg {
525525

526526
/// Returns the features offered by the device. Coded in a 64bit value.
527527
pub fn dev_features(&mut self) -> u64 {
528+
let device_feature_select = ptr::from_mut(&mut self.com_cfg.device_feature_select);
529+
let device_feature = ptr::from_mut(&mut self.com_cfg.device_feature);
528530
// Indicate device to show high 32 bits in device_feature field.
529531
// See Virtio specification v1.1. - 4.1.4.3
530532
memory_barrier();
531-
self.com_cfg.device_feature_select = 1;
533+
unsafe { device_feature_select.write_volatile(1) };
532534
memory_barrier();
533535

534536
// read high 32 bits of device features
535-
let mut dev_feat = u64::from(self.com_cfg.device_feature) << 32;
537+
let mut dev_feat = u64::from(unsafe { device_feature.read_volatile() }) << 32;
536538

537539
// Indicate device to show low 32 bits in device_feature field.
538540
// See Virtio specification v1.1. - 4.1.4.3
539-
self.com_cfg.device_feature_select = 0;
541+
unsafe { device_feature_select.write_volatile(0) };
540542
memory_barrier();
541543

542544
// read low 32 bits of device features
543-
dev_feat |= u64::from(self.com_cfg.device_feature);
545+
dev_feat |= u64::from(unsafe { device_feature.read_volatile() });
544546

545547
dev_feat
546548
}

0 commit comments

Comments
 (0)