linux-stable/tools
Thomas Richter eac8b39d08 perf report: Fix OOM error in TUI mode on s390
[ Upstream commit 8a07aa4e9b ]

Debugging a OOM error using the TUI interface revealed this issue
on s390:

[tmricht@m83lp54 perf]$ cat /proc/kallsyms |sort
....
00000001119b7158 B radix_tree_node_cachep
00000001119b8000 B __bss_stop
00000001119b8000 B _end
000003ff80002850 t autofs_mount	[autofs4]
000003ff80002868 t autofs_show_options	[autofs4]
000003ff80002a98 t autofs_evict_inode	[autofs4]
....

There is a huge gap between the last kernel symbol
__bss_stop/_end and the first kernel module symbol
autofs_mount (from autofs4 module).

After reading the kernel symbol table via functions:

 dso__load()
 +--> dso__load_kernel_sym()
      +--> dso__load_kallsyms()
	   +--> __dso_load_kallsyms()
	        +--> symbols__fixup_end()

the symbol __bss_stop has a start address of 1119b8000 and
an end address of 3ff80002850, as can be seen by this debug statement:

  symbols__fixup_end __bss_stop start:0x1119b8000 end:0x3ff80002850

The size of symbol __bss_stop is 0x3fe6e64a850 bytes!
It is the last kernel symbol and fills up the space until
the first kernel module symbol.

This size kills the TUI interface when executing the following
code:

  process_sample_event()
    hist_entry_iter__add()
      hist_iter__report_callback()
        hist_entry__inc_addr_samples()
          symbol__inc_addr_samples(symbol = __bss_stop)
            symbol__cycles_hist()
               annotated_source__alloc_histograms(...,
				                symbol__size(sym),
		                                ...)

This function allocates memory to save sample histograms.
The symbol_size() marco is defined as sym->end - sym->start, which
results in above value of 0x3fe6e64a850 bytes and
the call to calloc() in annotated_source__alloc_histograms() fails.

The histgram memory allocation might fail, make this failure
no-fatal and continue processing.

Output before:
[tmricht@m83lp54 perf]$ ./perf --debug stderr=1 report -vvvvv \
					      -i ~/slow.data 2>/tmp/2
[tmricht@m83lp54 perf]$ tail -5 /tmp/2
  __symbol__inc_addr_samples(875): ENOMEM! sym->name=__bss_stop,
		start=0x1119b8000, addr=0x2aa0005eb08, end=0x3ff80002850,
		func: 0
problem adding hist entry, skipping event
0x938b8 [0x8]: failed to process type: 68 [Cannot allocate memory]
[tmricht@m83lp54 perf]$

Output after:
[tmricht@m83lp54 perf]$ ./perf --debug stderr=1 report -vvvvv \
					      -i ~/slow.data 2>/tmp/2
[tmricht@m83lp54 perf]$ tail -5 /tmp/2
   symbol__inc_addr_samples map:0x1597830 start:0x110730000 end:0x3ff80002850
   symbol__hists notes->src:0x2aa2a70 nr_hists:1
   symbol__inc_addr_samples sym:unlink_anon_vmas src:0x2aa2a70
   __symbol__inc_addr_samples: addr=0x11094c69e
   0x11094c670 unlink_anon_vmas: period++ [addr: 0x11094c69e, 0x2e, evidx=0]
   	=> nr_samples: 1, period: 526008
[tmricht@m83lp54 perf]$

There is no error about failed memory allocation and the TUI interface
shows all entries.

Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
Link: http://lkml.kernel.org/r/90cb5607-3e12-5167-682d-978eba7dafa8@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2019-07-26 09:14:05 +02:00
..
accounting
arch jump_label: move 'asm goto' support test to Kconfig 2019-06-04 08:02:34 +02:00
bpf bpftool: exclude bash-completion/bpftool from .gitignore pattern 2019-05-31 06:46:08 -07:00
build perf build: Don't unconditionally link the libbfd feature test to -liberty and -lz 2019-02-12 19:47:16 +01:00
cgroup
firewire
gpio
hv Tools: hv: kvp: Fix a warning of buffer overflow with gcc 8.0.1 2019-02-12 19:46:59 +01:00
iio tools: iio: iio_generic_buffer: make num_loops signed 2019-02-15 08:10:10 +01:00
include tools include: Adopt linux/bits.h 2019-04-27 09:36:40 +02:00
kvm/kvm_stat tools/kvm_stat: fix fields filter for child events 2019-06-19 08:18:05 +02:00
laptop
leds
lib libbpf: fix samples/bpf build failure due to undefined UINT32_MAX 2019-05-31 06:46:14 -07:00
memory-model tools/memory-model: Rename litmus tests to comply to norm7 2018-07-17 09:30:36 +02:00
nfsd
objtool objtool: Support per-function rodata sections 2019-06-25 11:35:52 +08:00
pci tools: PCI: Add MSI-X support 2018-07-19 11:47:13 +01:00
pcmcia
perf perf report: Fix OOM error in TUI mode on s390 2019-07-26 09:14:05 +02:00
power cpupower : frequency-set -r option misses the last cpu in related cpu list 2019-07-26 09:14:03 +02:00
scripts
spi
testing selftests: fib_rule_tests: Fix icmp proto with ipv6 2019-07-10 09:53:45 +02:00
thermal/tmon
time
usb usbip: fix vhci_hcd controller counting 2019-04-20 09:16:01 +02:00
virtio virtio: fix test build after uio.h change 2019-01-13 09:51:03 +01:00
vm tools/vm/page-types.c: fix "defined but not used" warning 2018-09-04 16:45:02 -07:00
wmi
Makefile