Skip to content

Commit 12a6d29

Browse files
Thomas Richteracmel
authored andcommitted
perf record: Fix module size on s390
On s390 the modules loaded in memory have the text segment located after the GOT and Relocation table. This can be seen with this output: [root@m35lp76 perf]# fgrep qeth /proc/modules qeth 151552 1 qeth_l2, Live 0x000003ff800b2000 ... [root@m35lp76 perf]# cat /sys/module/qeth/sections/.text 0x000003ff800b3990 [root@m35lp76 perf]# There is an offset of 0x1990 bytes. The size of the qeth module is 151552 bytes (0x25000 in hex). The location of the GOT/relocation table at the beginning of a module is unique to s390. commit 203d8a4 ("perf s390: Fix 'start' address of module's map") adjusts the start address of a module in the map structures, but does not adjust the size of the modules. This leads to overlapping of module maps as this example shows: [root@m35lp76 perf] # ./perf report -D 0 0 0xfb0 [0xa0]: PERF_RECORD_MMAP -1/0: [0x3ff800b3990(0x25000) @ 0]: x /lib/modules/.../qeth.ko.xz 0 0 0x1050 [0xb0]: PERF_RECORD_MMAP -1/0: [0x3ff800d85a0(0x8000) @ 0]: x /lib/modules/.../ip6_tables.ko.xz The module qeth.ko has an adjusted start address modified to b3990, but its size is unchanged and the module ends at 0x3ff800d8990. This end address overlaps with the next modules start address of 0x3ff800d85a0. When the size of the leading GOT/Relocation table stored in the beginning of the text segment (0x1990 bytes) is subtracted from module qeth end address, there are no overlaps anymore: 0x3ff800d8990 - 0x1990 = 0x0x3ff800d7000 which is the same as 0x3ff800b2000 + 0x25000 = 0x0x3ff800d7000. To fix this issue, also adjust the modules size in function arch__fix_module_text_start(). Add another function parameter named size and reduce the size of the module when the text segment start address is changed. Output after: 0 0 0xfb0 [0xa0]: PERF_RECORD_MMAP -1/0: [0x3ff800b3990(0x23670) @ 0]: x /lib/modules/.../qeth.ko.xz 0 0 0x1050 [0xb0]: PERF_RECORD_MMAP -1/0: [0x3ff800d85a0(0x7a60) @ 0]: x /lib/modules/.../ip6_tables.ko.xz Reported-by: Stefan Liebler <[email protected]> Signed-off-by: Thomas Richter <[email protected]> Acked-by: Heiko Carstens <[email protected]> Cc: Hendrik Brueckner <[email protected]> Cc: Vasily Gorbik <[email protected]> Cc: [email protected] Fixes: 203d8a4 ("perf s390: Fix 'start' address of module's map") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent fa37bab commit 12a6d29

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

tools/perf/arch/s390/util/machine.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "api/fs/fs.h"
88
#include "debug.h"
99

10-
int arch__fix_module_text_start(u64 *start, const char *name)
10+
int arch__fix_module_text_start(u64 *start, u64 *size, const char *name)
1111
{
1212
u64 m_start = *start;
1313
char path[PATH_MAX];
@@ -17,6 +17,18 @@ int arch__fix_module_text_start(u64 *start, const char *name)
1717
if (sysfs__read_ull(path, (unsigned long long *)start) < 0) {
1818
pr_debug2("Using module %s start:%#lx\n", path, m_start);
1919
*start = m_start;
20+
} else {
21+
/* Successful read of the modules segment text start address.
22+
* Calculate difference between module start address
23+
* in memory and module text segment start address.
24+
* For example module load address is 0x3ff8011b000
25+
* (from /proc/modules) and module text segment start
26+
* address is 0x3ff8011b870 (from file above).
27+
*
28+
* Adjust the module size and subtract the GOT table
29+
* size located at the beginning of the module.
30+
*/
31+
*size -= (*start - m_start);
2032
}
2133

2234
return 0;

tools/perf/util/machine.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ static int machine__set_modules_path(struct machine *machine)
13781378
return map_groups__set_modules_path_dir(&machine->kmaps, modules_path, 0);
13791379
}
13801380
int __weak arch__fix_module_text_start(u64 *start __maybe_unused,
1381+
u64 *size __maybe_unused,
13811382
const char *name __maybe_unused)
13821383
{
13831384
return 0;
@@ -1389,7 +1390,7 @@ static int machine__create_module(void *arg, const char *name, u64 start,
13891390
struct machine *machine = arg;
13901391
struct map *map;
13911392

1392-
if (arch__fix_module_text_start(&start, name) < 0)
1393+
if (arch__fix_module_text_start(&start, &size, name) < 0)
13931394
return -1;
13941395

13951396
map = machine__findnew_module_map(machine, start, name);

tools/perf/util/machine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ struct symbol *machine__find_kernel_symbol_by_name(struct machine *machine,
222222

223223
struct map *machine__findnew_module_map(struct machine *machine, u64 start,
224224
const char *filename);
225-
int arch__fix_module_text_start(u64 *start, const char *name);
225+
int arch__fix_module_text_start(u64 *start, u64 *size, const char *name);
226226

227227
int machine__load_kallsyms(struct machine *machine, const char *filename);
228228

0 commit comments

Comments
 (0)