aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTony Luck <tony.luck@intel.com>2022-10-13 15:10:57 -0700
committerTony Luck <tony.luck@intel.com>2022-10-13 15:10:57 -0700
commitc8aef396cc8ff29f5c2dcc6dd6dc56ed2d9202ad (patch)
treebe9f66ff69f85390f96a54c583530ab8d9c60b37
parent9262f4f291dc1511b5d8ba83ffa46e6b7bb944fc (diff)
downloadras-tools-c8aef396cc8ff29f5c2dcc6dd6dc56ed2d9202ad.tar.gz
einj_mem-uc: Add new test case for kernel copy-on-write
Someday I'd like to fix this case in the kernel. For now just create a test case to generate the issue. Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r--einj_mem_uc.c38
1 files changed, 36 insertions, 2 deletions
diff --git a/einj_mem_uc.c b/einj_mem_uc.c
index aaba725..17567de 100644
--- a/einj_mem_uc.c
+++ b/einj_mem_uc.c
@@ -26,6 +26,7 @@
#include <sys/syscall.h>
#include <linux/futex.h>
#include <pthread.h>
+#include <sys/wait.h>
#ifndef MAP_HUGETLB
#define MAP_HUGETLB 0x40000
@@ -443,9 +444,9 @@ static void *hugetlb_alloc(void)
return p + HPS / 4;
}
-static void *data_alloc(void)
+static void *data_alloc_common(int flag)
{
- char *p = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANON, -1, 0);
+ char *p = mmap(NULL, pagesize, PROT_READ|PROT_WRITE, flag, -1, 0);
int i;
if (p == NULL) {
@@ -458,6 +459,16 @@ static void *data_alloc(void)
return p + pagesize / 4;
}
+static void *data_alloc(void)
+{
+ return data_alloc_common(MAP_SHARED|MAP_ANON);
+}
+
+static void *data_alloc_private(void)
+{
+ return data_alloc_common(MAP_PRIVATE|MAP_ANON);
+}
+
static FILE *pcfile;
static void *page_cache_alloc(void)
@@ -718,6 +729,25 @@ int trigger_copyout(char *addr)
return 0;
}
+int trigger_copy_on_write(char *addr)
+{
+ int pid, status;
+
+ switch (pid = fork()) {
+ case -1:
+ fprintf(stderr, "%s: fork failed\n", progname);
+ return -1;
+ case 0:
+ /* force kernel to copy this page */
+ *addr = '*';
+ exit(0);
+ }
+
+ while (wait(&status) != pid)
+ ;
+ return 0;
+}
+
int trigger_patrol(char *addr)
{
PRINT_TRIGGERING;
@@ -898,6 +928,10 @@ struct test {
page_cache_alloc, inject_uc, 1, trigger_copyout, F_MCE|F_CMCI|F_SIGBUS|F_FATAL,
},
{
+ "copy-on-write", "Kernel copies user page. Probably fatal",
+ data_alloc_private, inject_uc, 1, trigger_copy_on_write, F_MCE|F_CMCI|F_SIGBUS|F_FATAL,
+ },
+ {
"futex", "Kernel access to futex(2). Probably fatal",
data_alloc, inject_uc, 1, trigger_futex, F_MCE|F_CMCI|F_FATAL,
},