Stella Privilege Structure

 

The structure of a Stella system is highly pragmatic. There are three aspects of the structure that have a major influence on the flexibility, the efficiency and the robustness.

  1. The module and context structures.
  2. The module and entity linkage.
  3. The privilege structure.

Privilege for protection against erroneous accesses

The classic concept of privilege seeks to minimise the harm caused by programming errors in applications programs. Access to certain system resources is only permitted to code executing in a privileged processor mode. The central operating system functions execute in the highest privileged mode and can, therefore, access any system resources. Applications normally execute in a lower privilege mode and cannot access protected resources. Applications cannot, therefore, accidentally damage operating system data or carry out spurious hardware operations.

Not all computers support the notions of privilege and protection. If, however, the processor provides automatic privilege transitions and privilege related protection mechanisms, Stella can use these to improve system security.

Because the operating system itself can access any resource, it is not enough to prevent applications from accessing protected resources directly. For this type of protection to work, it is necessary for the operating system to check the parameters of all calls that can potentially modify memory locations. It must, for example, be impossible to request a "read from file" operation into an area on memory that should not be accessible to the application. The effect of reading a file on top of the system variables would be just as disastrous as if the application overwrote the variables itself.

A normal operating system call performs, therefore, two preliminary operations.

Code that is already executing in operating system context (for example a device driver) will not need to re-establish the operating system context but it may be wise to have the parameters checked (the parameters may have been supplied by an application).

Calls from one operating system module to another, and calls from critical event handlers, do not (or should not) need any parameter checking.

Hardware memory management

If the hardware incorporates a fully functional memory management unit, then it is possible to isolate each task or group of tasks from other tasks and groups of tasks. Unlike the UNIX style virtual machine concept, this isolation is invisible to applications unless they attempt to breach the barrier. Stella supports a full range of protection from no protection at all, through simple privilege protection, to complete task-by-task protection.

Low cost hardware and high performance systems

Low cost computers may not have any form of memory management unit to provide hardware access control. If however, the processor supports different levels of privilege, then, even though it is not possible to protect operating system data structures, there is still protection against applications programs accidentally accessing hardware resources.

Where the processor does not support levels of privilege, this is emulated in software. While this does give any real protection, it provides a uniformity of concept across the range of Stella modules and allows external monitoring hardware to be used to trap erroneous accesses during software development.

For high performance systems, time critical tasks will usually execute in privileged mode, thus by-passing the protection mechanisms in the interests of efficiency.

Levels of security

Checking the parameters on every operating system call can be very expensive in processor time. In cost critical systems, these checks may not provide any benefit for two reasons.
  1. The applications must be correct or the system will not work reliably whether or not the operating system checks the call parameters. If the system depends on the correct functioning of all the applications software, stopping an application because it might damage operating system data structures may cause no more or less harm than letting it continue.
  2. Cost critical hardware is unlikely to include any hardware protection mechanisms. An application is just as likely to destroy the system directly as destroy it by passing incorrect parameters to an operating system call.

On the other hand, even in low cost systems, parameter checks can be useful. Some Stella modules not only check the parameters but also check the integrity of the operating system data structures that will be used. When developing software on low cost systems without protection hardware, there two reasons for using such operating system entries.

  1. It is important that the operating system does not collapse completely because of small programming errors.
  2. It is even more important to ensure that damage to the operating system structures is detected before it has time to propagate and hide the original corruption. Stella modules, therefore, provide one of four levels of security.
    -R   Reduced security is used mainly for "live" cost critical systems.
    -N Normal security protects against common programming errors.
    -H High security provides more rigorous checks than normal.
    -P Paranoid security is principally for testing low cost systems without hardware protection. The integrity of the operating system data structures is checked before use.

Privilege for protection against access conflicts

The concept of privilege is also used in Stella to protect against access conflicts. An access conflict could occur if, for example, a task were in the process of manipulating the memory manager data structures when another task requested a memory allocation.

The earliest "multitasking" operating systems resolved this problem by simply "locking" the task switching while such operating system resources were being accessed. This approach is extremely simple to implement and it is very efficient. If, however, the operations on operating system resources are allowed to become too long, the system response can be degraded.

In "modern" operating systems such resources are often protected by some means of "mutual exclusion". In any system, this approach will always degrade the efficiency, the predictability and the reliability1 of the system by comparison with simple locking. In time critical systems, the side effects of this approach can be even worse2.

Two-level protection

Standard Stella modules use a very simple two-level locking scheme.

