todo: modpost undefined errors

This commit is contained in:
2025-08-23 11:02:25 +08:00
parent 64dbb93260
commit 9ae3a3f374
6 changed files with 93 additions and 70 deletions

View File

@ -7,7 +7,11 @@
#include "config.h" #include "config.h"
#include "../../mcctrl.h" #include "../../mcctrl.h"
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) && defined(CONFIG_X86_VSYSCALL_EMULATION)
#define gtod (&VVAR(vsyscall_gtod_data)) #define gtod (&VVAR(vsyscall_gtod_data))
#else
#define gtod NULL
#endif
//#define SC_DEBUG //#define SC_DEBUG
@ -24,7 +28,7 @@ static void *vdso_start;
static void *vdso_end; static void *vdso_end;
static struct page **vdso_pages; static struct page **vdso_pages;
#endif #endif
static void *__vvar_page; static void *__vvar_page_ptr;
static long *hpet_address; static long *hpet_address;
static void **hv_clock; static void **hv_clock;
@ -48,8 +52,8 @@ int arch_symbols_init(void)
return -EFAULT; return -EFAULT;
#endif #endif
__vvar_page = (void *) kallsyms_lookup_name("__vvar_page"); __vvar_page_ptr = (void *) &__vvar_page;
if (WARN_ON(!__vvar_page)) if (WARN_ON(!__vvar_page_ptr))
return -EFAULT; return -EFAULT;
hpet_address = (void *) kallsyms_lookup_name("hpet_address"); hpet_address = (void *) kallsyms_lookup_name("hpet_address");
@ -93,18 +97,18 @@ reserve_user_space(struct mcctrl_usrdata *usrdata, unsigned long *startp, unsign
#define DESIRED_USER_END 0x800000000000 #define DESIRED_USER_END 0x800000000000
#define GAP_FOR_MCEXEC 0x008000000000UL #define GAP_FOR_MCEXEC 0x008000000000UL
end = DESIRED_USER_END; end = DESIRED_USER_END;
down_write(&current->mm->mmap_sem); mmap_write_lock(current->mm);
vma = find_vma(current->mm, 0); vma = find_vma(current->mm, 0);
if (vma) { if (vma) {
end = (vma->vm_start - GAP_FOR_MCEXEC) & ~(GAP_FOR_MCEXEC - 1); end = (vma->vm_start - GAP_FOR_MCEXEC) & ~(GAP_FOR_MCEXEC - 1);
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
up_write(&current->mm->mmap_sem); mmap_write_unlock(current->mm);
#endif #endif
start = reserve_user_space_common(usrdata, start, end); start = reserve_user_space_common(usrdata, start, end);
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) #if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0)
up_write(&current->mm->mmap_sem); mmap_write_unlock(current->mm);
#endif #endif
mutex_unlock(&usrdata->reserve_lock); mutex_unlock(&usrdata->reserve_lock);
@ -161,19 +165,19 @@ void get_vdso_info(ihk_os_t os, long vdso_rpa)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,5,0)
vdso->vvar_is_global = 0; vdso->vvar_is_global = 0;
vdso->vvar_virt = (void *)(-3 * PAGE_SIZE); vdso->vvar_virt = (void *)(-3 * PAGE_SIZE);
vdso->vvar_phys = virt_to_phys(__vvar_page); vdso->vvar_phys = virt_to_phys(__vvar_page_ptr);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,17,0)
vdso->vvar_is_global = 0; vdso->vvar_is_global = 0;
vdso->vvar_virt = (void *)(-2 * PAGE_SIZE); vdso->vvar_virt = (void *)(-2 * PAGE_SIZE);
vdso->vvar_phys = virt_to_phys(__vvar_page); vdso->vvar_phys = virt_to_phys(__vvar_page_ptr);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,16,0) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,16,0)
vdso->vvar_is_global = 0; vdso->vvar_is_global = 0;
vdso->vvar_virt = (void *)(vdso->vdso_npages * PAGE_SIZE); vdso->vvar_virt = (void *)(vdso->vdso_npages * PAGE_SIZE);
vdso->vvar_phys = virt_to_phys(__vvar_page); vdso->vvar_phys = virt_to_phys(__vvar_page_ptr);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0)
vdso->vvar_is_global = 1; vdso->vvar_is_global = 1;
vdso->vvar_virt = (void *)fix_to_virt(VVAR_PAGE); vdso->vvar_virt = (void *)fix_to_virt(VVAR_PAGE);
vdso->vvar_phys = virt_to_phys(__vvar_page); vdso->vvar_phys = virt_to_phys(__vvar_page_ptr);
#endif #endif
/* HPET page */ /* HPET page */

