Subject: Kernel related (?) user space crash at ARM11 MPCore

From: [email-masked] (Jamie Lokier)
Date: Mon, 21 Sep 2009 09:31:09 +0100

I'm not able to tell from this thread, and I don't have the hardware
to test either:

I have some userspace ARM code which modifies instructions and data
used by those instructions in a few pages, using mprotect() to make
them writable, modify, and make them PROT_READ|PROT_EXEC again.

There is no execution of the modified code _during_ the modification,
only afterwards.

I expect the behaviour is the same as that toolchain which modifies
instructions in the ELF PLT.  (Which, by the way, an ARM FDPIC-ELF
for no-MMU I've been working on also does).

Would the crash problems being discussed affect that sort of code in
general on released ARM kernels?  Do I need an I-cache flush in
userspace after the mprotect - is that required, and will that always
be enough?  Will it still be required when the fix is in?

My question is about some simple code patching at application startup.
But, generalising to a JIT code generator, does it complicate matters
if code is being executed from a page _at the same time_ as another
thread (perhaps on another CPU) is writing to another part of the
_same page_ - writing code, and it's associated local data, to be
executed shortly after it's written while continuing to execute the
earlier code?

Thanks!
-- Jamie