From fe8c5e17acbb049222347358029f10e2909c06f7 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 7 Dec 2003 04:20:40 +0000 Subject: [PATCH] Add additional functionality to the upcall support to allow us to wait for an upcall instead of spin. Also fix a bug in the trap code. %gs faults have to be handled in nested interrupts because %gs is not saved and restored. It is also possible that %fs may have to be handled the same way, but I am not sure yet. --- sys/i386/i386/trap.c | 17 +++++++++++------ sys/kern/kern_upcall.c | 10 +++++++++- sys/platform/pc32/i386/trap.c | 17 +++++++++++------ sys/sys/proc.h | 3 ++- sys/sys/thread.h | 4 ++-- sys/sys/upcall.h | 3 ++- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index 21f1e259f6..1c56b05731 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.43 2003/11/21 05:29:07 dillon Exp $ + * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.44 2003/12/07 04:20:39 dillon Exp $ */ /* @@ -634,6 +634,16 @@ kernel_trap: goto out2; \ } \ } while (0) + /* + * Since we don't save %gs across an interrupt + * frame this check must occur outside the intr + * nesting level check. + */ + if (frame.tf_eip == (int)cpu_switch_load_gs) { + curthread->td_pcb->pcb_gs = 0; + psignal(p, SIGBUS); + goto out2; + } if (mycpu->gd_intr_nesting_level == 0) { /* * Invalid %fs's and %gs's can be created using @@ -644,11 +654,6 @@ kernel_trap: * (XXX) so that we can continue, and generate * a signal. */ - if (frame.tf_eip == (int)cpu_switch_load_gs) { - curthread->td_pcb->pcb_gs = 0; - psignal(p, SIGBUS); - goto out2; - } MAYBE_DORETI_FAULT(doreti_iret, doreti_iret_fault); MAYBE_DORETI_FAULT(doreti_popl_ds, diff --git a/sys/kern/kern_upcall.c b/sys/kern/kern_upcall.c index cbbdbe81db..2e1d381f62 100644 --- a/sys/kern/kern_upcall.c +++ b/sys/kern/kern_upcall.c @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/kern_upcall.c,v 1.3 2003/12/04 20:35:09 dillon Exp $ + * $DragonFly: src/sys/kern/kern_upcall.c,v 1.4 2003/12/07 04:20:40 dillon Exp $ */ /* @@ -137,6 +137,8 @@ upc_control(struct upc_control_args *uap) error = 0; targp = vu->vu_proc; targp->p_flag |= P_UPCALLPEND; + if (targp->p_flag & P_UPCALLWAIT) + wakeup(&targp->p_upcall); #ifdef SMP if (targp->p_thread->td_gd != mycpu) lwkt_send_ipiq(targp->p_thread->td_gd->gd_cpuid, sigupcall_remote, targp); @@ -205,6 +207,7 @@ upc_control(struct upc_control_args *uap) break; case UPC_CONTROL_POLL: case UPC_CONTROL_POLLANDCLEAR: + case UPC_CONTROL_WAIT: /* * If upcid is -1 poll for the first pending upcall and return the * id or 0 if no upcalls are pending. @@ -229,6 +232,11 @@ upc_control(struct upc_control_args *uap) break; } } + if (uap->cmd == UPC_CONTROL_WAIT && vu == NULL) { + p->p_flag |= P_UPCALLWAIT; + tsleep(&p->p_upcall, PCATCH, "wupcall", 0); + p->p_flag &= ~P_UPCALLWAIT; + } break; default: error = EINVAL; diff --git a/sys/platform/pc32/i386/trap.c b/sys/platform/pc32/i386/trap.c index b7acd58bfd..08b0b2274b 100644 --- a/sys/platform/pc32/i386/trap.c +++ b/sys/platform/pc32/i386/trap.c @@ -36,7 +36,7 @@ * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $ - * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.43 2003/11/21 05:29:07 dillon Exp $ + * $DragonFly: src/sys/platform/pc32/i386/trap.c,v 1.44 2003/12/07 04:20:39 dillon Exp $ */ /* @@ -634,6 +634,16 @@ kernel_trap: goto out2; \ } \ } while (0) + /* + * Since we don't save %gs across an interrupt + * frame this check must occur outside the intr + * nesting level check. + */ + if (frame.tf_eip == (int)cpu_switch_load_gs) { + curthread->td_pcb->pcb_gs = 0; + psignal(p, SIGBUS); + goto out2; + } if (mycpu->gd_intr_nesting_level == 0) { /* * Invalid %fs's and %gs's can be created using @@ -644,11 +654,6 @@ kernel_trap: * (XXX) so that we can continue, and generate * a signal. */ - if (frame.tf_eip == (int)cpu_switch_load_gs) { - curthread->td_pcb->pcb_gs = 0; - psignal(p, SIGBUS); - goto out2; - } MAYBE_DORETI_FAULT(doreti_iret, doreti_iret_fault); MAYBE_DORETI_FAULT(doreti_popl_ds, diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 224a79e560..fe26459015 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -37,7 +37,7 @@ * * @(#)proc.h 8.15 (Berkeley) 5/19/95 * $FreeBSD: src/sys/sys/proc.h,v 1.99.2.9 2003/06/06 20:21:32 tegge Exp $ - * $DragonFly: src/sys/sys/proc.h,v 1.37 2003/11/21 22:46:13 dillon Exp $ + * $DragonFly: src/sys/sys/proc.h,v 1.38 2003/12/07 04:20:38 dillon Exp $ */ #ifndef _SYS_PROC_H_ @@ -287,6 +287,7 @@ struct proc { #define P_ALTSTACK 0x4000000 /* have alternate signal stack */ #define P_INEXEC 0x8000000 /* Process is in execve(). */ #define P_PASSIVE_ACQ 0x10000000 /* Passive acquire cpu (see kern_switch) */ +#define P_UPCALLWAIT 0x20000000 /* Wait for upcall or signal */ #ifdef _KERNEL diff --git a/sys/sys/thread.h b/sys/sys/thread.h index b03d1f201f..9cbe1774c5 100644 --- a/sys/sys/thread.h +++ b/sys/sys/thread.h @@ -7,7 +7,7 @@ * Types which must already be defined when this header is included by * userland: struct md_thread * - * $DragonFly: src/sys/sys/thread.h,v 1.37 2003/11/21 22:46:13 dillon Exp $ + * $DragonFly: src/sys/sys/thread.h,v 1.38 2003/12/07 04:20:38 dillon Exp $ */ #ifndef _SYS_THREAD_H_ @@ -191,7 +191,7 @@ struct thread { #define TDF_PREEMPT_DONE 0x0008 /* acknowledge preemption complete */ #define TDF_IDLE_NOHLT 0x0010 /* we need to spin */ -#define TDF_UNUSED0100 0x0100 +#define TDF_SYSTHREAD 0x0100 /* system thread */ #define TDF_ALLOCATED_THREAD 0x0200 /* zalloc allocated thread */ #define TDF_ALLOCATED_STACK 0x0400 /* zalloc allocated stack */ #define TDF_VERBOSE 0x0800 /* verbose on exit */ diff --git a/sys/sys/upcall.h b/sys/sys/upcall.h index 18deca7bc2..bf7b279e43 100644 --- a/sys/sys/upcall.h +++ b/sys/sys/upcall.h @@ -23,7 +23,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/sys/upcall.h,v 1.6 2003/12/07 02:14:20 dillon Exp $ + * $DragonFly: src/sys/sys/upcall.h,v 1.7 2003/12/07 04:20:38 dillon Exp $ */ #ifndef _SYS_UPCALL_H_ @@ -46,6 +46,7 @@ struct upcall { #define UPC_CONTROL_DELETE 3 #define UPC_CONTROL_POLL 4 #define UPC_CONTROL_POLLANDCLEAR 5 +#define UPC_CONTROL_WAIT 6 #define UPC_CRITADD 32 /* NOTE! same as TDPRI_CRIT */ -- 2.41.0