linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: plagnioj@jcrosoft.com (Jean-Christophe PLAGNIOL-VILLARD)
To: linux-arm-kernel@lists.infradead.org
Subject: AT91: How copy kernel code to SRAM and execute?
Date: Mon, 27 Feb 2012 04:42:48 +0100	[thread overview]
Message-ID: <20120227034248.GC3318@game.jcrosoft.org> (raw)
In-Reply-To: <20120226210539.GB4706@n2100.arm.linux.org.uk>

On 21:05 Sun 26 Feb     , Russell King - ARM Linux wrote:
> On Sun, Feb 26, 2012 at 09:48:04PM +0100, Ulf Samuelsson wrote:
> > On 2012-02-26 18:50, Russell King - ARM Linux wrote:
> >> On Sun, Feb 26, 2012 at 06:37:25PM +0100, ARM Linux wrote:
> >>> I am looking for some examples on how to copy a small piece of kernel code
> >>> to internal SRAM and then execute it.
> >> See fncpy.h
> >>
> > Thanks, this does the copy.
> > My problem is in making the SRAM executable.
> > I have already copied to SRAM (I think), but when I jump there
> > I get a trap and a stackdump.
> 
> 
> 
> > The "mmap" system call, seems to do what I want, but is this callable
> > from within the kernel, or is there a better way?
> >
> > I can see that is has been split upo into "old_mmap" (obsolete) and the  
> > newer
> > "sys_mmap2" which turns off the MAP_EXECUTABLE.
> > "mprotect" maybe can be used to fix that.
> >
> > Googling for how to call a system call from within the kernel gave:
> >
> >     mm_segment_t     oldfs = get_fs();
> >     set_fs(KERNEL_DS);
> >     /* Do SysCalls */
> >         sys_mprotect(sram_shutdown, PAGE_SIZE, ... );
> >     set_fs(old_fs);
> 
> Don't even think about that.  Google doesn't always answer the correct
> question.  In this case, it's completely the wrong thing because all
> the userspace APIs are _only_ designed to work with userspace addresses.
> 
> Moreover, this will fail because it won't find a VMA for the address
> (which is a good thing - as it will attempt to modify the pages in
> ways which could end up exposing them to userspace.)
> 
> In general, if you're coding inside the kernel, calling kernel syscalls
> is 99.999% of the time totally the wrong thing to do.
> 
> The way to do this is to use __arm_ioremap_exec() to map the SRAM.
Ulf try to fix something the wrong way, this probelem is known for longtime on
at91 and fixed at the mainline on all SoC

Best Regards,
J.

  reply	other threads:[~2012-02-27  3:42 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-26 17:37 AT91: How copy kernel code to SRAM and execute? ARM Linux
2012-02-26 17:50 ` Russell King - ARM Linux
2012-02-26 20:48   ` Ulf Samuelsson
2012-02-26 21:05     ` Russell King - ARM Linux
2012-02-27  3:42       ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-02-26 18:44 ` Jean-Christophe PLAGNIOL-VILLARD
2012-02-26 20:52   ` ARM Linux
2012-02-27  3:40     ` Jean-Christophe PLAGNIOL-VILLARD

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=20120227034248.GC3318@game.jcrosoft.org \
    --to=plagnioj@jcrosoft.com \
    --cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).