View File

@ -126,8 +126,8 @@ static int load_elf(struct linux_binprm *bprm
if(st == 0){ if(st == 0){
off = p & ~PAGE_MASK; off = p & ~PAGE_MASK;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)
rc = get_user_pages_remote(current, bprm->mm, rc = get_user_pages_remote(bprm->mm,
bprm->p, 1, FOLL_FORCE, &page, NULL, NULL); bprm->p, 1, FOLL_FORCE, &page, NULL);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0)
rc = get_user_pages_remote(current, bprm->mm, rc = get_user_pages_remote(current, bprm->mm,
bprm->p, 1, FOLL_FORCE, &page, NULL); bprm->p, 1, FOLL_FORCE, &page, NULL);
@ -234,7 +234,7 @@ static int load_elf(struct linux_binprm *bprm
kfree(pbuf); kfree(pbuf);
return rc; return rc;
} }
rc = copy_strings_kernel(1, &bprm->interp, bprm); rc = copy_string_kernel(bprm->interp, bprm);
if (rc < 0){ if (rc < 0){
fput(file); fput(file);
kfree(pbuf); kfree(pbuf);
@ -242,7 +242,7 @@ static int load_elf(struct linux_binprm *bprm
} }
bprm->argc++; bprm->argc++;
wp = MCEXEC_PATH; wp = MCEXEC_PATH;
rc = copy_strings_kernel(1, &wp, bprm); rc = copy_string_kernel(wp, bprm);
if (rc){ if (rc){
fput(file); fput(file);
kfree(pbuf); kfree(pbuf);
@ -260,19 +260,25 @@ static int load_elf(struct linux_binprm *bprm
fput(bprm->file); fput(bprm->file);
bprm->file = file; bprm->file = file;
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
rc = prepare_binprm(bprm); rc = prepare_binprm(bprm);
if (rc < 0){ if (rc < 0){
kfree(pbuf); kfree(pbuf);
return rc; return rc;
} }
#endif
kfree(pbuf); kfree(pbuf);
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
return search_binary_handler(bprm return search_binary_handler(bprm
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) #if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)
, regs , regs
#endif #endif
); );
#else
return -ENOEXEC;
#endif
} }
static struct linux_binfmt mcexec_format = { static struct linux_binfmt mcexec_format = {

View File

@ -978,7 +978,9 @@ static long mcexec_get_cpuset(ihk_os_t os, unsigned long arg)
node = linux_numa_2_mckernel_numa(udp, node = linux_numa_2_mckernel_numa(udp,
cpu_to_node(mckernel_cpu_2_linux_cpu(udp, cpu_prev))); cpu_to_node(mckernel_cpu_2_linux_cpu(udp, cpu_prev)));
for_each_cpu_not(cpu, cpus_used) { for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
if (cpumask_test_cpu(cpu, cpus_used))
continue;
/* Invalid CPU? */ /* Invalid CPU? */
if (cpu >= udp->cpu_info->n_cpus) if (cpu >= udp->cpu_info->n_cpus)
break; break;
@ -1797,7 +1799,7 @@ out:
} }
LIST_HEAD(mckernel_exec_files); LIST_HEAD(mckernel_exec_files);
DEFINE_SEMAPHORE(mckernel_exec_file_lock); DEFINE_SEMAPHORE(mckernel_exec_file_lock, 1);
struct mckernel_exec_file { struct mckernel_exec_file {
@ -3262,8 +3264,9 @@ mcexec_uti_attr(ihk_os_t os, struct uti_attr_desc __user *_desc)
&lcache_topo->shared_cpu_map); &lcache_topo->shared_cpu_map);
} }
else { else {
cpumask_complement(wkmask, bitmap_complement(cpumask_bits(wkmask),
&lcache_topo->shared_cpu_map); cpumask_bits(&lcache_topo->shared_cpu_map),
nr_cpumask_bits);
cpumask_and(cpuset, cpuset, wkmask); cpumask_and(cpuset, cpuset, wkmask);
} }
} }
@ -3276,8 +3279,9 @@ mcexec_uti_attr(ihk_os_t os, struct uti_attr_desc __user *_desc)
&lcache_topo->shared_cpu_map); &lcache_topo->shared_cpu_map);
} }
else { else {
cpumask_complement(wkmask, bitmap_complement(cpumask_bits(wkmask),
&lcache_topo->shared_cpu_map); cpumask_bits(&lcache_topo->shared_cpu_map),
nr_cpumask_bits);
cpumask_and(cpuset, cpuset, wkmask); cpumask_and(cpuset, cpuset, wkmask);
} }
} }
@ -3290,8 +3294,9 @@ mcexec_uti_attr(ihk_os_t os, struct uti_attr_desc __user *_desc)
&lcache_topo->shared_cpu_map); &lcache_topo->shared_cpu_map);
} }
else { else {
cpumask_complement(wkmask, bitmap_complement(cpumask_bits(wkmask),
&lcache_topo->shared_cpu_map); cpumask_bits(&lcache_topo->shared_cpu_map),
nr_cpumask_bits);
cpumask_and(cpuset, cpuset, wkmask); cpumask_and(cpuset, cpuset, wkmask);
} }
} }

