aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuai Xue <xueshuai@linux.alibaba.com>2022-11-29 21:28:02 +0800
committerTony Luck <tony.luck@intel.com>2022-11-29 09:55:06 -0800
commit58d3e234d515e820febaa9fba5e7dfabf5baee95 (patch)
treee672ffcf93adf38f1cfee608d66287e70fbd0da5
parent2624df117af1b4d05f2d9bab14fbfc8f85c514d3 (diff)
downloadras-tools-58d3e234d515e820febaa9fba5e7dfabf5baee95.tar.gz
memattr: move the test case out of driver directory
Move the memattr test case out of driver directory and rename it with a generic name. Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com> Signed-off-by: Tony Luck <tony.luck@intel.com>
-rw-r--r--.gitignore4
-rw-r--r--Makefile7
-rw-r--r--memattr.c (renamed from memattr/test.c)47
-rw-r--r--pgprot-drv/LICENSE (renamed from memattr/LICENSE)0
-rw-r--r--pgprot-drv/Makefile (renamed from memattr/Makefile)0
-rw-r--r--pgprot-drv/README (renamed from memattr/README)7
-rw-r--r--pgprot-drv/pgprot_drv.c (renamed from memattr/pgprot_drv.c)0
7 files changed, 25 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index 6f31577..d25b558 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,9 +5,13 @@ hornet
lmce
mca-recover
vtop
+memattr
+rep_ce_page
.vscode
modules.order
+Module.symvers
*.cmd
*.mod
*.mod.c
+*.ko
diff --git a/Makefile b/Makefile
index 7dd98eb..0546b60 100644
--- a/Makefile
+++ b/Makefile
@@ -2,10 +2,10 @@
CFLAGS = -O
-all: mca-recover vtop cmcistorm hornet einj_mem_uc lmce rep_ce_page
+all: mca-recover vtop cmcistorm hornet einj_mem_uc lmce rep_ce_page memattr
clean:
- rm -f *.o mca-recover vtop cmcistorm hornet einj_mem_uc lmce rep_ce_page
+ rm -f *.o mca-recover vtop cmcistorm hornet einj_mem_uc lmce rep_ce_page memattr
mca-recover: mca-recover.c
cc -o mca-recover $(CFLAGS) mca-recover.c
@@ -27,3 +27,6 @@ einj_mem_uc: einj_mem_uc.o proc_cpuinfo.o proc_interrupt.o proc_pagemap.o do_mem
lmce: proc_pagemap.o lmce.o
cc -o lmce proc_pagemap.o lmce.o -pthread
+
+memattr: memattr.c
+ cc -o memattr $(CFLAGS) memattr.c
diff --git a/memattr/test.c b/memattr.c
index 5a83c68..1465c73 100644
--- a/memattr/test.c
+++ b/memattr.c
@@ -35,6 +35,7 @@ typedef struct
long long int paddr;
} mpgprot_drv_ctx;
+extern long long vtop(long long);
#define DEV_NAME "/dev/pgprot_drv"
#define PAGE_SHIFT 12
static mpgprot_drv_ctx *ctx = NULL;
@@ -50,6 +51,15 @@ static char *progname;
#define EINJ_DOIT "/sys/kernel/debug/apei/einj/error_inject"
#define EINJ_VENDOR "/sys/kernel/debug/apei/einj/vendor"
+static int is_privileged(void)
+{
+ if (getuid() != 0) {
+ fprintf(stderr, "%s: must be root to run error injection tests\n", progname);
+ return 0;
+ }
+ return 1;
+}
+
static void wfile(char *file, unsigned long long val)
{
FILE *fp;
@@ -68,39 +78,6 @@ static void wfile(char *file, unsigned long long val)
}
}
-/*
- * get information about address from /proc/self/pagemap
- */
-unsigned long long vtop(unsigned long long addr)
-{
- static int pagesize;
- unsigned long long pinfo;
- long offset;
- int fd;
-
- if (pagesize == 0)
- pagesize = getpagesize();
- offset = addr / pagesize * (sizeof pinfo);
- fd = open("/proc/self/pagemap", O_RDONLY);
- if (fd == -1)
- {
- perror("pagemap");
- exit(1);
- }
- if (pread(fd, &pinfo, sizeof pinfo, offset) != sizeof pinfo)
- {
- perror("pagemap");
- exit(1);
- }
- close(fd);
- if ((pinfo & (1ull << 63)) == 0)
- {
- printf("page not present\n");
- return ~0ull;
- }
- return ((pinfo & 0x007fffffffffffffull) * pagesize) + (addr & (pagesize - 1));
-}
-
static void inject_uc(unsigned long long addr, void *vaddr, int notrigger)
{
wfile(EINJ_ETYPE, 0x20);
@@ -132,6 +109,8 @@ int main(int argc, char *argv[])
void *vaddr;
progname = argv[0];
+ if (!is_privileged())
+ exit(1);
while ((c = getopt(argc, argv, "pb")) != -1)
switch (c)
{
@@ -146,7 +125,7 @@ int main(int argc, char *argv[])
kfd = open(DEV_NAME, O_RDWR | O_NDELAY);
if (kfd < 0)
{
- printf("open file %s error\n", DEV_NAME);
+ printf("open file %s error: Is the pgprot_drv.ko module loaded?\n", DEV_NAME);
return -1;
}
diff --git a/memattr/LICENSE b/pgprot-drv/LICENSE
index d159169..d159169 100644
--- a/memattr/LICENSE
+++ b/pgprot-drv/LICENSE
diff --git a/memattr/Makefile b/pgprot-drv/Makefile
index a5ff968..a5ff968 100644
--- a/memattr/Makefile
+++ b/pgprot-drv/Makefile
diff --git a/memattr/README b/pgprot-drv/README
index e4022d5..65c9cc2 100644
--- a/memattr/README
+++ b/pgprot-drv/README
@@ -8,7 +8,6 @@ Usage:
1. Compile the driver and test case
make
- gcc -o test test.c
2. Install the module with explicit memory attribute
@@ -27,13 +26,13 @@ Note: memory attribute index may vary with different kernel version.
reset. Run user-level test case with -b to bench performance. When the memory
attribute is normal memory (pgprot=0):
- #./test -b
+ #./memattr -b
check ctx: vaddr = 0xffff8b12d000, num 56, paddr 8d3512000
Buffer size: 4 KB, stride 128, time 0.000095 s, latency 1.45 ns
While if set the memory attribute as MT_DEVICE_nGnRnE (pgprot=4):
- #./test -b
+ #./memattr -b
check ctx: vaddr = 0xffff8652f000, num 56, paddr 8a2af2000
Buffer size: 4 KB, stride 128, time 0.008787 s, latency 134.15 ns
@@ -41,7 +40,7 @@ While if set the memory attribute as MT_DEVICE_nGnRnE (pgprot=4):
Run user-level test case with -p to poison.
modprobe einj
- ./test -p
+ ./memattr -p
Check dmesg with PTE value:
diff --git a/memattr/pgprot_drv.c b/pgprot-drv/pgprot_drv.c
index fe464e3..fe464e3 100644
--- a/memattr/pgprot_drv.c
+++ b/pgprot-drv/pgprot_drv.c