Skip to content

Commit 17c02f6

Browse files
Alexandra Iordachealxiord
authored andcommitted
Pass boot parameters by reference to guest mem
Signed-off-by: Alexandra Iordache <aghecen@amazon.com>
1 parent 9e1f223 commit 17c02f6

File tree

6 files changed

+22
-34
lines changed

6 files changed

+22
-34
lines changed

benches/aarch64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
3838
c.bench_function("configure_fdt", |b| {
3939
b.iter(|| {
4040
black_box(FdtBootConfigurator::write_bootparams::<GuestMemoryMmap>(
41-
fdt_boot_params.clone(),
41+
&fdt_boot_params,
4242
&guest_mem,
4343
))
4444
.unwrap();

benches/x86_64/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
9797
c.bench_function("configure_pvh", |b| {
9898
b.iter(|| {
9999
black_box(PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(
100-
pvh_boot_params.clone(),
100+
&pvh_boot_params,
101101
&guest_mem,
102102
))
103103
.unwrap();

src/configurator/aarch64/fdt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ impl BootConfigurator for FdtBootConfigurator {
7171
/// let guest_memory = create_guest_memory();
7272
/// let (fdt, fdt_addr) = create_fdt(&guest_memory);
7373
/// FdtBootConfigurator::write_bootparams::<GuestMemoryMmap>(
74-
/// BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr),
74+
/// &BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr),
7575
/// &guest_memory,
7676
/// ).unwrap();
7777
/// # }
7878
/// ```
79-
fn write_bootparams<M>(params: BootParams, guest_memory: &M) -> Result<()>
79+
fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()>
8080
where
8181
M: GuestMemory,
8282
{
@@ -116,7 +116,7 @@ mod tests {
116116
let fdt_addr = GuestAddress(guest_memory.last_addr().raw_value() - FDT_MAX_SIZE as u64 + 1);
117117
assert_eq!(
118118
FdtBootConfigurator::write_bootparams::<GuestMemoryMmap>(
119-
BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr),
119+
&BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr),
120120
&guest_memory,
121121
)
122122
.err(),
@@ -125,7 +125,7 @@ mod tests {
125125

126126
let fdt_addr = GuestAddress(guest_memory.last_addr().raw_value() - FDT_MAX_SIZE as u64);
127127
assert!(FdtBootConfigurator::write_bootparams::<GuestMemoryMmap>(
128-
BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr),
128+
&BootParams::new::<FdtPlaceholder>(&fdt, fdt_addr),
129129
&guest_memory,
130130
)
131131
.is_ok());

src/configurator/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub trait BootConfigurator {
120120
/// sections and modules, and their associated addresses in guest memory. These
121121
/// vary with the boot protocol used.
122122
/// * `guest_memory` - guest's physical memory.
123-
fn write_bootparams<M>(params: BootParams, guest_memory: &M) -> Result<()>
123+
fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()>
124124
where
125125
M: GuestMemory;
126126
}

src/configurator/x86_64/linux.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ impl BootConfigurator for LinuxBootConfigurator {
9090
/// let params = build_bootparams();
9191
/// let mut bootparams = BootParams::new::<boot_params>(&params, zero_page_addr);
9292
/// LinuxBootConfigurator::write_bootparams::<GuestMemoryMmap>(
93-
/// bootparams,
93+
/// &bootparams,
9494
/// &guest_memory,
9595
/// ).unwrap();
9696
/// }
9797
/// ```
9898
///
9999
/// [`boot_params`]: ../loader/bootparam/struct.boot_params.html
100-
fn write_bootparams<M>(params: BootParams, guest_memory: &M) -> Result<()>
100+
fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()>
101101
where
102102
M: GuestMemory,
103103
{
@@ -155,18 +155,15 @@ mod tests {
155155
);
156156
let mut bootparams = BootParams::new::<boot_params>(&params, bad_zeropg_addr);
157157
assert_eq!(
158-
LinuxBootConfigurator::write_bootparams::<GuestMemoryMmap>(
159-
bootparams.clone(),
160-
&guest_memory,
161-
)
162-
.err(),
158+
LinuxBootConfigurator::write_bootparams::<GuestMemoryMmap>(&bootparams, &guest_memory,)
159+
.err(),
163160
Some(Error::ZeroPagePastRamEnd.into()),
164161
);
165162

166163
// Success case.
167164
bootparams.header_start = zero_page_addr;
168165
assert!(LinuxBootConfigurator::write_bootparams::<GuestMemoryMmap>(
169-
bootparams,
166+
&bootparams,
170167
&guest_memory,
171168
)
172169
.is_ok());

src/configurator/x86_64/pvh.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,18 @@ impl BootConfigurator for PvhBootConfigurator {
124124
///
125125
/// let mut boot_params = BootParams::new::<hvm_start_info>(&start_info, start_info_addr);
126126
/// boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
127-
/// PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(boot_params, &guest_mem).unwrap();
127+
/// PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_mem).unwrap();
128128
/// }
129129
/// ```
130-
fn write_bootparams<M>(params: BootParams, guest_memory: &M) -> Result<()>
130+
fn write_bootparams<M>(params: &BootParams, guest_memory: &M) -> Result<()>
131131
where
132132
M: GuestMemory,
133133
{
134134
// The VMM has filled an `hvm_start_info` struct and a `Vec<hvm_memmap_table_entry>`
135135
// and has passed them on to this function.
136136
// The `hvm_start_info` will be written at `addr` and the memmap entries at
137137
// `start_info.0.memmap_paddr`.
138-
let memmap = params.sections.ok_or(Error::MemmapTableMissing)?;
138+
let memmap = params.sections.as_ref().ok_or(Error::MemmapTableMissing)?;
139139
let memmap_addr = params
140140
.sections_start
141141
.ok_or(Error::MemmapTableAddressMissing)?;
@@ -202,11 +202,8 @@ mod tests {
202202

203203
// Error case: configure without memory map.
204204
assert_eq!(
205-
PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(
206-
boot_params.clone(),
207-
&guest_memory,
208-
)
209-
.err(),
205+
PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_memory,)
206+
.err(),
210207
Some(Error::MemmapTableMissing.into())
211208
);
212209

@@ -217,11 +214,8 @@ mod tests {
217214
boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
218215
boot_params.header_start = bad_start_info_addr;
219216
assert_eq!(
220-
PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(
221-
boot_params.clone(),
222-
&guest_memory,
223-
)
224-
.err(),
217+
PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_memory,)
218+
.err(),
225219
Some(Error::StartInfoPastRamEnd.into())
226220
);
227221

@@ -235,17 +229,14 @@ mod tests {
235229
boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, bad_memmap_addr);
236230

237231
assert_eq!(
238-
PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(
239-
boot_params.clone(),
240-
&guest_memory,
241-
)
242-
.err(),
232+
PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(&boot_params, &guest_memory,)
233+
.err(),
243234
Some(Error::MemmapTablePastRamEnd.into())
244235
);
245236

246237
boot_params.set_sections::<hvm_memmap_table_entry>(&memmap_entries, memmap_addr);
247238
assert!(PvhBootConfigurator::write_bootparams::<GuestMemoryMmap>(
248-
boot_params,
239+
&boot_params,
249240
&guest_memory,
250241
)
251242
.is_ok());

0 commit comments

Comments
 (0)