In a single processor computer, or on each individual processor of a multiprocessor computer, only one task can be executing any one time. This task will continue to execute, either until it requests a reschedule or else it is interrupted by a hardware interrupt. Normally, when the "server" or "handler" for the interrupt has completed, the interrupted task will continue. The interrupt handler may, however, request a reschedule.

If interrupt servers do not make operating system calls, then things are fairly simple: all the operating system data structures will be completely immune from access conflicts if a task accessing these data structures cannot be forcibly suspended.

In standard Stella modules this is ensured by making all accesses to operating system data structures in privileged mode. (If the processor does not have a privileged execution mode, the mode transition is simulated in software.) While a task is executing in privileged mode, a request for a scheduling operation by an interrupt server will not take effect until the task returns to application mode. The request is not "lost": it is merely delayed. For most systems, these delays are much smaller than other timing uncertainties implicit in the multitasking concept.

This privilege controlled scheduler "lock-out" does not apply to interrupt servers (or external event handlers) as they are themselves "privileged" so the immediate response to external events is not affected.

It would seem that external event (or interrupt) handlers cannot make operating system calls (because they are not locked out during critical operations). Not all operating system functions, however, are protected in this way: the most important functions for external event (or interrupt) handling are intrinsically safe. The facilities for event handling, message passing, queuing, buffering, releasing jobs, etc. can be used without "additional" protection.

This approach creates a two-level system.

  1. Scheduled tasks, which can make any operating system call, the scheduler ensuring that access conflicts cannot occur.
  2. Asynchronous tasks such as interrupt handlers, which are not permitted to make certain calls that involve long operations on operating system data structures.

This restriction on asynchronous tasks is not completely arbitrary. There are other reasons for system designers to avoid making long operating system calls within interrupt handlers. In practice, therefore, this approach ensures that the most response critical operations are not burdened by mechanisms for resolving access conflicts, while for less critical tasks these mechanisms remain very simple.

The Stella modules using this approach are called bi-level modules (suffix -B). These bi-level modules do not provide a guaranteed maximum latency time for scheduled tasks (the length of time for which the scheduler is locked is not fully defined), other Stella modules provide guaranteed maximum scheduler latencies.

Atomised protection

Scheduler lock-out is unlikely to be a real problem for most systems. There is, however, a second series of Stella modules that limits the time for which the scheduler is locked during the execution of operating system functions. These "atomised" modules (suffix -A) limit the time for which the scheduler is locked to 25 "instructions" (about 10 Ás for an MC68020).

There are two disadvantages to using Stella atomised modules.

  1. The cost of major operating system calls is increased by about 10%,
  2. For the lowest priority jobs, the efficiency of the major operating system calls decreases as the system approaches full load.

Stella atomised modules guarantee maximum latency times much shorter than the "market leader" real time operating systems. They still do not, however, allow certain operating system calls to be made from interrupt servers.

Self synchronous protection

Stella "synchronous" modules (suffix -S) are similar to Stella atomised modules. However, they do not use privilege for protection but carry out the atomised operations with interrupts disabled. Interrupt servers cannot be invoked during a critical operation within the operating system: they are "synchronised" to internal operations. This has three main effects
  1. The restrictions on the operating system calls that may be made by an interrupt handler are removed.
  2. The maximum interrupt latency is increased by about a factor of 4 to about the same level as "real-time" systems such as VxWorks and VRTX32.
  3. The operating system call overheads are increased.

If the processor has "non-maskable" interrupts, then the handlers for these interrupts will not be affected: there is no additional latency and they may not make "long" operating system calls.

Where the processor has a number of interrupt levels, the interrupt "mask" can be set to a predetermined level during atomised operations. All handlers for interrupts at a priority above the predetermined level are unaffected: there is no additional latency and they may not make "long" operating system calls.

In principle, different operating system facilities could have different predetermined interrupt masks. This would, however, not improve the worst case performance, so this facility is not provided.

Comparison table for the Stella access conflict avoidance mechanisms

Modules Access to operating system facilities Interrupt latency Scheduler latency System efficiency
  Scheduled tasks Normal interrupt handlers High priority interrupt handler "Instructions" Normal/High priority "Instructions"  
-B Unrestricted Restricted Restricted 6/6 Undefined 99%
-A Unrestricted Restricted Restricted 6/6 25 90%
-S Unrestricted Unrestricted Restricted 25/6 25 85%

1  See "Mutual exclusion in operating systems".
2  See "Mutual exclusion in operating systems".  

  Back to table of contents.


Copyright (c) 1997 Tony Tebby.