-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from roy-hopkins/fs_view_main
fs: Add VMFileMapping to map ramfs file contents to virtual memory
- Loading branch information
Showing
16 changed files
with
874 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
// Author: Joerg Roedel <[email protected]> | ||
|
||
use super::control_regs::read_cr2; | ||
use super::percpu::this_cpu; | ||
use super::tss::IST_DF; | ||
use super::vc::handle_vc_exception; | ||
use super::{X86GeneralRegs, X86InterruptFrame}; | ||
|
@@ -39,6 +40,8 @@ pub const _HV_VECTOR: usize = 28; | |
pub const VC_VECTOR: usize = 29; | ||
pub const _SX_VECTOR: usize = 30; | ||
|
||
pub const PF_ERROR_WRITE: usize = 2; | ||
|
||
#[repr(C, packed)] | ||
#[derive(Default, Debug, Clone, Copy)] | ||
pub struct X86ExceptionContext { | ||
|
@@ -198,7 +201,11 @@ fn generic_idt_handler(ctx: &mut X86ExceptionContext) { | |
let rip = ctx.frame.rip; | ||
let err = ctx.error_code; | ||
|
||
if !handle_exception_table(ctx) { | ||
if this_cpu() | ||
.handle_pf(VirtAddr::from(cr2), (err & PF_ERROR_WRITE) != 0) | ||
.is_err() | ||
&& !handle_exception_table(ctx) | ||
{ | ||
panic!( | ||
"Unhandled Page-Fault at RIP {:#018x} CR2: {:#018x} error code: {:#018x}", | ||
rip, cr2, err | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,10 @@ | |
// Author: Joerg Roedel <[email protected]> | ||
|
||
use crate::address::{PhysAddr, VirtAddr}; | ||
use crate::error::SvsmError; | ||
use crate::locking::{RWLock, ReadLockGuard, WriteLockGuard}; | ||
use crate::mm::pagetable::PTEntryFlags; | ||
use crate::mm::vm::VMR; | ||
use crate::types::{PAGE_SHIFT, PAGE_SIZE}; | ||
|
||
use intrusive_collections::rbtree::Link; | ||
|
@@ -18,6 +20,16 @@ extern crate alloc; | |
use alloc::boxed::Box; | ||
use alloc::sync::Arc; | ||
|
||
/// Information required to resolve a page fault within a virtual mapping | ||
pub struct VMPageFaultResolution { | ||
/// The physical address of a page that must be mapped to the page fault | ||
/// virtual address to resolve the page fault. | ||
pub paddr: PhysAddr, | ||
|
||
/// The flags to use to map the virtual memory page. | ||
pub flags: PTEntryFlags, | ||
} | ||
|
||
pub trait VirtualMapping: core::fmt::Debug { | ||
/// Request the size of the virtual memory mapping | ||
/// | ||
|
@@ -48,14 +60,23 @@ pub trait VirtualMapping: core::fmt::Debug { | |
// Provide default in case there is nothing to do | ||
} | ||
|
||
/// Request the PTEntryFlags used for this virtual memory mapping. This is | ||
/// a combination of | ||
/// Request the PTEntryFlags used for this virtual memory mapping. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * 'offset' -> The offset in bytes into the `VirtualMapping`. The flags | ||
/// returned from this function relate to the page at the | ||
/// given offset | ||
/// | ||
/// # Returns | ||
/// | ||
/// A combination of: | ||
/// * PTEntryFlags::WRITABLE | ||
/// * PTEntryFlags::NX, | ||
/// * PTEntryFlags::ACCESSED | ||
/// * PTEntryFlags::DIRTY | ||
fn pt_flags(&self) -> PTEntryFlags; | ||
fn pt_flags(&self, offset: usize) -> PTEntryFlags; | ||
|
||
/// Request the page size used for mappings | ||
/// | ||
|
@@ -78,6 +99,30 @@ pub trait VirtualMapping: core::fmt::Debug { | |
// Shared with the HV - defaults not No | ||
false | ||
} | ||
|
||
/// Handle a page fault that occurred on a virtual memory address within | ||
/// this mapping. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * 'vmr' - Virtual memory range that contains the mapping. This | ||
/// [`VirtualMapping`] can use this to insert/remove regions | ||
/// as necessary to handle the page fault. | ||
/// | ||
/// * `offset` - Offset into the virtual mapping that was the subject of | ||
/// the page fault. | ||
/// | ||
/// * 'write' - `true` if the fault was due to a write to the memory | ||
/// location, or 'false' if the fault was due to a read. | ||
/// | ||
fn handle_page_fault( | ||
&mut self, | ||
_vmr: &VMR, | ||
_offset: usize, | ||
_write: bool, | ||
) -> Result<VMPageFaultResolution, SvsmError> { | ||
Err(SvsmError::Mem) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
|
@@ -186,4 +231,8 @@ impl VMM { | |
pub fn get_mapping_mut(&self) -> WriteLockGuard<Box<dyn VirtualMapping>> { | ||
self.mapping.get_mut() | ||
} | ||
|
||
pub fn get_mapping_clone(&self) -> Arc<Mapping> { | ||
self.mapping.clone() | ||
} | ||
} |
Oops, something went wrong.