From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
"H. Peter Anvin" <hpa@zytor.com>, Jason Baron <jbaron@redhat.com>
Subject: [PATCH 6/7] x86/jump lables: Show where and what was wrong on errors
Date: Thu, 08 Mar 2012 17:17:36 -0500 [thread overview]
Message-ID: <20120308222202.828095205@goodmis.org> (raw)
In-Reply-To: 20120308221730.807074710@goodmis.org
[-- Attachment #1: Type: text/plain, Size: 3080 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
When modifying text sections for jump labels, a paranoid check is
performed. If the check fails, the system "bugs". But why it failed
is not shown.
The BUG_ON()s in the jump label update code is replaced with bug_at(ip).
This is a function that will show what pointer failed, and what was
at the location of the failure that made jump label panic.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
arch/x86/kernel/jump_label.c | 31 +++++++++++++++++++++----------
1 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index d426da6..9bae2c9 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -32,6 +32,18 @@ union jump_code_union {
} __packed;
};
+static void bug_at(unsigned char *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.
+ */
+ printk("Unexpected op at %pS [%p] (%02x %02x %02x %02x %02x) %s:%d\n",
+ ip, ip, ip[0], ip[1], ip[2], ip[3], ip[4], __FILE__, line);
+ BUG();
+}
+
static void __jump_label_transform(struct jump_entry *entry,
enum jump_label_type type,
void *(*poker)(void *, const void *, size_t),
@@ -59,12 +71,7 @@ static void __jump_label_transform(struct jump_entry *entry,
code.jump = 0xe9;
code.offset = entry->target - (entry->code + size);
} else
- /*
- * The location is not a nop that we were expecting,
- * something went wrong. Crash the box, as something could be
- * corrupting the kernel.
- */
- BUG();
+ bug_at(ip, __LINE__);
} else {
/*
* We are disabling this jump label. If it is not what
@@ -78,7 +85,8 @@ static void __jump_label_transform(struct jump_entry *entry,
return;
/* We are initializing from the default nop */
- BUG_ON(memcmp(ip, default_nop, 5) != 0);
+ if (unlikely(memcmp(ip, default_nop, 5) != 0))
+ bug_at(ip, __LINE__);
/* Set to the ideal nop */
size = JUMP_LABEL_NOP_SIZE;
@@ -91,7 +99,9 @@ static void __jump_label_transform(struct jump_entry *entry,
code.jump = 0xe9;
code.offset = entry->target -
(entry->code + JUMP_LABEL_NOP_SIZE);
- BUG_ON(memcmp(ip, &code, 5) != 0);
+
+ if (unlikely(memcmp(ip, &code, 5) != 0))
+ bug_at(ip, __LINE__);
size = JUMP_LABEL_NOP_SIZE;
memcpy(&code, ideal_nops[NOP_ATOMIC5], size);
@@ -101,13 +111,14 @@ static void __jump_label_transform(struct jump_entry *entry,
/* Had better be a 2 byte jmp */
code.jump_short = 0xeb;
code.offset = entry->target - (entry->code + 2);
- BUG_ON(memcmp(ip, &code, 2) != 0);
+ if (unlikely(memcmp(ip, &code, 2) != 0))
+ bug_at(ip, __LINE__);
size = 2;
memcpy(&code, nop_short, size);
} else
/* The code was not what we expected! */
- BUG();
+ bug_at(ip, __LINE__);
}
(*poker)(ip, &code, size);
--
1.7.8.3
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-03-08 22:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-08 22:17 [PATCH 0/7] [GIT PULL] jump-labels: Implement 2 and 5 byte jumps Steven Rostedt
2012-03-08 22:17 ` [PATCH 1/7] x86/jump-label: Use best default nops for inital jump label calls Steven Rostedt
2012-03-08 22:17 ` [PATCH 2/7] x86/jump-label: Do not bother updating nops if they are correct Steven Rostedt
2012-03-08 22:17 ` [PATCH 3/7] x86/jump-label: Add safety checks to jump label conversions Steven Rostedt
2012-03-08 22:17 ` [PATCH 4/7] jump labels: Add infrastructure to update jump labels at compile time Steven Rostedt
2012-03-08 22:17 ` [PATCH 5/7] x86/jump labels: Use etiher 5 byte or 2 byte jumps Steven Rostedt
2012-03-12 16:17 ` Jason Baron
2012-03-12 16:29 ` Steven Rostedt
2012-03-12 17:27 ` Steven Rostedt
2012-03-12 18:03 ` Jason Baron
2012-03-08 22:17 ` Steven Rostedt [this message]
2012-03-08 22:17 ` [PATCH 7/7] x86/jump labels: Handle initialization of enabled nops 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=20120308222202.828095205@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=hpa@zytor.com \
--cc=jbaron@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.