Processor with configurable allocation of privileged resources and exceptions between protection rings
By introducing a programmable protection ring management system, the ring level of exception handling is dynamically adjusted, which solves the problem of strict organization of the software layer on the processor in the existing technology, and realizes flexible software layer execution and efficiency improvement.
Patent Information
- Application Number
- CN202011596401.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2019-12-31
- Filing Date
- 2020-12-29
- Publication Date
- 2026-11-20
- Estimated Expiration
- 2040-12-29
AI Technical Summary
In existing processors, the strict allocation of protection rings during exception handling leads to overly rigid organization of the software layer, making it difficult to flexibly adjust the execution of the software layer in different rings without recompiling the code.
By introducing a programmable protection ring management system, the ownership of exceptions or privileged resources to protection rings is defined using programmable tables. This allows for dynamic adjustment of the ring level for exception handling during processor execution and enables flexible allocation and access control of privileged resources through hardware units and registers.
It enables the software layer to execute in any ring without recompiling the code, improving the processor's flexibility and efficiency, reducing latency, and supporting various software stack configuration requirements.
Smart Images

Figure CN113127936B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a protection ring or privilege level for a processor, which allows different layers of software to interact securely. Background Technology
[0002] Processors are typically designed to provide multiple levels of execution privilege, also known as protection rings. These two terms are used interchangeably below.
[0003] In existing technologies, execution resources and hardware configuration registers are allocated to protection rings based on assumed privilege levels. Application code runs in the lowest privilege ring and has no access to functions such as configuring the memory management unit (MMU), input / output interfaces, clocks, etc. Supervisor code (e.g., the operating system) runs in a higher privilege ring but has no access to functions common to multiple virtual operating systems, such as configuring the interrupt controller. Hypervisor code, such as a virtual machine monitor, runs in an even higher privilege ring but has no access to hardware boot or low-level debugger configuration settings.
[0004] Figures 1A to 1C An example of protection ring allocation for different software stacks implemented on the same processor with four privilege levels PL0 to PL3, with privilege level PL0 being the highest. Privilege levels PL0 to PL3 are also referred to as rings 0 to 3. Such an organization is used, for example, in x86 architecture processors.
[0005] Figure 1A This illustrates a typical scenario for applications running on an operating system. The application (USER) runs in ring 3, the lowest privileged ring, while the operating system (OS) can be assigned to ring 2, which immediately follows below. In this case, the OS could also be assigned to either ring 1 or ring 0 if the remaining rings are not in use. In practice, on x86 processors, historically all four rings have never been fully utilized—application code runs in ring 3, while the operating system (Linux, Windows, macOS) runs in ring 0. Running software layers in different rings typically involves recompiling the code.
[0006] Figure 1B This explains the context of the virtual system. In this case, the hypervisor (host) system runs under an operating system (guest), for example, in ring 1. In x86 processors, ring 0 has historically been assigned to the operating system, so a "-1" ring must be created to run the hypervisor, as documented in https: / / en.wikipedia.org / wiki / Protection_ring.
[0007] Figure 1CThis describes the context of the low-level debugger in the virtual system. The debugger runs under the hypervisor of ring 0.
[0008] Figure 2 This is a timing diagram illustrating the transition between rings (e.g., between an application APP running in ring 3 and an operating system OS running in ring 2). Typically, a transition to a lower (higher privilege) ring begins when an exception EXC is triggered. The term "exception" includes interrupts, hardware traps, and system calls. Interrupts and traps are typically triggered by hardware, while system calls are instructions executed by the running program itself.
[0009] When an exception EXC is triggered, the running program APP is rerouted to the processor provided by the operating system running in ring 2. Upon processor completion, it returns to the original program by executing an instruction designated as RFE ("Return from Exception").
[0010] Exception handling is based on the processor status register PS, which contains several control bit fields, including the current execution cycle and the exception to be masked. When an exception is triggered, the processor saves the contents of the program counter PC and the PS register in a hardware and atomic operation to locations called SPC ("Saved Program Counter") and SPS ("Saved Processor State"), and masks subsequent interrupts by setting the appropriate fields in the PS register. The exception handler takes over and typically begins by saving additional information from the execution context; this operation should not be interrupted to avoid context loss.
[0011] The processor terminates upon execution of the RFE instruction. In response to the RFE instruction, the processor restores the original values of the PC and PS registers from backups at the SPC and SPS locations in hardware and atomically, after which the program application resumes from the point it reached when an exception is triggered.
[0012] Typically, this is achieved by constructing a system that assigns each exception to a specific ring of a lower privilege level than the ring where exceptions might occur, usually the next lower-privileged ring for simplicity. The result is a rigid architecture that, in some cases, leads to trade-offs and performance degradation. Summary of the Invention
[0013] Typically, a processor is provided that has multiple protection rings and includes a protection ring management system, in which the attribution of exceptions or privileged resources to protection rings is defined by a programmable table.
[0014] This table can be programmed via software when the processor is started.
[0015] The ring management system can be configured to respond to anomalies by transferring the handling of the anomaly to a ring programmed for that anomaly.
[0016] The protection ring management system can be configured to: trigger a privilege trap when access is made from a privileged ring that has lower privileges than the ring programmed for the privileged resource; and respond to the privilege trap by transferring the handling of the exception to the ring programmed for the privileged resource.
[0017] The processor may include: a hardware unit capable of triggering an exception upon the occurrence of an event during program execution; a processor status register identifying the current protection ring applied to the currently executing program; a programmable ownership register embodying a programmable table; a processor status backup register defining the protection ring and corresponding permissions for each protection ring; and exception handler circuitry configured to: when an exception is triggered, index the ownership register with an identifier generated with the exception to specify the corresponding protection ring; exchange the contents of the processor status register with the contents of the status backup register specified by the ownership register; and transfer the current program to the exception handler, whereby the processor executes within the protection ring defined by the new contents of the processor status register.
[0018] The processor may include: a program counter that identifies the address of the instruction currently being executed by the processor; a corresponding backup register for the program counter for each protection ring; and a corresponding exception vector for each protection ring that identifies the address of the exception handler for that protection ring. The exception handling circuitry may be configured to: when an exception is triggered, store the contents of the program counter in the program counter backup register specified by the ownership register; and write the address provided by the exception vector specified by the ownership register into the program counter.
[0019] The processor may include a system-register-write instruction, which is executed by the processor to write the sum of the current ring level and the parameters of the instruction's relative level to the ownership register identified by the instruction.
[0020] Exceptions can include level interrupts, and the ownership register is programmed to assign level interrupts to the same protection ring as the program that was running when the interrupt was triggered.
[0021] A method for managing protection rings in a processor is also provided, the method comprising the steps of: programming an ownership table to assign exceptions or privileged resources to protection rings; processing an event by a processor running in a protection ring assigned to the exception or privileged resource when a processor triggers a signal for an exception or access to a privileged resource in a ring with lower privileges than the ring programmed for the privileged resource; and finding the protection ring assigned to the exception or privileged resource in the ownership table.
[0022] The method may include steps of programming the ownership table by software executed when the processor is started.
[0023] The method may include the following steps: executing the current program in a protection ring according to the permissions defined in the protector status register; defining the protection ring and corresponding permissions in the corresponding processor status backup register for each protection ring; and exchanging the contents of the processor status register with the contents of the status backup register identified by the ownership table when an event is triggered.
[0024] The method may include the following steps: running a hypervisor in a first ring; running a guest operating system in a second ring with lower privileges than the first ring, wherein the guest operating system is designed to manage a translation table for translating virtual addresses to physical addresses; running a user program in a third ring with lower privileges than the second ring, wherein the user program is designed to use virtual addresses applied to the translation table; assigning a virtual address allocation failure exception to the second ring, which is triggered when there is no entry in the translation table for the virtual address applied by the user program; assigning the translation table as a privileged resource to the first ring, whereby write access attempts to the translation table by the lower-privileged rings trigger privilege traps; and configuring a privilege trap processor executed by the hypervisor in the first ring to update the translation table. Attached Figure Description
[0025] The embodiments will be disclosed in the following description with reference to the accompanying drawings, wherein:
[0026] • The above description Figures 1A to 1C This illustrates the different program organization within a set of protection rings;
[0027] • The above description Figure 2 It is a sequence diagram illustrating the general handling of exceptions;
[0028] · Figure 3 An architecture of an exemplary processor, which serves as the basis for this invention, is shown;
[0029] · Figure 4 An example of the system register set on which this invention can rely is shown;
[0030] · Figure 5A and 5B This shows how to use it when an exception occurs and when returning from an exception. Figure 4 The registers in;
[0031] · Figure 6A and 6B This describes the handling of so-called "level" interrupts in both conventional processors and processors with programmable ring allocation; and
[0032] · Figure 7 This illustrates an example of handling memory access errors in a virtual system. Detailed Implementation
[0033] As mentioned earlier, in a conventional processor architecture with protection rings, each exception is assigned to a specific ring by design. This typically imposes a strict organization of software layers within different rings. For example, if it should provide Figure 1C The final organization of the type shown, where each ring contains a specific software layer, will be used when not all layers are needed (e.g., Figure 1A As shown (in the diagram), it appears that the layers actually used remain in the rings assigned to them, where spaces are left. In reality, moving these software layers to other rings introduces modifications to the hardware platform as seen by the programs, and typically requires recompiling these programs. Referring to the x86 architecture example, historically application code and the operating system were "locked" in rings 3 and 0 respectively, making it difficult to insert hypervisor code in rings with higher privileges that were not provided.
[0034] In the remainder of this disclosure, the term "exception" is used to specify events that may cause the processor to be redirected, such as interrupts, hardware traps, and system calls. The term "resource" refers to hardware elements that can be manipulated by a program: specific instructions, specific registers, fields in registers, hardware components integrated into the kernel (such as clocks), or combinations thereof.
[0035] This disclosure proposes a processor architecture that allows software layers to be executed in any ring without requiring code recompilation. To this end, the allocation of exceptions and certain resources (called privileged resources) to the rings can be programmable. For example, during the processor boot phase prior to the execution of different provided software layers, each exception or privileged resource is allocated, for example, to one of the available rings based on the contents of a pre-programmed table, which is actually a dedicated register of one or more processors.
[0036] Figure 3 The architecture of an example processor core is shown, serving as the basis for programmable assignment of exceptions to loops, such as the core of the Kalray Coolidge processor. The core features a 7-level deep pipeline, including an instruction prefetch level (PF), an instruction decode level (ID), a register fetch level (RR), and four instruction execution levels (E1 through E4).
[0037] The PF level essentially includes the PFB buffer, which stores preloaded instructions from the ICACHE instruction cache. The ID level includes the instruction decoding unit DEC, which controls the register file RF that forms the RR level. The register file RF manages the general-purpose registers GPR, which in this example are 64 64-bit registers r0 through r63. Depending on the decoded instruction, the selected register is connected in read or write mode to one of the multiple parallel processing units forming the execution levels E1 through E4. These processing units may include the load / store unit (LSU) for accessing the DCACHE data cache, the floating-point unit (FPU), and multiple arithmetic and logic units (ALUs) (two in this case).
[0038] In fact, because the kernel has a VLIW (“Very Large Instruction Word”) architecture, the decoding unit DEC can process packets containing multiple instructions that will be executed simultaneously – the kernel can execute up to 5 instructions at a time, one instruction at each processing unit in the execution level, and one instruction in the BCU unit as described below.
[0039] Therefore, the kernel also includes branches and a linked compare unit (BCU) to handle dedicated instructions from the decoder (DEC). This BCU, designed to support exception handling, includes a set of system function registers (SFRs), including a program counter (PC) and a processor status register (PS). The program counter (PC) is configured to contain the address of the currently executing instruction (or the address of the first instruction in a VLIW packet). Among other things, the processor status register (PS) defines the loop in which the current instruction is executing, the associated permissions, and masked exceptions. Locations (SPC and SPS) are also provided for storing the program counter and processor status register.
[0040] The BCU connects to various other units to generate exceptions, such as hardware traps or system calls. In particular, the instruction decoder (DEC) captures system calls for specific instructions, while various units or resources can return hardware traps, which are often referred to as "unauthorized operations" (accessing non-existent or protected addresses, accessing protected resources, overflows, etc.).
[0041] Finally, the kernel includes various peripheral units, including: the interrupt controller (ITC) that generates interrupts to the BCU based on external events, the memory management unit (MMU) associated with the translation backup buffer (TLB), the input / output interface (IF), the performance monitor (PM), the cache memory, and other units that can also generate exceptions.
[0042] As described so far Figure 3 The architecture and operation of the invention are known and will not be described in detail below, except for those elements that are useful for understanding the invention.
[0043] Figure 4 An example of a set of system registers for implementing programmable allocation of ring-to-exception is shown. These registers may include and supplement the BCU's System Function Registers (SFRs) and may be accessed via instructions dedicated to the BCU for manipulating these registers.
[0044] As described above, the SFR register set includes the program counter (PC), the processor status register (PS), and locations SPC and SPS for storing the program counter and the processor status register, respectively. In practice, each of the SPC and SPS locations contains multiple registers SPC_PL(i) and SPS_PL(i) dedicated to an individual protection ring PL(i).
[0045] The SFR register set also includes: an exception vector EV, an exception checksum register ES, and an exception address register EA, one for each type of ring PL(i). The exception vector EV defines the address of the exception handler for each ring, representing the different types of exceptions that can occur in the corresponding ring. Each exception checksum ES contains data stored when an exception occurs in the corresponding ring, allowing the exception handler to identify the nature of the exception and adjust its handling. Similarly, each exception address register EA contains the memory address at the origin of the exception in the corresponding ring, allowing the processor to manage memory access traps. The functions of registers EV, ES, and EA are known and will not be described in detail further.
[0046] A set of SFR registers is supplemented by a set of registers, each typically referred to as REO (“Resource and Exception Ownership”), which together are configured to allocate each exception or privileged resource in the system to a given protection ring. The ownership register REO can be programmed by the system developer according to the specific needs of his / her software stack. In practice, the contents of the REO register (like the contents of other SFR registers) can be defined in the processor firmware, which is loaded each time the processor boots. To save hardware, configurable resources and exceptions can be grouped together in the REO registers, with the distinction then handled by the exception handler.
[0047] Furthermore, the SFR registers can be manipulated at any time via specific instructions dedicated to the BCU, including the REO register. Therefore, nothing prevents programming the REO registers after system startup. For example, firmware could be designed to load the operating system into a given ring, then leave that ring to the operating system for programming exceptions and resource ownership. However, it's important to remember that the operating system will also be unable to allocate resources or exceptions to rings with higher privileges than itself, nor can it allocate resources or exceptions to itself that have been allocated a higher privilege level than itself.
[0048] The REO register set may include:
[0049] SYO: General System Call Ownership Register;
[0050] ITO: Interrupt Ownership Register;
[0051] HTO: Hardware Trap Ownership Register;
[0052] DO: Ownership of resources and exceptions used for debugging (breakpoints, variable monitoring, etc.);
[0053] MO: (“various ownership”) Ownership of specific hardware resources (watchdog, performance monitor, MMU, SFR registers, etc.); and
[0054] PSO: Ownership of the bit present in the processor status register PS or the corresponding backup register SPS.
[0055] Therefore, these six registers are used to programmatically allocate exceptions and privileged resources to the ring.
[0056] Therefore, privileged hardware resources can be programmatically allocated to rings so that any access to such resources is permitted only to designated rings or rings with higher privileges. Privileged hardware resources may include specific execution units, whereby the execution of corresponding instructions is also considered an access to the hardware resource.
[0057] The BCU is then configured to trigger a "privileged" trap if such a privileged resource is used in an unauthorized ring. This privileged trap (although part of the traditional traps in the processor specification) is not attributed to a single ring or privilege level. Therefore, no REO register field is assigned to them to globally indicate their allocation. The handling of this hardware trap becomes the responsibility of the ring set for the privileged resource in the corresponding REO register field.
[0058] In the example processor, each REO register (constructed as 64-bit) can contain up to 32 2-bit fields, where the positions of these fields in the register correspond to exception or resource identifiers defined in the processor specification, and the two bits in each field identify a ring. Each of the 32 possible exceptions or privileged resources is assigned one of four rings. A one-to-one correspondence is not required—the fields can be used to organize the coordination set of resources or exceptions. The six REO registers configured in this way broadly cover all the exceptions and resources required in a general-purpose processor.
[0059] Figure 5A and 5B This demonstrates how to use it when an exception is triggered and when returning from an exception. Figure 4The registers. The operations described in each of these diagrams are performed in hardware.
[0060] exist Figure 5A In this context, exception E is triggered, where E represents one of the following exceptions: interrupt IT, system call SY, hardware trap HT, or debug exception D. The hardware can be designed to generate information indicating the handling of the exception; this is a tuple.<REO,n> REO identifies one of the following six registers: HTO, SYO, ITO, DO, PSO, MO; and "n" is the index in the register.
[0061] For privilege trap exception E (triggered by unauthorized access to a resource), the hardware can be designed to generate tuples.<MO|PSO,n> Its identifier is the resource to which the access is targeted (e.g., an unauthorized instruction defined in the MO register, an unauthorized field defined in the PSO register).
[0062] For interrupt exception E, the hardware can be designed to generate tuples.<ITO,s> , where “s” is the interrupt number.
[0063] For system call exception E, the hardware can be designed to generate tuples.<SYO,div(m,1024)> The "m" is the call number, which allows a range of 1024 call numbers to be associated with each field of the SYO register.
[0064] For hardware trap exception E (e.g., "page fault"), the hardware can generate tuples.<HTO,12> .exist Figure 5A In, abnormal tuples<REO,n> Identify the REO register to be used and apply index n to that register. This queries the field at position n in the register, which provides the value i that identifies the protection ring assigned to the exception.
[0065] The REO register provides the processor state backup register SPS_PL(i), the program counter backup register SPC_PL(i), and the exception vector EV_PL(i) assigned to level i.
[0066] At the same time, the contents of the PS and SPS_PL(i) registers are swapped, the value of the program counter PC is written to the SPC_PL(i) register, and the address provided by the exception vector EV_PL(i) is written to the program counter PC.
[0067] The corrector and exception address registers ES and EA are updated with values representing exceptions.
[0068] In the following clock cycle, the processor executes the instruction identified by the new program counter value PC, which is the first instruction of the exception handler. Taking into account other parameters defined in the processor status register PS (permissions, masked interrupts, etc.), the processor operates in a loop defined by the new value in that register.
[0069] In practice, the exception vector EV_PL(i) contains a single address, which may not be efficient for all exception types because different exception types require different handling. Therefore, as shown in the figure, depending on the type of exception E, the output address of the EV register may be affected by the offset D, so that execution is redirected to the appropriate processor.
[0070] In practice, the contents of the SPS_PL(i) register are not completely written to the PS register. In fact, the SPS_PL(i) register contains the values at the end of the last execution of the processor for ring i, which may have been changed from the required initial values. Therefore, the system can force certain initial values to be written to the PS register, such as interrupt masking and ring level provided by the REO register.
[0071] As indicated, E and<REO,n> The relationship can be wired in hardware. For example, in a conventional processor, at each execution, the hardware scans the MMU configuration instructions to verify that the running program is running in a ring associated with supervisor privileges, the current ring being identified by a special field in the processor status register PS. In other words, the special field in the PS register is typically compared to a fixed value, and a privilege trap is triggered if the comparison fails. In a processor of the type described here, the hardware is wired to compare the special field in the PS register with the programmable contents of the special field in the MO register (i.e., the field at position k), instead of comparing it to a fixed value. Then, when the comparison fails, the hardware will generate a tuple...<MO,k> To trigger the privilege trap.
[0072] exist Figure 5B In this process, the exception handler executes a return from an exception (RFE) intended to restore the interrupted program. The current ring i's level selection alternate registers SPS_PL(i) and SPC_PL(i) can be read from the PS register.
[0073] At the same time, the contents of the PS and SPS_PL(i) registers are swapped, and the program counter PC receives the contents of the SPC_PL(i) register, which restores the context of the interrupted program.
[0074] In the next clock cycle, the interrupted program resumes from where it stopped.
[0075] According to one embodiment, write instructions to the REO register are designed to be used in conjunction with a relative ring level (i.e., an increment between 0 and +3), which the BCU unit adds to the current ring level to obtain the absolute level to be written to the REO register. This functionality is... Figure 4 This is illustrated by the register write instruction "SET_REO" received by the BCU unit. This instruction conveys the relative ring level as a parameter, which is applied to adder 10. Adder 10 also receives the current ring level contained in the PL field of the processor status register PS. The sum of these parameters generates the absolute level to be written to the target REO register.
[0076] With this configuration, the processor firmware can boot the highest-privileged software layer in a given software stack from any ring, allowing that first software layer to program other layers within their own rings without needing to know which ring it's in. The software stack can then be placed anywhere in the available ring stack without having to recompile different layers.
[0077] For example, when the platform is provided with a low-level debugging layer (ring 0) for a given software stack (e.g.) Figure 1C (Example in the text), and when it is desired to put that software stack into production on the highest privileged ring later (i.e., ... Figure 1B This feature (moving the layer down one level in the middle) can be very useful.
[0078] On a conventional processor, removing the debug layer will result in Figure 1B The configuration shown has a blank space at ring 0. This will preserve the binaries for rings 2 and 3, but the hypervisor in ring 1 will still have to be recompiled to handle exceptions handled by the debugger. Then, moving the entire stack down will involve recompiling all layers.
[0079] Using the proposed implementation, recompilation is not required. Figure 1C In this case, the firmware is configured to boot the debugger in ring 0. The debugger is programmed with the exceptions it handles (relative level +0) and a hypervisor is started, which can be programmed with relative levels +0 to +2 (converted from absolute levels 1 to 3 by the BCU unit) for the exceptions it handles, as well as exceptions handled by higher layers. Alternatively, the hypervisor can delegate the programming of exceptions to be handled by the operating system and applications to the operating system—the operating system will use relative levels +0 and +1, which are converted from absolute levels 2 and 3 by the BCU unit.
[0080] By removing the debug layer, the firmware can be configured to boot the hypervisor in ring 0 this time. The hypervisor will operate in exactly the same way, programming exception assignments with relative levels +0 to +2 (this time converted from absolute levels 0 to 2 by the BCU unit).
[0081] Using relative levels to specify rings means employing guardrails to handle overflow and underflow. In practice, a software stack can accidentally start in a ring that is too high, where the last layer of the stack is above the last ring.
[0082] This situation can be caught by a dedicated "ring overflow" hardware trap triggered by the BCU, which can be handled by a system reset.
[0083] However, such overflow traps can also be redirected to simulate the presence of additional rings. Then, for example, the trap is handled by a routine that sets up the requested new ring by saving the contents of the SFR registers associated with the unused ring (potentially a lower-level ring), allocating those registers to the new ring, and reprogramming them to match the privileges of the new ring. This mode of operation allows for the envisioning of software stacks with more than four rings, and the use of physically implemented rings as caches.
[0084] The possibility of reprogramming the ownership of exceptions, resources, and instructions in the ring opens up many other perspectives, to name just a few.
[0085] For example, processors (such as Figure 3 A processor (in a system) typically includes multiple performance monitors (PMs), such as four. In a conventional architecture, these might be (in a fixed way) assigned to the operating system ring, and applications would access them via system calls, which introduces latency. Depending on the software stack the developer is targeting, there may be benefits to allocating performance monitors in different ways. For example, a single-layer software stack (such as a real-time system) is best executed in ring 0, where it has direct access to all four performance monitors. In a two-layer stack (operating system and application code), it may be beneficial to distribute performance monitors between two corresponding rings so that application code has direct access to a set of monitors dedicated to it.
[0086] In a software stack with a hypervisor, one might want to assign a performance monitor to each of the three involved rings.
[0087] The disclosed system accepts all these scenarios by programming corresponding fields in the MO register (for various exceptions) accordingly. Access to a specific resource (e.g., a performance monitor) can be performed via a dedicated field in the SFR register by executing instructions managed by the BCU. The MO register then assigns a given ring to a dedicated field in the SFR register. Therefore, if the current ring has the required permissions, the BCU instructions execute normally, providing direct access to the resource. Otherwise, the BCU unit triggers a trap for the ring specified in the MO register. This mechanism authorizes direct resource access to a given programmed ring.
[0088] Figure 6A and Figure 6B The handling of so-called “level” interrupts is shown in both a conventional processor and a processor with programmable attribution of exceptions with loops.
[0089] "Level" interrupts are interrupts that can be handled within the same ring in which the interrupted program runs. They may be interrupts generated by peripheral devices and can be directly accessed by application code without affecting system integrity. An example of a level interrupt implementation is the preemptive and asynchronous management of data from a command queue accessible to the application. Figure 6A This is a timeline illustrating how such interrupts are handled in a conventional manner. In a conventional processor, interrupts are always constructed to a higher-privilege ring. Therefore, when the application code APP running in ring 3 receives interrupt IT, execution is transferred to ring 2 (e.g., the operating system OS) to be handled there by the interrupt handler ITH (OS).
[0090] The interrupt handler ITH(OS) determines the nature of the interrupt and executes a special exception return RFE1, which prepares the program counter PC and PS registers to execute the interrupt handler ITH(USER) in ring 3 (usually a dedicated process for this purpose), instead of allowing the program APP to resume.
[0091] The process running the interrupt handler ITH(USER) handles the interrupt and ends with a system call to the operating system SYSCALL to restore the context of the program APP that was saved by the operating system when the interrupt occurred.
[0092] Finally, the operating system restores the context by executing an exception return to RFE2, which resumes the interrupted program.
[0093] Depending on the system, the implementation of interrupt-related user callback functions may vary, but it typically requires multiple round trips between the user world and the operating system world.
[0094] Figure 6B The same situation is illustrated by a processor with programmable ring allocation. Here, by programming the ITO register, the level interrupt in question, which can be identified by a given number n, is assigned to the same ring as the program that is expected to be interrupted, i.e., 3 in this example.
[0095] Therefore, when interrupt IT(n) occurs, the system... Figure 5A The mechanism operates to execute the ring 3 interrupt handler, and according to... Figure 5B The mechanism resumes the execution of interrupted programs. This avoids useless round trips between rings and has the benefit of significantly reducing latency.
[0096] Figure 7 Another application of a processor with programmable ring allocation is shown, which allows for relatively efficient use of memory in a virtualized configuration without dedicated virtual hardware.
[0097] The operating system typically provides its applications with a virtual address space, which is translated into physical addresses using the memory manager (MMU). (Note that the concept of a "virtual" address is separate from the concept of a "virtual" machine in the context of a virtual system.) Application code directly accesses the MMU using translation tables maintained by the operating system, called page tables, for regular read and write operations in memory. The most frequently used entries in the page tables are typically cached in the MMU, specifically in the so-called TLB (Translation Lookahead Buffer). Whenever a virtual address used by the application code has a translation in the page table, the operating system intervenes. When a translation is missing from the page table, a no-map trap is triggered, directing the system to update the page table.
[0098] Address translation becomes complex when the operating system is a "guest" system running in a virtual machine managed by a hypervisor or monitor ("host"). The physical addresses assigned to the virtual addresses are "guest" or intermediate physical addresses, which are meaningless because they are an illusion created by the hypervisor for the guest operating system. They will be further translated into physical host or machine addresses for exploitation. Several hardware extensions exist for handling these translations, such as SLAT ("Level 2 Address Translation"), over which current processor architectures do not offer any particular advantage. However, such hardware extensions are expensive in terms of silicon surface area.
[0099] However, this architecture can provide optimizations within the context of software management of address translation.
[0100] The hypervisor is typically configured to maintain an auxiliary table, often referred to as a "shadow table," used to directly translate virtual addresses into physical host addresses. This functionality will be used below.
[0101] The system is also configured so that the virtual machine can access the MMU without significant restrictions, but MMU write instructions can be assigned to ring 1 (hypervisor) by programming a special field of the MO register.
[0102] Figure 7 This is a timing diagram illustrating an example of how to handle unmapped traps that occur in this configuration.
[0103] During its normal execution, applications (APPs) running on virtual machines (e.g., in ring 3) use the MMU (or TLB) to perform memory accesses. The TLB, based on an auxiliary translation table, directly translates the virtual addresses used by the application into physical host addresses through the covert intervention of the hypervisor.
[0104] Then, the performance of the virtual machine is the same as that of the real machine.
[0105] When the virtual address being used is not translated, the MMU triggers a no-map trap, which is typically directed to ring 2 running a guest operating system.
[0106] The operating system then reacts in the usual way by attempting to update the MMU. Since the MMU write instruction has been assigned to ring 1, this initiative results in a privilege trap on the hypervisor ring. The hypervisor then takes over to "correct" the update initiated by the operating system. To do this, the hypervisor uses an auxiliary table and replaces the physical guest address used by the operating system with the physical host address, then switches to the guest operating system by returning RFE1 from an exception. The guest operating system "determines" that it has updated the MMU and switches to the application by returning RFE2 from an exception.
[0107] This architecture also allows the software stack running in the virtual machine to run without recompiling on a real machine. In other words, if the virtual machine is isolated in the system, the hypervisor layer can be removed, leaving only the layers in rings 2 and 3. For this, it is sufficient to reallocate the MMU write instructions to ring 2.
Claims
1. A processor having multiple protection rings and including a protection ring management system, wherein, The ownership of privileged hardware resources to the protection ring is defined by a programmable ownership table; The programmable ownership table is represented by one or more ownership registers, each ownership register including a field whose location corresponds to an identifier of a privileged hardware resource defined by the processor specification and whose content identifies the corresponding protection ring allocated to the privileged hardware resource. Specifically, the protection ring or higher-privileged protection ring allocated to the resource is allowed to access each privileged hardware resource, and The protection ring management system is configured to, when the currently executing program accesses privileged hardware resources: The current protection ring identified in the processor status register is compared with the protection ring identified by the field corresponding to the privileged hardware resource being accessed; A privilege trap is triggered when the privilege of the current protection ring is lower than the privilege of the protection ring identified by the field; and The processing of the privileged trap is transferred to the protection ring identified by the field.
2. The processor according to claim 1, wherein, When the processor is started, the programmable ownership table is programmed by software.
3. The processor according to claim 1, wherein, The programmable ownership table also assigns exceptions to protection rings, and the protection ring management system is configured to respond to exceptions by transferring the handling of the exception to a ring programmed for the exception in the programmable ownership table.
4. The processor according to claim 1, wherein, The privileged hardware resources include at least a designated execution unit and a processor configuration register, and executing the corresponding instructions is considered an access to the designated execution unit.
5. The processor according to claim 3, comprising: A hardware unit capable of triggering an exception when an event occurs during program execution by the processor; The processor status register identifies the current protection ring applied to the currently executing program; The programmable ownership register that embodies the programmable ownership table; For each protection ring, a corresponding protection ring and a processor state backup register with corresponding permissions are defined; as well as An exception handling circuit is configured to, when an exception is triggered: - Index the ownership register with the identifier generated along with the exception to specify the corresponding protection ring; - Exchange the contents of the processor status register with the contents of the status backup register specified by the ownership register; as well as - Transfer the current program to the exception handler, whereby the handler executes in a protection ring defined by the new contents of the processor status register.
6. The processor according to claim 5, comprising: A program counter, which identifies the address of the instruction currently being executed by the processor; For each protection ring, the corresponding backup register of the program counter; For each protection ring, an exception vector is assigned to the address of the exception handler for that protection ring. The exception handling circuit is also configured to: when an exception is triggered: The contents of the program counter are stored in the program counter backup register specified by the ownership register; and The address provided by the exception vector specified by the ownership register is written to the program counter.
7. The processor of claim 5, comprising a system-register-write instruction, the instruction being implemented by the processor to write the sum of the current ring level and a parameter representing the relative level of the instruction to an ownership register identified by the instruction.
8. The processor according to claim 5, wherein, The exception includes a horizontal interrupt, and the ownership register is programmed to assign the horizontal interrupt to the same protection ring as the program running when the interrupt is triggered.
9. A method for managing a protection ring in a processor, comprising the following steps: The ownership table is programmed to assign privileged hardware resources to protection rings. The ownership table is represented by one or more ownership registers, which include an identifier whose location corresponds to a privileged hardware resource as defined by the processor specification and whose contents identify the corresponding protection ring assigned to the privileged hardware resource. Execute the current program in the current protection ring identified in the processor status register; When the current program accesses privileged hardware resources, the field corresponding to the identifier of the accessed privileged hardware resource is found in the ownership table, and the current protection ring is compared with the protection ring identified by the field. A privilege trap is triggered when the privilege of the current protection ring is lower than the privilege of the protection ring identified by the field. as well as The privileged trap is processed by a processor running in the protection ring identified by the field.
10. The method of claim 9, further comprising programming the ownership table by software executed when the processor is started.
11. The method according to claim 9, comprising the following steps: For each protection ring, define the protection ring and its corresponding permissions in the corresponding processor state backup register; as well as When the privilege trap is triggered, the contents of the processor status register are exchanged with the contents of the status backup register identified by the ownership table.
12. The method according to claim 9, comprising the following steps: Run the host management program in the first ring; A guest operating system runs in a second ring with lower privileges than the first ring, wherein the guest operating system is designed to manage translation tables for converting virtual addresses to physical addresses; The user program runs in a third ring with lower privileges than the second ring, wherein the user program is designed to use a virtual address applied to the translation table; In the ownership table, the unmapped trap triggered when the translation table fails to translate the virtual address used by the user program is assigned to the second ring; In the ownership table, the translation table is assigned as a privileged resource to the first ring, thereby triggering a privilege trap if a lower-privileged ring attempts to write to the translation table; and Configure the privileged trap processor, executed by the hypervisor in the first ring, to update the translation table.
Citation Information
Patent Citations
Multi-Ring Shared, Traversable, and Dynamic Advanced Database
US20190163626A1
Reentrant protected mode kernel using virtual 8086 mode interrupt service routines
US5303378A
