Skip to content

Commit cc2929f

Browse files
committed
bzimage: Align start of initrd to page boundary
We use 2MiB pages so align the start of the address for the initrd to the page boundary to prevent the kernel trying to access memory outside of the accessible memory (initrd is placed a the top of usable RAM.) Signed-off-by: Rob Bradford <robert.bradford@intel.com>
1 parent 6354879 commit cc2929f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/bzimage.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> {
7373
top_of_usable_ram = max_load_address;
7474
}
7575

76-
let initrd_address = top_of_usable_ram - u64::from(f.get_size());
76+
// Align address to 2MiB boundary as we use 2 MiB pages
77+
let initrd_address = (top_of_usable_ram - u64::from(f.get_size())) & !((2 << 20) - 1);
7778
let mut initrd_region = crate::mem::MemoryRegion::new(initrd_address, u64::from(f.get_size()));
7879

7980
let mut offset = 0;
@@ -94,7 +95,6 @@ pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> {
9495
}
9596

9697
let dst = initrd_region.as_mut_slice(u64::from(offset), 512);
97-
9898
match f.read(dst) {
9999
Err(crate::fat::Error::EndOfFile) => break,
100100
Err(_) => return Err(Error::FileError),

0 commit comments

Comments
 (0)