Skip to content

Commit 22916fd

Browse files
ahunter6acmel
authored andcommitted
perf kcore_copy: Amend the offset of sections that remap kernel text
x86 PTI entry trampolines all map to the same physical page. If that is reflected in the program headers of /proc/kcore, then do the same for the copy of kcore. 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 a1a3a06 commit 22916fd

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

tools/perf/util/symbol-elf.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,7 @@ struct phdr_data {
13901390
u64 addr;
13911391
u64 len;
13921392
struct list_head node;
1393+
struct phdr_data *remaps;
13931394
};
13941395

13951396
struct sym_data {
@@ -1597,16 +1598,62 @@ static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf)
15971598
return 0;
15981599
}
15991600

1601+
static void kcore_copy__find_remaps(struct kcore_copy_info *kci)
1602+
{
1603+
struct phdr_data *p, *k = NULL;
1604+
u64 kend;
1605+
1606+
if (!kci->stext)
1607+
return;
1608+
1609+
/* Find phdr that corresponds to the kernel map (contains stext) */
1610+
kcore_copy__for_each_phdr(kci, p) {
1611+
u64 pend = p->addr + p->len - 1;
1612+
1613+
if (p->addr <= kci->stext && pend >= kci->stext) {
1614+
k = p;
1615+
break;
1616+
}
1617+
}
1618+
1619+
if (!k)
1620+
return;
1621+
1622+
kend = k->offset + k->len;
1623+
1624+
/* Find phdrs that remap the kernel */
1625+
kcore_copy__for_each_phdr(kci, p) {
1626+
u64 pend = p->offset + p->len;
1627+
1628+
if (p == k)
1629+
continue;
1630+
1631+
if (p->offset >= k->offset && pend <= kend)
1632+
p->remaps = k;
1633+
}
1634+
}
1635+
16001636
static void kcore_copy__layout(struct kcore_copy_info *kci)
16011637
{
16021638
struct phdr_data *p;
16031639
off_t rel = 0;
16041640

1641+
kcore_copy__find_remaps(kci);
1642+
16051643
kcore_copy__for_each_phdr(kci, p) {
1606-
p->rel = rel;
1607-
rel += p->len;
1644+
if (!p->remaps) {
1645+
p->rel = rel;
1646+
rel += p->len;
1647+
}
16081648
kci->phnum += 1;
16091649
}
1650+
1651+
kcore_copy__for_each_phdr(kci, p) {
1652+
struct phdr_data *k = p->remaps;
1653+
1654+
if (k)
1655+
p->rel = p->offset - k->offset + k->rel;
1656+
}
16101657
}
16111658

16121659
static int kcore_copy__calc_maps(struct kcore_copy_info *kci, const char *dir,
@@ -1821,6 +1868,8 @@ int kcore_copy(const char *from_dir, const char *to_dir)
18211868
kcore_copy__for_each_phdr(&kci, p) {
18221869
off_t offs = p->rel + offset;
18231870

1871+
if (p->remaps)
1872+
continue;
18241873
if (copy_bytes(kcore.fd, p->offset, extract.fd, offs, p->len))
18251874
goto out_extract_close;
18261875
}

0 commit comments

Comments
 (0)