Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize x86 userspace page table memory usage #13441

Closed
2 of 4 tasks
andrewboie opened this issue Feb 15, 2019 · 2 comments
Closed
2 of 4 tasks

optimize x86 userspace page table memory usage #13441

andrewboie opened this issue Feb 15, 2019 · 2 comments
Labels
area: Memory Protection Enhancement Changes/Updates/Additions to existing features priority: low Low impact/importance bug

Comments

@andrewboie
Copy link
Contributor

andrewboie commented Feb 15, 2019

We have some memory usage problems with how x86 is setting up page tables:

  • Every page directory pointer table is in its own memory page, even though it is far smaller than that and requires just 32 byte alignment
  • Unpredictability of kobject wordlist tables results in the entire flash ROM region being mapped instead of just pages that are in use on XIP systems
  • User page tables has page tables for regions which will never be marked user accessible, should just be non-present in PDPTE/PDE (like LOAPIC/IOAPIC MMIO)
  • page tables for TEXT/ROM might in some cases be share-able between kernel and user page tables, user tables would not need a copy
@andrewboie andrewboie added Enhancement Changes/Updates/Additions to existing features area: Memory Protection labels Feb 15, 2019
@andrewboie
Copy link
Contributor Author

andrewboie commented Feb 15, 2019

Start address of page tables: 0x0041d000
Build-time memory regions:
    Region 000: 0x00402000 - 0x00bfefff (0x8000000010000002)
    Region 001: 0x00400000 - 0x00401fff (0x8000000010000002)
    Region 002: 0x0000c000 - 0x003fffff (0x8000000000000004)
    Region 003: 0x00001000 - 0x0000bfff (0x0000000000000004)
    Region 004: 0xfed00000 - 0xfed00fff (0x0000000000000002)
    Region 005: 0xfec00000 - 0xfecfffff (0x0000000000000002)
    Region 006: 0xfee00000 - 0xfee00fff (0x0000000000000002)
PDPTE at 0x41d000
Page directory 0 at 0x41e000
XXAAAA..........................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
Page directory 3 at 0x41f000
................................................................................................................................
................................................................................................................................
................................................................................................................................
......................................................................................................................aa........
Page table for 0x00000000 - 0x001f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wwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww.
Page table for 0xfec00000 - 0xfedfffff at 0x00426000
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
a...............................................................................................................................
................................................................................................................................
Page table for 0xfee00000 - 0xfeffffff at 0x00427000
a...............................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
PDPTE at 0x428000
Page directory 0 at 0x429000
XXAAAA..........................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
Page directory 3 at 0x42a000
................................................................................................................................
................................................................................................................................
................................................................................................................................
......................................................................................................................aa........
Page table for 0x00000000 - 0x001fffff at 0x0042b000
.XXXXXXXXXXXRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Page table for 0x00200000 - 0x003fffff at 0x0042c000
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
Page table for 0x00400000 - 0x005fffff at 0x0042d000
...........................w....................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
Page table for 0x00600000 - 0x007fffff at 0x0042e000
................................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
Page table for 0x00800000 - 0x009fffff at 0x0042f000
................................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
Page table for 0x00a00000 - 0x00bfffff at 0x00430000
................................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
Page table for 0xfec00000 - 0xfedfffff at 0x00431000
................................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................
Page table for 0xfee00000 - 0xfeffffff at 0x00432000
................................................................................................................................
................................................................................................................................
................................................................................................................................
................................................................................................................................

For example:

  • Note all of flash being mapped in page tables 0x00420000 0x00421000
  • Page directory at 0x42a000 could be removed just have a non-present entry in user PDPT
  • Page tables at 0x00431000 and 0x00432000 could be removed
  • Page tables at 0x0042b000 and 0x0042c000 could be removed, re-using the tables at 0x00420000 and 0x00421000 instead

@andrewboie andrewboie added the priority: medium Medium impact/importance bug label Mar 15, 2019
@andrewboie andrewboie added priority: low Low impact/importance bug and removed priority: medium Medium impact/importance bug labels Jul 26, 2019
@andrewboie
Copy link
Contributor Author

Two of these sub-items resolved by #17959

andrewboie pushed a commit to andrewboie/zephyr that referenced this issue Aug 3, 2019
The current API was assuming too much, in that it expected that
arch-specific memory domain configuration is only maintained
in some global area, and updates to domains that are not currently
active have no effect.

This was true when all memory domain state was tracked in page
tables or MPU registers, but no longer works when arch-specific
memory management information is stored in thread-specific areas.

This is needed for: zephyrproject-rtos#13441 zephyrproject-rtos#13074 zephyrproject-rtos#15135

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
kraj pushed a commit to YoeDistro/zephyr that referenced this issue Aug 5, 2019
The current API was assuming too much, in that it expected that
arch-specific memory domain configuration is only maintained
in some global area, and updates to domains that are not currently
active have no effect.

This was true when all memory domain state was tracked in page
tables or MPU registers, but no longer works when arch-specific
memory management information is stored in thread-specific areas.

This is needed for: zephyrproject-rtos#13441 zephyrproject-rtos#13074 zephyrproject-rtos#15135

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
LeiW000 pushed a commit to LeiW000/zephyr that referenced this issue Sep 2, 2019
The current API was assuming too much, in that it expected that
arch-specific memory domain configuration is only maintained
in some global area, and updates to domains that are not currently
active have no effect.

This was true when all memory domain state was tracked in page
tables or MPU registers, but no longer works when arch-specific
memory management information is stored in thread-specific areas.

This is needed for: zephyrproject-rtos#13441 zephyrproject-rtos#13074 zephyrproject-rtos#15135

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Memory Protection Enhancement Changes/Updates/Additions to existing features priority: low Low impact/importance bug
Projects
None yet
Development

No branches or pull requests

1 participant