2021-05-07 00:03:26

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH 05/13] jump_label, x86: Improve error when we fail expected text

There is only a single usage site left, remove the function and extend
the print to include more information, like the expected text and the
patch type.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
arch/x86/kernel/jump_label.c | 33 ++++++++++++++-------------------
1 file changed, 14 insertions(+), 19 deletions(-)

--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -16,38 +16,33 @@
#include <asm/alternative.h>
#include <asm/text-patching.h>

-static void bug_at(const void *ip, int line)
-{
- /*
- * The location is not an op that we were expecting.
- * Something went wrong. Crash the box, as something could be
- * corrupting the kernel.
- */
- pr_crit("jump_label: Fatal kernel bug, unexpected op at %pS [%p] (%5ph) %d\n", ip, ip, ip, line);
- BUG();
-}
-
static const void *
__jump_label_set_jump_code(struct jump_entry *entry, enum jump_label_type type)
{
const void *expect, *code;
const void *addr, *dest;
- int line;

addr = (void *)jump_entry_code(entry);
dest = (void *)jump_entry_target(entry);

code = text_gen_insn(JMP32_INSN_OPCODE, addr, dest);

- if (type == JUMP_LABEL_JMP) {
- expect = x86_nops[5]; line = __LINE__;
- } else {
- expect = code; line = __LINE__;
+ if (type == JUMP_LABEL_JMP)
+ expect = x86_nops[5];
+ else
+ expect = code;
+
+ if (memcmp(addr, expect, JUMP_LABEL_NOP_SIZE)) {
+ /*
+ * The location is not an op that we were expecting.
+ * Something went wrong. Crash the box, as something could be
+ * corrupting the kernel.
+ */
+ pr_crit("jump_label: Fatal kernel bug, unexpected op at %pS [%p] (%5ph != %5ph)) type:%d\n",
+ addr, addr, addr, expect, type);
+ BUG();
}

- if (memcmp(addr, expect, JUMP_LABEL_NOP_SIZE))
- bug_at(addr, line);
-
if (type == JUMP_LABEL_NOP)
code = x86_nops[5];




Subject: [tip: objtool/core] jump_label, x86: Improve error when we fail expected text

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: f9510fa9caaf8229381d5f86ba0774bf1a6ca39b
Gitweb: https://git.kernel.org/tip/f9510fa9caaf8229381d5f86ba0774bf1a6ca39b
Author: Peter Zijlstra <[email protected]>
AuthorDate: Thu, 06 May 2021 21:33:57 +02:00
Committer: Ingo Molnar <[email protected]>
CommitterDate: Wed, 12 May 2021 14:54:55 +02:00

jump_label, x86: Improve error when we fail expected text

There is only a single usage site left, remove the function and extend
the print to include more information, like the expected text and the
patch type.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
arch/x86/kernel/jump_label.c | 33 ++++++++++++++-------------------
1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index 6a2eb62..638d3b9 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -16,37 +16,32 @@
#include <asm/alternative.h>
#include <asm/text-patching.h>

-static void bug_at(const void *ip, int line)
-{
- /*
- * The location is not an op that we were expecting.
- * Something went wrong. Crash the box, as something could be
- * corrupting the kernel.
- */
- pr_crit("jump_label: Fatal kernel bug, unexpected op at %pS [%p] (%5ph) %d\n", ip, ip, ip, line);
- BUG();
-}
-
static const void *
__jump_label_set_jump_code(struct jump_entry *entry, enum jump_label_type type)
{
const void *expect, *code;
const void *addr, *dest;
- int line;

addr = (void *)jump_entry_code(entry);
dest = (void *)jump_entry_target(entry);

code = text_gen_insn(JMP32_INSN_OPCODE, addr, dest);

- if (type == JUMP_LABEL_JMP) {
- expect = x86_nops[5]; line = __LINE__;
- } else {
- expect = code; line = __LINE__;
- }
+ if (type == JUMP_LABEL_JMP)
+ expect = x86_nops[5];
+ else
+ expect = code;

- if (memcmp(addr, expect, JUMP_LABEL_NOP_SIZE))
- bug_at(addr, line);
+ if (memcmp(addr, expect, JUMP_LABEL_NOP_SIZE)) {
+ /*
+ * The location is not an op that we were expecting.
+ * Something went wrong. Crash the box, as something could be
+ * corrupting the kernel.
+ */
+ pr_crit("jump_label: Fatal kernel bug, unexpected op at %pS [%p] (%5ph != %5ph)) type:%d\n",
+ addr, addr, addr, expect, type);
+ BUG();
+ }

if (type == JUMP_LABEL_NOP)
code = x86_nops[5];