Skip to content

Conversation

@Anekoique
Copy link

Problem

I encountered this problem when adapting to ROS2.
Multi-threaded applications crash with "No pages populated" error when
threads concurrently access the same lazy-loaded page in COW mappings.

Scenario:

  1. Thread A triggers page fault on unmapped page
  2. Page fault handler populates the page
  3. Context switch to Thread B before Thread A resumes
  4. Thread B faults on same page, finds it already mapped
  5. populate() returns 0 (treated as failure) → segmentation fault

Root Cause

In both cow.rs and file.rs, the populate() functions only count
pages that need work (COW copy, permission upgrade, or new allocation),
but return 0 when a page is already correctly mapped by another thread.

Solution

In both backends, count already-mapped pages with correct permissions as
successful population.

Copilot AI review requested due to automatic review settings November 25, 2025 10:45
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical concurrency bug in the memory management module that caused multi-threaded applications to crash when concurrent page faults occurred on the same lazy-loaded page. The fix ensures that already-mapped pages with correct permissions are counted as successfully populated, preventing spurious "No pages populated" errors.

  • Addresses race condition where Thread B faults on a page already mapped by Thread A
  • Updates both COW and file-backed memory backends to count pre-mapped pages
  • Prevents populate() from incorrectly returning 0 for already-correctly-mapped pages

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
modules/axmm/src/backend/cow.rs Added check to count already-mapped pages with correct permissions in COW backend's populate function
modules/axmm/src/backend/file.rs Added check to count already-mapped pages with correct permissions in file backend's populate function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AsakuraMizu AsakuraMizu requested a review from Mivik November 25, 2025 10:47
Copy link

@Mivik Mivik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the docs of BackendOps::populate accordingly

@Anekoique
Copy link
Author

Please update the docs of BackendOps::populate accordingly

DONE

Copy link

@Mivik Mivik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tested and it seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants