Skip to content

Instantly share code, notes, and snippets.

@soleen
Created January 20, 2022 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soleen/fdcd501d5df103976245fe84e9535087 to your computer and use it in GitHub Desktop.
Save soleen/fdcd501d5df103976245fe84e9535087 to your computer and use it in GitHub Desktop.
page table check panic repro
#define _GNU_SOURCE
#include <fcntl.h>
#include <sched.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/mman.h>
#include <linux/perf_event.h>
#include <stdio.h>
int main(void)
{
char *addr = (char *)0x20000000ul;
struct perf_event_attr *attr = (void *)addr + 1024 * 1024;
char *file = "./bus";
char *dir = "./dir";
int fd1, fd2;
void *rv_mmap;
unshare(CLONE_NEWNS);
mkdir(dir, 0777);
mount(NULL, dir, "tmpfs", 0, "huge=always");
chdir(dir);
fd1 = creat(file, 0);
ftruncate(fd1, 2 * 1024 * 1024);
close(fd1);
fd1 = open(file, 0);
rv_mmap = mmap(addr, 2 * 1024 * 1024, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE | MAP_LOCKED, -1, 0ul);
attr->type = 6;
attr->bp_addr = (uint64_t)file;
fd2 = syscall(__NR_perf_event_open, attr, 0, 0ul, -1, 0ul);
rv_mmap = mmap(addr, 2 * 1024 * 1024, PROT_READ, MAP_FIXED | MAP_PRIVATE | MAP_LOCKED, fd1, 0ul);
close(fd2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment