From cc2929f6dcab633935ee57a341d58659ed7318a7 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 9 Dec 2019 16:13:21 +0000 Subject: [PATCH] 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 --- src/bzimage.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bzimage.rs b/src/bzimage.rs index 15bd0a0b..6ba81c5d 100644 --- a/src/bzimage.rs +++ b/src/bzimage.rs @@ -73,7 +73,8 @@ pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> { top_of_usable_ram = max_load_address; } - let initrd_address = top_of_usable_ram - u64::from(f.get_size()); + // Align address to 2MiB boundary as we use 2 MiB pages + let initrd_address = (top_of_usable_ram - u64::from(f.get_size())) & !((2 << 20) - 1); let mut initrd_region = crate::mem::MemoryRegion::new(initrd_address, u64::from(f.get_size())); let mut offset = 0; @@ -94,7 +95,6 @@ pub fn load_initrd(f: &mut dyn Read) -> Result<(), Error> { } let dst = initrd_region.as_mut_slice(u64::from(offset), 512); - match f.read(dst) { Err(crate::fat::Error::EndOfFile) => break, Err(_) => return Err(Error::FileError),