diff --git a/arch/arm64/kernel/include/syscall_list.h b/arch/arm64/kernel/include/syscall_list.h index 4747f3a4..b3c56b85 100644 --- a/arch/arm64/kernel/include/syscall_list.h +++ b/arch/arm64/kernel/include/syscall_list.h @@ -7,11 +7,7 @@ SYSCALL_DELEGATED(25, fcntl) SYSCALL_HANDLED(29, ioctl) SYSCALL_DELEGATED(43, statfs) SYSCALL_DELEGATED(44, fstatfs) -#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */ SYSCALL_HANDLED(56, openat) -#else /* POSTK_DEBUG_ARCH_DEP_62 */ -SYSCALL_DELEGATED(56, openat) -#endif /* POSTK_DEBUG_ARCH_DEP_62 */ SYSCALL_HANDLED(57, close) SYSCALL_DELEGATED(61, getdents64) SYSCALL_DELEGATED(62, lseek) diff --git a/arch/x86_64/kernel/include/syscall_list.h b/arch/x86_64/kernel/include/syscall_list.h index 6de0cccc..ce28d52e 100644 --- a/arch/x86_64/kernel/include/syscall_list.h +++ b/arch/x86_64/kernel/include/syscall_list.h @@ -133,9 +133,7 @@ SYSCALL_HANDLED(238, set_mempolicy) SYSCALL_HANDLED(239, get_mempolicy) SYSCALL_HANDLED(247, waitid) SYSCALL_HANDLED(256, migrate_pages) -#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */ SYSCALL_HANDLED(257, openat) -#endif /* POSTK_DEBUG_ARCH_DEP_62 */ SYSCALL_DELEGATED(270, pselect6) SYSCALL_DELEGATED(271, ppoll) SYSCALL_HANDLED(273, set_robust_list) diff --git a/kernel/include/xpmem.h b/kernel/include/xpmem.h index bb4a7772..5c3fb330 100644 --- a/kernel/include/xpmem.h +++ b/kernel/include/xpmem.h @@ -19,14 +19,13 @@ #define XPMEM_DEV_PATH "/dev/xpmem" -#if defined(POSTK_DEBUG_ARCH_DEP_46) || defined(POSTK_DEBUG_ARCH_DEP_62) -extern int xpmem_open(int, const char*, int, ihk_mc_user_context_t *ctx); -#else /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */ -extern int xpmem_open(ihk_mc_user_context_t *ctx); -#endif /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */ -extern int xpmem_remove_process_memory_range(struct process_vm *vm, +int xpmem_open(const char *pathname, + int flags, ihk_mc_user_context_t *ctx); +int xpmem_openat(const char *pathname, + int flags, ihk_mc_user_context_t *ctx); +int xpmem_remove_process_memory_range(struct process_vm *vm, struct vm_range *vmr); -extern int xpmem_fault_process_memory_range(struct process_vm *vm, +int xpmem_fault_process_memory_range(struct process_vm *vm, struct vm_range *vmr, unsigned long vaddr, uint64_t reason); #endif /* _XPMEM_H */ diff --git a/kernel/include/xpmem_private.h b/kernel/include/xpmem_private.h index a12c406a..48d2b6e3 100644 --- a/kernel/include/xpmem_private.h +++ b/kernel/include/xpmem_private.h @@ -305,8 +305,8 @@ static int xpmem_pin_page(struct xpmem_thread_group *, struct thread *, static void xpmem_unpin_pages(struct xpmem_segment *, struct process_vm *, unsigned long, size_t); -static struct xpmem_thread_group * __xpmem_tg_ref_by_tgid_nolock_internal( - pid_t, int, int); +static struct xpmem_thread_group *__xpmem_tg_ref_by_tgid_nolock_internal( + pid_t tgid, int index, int return_destroying); static inline struct xpmem_thread_group *__xpmem_tg_ref_by_tgid( pid_t tgid, @@ -355,16 +355,16 @@ static inline struct xpmem_thread_group *__xpmem_tg_ref_by_tgid_nolock( #define xpmem_tg_ref_by_tgid_nolock(t) __xpmem_tg_ref_by_tgid_nolock(t, 0) #define xpmem_tg_ref_by_tgid_all_nolock(t) __xpmem_tg_ref_by_tgid_nolock(t, 1) -static struct xpmem_thread_group * xpmem_tg_ref_by_segid(xpmem_segid_t); -static struct xpmem_thread_group * xpmem_tg_ref_by_apid(xpmem_apid_t); -static void xpmem_tg_deref(struct xpmem_thread_group *); +static struct xpmem_thread_group *xpmem_tg_ref_by_segid(xpmem_segid_t); +static struct xpmem_thread_group *xpmem_tg_ref_by_apid(xpmem_apid_t); +static void xpmem_tg_deref(struct xpmem_thread_group *tg); static struct xpmem_segment *xpmem_seg_ref_by_segid(struct xpmem_thread_group *, xpmem_segid_t); -static void xpmem_seg_deref(struct xpmem_segment *); +static void xpmem_seg_deref(struct xpmem_segment *seg); static struct xpmem_access_permit * xpmem_ap_ref_by_apid( - struct xpmem_thread_group *, xpmem_apid_t); -static void xpmem_ap_deref(struct xpmem_access_permit *); -static void xpmem_att_deref(struct xpmem_attachment *); + struct xpmem_thread_group *ap_tg, xpmem_apid_t apid); +static void xpmem_ap_deref(struct xpmem_access_permit *ap); +static void xpmem_att_deref(struct xpmem_attachment *att); static int xpmem_validate_access(struct xpmem_access_permit *, off_t, size_t, int, unsigned long *); diff --git a/kernel/syscall.c b/kernel/syscall.c index 67dc258d..6f3e698f 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -3486,66 +3486,67 @@ SYSCALL_DECLARE(ioctl) SYSCALL_DECLARE(open) { - const char *pathname = (const char *)ihk_mc_syscall_arg0(ctx); + const char *_pathname = (const char *)ihk_mc_syscall_arg0(ctx); + int flags = (int)ihk_mc_syscall_arg1(ctx); int len; - char *xpmem_wk; + char *pathname; long rc; - len = strlen_user(pathname); + len = strlen_user(_pathname); if (len < 0) return len; - if (!(xpmem_wk = kmalloc(len + 1, IHK_MC_AP_NOWAIT))) - return -ENOMEM; - if (copy_from_user(xpmem_wk, pathname, len + 1)) { - kfree(xpmem_wk); - return -EFAULT; - } - dkprintf("open(): pathname=%s\n", xpmem_wk); - rc = strcmp(xpmem_wk, XPMEM_DEV_PATH); -#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */ - if (!rc) { - rc = xpmem_open(__NR_open, xpmem_wk, (int)ihk_mc_syscall_arg1(ctx), ctx); - } - else { - rc = syscall_generic_forwarding(__NR_open, ctx); - } - kfree(xpmem_wk); -#else /* POSTK_DEBUG_ARCH_DEP_62 */ - kfree(xpmem_wk); - if (!rc) { - rc = xpmem_open(ctx); - } - else { - rc = syscall_generic_forwarding(__NR_open, ctx); - } -#endif /* POSTK_DEBUG_ARCH_DEP_62 */ - - return rc; -} - -#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */ -SYSCALL_DECLARE(openat) -{ - const char *pathname_user = (const char *)ihk_mc_syscall_arg1(ctx); - int flags = (int)ihk_mc_syscall_arg2(ctx); - char *pathname; - int len = strlen_user(pathname_user) + 1; - long rc; + len++; pathname = kmalloc(len, IHK_MC_AP_NOWAIT); if (!pathname) { - dkprintf("%s: error allocating pathname\n", __FUNCTION__); + dkprintf("%s: error allocating pathname\n", __func__); return -ENOMEM; } - if (copy_from_user(pathname, pathname_user, len)) { - dkprintf("%s: error: copy_from_user pathname\n", __FUNCTION__); + if (copy_from_user(pathname, _pathname, len)) { + dkprintf("%s: error: copy_from_user pathname\n", __func__); + rc = -EFAULT; + goto out; + } + + dkprintf("open(): pathname=%s\n", pathname); + if (!strncmp(pathname, XPMEM_DEV_PATH, len)) { + rc = xpmem_open(pathname, flags, ctx); + } else { + rc = syscall_generic_forwarding(__NR_open, ctx); + } + + out: + kfree(pathname); + return rc; +} + +SYSCALL_DECLARE(openat) +{ + const char *_pathname = (const char *)ihk_mc_syscall_arg1(ctx); + int flags = (int)ihk_mc_syscall_arg2(ctx); + char *pathname; + int len; + long rc; + + len = strlen_user(_pathname); + if (len < 0) + return len; + len++; + + pathname = kmalloc(len, IHK_MC_AP_NOWAIT); + if (!pathname) { + dkprintf("%s: error allocating pathname\n", __func__); + return -ENOMEM; + } + if (copy_from_user(pathname, _pathname, len)) { + dkprintf("%s: error: copy_from_user pathname\n", __func__); rc = -EFAULT; goto out; } dkprintf("openat(): pathname=%s\n", pathname); - if (!strcmp(pathname, XPMEM_DEV_PATH)) { - rc = xpmem_open(__NR_openat, pathname, flags, ctx); + if (!strncmp(pathname, XPMEM_DEV_PATH, len)) { + rc = xpmem_openat(pathname, flags, ctx); } else { rc = syscall_generic_forwarding(__NR_openat, ctx); } @@ -3554,7 +3555,6 @@ out: kfree(pathname); return rc; } -#endif /* POSTK_DEBUG_ARCH_DEP_62 */ SYSCALL_DECLARE(close) { diff --git a/kernel/xpmem.c b/kernel/xpmem.c index 8419409d..4de99832 100644 --- a/kernel/xpmem.c +++ b/kernel/xpmem.c @@ -36,9 +36,7 @@ struct xpmem_partition *xpmem_my_part = NULL; /* pointer to this partition */ - -#if defined(POSTK_DEBUG_ARCH_DEP_46) || defined(POSTK_DEBUG_ARCH_DEP_62) -int xpmem_open(int num, const char *pathname, +static int do_xpmem_open(int syscall_num, const char *pathname, int flags, ihk_mc_user_context_t *ctx) { int ret; @@ -48,23 +46,8 @@ int xpmem_open(int num, const char *pathname, struct mckfd *mckfd; long irqstate; - XPMEM_DEBUG("call: syscall_num=%d, pathname=%s, flags=%d", num, pathname, flags); -#else /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */ -int xpmem_open( - ihk_mc_user_context_t *ctx) -{ - const char *pathname = (const char *)ihk_mc_syscall_arg0(ctx); - int flags = (int)ihk_mc_syscall_arg1(ctx); - int ret; - struct thread *thread = cpu_local_var(current); - struct process *proc = thread->proc; - struct syscall_request request IHK_DMA_ALIGN; - int fd; - struct mckfd *mckfd; - long irqstate; - - XPMEM_DEBUG("call: pathname=%s, flags=%d", pathname, flags); -#endif /* POSTK_DEBUG_ARCH_DEP_46 || POSTK_DEBUG_ARCH_DEP_62 */ + XPMEM_DEBUG("call: syscall_num=%d, pathname=%s, flags=%d", + syscall_num, pathname, flags); if (!xpmem_my_part) { ret = xpmem_init(); @@ -73,22 +56,11 @@ int xpmem_open( } } -#ifdef POSTK_DEBUG_ARCH_DEP_62 /* Absorb the difference between open and openat args. */ - fd = syscall_generic_forwarding(num, ctx); + fd = syscall_generic_forwarding(syscall_num, ctx); if(fd < 0){ - XPMEM_DEBUG("syscall_num=%d error: fd=%d", num, fd); + XPMEM_DEBUG("syscall_num=%d error: fd=%d", syscall_num, fd); return fd; } -#else /* POSTK_DEBUG_ARCH_DEP_62 */ - request.number = __NR_open; - request.args[0] = (unsigned long)pathname; - request.args[1] = flags; - fd = do_syscall(&request, ihk_mc_get_processor_id()); - if (fd < 0) { - XPMEM_DEBUG("__NR_open error: fd=%d", fd); - return fd; - } -#endif /* POSTK_DEBUG_ARCH_DEP_62 */ ret = __xpmem_open(); if (ret) { @@ -129,6 +101,17 @@ int xpmem_open( return mckfd->fd; } +int xpmem_open(const char *pathname, + int flags, ihk_mc_user_context_t *ctx) +{ + return do_xpmem_open(__NR_open, pathname, flags, ctx); +} + +int xpmem_openat(const char *pathname, + int flags, ihk_mc_user_context_t *ctx) +{ + return do_xpmem_open(__NR_openat, pathname, flags, ctx); +} static int xpmem_ioctl( struct mckfd *mckfd, @@ -2127,7 +2110,7 @@ static void xpmem_unpin_pages( } -static struct xpmem_thread_group * __xpmem_tg_ref_by_tgid_nolock_internal( +static struct xpmem_thread_group *__xpmem_tg_ref_by_tgid_nolock_internal( pid_t tgid, int index, int return_destroying) @@ -2152,7 +2135,7 @@ static struct xpmem_thread_group * __xpmem_tg_ref_by_tgid_nolock_internal( } -static struct xpmem_thread_group * xpmem_tg_ref_by_segid( +static struct xpmem_thread_group *xpmem_tg_ref_by_segid( xpmem_segid_t segid) { struct xpmem_thread_group *tg; @@ -2163,7 +2146,7 @@ static struct xpmem_thread_group * xpmem_tg_ref_by_segid( } -static struct xpmem_thread_group * xpmem_tg_ref_by_apid( +static struct xpmem_thread_group *xpmem_tg_ref_by_apid( xpmem_apid_t apid) { struct xpmem_thread_group *tg; @@ -2215,8 +2198,7 @@ static struct xpmem_segment * xpmem_seg_ref_by_segid( } -static void xpmem_seg_deref( - struct xpmem_segment *seg) +static void xpmem_seg_deref(struct xpmem_segment *seg) { DBUG_ON(ihk_atomic_read(&seg->refcnt) <= 0); if (ihk_atomic_dec_return(&seg->refcnt) != 0) { @@ -2262,8 +2244,7 @@ static struct xpmem_access_permit * xpmem_ap_ref_by_apid( } -static void xpmem_ap_deref( - struct xpmem_access_permit *ap) +static void xpmem_ap_deref(struct xpmem_access_permit *ap) { DBUG_ON(ihk_atomic_read(&ap->refcnt) <= 0); if (ihk_atomic_dec_return(&ap->refcnt) != 0) { @@ -2278,8 +2259,7 @@ static void xpmem_ap_deref( } -static void xpmem_att_deref( - struct xpmem_attachment *att) +static void xpmem_att_deref(struct xpmem_attachment *att) { DBUG_ON(ihk_atomic_read(&att->refcnt) <= 0); if (ihk_atomic_dec_return(&att->refcnt) != 0) {