mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suresh Siddha <suresh.b.siddha@intel.com>
To: "rostedt@goodmis.org" <rostedt@goodmis.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] [GIT PULL] tracing: allow to change permissions for text with dynamic ftrace enabled
Date: Tue, 27 Oct 2009 14:26:04 -0800	[thread overview]
Message-ID: <1256682364.2691.33.camel@sbs-t61.sc.intel.com> (raw)
In-Reply-To: <1256668438.26028.414.camel@gandalf.stny.rr.com>

On Tue, 2009-10-27 at 11:33 -0700, Steven Rostedt wrote:
> On Tue, 2009-10-27 at 11:20 -0800, Suresh Siddha wrote:
> 
> > Steven, Is it possible for dynamic ftrace to use the kernel identity
> > mapping instead of the kernel text mapping for converting the tracing
> > calls to nops etc.
> 
> Not sure what you mean by "kernel identity" mapping.

64bit has the kernel text pages mapped at two locations. kernel identity
mapping  (__PAGE_OFFSET) and kernel image/text mapping
(__START_KERNEL_map).

DEBUG_RODATA patch was trying to preserve large page mapping (for perf
reasons) for kernel text. We can use the identity mapping for modifying
the kernel text.

This patch seems to fix.

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 5a1b975..7e1799b 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -215,6 +215,11 @@ do_ftrace_mod_code(unsigned long ip, void *new_code)
 }
 
 
+static inline int
+within(unsigned long addr, unsigned long start, unsigned long end)
+{
+	return addr >= start && addr < end;
+}
 
 
 static unsigned char ftrace_nop[MCOUNT_INSN_SIZE];
@@ -248,6 +253,14 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
 	if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
 		return -EINVAL;
 
+	/*
+	 * On x86_64, we use the kernel identity mapping instead of the
+	 * kernel text mapping to modify the kernel text. This is a nop
+	 * for 32bit kernels.
+	 */
+	if (within(ip, (unsigned long)_text, (unsigned long)_etext))
+		ip = (unsigned long)__va(__pa(ip));
+
 	/* replace the text with the new text */
 	if (do_ftrace_mod_code(ip, new_code))
 		return -EPERM;



  reply	other threads:[~2009-10-27 21:27 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-27 17:53 Steven Rostedt
2009-10-27 18:11 ` Ingo Molnar
2009-10-27 19:20 ` Suresh Siddha
2009-10-27 18:33   ` Steven Rostedt
2009-10-27 22:26     ` Suresh Siddha [this message]
2009-10-27 21:35       ` Steven Rostedt
2009-10-27 23:23         ` Suresh Siddha
2009-10-27 23:31           ` Steven Rostedt
2009-10-28 19:56             ` Suresh Siddha
2009-10-28 20:15               ` Steven Rostedt
2009-10-28 22:07                 ` Suresh Siddha
2009-10-29  1:20                   ` 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=1256682364.2691.33.camel@sbs-t61.sc.intel.com \
    --to=suresh.b.siddha@intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.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

all inboxes | Powered by JetHome®