From: David Daney <ddaney@caviumnetworks.com>
To: Aurelien Jarno <aurelien@aurel32.net>
Cc: linux-mips@linux-mips.org, Arnaud Patard <arnaud.patard@rtp-net.org>
Subject: Re: Syncing CPU caches from userland on MIPS
Date: Tue, 24 Nov 2009 13:04:55 -0800 [thread overview]
Message-ID: <4B0C4A77.9020103@caviumnetworks.com> (raw)
In-Reply-To: <20091124182841.GE17477@hall.aurel32.net>
Aurelien Jarno wrote:
> Hi all,
>
> This question is not really kernel related, but still MIPS related, I
> hope you don't mind.
>
> Arnaud Patard and myself are trying to get qemu working on MIPS [1],
> which includes translating TCG code (internal representation) into MIPS
> instructions, that are then executed. Most of the code works, but we
> have some strange behaviors that seems related to CPU caches.
>
> The code is written to a buffer, which is then executed. Before the
> execution, the caches are synced using the cacheflush syscall:
>
> | #include <sys/cachectl.h>
> |
> |
> | static inline void flush_icache_range(unsigned long start, unsigned long stop)
> | {
> | cacheflush ((void *)start, stop-start, ICACHE);
> | }
>
> It seems this is not enough, as sometimes, some executed code does not
> correspond to the assembly dump of this memory region. This seems to be
> especially the case of memory regions that are written twice, due to
> relocations:
> 1) a branch instruction is written with an offset of 0
> 2) the offset is patched
Try inserting an 'asm volatile ("sync" ::: "memory");' here. If that
fixes things, then we can assume that your cacheflush system call is
buggy, and would need to add a sync.
> 3) cacheflush is called
>
> Sometimes the executed code correspond to the code written in 1), which
> means the branch is skipped.
>
> Does someone knows and/or has example code to correctly sync the CPU
> caches from userland on MIPS?
>
http://gcc.gnu.org/viewcvs/trunk/libffi/src/mips/ffi.c
Look at ffi_prep_closure_loc() around line 721.
We also do a similar thing in the kernel in flush_cache_sigtramp(), but
that is not really userland.
David Daney
next prev parent reply other threads:[~2009-11-24 21:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-24 18:28 Syncing CPU caches from userland on MIPS Aurelien Jarno
2009-11-24 21:04 ` David Daney [this message]
2009-11-24 21:35 ` Aurelien Jarno
2009-11-25 14:01 ` Florian Lohoff
2009-11-25 14:39 ` Arnaud Patard
2009-11-25 14:32 ` Florian Lohoff
2009-11-25 14:48 ` Arnaud Patard
2009-11-25 15:18 ` peter fuerst
2009-11-25 15:01 ` Ralf Baechle
2009-11-25 15:00 ` Ralf Baechle
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=4B0C4A77.9020103@caviumnetworks.com \
--to=ddaney@caviumnetworks.com \
--cc=arnaud.patard@rtp-net.org \
--cc=aurelien@aurel32.net \
--cc=linux-mips@linux-mips.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 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.