All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level
@ 2019-03-08  2:56 Baoquan He
  2019-03-08  2:56 ` [PATCH v3 1/2] x86/mm/KASLR: Only build one PUD entry of area for real mode trampoline Baoquan He
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Baoquan He @ 2019-03-08  2:56 UTC (permalink / raw)
  To: linux-kernel, kirill.shutemov
  Cc: dave.hansen, luto, peterz, tglx, mingo, bp, hpa, x86, keescook,
	thgarnie, Baoquan He

This is v3 post, v2 post is here:
http://lkml.kernel.org/r/20190228003522.9957-1-bhe@redhat.com
v1 can be found here:
http://lkml.kernel.org/r/20190224132231.4878-1-bhe@redhat.com

Background:
***
Earlier, during a series of KASLR patch reviewing, Ingo got the current
memory region KASLR only has granularity of randomization in PUD size in
4-level paging mode, and P4D size in 5-level paging mode, He suggested
me to try to change both of them to be PMD size at granularity:

  http://lkml.kernel.org/r/20180912100135.GB3333@gmail.com

Later, I changed code to support PMD level of randomization for both
4-level and 5-level.

  https://github.com/baoquan-he/linux/commits/mm-kaslr-2m-aligned

The test passed on my KVM guest with 1 GB RAM, but failed when I
increased the RAM to 4 GB, and failed either on larger RAM.

After analyzing, it's because that 1 GB page mapping need be mapped at 1
GB aligned physical address for intel CPU. The 2 MB level of randomization
will break it and cause error. Please check below table in intel IA32 manual.

  Table 4-15. Format of an IA-32e Page-Directory-Pointer-Table Entry (PDPTE) that Maps a 1-GByte Page

So PMD level of randomization for mm KASLR is not doable.

However, during investigation and testing above code, it turns out that the
current code is misleading to build identity mapping for the real mode
trampoline in case KASLR enabled. From code, only a small area (which is
smaller than 1 MB) need be identity mapped. Please check below patch which
is from above mm-kaslr-2m-aligned patch series. it only builds up 2 MB
identity maping for real mode trampoline, and test passed on machines
with 32 GB RAM of 4-level and on KVM guest of 5-level.

https://github.com/baoquan-he/linux/commit/e120e67fbf9a5aa818d20084d8dea5b4a27ecf97

Result:
Make a patchset to:
  1)change code to only build 1 GB of area for real mode trampoline,
    namely only copy one PUD entry where physical address 0 resides;

  2)improve the randomization granularity of 5-level from P4D size to PUD size.

Changelog:
v2->v3:
  Improve patch 1/2 according to Kirill's comments:
    *) Adjust code change of 1/2;
    *) Add code comment to explain the two kinds of mapping thing for
       real mode;
  
v1->v2:
  Improve patch according to Kirill's suggestions:
    *)Add more information to code comment for better understanding;
    *)Improve code to save one low memory page in 4-level;

Baoquan He (2):
  x86/mm/KASLR: Only build one PUD entry of area for real mode
    trampoline
  x86/mm/KASLR: Change the granularity of randomization to PUD size in
    5-level

 arch/x86/mm/kaslr.c | 98 ++++++++++++++++++++-------------------------
 1 file changed, 43 insertions(+), 55 deletions(-)

-- 
2.17.2


^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH v2 0/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level
@ 2019-02-28  0:35 Baoquan He
  2019-02-28  9:10 ` Kirill A. Shutemov
  0 siblings, 1 reply; 9+ messages in thread
From: Baoquan He @ 2019-02-28  0:35 UTC (permalink / raw)
  To: linux-kernel, kirill.shutemov
  Cc: dave.hansen, luto, peterz, tglx, mingo, bp, hpa, x86, keescook,
	thgarnie, Baoquan He

This is v2 post. v1 can be found here:
http://lkml.kernel.org/r/20190224132231.4878-1-bhe@redhat.com

Background:
***
Earlier, during a series of KASLR patch reviewing, Ingo got the current
memory region KASLR only has granularity of randomization in PUD size in
4-level paging mode, and P4D size in 5-level paging mode, He suggested
me to try to change both of them to be PMD size at granularity:

  http://lkml.kernel.org/r/20180912100135.GB3333@gmail.com

Later, I changed code to support PMD level of randomization for both
4-level and 5-level.

  https://github.com/baoquan-he/linux/commits/mm-kaslr-2m-aligned

The test passed on my KVM guest with 1 GB RAM, but failed when I
increased the RAM to 4 GB, and failed either on larger RAM.

After analyzing, it's because that 1 GB page mapping need be mapped at 1
GB aligned physical address for intel CPU. The 2 MB level of randomization
will break it and cause error. Please check below table in intel IA32 manual.

  Table 4-15. Format of an IA-32e Page-Directory-Pointer-Table Entry (PDPTE) that Maps a 1-GByte Page

So PMD level of randomization for mm KASLR is not doable.

However, during investigation and testing above code, it turns out that the
current code is misleading to build identity mapping for the real mode
trampoline in case KASLR enabled. From code, only a small area (which is
smaller than 1 MB) need be identity mapped. Please check below patch which
is from above mm-kaslr-2m-aligned patch series. it only builds up 2 MB
identity maping for real mode trampoline, and test passed on machines
with 32 GB RAM of 4-level and on KVM guest of 5-level. 

https://github.com/baoquan-he/linux/commit/e120e67fbf9a5aa818d20084d8dea5b4a27ecf97

Result:
Make a patchset to:
  1)change code to only build 1 GB of area for real mode trampoline,
    namely only copy one PUD entry where physical address 0 resides;

  2)improve the randomization granularity of 5-level from P4D size to PUD size.

Changelog:
v1->v2:
  Improve patch according to Kirill's suggestions:
    *)Add more information to code comment for better understanding;
    *)Improve code to save one low memory page in 4-level;

Baoquan He (2):
  x86/mm/KASLR: Only build one PUD entry of area for real mode
    trampoline
  x86/mm/KASLR: Change the granularity of randomization to PUD size in
    5-level

 arch/x86/mm/kaslr.c | 92 ++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 52 deletions(-)

-- 
2.17.2


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-04-05 20:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-08  2:56 [PATCH v3 0/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level Baoquan He
2019-03-08  2:56 ` [PATCH v3 1/2] x86/mm/KASLR: Only build one PUD entry of area for real mode trampoline Baoquan He
2019-03-12  7:38   ` Kirill A. Shutemov
2019-04-05 20:19   ` [tip:x86/mm] x86/mm/KASLR: Use only one PUD entry " tip-bot for Baoquan He
2019-03-08  2:56 ` [PATCH v3 2/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level Baoquan He
2019-03-12  7:39   ` Kirill A. Shutemov
2019-04-05 20:19   ` [tip:x86/mm] x86/mm/KASLR: Reduce randomization granularity for 5-level paging to 1GB tip-bot for Baoquan He
2019-04-04  2:18 ` [PATCH v3 0/2] x86/mm/KASLR: Change the granularity of randomization to PUD size in 5-level Baoquan He
  -- strict thread matches above, loose matches on Subject: below --
2019-02-28  0:35 [PATCH v2 " Baoquan He
2019-02-28  9:10 ` Kirill A. Shutemov
2019-02-28  9:29   ` [PATCH v3 " Baoquan He

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.