New RS and new signal handling for system processes.

UPDATING INFO:
20100317:
        /usr/src/etc/system.conf updated to ignore default kernel calls: copy
        it (or merge it) to /etc/system.conf.
        The hello driver (/dev/hello) added to the distribution:
        # cd /usr/src/commands/scripts && make clean install
        # cd /dev && MAKEDEV hello

KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.

PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.

SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.

VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().

RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.

DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.

DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
This commit is contained in:
Cristiano Giuffrida
2010-03-17 01:15:29 +00:00
parent 7685e98304
commit cb176df60f
148 changed files with 4600 additions and 3308 deletions

View File

@@ -27,10 +27,12 @@ OBJECTS = \
do_fork.o \
do_exec.o \
do_newmap.o \
do_clear.o \
do_exit.o \
do_trace.o \
do_nice.o \
do_runctl.o \
do_update.o \
do_times.o \
do_setalarm.o \
do_stime.o \

View File

@@ -19,7 +19,7 @@
PUBLIC int do_abort(struct proc * caller, message * m_ptr)
{
/* Handle sys_abort. MINIX is unable to continue. This can originate e.g.
* in the PM (normal abort or panic) or TTY (after CTRL-ALT-DEL).
* in the PM (normal abort) or TTY (after CTRL-ALT-DEL).
*/
int how = m_ptr->ABRT_HOW;

75
kernel/system/do_clear.c Normal file
View File

@@ -0,0 +1,75 @@
/* The kernel call implemented in this file:
* m_type: SYS_CLEAR
*
* The parameters for this kernel call are:
* m1_i1: PR_ENDPT (endpoint of process to clean up)
*/
#include "../system.h"
#include <minix/endpoint.h>
#if USE_CLEAR
/*===========================================================================*
* do_clear *
*===========================================================================*/
PUBLIC int do_clear(struct proc * caller, message * m_ptr)
{
/* Handle sys_clear. Only the PM can request other process slots to be cleared
* when a process has exited.
* The routine to clean up a process table slot cancels outstanding timers,
* possibly removes the process from the message queues, and resets certain
* process table fields to the default values.
*/
struct proc *rc;
int exit_p;
int i;
if(!isokendpt(m_ptr->PR_ENDPT, &exit_p)) { /* get exiting process */
return EINVAL;
}
rc = proc_addr(exit_p); /* clean up */
/* Don't clear if already cleared. */
if(isemptyp(rc)) return;
/* Check the table with IRQ hooks to see if hooks should be released. */
for (i=0; i < NR_IRQ_HOOKS; i++) {
if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
}
}
/* Remove the process' ability to send and receive messages */
clear_endpoint(rc);
/* Turn off any alarm timers at the clock. */
reset_timer(&priv(rc)->s_alarm_timer);
/* Make sure that the exiting process is no longer scheduled,
* and mark slot as FREE. Also mark saved fpu contents as not significant.
*/
RTS_SETFLAGS(rc, RTS_SLOT_FREE);
rc->p_misc_flags &= ~MF_FPU_INITIALIZED;
/* Release the process table slot. If this is a system process, also
* release its privilege structure. Further cleanup is not needed at
* this point. All important fields are reinitialized when the
* slots are assigned to another, new process.
*/
if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
#if 0
/* Clean up virtual memory */
if (rc->p_misc_flags & MF_VM) {
vm_map_default(rc);
}
#endif
return OK;
}
#endif /* USE_CLEAR */

View File

