Skip to content

Commit af07352

Browse files
Vasily Gorbikhcahca
authored andcommitted
s390/mem_detect: do not truncate online memory ranges info
Commit bf64f05 ("s390/mem_detect: handle online memory limit just once") introduced truncation of mem_detect online ranges based on identity mapping size. For kdump case however the full set of online memory ranges has to be feed into memblock_physmem_add so that crashed system memory could be extracted. Instead of truncating introduce a "usable limit" which is respected by mem_detect api. Also add extra online memory ranges iterator which still provides full set of online memory ranges disregarding the "usable limit". Fixes: bf64f05 ("s390/mem_detect: handle online memory limit just once") Reported-by: Alexander Egorenkov <[email protected]> Tested-by: Alexander Egorenkov <[email protected]> Reviewed-by: Alexander Gordeev <[email protected]> Signed-off-by: Vasily Gorbik <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent 55d169c commit af07352

File tree

8 files changed

+40
-28
lines changed

8 files changed

+40
-28
lines changed

arch/s390/boot/boot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct vmlinux_info {
3434

3535
void startup_kernel(void);
3636
unsigned long detect_memory(unsigned long *safe_addr);
37-
void mem_detect_truncate(unsigned long limit);
37+
void mem_detect_set_usable_limit(unsigned long limit);
3838
bool is_ipl_block_dump(void);
3939
void store_ipl_parmblock(void);
4040
unsigned long read_ipl_report(unsigned long safe_addr);

arch/s390/boot/kaslr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ static unsigned long count_valid_kernel_positions(unsigned long kernel_size,
132132
unsigned long start, end, pos = 0;
133133
int i;
134134

135-
for_each_mem_detect_block(i, &start, &end) {
135+
for_each_mem_detect_usable_block(i, &start, &end) {
136136
if (_min >= end)
137137
continue;
138138
if (start >= _max)
@@ -153,7 +153,7 @@ static unsigned long position_to_address(unsigned long pos, unsigned long kernel
153153
unsigned long start, end;
154154
int i;
155155

156-
for_each_mem_detect_block(i, &start, &end) {
156+
for_each_mem_detect_usable_block(i, &start, &end) {
157157
if (_min >= end)
158158
continue;
159159
if (start >= _max)
@@ -172,7 +172,7 @@ static unsigned long position_to_address(unsigned long pos, unsigned long kernel
172172

173173
unsigned long get_random_base(unsigned long safe_addr)
174174
{
175-
unsigned long online_mem_total = get_mem_detect_online_total();
175+
unsigned long usable_total = get_mem_detect_usable_total();
176176
unsigned long memory_limit = get_mem_detect_end();
177177
unsigned long base_pos, max_pos, kernel_size;
178178
int i;
@@ -182,8 +182,8 @@ unsigned long get_random_base(unsigned long safe_addr)
182182
* which vmem and kasan code will use for shadow memory and
183183
* pgtable mapping allocations.
184184
*/
185-
memory_limit -= kasan_estimate_memory_needs(online_mem_total);
186-
memory_limit -= vmem_estimate_memory_needs(online_mem_total);
185+
memory_limit -= kasan_estimate_memory_needs(usable_total);
186+
memory_limit -= vmem_estimate_memory_needs(usable_total);
187187

188188
safe_addr = ALIGN(safe_addr, THREAD_SIZE);
189189
kernel_size = vmlinux.image_size + vmlinux.bss_size;

arch/s390/boot/mem_detect.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,20 +172,20 @@ unsigned long detect_memory(unsigned long *safe_addr)
172172
return max_physmem_end;
173173
}
174174

175-
void mem_detect_truncate(unsigned long limit)
175+
void mem_detect_set_usable_limit(unsigned long limit)
176176
{
177177
struct mem_detect_block *block;
178178
int i;
179179

180+
/* make sure mem_detect.usable ends up within online memory block */
180181
for (i = 0; i < mem_detect.count; i++) {
181182
block = __get_mem_detect_block_ptr(i);
182-
if (block->start >= limit) {
183-
mem_detect.count = i;
183+
if (block->start >= limit)
184184
break;
185-
} else if (block->end > limit) {
186-
block->end = (u64)limit;
187-
mem_detect.count = i + 1;
185+
if (block->end >= limit) {
186+
mem_detect.usable = limit;
188187
break;
189188
}
189+
mem_detect.usable = block->end;
190190
}
191191
}

arch/s390/boot/startup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void startup_kernel(void)
304304
setup_ident_map_size(max_physmem_end);
305305
setup_vmalloc_size();
306306
asce_limit = setup_kernel_memory_layout();
307-
mem_detect_truncate(ident_map_size);
307+
mem_detect_set_usable_limit(ident_map_size);
308308

309309
if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && kaslr_enabled) {
310310
random_lma = get_random_base(safe_addr);

arch/s390/boot/vmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void setup_vmem(unsigned long asce_limit)
252252
*/
253253
pgtable_populate_init();
254254
pgtable_populate(0, sizeof(struct lowcore), POPULATE_ONE2ONE);
255-
for_each_mem_detect_block(i, &start, &end)
255+
for_each_mem_detect_usable_block(i, &start, &end)
256256
pgtable_populate(start, end, POPULATE_ONE2ONE);
257257
pgtable_populate(__abs_lowcore, __abs_lowcore + sizeof(struct lowcore),
258258
POPULATE_ABS_LOWCORE);

arch/s390/include/asm/mem_detect.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct mem_detect_block {
3030
struct mem_detect_info {
3131
u32 count;
3232
u8 info_source;
33+
unsigned long usable;
3334
struct mem_detect_block entries[MEM_INLINED_ENTRIES];
3435
struct mem_detect_block *entries_extended;
3536
};
@@ -38,7 +39,7 @@ extern struct mem_detect_info mem_detect;
3839
void add_mem_detect_block(u64 start, u64 end);
3940

4041
static inline int __get_mem_detect_block(u32 n, unsigned long *start,
41-
unsigned long *end)
42+
unsigned long *end, bool respect_usable_limit)
4243
{
4344
if (n >= mem_detect.count) {
4445
*start = 0;
@@ -53,28 +54,37 @@ static inline int __get_mem_detect_block(u32 n, unsigned long *start,
5354
*start = (unsigned long)mem_detect.entries_extended[n - MEM_INLINED_ENTRIES].start;
5455
*end = (unsigned long)mem_detect.entries_extended[n - MEM_INLINED_ENTRIES].end;
5556
}
57+
58+
if (respect_usable_limit && mem_detect.usable) {
59+
if (*start >= mem_detect.usable)
60+
return -1;
61+
if (*end > mem_detect.usable)
62+
*end = mem_detect.usable;
63+
}
5664
return 0;
5765
}
5866

5967
/**
60-
* for_each_mem_detect_block - early online memory range iterator
68+
* for_each_mem_detect_usable_block - early online memory range iterator
6169
* @i: an integer used as loop variable
6270
* @p_start: ptr to unsigned long for start address of the range
6371
* @p_end: ptr to unsigned long for end address of the range
6472
*
65-
* Walks over detected online memory ranges.
73+
* Walks over detected online memory ranges below usable limit.
6674
*/
67-
#define for_each_mem_detect_block(i, p_start, p_end) \
68-
for (i = 0, __get_mem_detect_block(i, p_start, p_end); \
69-
i < mem_detect.count; \
70-
i++, __get_mem_detect_block(i, p_start, p_end))
75+
#define for_each_mem_detect_usable_block(i, p_start, p_end) \
76+
for (i = 0; !__get_mem_detect_block(i, p_start, p_end, true); i++)
77+
78+
/* Walks over all detected online memory ranges disregarding usable limit. */
79+
#define for_each_mem_detect_block(i, p_start, p_end) \
80+
for (i = 0; !__get_mem_detect_block(i, p_start, p_end, false); i++)
7181

72-
static inline unsigned long get_mem_detect_online_total(void)
82+
static inline unsigned long get_mem_detect_usable_total(void)
7383
{
7484
unsigned long start, end, total = 0;
7585
int i;
7686

77-
for_each_mem_detect_block(i, &start, &end)
87+
for_each_mem_detect_usable_block(i, &start, &end)
7888
total += end - start;
7989

8090
return total;
@@ -95,8 +105,10 @@ static inline unsigned long get_mem_detect_end(void)
95105
unsigned long start;
96106
unsigned long end;
97107

108+
if (mem_detect.usable)
109+
return mem_detect.usable;
98110
if (mem_detect.count) {
99-
__get_mem_detect_block(mem_detect.count - 1, &start, &end);
111+
__get_mem_detect_block(mem_detect.count - 1, &start, &end, false);
100112
return end;
101113
}
102114
return 0;

arch/s390/kernel/setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,10 +772,10 @@ static void __init memblock_add_mem_detect_info(void)
772772
get_mem_info_source(), mem_detect.info_source);
773773
/* keep memblock lists close to the kernel */
774774
memblock_set_bottom_up(true);
775-
for_each_mem_detect_block(i, &start, &end) {
775+
for_each_mem_detect_usable_block(i, &start, &end)
776776
memblock_add(start, end - start);
777+
for_each_mem_detect_block(i, &start, &end)
777778
memblock_physmem_add(start, end - start);
778-
}
779779
memblock_set_bottom_up(false);
780780
memblock_set_node(0, ULONG_MAX, &memblock.memory, 0);
781781
}

arch/s390/mm/kasan_init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ void __init kasan_early_init(void)
244244
memset64((u64 *)kasan_early_shadow_pte, pte_val(pte_z), PTRS_PER_PTE);
245245

246246
if (has_edat) {
247-
shadow_alloc_size = get_mem_detect_online_total() >> KASAN_SHADOW_SCALE_SHIFT;
247+
shadow_alloc_size = get_mem_detect_usable_total() >> KASAN_SHADOW_SCALE_SHIFT;
248248
segment_pos = round_down(pgalloc_pos, _SEGMENT_SIZE);
249249
segment_low = segment_pos - shadow_alloc_size;
250250
segment_low = round_down(segment_low, _SEGMENT_SIZE);
@@ -282,7 +282,7 @@ void __init kasan_early_init(void)
282282
* +- shadow end ----+---------+- shadow end ---+
283283
*/
284284
/* populate kasan shadow (for identity mapping and zero page mapping) */
285-
for_each_mem_detect_block(i, &start, &end)
285+
for_each_mem_detect_usable_block(i, &start, &end)
286286
kasan_early_pgtable_populate(__sha(start), __sha(end), POPULATE_MAP);
287287
if (IS_ENABLED(CONFIG_KASAN_VMALLOC)) {
288288
untracked_end = VMALLOC_START;

0 commit comments

Comments
 (0)