From: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
To: Adrian Hunter <adrian.hunter@intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
namhyung@kernel.org, maddy@linux.ibm.com, kjain@linux.ibm.com,
disgoel@linux.vnet.ibm.com, linux-perf-users@vger.kernel.org,
Disha Goel <disgoel@linux.ibm.com>,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH V2 2/2] tools/perf/tests: Fix object code reading to skip address that falls out of text section
Date: Thu, 7 Sep 2023 21:25:50 +0530 [thread overview]
Message-ID: <CA07D95F-CEDF-43B2-99B5-D71262E0FC2F@linux.vnet.ibm.com> (raw)
In-Reply-To: <da3492ac-5473-f25b-f229-f213242321b1@intel.com>
> On 18-Aug-2023, at 12:45 PM, Adrian Hunter <adrian.hunter@intel.com> wrote:
>
> On 17/08/23 20:18, Athira Rajeev wrote:
>> The testcase "Object code reading" fails in somecases
>> for "fs_something" sub test as below:
>>
>> Reading object code for memory address: 0xc008000007f0142c
>> File is: /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko
>> On file address is: 0x1114cc
>> Objdump command is: objdump -z -d --start-address=0x11142c --stop-address=0x1114ac /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko
>> objdump read too few bytes: 128
>> test child finished with -1
>>
>> This can alo be reproduced when running perf record with
>> workload that exercises fs_something() code. In the test
>> setup, this is exercising xfs code since root is xfs.
>>
>> # perf record ./a.out
>> # perf report -v |grep "xfs.ko"
>> 0.76% a.out /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko 0xc008000007de5efc B [k] xlog_cil_commit
>> 0.74% a.out /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko 0xc008000007d5ae18 B [k] xfs_btree_key_offset
>> 0.74% a.out /lib/modules/6.5.0-rc3+/kernel/fs/xfs/xfs.ko 0xc008000007e11fd4 B [k] 0x0000000000112074
>>
>> Here addr "0xc008000007e11fd4" is not resolved. since this is a
>> kernel module, its offset is from the DSO. Xfs module is loaded
>> at 0xc008000007d00000
>>
>> # cat /proc/modules | grep xfs
>> xfs 2228224 3 - Live 0xc008000007d00000
>>
>> And size is 0x220000. So its loaded between 0xc008000007d00000
>> and 0xc008000007f20000. From objdump, text section is:
>> text 0010f7bc 0000000000000000 0000000000000000 000000a0 2**4
>>
>> Hence perf captured ip maps to 0x112074 which is:
>> ( ip - start of module ) + a0
>>
>> This offset 0x112074 falls out .text section which is up to 0x10f7bc
>> In this case for module, the address 0xc008000007e11fd4 is pointing
>> to stub instructions. This address range represents the module stubs
>> which is allocated on module load and hence is not part of DSO offset.
>>
>> To address this issue in "object code reading", skip the sample if
>> address falls out of text section and is within the module end.
>> Use the "text_end" member of "struct dso" to do this check.
>>
>> To address this issue in "perf report", exploring an option of
>> having stubs range as part of the /proc/kallsyms, so that perf
>> report can resolve addresses in stubs range
>>
>> However this patch uses text_end to skip the stub range for
>> Object code reading testcase.
>>
>> Reported-by: Disha Goel <disgoel@linux.ibm.com>
>> Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
>> ---
>> tools/perf/tests/code-reading.c | 8 ++++++++
>> 1 file changed, 8 insertions(+)
>>
>> diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
>> index ed3815163d1b..911f8fa13677 100644
>> --- a/tools/perf/tests/code-reading.c
>> +++ b/tools/perf/tests/code-reading.c
>> @@ -269,6 +269,14 @@ static int read_object_code(u64 addr, size_t len, u8 cpumode,
>> if (addr + len > map__end(al.map))
>> len = map__end(al.map) - addr;
>>
>> + /* Check if the ip offset falls in stubs sections for kernel modules */
>
> What arches have stubs - maybe expand the comment a bit e.g.
> "Some architectures (such as blah blah) have stubs (trampolines) in kernel modules to manage long jumps”
Ok
>
>> + if (strstr(dso->long_name, ".ko")) {
>> + if ((al.addr < map__end(al.map)) && (al.addr > dso->text_end)) {
>
> Why check al.addr < map__end(al.map) ? addr must be on the map mustn't it?
Yes, you are right.
>
> Also please remove redundant parentheses.
>
>> + pr_debug(" - skipping\n");
>
> "skipping" but why. Maybe "skipping module address after text end"
Sure, will post V2 with these changes
Thanks
Athira
>
>> + goto out;
>> + }
>> + }
>> +
>> /* Read the object code using perf */
>> ret_len = dso__data_read_offset(dso, maps__machine(thread__maps(thread)),
>> al.addr, buf1, len);
next prev parent reply other threads:[~2023-09-07 16:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-17 17:18 [PATCH V2 1/2] tools/perf: Add text_end to "struct dso" to save .text section size Athira Rajeev
2023-08-17 17:18 ` [PATCH V2 2/2] tools/perf/tests: Fix object code reading to skip address that falls out of text section Athira Rajeev
2023-08-18 7:15 ` Adrian Hunter
2023-09-07 15:55 ` Athira Rajeev [this message]
2023-08-18 6:37 ` [PATCH V2 1/2] tools/perf: Add text_end to "struct dso" to save .text section size Adrian Hunter
2023-09-07 15:54 ` Athira Rajeev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CA07D95F-CEDF-43B2-99B5-D71262E0FC2F@linux.vnet.ibm.com \
--to=atrajeev@linux.vnet.ibm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=disgoel@linux.ibm.com \
--cc=disgoel@linux.vnet.ibm.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kjain@linux.ibm.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).