@@ -15,8 +15,8 @@
PUBLIC int do_endksig(struct proc * caller, message * m_ptr)
{
/* Finish up after a kernel type signal, caused by a SYS_KILL message or a
* call to cause_sig by a task. This is called by the PM after processing a
* signal it got with SYS_GETKSIG.
* call to cause_sig by a task. This is called by a signal manager after
* processing a signal it got with SYS_GETKSIG.
*/
register struct proc *rp;
int proc_nr;
@@ -28,9 +28,10 @@ PUBLIC int do_endksig(struct proc * caller, message * m_ptr)
return EINVAL;
rp = proc_addr(proc_nr);
if (caller->p_endpoint != priv(rp)->s_sig_mgr) return(EPERM);
if (!RTS_ISSET(rp, RTS_SIG_PENDING)) return(EINVAL);
/* PM has finished one kernel signal. Perhaps process is ready now? */
/* The signal manager has finished one kernel signal. Is the process ready? */
if (!RTS_ISSET(rp, RTS_SIGNALED)) /* new signal arrived */
RTS_UNSET(rp, RTS_SIG_PENDING); /* remove pending flag */
return(OK);

View File

@@ -1,91 +1,27 @@
/* The kernel call implemented in this file:
* m_type: SYS_EXIT
*
* The parameters for this kernel call are:
* m1_i1: PR_ENDPT (slot number of exiting process)
*/
#include "../system.h"
#include <minix/endpoint.h>
#include <signal.h>
#if USE_EXIT
FORWARD _PROTOTYPE( void clear_proc, (register struct proc *rc));
/*===========================================================================*
* do_exit *
* do_exit *
*===========================================================================*/
PUBLIC int do_exit(struct proc * caller, message * m_ptr)
{
/* Handle sys_exit. A user process has exited or a system process requests
* to exit. Only the PM can request other process slots to be cleared.
* The routine to clean up a process table slot cancels outstanding timers,
* possibly removes the process from the message queues, and resets certain
* process table fields to the default values.
/* Handle sys_exit. A system process has requested to exit. Generate a
* self-termination signal.
*/
int exit_e;
int sig_nr = SIGABRT;
/* Determine what process exited. User processes are handled here. */
if (PM_PROC_NR == caller->p_endpoint) {
if (m_ptr->PR_ENDPT != SELF) { /* PM tries to exit self */
if(!isokendpt(m_ptr->PR_ENDPT, &exit_e)) /* get exiting process */
return EINVAL;
clear_proc(proc_addr(exit_e)); /* exit a user process */
return(OK); /* report back to PM */
}
}
cause_sig(caller->p_nr, sig_nr); /* send a signal to the caller */
/* The PM or some other system process requested to be exited. */
clear_proc(caller);
return(EDONTREPLY);
}
/*===========================================================================*
* clear_proc *
*===========================================================================*/
PRIVATE void clear_proc(rc)
register struct proc *rc; /* slot of process to clean up */
{
int i;
/* Don't clear if already cleared. */
if(isemptyp(rc)) return;
/* Check the table with IRQ hooks to see if hooks should be released. */
for (i=0; i < NR_IRQ_HOOKS; i++) {
if (rc->p_endpoint == irq_hooks[i].proc_nr_e) {
rm_irq_handler(&irq_hooks[i]); /* remove interrupt handler */
irq_hooks[i].proc_nr_e = NONE; /* mark hook as free */
}
}
/* Remove the process' ability to send and receive messages */
clear_endpoint(rc);
/* Turn off any alarm timers at the clock. */
reset_timer(&priv(rc)->s_alarm_timer);
/* Make sure that the exiting process is no longer scheduled,
* and mark slot as FREE. Also mark saved fpu contents as not significant.
*/
RTS_SETFLAGS(rc, RTS_SLOT_FREE);
rc->p_misc_flags &= ~MF_FPU_INITIALIZED;
/* Release the process table slot. If this is a system process, also
* release its privilege structure. Further cleanup is not needed at
* this point. All important fields are reinitialized when the
* slots are assigned to another, new process.
*/
if (priv(rc)->s_flags & SYS_PROC) priv(rc)->s_proc_nr = NONE;
#if 0
/* Clean up virtual memory */
if (rc->p_misc_flags & MF_VM) {
vm_map_default(rc);
}
#endif
return(EDONTREPLY); /* don't reply */
}
#endif /* USE_EXIT */

View File

@@ -17,21 +17,20 @@
*===========================================================================*/
PUBLIC int do_getksig(struct proc * caller, message * m_ptr)
{
/* PM is ready to accept signals and repeatedly does a kernel call to get
* one. Find a process with pending signals. If no signals are available,
* return NONE in the process number field.
* It is not sufficient to ready the process when PM is informed, because
* PM can block waiting for FS to do a core dump.
/* The signal manager is ready to accept signals and repeatedly does a kernel
* call to get one. Find a process with pending signals. If no signals are
* available, return NONE in the process number field.
*/
register struct proc *rp;
/* Find the next process with pending signals. */
for (rp = BEG_USER_ADDR; rp < END_PROC_ADDR; rp++) {
if (RTS_ISSET(rp, RTS_SIGNALED)) {
if (caller->p_endpoint != priv(rp)->s_sig_mgr) continue;
/* store signaled process' endpoint */
m_ptr->SIG_ENDPT = rp->p_endpoint;
m_ptr->SIG_MAP = rp->p_pending; /* pending signals map */
sigemptyset(&rp->p_pending); /* ball is in PM's court */
sigemptyset(&rp->p_pending); /* clear map in the kernel */
RTS_UNSET(rp, RTS_SIGNALED); /* blocked by SIG_PENDING */
return(OK);
}

View File

@@ -16,13 +16,11 @@
*===========================================================================*/
PUBLIC int do_kill(struct proc * caller, message * m_ptr)
{
/* Handle sys_kill(). Cause a signal to be sent to a process. The PM is the
* central server where all signals are processed and handler policies can
* be registered. Any request, except for PM requests, is added to the map
* of pending signals and the PM is informed about the new signal.
* Since system servers cannot use normal POSIX signal handlers (because they
* are usually blocked on a RECEIVE), they can request the PM to transform
* signals into messages. This is done by the PM with a call to sys_kill().
/* Handle sys_kill(). Cause a signal to be sent to a process. Any request
* is added to the map of pending signals and the signal manager
* associated to the process is informed about the new signal. The signal
* is then delivered using POSIX signal handlers for user processes, or
* translated into an IPC message for system services.
*/
proc_nr_t proc_nr, proc_nr_e;
int sig_nr = m_ptr->SIG_NUMBER;
@@ -33,10 +31,9 @@ PUBLIC int do_kill(struct proc * caller, message * m_ptr)
if (sig_nr >= _NSIG) return(EINVAL);
if (iskerneln(proc_nr)) return(EPERM);
/* Set pending signal to be processed by the PM. */
/* Set pending signal to be processed by the signal manager. */
cause_sig(proc_nr, sig_nr);
if (sig_nr == SIGKILL)
clear_endpoint(proc_addr(proc_nr));
return(OK);
}

View File

@@ -111,6 +111,9 @@ PUBLIC int do_privctl(struct proc * caller, message * m_ptr)
priv(rp)->s_k_call_mask[i] = (kcalls == NO_C ? 0 : (~0));
}
/* Set the default signal manager. */
priv(rp)->s_sig_mgr = DEF_SYS_SM;
/* Set defaults for resources: no I/O resources, no memory resources,
* no IRQs, no grant table
*/
@@ -123,8 +126,9 @@ PUBLIC int do_privctl(struct proc * caller, message * m_ptr)
/* Override defaults if the caller has supplied a privilege structure. */
if (m_ptr->CTL_ARG_PTR)
{
/* Copy s_flags. */
/* Copy s_flags and signal manager. */
priv(rp)->s_flags = priv.s_flags;
priv(rp)->s_sig_mgr = priv.s_sig_mgr;
/* Copy IRQs */
if(priv.s_flags & CHECK_IRQ) {

View File

@@ -19,7 +19,7 @@ PUBLIC int do_runctl(struct proc * caller, message * m_ptr)
/* Control a process's RTS_PROC_STOP flag. Used for process management.
* If the process is queued sending a message or stopped for system call
* tracing, and the RC_DELAY request flag is given, set MF_SIG_DELAY instead
* of RTS_PROC_STOP, and send a SIGNDELAY signal later when the process is done
* of RTS_PROC_STOP, and send a SIGKNDELAY signal later when the process is done
* sending (ending the delay). Used by PM for safe signal delivery.
*/
int proc_nr, action, flags, delayed;

View File

@@ -13,11 +13,13 @@
#include <assert.h>
#include <minix/type.h>
#include <minix/type.h>
#include <minix/safecopies.h>
#include "../system.h"
#include <signal.h>
struct map_info_s {
int flag;
@@ -161,7 +163,7 @@ PUBLIC int map_invoke_vm(struct proc * caller,
/* Connect caller on vmrequest wait queue. */
if(!(caller->p_vmrequest.nextrequestor = vmrequest))
mini_notify(proc_addr(SYSTEM), VM_PROC_NR);
send_sig(VM_PROC_NR, SIGKMEM);
vmrequest = caller;
return OK;

165
kernel/system/do_update.c Normal file
View File

@@ -0,0 +1,165 @@
/* The kernel call implemented in this file:
* m_type: SYS_UPDATE
*
* The parameters for this kernel call are:
* m2_i1: SYS_UPD_SRC_ENDPT (source process endpoint)
* m2_i2: SYS_UPD_DST_ENDPT (destination process endpoint)
*/
#include "../system.h"
#include "../ipc.h"
#include <string.h>
#if USE_UPDATE
#define DEBUG 0
#define proc_is_updatable(p) \
(RTS_ISSET(p, RTS_NO_PRIV) || RTS_ISSET(p, RTS_SIG_PENDING) \
|| (RTS_ISSET(p, RTS_RECEIVING) && !RTS_ISSET(p, RTS_SENDING)))
FORWARD _PROTOTYPE(void adjust_proc_slot, (struct proc *rp,
struct proc *from_rp));
FORWARD _PROTOTYPE(void adjust_priv_slot, (struct priv *privp,
struct priv *from_privp));
FORWARD _PROTOTYPE(void swap_proc_slot_pointer, (struct proc **rpp,
struct proc *src_rp, struct proc *dst_rp));
/*===========================================================================*
* do_update *
*===========================================================================*/
PUBLIC int do_update(struct proc * caller, message * m_ptr)
{
/* Handle sys_update(). Update a process into another by swapping their process
* slots.
*/
endpoint_t src_e, dst_e;
int src_p, dst_p;
struct proc *src_rp, *dst_rp, *rp;
struct priv *src_privp, *dst_privp;
struct proc orig_src_proc;
struct proc orig_dst_proc;
struct priv orig_src_priv;
struct priv orig_dst_priv;
int r;
reg_t src_vbp, dst_vbp;
/* Lookup slots for source and destination process. */
src_e = m_ptr->SYS_UPD_SRC_ENDPT;
if(!isokendpt(src_e, &src_p)) {
return EINVAL;
}
src_rp = proc_addr(src_p);
src_privp = priv(src_rp);
if(!(src_privp->s_flags & SYS_PROC)) {
return EPERM;
}
dst_e = m_ptr->SYS_UPD_DST_ENDPT;
if(!isokendpt(dst_e, &dst_p)) {
return EINVAL;
}
dst_rp = proc_addr(dst_p);
dst_privp = priv(dst_rp);
if(!(dst_privp->s_flags & SYS_PROC)) {
return EPERM;
}
/* Check if processes are updatable. */
if(!proc_is_updatable(src_rp) || !proc_is_updatable(dst_rp)) {
return EBUSY;
}
#if DEBUG
printf("do_update: updating %d (%s, %d, %d) into %d (%s, %d, %d)\n",
src_rp->p_endpoint, src_rp->p_name, src_rp->p_nr, priv(src_rp)->s_proc_nr,
dst_rp->p_endpoint, dst_rp->p_name, dst_rp->p_nr, priv(dst_rp)->s_proc_nr);
proc_stacktrace(src_rp);
proc_stacktrace(dst_rp);
printf("do_update: curr ptproc %d\n", ptproc->p_endpoint);
#endif
/* Save existing data. */
orig_src_proc = *src_rp;
orig_src_priv = *(priv(src_rp));
orig_dst_proc = *dst_rp;
orig_dst_priv = *(priv(dst_rp));
/* Swap slots. */
*src_rp = orig_dst_proc;
*src_privp = orig_dst_priv;
*dst_rp = orig_src_proc;
*dst_privp = orig_src_priv;
/* Adjust process slots. */
adjust_proc_slot(src_rp, &orig_src_proc);
adjust_proc_slot(dst_rp, &orig_dst_proc);
/* Adjust privilege slots. */
adjust_priv_slot(priv(src_rp), &orig_src_priv);
adjust_priv_slot(priv(dst_rp), &orig_dst_priv);
/* Swap global process slot addresses. */
swap_proc_slot_pointer(&ptproc, src_rp, dst_rp);
/* Fix segments. */
alloc_segments(src_rp);
alloc_segments(dst_rp);
prot_init();
#if DEBUG
printf("do_update: updated %d (%s, %d, %d) into %d (%s, %d, %d)\n",
src_rp->p_endpoint, src_rp->p_name, src_rp->p_nr, priv(src_rp)->s_proc_nr,
dst_rp->p_endpoint, dst_rp->p_name, dst_rp->p_nr, priv(dst_rp)->s_proc_nr);
proc_stacktrace(src_rp);
proc_stacktrace(dst_rp);
printf("do_update: curr ptproc %d\n", ptproc->p_endpoint);
#endif
return OK;
}
/*===========================================================================*
* adjust_proc_slot *
*===========================================================================*/
PRIVATE void adjust_proc_slot(struct proc *rp, struct proc *from_rp)
{
/* Preserve endpoints, slot numbers, priv structure. */
rp->p_endpoint = from_rp->p_endpoint;
rp->p_nr = from_rp->p_nr;
rp->p_priv = from_rp->p_priv;
priv(rp)->s_proc_nr = from_rp->p_nr;
}
/*===========================================================================*
* adjust_priv_slot *
*===========================================================================*/
PRIVATE void adjust_priv_slot(struct priv *privp, struct priv *from_privp)
{
/* Preserve privilege ids and non-privilege stuff in the priv structure. */
privp->s_id = from_privp->s_id;
privp->s_notify_pending = from_privp->s_notify_pending;
privp->s_int_pending = from_privp->s_int_pending;
privp->s_sig_pending = from_privp->s_sig_pending;
privp->s_alarm_timer = from_privp->s_alarm_timer;
memcpy(privp->s_farmem, from_privp->s_farmem, sizeof(privp->s_farmem));
}
/*===========================================================================*
* swap_proc_slot_pointer *
*===========================================================================*/
PRIVATE void swap_proc_slot_pointer(struct proc **rpp, struct proc *src_rp,
struct proc *dst_rp)
{
if(*rpp == src_rp) {
*rpp = dst_rp;
}
else if(*rpp == dst_rp) {
*rpp = src_rp;
}
}
#endif /* USE_UPDATE */