Skip to content

Commit b0bca9f

Browse files
committed
Retry non-fixed mmap hints after host collisions
When a non-fixed guest mmap hint collides with host/global-allocator pages inside the guest partition, retry another guest VA instead of surfacing ENOMEM immediately.\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d4c0c9a commit b0bca9f

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

litebox/src/mm/linux.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -693,21 +693,19 @@ impl<Platform: PageManagementProvider<ALIGN> + 'static, const ALIGN: usize> Vmem
693693
FixedAddressBehavior::Hint
694694
};
695695
let mut next_top_down_max_start = None;
696-
let mut pending_hint = suggested_address.filter(|_| require_low_2g);
696+
let mut pending_hint = if fixed_addr { None } else { suggested_address };
697697
loop {
698-
let candidate_hint = if next_top_down_max_start.is_none() {
698+
let candidate_hint = if fixed_addr {
699+
suggested_address
700+
} else if next_top_down_max_start.is_none() {
699701
pending_hint.take()
700702
} else {
701703
None
702704
};
703705
let used_hint = candidate_hint.is_some();
704706
let new_addr = self
705707
.get_unmmaped_area(
706-
if require_low_2g {
707-
candidate_hint
708-
} else {
709-
suggested_address
710-
},
708+
candidate_hint,
711709
total_length,
712710
fixed_addr,
713711
require_low_2g,
@@ -727,8 +725,12 @@ impl<Platform: PageManagementProvider<ALIGN> + 'static, const ALIGN: usize> Vmem
727725
)
728726
} {
729727
Ok(ret) => return Ok(ret),
728+
// Non-fixed mappings treat the requested address as a hint.
729+
// If the host allocator can't realize that hint inside the
730+
// guest partition, fall back to another guest VA instead of
731+
// surfacing ENOMEM immediately.
730732
Err(AllocationError::AddressInUseByPlatform | AllocationError::OutOfMemory)
731-
if require_low_2g && !fixed_addr =>
733+
if !fixed_addr =>
732734
{
733735
if used_hint {
734736
continue;

0 commit comments

Comments
 (0)