mirror of https://github.com/torvalds/linux.git
s390/mm/ptdump: Generate address marker array dynamically
Generate the address marker array dynamically instead of modifying a large static array at kernel startup. Each marker is added twice to the array: with and without a "start" indicator. This way the code and logic stays similar to other architectures. Acked-by: Alexander Gordeev <agordeev@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
This commit is contained in:
parent
e09e58f425
commit
d0e7915d2a
|
|
@ -18,89 +18,12 @@ static unsigned long max_addr;
|
||||||
struct addr_marker {
|
struct addr_marker {
|
||||||
int is_start;
|
int is_start;
|
||||||
unsigned long start_address;
|
unsigned long start_address;
|
||||||
|
unsigned long size;
|
||||||
const char *name;
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum address_markers_idx {
|
static struct addr_marker *markers;
|
||||||
KVA_NR = 0,
|
static unsigned int markers_cnt;
|
||||||
LOWCORE_START_NR,
|
|
||||||
LOWCORE_END_NR,
|
|
||||||
AMODE31_START_NR,
|
|
||||||
AMODE31_END_NR,
|
|
||||||
KERNEL_START_NR,
|
|
||||||
KERNEL_END_NR,
|
|
||||||
#ifdef CONFIG_KFENCE
|
|
||||||
KFENCE_START_NR,
|
|
||||||
KFENCE_END_NR,
|
|
||||||
#endif
|
|
||||||
IDENTITY_START_NR,
|
|
||||||
IDENTITY_END_NR,
|
|
||||||
VMEMMAP_NR,
|
|
||||||
VMEMMAP_END_NR,
|
|
||||||
VMALLOC_NR,
|
|
||||||
VMALLOC_END_NR,
|
|
||||||
#ifdef CONFIG_KMSAN
|
|
||||||
KMSAN_VMALLOC_SHADOW_START_NR,
|
|
||||||
KMSAN_VMALLOC_SHADOW_END_NR,
|
|
||||||
KMSAN_VMALLOC_ORIGIN_START_NR,
|
|
||||||
KMSAN_VMALLOC_ORIGIN_END_NR,
|
|
||||||
KMSAN_MODULES_SHADOW_START_NR,
|
|
||||||
KMSAN_MODULES_SHADOW_END_NR,
|
|
||||||
KMSAN_MODULES_ORIGIN_START_NR,
|
|
||||||
KMSAN_MODULES_ORIGIN_END_NR,
|
|
||||||
#endif
|
|
||||||
MODULES_NR,
|
|
||||||
MODULES_END_NR,
|
|
||||||
ABS_LOWCORE_NR,
|
|
||||||
ABS_LOWCORE_END_NR,
|
|
||||||
MEMCPY_REAL_NR,
|
|
||||||
MEMCPY_REAL_END_NR,
|
|
||||||
#ifdef CONFIG_KASAN
|
|
||||||
KASAN_SHADOW_START_NR,
|
|
||||||
KASAN_SHADOW_END_NR,
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct addr_marker address_markers[] = {
|
|
||||||
[KVA_NR] = {0, 0, "Kernel Virtual Address Space"},
|
|
||||||
[LOWCORE_START_NR] = {1, 0, "Lowcore Start"},
|
|
||||||
[LOWCORE_END_NR] = {0, 0, "Lowcore End"},
|
|
||||||
[IDENTITY_START_NR] = {1, 0, "Identity Mapping Start"},
|
|
||||||
[IDENTITY_END_NR] = {0, 0, "Identity Mapping End"},
|
|
||||||
[AMODE31_START_NR] = {1, 0, "Amode31 Area Start"},
|
|
||||||
[AMODE31_END_NR] = {0, 0, "Amode31 Area End"},
|
|
||||||
[KERNEL_START_NR] = {1, (unsigned long)_stext, "Kernel Image Start"},
|
|
||||||
[KERNEL_END_NR] = {0, (unsigned long)_end, "Kernel Image End"},
|
|
||||||
#ifdef CONFIG_KFENCE
|
|
||||||
[KFENCE_START_NR] = {1, 0, "KFence Pool Start"},
|
|
||||||
[KFENCE_END_NR] = {0, 0, "KFence Pool End"},
|
|
||||||
#endif
|
|
||||||
[VMEMMAP_NR] = {1, 0, "vmemmap Area Start"},
|
|
||||||
[VMEMMAP_END_NR] = {0, 0, "vmemmap Area End"},
|
|
||||||
[VMALLOC_NR] = {1, 0, "vmalloc Area Start"},
|
|
||||||
[VMALLOC_END_NR] = {0, 0, "vmalloc Area End"},
|
|
||||||
#ifdef CONFIG_KMSAN
|
|
||||||
[KMSAN_VMALLOC_SHADOW_START_NR] = {1, 0, "Kmsan vmalloc Shadow Start"},
|
|
||||||
[KMSAN_VMALLOC_SHADOW_END_NR] = {0, 0, "Kmsan vmalloc Shadow End"},
|
|
||||||
[KMSAN_VMALLOC_ORIGIN_START_NR] = {1, 0, "Kmsan vmalloc Origins Start"},
|
|
||||||
[KMSAN_VMALLOC_ORIGIN_END_NR] = {0, 0, "Kmsan vmalloc Origins End"},
|
|
||||||
[KMSAN_MODULES_SHADOW_START_NR] = {1, 0, "Kmsan Modules Shadow Start"},
|
|
||||||
[KMSAN_MODULES_SHADOW_END_NR] = {0, 0, "Kmsan Modules Shadow End"},
|
|
||||||
[KMSAN_MODULES_ORIGIN_START_NR] = {1, 0, "Kmsan Modules Origins Start"},
|
|
||||||
[KMSAN_MODULES_ORIGIN_END_NR] = {0, 0, "Kmsan Modules Origins End"},
|
|
||||||
#endif
|
|
||||||
[MODULES_NR] = {1, 0, "Modules Area Start"},
|
|
||||||
[MODULES_END_NR] = {0, 0, "Modules Area End"},
|
|
||||||
[ABS_LOWCORE_NR] = {1, 0, "Lowcore Area Start"},
|
|
||||||
[ABS_LOWCORE_END_NR] = {0, 0, "Lowcore Area End"},
|
|
||||||
[MEMCPY_REAL_NR] = {1, 0, "Real Memory Copy Area Start"},
|
|
||||||
[MEMCPY_REAL_END_NR] = {0, 0, "Real Memory Copy Area End"},
|
|
||||||
#ifdef CONFIG_KASAN
|
|
||||||
[KASAN_SHADOW_START_NR] = {1, KASAN_SHADOW_START, "Kasan Shadow Start"},
|
|
||||||
[KASAN_SHADOW_END_NR] = {0, KASAN_SHADOW_END, "Kasan Shadow End"},
|
|
||||||
#endif
|
|
||||||
{1, -1UL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct pg_state {
|
struct pg_state {
|
||||||
struct ptdump_state ptdump;
|
struct ptdump_state ptdump;
|
||||||
|
|
@ -173,7 +96,8 @@ static void note_page_update_state(struct pg_state *st, unsigned long addr, unsi
|
||||||
|
|
||||||
while (addr >= st->marker[1].start_address) {
|
while (addr >= st->marker[1].start_address) {
|
||||||
st->marker++;
|
st->marker++;
|
||||||
pt_dump_seq_printf(m, "---[ %s ]---\n", st->marker->name);
|
pt_dump_seq_printf(m, "---[ %s %s ]---\n", st->marker->name,
|
||||||
|
st->marker->is_start ? "Start" : "End");
|
||||||
}
|
}
|
||||||
st->start_address = addr;
|
st->start_address = addr;
|
||||||
st->current_prot = prot;
|
st->current_prot = prot;
|
||||||
|
|
@ -202,7 +126,7 @@ static void note_page(struct ptdump_state *pt_st, unsigned long addr, int level,
|
||||||
if (level == -1)
|
if (level == -1)
|
||||||
addr = max_addr;
|
addr = max_addr;
|
||||||
if (st->level == -1) {
|
if (st->level == -1) {
|
||||||
pt_dump_seq_printf(m, "---[ %s ]---\n", st->marker->name);
|
pt_dump_seq_puts(m, "---[ Kernel Virtual Address Space ]---\n");
|
||||||
note_page_update_state(st, addr, prot, level);
|
note_page_update_state(st, addr, prot, level);
|
||||||
} else if (prot != st->current_prot || level != st->level ||
|
} else if (prot != st->current_prot || level != st->level ||
|
||||||
addr >= st->marker[1].start_address) {
|
addr >= st->marker[1].start_address) {
|
||||||
|
|
@ -276,7 +200,7 @@ static int ptdump_show(struct seq_file *m, void *v)
|
||||||
.check_wx = false,
|
.check_wx = false,
|
||||||
.wx_pages = 0,
|
.wx_pages = 0,
|
||||||
.start_address = 0,
|
.start_address = 0,
|
||||||
.marker = address_markers,
|
.marker = markers,
|
||||||
};
|
};
|
||||||
|
|
||||||
get_online_mems();
|
get_online_mems();
|
||||||
|
|
@ -299,10 +223,23 @@ static int ptdump_cmp(const void *a, const void *b)
|
||||||
if (ama->start_address < amb->start_address)
|
if (ama->start_address < amb->start_address)
|
||||||
return -1;
|
return -1;
|
||||||
/*
|
/*
|
||||||
* If the start addresses of two markers are identical consider the
|
* If the start addresses of two markers are identical sort markers in an
|
||||||
* marker which defines the start of an area higher than the one which
|
* order that considers areas contained within other areas correctly.
|
||||||
* defines the end of an area. This keeps pairs of markers sorted.
|
|
||||||
*/
|
*/
|
||||||
|
if (ama->is_start && amb->is_start) {
|
||||||
|
if (ama->size > amb->size)
|
||||||
|
return -1;
|
||||||
|
if (ama->size < amb->size)
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!ama->is_start && !amb->is_start) {
|
||||||
|
if (ama->size > amb->size)
|
||||||
|
return 1;
|
||||||
|
if (ama->size < amb->size)
|
||||||
|
return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if (ama->is_start)
|
if (ama->is_start)
|
||||||
return 1;
|
return 1;
|
||||||
if (amb->is_start)
|
if (amb->is_start)
|
||||||
|
|
@ -310,12 +247,41 @@ static int ptdump_cmp(const void *a, const void *b)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int add_marker(unsigned long start, unsigned long end, const char *name)
|
||||||
|
{
|
||||||
|
size_t oldsize, newsize;
|
||||||
|
|
||||||
|
oldsize = markers_cnt * sizeof(*markers);
|
||||||
|
newsize = oldsize + 2 * sizeof(*markers);
|
||||||
|
if (!oldsize)
|
||||||
|
markers = kvmalloc(newsize, GFP_KERNEL);
|
||||||
|
else
|
||||||
|
markers = kvrealloc(markers, oldsize, newsize, GFP_KERNEL);
|
||||||
|
if (!markers)
|
||||||
|
goto error;
|
||||||
|
markers[markers_cnt].is_start = 1;
|
||||||
|
markers[markers_cnt].start_address = start;
|
||||||
|
markers[markers_cnt].size = end - start;
|
||||||
|
markers[markers_cnt].name = name;
|
||||||
|
markers_cnt++;
|
||||||
|
markers[markers_cnt].is_start = 0;
|
||||||
|
markers[markers_cnt].start_address = end;
|
||||||
|
markers[markers_cnt].size = end - start;
|
||||||
|
markers[markers_cnt].name = name;
|
||||||
|
markers_cnt++;
|
||||||
|
return 0;
|
||||||
|
error:
|
||||||
|
markers_cnt = 0;
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
static int pt_dump_init(void)
|
static int pt_dump_init(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_KFENCE
|
#ifdef CONFIG_KFENCE
|
||||||
unsigned long kfence_start = (unsigned long)__kfence_pool;
|
unsigned long kfence_start = (unsigned long)__kfence_pool;
|
||||||
#endif
|
#endif
|
||||||
unsigned long lowcore = (unsigned long)get_lowcore();
|
unsigned long lowcore = (unsigned long)get_lowcore();
|
||||||
|
int rc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Figure out the maximum virtual address being accessible with the
|
* Figure out the maximum virtual address being accessible with the
|
||||||
|
|
@ -324,41 +290,38 @@ static int pt_dump_init(void)
|
||||||
*/
|
*/
|
||||||
max_addr = (get_lowcore()->kernel_asce.val & _REGION_ENTRY_TYPE_MASK) >> 2;
|
max_addr = (get_lowcore()->kernel_asce.val & _REGION_ENTRY_TYPE_MASK) >> 2;
|
||||||
max_addr = 1UL << (max_addr * 11 + 31);
|
max_addr = 1UL << (max_addr * 11 + 31);
|
||||||
address_markers[LOWCORE_START_NR].start_address = lowcore;
|
/* start + end markers - must be added first */
|
||||||
address_markers[LOWCORE_END_NR].start_address = lowcore + sizeof(struct lowcore);
|
rc = add_marker(0, -1UL, NULL);
|
||||||
address_markers[IDENTITY_START_NR].start_address = __identity_base;
|
rc |= add_marker((unsigned long)_stext, (unsigned long)_end, "Kernel Image");
|
||||||
address_markers[IDENTITY_END_NR].start_address = __identity_base + ident_map_size;
|
rc |= add_marker(lowcore, lowcore + sizeof(struct lowcore), "Lowcore");
|
||||||
address_markers[AMODE31_START_NR].start_address = (unsigned long)__samode31;
|
rc |= add_marker(__identity_base, __identity_base + ident_map_size, "Identity Mapping");
|
||||||
address_markers[AMODE31_END_NR].start_address = (unsigned long)__eamode31;
|
rc |= add_marker((unsigned long)__samode31, (unsigned long)__eamode31, "Amode31 Area");
|
||||||
address_markers[MODULES_NR].start_address = MODULES_VADDR;
|
rc |= add_marker(MODULES_VADDR, MODULES_END, "Modules Area");
|
||||||
address_markers[MODULES_END_NR].start_address = MODULES_END;
|
rc |= add_marker(__abs_lowcore, __abs_lowcore + ABS_LOWCORE_MAP_SIZE, "Lowcore Area");
|
||||||
address_markers[ABS_LOWCORE_NR].start_address = __abs_lowcore;
|
rc |= add_marker(__memcpy_real_area, __memcpy_real_area + MEMCPY_REAL_SIZE, "Real Memory Copy Area");
|
||||||
address_markers[ABS_LOWCORE_END_NR].start_address = __abs_lowcore + ABS_LOWCORE_MAP_SIZE;
|
rc |= add_marker((unsigned long)vmemmap, (unsigned long)vmemmap + vmemmap_size, "vmemmap Area");
|
||||||
address_markers[MEMCPY_REAL_NR].start_address = __memcpy_real_area;
|
rc |= add_marker(VMALLOC_START, VMALLOC_END, "vmalloc Area");
|
||||||
address_markers[MEMCPY_REAL_END_NR].start_address = __memcpy_real_area + MEMCPY_REAL_SIZE;
|
|
||||||
address_markers[VMEMMAP_NR].start_address = (unsigned long) vmemmap;
|
|
||||||
address_markers[VMEMMAP_END_NR].start_address = (unsigned long)vmemmap + vmemmap_size;
|
|
||||||
address_markers[VMALLOC_NR].start_address = VMALLOC_START;
|
|
||||||
address_markers[VMALLOC_END_NR].start_address = VMALLOC_END;
|
|
||||||
#ifdef CONFIG_KFENCE
|
#ifdef CONFIG_KFENCE
|
||||||
address_markers[KFENCE_START_NR].start_address = kfence_start;
|
rc |= add_marker(kfence_start, kfence_start + KFENCE_POOL_SIZE, "KFence Pool");
|
||||||
address_markers[KFENCE_END_NR].start_address = kfence_start + KFENCE_POOL_SIZE;
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_KMSAN
|
#ifdef CONFIG_KMSAN
|
||||||
address_markers[KMSAN_VMALLOC_SHADOW_START_NR].start_address = KMSAN_VMALLOC_SHADOW_START;
|
rc |= add_marker(KMSAN_VMALLOC_SHADOW_START, KMSAN_VMALLOC_SHADOW_END, "Kmsan vmalloc Shadow");
|
||||||
address_markers[KMSAN_VMALLOC_SHADOW_END_NR].start_address = KMSAN_VMALLOC_SHADOW_END;
|
rc |= add_marker(KMSAN_VMALLOC_ORIGIN_START, KMSAN_VMALLOC_ORIGIN_END, "Kmsan vmalloc Origins");
|
||||||
address_markers[KMSAN_VMALLOC_ORIGIN_START_NR].start_address = KMSAN_VMALLOC_ORIGIN_START;
|
rc |= add_marker(KMSAN_MODULES_SHADOW_START, KMSAN_MODULES_SHADOW_END, "Kmsan Modules Shadow");
|
||||||
address_markers[KMSAN_VMALLOC_ORIGIN_END_NR].start_address = KMSAN_VMALLOC_ORIGIN_END;
|
rc |= add_marker(KMSAN_MODULES_ORIGIN_START, KMSAN_MODULES_ORIGIN_END, "Kmsan Modules Origins");
|
||||||
address_markers[KMSAN_MODULES_SHADOW_START_NR].start_address = KMSAN_MODULES_SHADOW_START;
|
|
||||||
address_markers[KMSAN_MODULES_SHADOW_END_NR].start_address = KMSAN_MODULES_SHADOW_END;
|
|
||||||
address_markers[KMSAN_MODULES_ORIGIN_START_NR].start_address = KMSAN_MODULES_ORIGIN_START;
|
|
||||||
address_markers[KMSAN_MODULES_ORIGIN_END_NR].start_address = KMSAN_MODULES_ORIGIN_END;
|
|
||||||
#endif
|
#endif
|
||||||
sort(address_markers, ARRAY_SIZE(address_markers) - 1,
|
#ifdef CONFIG_KASAN
|
||||||
sizeof(address_markers[0]), ptdump_cmp, NULL);
|
rc |= add_marker(KASAN_SHADOW_START, KASAN_SHADOW_END, "Kasan Shadow");
|
||||||
|
#endif
|
||||||
|
if (rc)
|
||||||
|
goto error;
|
||||||
|
sort(&markers[1], markers_cnt - 1, sizeof(*markers), ptdump_cmp, NULL);
|
||||||
#ifdef CONFIG_PTDUMP_DEBUGFS
|
#ifdef CONFIG_PTDUMP_DEBUGFS
|
||||||
debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, &ptdump_fops);
|
debugfs_create_file("kernel_page_tables", 0400, NULL, NULL, &ptdump_fops);
|
||||||
#endif /* CONFIG_PTDUMP_DEBUGFS */
|
#endif /* CONFIG_PTDUMP_DEBUGFS */
|
||||||
return 0;
|
return 0;
|
||||||
|
error:
|
||||||
|
kvfree(markers);
|
||||||
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
device_initcall(pt_dump_init);
|
device_initcall(pt_dump_init);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue