summaryrefslogtreecommitdiff
path: root/arch/s390/boot/physmem_info.c
diff options
context:
space:
mode:
authorVasily Gorbik <gor@linux.ibm.com>2023-02-21 23:08:42 +0100
committerVasily Gorbik <gor@linux.ibm.com>2023-04-13 17:36:27 +0200
commit6e259bc5a15ec49693fa3d19fdd4511f7679a20d (patch)
tree26adb36a3f3907aa179194e67ff95fa3992a7d76 /arch/s390/boot/physmem_info.c
parent898435203c115b164b96f30be7d9c790bbb50338 (diff)
s390/kaslr: generalize and improve random base distribution
Improve the distribution algorithm of random base address to ensure a uniformity among all suitable addresses. To generate a random value once, and to build a continuous range in which every value is suitable, count all the suitable addresses (referred to as positions) that can be used as a base address. The positions are counted by iterating over the usable memory ranges. For each range that is big enough to accommodate the image, count all the suitable addresses where the image can be placed, while taking reserved memory ranges into consideration. A new function "iterate_valid_positions()" has dual purpose. Firstly, it is called to count the positions in a given memory range, and secondly, to convert a random position back to an address. "get_random_base()" has been replaced with more generic "randomize_within_range()" which now could be called for randomizing base addresses not just for the kernel image. Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Diffstat (limited to 'arch/s390/boot/physmem_info.c')
-rw-r--r--arch/s390/boot/physmem_info.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/arch/s390/boot/physmem_info.c b/arch/s390/boot/physmem_info.c
index 4ee9b7381142..0cf79826eef9 100644
--- a/arch/s390/boot/physmem_info.c
+++ b/arch/s390/boot/physmem_info.c
@@ -321,3 +321,8 @@ unsigned long physmem_alloc_top_down(enum reserved_range_type type, unsigned lon
physmem_alloc_ranges = ranges_left;
return addr;
}
+
+unsigned long get_physmem_alloc_pos(void)
+{
+ return physmem_alloc_pos;
+}