Skip to content

Commit 5333d8c

Browse files
configurator: Load hvm_modlist_entry when requested.
Previously module descriptions in BootParams were silently ignored. This change loads them into guest memory according to the PVH boot spec. Signed-off-by: Kirill Nikolaev <cyril7@gmail.com>
1 parent db0b391 commit 5333d8c

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# Upcoming Release
2+
3+
## Changed
4+
5+
- [[#177](https://github.com/rust-vmm/linux-loader/pull/176)] Added loading
6+
of PVH module blobs into guest memory. This enables booting with `initrd`
7+
via PVH boot.
8+
19
# [v0.11.0]
210

311
## Changed

src/configurator/x86_64/pvh.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ pub enum Error {
3939
StartInfoPastRamEnd,
4040
/// Error writing hvm_start_info to guest memory.
4141
StartInfoSetup,
42+
/// The starting address for the modules descriptions wasn't passed to the boot configurator.
43+
ModulesAddressMissing,
44+
/// Error writing module descriptions to guest memory.
45+
ModulesSetup,
4246
}
4347

4448
impl fmt::Display for Error {
@@ -55,6 +59,8 @@ impl fmt::Display for Error {
5559
"the hvm_start_info structure extends past the end of guest memory."
5660
}
5761
StartInfoSetup => "error writing hvm_start_info to guest memory.",
62+
ModulesAddressMissing => "the starting address for the modules descriptions wasn't passed to the boot configurator.",
63+
ModulesSetup => "error writing module descriptions to guest memory.",
5864
};
5965

6066
write!(f, "PVH Boot Configurator: {}", desc)
@@ -164,6 +170,13 @@ impl BootConfigurator for PvhBootConfigurator {
164170
.write_slice(params.header.as_slice(), params.header_start)
165171
.map_err(|_| Error::StartInfoSetup)?;
166172

173+
if let Some(modules) = params.modules.as_ref() {
174+
let modules_addr = params.modules_start.ok_or(Error::ModulesAddressMissing)?;
175+
guest_memory
176+
.write_slice(modules.as_slice(), modules_addr)
177+
.map_err(|_| Error::ModulesSetup)?;
178+
}
179+
167180
Ok(())
168181
}
169182
}
@@ -182,7 +195,11 @@ mod tests {
182195
GuestMemoryMmap::from_ranges(&[(GuestAddress(0x0), (MEM_SIZE as usize))]).unwrap()
183196
}
184197

185-
fn build_bootparams_common() -> (hvm_start_info, Vec<hvm_memmap_table_entry>) {
198+
fn build_bootparams_common() -> (
199+
hvm_start_info,
200+
Vec<hvm_memmap_table_entry>,
201+
Vec<hvm_modlist_entry>,
202+
) {
186203
let mut start_info = hvm_start_info::default();
187204
let memmap_entry = hvm_memmap_table_entry {
188205
addr: 0x7000,
@@ -191,21 +208,29 @@ mod tests {
191208
reserved: 0,
192209
};
193210

211+
let modlist_entry = hvm_modlist_entry {
212+
paddr: 0x10000,
213+
size: 0x100,
214+
cmdline_paddr: 0,
215+
reserved: 0,
216+
};
217+
194218
start_info.magic = XEN_HVM_START_MAGIC_VALUE;
195219
start_info.version = 1;
196220
start_info.nr_modules = 0;
197221
start_info.memmap_entries = 0;
198222

199-
(start_info, vec![memmap_entry])
223+
(start_info, vec![memmap_entry], vec![modlist_entry])
200224
}
201225

202226
#[test]
203227
fn test_configure_pvh_boot() {
204-
let (mut start_info, memmap_entries) = build_bootparams_common();
228+
let (mut start_info, memmap_entries, modlist_entries) = build_bootparams_common();
205229
let guest_memory = create_guest_mem();
206230

207231
let start_info_addr = GuestAddress(0x6000);
208232
let memmap_addr = GuestAddress(0x7000);
233+
let modlist_addr = GuestAddress(0x6040);
209234
start_info.memmap_paddr = memmap_addr.raw_value();
210235

211236
let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
@@ -245,6 +270,7 @@ mod tests {
245270
);
246271

247272
boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
273+
boot_params.set_modules::<hvm_modlist_entry>(&modlist_entries, modlist_addr);
248274
assert!(PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(
249275
&boot_params,
250276
&guest_memory,

0 commit comments

Comments
 (0)