Index: sys/arch/amd64/amd64/netbsd32_syscall.c =================================================================== RCS file: /cvsroot/src/sys/arch/amd64/amd64/netbsd32_syscall.c,v retrieving revision 1.33 diff -p -u -u -r1.33 netbsd32_syscall.c --- sys/arch/amd64/amd64/netbsd32_syscall.c 7 Mar 2015 18:41:40 -0000 1.33 +++ sys/arch/amd64/amd64/netbsd32_syscall.c 20 Mar 2019 10:53:11 -0000 @@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_sys #include #include #include +#include /* XXX this file ought to include the netbsd32 version of these 2 headers */ #include #include @@ -50,6 +51,10 @@ __KERNEL_RCSID(0, "$NetBSD: netbsd32_sys #include #include +// XXXMRG +#include +#include + void netbsd32_syscall_intern(struct proc *); static void netbsd32_syscall(struct trapframe *); @@ -121,6 +126,12 @@ out: frame->tf_rflags &= ~PSL_C; /* carry bit */ } else { switch (error) { +#if 1 /* COMPAT_DRM */ + case ELAST+1: /* linux-y ERESTARTSYS */ + uprintf("%s: got linux ERESTARTSYS for syscall %d\n", __func__, code); + db_lstacktrace(); +#endif + /* FALLTHROUGH */ case ERESTART: /* * The offset to adjust the PC by depends on whether we Index: sys/arch/x86/x86/syscall.c =================================================================== RCS file: /cvsroot/src/sys/arch/x86/x86/syscall.c,v retrieving revision 1.16 diff -p -u -u -r1.16 syscall.c --- sys/arch/x86/x86/syscall.c 12 Aug 2017 07:21:57 -0000 1.16 +++ sys/arch/x86/x86/syscall.c 20 Mar 2019 10:53:11 -0000 @@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: syscall.c,v #include #include #include +#include #include @@ -47,6 +48,10 @@ __KERNEL_RCSID(0, "$NetBSD: syscall.c,v #include #include +// XXXMRG +#include +#include + #include "opt_dtrace.h" #ifndef __x86_64__ @@ -145,6 +150,12 @@ syscall(struct trapframe *frame) X86_TF_RFLAGS(frame) &= ~PSL_C; /* carry bit */ } else { switch (error) { +#if 1 /* COMPAT_DRM */ + case ELAST+1: /* linux-y ERESTARTSYS */ + uprintf("%s: got linux ERESTARTSYS for syscall %ld\n", __func__, code); + db_lstacktrace(); +#endif + /* FALLTHROUGH */ case ERESTART: /* * The offset to adjust the PC by depends on whether we Index: sys/ddb/db_interface.h =================================================================== RCS file: /cvsroot/src/sys/ddb/db_interface.h,v retrieving revision 1.36 diff -p -u -u -r1.36 db_interface.h --- sys/ddb/db_interface.h 4 Mar 2018 07:14:50 -0000 1.36 +++ sys/ddb/db_interface.h 20 Mar 2019 10:53:11 -0000 @@ -84,4 +84,12 @@ void db_show_disk(db_expr_t, bool, db_e db_stack_trace_print((db_expr_t)(intptr_t)__builtin_frame_address(0), \ true, 65535, "", printf) +#define db_ustacktrace() \ + db_stack_trace_print((db_expr_t)(intptr_t)__builtin_frame_address(0), \ + true, 65535, "", uprintf) + +#define db_lstacktrace() \ + db_stack_trace_print((db_expr_t)(intptr_t)__builtin_frame_address(0), \ + true, 65535, "", addlog) + #endif /* _DDB_DB_INTERFACE_H_ */ Index: sys/external/bsd/common/include/linux/err.h =================================================================== RCS file: /cvsroot/src/sys/external/bsd/common/include/linux/err.h,v retrieving revision 1.2 diff -p -u -u -r1.2 err.h --- sys/external/bsd/common/include/linux/err.h 27 Aug 2018 07:20:25 -0000 1.2 +++ sys/external/bsd/common/include/linux/err.h 20 Mar 2019 10:53:11 -0000 @@ -38,7 +38,7 @@ #include #include -#define MAX_ERRNO ELAST +#define MAX_ERRNO 4095 static inline bool IS_ERR_VALUE(uintptr_t n) Index: sys/external/bsd/common/include/linux/errno.h =================================================================== RCS file: /cvsroot/src/sys/external/bsd/common/include/linux/errno.h,v retrieving revision 1.3 diff -p -u -u -r1.3 errno.h --- sys/external/bsd/common/include/linux/errno.h 16 Jul 2014 20:56:24 -0000 1.3 +++ sys/external/bsd/common/include/linux/errno.h 20 Mar 2019 10:53:11 -0000 @@ -35,7 +35,8 @@ * - Linux consistently passes around negative errno values. NetBSD * consistently passes around positive ones, except the special magic * in-kernel ones (EJUSTRETURN, ERESTART, &c.) which should not be - * exposed to userland. Be careful! + * exposed to userland *or* linux-only code using the negative pointer + * means error return pattern. Be careful! */ #ifndef _LINUX_ERRNO_H_ @@ -43,7 +44,7 @@ #include -#define ERESTARTSYS ERESTART +#define ERESTARTSYS (ELAST+1) /* XXX */ #define ENOTSUPP ENOTSUP /* XXX ??? */ #define EREMOTEIO EIO /* XXX Urk... */ #define ECHRNG ERANGE /* XXX ??? */ Index: sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c,v retrieving revision 1.16 diff -p -u -u -r1.16 nouveau_drm.c --- sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c 21 Dec 2018 07:51:17 -0000 1.16 +++ sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c 20 Mar 2019 10:53:11 -0000 @@ -966,7 +966,7 @@ nouveau_ioctl_override(struct file *fp, ret = pm_runtime_get_sync(dev->dev); if (ret < 0 && ret != -EACCES) - return ret; + return -ret; switch (DRM_IOCTL_NR(cmd) - DRM_COMMAND_BASE) { case DRM_NOUVEAU_NVIF: Index: sys/external/bsd/drm2/drm/drm_cdevsw.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/drm2/drm/drm_cdevsw.c,v retrieving revision 1.13 diff -p -u -u -r1.13 drm_cdevsw.c --- sys/external/bsd/drm2/drm/drm_cdevsw.c 21 Dec 2018 07:51:18 -0000 1.13 +++ sys/external/bsd/drm2/drm/drm_cdevsw.c 20 Mar 2019 10:53:11 -0000 @@ -184,6 +184,8 @@ fail2: mutex_lock(&drm_global_mutex); (void)drm_lastclose(dev); fail1: drm_minor_release(dminor); fail0: KASSERT(error); + if (error == ERESTARTSYS) + error = ERESTART; return error; } @@ -299,6 +301,8 @@ drm_read(struct file *fp, off_t *off, st } /* Success! */ + if (error == ERESTARTSYS) + error = ERESTART; return error; } @@ -345,11 +349,16 @@ drm_ioctl_shim(struct file *fp, unsigned { struct drm_file *file = fp->f_data; struct drm_driver *driver = file->minor->dev->driver; + int error; if (driver->ioctl_override) - return driver->ioctl_override(fp, cmd, data); + error = driver->ioctl_override(fp, cmd, data); else - return drm_ioctl(fp, cmd, data); + error = drm_ioctl(fp, cmd, data); + if (error == ERESTARTSYS) + error = ERESTART; + + return error; } static int @@ -475,11 +484,14 @@ drm_fop_mmap(struct file *fp, off_t *off int error; KASSERT(fp == file->filp); - error = (*dev->driver->mmap_object)(dev, *offp, len, prot, uobjp, + /* XXX errno Linux->NetBSD */ + error = -(*dev->driver->mmap_object)(dev, *offp, len, prot, uobjp, offp, file->filp); *maxprotp = prot; *advicep = UVM_ADV_RANDOM; - return -error; + if (error == ERESTARTSYS) + error = ERESTART; + return error; } static paddr_t Index: sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h =================================================================== RCS file: /cvsroot/src/sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h,v retrieving revision 1.14 diff -p -u -u -r1.14 drm_wait_netbsd.h --- sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h 13 May 2016 15:25:57 -0000 1.14 +++ sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h 20 Mar 2019 10:53:11 -0000 @@ -114,10 +114,13 @@ DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, * Like the legacy DRM_WAIT_ON, DRM_SPIN_WAIT_ON returns * * . -EBUSY if timed out (yes, -EBUSY, not -ETIMEDOUT or -EWOULDBLOCK), - * . -EINTR/-ERESTART if interrupted by a signal, or + * . -EINTR/-ERESTARTSYS if interrupted by a signal, or * . 0 if the condition was true before or just after the timeout. * * Note that cv_timedwait* return -EWOULDBLOCK, not -EBUSY, on timeout. + * + * Note that ERESTARTSYS is actually ELAST+1 and only used in Linux + * code and must be converted for use in NetBSD code (user or kernel.) */ #define DRM_SPIN_WAIT_ON(RET, Q, INTERLOCK, TICKS, CONDITION) do \ @@ -148,6 +151,8 @@ DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, else \ _dswo_ticks = 0; \ if (RET) { \ + if ((RET) == -ERESTART) \ + (RET) = -ERESTARTSYS; \ if ((RET) == -EWOULDBLOCK) \ /* Waited only one tick. */ \ continue; \ @@ -165,26 +170,29 @@ DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, * * The untimed DRM_*WAIT*_UNTIL macros return * - * . -EINTR/-ERESTART if interrupted by a signal, or + * . -EINTR/-ERESTARTSYS if interrupted by a signal, or * . zero if the condition evaluated * * The timed DRM_*TIMED_WAIT*_UNTIL macros return * - * . -EINTR/-ERESTART if interrupted by a signal, + * . -EINTR/-ERESTARTSYS if interrupted by a signal, * . 0 if the condition was false after the timeout, * . 1 if the condition was true just after the timeout, or * . the number of ticks remaining if the condition was true before the * timeout. * - * Contrast DRM_SPIN_WAIT_ON which returns -EINTR/-ERESTART on signal, + * Contrast DRM_SPIN_WAIT_ON which returns -EINTR/-ERESTARTSYS on signal, * -EBUSY on timeout, and zero on success; and cv_*wait*, which return - * -EINTR/-ERESTART on signal, -EWOULDBLOCK on timeout, and zero on + * -EINTR/-ERESTARTSYS on signal, -EWOULDBLOCK on timeout, and zero on * success. * * XXX In retrospect, giving the timed and untimed macros a different * return convention from one another to match Linux may have been a * bad idea. All of this inconsistent timeout return convention logic * has been a consistent source of bugs. + * + * Note that ERESTARTSYS is actually ELAST+1 and only used in Linux + * code and must be converted for use in NetBSD code (user or kernel.) */ #define _DRM_WAIT_UNTIL(RET, WAIT, Q, INTERLOCK, CONDITION) do \ @@ -199,8 +207,11 @@ DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, } \ /* XXX errno NetBSD->Linux */ \ (RET) = -WAIT((Q), &(INTERLOCK)->mtx_lock); \ - if (RET) \ + if (RET) { \ + if ((RET) == -ERESTART) \ + (RET) = -ERESTARTSYS; \ break; \ + } \ } \ } while (0) @@ -240,6 +251,8 @@ DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, else \ _dtwu_ticks = 0; \ if (RET) { \ + if ((RET) == -ERESTART) \ + (RET) = -ERESTARTSYS; \ if ((RET) == -EWOULDBLOCK) \ (RET) = (CONDITION) ? 1 : 0; \ break; \ @@ -270,6 +283,8 @@ DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, while (!(CONDITION)) { \ /* XXX errno NetBSD->Linux */ \ (RET) = -WAIT((Q), &(INTERLOCK)->sl_lock); \ + if ((RET) == -ERESTART) \ + (RET) = -ERESTARTSYS; \ if (RET) \ break; \ } \ @@ -311,6 +326,8 @@ DRM_SPIN_WAKEUP_ALL(drm_waitqueue_t *q, else \ _dstwu_ticks = 0; \ if (RET) { \ + if ((RET) == -ERESTART) \ + (RET) = -ERESTARTSYS; \ if ((RET) == -EWOULDBLOCK) \ (RET) = (CONDITION) ? 1 : 0; \ break; \ Index: sys/external/bsd/drm2/linux/linux_fence.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/drm2/linux/linux_fence.c,v retrieving revision 1.14 diff -p -u -u -r1.14 linux_fence.c --- sys/external/bsd/drm2/linux/linux_fence.c 5 Jan 2019 22:24:24 -0000 1.14 +++ sys/external/bsd/drm2/linux/linux_fence.c 20 Mar 2019 10:53:11 -0000 @@ -565,8 +565,11 @@ fence_wait_any_timeout(struct fence **fe } end = hardclock_ticks; __insn_barrier(); - if (ret) + if (ret) { + if (ret == -ERESTART) + ret = -ERESTARTSYS; break; + } timeout -= MIN(timeout, (unsigned)end - (unsigned)start); } mutex_exit(&common.lock); @@ -709,8 +712,11 @@ fence_default_wait(struct fence *fence, } } /* If the wait failed, give up. */ - if (ret) + if (ret) { + if (ret == -ERESTART) + ret = -ERESTARTSYS; break; + } } out: Index: sys/external/bsd/drm2/linux/linux_ww_mutex.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/drm2/linux/linux_ww_mutex.c,v retrieving revision 1.5 diff -p -u -u -r1.5 linux_ww_mutex.c --- sys/external/bsd/drm2/linux/linux_ww_mutex.c 27 Aug 2018 15:11:32 -0000 1.5 +++ sys/external/bsd/drm2/linux/linux_ww_mutex.c 20 Mar 2019 10:53:11 -0000 @@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_ww_mut #include #include +#include #define WW_WANTLOCK(WW) \ LOCKDEBUG_WANTLOCK((WW)->wwm_debug, (WW), \ @@ -250,6 +251,8 @@ ww_mutex_state_wait_sig(struct ww_mutex do { /* XXX errno NetBSD->Linux */ ret = -cv_wait_sig(&mutex->wwm_cv, &mutex->wwm_lock); + if (ret == -ERESTART) + ret = -ERESTARTSYS; if (ret) break; } while (mutex->wwm_state == state); @@ -315,6 +318,8 @@ ww_mutex_lock_wait_sig(struct ww_mutex * do { /* XXX errno NetBSD->Linux */ ret = -cv_wait_sig(&mutex->wwm_cv, &mutex->wwm_lock); + if (ret == -ERESTART) + ret = -ERESTARTSYS; if (ret) goto out; } while (!(((mutex->wwm_state == WW_CTX) ||