Skip to content

Commit f745e02

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

File tree

1 file changed

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

1 file changed

+4
-4
lines changed

src/drivers/virtio/transport/pci.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,19 +528,19 @@ impl ComCfg {
528528
// Indicate device to show high 32 bits in device_feature field.
529529
// See Virtio specification v1.1. - 4.1.4.3
530530
memory_barrier();
531-
self.com_cfg.device_feature_select = 1;
531+
unsafe { ptr::from_mut(&mut self.com_cfg.device_feature_select).write_volatile(1) };
532532
memory_barrier();
533533

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

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

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

545545
dev_feat
546546
}

0 commit comments

Comments
 (0)