Skip to content

x86/mm/cpa: Improve large page preservation handling

Thomas Gleixner lkml 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest11 patches 18 repliesIn review
  2. v210 patches 1 replySuperseded
  3. v110 patches 3 repliesSuperseded

Changes in v3 from the cover letter

- Fix the print format so it works for 32bit(PAE) and 64bit

- Make mark_rodata_do() on 32bit convert text and rodata in one go to prevent the 'invalid existing mapping' check to trigger

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/11x86/mm/init32: Mark text and rodata RO in one goarch/x86/mm/init_32.c+4 -191 reply
2/11x86/mm/cpa: Split, rename and clean up try_preserve_large_page()arch/x86/mm/pageattr.c+60 -615 replies
3/11x86/mm/cpa: Rework static_protections()arch/x86/mm/pageattr.c+95 -641 reply
4/11x86/mm/cpa: Allow range check for static protectionsarch/x86/mm/pageattr.c+44 -251 reply
5/11x86/mm/cpa: Add debug mechanismarch/x86/mm/pageattr.c+52 -92 replies
6/11x86/mm/cpa: Add large page preservation statisticsarch/x86/Kconfig arch/x86/mm/pageattr.c+105 -21 reply
7/11x86/mm/cpa: Avoid static protection checks on unmaparch/x86/mm/pageattr.c+7 -01 reply
8/11x86/mm/cpa: Add sanity check for existing mappingsarch/x86/mm/pageattr.c+67 -102 replies
9/11x86/mm/cpa: Optimize same protection checkarch/x86/mm/pageattr.c+14 -02 replies
10/11x86/mm/cpa: Do the range check earlyarch/x86/mm/pageattr.c+23 -41 reply
11/11x86/mm/cpa: Avoid the 4k pages check completelyarch/x86/mm/pageattr.c+17 -491 reply

Reviews trailers per patch

All 11 patches have a Reviewed-by or Acked-by.

PatchDave Hansen
1/11R-b
2/11R-b
3/11R-b
4/11R-b
5/11R-b
6/11R-b
7/11R-b
8/11R-b
9/11R-b
10/11R-b
11/11R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [patch V3 00/11] x86/mm/cpa: Improve large page preservation handling

This is the 3rd revision of this series. Previous versions are here:

https://lkml.kernel.org/r/[email protected]
https://lkml.kernel.org/r/[email protected]

Changes since v2:

- Fix the print format so it works for 32bit(PAE) and 64bit

- Make mark_rodata_do() on 32bit convert text and rodata in one go to prevent the 'invalid existing mapping' check to trigger

Bin reported that try_preserve_large_page() in the page attribute code consumes an large amount of CPU time. His initial attempts of addressing this made me look deeper into the code.

The logic in this code is not really intelligent. It requires to check a large page in 4k steps for conflicts. That's insane as most operations do not conflict at all.

The code also lacks sanity checks which allow to detect whether the existing mapping is incorrect vs. the static protections.

Any form of debugging or statistics is missing as well.

The following series addresses this:

- Clean up the code so it becomes extensible

- Provide the ability to check a full range for conflicts

- Add debug output and statistics to quantify the changes and to allow observation of the mechanism in the future.

- Add a sanity check for existing mappings with a fixup for the 2M case and a warning for the 1G case. The 2M case is trivial to address, the 1G case requires larger changes and is just warned about for now.

- Avoid conflict checks for operations which clear the PRESENT bit

- Utilize the range checks to detect conflicts in one operation

- Drop the 4k wise checking which turned out to provide no extra large page preservation in testing. There might be corner cases where a page would be preserved, but that's overkill for the common cases.

Before:

 1G pages checked:                    2
 1G pages sameprot:                   0
 1G pages preserved:                  0

2M pages checked: 540
2M pages sameprot: 466
2M pages preserved: 47
4K pages checked: 800770
4K pages set-checked: 7668

After:

 1G pages checked:                    2
 1G pages sameprot:                   0
 1G pages preserved:                  0

2M pages checked: 538
2M pages sameprot: 466
2M pages preserved: 47
4K pages set-checked: 7668

This gets rid of ~800000 checks whether a particular address is with a static protection region. Each check tests against 4 different regions, which adds up to several million instructions.

Thanks,

tglx

8<---------------------

 Kconfig       |    8 
 mm/init_32.c  |   23 --
 mm/pageattr.c |  516 +++++++++++++++++++++++++++++++++++++++++++---------------
 3 files changed, 396 insertions(+), 151 deletions(-)