diff options
| author | Adrian Hunter <adrian.hunter@intel.com> | 2018-05-22 06:54:45 -0400 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2018-05-23 09:26:44 -0400 |
| commit | 22916fdb9c50e8fb303bdcedca88fd8798a85844 (patch) | |
| tree | b472f57dedf889ceb56407840a4b218c8014fade | |
| parent | a1a3a0624e6cd0e2c46a7400800a5e687521a504 (diff) | |
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 <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86@kernel.org
Link: http://lkml.kernel.org/r/1526986485-6562-18-git-send-email-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
| -rw-r--r-- | tools/perf/util/symbol-elf.c | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c index 584966913aeb..29770ea61768 100644 --- a/tools/perf/util/symbol-elf.c +++ b/tools/perf/util/symbol-elf.c | |||
| @@ -1390,6 +1390,7 @@ struct phdr_data { | |||
| 1390 | u64 addr; | 1390 | u64 addr; |
| 1391 | u64 len; | 1391 | u64 len; |
| 1392 | struct list_head node; | 1392 | struct list_head node; |
| 1393 | struct phdr_data *remaps; | ||
| 1393 | }; | 1394 | }; |
| 1394 | 1395 | ||
| 1395 | struct sym_data { | 1396 | struct sym_data { |
| @@ -1597,16 +1598,62 @@ static int kcore_copy__read_maps(struct kcore_copy_info *kci, Elf *elf) | |||
| 1597 | return 0; | 1598 | return 0; |
| 1598 | } | 1599 | } |
| 1599 | 1600 | ||
| 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 | |||
| 1600 | static void kcore_copy__layout(struct kcore_copy_info *kci) | 1636 | static void kcore_copy__layout(struct kcore_copy_info *kci) |
| 1601 | { | 1637 | { |
| 1602 | struct phdr_data *p; | 1638 | struct phdr_data *p; |
| 1603 | off_t rel = 0; | 1639 | off_t rel = 0; |
| 1604 | 1640 | ||
| 1641 | kcore_copy__find_remaps(kci); | ||
| 1642 | |||
| 1605 | kcore_copy__for_each_phdr(kci, p) { | 1643 | kcore_copy__for_each_phdr(kci, p) { |
| 1606 | p->rel = rel; | 1644 | if (!p->remaps) { |
| 1607 | rel += p->len; | 1645 | p->rel = rel; |
| 1646 | rel += p->len; | ||
| 1647 | } | ||
| 1608 | kci->phnum += 1; | 1648 | kci->phnum += 1; |
| 1609 | } | 1649 | } |
| 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 | } | ||
| 1610 | } | 1657 | } |
| 1611 | 1658 | ||
| 1612 | static int kcore_copy__calc_maps(struct kcore_copy_info *kci, const char *dir, | 1659 | 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) | |||
| 1821 | kcore_copy__for_each_phdr(&kci, p) { | 1868 | kcore_copy__for_each_phdr(&kci, p) { |
| 1822 | off_t offs = p->rel + offset; | 1869 | off_t offs = p->rel + offset; |
| 1823 | 1870 | ||
| 1871 | if (p->remaps) | ||
| 1872 | continue; | ||
| 1824 | if (copy_bytes(kcore.fd, p->offset, extract.fd, offs, p->len)) | 1873 | if (copy_bytes(kcore.fd, p->offset, extract.fd, offs, p->len)) |
| 1825 | goto out_extract_close; | 1874 | goto out_extract_close; |
| 1826 | } | 1875 | } |
