Skip to content

Commit 965b14a

Browse files
committed
pvh: Do not attempt PVH boot if kernel_offset is requested
In x86, the kernel_offset parameter is used to request that the kernel is loaded in guest memory at a fixed offset from the default load address encoded in the phdr.p_paddr field of the Elf header. Do not attempt to look for a PVH entry point if a load offset has been requested using kernel_offset, since PVH expects the kernel to be loaded at the default load address. Signed-off-by: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
1 parent 9a258e8 commit 965b14a

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/loader/x86_64/elf/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ impl Elf {
130130
impl KernelLoader for Elf {
131131
/// Loads a kernel from a vmlinux elf image into guest memory.
132132
///
133-
/// The kernel is loaded into guest memory at offset `phdr.p_paddr` specified by the elf image.
133+
/// By default, the kernel is loaded into guest memory at offset `phdr.p_paddr` specified by the elf image.
134+
/// When used, `kernel_offset` specifies a fixed offset from `phdr.p_paddr` at which to load the kernel. If
135+
/// `kernel_offset` is requested, the `pvh_entry_addr` field of the result will not be populated.
134136
///
135137
/// # Arguments
136138
///
@@ -212,7 +214,12 @@ impl KernelLoader for Elf {
212214
// Read in each section pointed to by the program headers.
213215
for phdr in phdrs {
214216
if phdr.p_type != elf::PT_LOAD || phdr.p_filesz == 0 {
215-
if phdr.p_type == elf::PT_NOTE {
217+
// The PVH boot protocol currently requires that the kernel is loaded at
218+
// the default kernel load address in guest memory (specified at kernel
219+
// build by the value of CONFIG_PHYSICAL_START). Therefore, only attempt
220+
// to use PVH if an offset from the default load address has not been
221+
// requested using the kernel_offset parameter.
222+
if phdr.p_type == elf::PT_NOTE && kernel_offset.is_none() {
216223
// This segment describes a Note, check if PVH entry point is encoded.
217224
loader_result.pvh_entry_addr = parse_elf_note(&phdr, kernel_image)?;
218225
}

0 commit comments

Comments
 (0)