Skip to content

Design: refactoring read_physical API #175

@Wenzel

Description

@Wenzel

In light of the work we already accomplished with #165, I would like to open this design issue to provide some ideas about refactoring the read_physical API, and implementation.

read_physical_padded

It would be convient to have a read_physical_padded() API,directly available in the Introspectable trait, instead of implementing in the Python layer, at PaddedPhysicalMemoryIO.
It would be more efficient, and available to the C and Rust programs.

moving read algorithms from driver to Introspectable trait

If we take a look at the current implementation for Xen and KVM

Both of them will split the read by 4K chunks, the size of a page.

the proposal would be to move a maximum of this common read algorithm into the Introspectable trait

Proposal

use std::io::Read;

trait Introspectable {
  fn read_physical(paddr: u64, buf: &mut [u8], bytes_read: &mut u64) -> Result<(), Box<dyn Error>> {
     // implementation provided in the trait
    for (i, chunk) in buf.chunks_mut(PAGE_SIZE).enumerate() {
      let new_gfn = xxxx;
      let page = self.get_physical_page(gfn)?;
      page.read(PAGE_SIZE, chunk)?;
    }
  }

  fn read_physical_padded(paddr: u64, buf: &mut [u8], bytes_read: &mut u64) -> Result<(), Box<dyn Error>> {
    // same as above, but doesn't stop when a page is missing, fill with zeroes instead
  }

  // Return a Readable object that represents a physical page (or frame)
  fn get_physical_page(gfn: u64) -> Result<Box<dyn Read>, Box<dyn Error>>;
}

With this solution we factorise read operation code in the trait, and we can handle the Xen situation where a page has to be mapped / unmapped by returning a Boxed object, that can implement a Drop trait and handle unmapping on deallocation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions