Skip to content

Commit a1a3a06

Browse files
ahunter6acmel
authored andcommitted
perf kcore_copy: Copy x86 PTI entry trampoline sections
Identify and copy any sections for x86 PTI entry trampolines. Signed-off-by: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Dave Hansen <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Joerg Roedel <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent b4503cd commit a1a3a06

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tools/perf/util/symbol-elf.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,11 @@ struct phdr_data {
13921392
struct list_head node;
13931393
};
13941394

1395+
struct sym_data {
1396+
u64 addr;
1397+
struct list_head node;
1398+
};
1399+
13951400
struct kcore_copy_info {
13961401
u64 stext;
13971402
u64 etext;
@@ -1401,6 +1406,7 @@ struct kcore_copy_info {
14011406
u64 last_module_symbol;
14021407
size_t phnum;
14031408
struct list_head phdrs;
1409+
struct list_head syms;
14041410
};
14051411

14061412
#define kcore_copy__for_each_phdr(k, p) \
@@ -1441,6 +1447,29 @@ static void kcore_copy__free_phdrs(struct kcore_copy_info *kci)
14411447
}
14421448
}
14431449

1450+
static struct sym_data *kcore_copy__new_sym(struct kcore_copy_info *kci,
1451+
u64 addr)
1452+
{
1453+
struct sym_data *s = zalloc(sizeof(*s));
1454+
1455+
if (s) {
1456+
s->addr = addr;
1457+
list_add_tail(&s->node, &kci->syms);
1458+
}
1459+
1460+
return s;
1461+
}
1462+
1463+
static void kcore_copy__free_syms(struct kcore_copy_info *kci)
1464+
{
1465+
struct sym_data *s, *tmp;
1466+
1467+
list_for_each_entry_safe(s, tmp, &kci->syms, node) {
1468+
list_del(&s->node);
1469+
free(s);
1470+
}
1471+
}
1472+
14441473
static int kcore_copy__process_kallsyms(void *arg, const char *name, char type,
14451474
u64 start)
14461475
{
@@ -1471,6 +1500,9 @@ static int kcore_copy__process_kallsyms(void *arg, const char *name, char type,
14711500
return 0;
14721501
}
14731502

1503+
if (is_entry_trampoline(name) && !kcore_copy__new_sym(kci, start))
1504+
return -1;
1505+
14741506
return 0;
14751507
}
14761508

@@ -1538,6 +1570,7 @@ static int kcore_copy__read_map(u64 start, u64 len, u64 pgoff, void *data)
15381570
{
15391571
struct kcore_copy_info *kci = data;
15401572
u64 end = start + len;
1573+
struct sym_data *sdat;
15411574

15421575
if (kcore_copy__map(kci, start, end, pgoff, kci->stext, kci->etext))
15431576
return -1;
@@ -1546,6 +1579,13 @@ static int kcore_copy__read_map(u64 start, u64 len, u64 pgoff, void *data)
15461579
kci->last_module_symbol))
15471580
return -1;
15481581

1582+
list_for_each_entry(sdat, &kci->syms, node) {
1583+
u64 s = round_down(sdat->addr, page_size);
1584+
1585+
if (kcore_copy__map(kci, start, end, pgoff, s, s + len))
1586+
return -1;
1587+
}
1588+
15491589
return 0;
15501590
}
15511591

@@ -1740,6 +1780,7 @@ int kcore_copy(const char *from_dir, const char *to_dir)
17401780
struct phdr_data *p;
17411781

17421782
INIT_LIST_HEAD(&kci.phdrs);
1783+
INIT_LIST_HEAD(&kci.syms);
17431784

17441785
if (kcore_copy__copy_file(from_dir, to_dir, "kallsyms"))
17451786
return -1;
@@ -1806,6 +1847,7 @@ int kcore_copy(const char *from_dir, const char *to_dir)
18061847
kcore_copy__unlink(to_dir, "kallsyms");
18071848

18081849
kcore_copy__free_phdrs(&kci);
1850+
kcore_copy__free_syms(&kci);
18091851

18101852
return err;
18111853
}

0 commit comments

Comments
 (0)