From: Vasily Gorbik <gor@linux.ibm.com>
To: Josh Poimboeuf <jpoimboe@redhat.com>,
Shile Zhang <shile.zhang@linux.alibaba.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Miroslav Benes <mbenes@suse.cz>,
Alexandre Chartre <alexandre.chartre@oracle.com>,
Julien Thierry <jthierry@redhat.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH] scripts/sorttable: Fix ORC unwind table sorting on big endian
Date: Sat, 14 Nov 2020 13:53:10 +0100 [thread overview]
Message-ID: <patch.git-45d71f2e4f14.your-ad-here.call-01605357883-ext-1218@work.hours> (raw)
In-Reply-To: <cover.thread-1e2854.your-ad-here.call-01605220128-ext-6070@work.hours>
Currently when x86_64 kernel is cross compiled on big endian hardware
ORC unwind table is not sorted correctly. Due to missing byte swaps and
treating size as 4-byte value ORC sections sizes end up as 0 and the
problem is silently ignored.
Make ORC unwind table sorting endianness aware.
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
This goes on top of the patch series:
http://lkml.kernel.org/r/cover.thread-1e2854.your-ad-here.call-01605220128-ext-6070@work.hours
scripts/sorttable.h | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/scripts/sorttable.h b/scripts/sorttable.h
index a2baa2fefb13..99f3fa1767d1 100644
--- a/scripts/sorttable.h
+++ b/scripts/sorttable.h
@@ -59,6 +59,8 @@
# define uint_t uint64_t
# define _r r8
# define _w w8
+# define _r4 r
+# define _w4 w
#else
# define extable_ent_size 8
# define compare_extable compare_extable_32
@@ -80,6 +82,8 @@
# define uint_t uint32_t
# define _r r
# define _w w
+# define _r4 r
+# define _w4 w
#endif
#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
@@ -98,7 +102,7 @@ pthread_t orc_sort_thread;
static inline unsigned long orc_ip(const int *ip)
{
- return (unsigned long)ip + *ip;
+ return (unsigned long)ip + (int)_r4((uint32_t *)ip);
}
static int orc_sort_cmp(const void *_a, const void *_b)
@@ -158,7 +162,7 @@ static void *sort_orctable(void *arg)
/* initialize indices array, convert ip_table to absolute address */
for (i = 0; i < num_entries; i++) {
idxs[i] = i;
- tmp_orc_ip_table[i] = g_orc_ip_table[i] + i * sizeof(int);
+ tmp_orc_ip_table[i] = (int)_r4((uint32_t *)&g_orc_ip_table[i]) + i * sizeof(int);
}
memcpy(tmp_orc_table, g_orc_table, orc_size);
@@ -169,7 +173,7 @@ static void *sort_orctable(void *arg)
continue;
/* convert back to relative address */
- g_orc_ip_table[i] = tmp_orc_ip_table[idxs[i]] - i * sizeof(int);
+ _w4(tmp_orc_ip_table[idxs[i]] - i * sizeof(int), (uint32_t *)&g_orc_ip_table[i]);
g_orc_table[i] = tmp_orc_table[idxs[i]];
}
@@ -256,14 +260,12 @@ static int do_sort(Elf_Ehdr *ehdr,
#if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED)
/* locate the ORC unwind tables */
if (!strcmp(secstrings + idx, ".orc_unwind_ip")) {
- orc_ip_size = s->sh_size;
- g_orc_ip_table = (int *)((void *)ehdr +
- s->sh_offset);
+ orc_ip_size = _r(&s->sh_size);
+ g_orc_ip_table = (int *)((void *)ehdr + _r(&s->sh_offset));
}
if (!strcmp(secstrings + idx, ".orc_unwind")) {
- orc_size = s->sh_size;
- g_orc_table = (struct orc_entry *)((void *)ehdr +
- s->sh_offset);
+ orc_size = _r(&s->sh_size);
+ g_orc_table = (struct orc_entry *)((void *)ehdr + _r(&s->sh_offset));
}
#endif
} /* for loop */
--
2.25.4
next prev parent reply other threads:[~2020-11-14 12:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-12 23:03 [PATCH v5 0/5] objtool and cross compilation Vasily Gorbik
2020-11-12 23:03 ` [PATCH v5 1/5] x86/tools: Use tools headers for instruction decoder selftests Vasily Gorbik
2020-11-12 23:03 ` [PATCH v5 2/5] x86/insn: Support big endian cross-compiles Vasily Gorbik
2020-11-12 23:03 ` [PATCH v5 3/5] objtool: Fix reloc generation on big endian cross compiles Vasily Gorbik
2020-11-12 23:03 ` [PATCH v5 4/5] objtool: Fix x86 orc " Vasily Gorbik
2020-11-12 23:03 ` [PATCH v5 5/5] objtool: Rework header include paths Vasily Gorbik
2020-11-13 8:06 ` Peter Zijlstra
2020-11-13 16:09 ` [PATCH] x86/insn: Fix vector instructions decoding on big endian Vasily Gorbik
2020-11-13 17:30 ` Josh Poimboeuf
2020-11-24 13:33 ` Vasily Gorbik
2020-11-25 16:27 ` Masami Hiramatsu
2020-11-14 12:53 ` Vasily Gorbik [this message]
2020-11-24 13:34 ` [PATCH] scripts/sorttable: Fix ORC unwind table sorting " Vasily Gorbik
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=patch.git-45d71f2e4f14.your-ad-here.call-01605357883-ext-1218@work.hours \
--to=gor@linux.ibm.com \
--cc=alexandre.chartre@oracle.com \
--cc=bp@alien8.de \
--cc=hpa@zytor.com \
--cc=jpoimboe@redhat.com \
--cc=jthierry@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=shile.zhang@linux.alibaba.com \
--cc=tglx@linutronix.de \
--cc=x86@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