From: Sven Schnelle <svens@linux.ibm.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: keescook@chromium.org, hca@linux.ibm.com,
linux-kernel@vger.kernel.org,
Steven Rostedt <rostedt@goodmis.org>,
Sachin Sant <sachinp@linux.ibm.com>,
Yinan Liu <yinan@linux.alibaba.com>,
linuxppc-dev@lists.ozlabs.org, ardb@kernel.org
Subject: Re: [powerpc] ftrace warning kernel/trace/ftrace.c:2068 with code-patching selftests
Date: Thu, 27 Jan 2022 14:16:31 +0100 [thread overview]
Message-ID: <yt9dsft9gvyo.fsf@linux.ibm.com> (raw)
In-Reply-To: <YfKZXvB9vCN1bA1c@FVFF77S0Q05N> (Mark Rutland's message of "Thu, 27 Jan 2022 13:08:46 +0000")
Mark Rutland <mark.rutland@arm.com> writes:
> On Thu, Jan 27, 2022 at 07:46:01AM -0500, Steven Rostedt wrote:
>> On Thu, 27 Jan 2022 12:27:04 +0000
>> Mark Rutland <mark.rutland@arm.com> wrote:
>>
>> > Ah, so those non-ELF relocations for the mcount_loc table just mean "apply the
>> > KASLR offset here", which is equivalent for all entries.
>> >
>> > That makes sense, thanks!
>>
>> And this is why we were having such a hard time understanding each other ;-)
>
> ;)
>
> With that in mind, I think that we understand that the build-time sort works
> for:
>
> * arch/x86, becuase the non-ELF relocations for mcount_loc happen to be
> equivalent.
>
> * arch/arm, because there's no dynamic relocaiton and the mcount_loc entries
> have been finalized prior to sorting.
>
> ... but doesn't work for anyone else (including arm64) because the ELF
> relocations are not equivalent, and need special care that is not yet
> implemented.
For s390 my idea is to just skip the addresses between __start_mcount_loc
and __stop_mcount_loc, because for these addresses we know that they are
64 bits wide, so we just need to add the KASLR offset.
I'm thinking about something like this:
diff --git a/arch/s390/boot/compressed/decompressor.h b/arch/s390/boot/compressed/decompressor.h
index f75cc31a77dd..015d7e2e94ef 100644
--- a/arch/s390/boot/compressed/decompressor.h
+++ b/arch/s390/boot/compressed/decompressor.h
@@ -25,6 +25,8 @@ struct vmlinux_info {
unsigned long rela_dyn_start;
unsigned long rela_dyn_end;
unsigned long amode31_size;
+ unsigned long start_mcount_loc;
+ unsigned long stop_mcount_loc;
};
/* Symbols defined by linker scripts */
diff --git a/arch/s390/boot/startup.c b/arch/s390/boot/startup.c
index 1aa11a8f57dd..7bb0d88db5c6 100644
--- a/arch/s390/boot/startup.c
+++ b/arch/s390/boot/startup.c
@@ -88,6 +88,11 @@ static void handle_relocs(unsigned long offset)
dynsym = (Elf64_Sym *) vmlinux.dynsym_start;
for (rela = rela_start; rela < rela_end; rela++) {
loc = rela->r_offset + offset;
+ if ((loc >= vmlinux.start_mcount_loc) &&
+ (loc < vmlinux.stop_mcount_loc)) {
+ (*(unsigned long *)loc) += offset;
+ continue;
+ }
val = rela->r_addend;
r_sym = ELF64_R_SYM(rela->r_info);
if (r_sym) {
@@ -232,6 +237,8 @@ static void offset_vmlinux_info(unsigned long offset)
vmlinux.rela_dyn_start += offset;
vmlinux.rela_dyn_end += offset;
vmlinux.dynsym_start += offset;
+ vmlinux.start_mcount_loc += offset;
+ vmlinux.stop_mcount_loc += offset;
}
static unsigned long reserve_amode31(unsigned long safe_addr)
diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S
index 42c43521878f..51c773405608 100644
--- a/arch/s390/kernel/vmlinux.lds.S
+++ b/arch/s390/kernel/vmlinux.lds.S
@@ -213,6 +213,8 @@ SECTIONS
QUAD(__rela_dyn_start) /* rela_dyn_start */
QUAD(__rela_dyn_end) /* rela_dyn_end */
QUAD(_eamode31 - _samode31) /* amode31_size */
+ QUAD(__start_mcount_loc)
+ QUAD(__stop_mcount_loc)
} :NONE
/* Debugging sections. */
Not sure whether that would also work on power, and also not sure
whether i missed something thinking about that. Maybe it doesn't even
work. ;-)
next prev parent reply other threads:[~2022-01-27 21:45 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 9:19 [powerpc] ftrace warning kernel/trace/ftrace.c:2068 with code-patching selftests Sachin Sant
2022-01-24 12:15 ` Yinan Liu
2022-01-24 16:45 ` Steven Rostedt
2022-01-25 3:20 ` Yinan Liu
2022-01-26 14:37 ` Mark Rutland
2022-01-27 11:46 ` Mark Rutland
2022-01-27 12:03 ` Ard Biesheuvel
2022-01-27 12:20 ` Mark Rutland
2022-01-27 12:22 ` Ard Biesheuvel
2022-01-27 12:59 ` Mark Rutland
2022-01-27 13:07 ` Ard Biesheuvel
2022-01-27 13:24 ` Mark Rutland
2022-01-27 13:59 ` Ard Biesheuvel
2022-01-27 14:54 ` Mark Rutland
2022-01-27 15:01 ` Ard Biesheuvel
2022-01-27 12:04 ` Sven Schnelle
2022-01-27 12:27 ` Mark Rutland
2022-01-27 12:46 ` Steven Rostedt
2022-01-27 13:08 ` Mark Rutland
2022-01-27 13:16 ` Sven Schnelle [this message]
2022-01-27 13:33 ` Mark Rutland
2022-01-27 13:55 ` Steven Rostedt
2022-01-27 14:56 ` Mark Rutland
2022-01-27 16:41 ` Kees Cook
2022-01-25 4:00 ` Sachin Sant
2022-01-25 14:28 ` Steven Rostedt
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=yt9dsft9gvyo.fsf@linux.ibm.com \
--to=svens@linux.ibm.com \
--cc=ardb@kernel.org \
--cc=hca@linux.ibm.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mark.rutland@arm.com \
--cc=rostedt@goodmis.org \
--cc=sachinp@linux.ibm.com \
--cc=yinan@linux.alibaba.com \
/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).