From: Juergen Kienhoefer <juergen@kienhoefer.com>
To: linuxppc-dev@lists.linuxppc.org
Subject: cache coherence problem
Date: Mon, 17 Nov 2003 17:16:24 -0800 [thread overview]
Message-ID: <3FB972E8.5090701@kienhoefer.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 327 bytes --]
Guys,
Look at the folloging test program. It mmaps memory, puts some
instructions in it and executes it.
Sometimes it works, sometimes it crashes with illegal instruction.
This smells like cache problems.
Should the kernel clean the instruction cache for these addresses
in mmap system call?
Thanks for any thoughts!
Juergen
[-- Attachment #2: mmapexec.c --]
[-- Type: text/plain, Size: 1659 bytes --]
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <errno.h>
#include <sys/ptrace.h>
#include <signal.h>
#include <sched.h>
int main( int argc, char** argv ) {
long* loc;
int (*init)(void);
long returninstr0 = 0x38600009; // li r3,4
long returninstr1 = 0x4e800020; // blr
int returned;
int fd;
char zero;
char tempfile[20] = { "test-XXXXXX" };
printf( "start of test\n" );
fd = mkstemp( tempfile );
printf( "memfile name test-XXXXXX, fd %d\n", fd );
if (fchmod(fd, 0777) < 0){
perror("fchmod");
exit(1);
}
if( lseek( fd, 32768*1024, SEEK_SET ) != 32768*1024 ){ //32M
perror("lseek");
exit(1);
}
zero = 0;
if( write(fd, &zero, 1 ) != 1){
perror("write");
exit(1);
}
if( fcntl(fd, F_SETFD, FD_CLOEXEC ) != 0)
perror("Setting FD_CLOEXEC failed");
loc = mmap( (void *) 0x62800000, 12288,
PROT_READ | PROT_WRITE | PROT_EXEC,
MAP_SHARED | MAP_FIXED,
fd, 0x3a0000);
printf( "memory allocated at addr %x\n", loc );
printf( "data %x\n", loc[0] );
// random behaviour, sometimes works, sometimes illegal instruction
//loc = (long*)0x62800000; // set the address
loc = (long*)0x62802000; // set the address
// always illegal instruction
//loc = (long*)0x62801b44;
//loc = (long*)0x62801000;
loc[0] = returninstr0;
loc[1] = returninstr1;
printf( "new code: addr %x, %x\n", loc, loc[0] );
init = (int (*)(void))loc;
returned = init();
printf( "function returned %d\n", returned );
}
next reply other threads:[~2003-11-18 1:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-11-18 1:16 Juergen Kienhoefer [this message]
2003-11-18 2:36 ` cache coherence problem Matt Porter
2003-11-18 2:38 ` Michael R. Zucca
2003-11-19 22:35 ` linas
2003-11-18 3:02 ` Benjamin Herrenschmidt
2003-11-18 5:00 ` Juergen Kienhoefer
2003-11-18 5:22 ` Benjamin Herrenschmidt
2003-11-18 5:24 ` Benjamin Herrenschmidt
2003-11-18 17:40 ` cache coherence problem: FIXED Juergen Kienhoefer
2003-11-18 8:04 ` cache coherence problem Wolfgang Denk
2003-11-18 9:37 ` Gabriel Paubert
2003-11-19 0:35 ` Benjamin Herrenschmidt
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=3FB972E8.5090701@kienhoefer.com \
--to=juergen@kienhoefer.com \
--cc=linuxppc-dev@lists.linuxppc.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.