diff options
author | Tony Luck <tony.luck@intel.com> | 2020-06-17 10:45:12 -0700 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2020-06-17 10:45:12 -0700 |
commit | b17c27b2c21da9dc472594376e1f7c430d5364da (patch) | |
tree | 52a96e291cf18ea2dde2078d62d304e9644cf906 | |
parent | a850a9da964ae23541f5a1d3f117fe43856a8933 (diff) | |
download | ras-tools-b17c27b2c21da9dc472594376e1f7c430d5364da.tar.gz |
einj_mem_uc: new test case for copyout
Create a file and write a page of data to it. Map that file and
use an address in the mapped range to inject an error.
Trigger the error by issing a read(2) system call which will
make the kernel copy from the page cache copy of the data (which
has been injected with a UC error).
Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r-- | einj_mem_uc.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/einj_mem_uc.c b/einj_mem_uc.c index 0f1851a..affd9f1 100644 --- a/einj_mem_uc.c +++ b/einj_mem_uc.c @@ -169,6 +169,30 @@ static void *data_alloc(void) return p + pagesize / 4; } +static FILE *pcfile; + +static void *page_cache_alloc(void) +{ + FILE *pcfile = tmpfile(); + char c, *p; + int i; + + for (i = 0; i < pagesize; i++) { + c = random(); + fputc(c, pcfile); + } + fflush(pcfile); + + p = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(pcfile), 0); + if (p == NULL) { + fprintf(stderr, "%s: cannot mmap tmpfile\n", progname); + exit(1); + } + *p = random(); + + return p + pagesize / 4; +} + static void *mlock_data_alloc(void) { char *p = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0); @@ -289,6 +313,21 @@ int trigger_copyin(char *addr) return 0; } +int trigger_copyout(char *addr) +{ + char *buf = malloc(pagesize); + int ret; + + if (buf == NULL) { + fprintf(stderr, "%s: couldn't allocate memory\n", progname); + return -1; + } + ret = read(fileno(pcfile), buf, pagesize); + fprintf(stderr, "%s: read returned %d\n", progname); + + return 0; +} + int trigger_patrol(char *addr) { sleep(1); @@ -365,6 +404,10 @@ struct test { data_alloc, inject_uc, 1, trigger_copyin, F_MCE|F_CMCI|F_SIGBUS|F_FATAL, }, { + "copyout", "Kernel copies data to user. Probably fatal", + page_cache_alloc, inject_uc, 1, trigger_copyout, F_MCE|F_CMCI|F_SIGBUS|F_FATAL, + }, + { "mlock", "mlock target page then inject/read to generates SRAR machine check", mlock_data_alloc, inject_uc, 1, trigger_single, F_MCE|F_CMCI|F_SIGBUS, }, |