// SPDX-License-Identifier: GPL-2.0/* * HMM stands for Heterogeneous Memory Management, it is a helper layer inside * the linux kernel to help device drivers mirror a process address space in * the device. This allows the device to use the same address space which * makes communication and data exchange a lot easier. * * This framework's sole purpose is to exercise various code paths inside * the kernel to make sure that HMM performs as expected and to flush out any * bugs. */#include"../kselftest_harness.h"#include<errno.h>#include<fcntl.h>#include<stdio.h>#include<stdlib.h>#include<stdint.h>#include<unistd.h>#include<strings.h>#include<time.h>#include<pthread.h>#include<hugetlbfs.h>#include<sys/types.h>#include<sys/stat.h>#include<sys/mman.h>#include<sys/ioctl.h>/* * This is a private UAPI to the kernel test module so it isn't exported * in the usual include/uapi/... directory. */#include"../../../../lib/test_hmm_uapi.h"structhmm_buffer{void*ptr;void*mirror;unsignedlongsize;intfd;uint64_tcpages;uint64_tfaults;};#define TWOMEG (1 << 21)#define HMM_BUFFER_SIZE (1024 << 12)#define HMM_PATH_MAX 64#define NTIMES 10#define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1)))FIXTURE(hmm){intfd;unsignedintpage_size;unsignedintpage_shift;};FIXTURE(hmm2){intfd0;int