File tree Expand file tree Collapse file tree 11 files changed +282
-171
lines changed Expand file tree Collapse file tree 11 files changed +282
-171
lines changed Original file line number Diff line number Diff line change @@ -5293,7 +5293,9 @@ name = "page_table"
52935293version = " 0.0.0"
52945294dependencies = [
52955295 " bitfield-struct 0.11.0" ,
5296+ " static_assertions" ,
52965297 " thiserror 2.0.16" ,
5298+ " tracing" ,
52975299 " zerocopy 0.8.25" ,
52985300]
52995301
Original file line number Diff line number Diff line change @@ -45,11 +45,10 @@ pub fn load_x86(
4545 let page_table_builder = page_table:: x64:: IdentityMapBuilder :: new (
4646 page_table_base,
4747 page_table:: IdentityMapSize :: Size4Gb ,
48- ) ;
49- let page_tables = page_table_builder. build (
5048 page_table_work_buffer. as_mut_slice ( ) ,
5149 page_tables. as_mut_slice ( ) ,
5250 ) ?;
51+ let page_tables = page_table_builder. build ( ) ;
5352 loader
5453 . import_pages (
5554 page_table_base >> 12 ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ aarch64defs.workspace = true
1111igvm.workspace = true
1212loader_defs.workspace = true
1313memory_range.workspace = true
14- page_table. workspace = true
14+ page_table = { workspace = true , features = [ " tracing " ] }
1515hvdef.workspace = true
1616vm_topology.workspace = true
1717x86defs.workspace = true
Original file line number Diff line number Diff line change 5757 }
5858 }
5959 ]
60- }
60+ }
Original file line number Diff line number Diff line change @@ -9,6 +9,13 @@ rust-version.workspace = true
99[dependencies ]
1010bitfield-struct.workspace = true
1111thiserror.workspace = true
12+ static_assertions.workspace = true
13+ tracing = { workspace = true , optional = true }
1214zerocopy.workspace = true
15+
16+ [features ]
17+ tracing = [" dep:tracing" , " std" ]
18+ std = []
19+
1320[lints ]
1421workspace = true
Original file line number Diff line number Diff line change @@ -437,6 +437,11 @@ impl<'a> Arm64PageTableSpace<'a> {
437437 debug_assert ! ( aligned( phys_table_start, Arm64PageSize :: Small ) ) ;
438438 debug_assert ! ( index < PAGE_SIZE_4K as usize / size_of:: <Arm64PageTableEntry >( ) ) ;
439439
440+ #[ cfg( feature = "tracing" ) ]
441+ tracing:: debug!(
442+ "Writing page table entry {entry:#016x}, index {index:#x}, table {phys_table_start:#x}"
443+ ) ;
444+
440445 let pos = phys_table_start as usize - self . phys_page_table_root
441446 + index * size_of :: < Arm64PageTableEntry > ( ) ;
442447 self . space [ pos..pos + 8 ] . copy_from_slice ( & entry. to_le_bytes ( ) ) ;
@@ -689,6 +694,11 @@ pub fn build_identity_page_tables_aarch64(
689694 panic ! ( "size not 2mb aligned" ) ;
690695 }
691696
697+ #[ cfg( feature = "tracing" ) ]
698+ tracing:: debug!(
699+ "Creating Aarch64 page tables at {page_table_gpa:#x} mapping starting at {start_gpa:#x} of size {size} bytes"
700+ ) ;
701+
692702 let mut page_tables =
693703 Arm64PageTableSpace :: new ( page_table_gpa as usize , page_table_space) . unwrap ( ) ;
694704 page_tables
@@ -705,12 +715,18 @@ pub fn build_identity_page_tables_aarch64(
705715
706716 let used_space = page_tables. used_space ( ) ;
707717
718+ #[ cfg( feature = "tracing" ) ]
719+ {
720+ tracing:: debug!( "Page tables use {used_space} bytes" ) ;
721+ tracing:: debug!( "Page tables stats by level: {:?}" , page_tables. lvl_stats( ) ) ;
722+ }
723+
708724 & page_table_space[ 0 ..used_space]
709725}
710726
711727#[ cfg( test) ]
712728mod tests {
713- extern crate std;
729+ use std;
714730
715731 use super :: * ;
716732 use std:: vec;
Original file line number Diff line number Diff line change 33
44//! Methods to construct page tables.
55
6- #![ no_std]
6+ #![ cfg_attr ( not ( feature = "std" ) , no_std) ]
77#![ expect( missing_docs) ]
88#![ forbid( unsafe_code) ]
99
@@ -17,9 +17,29 @@ use thiserror::Error;
1717pub enum Error {
1818 /// The PageTableBuilder bytes buffer does not match the size of the struct buffer
1919 #[ error(
20- "PageTableBuilder bytes buffer size [ {bytes_buf}] does not match the struct buffer size [{struct_buf}]"
20+ "PageTableBuilder bytes buffer size {bytes_buf} does not match the struct buffer size [{struct_buf}]"
2121 ) ]
2222 BadBufferSize { bytes_buf : usize , struct_buf : usize } ,
23+
24+ /// The page table mapping size is not 2MB aligned
25+ #[ error( "page table mapping size {0:#x} is not 2MB-aligned" ) ]
26+ SizeAlignment ( u64 ) ,
27+
28+ /// The page table mapping size is not 2MB aligned
29+ #[ error( "start_gpa {0:#x} is not 2MB aligned" ) ]
30+ StartAlignment ( u64 ) ,
31+
32+ /// The page table mapping size is greater than 512GB
33+ #[ error( "size {0:#x} is larger than 512GB" ) ]
34+ MappingSize ( u64 ) ,
35+
36+ /// The page table mapping size is missing
37+ #[ error( "the page table builder was invoked without a mapping size" ) ]
38+ MissingSize ,
39+
40+ /// The page table builder is generating overlapping mappings
41+ #[ error( "the page table builder was invoked without a mapping size" ) ]
42+ OverlappingMappings ,
2343}
2444
2545/// Size of the initial identity map
You can’t perform that action at this time.
0 commit comments