View File

@ -51,7 +51,7 @@ static long uti_wait_event(void *_resp, unsigned long nsec_timeout)
} }
} }
static int uti_clock_gettime(clockid_t clk_id, struct timespec *tp) static int uti_clock_gettime(clockid_t clk_id, struct timespec64 *tp)
{ {
int ret = 0; int ret = 0;
struct timespec64 ts64; struct timespec64 ts64;
@ -60,7 +60,7 @@ static int uti_clock_gettime(clockid_t clk_id, struct timespec *tp)
clk_id, CLOCK_REALTIME, CLOCK_MONOTONIC); clk_id, CLOCK_REALTIME, CLOCK_MONOTONIC);
switch (clk_id) { switch (clk_id) {
case CLOCK_REALTIME: case CLOCK_REALTIME:
getnstimeofday64(&ts64); ktime_get_real_ts64(&ts64);
tp->tv_sec = ts64.tv_sec; tp->tv_sec = ts64.tv_sec;
tp->tv_nsec = ts64.tv_nsec; tp->tv_nsec = ts64.tv_nsec;
dprintk("%s: CLOCK_REALTIME,%ld.%09ld\n", __func__, dprintk("%s: CLOCK_REALTIME,%ld.%09ld\n", __func__,
@ -1061,12 +1061,14 @@ static int futex(uint32_t *uaddr, int op, uint32_t val, uint64_t timeout,
switch (cmd) { switch (cmd) {
case FUTEX_WAIT: case FUTEX_WAIT:
val3 = FUTEX_BITSET_MATCH_ANY; val3 = FUTEX_BITSET_MATCH_ANY;
/* fallthrough */
case FUTEX_WAIT_BITSET: case FUTEX_WAIT_BITSET:
ret = futex_wait(uaddr, fshared, val, timeout, ret = futex_wait(uaddr, fshared, val, timeout,
val3, clockrt, uti_info); val3, clockrt, uti_info);
break; break;
case FUTEX_WAKE: case FUTEX_WAKE:
val3 = FUTEX_BITSET_MATCH_ANY; val3 = FUTEX_BITSET_MATCH_ANY;
/* fallthrough */
case FUTEX_WAKE_BITSET: case FUTEX_WAKE_BITSET:
ret = futex_wake(uaddr, fshared, val, val3, uti_info); ret = futex_wake(uaddr, fshared, val, val3, uti_info);
break; break;
@ -1127,7 +1129,7 @@ long do_futex(int n, unsigned long arg0, unsigned long arg1,
int op = (int)arg1; int op = (int)arg1;
uint32_t val = (uint32_t)arg2; uint32_t val = (uint32_t)arg2;
struct timespec *utime = (struct timespec *)arg3; struct timespec *utime = (struct timespec *)arg3;
struct timespec ts; struct timespec64 ts;
uint32_t *uaddr2 = (uint32_t *)arg4; uint32_t *uaddr2 = (uint32_t *)arg4;
uint32_t val3 = (uint32_t)arg5; uint32_t val3 = (uint32_t)arg5;
int flags = op; int flags = op;
@ -1158,12 +1160,12 @@ long do_futex(int n, unsigned long arg0, unsigned long arg1,
} }
dprintk("%s: utime=%ld.%09ld\n", __func__, ts.tv_sec, ts.tv_nsec); dprintk("%s: utime=%ld.%09ld\n", __func__, ts.tv_sec, ts.tv_nsec);
if (!timespec_valid(&ts)) { if (!timespec64_valid(&ts)) {
return -EINVAL; return -EINVAL;
} }
if (op == FUTEX_WAIT_BITSET) { /* User passed absolute time */ if (op == FUTEX_WAIT_BITSET) { /* User passed absolute time */
struct timespec ats; struct timespec64 ats;
ret = uti_clock_gettime((flags & FUTEX_CLOCK_REALTIME) ? ret = uti_clock_gettime((flags & FUTEX_CLOCK_REALTIME) ?
CLOCK_REALTIME : CLOCK_MONOTONIC, &ats); CLOCK_REALTIME : CLOCK_MONOTONIC, &ats);

View File

@ -40,7 +40,7 @@ typedef gid_t kgid_t;
struct procfs_entry { struct procfs_entry {
char *name; char *name;
mode_t mode; mode_t mode;
const struct file_operations *fops; const struct proc_ops *fops;
}; };
#define NOD(NAME, MODE, FOP) { \ #define NOD(NAME, MODE, FOP) { \
@ -58,8 +58,8 @@ struct procfs_entry {
static const struct procfs_entry tid_entry_stuff[]; static const struct procfs_entry tid_entry_stuff[];
static const struct procfs_entry pid_entry_stuff[]; static const struct procfs_entry pid_entry_stuff[];
static const struct procfs_entry base_entry_stuff[]; static const struct procfs_entry base_entry_stuff[];
static const struct file_operations mckernel_forward_ro; static const struct proc_ops mckernel_forward_ro;
static const struct file_operations mckernel_forward; static const struct proc_ops mckernel_forward;
static ssize_t mckernel_procfs_read(struct file *file, char __user *buf, static ssize_t mckernel_procfs_read(struct file *file, char __user *buf,
size_t nbytes, loff_t *ppos); size_t nbytes, loff_t *ppos);
@ -84,7 +84,7 @@ struct procfs_list_entry {
* file. * file.
*/ */
LIST_HEAD(procfs_file_list); LIST_HEAD(procfs_file_list);
DEFINE_SEMAPHORE(procfs_file_list_lock); DEFINE_SEMAPHORE(procfs_file_list_lock, 1);
static char * static char *
getpath(struct procfs_list_entry *e, char *buf, int bufsize) getpath(struct procfs_list_entry *e, char *buf, int bufsize)
@ -183,10 +183,10 @@ add_procfs_entry(struct procfs_list_entry *parent, const char *name, int mode,
pde = proc_symlink(name, parent_pde, (char *)opaque); pde = proc_symlink(name, parent_pde, (char *)opaque);
} }
else { else {
const struct file_operations *fop; const struct proc_ops *fop;
if(opaque) if(opaque)
fop = (const struct file_operations *)opaque; fop = (const struct proc_ops *)opaque;
else if(mode & S_IWUSR) else if(mode & S_IWUSR)
fop = &mckernel_forward; fop = &mckernel_forward;
else else
@ -509,7 +509,7 @@ static ssize_t __mckernel_procfs_read_write(
struct proc_dir_entry *dp = PDE(inode); struct proc_dir_entry *dp = PDE(inode);
struct procfs_list_entry *e = dp->data; struct procfs_list_entry *e = dp->data;
#else #else
struct procfs_list_entry *e = PDE_DATA(inode); struct procfs_list_entry *e = pde_data(inode);
#endif #endif
loff_t offset = *ppos; loff_t offset = *ppos;
char pathbuf[PROCFS_NAME_MAX]; char pathbuf[PROCFS_NAME_MAX];
@ -770,16 +770,16 @@ int procfsm_packet_handler(void *os, int msg, int pid, unsigned long arg,
return 0; return 0;
} }
static const struct file_operations mckernel_forward_ro = { static const struct proc_ops mckernel_forward_ro = {
.llseek = mckernel_procfs_lseek, .proc_lseek = mckernel_procfs_lseek,
.read = mckernel_procfs_read, .proc_read = mckernel_procfs_read,
.write = NULL, .proc_write = NULL,
}; };
static const struct file_operations mckernel_forward = { static const struct proc_ops mckernel_forward = {
.llseek = mckernel_procfs_lseek, .proc_lseek = mckernel_procfs_lseek,
.read = mckernel_procfs_read, .proc_read = mckernel_procfs_read,
.write = mckernel_procfs_write, .proc_write = mckernel_procfs_write,
}; };
#define PA_NULL (-1L) #define PA_NULL (-1L)
@ -812,7 +812,7 @@ static int mckernel_procfs_buff_open(struct inode *inode, struct file *file)
struct proc_dir_entry *dp = PDE(inode); struct proc_dir_entry *dp = PDE(inode);
struct procfs_list_entry *e = dp->data; struct procfs_list_entry *e = dp->data;
#else #else
struct procfs_list_entry *e = PDE_DATA(inode); struct procfs_list_entry *e = pde_data(inode);
#endif #endif
os = osnum_to_os(e->osnum); os = osnum_to_os(e->osnum);
@ -1071,12 +1071,12 @@ rep:
return l; return l;
} }
static const struct file_operations mckernel_buff_io = { static const struct proc_ops mckernel_buff_io = {
.llseek = mckernel_procfs_lseek, .proc_lseek = mckernel_procfs_lseek,
.read = mckernel_procfs_buff_read, .proc_read = mckernel_procfs_buff_read,
.write = NULL, .proc_write = NULL,
.open = mckernel_procfs_buff_open, .proc_open = mckernel_procfs_buff_open,
.release = mckernel_procfs_buff_release, .proc_release = mckernel_procfs_buff_release,
}; };
static const struct procfs_entry tid_entry_stuff[] = { static const struct procfs_entry tid_entry_stuff[] = {

View File

@ -733,7 +733,7 @@ static struct vm_operations_struct rus_vmops = {
static int rus_mmap(struct file *file, struct vm_area_struct *vma) static int rus_mmap(struct file *file, struct vm_area_struct *vma)
{ {
vma->vm_flags |= arch_rus_vm_flags; vm_flags_set(vma, arch_rus_vm_flags);
vma->vm_ops = &rus_vmops; vma->vm_ops = &rus_vmops;
return 0; return 0;
} }
@ -776,10 +776,10 @@ reserve_user_space_common(struct mcctrl_usrdata *usrdata, unsigned long start, u
#if 0 #if 0
{ /* debug */ { /* debug */
struct vm_area_struct *vma; struct vm_area_struct *vma;
down_write(&current->mm->mmap_sem); mmap_write_lock(current->mm);
vma = find_vma(current->mm, start); vma = find_vma(current->mm, start);
vma->vm_flags |= VM_DONTCOPY; vm_flags_set(vma, VM_DONTCOPY);
up_write(&current->mm->mmap_sem); mmap_write_unlock(current->mm);
} }
#endif #endif
revert_creds(original); revert_creds(original);
@ -1463,12 +1463,12 @@ static int pager_req_map(ihk_os_t os, int fd, size_t len, off_t off,
} }
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) #if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0)
down_write(&current->mm->mmap_sem); mmap_write_lock(current->mm);
va = do_mmap_pgoff(file, ANY_WHERE, len, maxprot, va = do_mmap_pgoff(file, ANY_WHERE, len, maxprot,
prot_and_flags, pgoff); prot_and_flags, pgoff);
up_write(&current->mm->mmap_sem); mmap_write_unlock(current->mm);
#else #else
va = vm_mmap(file, ANY_WHERE, len, maxprot, va = vm_mmap(file, ANY_WHERE, len, maxprot,
prot_and_flags, pgoff << PAGE_SHIFT); prot_and_flags, pgoff << PAGE_SHIFT);
@ -1571,7 +1571,7 @@ static int pager_req_pfn(ihk_os_t os, uintptr_t handle, off_t off, uintptr_t ppf
#define PFN_VALID ((uintptr_t)1 << 63) #define PFN_VALID ((uintptr_t)1 << 63)
pfn = PFN_VALID; /* Use "not present" as the default setting */ pfn = PFN_VALID; /* Use "not present" as the default setting */
down_read(&current->mm->mmap_sem); mmap_read_lock(current->mm);
retry: retry:
pgd = pgd_offset(current->mm, va); pgd = pgd_offset(current->mm, va);
if (!pgd_none(*pgd) && !pgd_bad(*pgd) && pgd_present(*pgd)) { if (!pgd_none(*pgd) && !pgd_bad(*pgd) && pgd_present(*pgd)) {
@ -1623,7 +1623,9 @@ retry:
goto out_release; goto out_release;
} }
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || \ #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
fault = handle_mm_fault(vma, va, flags, NULL);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || \
(defined(RHEL_RELEASE_CODE) && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)) (defined(RHEL_RELEASE_CODE) && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5))
fault = handle_mm_fault(vma, va, flags); fault = handle_mm_fault(vma, va, flags);
#else #else
@ -1656,7 +1658,7 @@ retry:
} }
out_release: out_release:
up_read(&current->mm->mmap_sem); mmap_read_unlock(current->mm);
phys = ihk_device_map_memory(dev, ppfn_rpa, sizeof(*ppfn)); phys = ihk_device_map_memory(dev, ppfn_rpa, sizeof(*ppfn));
ppfn = ihk_device_map_virtual(dev, phys, sizeof(*ppfn), NULL, 0); ppfn = ihk_device_map_virtual(dev, phys, sizeof(*ppfn), NULL, 0);
@ -1682,9 +1684,9 @@ static int __pager_unmap(struct pager *pager)
int error; int error;
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) #if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0)
down_write(&current->mm->mmap_sem); mmap_write_lock(current->mm);
error = do_munmap(current->mm, pager->map_uaddr, pager->map_len); error = do_munmap(current->mm, pager->map_uaddr, pager->map_len);
up_write(&current->mm->mmap_sem); mmap_write_unlock(current->mm);
#else #else
error = vm_munmap(pager->map_uaddr, pager->map_len); error = vm_munmap(pager->map_uaddr, pager->map_len);
#endif #endif
@ -1749,9 +1751,11 @@ static long pager_req_mlock_list(ihk_os_t os, unsigned long start,
struct vm_area_struct *vma; struct vm_area_struct *vma;
kprintf("pager_req_mlock_list: addr(%p)\n", addr); kprintf("pager_req_mlock_list: addr(%p)\n", addr);
vma = find_vma(current->mm, 0x7010a0);
for (vma = mm->mmap; vma != NULL; vma = vma->vm_next) { /* Use find_vma to iterate through VMAs */
if (vma->vm_start < start || vma->vm_start > end) continue; vma = find_vma(mm, start);
while (vma != NULL) {
if (vma->vm_start > end) break;
kprintf("\t%p: %p -- %p\t%lx\n", vma, kprintf("\t%p: %p -- %p\t%lx\n", vma,
(void*)vma->vm_start, (void*)vma->vm_end, (void*)vma->vm_start, (void*)vma->vm_end,
vma->vm_flags & VM_LOCKED); vma->vm_flags & VM_LOCKED);
@ -1766,6 +1770,8 @@ static long pager_req_mlock_list(ihk_os_t os, unsigned long start,
addrpair->flag = vma->vm_flags; addrpair->flag = vma->vm_flags;
addrpair++; addrpair++;
} }
/* Use find_vma to get next VMA */
vma = find_vma(mm, vma->vm_end);
} }
full: full:
return cnt; return cnt;
@ -2129,14 +2135,14 @@ static int remap_user_space(uintptr_t rva, size_t len, int prot)
uintptr_t map; uintptr_t map;
dprintk("remap_user_space(%lx,%lx,%x)\n", rva, len, prot); dprintk("remap_user_space(%lx,%lx,%x)\n", rva, len, prot);
down_write(&mm->mmap_sem); mmap_write_lock(mm);
vma = find_vma(mm, rva); vma = find_vma(mm, rva);
if (!vma || (rva < vma->vm_start)) { if (!vma || (rva < vma->vm_start)) {
printk("remap_user_space(%lx,%lx,%x):find_vma failed. %p %lx %lx\n", printk("remap_user_space(%lx,%lx,%x):find_vma failed. %p %lx %lx\n",
rva, len, prot, vma, rva, len, prot, vma,
(vma)? vma->vm_start: -1, (vma)? vma->vm_start: -1,
(vma)? vma->vm_end: 0); (vma)? vma->vm_end: 0);
up_write(&mm->mmap_sem); mmap_write_unlock(mm);
map = -ENOMEM; map = -ENOMEM;
goto out; goto out;
} }
@ -2150,7 +2156,7 @@ static int remap_user_space(uintptr_t rva, size_t len, int prot)
prot, MAP_FIXED|MAP_SHARED, pgoff); prot, MAP_FIXED|MAP_SHARED, pgoff);
#endif #endif
up_write(&mm->mmap_sem); mmap_write_unlock(mm);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)
map = vm_mmap(file, start, len, map = vm_mmap(file, start, len,
@ -2175,7 +2181,7 @@ int mcctrl_clear_pte_range(uintptr_t start, uintptr_t len)
int ret; int ret;
ret = 0; ret = 0;
down_read(&mm->mmap_sem); mmap_read_lock(mm);
addr = start; addr = start;
while (addr < (start + len)) { while (addr < (start + len)) {
vma = find_vma(mm, addr); vma = find_vma(mm, addr);
@ -2193,7 +2199,7 @@ int mcctrl_clear_pte_range(uintptr_t start, uintptr_t len)
if (addr < end) { if (addr < end) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0) #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0)
/* Revert permission */ /* Revert permission */
vma->vm_flags |= VM_READ | VM_WRITE | VM_EXEC; vm_flags_set(vma, VM_READ | VM_WRITE | VM_EXEC);
error = zap_vma_ptes(vma, addr, end-addr); error = zap_vma_ptes(vma, addr, end-addr);
if (error) { if (error) {
mcctrl_zap_page_range(vma, addr, end-addr, mcctrl_zap_page_range(vma, addr, end-addr,
@ -2212,14 +2218,14 @@ int mcctrl_clear_pte_range(uintptr_t start, uintptr_t len)
} }
else { else {
/* Revert permission */ /* Revert permission */
vma->vm_flags |= VM_READ | VM_WRITE | VM_EXEC; vm_flags_set(vma, VM_READ | VM_WRITE | VM_EXEC);
zap_vma_ptes(vma, addr, end-addr); zap_vma_ptes(vma, addr, end-addr);
} }
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0) */ #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0) */
} }
addr = end; addr = end;
} }
up_read(&mm->mmap_sem); mmap_read_unlock(mm);
return ret; return ret;
} }