Apparatus and method for efficiently managing and handling shadow stacks - Patents.com
A shadow stack mechanism with specific instructions and validation ensures robust protection against ROP attacks, maintaining security and performance in diverse processor environments.
Patent Information
- Application Number
- JP2020196091
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2020-03-28
- Filing Date
- 2020-11-26
- Publication Date
- 2024-09-18
- Estimated Expiration
- 2040-11-26
AI Technical Summary
Existing methods for preventing Return-Oriented Programming (ROP) attacks, such as shadow stacks and canary values, often require significant performance overhead or modifications to guest software, and processor architectures with inaccessible call stacks are not universally applicable.
Implementing a shadow stack mechanism that includes a separate stack to store control information, using specific instructions to protect it from tampering during privilege level transitions, and employing a shadow stack pointer validation system to ensure stack integrity.
Enhances security against ROP attacks by maintaining stack integrity without performance degradation and without requiring software modifications, ensuring reliable protection across various processor architectures.
Smart Images

Figure 0007553019000013 
Figure 0007553019000018 
Figure 0007553019000021
Abstract
Description
[Technical field]
[0001] FIELD OF THE DISCLOSURE
[0002] Embodiments of the present invention relate generally to the field of computer processors, and more particularly to an apparatus and method for efficiently managing and handling shadow stacks. [Background technology]
[0002] Return-oriented programming (ROP) exploits are an increasingly common form of malicious software (malware) that can circumvent certain defenses that mark memory locations as non-executable. ROP exploits work by stringing together many existing segments of executable code (called gadgets), each of which ends with a "return" instruction. Each ROP gadget is typically short and typically does not correspond to existing steps in the executable code or even existing instruction boundaries. The attacker builds a malicious stack that contains a series of return addresses that point to the desired sequence of the gadgets. ROP exploits are performed by tricking a computer's processor into running software using a malicious stack instead of the legitimate system stack. For example, a malicious stack can occur by corrupting the stack, using a buffer overflow exploit, pivoting to a new stack, or otherwise corrupting the system stack.
[0003] Exploitation of certain ROPs can be prevented by maintaining a "shadow stack" in parallel with the normal system stack (also known as the "legacy stack"). The shadow stack keeps a copy of the legacy stack in memory that is inaccessible to normal software and may be used to determine if the legacy stack has been tampered with by malware. Shadow stacks can be implemented using binary instrumentation, although in some usages this can result in significant performance degradation.
[0004] Other measures are available to prevent exploitation of ROP. For example, a "canary" value can be inserted in the stack near the return address and monitored for modification. As another example, a "control transfer end instruction" can be inserted into the binary to specifically identify a legitimate return target. However, such measures may require recompiling or otherwise modifying the guest software. Additionally, certain processor architectures may provide call stacks that are inaccessible to certain software. For example, certain microcontrollers may maintain call stacks that are inaccessible to software. As another example, certain processor architectures may maintain call stack information in a separate memory area from other stack values, such as automatic variables.
[0005] The present invention can be better understood from the following detailed description taken in conjunction with the following drawings. [Brief description of the drawings]
[0006] [Figure 1A] FIG. 2 is a block diagram illustrating a generic vector friendly instruction format and its instruction templates according to an embodiment of the present invention. [Figure 1B] FIG. 2 is a block diagram illustrating a generic vector friendly instruction format and its instruction templates according to an embodiment of the present invention.
[0007] [Figure 2A] FIG. 2 is a block diagram illustrating an exemplary VEX instruction format according to an embodiment of the present invention. [Figure 2B] FIG. 2 is a block diagram illustrating an exemplary VEX instruction format according to an embodiment of the present invention. [Figure 2C] FIG. 2 is a block diagram illustrating an exemplary VEX instruction format according to an embodiment of the present invention.
[0008] [Diagram 3] FIG. 2 is a block diagram of a register architecture according to one embodiment of the present invention.
[0009] [Figure 4A] FIG. 2 is a block diagram illustrating both an exemplary in-order fetch, decode, and retire pipeline and an exemplary register renaming, out-of-order issue / execution pipeline, in accordance with an embodiment of the present invention.
[0010] [Figure 4B] FIG. 2 is a block diagram illustrating both an exemplary embodiment of an in-order fetch, decode, retire core and an exemplary register renaming, out-of-order issue / execution architecture core included in a processor in accordance with an embodiment of the present invention.
[0011] [Figure 5A] FIG. 2 is a block diagram of a single processor core with connections to an on-die interconnect network.
[0012] [Figure 5B] 5B illustrates an expanded view of a portion of the processor core of FIG. 5A in accordance with an embodiment of the present invention.
[0013] [Figure 6] 1A-1C are block diagrams of single-core and multi-core processors with integrated memory controllers and graphics, according to embodiments of the present invention.
[0014] [Figure 7] 1 shows a block diagram of a system according to one embodiment of the present invention.
[0015] [Figure 8] FIG. 2 shows a block diagram of a second system according to an embodiment of the present invention.
[0016] [Figure 9] FIG. 13 shows a block diagram of a third system according to an embodiment of the present invention.
[0017] [Figure 10]1 illustrates a block diagram of a system on a chip (SoC) in accordance with one embodiment of the present invention.
[0018] [Figure 11] 1 shows a block diagram contrasting the use of a software instruction converter to convert binary instructions in a source instruction set to binary instructions in a target instruction set in accordance with an embodiment of the present invention;
[0019] [Figure 12] 1 illustrates a processing device with a shadow stack, according to one embodiment.
[0020] [Figure 13] 1 illustrates shadow stack pointer management according to one embodiment.
[0021] [Figure 14] 1 illustrates one embodiment of processing an SSP based on an interrupt.
[0022] [Figure 15] 1 illustrates additional details related to shadow stack pointer management, according to one embodiment.
[0023] [Figure 16] 1 illustrates an embodiment in which the SSP is selected and verified using atomic or non-atomic operations.
[0024] [Figure 17] 1 illustrates one embodiment of a verification / validation operation.
[0025] [Figure 18] 1 illustrates a method according to one embodiment of the present invention.
[0026] [Figure 19] 13 shows additional details of a method for selecting between atomic and non-atomic validation and busy check operations. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS
[0027] In the following description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the invention described below. However, it will be apparent to one skilled in the art that embodiments of the invention may be practiced without some of these specific details. In other instances, well-known structures and devices are shown in block diagram form in order to avoid obscuring the principles underlying embodiments of the invention.
[0028] Exemplary Processor Architectures, Instruction Formats, and Data Formats An instruction set includes one or more instruction formats. A particular instruction format defines various fields (number of bits, bit positions) to specify, among other things, the operation to be performed (opcode) and the operands on which to perform that operation. Some instruction formats are further subdivided by the definition of instruction templates (or sub-formats). For example, instruction templates for a particular instruction format may be defined to have different subsets of the instruction format's fields (fields included are typically in the same order, but fewer fields are included so that at least some bit positions are different) and / or to have specific fields that are interpreted differently. Thus, each instruction of the ISA is expressed using a specified instruction format (and, if defined, in a specified one of the instruction templates for that instruction format) and includes fields for specifying an operation and operands. For example, an exemplary ADD instruction has an instruction format that includes a particular opcode and an opcode field for specifying that opcode and operand fields for selecting operands (source1 / destination and source2), and when this ADD instruction occurs in the instruction stream, the operand field that selects the particular operand has a particular content.
[0029] Embodiments of the instructions described herein may be implemented in different formats. Further, exemplary systems, architectures, and pipelines are detailed below. Embodiments of the instructions may be executed on such systems, architectures, and pipelines, but are not limited to those detailed.
[0030] Generic Vector Instruction Format
[0031] The vector friendly instruction format is an instruction format that is suitable for vector instructions (e.g., has certain fields that are specific to vector operations). Although embodiments are described in which both vector and scalar operations are supported via the vector friendly instruction format, alternative embodiments use only vector operations via the vector friendly instruction format.
[0032] 1A-1B are block diagrams illustrating a generic vector friendly instruction format and its instruction templates according to an embodiment of the present invention. FIG. 1A is a block diagram illustrating a generic vector friendly instruction format and its class A instruction templates according to an embodiment of the present invention. Meanwhile, FIG. 1B is a block diagram illustrating a generic vector friendly instruction format and its class B instruction templates according to an embodiment of the present invention. Specifically, a generic vector friendly instruction format 100 has class A and class B instruction templates defined, neither of which includes a memory access 105 instruction template and a memory access 120 instruction template. The term generic in the context of a vector friendly instruction format refers to an instruction format that is not associated with a specific instruction set.
[0033] While embodiments of the invention are described in which the vector friendly instruction format supports vector operand lengths (or sizes) of 64 bytes with data element widths (or sizes) of 32 bits (4 bytes) or 64 bits (8 bytes) (so a 64 byte vector consists of 16 doubleword sized elements, or 8 quadword sized elements), vector operand lengths (or sizes) of 64 bytes with data element widths (or sizes) of 16 bits (2 bytes) or 8 bits (1 byte), 32 bits (4 bytes), 64 bits (8 bytes), 16 bits (2 bytes), or In one embodiment, the vector operand length (or size) may be 32 bytes with a data element width (or size) of 32 bits (4 bytes), 64 bits (8 bytes), 16 bits (2 bytes), or 16 bytes with a data element width (or size) of 8 bits (1 byte); alternative embodiments may support more, fewer, and / or different vector operand sizes (e.g., 256 byte vector operands) with more, fewer, or different data element widths (e.g., a data element width of 128 bits (16 byte).
[0034] The instruction templates of class A in Figure 1A include the following: 1) within the instruction templates without memory access 105, an instruction template for full round control type operation with no memory access 110 and an instruction template for data transform type operation with no memory access 115 are shown, and 2) within the instruction templates with memory access 120, an instruction template for with temporary memory access 125 and an instruction template for with non-temporal memory access 130 are shown. The instruction templates of class B in Figure 1B include the following: 1) within the instruction templates without memory access 105, an instruction template for no memory access, write mask control, partial round control type operation 112 and an instruction template for no memory access, write mask control, VSIZE type operation 117 are shown, and 2) within the instruction templates with memory access 120, an instruction template for memory access, write mask control 127 is shown.
[0035] The generic vector friendly instruction format 100 includes the following fields, listed below in the order shown in FIGS. 1A-1B:
[0036] The format field 140, and thus the particular value of this field (the instruction format identifier value), uniquely identifies the vector friendly instruction format and therefore the occurrence of instructions of the vector friendly instruction format in an instruction stream. As such, this field is optional in the sense that it is not required for instruction sets that only have a generic vector friendly instruction format.
[0037] The basic operation field 142, whose contents distinguish various basic operations.
[0038] The register index field 144, whose contents specify the location of the source and destination operands in registers or in memory, either directly or through address generation. They contain a sufficient number of bits to select N registers from a PxQ (e.g., 32x512, 16x128, 32x1024, 64x1024) register file. In one embodiment, N can be up to three source and one destination registers, although alternative embodiments may support more or fewer source and destination registers (e.g., may support up to two sources where one of these sources also serves as a destination, may support up to three sources where one of these sources also serves as a destination, may support up to two sources and one destination).
[0039] The qualifier field 146 distinguishes occurrences of general vector instruction format instructions whose contents specify a memory access from those that do not; that is, between a no memory access 105 instruction template and a with memory access 120 instruction template. Operations with memory access read and / or write the memory hierarchy (possibly using values in registers to specify source and / or destination addresses), while operations without memory access do not (e.g., the source and destination are registers). In one embodiment, this field also selects between three different ways to perform memory address calculations, although alternative embodiments may support more, fewer, or different ways to perform memory address calculations.
[0040] The extended operation field 150, whose contents distinguish any one of a variety of different operations to be performed in addition to the basic operation, is context specific. In one embodiment of the invention, this field is divided into a class field 168, an alpha field 152, and a beta field 154. The extended operation field 150 allows a common group of operations to be performed with a single instruction rather than two, three, or four instructions.
[0041] The scale field 160 allows the content of the index field to be scaled for memory address generation (e.g., 2 scale *For address generation using index+base).
[0042] The displacement field 162A is a field whose contents are used as part of memory address generation (e.g., 2 scale *For address generation using index+base+displacement).
[0043] The displacement factor field 162B (note that the juxtaposition of the displacement field 162A directly above the displacement factor field 162B indicates that one or the other may be used) specifies the displacement factor whose contents are used as part of the address generation. It specifies a displacement factor that is scaled by the size (N) of the memory access, where N is the number of bytes in the memory access (e.g., 2 scale *For address generation using index+base+scaled displacement). Redundant low-order bits are ignored so that the contents of the displacement factor field are multiplied by the total size of the memory operands (N) to generate the final displacement used to calculate the effective address. The value of N is determined by the processor hardware at run-time based on the complete opcode field 174 (described later herein) and data operation field 154C. The displacement field 162A and displacement factor field 162B are optional in the sense that they are not used for the no memory access 105 instruction template and / or different embodiments implement only one of the two or none at all.
[0044] Data element width field 164 - its contents distinguish whether any one of several data element widths should be used (in some embodiments, for all instructions; in other embodiments, only for some instructions). This field is optional in the sense that it is not needed if only one data element width is supported or if data element widths are supported using some aspect of the opcode.
[0045] The write mask field 170 controls whether the position of a data element in the destination vector operand reflects the result of the basic and extended operations, based on the position of each data element. Class A instruction templates support merge write masking, and class B instruction templates support both merge write masking and zero justification write masking. When merging, the vector mask allows a set of elements in the destination to be protected from updates during the execution of the operation (specified by the basic and extended operations). In another embodiment, the old value of each element in the destination whose corresponding mask bit has a value of 0 is preserved. In contrast, a zeroing vector mask allows a set of elements in the destination to be zeroed during the execution of the operation (specified by the basic and extended operations). In one embodiment, an element in the destination is set to 0 if its corresponding mask bit has a value of 0. A subset of this functionality is the ability to control the vector length of the operation being performed (i.e., the span of elements that are modified from start to finish). However, the elements modified need not be contiguous. Thus, the write mask field 170 allows partial vector operations, including loads, stores, arithmetic, logical, etc. Although an embodiment of the invention is described in which the write mask field 170 contents select one of several write mask registers that contain the write mask to be used (and thus the write mask field 170 contents indirectly identify the masking to be performed), alternative embodiments instead or in addition allow the write mask field 170 contents to directly specify the masking to be performed.
[0046] The content of the immediate field 172 allows the specification of an immediate. This field is optional in the sense that it is not present in implementations of the general vector friendly format that do not support immediates, and is not present in instructions that do not use immediates.
[0047] The class field 168 has a content that distinguishes between different classes of instructions. With reference to FIGS. 1A-1B, the content of this field selects between class A and class B instructions. In FIGS. 1A-1B, a rounded box is used to indicate that a particular value is present in the field (e.g., class A 168A and class B 168B for class field 168 in FIGS. 1A-1B).
[0048] Class A instruction template
[0049] For class A no memory access 105 instruction templates, the alpha field 152 is interpreted as an RS field 152A whose content distinguishes which of the different extended operation types is to be performed (e.g., round 152A.1) and data transform 152A.2 are specified for the no memory access, round type operation 110 and no memory access, data transform type operation 115 instruction templates, respectively, while the beta field 154 indicates which of the specified types of operations is to be performed. For no memory access 105 instruction templates, the scale field 160, displacement field 162A, and displacement scale field 162B are not present.
[0050] Instruction template without memory access - full round control type operation
[0051] In the instruction template for full round control type operation without memory access 110, the beta field 154 is interpreted as a round control field 154A whose contents provide static rounding. In the described embodiment of the invention, the round control field 154A includes a suppression of all floating-point exceptions (SAE) field 156 and a round operation control field 158, although alternative embodiments may encode both of these concepts in the same field or may have only one or these other concepts / fields (e.g., may have only the round operation control field 158).
[0052] SAE field 156 distinguishes whether its content disables exception event reporting. If the content of SAE field 156 indicates that suppression is enabled, then the particular instruction will not report any kind of floating-point exception flags and will not raise any floating-point exception handlers.
[0053] The round operation control field 158 distinguishes whether its contents perform one of a group of rounding operations (e.g., round up, round down, round towards zero, and round to nearest). Thus, the round operation control field 158 allows for the changing of the rounding mode on a per-instruction basis. In one embodiment of the present invention in which the processor includes a control register for specifying the rounding mode, the contents of the round operation control field 150 overwrite that register value.
[0054] Instruction template without memory access - Data transformation type operation
[0055] In the instruction template for a data transform type operation without memory access 115, the beta field 154 is interpreted as a data transform field 154B, whose content distinguishes whether any one of a number of data transforms should be performed (e.g., no data transform, swizzle, broadcast).
[0056] For class A with memory access 120 instruction templates, the alpha field 152 is interpreted as an eviction hint field 152B, whose content distinguishes whether one of the eviction hints is used (in FIG. 1A, temporal 152B.1 and non-temporal 152B.2 are specified for the memory access, temporal 125 instruction template and the memory access, non-temporal 130 instruction template, respectively), while the beta field 154 is interpreted as a data manipulation field 154C, whose content distinguishes whether one of the eviction hints is used. A number of data manipulation operations (also called primitives) are performed (e.g., no operation, broadcast, source upconversion, destination downconversion, etc.). The with memory access 120 instruction templates include a scale field 160 and, optionally, a displacement field 162A or a displacement scale field 162B.
[0057] Vector memory instructions perform vector loads from memory and vector stores to memory, with support for transformations. Like regular vector instructions, vector memory instructions transfer data to and from memory on a data element by data element basis. The elements actually transferred depend on the contents of the vector mask selected as the writemask.
[0058] Instruction Template with Memory Access - Temporal
[0059] Temporary data is data that is likely to be reused long enough to benefit from caching, however this is a hint and different processors may implement it in different ways, including ignoring the hint entirely.
[0060] Instruction Templates with Memory Access - Non-Temporal
[0061] Non-temporal data is data that is unlikely to be reused soon enough to benefit from being cached in a first level cache and should be prioritized for eviction, although this is a hint and different processors may implement it in different ways, including ignoring the hint entirely.
[0062] Class B instruction template
[0063] For class B instruction templates, the alpha field 152 is interpreted as a write mask control (Z) field 152C, whose content distinguishes whether the write masking controlled by the write mask field 170 should be merging or zeroing.
[0064] For no memory access 105 instruction templates of class B, a portion of the beta field 154 is interpreted as an RL field 157A, whose content distinguishes which of the different extended operation types should be performed (e.g., round 157A.1 and vector length (VSIZE) 157A.2 are specified for the no memory access, writemask control, partial round control type operation 112 instruction template and the no memory access, writemask control, VSIZE type operation 117 instruction template, respectively), while the remaining portion of the beta field 154 distinguishes which of the specified types of operation should be performed. In the no memory access 105 instruction template, the scale field 160, the displacement field 162A, and the displacement scale field 162B are not present.
[0065] For the no memory access, write mask control, partial round control type operation 110 instruction template, the remainder of the beta field 154 is interpreted as the round operation control field 159A and exception event reporting is disabled (the given instruction does not report any kind of floating-point exception flags and does not raise any floating-point exception handlers).
[0066] Round operation control field 159A - similar to round operation control field 158, its content distinguishes between performing one of a group of rounding operations (e.g., round up, round down, round towards zero, round to nearest). Thus, round operation control field 159A allows for changing the rounding mode on a per-instruction basis. In one embodiment of the invention where the processor includes a control register for specifying the rounding mode, the content of round operation control field 150 overwrites that register value.
[0067] In the no memory access, write mask control, VSIZE type operation 117 instruction template, the remainder of the beta field 154 is interpreted as a vector length field 159B, whose content distinguishes whether any one of several data vector lengths is executed (e.g., 128, 256, or 512 bytes).
[0068] For instruction templates with memory access 120 of class B, part of the beta field 154 is interpreted as a broadcast field 157B, whose content distinguishes whether a broadcast type data manipulation operation is performed, and the remaining part of the beta field 154 is interpreted as a vector length field 159B. Instruction templates with memory access 120 include a scale field 160 and, optionally, a displacement field 162A or a displacement scale field 162B.
[0069] For generic vector friendly instruction format 100, a complete opcode field 174 is shown, including format field 140, basic operation field 142, and data element width field 164. While one embodiment is shown in which complete opcode field 174 includes all of these fields, complete opcode field 174 may include less than all of these fields in embodiments that do not support all of them. Complete opcode field 174 provides an operation code (opcode).
[0070] The extended operation field 150, data element width field 164, and writemask field 170 allow these characteristics to be specified on a per-instruction basis in the generic vector friendly instruction format.
[0071] The combination of the write mask field and the data element width field creates a typed instruction in that masks can be applied based on different data element widths.
[0072] Different instruction templates in class A and class B are useful in different situations. In some embodiments of the invention, different processors or different cores within a processor may support only class A, only class B, or both classes. For example, a high performance general out-of-order core targeted for general purpose computing may support only class B, a core targeted primarily for graphics and / or scientific (throughput) computing may support only class A, and a core for both may support both (of course, a core having some combination of templates and instructions from both classes, but not all templates and instructions from both classes, is within the scope of the invention). Also, a single processor may include multiple cores, all of which support the same class, or different cores support different classes. For example, in a processor with separate graphics and general purpose cores, one of the graphics cores targeted primarily for graphics and / or scientific computing may support only class A, and one or more of the general purpose cores may be high performance general purpose cores using out-of-order execution and register renaming targeted for general purpose computing supporting only class B. Another processor without a separate graphics core may include another general purpose sequential or out-of-order core supporting both class A and class B. Of course, features from one class may be implemented in other classes in different embodiments of the invention. Programs written in high-level languages are converted (e.g., just-in-time or statically compiled) into various executable formats such as 1) a format that contains only instructions of classes supported by the target processor for execution, or 2) a format that has alternative routines written using various combinations of instructions from all classes, with control flow code that selects which routine to execute based on the instructions supported by the processor currently executing the code.
[0073] VEX Instruction Format
[0074] VEX encoding allows instructions to have more than two operands, allowing SIMD vector registers to be longer than 28 bits. Using the VEX prefix provides a three-operand (or more) syntax. For example, previous two-operand instructions performed operations such as A=A+B that overwrite the source operand. Using the VEX prefix allows non-destructive operations such as A=B+C to be performed on the operands.
[0075] Figure 2A shows an example AVX instruction format including a VEX prefix 202, an actual opcode field 230, a Mod R / M byte 240, a SIB byte 250, a displacement field 262, and an IMM8 272. Figure 2B shows which fields from Figure 2A make up the complete opcode field 274 and the base operation field 241. Figure 2C shows which fields from Figure 2A make up the register index field 244.
[0076] The VEX prefix (bytes 0-2) 202 is encoded in a three-byte format. The first byte is a format field 290 (VEX byte 0, bits [7:0]) that contains an explicit C4 byte value (a unique value used to distinguish C4 instruction formats). The second and third bytes (VEX bytes 1-2) contain several bit fields that provide specific functionality. Specifically, the REX field 205 (VEX byte 1, bits [7-5]) is composed of the VEX.R bit field (VEX byte 1, bits [7]-R), the VEX.X bit field (VEX byte 1, bits [6]-X), and the VEX.B bit field (VEX byte 1, bits [5]-B). The other fields of the instruction encode the lower three bits of the register index (rrr, xxx, and bbb) as known in the art, so that Rrrr, Xxxx, and Bbbb are formed by adding VEX.R, VEX.X, and VEX.B. The opcode map field 215 (VEX byte 1, bits [4:0]-mmmmm) contains contents that encode the implied preceding opcode byte. The W field 264 (VEX byte 2, bits [7]-W) is represented by the notation VEX.W and serves different functions depending on the instruction. The roles of VEX.vvvv 220 (VEX byte 2, bits [6:3]-vvvv) include: 1) VEX.vvvv encodes the first source register operand specified in inverted (one's complement) form and is valid for instructions with two or more source operands, 2) VEX.vvvv encodes the destination register operand specified in one's complement form for certain vector shifts, or 3) VEX.vvvv does not encode an operand, the field is reserved and must contain 1111b. The VEX.L 268 size field (VEX byte 2, bit [2]-L) = 0 indicates a 28-bit vector, and VEX.L = 1 indicates a 256-bit vector. The prefix encoding field 225 (VEX byte 2, bits [1:0]-pp) provides additional bits to the base operation field 241.
[0077] The actual opcode field 230 (byte 3), also called the opcode byte, specifies part of the opcode.
[0078] MOD R / M field 240 (byte 4) includes MOD field 242 (bits [7-6]), register index field 244 (bits [5-3]), and R / M field 246 (bits [2-0]). The role of register index field 244 may include the following: encoding either a destination register operand or a source register operand (rrr of Rrrr), or being treated as an opcode extension and not used to encode an instruction operand. The role of R / M field 246 may include the following: encoding an instruction operand that references a memory address, or encoding either a destination register operand or a source register operand.
[0079] Scale, Index, Base (SIB) - The contents of the scale field 250 (byte 5) contain the SS 252 (bits [7-6]) used to generate memory addresses. The contents of SIB.xxx 254 (bits [5-3]) and SIB.bbb 256 (bits [2-0]) are pre-referenced with respect to the register indices Xxxx and Bbbb.
[0080] The displacement field 262 and the immediate field (IMM8) 272 contain data.
[0081] Exemplary Register Architecture
[0082] 3 is a block diagram of a register architecture 300 according to one embodiment of the present invention. In the embodiment shown, there are 32 vector registers 310 that are 512 bits wide. These registers are referenced as zmm0 through zmm31. The lower 256 bits of the lower six zmm registers are overlapped into registers ymm0-15. The lower 128 bits of the lower six zmm registers (the lower 128 bits of the ymm registers) are overlapped into registers xmm0-15.
[0083] General purpose registers 325, in the illustrated embodiment, are sixteen 64-bit general purpose registers that are used in conjunction with existing x86 addressing modes to address memory operands. These registers are referenced by the names RAX, RBX, RCX, RDX, RBP, RSI, RDI, RSP, and R8 through R15.
[0084] Scalar floating-point stack register file (x87 stack) 345, in the illustrated embodiment, has MMX packed integer flat register file 350 aliased onto it; the x87 stack is an eight-element stack used to perform scalar floating-point operations on 32 / 64 / 80-bit floating-point data using the x87 instruction set extensions, while the MMX registers are used to perform operations on 64-bit packed integer data and to hold operands for some operations performed between MMX and XMM registers.
[0085] Alternate embodiments of the invention may use wider or narrower registers. Additionally, alternative embodiments of the invention may use more, fewer, or different register files and registers.
[0086] Exemplary Core Architectures, Processors, and Computer Architectures
[0087] Processor cores can be implemented in different ways, for different purposes, and with different processors. For example, implementations of such cores may include the following: 1) a general-purpose sequential core intended for general-purpose computing; 2) a high-performance general out-of-order core intended for general-purpose computing; 3) a special-purpose core intended primarily for graphics and / or scientific (throughput) computing. Different processor implementations may include the following: 1) a CPU including one or more general sequential cores intended for general-purpose computing and / or one or more general out-of-order cores intended for general-purpose computing; 2) a coprocessor including one or more special-purpose cores intended primarily for graphics and / or scientific (throughput). Such different processors lead to different computer system architectures including: 1) a coprocessor on a separate chip from the CPU; 2) a coprocessor on a separate die in the same package as the CPU; 3) a coprocessor on the same die as the CPU (in which case such coprocessors may be referred to as special-purpose logic, such as integrated graphics or scientific (throughput) logic, or special-purpose cores); 4) a system on a chip that may include the described CPU (sometimes referred to as an application core or application processor), the coprocessor described above, and additional functionality on the same die. Next, an exemplary core architecture is described, followed by an exemplary processor and computer architecture. Circuits (units) including exemplary cores, processors, etc. are described in detail herein.
[0088] Exemplary Core Architecture
[0089] FIG. 4A is a block diagram illustrating both an exemplary sequential pipeline and an exemplary register renaming, out-of-order issue / execution pipeline, according to an embodiment of the present invention. FIG. 4B is a block diagram illustrating both an exemplary embodiment of a sequential architecture core and an exemplary register renaming, out-of-order issue / execution architecture core included in a processor, according to an embodiment of the present invention. The solid lined boxes in FIGS. 4A-B illustrate the sequential pipeline and sequential core, with the optional addition of dashed lined boxes illustrating the register renaming, out-of-order issue / execution pipeline and core. The out-of-order aspects are described with the understanding that the sequential aspects are a subset of the out-of-order aspects.
[0090] In FIG. 4A , the processor pipeline 400 includes a fetch stage 402, a length decode stage 404, a decode stage 406, an allocation stage 408, a renaming stage 410, a scheduling (also known as dispatch or issue) stage 412, a register read / memory read stage 414, an execution stage 416, a writeback / memory write stage 418, an exception handling stage 422, and a commit stage 424.
[0091] 4B shows a processor core 490 including a front end unit 430 coupled to an execution engine unit 450, both of which are coupled to a memory unit 470. Core 490 may be a reduced instruction set computing (RISC) core, a complex instruction set computing (CISC) core, a very long instruction word (VLIW) core, or a hybrid or alternative core type. As yet another option, core 490 may be a special-purpose core, such as, for example, a network or communication core, a compression engine, a co-processor core, a general purpose computing graphics processing unit (GPGPU) core, a graphics core, etc.
[0092] The front-end unit 430 includes a branch prediction unit 432 coupled to an instruction cache unit 434 coupled to an instruction translation lookaside buffer (TLB) 436 coupled to an instruction fetch unit 438 coupled to a decode unit 440. The decode unit 440 (or decode section) may decode instructions and generate as output one or more micro-operations, microcode entry points, microinstructions, other instructions, or other control signals that are otherwise decoded or otherwise reflected from the original instruction. The decode unit 440 may be implemented using a variety of different mechanisms. Examples of suitable mechanisms include, but are not limited to, look-up tables, hardware implementations, programmable logic arrays (PLAs), microcode read-only memories (ROMs), and the like. In one embodiment, the core 490 includes a microcode ROM or other medium that stores microcode for particular macro-instructions (e.g., within the decode unit 440 or otherwise within the front-end unit 430). The decode unit 440 is coupled to a renaming / allocator unit 452 in the execution engine unit 450.
[0093] The execution engine units 450 include a renaming / allocator unit 452 coupled to a retirement unit 454 and a set of one or more scheduler units 456. The scheduler units 456 represent any number of different schedulers, including reservation stations, central instruction windows, etc. The scheduler units 456 are coupled to physical register file units 458. Each of the physical register file units 458 represents one or more physical register files, the different files storing one or more different data formats, such as scalar integer, scalar floating point, packed integer, packed floating point, vector integer, vector floating point, status (e.g., an instruction pointer, which is the address of the next instruction to be executed). In one embodiment, the physical register file units 458 include a vector register unit and a scalar register unit. These register units may provide architectural vector registers, vector mask registers, and general purpose registers. The physical register file unit 458 overlaps with the retirement unit 454 to illustrate various ways in which register renaming and out-of-order execution can be implemented (e.g., using a reorder buffer and retirement register file, using a future file, history buffer, and retirement register file, using a register map and pool of registers, etc.). The retirement unit 454 and the physical register file unit 458 are coupled to an execution cluster 460. The execution cluster 460 includes a set of one or more execution units 462 and a set of one or more memory access units 464. The execution units 462 can perform various operations (e.g., shift, add, subtract, multiply) and on various types of data (e.g., scalar floating point, packed integer, packed floating point, vector integer, vector floating point). Some embodiments may include several execution units dedicated to a particular function or set of functions, while other embodiments may include only one execution unit or multiple execution units that all perform all functions.Scheduler unit 456, physical register file unit 458, and execution cluster 460 are shown as possibly multiple because particular embodiments create separate pipelines for particular types of data / operations (e.g., a scalar integer pipeline, a scalar floating point / packed integer / packed floating point / vector integer / vector floating point pipeline, and / or each with its own scheduler unit, physical register file unit, and / or memory access pipeline execution cluster - and in the case of a separate memory access pipeline, particular embodiments are implemented where only the execution cluster of this pipeline has a memory access unit 464). It should also be understood that if separate pipelines are used, one or more of these pipelines may be out-of-order issue / execution and the rest out-of-order.
[0094] The set of memory access units 464 are coupled to a memory unit 470, which includes a data TLB unit 472 coupled to a data cache unit 474 coupled to a level 2 (L2) cache unit 476. In an exemplary embodiment, the memory access units 464 may include a load unit, a store address unit, and a store data unit, each of which is coupled to the data TLB unit 472 in the memory unit 470. The instruction cache unit 434 is further coupled to a level 2 (L2) cache unit 476 in the memory unit 470. The L2 cache unit 476 is coupled to one or more other levels of cache and ultimately to a main memory.
[0095] As an example, an exemplary register renaming, out-of-order issue / execution core architecture may implement pipeline 400 as follows: 1) instruction fetch 438 performs fetch and length decode stages 402 and 404; 2) decode unit 440 performs decode stage 406; 3) renaming / allocator unit 452 performs allocation stage 408 and renaming stage 410; 4) scheduler unit 456 performs schedule stage 412; 5) physical register file unit 458 and memory unit 470 perform register read / memory read stage 414; execution cluster 460 performs execution stage 416; 6) memory unit 470 and physical register file unit 458 perform writeback / memory write stage 418; 7) various units may be involved in exception handling stage 422; and 8) retirement unit 454 and physical register file unit 458 perform commit stage 424.
[0096] Core 490 may support one or more instruction sets (e.g., the x86 instruction set (including some extensions added in newer versions), the MIPS instruction set from MIPS Technologies of Sunnyvale, Calif., the ARM instruction set (including optional additional extensions such as NEON) from ARM Holdings of Sunnyvale, Calif.), including the instructions described herein. In one embodiment, core 490 includes logic to support packed data instruction set extensions (e.g., AVX1, AVX2), thereby enabling it to perform operations using packed data used by many multimedia applications.
[0097] It should be understood that a core may support multithreading (executing two or more parallel sets of operations or threads) and may do so in a variety of ways, including time-sliced multithreading, simultaneous multithreading (where a single physical core provides a logical core for each thread that the physical core is simultaneously multithreaded on), or a combination thereof (e.g., time-sliced fetch and decode followed by simultaneous multithreading such as Intel® Hyper-Threading Technology).
[0098] Although register renaming is described in the context of out-of-order execution, it should be understood that register renaming may be used in sequential architectures. The illustrated embodiment of the processor also includes separate instruction and data cache units 434 / 474 and a shared L2 cache unit 476, although alternative embodiments may have a single internal cache for both instructions and data, such as, for example, a level 1 (L1) internal cache, or multiple levels of internal cache. In some embodiments, the system may include a combination of internal and external caches that are external to the core and / or processor. Alternatively, all caches may be external to the core and / or processor.
[0099] Specific Exemplary Sequential Core Architecture
[0100] 5A-5B show block diagrams of a more specific exemplary sequential core architecture, where the core is one of several logic blocks (including other cores of the same and / or different types) in a chip. The logic block communicates with some fixed function logic, memory I / O interfaces, and other required I / O logic over a high bandwidth interconnect network (e.g., a ring network) depending on the application.
[0101] 5A is a block diagram of a single processor core with its connection to an on-die interconnect network 502 and its local subset of a level 2 (L2) cache 504, according to an embodiment of the invention. In one embodiment, an instruction decoder 500 supports the x86 instruction set with packed data instruction set extension. An L1 cache 506 allows low latency access to cache memory for the scalar and vector units. In one embodiment (to simplify the design), the scalar unit 508 and the vector unit 510 use separate register sets (scalar registers 512 and vector registers 514, respectively), and data transferred between them is written to memory and then stored in the level 1 (L1) cache 506; alternative embodiments of the invention may use different approaches (e.g., using a single register set or including a communication path that allows data to be transferred between the two register files without writing and reading them).
[0102] The local subset of the L2 cache 504 is part of a global L2 cache that is divided into separate local subsets, one for each processor core. Each processor core has a direct access path to its own local subset of the L2 cache 504. Data read by a processor core is stored in its L2 cache subset 504 and can be accessed quickly in parallel with other processor cores accessing their own local L2 cache subsets. Data written by a processor core is stored in its own L2 cache subset 504 and is flushed from other subsets as needed. The ring network ensures consistency of shared data. The ring network is bidirectional, allowing agents such as processor cores, L2 caches, and other logic blocks to communicate with each other within the chip. In some embodiments, each ring data path is 1024 bits wide per direction.
[0103] Figure 5B is an expanded view of a portion of the processor core of Figure 5A, in accordance with an embodiment of the present invention. Figure 5B includes a portion of the L1 data cache 506A of the L1 cache 504, as well as more detailed information regarding the vector unit 510 and vector registers 514. Specifically, the vector unit 510 is a 6-wide vector processing unit (VPU) (see 16-wide ALU 528) that executes one or more of the following instructions: integer, single precision floating point, and double precision floating point. The VPU supports swizzling of register inputs in swizzle unit 520, numeric conversion in numeric conversion units 522A-522B, and duplication in duplication unit 524 on the memory input.
[0104] Processor with integrated memory controller and graphics
[0105] Figure 6 is a block diagram of a processor 600 that may have more than one core, may have an integrated memory controller, and may have integrated graphics, in accordance with an embodiment of the invention. The solid lined box in Figure 6 illustrates a processor 600 with a single core 602A, a system agent 610, and a set of one or more bus controller units 616, while the optional addition of a dashed lined box illustrates an alternative processor 600 with multiple cores 602A-602N, a set of one or more integrated memory controller units 614 in the system agent unit 610, and special purpose logic 608.
[0106] Thus, different implementations of processor 600 may include: 1) a CPU with special purpose logic 608 that is integrated graphics and / or scientific (throughput) logic (which may include one or more cores), and cores 602A-602N that are one or more general purpose cores (e.g., general purpose sequential cores, general purpose out-of-order cores, a combination of the two); 2) a coprocessor where cores 602A-602N are multiple special purpose cores primarily intended for graphics and / or science (throughput); 3) a coprocessor where cores 602A-602N are multiple general purpose sequential cores. Thus, processor 600 may be a general purpose processor, coprocessor, or special purpose processor, such as, for example, a network or communication processor, compression engine, graphics processor, GPGPU (general purpose graphics processing unit), high throughput integrated core (MIC) coprocessor (containing 30 or more cores), embedded processor, etc. The processor may be implemented on one or more chips. The processor 600 may be a part of and / or may be implemented using any of a number of process technologies, such as, for example, BiCMOS, CMOS, or NMOS.
[0107] The memory hierarchy includes one or more levels of cache, set or one or more shared cache units 606 within the cores 604A-604N, and an external memory (not shown) coupled to a set of integrated memory controller units 614. The set of shared cache units 606 may include level 2 (L2), level 3 (L3), level 4 (L4), or other levels of cache, one or more intermediate levels of cache, such as a last level cache (LLC), and / or combinations thereof. In one embodiment, a ring-based interconnect unit 612 interconnects the integrated graphics logic 608, the set of shared cache units 606, and the system agent unit 610 / integrated memory controller unit 614, although alternative embodiments may use known techniques for interconnecting any number of such units. In one embodiment, coherency is maintained between the one or more cache units 606 and the cores 602A-602N.
[0108] In some embodiments, one or more of the cores 602A-602N are capable of multi-threading. The system agent 610 includes these components that coordinate and operate the cores 602A-602N. The system agent unit 610 may include, for example, a power control unit (PCU) and a display unit. The PCU may be or may include the logic and components necessary to coordinate the power state of the cores 602A-602N and the integrated graphics logic 608. The display unit is for driving one or more externally connected displays.
[0109] The cores 602A-602N may be homogenous or heterogeneous with respect to architectural instruction sets, i.e., two or more cores 602A-602N may be capable of executing the same instruction set, while other cores may be capable of only executing a subset of that instruction set or a different instruction set.
[0110] Exemplary Computer Architecture
[0111] 7-10 are block diagrams of exemplary computer architectures. Other system designs and configurations for laptops, desktops, handheld PCs, personal digital assistants, engineering workstations, servers, network devices, network hubs, switches, embedded processors, digital signal processors (DSPs), graphics devices, video game devices, set-top boxes, microcontrollers, mobile phones, personal digital assistants, handheld devices, and a variety of other electronic devices are also suitable. In general, a wide variety of systems or electronic devices that can incorporate a processor and / or other execution logic as disclosed herein are generally suitable.
[0112] 7, a block diagram of a system 700 according to one embodiment of the present invention is shown. The system 700 may include one or more processors 710, 715 coupled to a controller hub 720. In one embodiment, the controller hub 720 includes a graphics memory controller hub (GMCH) 790 and an input / output hub (IOH) 750 (which may be on separate chips), where the GMCH 790 includes a memory and graphics controller to which the memory 740 and coprocessor 745 are coupled, and the IOH 750 couples the input / output (I / O) devices 760 to the GMCH 790. Alternatively, one or both of the memory and graphics controller are integrated within the processor (as described herein), the memory 740 and coprocessor 745 are directly coupled to the processor 710, and the controller hub 720 is a single chip with the IOH 750.
[0113] The optional nature of the additional processors 715 is indicated by dashed lines in Figure 7. Each processor 710, 715 may include one or more of the processing cores described herein and may be some version of the processor 600.
[0114] The memory 740 may be, for example, dynamic random access memory (DRAM), phase change memory (PCM), or a combination of the two. In at least one embodiment, the controller hub 720 communicates with the processors 710, 715 via a multi-drop bus, such as a front side bus (FSB), point-to-point interface, or similar connection 795.
[0115] In one embodiment, coprocessor 745 is a special purpose processor such as, for example, a high throughput MIC processor, a network or communication processor, a compression engine, a graphics processor, a GPGPU, an embedded processor, etc. In one embodiment, controller hub 720 may include an integrated graphics accelerator.
[0116] There may be a wide variety of differences between the physical resources 710, 7155 with respect to a spectrum of metrics of merit including architectural, microarchitectural, thermal, power consumption characteristics, and the like.
[0117] In one embodiment, the processor 710 executes instructions that control a general type of data processing operation. Embedded within the instructions are coprocessor instructions. The processor 710 recognizes these coprocessor instructions as being of a type that should be executed by the connected coprocessor 745. Thus, the processor 710 issues these coprocessor instructions (or control signals representing the coprocessor instructions) to the coprocessor 745 on a coprocessor bus or other interconnect. The coprocessor 745 accepts and executes the received coprocessor instructions.
[0118] Referring now to Figure 8, a block diagram of a first more specific exemplary system 800 according to an embodiment of the present invention is shown. As shown in Figure 8, the multiprocessor system 800 is a point-to-point interconnect system and includes a first processor 870 and a second processor 880 coupled via a point-to-point interconnect 850. Each of the processors 870 and 880 may be some version of the processor 600. In one embodiment of the present invention, the processors 870 and 880 are processors 710 and 715, respectively, and the coprocessor 838 is coprocessor 745. In another embodiment, the processors 870 and 880 are processors 710 and coprocessor 745, respectively.
[0119] Processors 870 and 880 are shown including integrated memory controller (IMC) units 872 and 882, respectively. Processor 870 also includes point-to-point (PP) interfaces 876 and 878 as part of its bus controller unit. Similarly, a second processor 880 includes PP interfaces 886 and 888. Processors 870, 880 can exchange information over a point-to-point (PP) interface 850 using PP interface circuits 878, 888. As shown in FIG. 8, IMCs 872 and 882 couple the processors to respective memories, i.e., memory 832 and memory 834, which may be part of a main memory locally connected to the respective processors.
[0120] Each of the processors 870, 880 may exchange information with a chipset 890 via respective PP interfaces 852, 854 using point-to-point interface circuits 876, 894, 886, 898. The chipset 890 may optionally exchange information with a coprocessor 838 via a high performance interface 892. In one embodiment, the coprocessor 838 is a special purpose processor such as, for example, a high throughput MIC processor, a network or communication processor, a compression engine, a graphics processor, a GPGPU, an embedded processor, or the like.
[0121] A shared cache (not shown) may be included in either of the processors or may be external to both processors and connected to the processors via the PP interconnect, such that when the processors are placed in a low power mode, local cache information of either or both processors is stored in the shared cache.
[0122] Chipset 890 may be coupled to a first bus 816 via an interface 896. In one embodiment, first bus 816 may be a bus such as a Peripheral Component Interconnect (PCI) bus, or a PCI Express bus or another I / O interconnect bus, although the scope of the invention is not so limited.
[0123] As shown in FIG. 8, various I / O devices 814 may be coupled to the first bus 816 along with a bus bridge 818 coupling the first bus 816 to a second bus 820. In one embodiment, one or more additional processors 815, such as a co-processor, a high throughput MIC processor, a GPGPU, an accelerator (e.g., a graphics accelerator or a digital signal processing (DSP) unit), a field programmable gate array, or any other processor, are coupled to the first bus 816. In one embodiment, the second bus 820 may be a low pin count (LPC) bus. In one embodiment, various devices may be coupled to the second bus 820 including, for example, a keyboard and / or mouse 822, a communication device 827, and storage device 828, such as a disk drive or other mass storage device that may include instructions / code and data 830. Additionally, audio I / O 824 may be coupled to the second bus 816. It should be noted that other architectures are possible. For example, instead of the point-to-point architecture of FIG. 8, the system may implement a multi-drop bus or other such architecture.
[0124] Referring now to Figure 9, there is shown a block diagram of a second, more specific exemplary system 900, in accordance with an embodiment of the present invention. Like elements in Figures 8 and 9 are labeled with like reference numbers, and certain aspects of Figure 8 have been omitted from Figure 9 so as not to obscure other aspects of Figure 9.
[0125] 9 shows that the processors 870, 880 may include integrated memory and I / O control logic ("CL") 972 and 982, respectively. Thus, the CL 972, 982 includes an integrated memory controller unit and includes I / O control logic. FIG. 9 shows that not only are the memories 832, 834 coupled to the CL 872, 882, but also the I / O devices 914 coupled to the control logic 872, 882. The legacy I / O devices 915 are coupled to the chipset 890.
[0126] Referring now to FIG. 10, a block diagram of a SoC 1000 according to an embodiment of the present invention is shown. Similar elements in FIG. 6 are labeled with similar reference numbers. Also, dashed boxes are optional features for more advanced SoCs. In FIG. 10, an interconnect unit 1002 is coupled to an application processor 1010 including one or more cores 102A-102N, a set of cache units 604A-604N, and a shared cache unit 606, a system agent unit 610, a bus controller unit 616, an integrated memory controller unit 614, a set or one or more coprocessors 1020 that may include integrated graphics logic, image processors, audio processors, and video processors, a static random access memory (SRAM) unit 1030, a direct memory access (DMA) unit 1032, a display unit 1040 for coupling to one or more external displays. In one embodiment, the coprocessor 1020 includes a special purpose processor such as, for example, a network or communication processor, a compression engine, a GPGPU, a high throughput MIC processor, an embedded processor, or the like.
[0127] The embodiments of the mechanisms disclosed herein may be implemented in hardware, software, firmware, or a combination of such implementation approaches.Embodiments of the present invention may be implemented as a computer program or program code running on a programmable system including at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.
[0128] 8 may be applied to the input instructions to perform functions described herein and to generate output information. The output information may be applied to one or more output devices, in known fashion. For purposes of this application, a processing system includes any system having a processor, such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0129] The program code may be implemented in a high level procedural or object oriented programming language to communicate with a processing system. The program code may also be implemented in assembly or machine language, if desired. Indeed, the mechanisms described herein are not limited in scope to any particular programming language. In any case, the language may be a compiled or interpreted language.
[0130] One or more aspects of at least one embodiment may be implemented by representative instructions stored on a machine-readable medium that represent various logic within a processor and, when read by a machine, causes the machine to manufacture logic that performs the techniques described herein. Such representations, known as "IP cores," are stored on tangible machine-readable media and supplied to various customers or manufacturing facilities to be loaded into manufacturing machines that actually produce the logic or processor.
[0131] Such machine-readable storage media may include, but are not limited to, non-transitory, tangible arrangements of articles manufactured or formed by a machine or device, including storage media such as hard disks, floppy disks, optical disks, compact disk-read only memory (CD-ROM), compact disk-rewriteable (CD-RW), and other types of disks including magneto-optical disks, semiconductor devices such as read-only memory (ROM), random access memory (RAM) such as dynamic random access memory (DRAM), static random access memory (SRAM), erasable programmable read-only memory (EPROM), flash memory, electrically erasable programmable read-only memory (EEPROM), phase change memory (PCM), magnetic or optical cards, or other types of media suitable for storing electronic instructions.
[0132] Accordingly, embodiments of the present invention also include non-transitory, tangible, machine-readable media that include instructions or include design data, such as a Hardware Description Language (HDL), that define the structures, circuits, devices, processors, and / or system functions described herein. Such embodiments may also be referred to as program products.
[0133] Emulation (including binary conversion, code morphing, etc.)
[0134] In some cases, an instruction converter may be used to convert instructions from a source instruction set to a target instruction set. For example, the instruction converter may translate, transform, emulate, or convert instructions (e.g., using static binary translation, dynamic binary translation including dynamic compilation) into one or more other instructions to be processed by the core. The instruction converter may be implemented in software, hardware, firmware, or a combination thereof. The instruction converter may be on-processor, off-processor, or partly on and partly off-processor.
[0135] FIG. 11 is a block diagram contrasting the use of a software instruction converter to convert binary instructions in a source instruction set to binary instructions in a target instruction set, according to an embodiment of the present invention. In the illustrated embodiment, the instruction converter is a software instruction converter, but alternatively, the instruction converter may be implemented in software, firmware, hardware, or various combinations thereof. FIG. 11 illustrates that a program in a high-level language 1102 may be compiled using a first compiler 1104 to generate a first binary code (e.g., x86) 1106 that may be natively executed by a processor having at least one first instruction set core 1116. In some embodiments, a processor with at least one first instruction set core 1116 represents any processor that can perform substantially the same functions as an Intel processor with at least one x86 instruction set core by compatibly executing or processing a substantial portion of (1). or (2) an object code version of an application or other software intended to run on an Intel processor with at least one x86 instruction set core, to achieve substantially the same results as an Intel processor with at least one x86 instruction set core. A first compiler 1104 represents a compiler operable to generate binary code 1106 (e.g., object code) in a first instruction set that can be executed on a processor with at least one first instruction set core 1116, with or without additional linkage processing. Similarly, FIG. 11 illustrates that a program in a high-level language 1102 may be compiled using an alternative instruction set compiler 1108 to generate alternative instruction set binary code 1110 that can be executed natively by a processor without at least one first instruction set core 1114 (e.g., a processor with a core that executes the MIPS instruction set from MIPS Technology, Inc. of Sunnyvale, Calif. and / or a core that executes the ARM instruction set from ARM Holdings, Inc. of Sunnyvale, Calif.).The instruction converter 1112 is used to convert the first binary code 1106 into code that can be executed natively by a processor without the first instruction set core 1114. This converted code is unlikely to be identical to the alternative instruction set binary code 1110 because of the difficulty of creating an instruction converter capable of this. However, the converted code performs common operations and is composed of instructions from the alternative instruction set. Thus, the instruction converter 1112 represents software, firmware, hardware, or a combination thereof that enables a processor or other electronic device without a first instruction set processor or core to execute the first binary code 1106, through emulation, simulation, or any other process.
[0136] Apparatus and method for efficiently managing and handling shadow stacks - Patents.com
[0137] One embodiment of the present invention implements a technique that avoids atomic operations for validation of tokens used to validate a Shadow Stack Pointer (SSP) while preserving the underlying security properties of the token mechanism. Additionally, certain embodiments include virtualization extensions to support an efficient token validation architecture.
[0138] Instruction set architectures (ISAs), such as the x86 architecture, often provide multiple privilege levels at which instructions can be executed. Privilege levels are used to improve the reliability of an operating system (e.g., kernel) associated with a hardware platform by protecting resources from direct access by less trusted entities. In some embodiments, these privilege levels range from ring 0 (e.g., supervisor mode), which is the most trusted privilege level, to ring 3, or a non-privileged level (e.g., application or user mode). Each privilege level requires some resources to be pre-allocated and saved for later use during a ring transition to a new privilege level.
[0139] The processor's current privilege level controls the execution of instructions. The processor can change the current privilege level to control an application's access to system resources, such as system registers, system instructions, and designated system memory areas. In executing an application, the processor utilizes a data stack that stores both data (e.g., parameters and other data passed to subroutines) and control information to direct the control flow of executed instructions. Typically, the control information includes one or more return addresses to which control flow returns when the called procedure is completed.
[0140] In a Return-Oriented Programming (ROP) attack, an attacker attempts to hijack the control flow of a program by gaining control of the data stack. For example, an attacker may perform an unauthorized stack modification of the return address of a procedure stored in the data stack. The unauthorized stack modification is used to divert the control flow of the current process to an arbitrary memory location to further the hacking goal. One factor that makes the data stack more vulnerable to ROP and other types of control flow subversion attacks is that the data stack must be software writable, since the stack generally stores both data and control information. Another factor that makes the data stack more vulnerable to such attacks is that switching the data stack is generally performed as an unprivileged operation.
[0141] In response to some event (e.g., interrupt / exception), the processor may transfer control of a sequence of instructions executed at non-privileged user level to the supervisor privilege level in order to access resources required to handle that event. These factors above tend to increase the exposure of the system to control flow subversion attacks due to exploited bugs that allow modification of the stack pointer and / or control flow information (e.g., return address) (e.g., to point to malware / attacker controlled memory).
[0142] An embodiment of the present invention includes techniques for protecting stacks from control flow subversion attacks on privileged transfers. In one embodiment, several "shadow" stacks are provided to protect against attempts to tamper with control information on the data stack. As used herein, a shadow stack is a second stack separate from the data stack and used to store and protect information from the data stack used in control transfer operations. For example, a shadow stack can store control information but not data (e.g., parameters and other data of the type stored in a stack that user-level application programs write and modify).
[0143] In some embodiments, the shadow stack can only be written by certain instructions, such as "CALL" (which is an example of a procedure that invokes a mechanism that uses the data stack) and "FAR CALL" (which is an example of a branch instruction that implements both micro-branch and macro-branch jump instructions), which perform control transfer operations and flow (e.g., interrupt / exception delivery). In such circumstances, the shadow stack may not be writable by other software-initiated stores via other instructions, such as "MOV", which transfers multiple bytes in one operation, or "XSAVE", which is used to store context state to memory and restore the context state from memory to the processor's registers. This write protection is achieved by marking the memory used for the shadow stack in the page tables as shadow stack memory, so that software-initiated stores using instructions such as "MOV", "XSAVE", etc. do not complete and cause a fault. Similarly, instructions such as "CALL", when generating store instructions that target shadow stack memory, use a specific store operation such that they will only complete if the memory to which the store is performed is marked as shadow stack memory in the page tables; otherwise, a fault will occur.
[0144] In some embodiments, the shadow stack may be optionally configured to operate individually in a non-privileged user level mode (e.g., ring 3 privilege level) or a privileged or supervisor privilege level mode (ring 0, ring 1, or ring 2 privilege level). To support switching of the shadow stack on a privilege switch from a source privilege level to a new privilege level, one implementation includes a register associated with each privilege level.
[0145] In some embodiments, system software (e.g., system kernel or operating system) loads a shadow stack pointer (SSP) into one or more registers at each privilege level. The processor then accesses the SSP via a register associated with the new privilege level to identify the shadow stack for that privilege level. In operation, when the processor selects an SSP for a new privilege level, the processor validates / verifies the SSP that the processor will use at the new level. If the validation is successful, the processor sets the shadow stack as busy at the new privilege level and pushes the return address information of the source privilege level onto the shadow stack. Then, embodiments of the present disclosure ensure that a transition of the processor back to the source privilege level is validated before the shadow stack is marked as not busy. This validation includes verifying that the return address of the source privilege level pushed onto the shadow stack matches the current address associated with the data stack. To perform this validation, the processor uses a specific load operation (e.g., "shadowStackPop" or load with shadow stack semantics) to ensure that if the load operation is not to memory marked as shadow stack memory in the page table, this load will not be completed (e.g., generate a fault condition). Thus, any attempt to point a shadow stack pointer to non-shadow stack memory is detected and prevented.
[0146] In other embodiments, the techniques described herein may be used to protect shadow stack switching, for example, as part of interrupt / exception delivery or as part of a task switch from a current task at a source privilege level to a new task at a new privilege level, using the shadow stack to perform fast system calls (e.g., transitioning user mode privileges to a mode that has full control of hardware permissions), protecting the shadow stack from cross-thread attacks, such as attacks from a less privileged process to a more privileged process, and protecting the shadow stack during ring transitions from other types of unauthorized stack modifications employed by an attacker.
[0147] FIG. 12 illustrates a block diagram of a processing device for supporting processor extensions to protect stacks during ring transitions, according to one embodiment. A processing device may be generally referred to as a "processor" or "CPU." A "processor" or "CPU" herein refers to a device that can execute instructions that encode arithmetic, logical, or I / O operations. In one example, a processor may include an arithmetic logic unit (ALU), a control unit, and multiple registers. In a further aspect, a processor may include one or more processing cores, and thus may be a single-core processor that is typically capable of processing a single instruction pipeline, or a multi-core processor that may process multiple instruction pipelines simultaneously. In another aspect, a processor may be implemented as a single integrated circuit, two or more integrated circuits, or may be a component of a multi-chip module (e.g., individual microprocessor dies are included in a single integrated circuit package and thus share a single socket).
[0148] As shown in FIG. 12, a processing device may include various components. In one embodiment, the processing device may include one or more processing cores 1210 and a memory controller unit 1220, among other components, coupled together as shown. The processing device may also include a communication component (not shown) that may be used for point-to-point communication between various components of the processing device 1200. The processing device may be used in a computing system (not shown) including, but not limited to, a desktop computer, a tablet computer, a laptop computer, a netbook, a notebook computer, a personal digital assistant (PDA), a server, a workstation, a mobile phone, a mobile computing device, a smartphone, an Internet appliance, or other types of computing devices. In another embodiment, the processing device may be used in a system-on-a-chip (SoC) system. In one embodiment, the SoC may include the processing device and a memory. One memory in such a system is a DRAM memory. The DRAM memory may be located on the same chip as the processor and other system components. Additionally, other logic blocks such as a memory controller and a graphics controller may also be located on the chip.
[0149] The processing core 1210 may execute instructions for the processing device 1200. The instructions may include, but are not limited to, prefetch logic to fetch instructions, decode logic to decode instructions, execute logic to execute instructions, and the like. The computing system may be representative of a processing system based on the Intel x86 family of processors and / or microprocessors available from Intel Corporation of Santa Clara, California (e.g., Intel Core i5, i7 processors, etc.), although other systems may be used, including computing devices having other microprocessors, engineering workstations, set-top boxes, and the like. In one embodiment, the sample computing system may execute a version of an operating system, embedded software, and / or a graphical user interface. Thus, embodiments of the present disclosure are not limited to any particular combination of hardware circuitry and software.
[0150] In an illustrative example, the processing core 1210 may have a microarchitecture that includes processor logic and circuitry. Processor cores with different microarchitectures may share at least a portion of a common instruction set. For example, a similar register architecture may be implemented in different ways in different microarchitectures using different techniques, such as dedicated physical registers, one or more physical registers dynamically allocated using a register renaming mechanism (e.g., using a register alias table (RAT), a reorder buffer (ROB), and a retirement register file).
[0151] The memory controller 1220 may perform functions that allow the processing device to access and communicate with memory (not shown), including volatile and / or non-volatile memory. In some embodiments, the memory controller 1220 may be located on a processor die associated with the processing device 1200, while the memory is located off the processor die. In some embodiments, the processing device includes a cache unit 1230 for caching instructions and / or data. The cache unit 1230 includes, but is not limited to, a level 1 (L1) 1232, a level 2 (L2) 1234, and a last level cache (LLC) 1236, or other configurations of cache memory in the processing device 1200. In some embodiments, the L1 cache 1232 and the L2 cache 1234 may transfer data to and from the LLC 1236. In one embodiment, the memory controller 1220 may be connected to the LLC 1236 to transfer data between the cache unit 1230 and the memory. As shown, the cache unit 1230 may be integrated into the processing core 1210. Cache unit 1230 may store data (including, for example, instructions) utilized by one or more components of processing device 1200.
[0152] In some embodiments, the processing device may execute one or more user-level applications 1240 (e.g., user-level multi-threaded applications). Such user-level applications 1240 may be executed by system software (not shown) installed on the processing device 1200. Examples of system software include, but are not limited to, one or more operating systems, virtual machine monitors (VMMs), hypervisors, and the like, and combinations thereof. The user-level applications 1240 may use instructions (e.g., instructions 1250) to control the processing device as disclosed herein. The instructions 1250 may represent macro instructions, assembly language instructions, or machine-level instructions that are provided to the processing core 1210 for execution.
[0153] In some embodiments, the processing core 1210 is operable to execute an embodiment of a call procedure instruction 1252 and an embodiment of a return from procedure instruction 1254 as specified by instruction 1250. The call procedure instruction 1252 is often simply referred to as a call instruction, and the return from procedure instruction 1254 is often simply referred to as a return instruction. The call and return instructions may represent instructions or control signals of a particular instruction set for a processing device to execute at a particular privilege level. During operation, the processing core 1210 may receive a call instruction 1252. For example, the call instruction 1252 may be received from a call procedure associated with a user-level application 1240 that is calling a subroutine, routine, interrupt handler, etc. In some embodiments, the address of the return instruction 1254 may be pushed onto a data stack stored in memory when a function or procedure is called.
[0154] If the call instruction 1252 causes a change in the current privilege level of the processing device 1200, the processing device performs a stack switch from the current stack to a stack defined for the new privilege level. For example, the call instruction 1252 may cause the processing device to change the current privilege level to access certain system resources that are not accessible at the current privilege level. In some embodiments, one or more shadow stacks stored in memory are used to help protect the data stack from tampering and / or to help increase computer security. Information stored in the shadow stack may represent return address related information associated with the return instruction 1254 (e.g., the actual return address, information for validating / verifying the return address, other return address information).
[0155] To identify the current shadow stack for a particular privilege level, the processing device includes a number of shadow stack registers 1270, with each register associated with a particular privilege level. As an illustrative example, the processing device may include four registers called IA32_PLx_SSP, where x represents a privilege level (e.g., 0, 1, 2, or 3). In some embodiments, the shadow stack registers 1270 may be model specific registers (MSRs) or general purpose registers (GPRs). In other embodiments, various types of structures may be used as the registers 1270, so long as they are capable of storing and providing data as described herein.
[0156] Upon power-up of the processing device 1200, system software associated with the device may program a stack pointer (SSP) 1275 into each of the shadow stack registers 1270. The stack pointer (SSP) 1275 operates to identify a particular shadow stack for the privilege level identified by the register. For example, the SSP 1275 may be a linear address in memory that points to the top of the shadow stack. In one embodiment, the processing device may include shadow stack protection logic 1280 for controlling access to the shadow stack via the shadow stack registers 1270 during ring transitions.
[0157] The shadow stack protection logic 1280 may also force loads and stores targeted to the shadow stack to generate a fault condition if the address at which the load or store is performed is not marked as a shadow stack type in the page table. This shadow stack protection logic 1280 may also prevent software initiated stores via instructions such as "MOV" or "XSAVE" from storing to the shadow stack memory. In some embodiments, the shadow stack protection logic 1280 may also include an optional configurable shadow stack mode 1285. The shadow stack mode 1285 may be a bit indicator configured to alternately enable and disable use of the shadow stack by the processing device 1200. Alternatively, the shadow stack may optionally be always enabled and the shadow stack mode 1285 may optionally be omitted. Alternatively, there may be a shadow stack mode corresponding to each privilege level.
[0158] FIG. 13 illustrates a system 1300 including a memory 1301 for supporting a processor extension for stack protection during ring transitions, according to one embodiment. In this example, the memory 1301 stores one or more data stacks, such as a data stack 1303. The data stack may also be referred to as a call stack, a data stack, or simply a stack. The data stack 1303 may represent a stack-type data structure that operates to store both data 1305 and control information 1307 to direct the control flow of executed instructions. Typically, there is a data stack 1303 for each privilege level associated with the processing device 1200. Thus, when the processing device switches privilege levels, it also switches the data stack 1303, as with the shadow stack, as described in this disclosure. The data 1305 of each data stack may represent any of a wide variety of different types of data that can be pushed onto the data stack 1301 (e.g., parameters passed to a subroutine and other data, etc.). In general, the control information 1307 may include one or more return addresses for one or more previously executed procedure calls. These return addresses may represent the instruction addresses to which the called procedure returns control flow when the called procedure finishes and returns.
[0159] As shown in FIG. 13, memory 1301 also includes multiple shadow stacks 1309. Shadow stacks 1309 are used to help protect data stack 1303 from certain types of control flow attacks. Shadow stacks 1309 may represent additional stack-type data structures separate from data stack 1303. In some embodiments, shadow stack 1309 may be used to store information related to control information 1307 of executed instructions, but not data 1305. In one illustrative example, shadow stack 1309 may store code segment (CS) descriptors, such as CS 1340, that identify the code segment in memory 1301 being executed, and instruction pointers (EIPs), such as EIP 1350, that identify return addresses associated with instructions in data stack 1303, and other information. In some embodiments, memory used to create the shadow stacks may be marked in the page tables to be of a shadow stack memory type, such that loads and stores to shadow stack fault if they are not shadow stack type memory. Similarly, stores that are not intended to shadow stack fault will fail if made to memory marked as shadow stack memory.
[0160] The system 1300 may include multiple shadow stacks 1309, but only one shadow stack at a time may be selected as the current shadow stack 1310. In this regard, the shadow stacks 1309 may individually operate in a non-privileged user level mode (e.g., ring 3 privilege level) or a privileged or supervisor privilege level mode (ring 0, ring 1, or ring 2 privilege level). In some embodiments, each of the shadow stacks 1309 includes a shadow stack pointer (SSP), such as SSP 1320, that operates to identify the top of the shadow stack. For example, the SSP 1320 may be a linear address in the memory 1301 that points to the top of the current shadow stack. As noted above, the SSP 1320 may be stored in one of the shadow stack registers 1270 associated with a particular privilege level.
[0161] As shown, system 1300 may also include a processing device from FIG. 12. In some embodiments, the processing device may have a current privilege level that controls the execution of applications in system 1300. In certain circumstances, the processing device may change its current privilege level to a new privilege level to control the application's accessibility to resources of system 1300. For example, the processing device may change the current privilege level in response to certain types of operations, such as called procedures, interrupt / exception handlers, or in response to other types of operations. In some embodiments, the processing device may use shadow stack protection logic 1280 to protect the stack during privilege level transitions.
[0162] In one example of a privilege level transition, a processing device may transition from a current privilege level (CPL) in user mode (e.g., CPL3) to a new privilege level in supervisor mode (e.g., CPL<3). This type of privilege level transition may be initiated, for example, by a call through a call gate requesting a change to a higher privilege level or by invoking an interrupt / exception handler. In response to a privilege level transition from user mode to supervisor mode, the processing device checks whether a shadow stack 1309 is enabled for the processing device at the new privilege level. For example, the processing device may check a setting of the shadow stack mode 1285 indicator to determine whether the shadow stack 1309 is enabled or disabled. If the shadow stack 1309 is enabled, the current SSP associated with the user mode is saved in one of the shadow stack registers 1270. A new shadow stack 1310 is then established for the supervisor mode using an SSP, such as SSP 1320, stored in a register associated with the new privilege level. In some embodiments, the user mode SSP is stored in a shadow stack register so that a processing device in supervisor mode can modify the user mode SSP as necessary, such as unwinding the shadow stack to remove stack and other types of entries, and making other types of modifications, before returning to user mode again.
[0163] When the processing device retrieves the SSP 220 from a register associated with the new privilege level, the processing device automatically performs several checks to validate the SSP programmed into the register using certain logic of the shadow stack protection logic 1280, such as the busy validation and set logic 1325. The automatic checks include, but are not limited to, verifying that the SSP 1320 programmed into the register points to the top of a supervisor shadow stack (e.g., shadow stack 1310). The shadow stack identified by the SSP 1320 is used for the current mode of the platform hardware associated with the processing device, and that shadow stack is not loaded into other process threads. These checks can be used to prevent certain attacks, such as cross-threading, where an attacker can point registers of two different processor threads to the same shadow stack to manipulate the return address consumed by one processor by making a call in the second processor.
[0164] To perform a check to validate the SSP 1320, the processing device's system software (e.g., kernel or OS) identifies a token 1330 at the top of the shadow stack 1310 pointed to by the SSP. In some embodiments, the processing device may (e.g., atomically) load the (e.g., 8-byte) token 1330 from an address specified by the SSP 1320. In one embodiment, the loading of the token 1330 locks the token and / or a location (e.g., a cache line) to prevent the token from being copied or modified by another processor core or processing device. In one embodiment, the loading of the token is performed by the processing device using a specific shadow stack operation, and if the address where the load or store is performed is not a memory marked as shadow stack memory in the page table, it causes a fault.
[0165] The token 1330 includes a number of bits that are used to verify the SSP 1320 programmed into the register. In some embodiments, the processing device analyzes the number of bits to identify a set bit that represents the linear address of the token 1330, a busy indicator, which may be a determined bit in the token that is set to a value (e.g., 1 or 0), a flag indicator, which may be another determined bit in the token that is set to a value (e.g., 1 or 0) that indicates whether the shadow stack 1310 is already loaded on any logical processor, whether the shadow stack 1310 is used in a particular bit mode (e.g., 32-bit or 64-bit), and other relevant information.
[0166] According to the validation logic 1325, the processing device checks that a busy indicator is not set (e.g., 0), indicating that the shadow stack 1310 has not yet been loaded into any logical processor. The processing device also checks that the hardware platform of the system 1300 is operating in a mode that matches the bit mode represented by the flag indicator. For example, based on the flag indicator, the flag processing device may determine that the shadow stack 1310 is for use with a 32-bit or 64-bit machine. The processing device may then, for example, check a platform register associated with the hardware platform to verify that the platform is in the corresponding operating mode (e.g., 32-bit or 64-bit). The processing device also checks that the linear address recorded in the token 1330 matches the linear address of the SSP 1320.
[0167] This check to match the linear address verifies that register 1270 points to the top of a valid shadow stack, since the linear address of an 8-byte location on the shadow stack does not appear in the contents of those 8 bytes on the shadow stack other than when created by the system software to initialize token 1330. Thus, token 1330 forms an indicator that the shadow stack pointer stored in register 1270 points to the top of a valid shadow stack. In some embodiments, the processing device enforces that the shadow stack is 4-byte or 8-byte aligned, depending on whether the processing device is in a 32-bit or 64-bit mode of operation, and thus the lower two bits of shadow stack pointer 1320 are always 0 and can be used to save a busy indicator and a flag in token 1330. If the results of all the above checks are a correct indication, the busy indicator in the token can be set to a value (e.g., 1) to indicate that the shadow stack pointed to by SSP 1320 is being used at the new privilege level. Note that while these checks are being performed, the memory location (e.g., a cache line) containing the token 1330 is locked by the processing device so that it cannot be modified (e.g., set to busy by another logical processor). After setting the busy bit, the processor unlocks this memory location. Performing these check operations with the token locked ensures that no problems will occur between the time of check and the time of use. Otherwise, if any of the above checks fail, the processing device may generate a fault or alert that can be sent, for example, to an operating system associated with the processing device 1200. In some embodiments, if a fault is generated, the lock on the memory location containing the token 1330 is released without modifying the contents of the location.
[0168] When returning from supervisor mode to a user mode privilege level, such as a CPL 0 / 1 / 2 → CPL 3 mode transition, the processing device performs several checks using specific logic, such as busy verify and clear logic 1335. This type of privilege level transition can be initiated, for example, by an interrupt return (IRET) instruction, or a "FAR RET" instruction that shifts the next address to be executed into the CPU's instruction pointer or other type of return instruction.
[0169] As part of the transition back to the user mode privilege level, the processing device, as directed by busy verify and clear logic 1335, checks whether the busy indicator in the token 1330 is set and whether the linear address recorded in the token matches the address of the SSP 1320 if the SSP 1320 points to an 8-byte aligned address. If all of the above checks result in a correct indication, the processing device marks the token 1330 as "free" by clearing the busy indicator in the token 1330. Note that the token is loaded from the memory address pointed to by the SSP 1320 using a locked load, so that the location (e.g., a cache line) is locked from further modification. If the verification is successful, the busy bit is cleared and the lock is released. If the verification is not successful, the lock is released without modifying the contents of the location. The processing device then retrieves the user mode SSP from the appropriate shadow stack register 1270 associated with its privilege level. If not, the processing device may generate a fault indicating that the token 1330 is invalid.
[0170] In another example of a privilege level transition, a processing device may transition from a current supervisor mode privilege level to a new higher supervisor mode, such as a CPL2 → CPL1, CPL1 → CPL0 or CPL2 → CPL0 mode transition. This type of privilege level transition may be initiated, for example, by a call through a call gate requesting a higher privilege level change, or by a call and interrupt / exception handler. During such a transition, the processing device selects the SSP 1320 for the new privilege level from the appropriate one of the shadow stack registers 1270 for that level. Once the processing device retrieves the SSP 1320 from the register associated with the new privilege level, the processing device performs several checks to validate the SSP programmed in the register.
[0171] In some embodiments, the processing device performs the check by using the busy validation and setting logic 1325 as described above. If the check is successful, the processing device marks the shadow stack 1310 as busy by setting a busy indicator in the token 1330. The processing device then pushes a CS 1340 selector (e.g., a code segment selector) that identifies the code segment in memory 1301 being executed, an EIP 1350 that identifies return address information, and an SSP 1360 associated with the current privilege level onto the shadow stack of the new privilege level. In some embodiments, the processing device may push a linear instruction pointer (LIP) (which is the EIP plus the code segment base) onto the shadow stack of the new privilege level instead of the EIP 1350. This may be done to detect attempts to change the code segment base between a call and a return from the call.
[0172] Upon returning from the new supervisor mode to the previous supervisor mode, the processing device ensures that such return is to the same address at which the previous call was made. For example, the processing device verifies that the CS 1340 and EIP 1350 (or LIP) from the shadow stack 1310 match the corresponding values on the data stack 1303. If there is a match, the processing device removes or pops the CS 1340, EIP 1350, and SSP 1360 from the shadow stack 1310 to establish a new SSP to be used at the new privilege level. In some embodiments, the push and pop operations are performed using certain shadow stack store and load operations, such that if the operation is to memory that is not marked as shadow stack memory in the page table, the operation will cause a fault.
[0173] As part of the transition, the processing device, as directed by busy validation and clear logic 1335, checks whether a busy indicator in the token 1330 of the shadow stack that points to the SSP 1320 is set, and whether the linear address recorded in the token 1330 matches the address of the SSP 1320. If all of the above checks result in a correct indication, the processing device marks the token 1330 as "free" by clearing the busy indicator in the token 1330.
[0174] Yet another example of a privilege level transition may be based on a mode transition from a user mode of the processing device to the most trusted privilege level, e.g., a CPL3→CPL0 mode transition. This type of privilege level transition may be initiated using a specific instruction, e.g., SYSCALL or SYSENTER, designed to invoke a system call where some of the system calls do not use a stack to perform system call operations. In such a transition, the processing device saves the current SSP in a register associated with the user mode and switches to a shadow stack associated with the CPL0 privilege level by retrieving the SSP in the corresponding register. The processing device may be performing a system-critical operation and therefore does not validate the SSP, but selects one of the shadow stacks from the set of shadow stacks as the current SSP for the new privilege level. For example, this type of privilege level transition may be initiated by a fast system call, e.g., that does not use a stack to perform system call operations. In some embodiments, if the system call needs to use a stack to make the invocation, it may be configured to use a new instruction provided by the processing device to perform validation and marking of the shadow stack as busy, such as for use in busy validation and setting logic 1325. This operation of the verify and set busy logic 1325 is performed on the shadow stack that has been selected but has not previously verified and set busy.
[0175] Upon returning to the previous user mode from the most trusted privilege level, such as a CPL0 → CPL3 mode transition, the processing device restores the user mode shadow stack by accessing the SSP stored in a register corresponding to the user mode privilege level. This type of privilege level transition can be initiated, for example, by a system return or exit instruction (e.g., SYSRET or SYSEXIT). If the system call validated and marked the shadow stack as busy using a new instruction provided by the processing device before returning to CPL3, a complementary instruction is provided by the processing device, such as used in busy validate and clear logic 1335, to validate and mark the shadow stack as free.
[0176] FIG. 14 illustrates a system 1400 including the memory 1301 of FIG. 13 for switching stacks as part of interrupt or exception delivery, according to one embodiment. In some embodiments, the present disclosure provides techniques to complement a shadow stack switch during delivery and execution of a particular interrupt by using an interrupt shadow stack pointer table 1410 instead of the shadow stack register 1270 used to select the shadow stack pointer of the privilege level at which this interrupt or exception handler executes. System software of the processing device 1210 can program the address of the table 1410 into a register, such as the interrupt SSP table address register 1420. The table 1410 is used to store the SSP 1320 identified by the processing device during a ring transition as described above with respect to the system 1300, or to cause a stack switch even in the absence of a ring transition if the interrupt or exception is configured to operate on a new shadow stack. In this regard, the selection of the new shadow stack is from one of the shadow stack pointers in the interrupt shadow stack table 1410 using a selector 1430 configured for that interrupt in the interrupt descriptor table (IDT).
[0177] During operation, when an exception or interrupt occurs, the processing device may respond with a control transfer to a specific code sequence intended to handle such an event. This code sequence is typically executed in supervisor mode. The address of this special code sequence or routine is obtained by the processing device from an interrupt descriptor table (IDT) using an index into the IDT specific to the type of exception that occurred (e.g., one index corresponds to a page fault, another to an overflow exception). This IDT entry may further have an index into an interrupt shadow stack table 1410 such that, if this index value is non-zero, it indicates that a shadow stack switch must be performed for that interrupt or exception even if no change in privilege to deliver the interrupt or exception is required. The processing device may use the index associated with the IDT to index into the interrupt shadow stack pointer table 1410 to identify an entry that stores the SSP 1320. For example, the entry in the interrupt shadow stack pointer table 1410 may also be specific to the type of exception that occurred. The SSP 1320 may then be used by the processing device at the new privilege level associated with the interrupt. Following selection of the SSP, the processor device invokes specific logic (e.g., busy verification and setting logic 1325) to ensure that the SSP 1320 stored in the interrupt shadow stack table 1410 points to the top of a valid shadow stack for that operating mode and that the shadow stack is not busy.
[0178] FIG. 15 illustrates a system 1500 including the memory 1301 of FIG. 13 for switching stacks as part of a task switch according to one embodiment. In a task switch operation, a processing device may execute a control transfer instruction that causes a task switch from a currently executing task to a new task. In some embodiments, a task may represent a unit of work that a processing device can dispatch, execute, or suspend. By way of example, a task may be used to execute one or more of a program, a task or process, an operating system service utility, an interrupt or exception handler, or a kernel or execution utility. In one aspect, a task switch may be performed when a calling procedure instruction is executed, or when an interrupt or exception occurs, or in other manner.
[0179] When a processing device performs a task switch from a current task to a new task, the device saves state information for the current task corresponding to the current task in a data structure in memory 1301 called a task state segment (TSS), such as current TSS 1520. State information for the new task 1527 may be loaded or retrieved from another TSS (e.g., new TSS 1525) corresponding to the new task 1527. This state information may include information necessary to perform the task switch, such as, but not limited to, stack and instruction pointers, 1210 map base address, etc.
[0180] The TSS represents a hardware-managed data structure in memory on a computer that can be used to store information about a task. For example, the TSS includes information necessary for the processing device 1200 to perform a task switch, such as stack pointers. Each TSS for a different task may include stack pointers to different stacks (e.g., data stacks used to store both control information and data) for different privilege levels. The stack pointers are used to identify the appropriate stack when the privilege level is changed by a task switch operation. For example, a task switch operation may include switching a current task at a current privilege level to a new task at a new privilege level.
[0181] In some embodiments, a shadow stack as described herein may be used to protect the data stack during privilege level transitions from a current task to a new task. As described above, the shadow stack is a second stack, separate from the data stack, that stores and protects information from the data stack used in control transfer operations. In one embodiment, shadow stack selection information, such as the shadow stack pointer 1530, may be stored in a TSS structure of a particular processor architecture (e.g., Intel Core i7, i5, and Xeon processors).
[0182] 15, an operating processing device responds to a task switch from a current task to a new task by identifying a TSS 1520 associated with the new task. In this regard, the task switch may be initiated by, for example, a call instruction, an interrupt / exception, or otherwise. In some embodiments, the processing device searches for an SSP 1530 stored in the TSS 1520. The SSP 1530 identifies a shadow stack 1510 to use with the new task.
[0183] In some embodiments, the processing device validates the SSP 1530 by performing a check using the busy validation and setting logic 1325 as described above. If the check is successful, the processing device marks the shadow stack 1310 as busy by setting a busy indicator in the token 1540. The processing device then pushes onto the new shadow stack a CS 1550 pointer that identifies the code segment of the current task being executed, an EIP 1560 that identifies return address information related to the current task, and an SSP 1570 that is associated with the current privilege level of the current task.
[0184] Upon returning from a new task to a previous task, the processing device verifies that such return is at the same address as the previous task. For example, the processing device verifies that the CS 1550 and EIP 1560 from the shadow stack 1510 match the corresponding values in the TSS associated with the previous task. If there is a match, the processing device removes or pops the CS 1550, EIP 1560, and SSP 1570 from the shadow stack 1510 to establish the current SSP used by the previous task. As part of the return transition to the previous task, the processing device, directed by the busy validation and clear logic 1335, checks whether the busy indicator of the token 1540 is set and whether the linear address of the token 1540 matches the address of the SSP 1530. If all of the above checks result in a correct indication, the processing device marks the token 1540 as "free" by clearing the busy indicator of the token 1540.
[0185] Certain architectures support operation at privilege levels 1 or 2 (CPL==1 or CPL==2), but these privilege rings are not used by some operating systems. Additionally, certain architectures do not support interrupt / exception delivery by handlers operating at privilege levels greater than 0. While the remainder of this detailed description focuses on interactions within privilege ring 0, the underlying principles of the invention are not limited to operation at any particular privilege level.
[0186] An embodiment of the processing device supports a fast return and event delivery (FRED) implementation that targets significantly speeding up the interrupt / exception delivery architecture of modern 64-bit operating systems. In particular, this embodiment replaces delivery via the interrupt descriptor table (IDT), thereby removing the burden of memory accesses and descriptor tables required to find the event handler's code and stack segment selectors and pointers. Additionally, the deprecation of ring 1 and 2 event / exception delivery reduces latency as event delivery microcode and / or circuitry do not need to consider these paths. Finally, an embodiment provides separate instructions for returning to user space and supervisor space for low latency and optimal microcode implementation.
[0187] In one embodiment, when multiple shadow stacks are used, there is only one shadow stack available at a given time (the current shadow stack). As noted above, a pointer to the top of the current shadow stack is held in the Shadow Stack Pointer (SSP) 1320. To support switching between shadow stacks on a privilege switch, one embodiment of the processor includes the following Model Specific Registers (MSRs): 1. IA32_PL3_SSP 2. IA32_FRED_SSP0 3. IA32_FRED_SSP1 4. IA32_FRED_SSP2 5. IA32_FRED_SSP3 In one embodiment, the IA32_PL3_SSP MSR holds the SSP value established when transitioning to CPL 3. The IA32_FRED_SSPi holds the SSP value established when transitioning to CPL 0 for interrupt or event delivery.
[0188] FIG. 16 illustrates an embodiment in which the event handling circuit / logic 1690 selects an SSP MSR 1600-1604 with a pointer to a shadow stack 1640-1644, respectively, based on the priority level of the interrupt / exception 1694 and the current privilege level 1696. In this embodiment, the interrupts and exceptions 1694 are categorized into one of four priority levels, 0-3, with 0 being the lowest priority and 3 being the highest priority. When an event needs to be handled, the event handling circuit / logic 1690 delivers the event at the stack level set to that level ("i") by switching the SSP to the value of the corresponding IA32_FRED_SSPi MSR. For example, in response to a priority level 2 interrupt or exception 1694, the shadow stack pointer from the FRED SSP2 MSR 1602 is selected to identify the supervisor shadow stack SS2 1642 (depending on the current privilege level 1696, as described below). However, if the processor is already processing an event classified to be delivered at a higher stack level than the currently active stack level, the processor will remain in the current stack.
[0189] The remainder of this description assumes a switch to the shadow stack of stack level "i" where an event / interrupt needs to be delivered. In one embodiment, each of the FRED SSPi MSRs 1600-1603 stores the following bit field definitions: · Bit 0 - Validated (V) - Indicates whether the MSR points to a validated supervisor-shadow-stack token (see below). Bits 2:1 - reserved (set to 0) · Bits 63:3 - Linear address of a valid supervisor shadow stack token on the supervisor shadow stack.
[0190] In one embodiment, the event handling circuit / logic 1690 selects a pointer from one of the SSP MSRs 1600-1603 that identifies a new supervisor shadow stack 1640-1643 if an event 1694 arrives when the processor is running in user mode at CPL3 (i.e., as indicated by current privilege level 1694), or if the processor is already running in supervisor mode at CPL0 and the event 1694 needs to be delivered at a higher stack level, respectively. Thus, assuming shadow stacks are enabled at CPL3 (user mode) and CLP0 (supervisor mode), the SSP is saved in the PL3 SSP 1604 (i.e., when booting in user mode) and a shadow stack is established for supervisor mode using the SSP address in the selected FRED SSPi MSRs 1600-1603, where i is the stack level to be switched to as identified by the priority of the event 1694 to be delivered.
[0191] When a supervisor mode interim SSP is selected from one of the FRED SSPi MSRs 1600-1603 as the PL0 SSP 1650, the validation and usage check circuit / logic 1695 verifies that (1) the SSP programmed in the selected SSP MSRs 1600-1603 points to the top of the corresponding Supervisor Shadow Stack 1640-1643, respectively, and (2) the Supervisor Shadow Stack 1640-1643 that this interim SSP 1602 points to is not already active in another logical processor, as indicated by the busy bit (B). If both checks pass, the FRED SSPi MSR 1602 becomes the new privilege level 0 (PL0) SSP 1650.
[0192] These checks are performed to prevent cross-thread attacks where an attacker could point MSRs on two logical processors to the same shadow stack and manipulate the return address consumed on one logical processor by making a call on the second logical processor.
[0193] In one embodiment, to perform these checks, the system software places a supervisor shadow stack token 1650-1653 at the top of each supervisor shadow stack. In one particular implementation, the supervisor shadow stack tokens 1650-1653 are formatted as follows: Bits 63:3 - Linear address of the token on the shadow stack Bits 2:1 - reserved (set to 0) Bit 0 - Busy (B). If this bit is 0, the selected shadow stack 1640-1643 is not loaded onto any logical processor.
[0194] 17 shows the supervisor shadow stack 1642 with the supervisor shadow stack token 1652. PL0_SSP 1650 holds a linear address 0x1008 that points to the top of the supervisor shadow stack 1642, which holds the supervisor shadow stack token 1652. When the system software creates this shadow stack, a busy flag 1701 (bit 0) is initialized to 0.
[0195] A method according to one embodiment of the present invention is illustrated in Figure 18. The method can be implemented on the processor and system architectures described herein, but is not limited to any particular architecture.
[0196] At 1801, a system event (e.g., an interrupt) is received at the current privilege level at priority i. At 1802, a determination is made as to whether a change to the shadow stack pointer at privilege level 0 is required. As noted above, a change is required if the event arrives when the processor is running in user mode at CPL 3, or if the processor is already running in supervisor mode at CPL 0 and the event needs to be delivered at a higher stack level. If no change is required, the process remains at its current privilege level with its current SSP at 1810.
[0197] If a change is required, then at 1803, an interim SSP is selected based on the priority (i) of the event. For example, the interim SSP may be selected from SSP MSRi. At 1804, validation and busy checks are performed in the interim SSP. For example, the token at the top of the shadow stack may be compared to the interim SSP and a busy bit may be checked to ensure that the shadow stack identified by the interim SSP is not loaded on other logical processors. If any of these checks, as determined at 1805, fail, then a fault / exception is generated at 1811.
[0198] If both checks pass at 1805, then at 1806 the shadow stack pointer for privilege level 0 is set to the interim SSP. The current privilege level may also change. At 1807 the event is processed at the current privilege level, using the new SSP PL0 value. The process then returns to 1801 when the next system event is received.
[0199] In one embodiment, the validation and usage check circuit / logic 1690 and validation and busy check 1804 operate to ensure that if the MSR is marked as not validated, the shadow stack (e.g., FRED SSP2 1602) can only be loaded into one logical processor at any time ("check 1" in the code sequence above). Additionally, these embodiments ensure that the shadow stack pointer in the MSR points to a valid supervisor shadow stack token at the top of the stack ("check 2" in the code sequence above).
[0200] In one embodiment, the following code sequence is executed to validate the token and set the shadow stack pointer SSP to the address in the token:
number
[0201] Note that if the MSR is not marked as validated, these checks can be performed atomically using a locked read-modify-write, as shown by Atomic-Start and Atomic-End in the code sequence above, which acquires a lock on the cache line, then releases the acquired lock. If these checks are successful, the token is marked as busy and the MSR is marked as validated.
[0202] In one embodiment, once an MSR is marked as verified, subsequent invocations of these operations do not perform any further locked read-modify-write operations. Rather, if an MSR is already marked as verified, the same two checks can be performed by loading the token from memory without acquiring a lock on the cache line holding the token. In one embodiment, to avoid the verified bit being set in the MSR accidentally or maliciously, the instruction used to write this MSR always ignores the verified bit (e.g., bit 0) of the written value and unconditionally clears the verified bit to 0. Such instructions include, but are not limited to, the WRMSR instruction (write model-specific MSR) and the XRSTORS instruction (restore processor supervisor mode extended state from memory).
[0203] 19 illustrates one embodiment of a method for selecting between atomic and non-atomic operations based on a validated bit. At 1901, a system event, such as an interrupt, is received at priority level i. At 1902, a check is made to determine if the validated bit (e.g., SSPi=0) is 0 (i.e., not validated). If the validated bit is 0, then a set of atomic operations is initiated at 1903. The busy bit is checked at 1904. If it is set to 0, then the shadow stack token is compared to the temporary SSP at 1905. If they match, the atomic operations are completed at 1906. The validated bit is set to 1 at 1907 and the temporary shadow stack pointer (SSPi) becomes the current shadow stack pointer (SSP) at 1908.
[0204] Returning to 1904, if the busy bit is set to 1 (meaning the shadow stack is being used by another logical processor) or if, at 1905, the token does not match the temporary SSP, a fault condition is generated at 1913. Furthermore, if, at 1902, the validated bit is set to 1 (meaning the SSP is already validated), no atomic set of operations is required. The same two checks can be performed at 1914 (checking the busy bit) and 1915 (comparing the tokens). However, these operations are performed without acquiring locks on the cache lines that hold the required data. For example, performance is improved because no locks are acquired on the cache line that stores the token, allowing other operations to continue simultaneously.
[0205] The processor may switch out of the supervisor shadow stack (e.g. PL0 SSP 1650) when returning to user mode (CPL3) when returning from handling an interrupt / exception, or when in supervisor mode returning to an interrupted procedure that was executing at a lower stack level than the stack level at which the event was handled.
[0206] The operating system as part of handling an event / interrupt may also perform a context switch. In one embodiment, a context switch causes a write to the FRED_SSPi MSR to update the shadow stack pointer associated with one or more priority levels. In such a case, the write to the FRED_SSPi MSR clears the MSR's verified bit to 0.
[0207] Thus, in one embodiment, three cases can occur upon return from an event handler. (1)FRED_SSPi=SSP|1: - The SSP matches the MSR value (the SSP is at the bottom of the stack) and the MSR is verified -Do nothing (2) FRED_SSPi = SSP -SSP matches MSR value but MSR is not verified -Check the token to see if the MSR can be revalidated. (3)FRED_SSPi[63:1]≠SSP[63:1] -SSP does not match MSR. Reset and release the token to clear MSR validation -This operation requires an atomic read-modify-write as described above.
number
[0208] Thus, if the MSR points to a valid and busy supervisor shadow stack token, the MSR is marked as validated. This operation is the most frequent case and does not require locked operations, improving performance. If the MSR does not point to a valid and busy supervisor shadow stack token on the current shadow stack, and if there is a busy supervisor shadow stack token on the current shadow stack, that token is released. This operation is performed using locked operations to ensure consistency and security.
[0209] After clearing the token, if the processor returns to user mode (CPL3), it establishes a user mode shadow stack pointer from PL3_SSP 1604. If the processor returns to the interrupted procedure in supervisor mode (CPL0), the shadow stack pointer of the interrupted procedure is restored (e.g., using the FRED SSP0 pointer).
[0210] Note that a WRMSR or XRSTORS instruction that writes to the FRED_SSPi MSR clears the validated bit of that MSR to 0. However, a Virtual Machine Manager (VMM) or hypervisor must context switch the state of these MSRs on a Virtual Machine (VM) switch. In this embodiment, a VM context switch should not cause the validated state of these MSRs to be lost.
[0211] In one embodiment, to handle this case when a VM exit occurs, the processor saves the FRED_SSPi MSRs with the validated bits in a Virtual Machine Control Structure (VMCS). On one of the subsequent VM entries, the processor restores the state of these MSRs with the validated bits from the VMCS.
[0212] example
[0213] Below are exemplary implementations of different embodiments of the present invention.
[0214] [Example 1] A processor comprising: a plurality of registers for storing a plurality of shadow stack pointers (SSPs), each SSP associated with a different event priority; an event processing circuit for selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers in response to receiving a first event associated with a first event priority level, the first SSP being usable to identify the top of a first shadow stack; and a validation and usage check circuit for determining whether the first SSP has been previously validated; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and verify that the first SSP is not in use, the series of atomic operations using a locking operation that locks data until the series of atomic operations is completed; and if the first SSP has been previously validated, revalidating the first SSP and verifying that the first SSP is not in use without using a locking operation.
[0215] [Example 2] A processor as described in Example 1, wherein the multiple SSPs include multiple supervisor SSPs including a first SSP that point to corresponding multiple supervisor shadow stacks associated with supervisor privilege levels.
[0216] [Example 3] A processor as described in Example 2, wherein the multiple SSPs further include at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level.
[0217] [Example 4] A processor as described in Example 1, wherein the first event includes a first interrupt or a first exception associated with a first event priority level.
[0218] [Example 5] A processor as described in Example 4, wherein multiple SSPs are associated with corresponding multiple event priority levels.
[0219] [Example 6] A processor as described in Example 1, wherein verifying that the first SSP is not in use includes checking a value of a busy bit associated with the first SSP.
[0220] [Example 7] A processor as described in Example 6, wherein validating and revalidating the first SSP includes comparing the first SSP with a first token value stored at the top of the first shadow stack.
[0221] [Example 8] A processor as described in Example 7, further comprising an execution circuit that executes one or more instructions at a first supervisor privilege level associated with the first data stack using a first data stack associated with the first shadow stack.
[0222] [Example 9] A processor as described in Example 8, wherein the event processing circuit and the verification and usage check circuit include portions of the processor's instruction execution pipeline, the verification and usage check circuit includes a first portion of the instruction execution pipeline for executing a first series of instructions related to SSP verification and usage check, and the event processing circuit includes a second portion of the instruction execution pipeline for executing a second series of instructions related to event processing.
[0223] [Example 10] A method comprising: storing multiple shadow stack pointers (SSPs) in corresponding multiple registers, each SSP associated with a different event priority; selecting a first SSP of the multiple SSPs from a first register of the multiple registers in response to receiving a first event associated with a first event priority level, the first SSP being usable to identify the top of a first shadow stack; and determining whether the first SSP has been previously validated; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and verify that the first SSP is not in use, the series of atomic operations using a locking operation that locks data until the series of atomic operations is completed; and if the first SSP has been previously validated, re-validating the first SSP and verifying that the first SSP is not in use without using a locking operation.
[0224] [Example 11] The method described in Example 10, wherein the multiple SSPs include multiple supervisor SSPs including a first SSP that point to corresponding multiple supervisor shadow stacks associated with supervisor privilege levels.
[0225] [Example 12] The method described in Example 11, wherein the multiple SSPs further include at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level.
[0226] [Example 13] The method described in Example 10, wherein the first event includes a first interrupt or a first exception associated with a first event priority level.
[0227] [Example 14] The method described in Example 13, wherein multiple SSPs are associated with multiple corresponding event priority levels.
[0228] [Example 15] The method described in Example 10, wherein verifying that the first SSP is not in use includes checking a value of a busy bit associated with the first SSP.
[0229] [Example 16] The method described in Example 15, wherein verifying and reverifying the first SSP includes comparing the first SSP with a first token value stored at the top of the first shadow stack.
[0230] [Example 17] The method described in Example 16, further comprising executing one or more instructions using a first data stack associated with a first shadow stack at a first supervisor privilege level associated with the first data stack.
[0231] [Example 18] A machine-readable medium having program code stored thereon, the program code, when executed by the machine, causing the machine to perform the following operations: storing a plurality of shadow stack pointers (SSPs) in a corresponding plurality of registers, each SSP being associated with a different event priority; in response to receiving a first event associated with a first event priority level, selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers, the first SSP being usable to identify the top of the first shadow stack; and determining whether the first SSP has been previously validated; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and verifying that the first SSP is not in use, the series of atomic operations using a locking operation that locks the data until the series of atomic operations is completed; and if the first SSP has been previously validated, re-validating the first SSP and verifying that the first SSP is not in use without using a locking operation. The machine-readable medium.
[0232] [Example 19] A machine-readable medium as described in Example 18, wherein the multiple SSPs include multiple supervisor SSPs including a first SSP that point to corresponding multiple supervisor shadow stacks associated with supervisor privilege levels.
[0233] [Example 20] The machine-readable medium of Example 19, wherein the multiple SSPs further include at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level.
[0234] [Example 21] A machine-readable medium as described in Example 18, wherein the first event includes a first interrupt or a first exception associated with a first event priority level.
[0235] [Example 22] The machine-readable medium of Example 21, wherein multiple SSPs are associated with corresponding multiple event priority levels.
[0236] [Example 23] A machine-readable medium as described in Example 18, wherein verifying that the first SSP is not in use includes checking a value of a busy bit associated with the first SSP.
[0237] [Example 24] A machine-readable medium as described in Example 23, wherein verifying and re-verifying the first SSP includes comparing the first SSP with a first token value stored at the top of the first shadow stack.
[0238] [Example 25] A machine-readable medium as described in Example 24, further comprising program code for causing a machine to perform the operation of executing one or more instructions at a first supervisor privilege level associated with the first data stack using a first data stack associated with the first shadow stack.
[0239] In the foregoing specification, embodiments of the invention have been described with reference to certain exemplary embodiments thereof. It will be apparent, however, that various modifications and changes can be made thereto without departing from the broader spirit and scope of the invention as set forth in the appended claims. The specification and drawings are therefore to be regarded in an illustrative rather than a restrictive sense.
[0240] An embodiment of the present invention may include various steps as described above. The steps may be embodied in machine-executable instructions that may be used to cause a general-purpose or special-purpose processor to perform the steps. Alternatively, the steps may be performed by specific hardware components that contain hardwired logic for performing the steps, or by any combination of programmed computer components and custom hardware components.
[0241] As described herein, instructions may refer to a particular configuration of hardware, such as an application specific integrated circuit (ASIC) configured to perform a particular operation or having a predetermined function or software instructions stored in a memory embodied in a non-transitory computer readable medium. Thus, the techniques illustrated in the figures may be implemented using code and data stored and executed in one or more electronic devices (e.g., end stations, network elements, etc.). Such electronic devices store and communicate code and data (internally and / or with other electronic devices over a network) using computer machine readable media, such as non-transitory computer machine readable storage media (e.g., magnetic disks, optical disks, random access memory, read only memory, flash memory devices, phase change memory), and transient computer machine readable communication media (e.g., electrical, optical, acoustic, or other forms of propagated signals (carrier waves, infrared signals, digital signals, etc.)). Furthermore, such electronic devices typically include a set of one or more processors coupled to one or more other components, such as one or more memory devices (non-transitory machine readable storage media), user input / output devices (e.g., keyboards, touch screens, and / or displays), and network connections. The coupling of the set of processors and other components is typically via one or more buses and bridges (also referred to as bus controllers). The storage devices and signals carrying network traffic represent one or more machine-readable storage media and machine-readable communication media, respectively. Thus, the storage device of a given electronic device typically stores code and / or data for execution on the set of one or more processors of that electronic device. Of course, one or more portions of an embodiment of the invention may be implemented using different combinations of software, firmware, and / or hardware. Throughout this detailed description, for purposes of explanation, numerous specific details have been set forth in order to provide a thorough understanding of the invention.However, it will be apparent to those skilled in the art that the present invention may be practiced without some of these specific details. In certain instances, well-known structures and functions are not described in detail to avoid obscuring the subject matter of the present invention. Therefore, the scope and spirit of the present invention should be judged in terms of the following claims. (Item 1) A plurality of registers for storing a plurality of shadow stack pointers (SSPs), each SSP being associated with a different event priority; an event processing circuit for selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers in response to receiving a first event associated with a first event priority level, the first SSP being usable to identify a top of a first shadow stack; a verification and usage check circuit for determining whether the first SSP has been previously verified; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and ensure that the first SSP is not in use, the series of atomic operations using a locking operation to lock data until the series of atomic operations are completed; If the first SSP has been previously validated, the processor revalidates the first SSP to ensure that the first SSP has not been used without the locking operation. (Item 2) The processor of item 1, wherein the multiple SSPs include multiple supervisor SSPs including the first SSP, which point to corresponding multiple supervisor shadow stacks associated with supervisor privilege levels. (Item 3) The processor described in item 2, wherein the plurality of SSPs further includes at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level. (Item 4) The processor of item 1, wherein the first event includes a first interrupt or a first exception associated with the first event priority level. (Item 5) The processor of item 4, wherein the multiple SSPs are associated with a corresponding multiple event priority levels. (Item 6) The processor of item 1, wherein verifying that the first SSP is not in use includes checking a value of a busy bit associated with the first SSP. (Item 7) The processor of item 6, wherein validating and revalidating the first SSP includes comparing the first SSP with a first token value stored at the top of the first shadow stack. and an execution circuit for executing one or more instructions at a first supervisor privilege level associated with the first data stack using a first data stack associated with the first shadow stack. 8. The processor of claim 7, further comprising: (Item 9) The processor described in Item 8, wherein the event processing circuit and the verification and usage check circuit comprise portions of the processor's instruction execution pipeline, the verification and usage check circuit comprising a first portion of the instruction execution pipeline for executing a first series of instructions related to SSP verification and usage check, and the event processing circuit comprising a second portion of the instruction execution pipeline for executing a second series of instructions related to event processing. (Item 10) A plurality of shadow stack pointers (SSPs) are stored in corresponding registers, and each SSP is associated with a different event priority; selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers in response to receiving a first event associated with a first event priority level, the first SSP being usable to identify a top of a first shadow stack; determining whether the first SSP has been previously verified; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and ensure that the first SSP is not in use, the series of atomic operations using a locking operation to lock data until the series of atomic operations are completed; If the first SSP has been previously validated, then revalidating the first SSP to ensure that the first SSP has not been used without using the locking operation. (Item 11) The method of item 10, wherein the plurality of SSPs includes a plurality of supervisor SSPs including the first SSP that point to corresponding plurality of supervisor shadow stacks associated with supervisor privilege levels. (Item 12) The method of item 11, wherein the plurality of SSPs further includes at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level. (Item 13) The method of item 10, wherein the first event includes a first interrupt or a first exception associated with the first event priority level. (Item 14) The method of item 13, wherein the multiple SSPs are associated with a corresponding multiple event priority levels. (Item 15) The method of item 10, wherein verifying that the first SSP is not in use includes checking a value of a busy bit associated with the first SSP. (Item 16) The method described in Item 15, wherein verifying and re-verifying the first SSP includes comparing the first SSP with a first token value stored at the top of the first shadow stack. Executing one or more instructions at a first supervisor privilege level associated with the first data stack using a first data stack associated with the first shadow stack; 17. The method of claim 16, further comprising: (Item 18) A machine-readable medium having program code stored thereon, the machine being capable of executing the program code by the machine, storing a plurality of shadow stack pointers (SSPs) in a corresponding plurality of registers, each SSP being associated with a different event priority; selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers in response to receiving a first event associated with a first event priority level, the first SSP being usable to identify a top of a first shadow stack; determining whether the first SSP has been previously verified; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and ensure that the first SSP is not in use, the series of atomic operations using a locking operation to lock data until the series of atomic operations are completed; if the first SSP has been previously validated, revalidating the first SSP and verifying that the first SSP has not been used without using the locking operation; A machine-readable medium for performing the operations of: (Item 19) The machine-readable medium of item 18, wherein the multiple SSPs include multiple supervisor SSPs including the first SSP that point to corresponding multiple supervisor shadow stacks associated with supervisor privilege levels. (Item 20) The machine-readable medium of item 19, wherein the plurality of SSPs further includes at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level. (Item 21) The machine-readable medium of item 18, wherein the first event includes a first interrupt or a first exception associated with the first event priority level. (Item 22) The machine-readable medium of item 21, wherein the multiple SSPs are associated with a corresponding multiple event priority levels. (Item 23) The machine-readable medium of item 18, wherein verifying that the first SSP is not in use includes checking a value of a busy bit associated with the first SSP. (Item 24) The machine-readable medium of item 23, wherein verifying and re-verifying the first SSP includes comparing the first SSP with a first token value stored at the top of the first shadow stack. Using a first data stack associated with the first shadow stack, one or more instructions are executed at a first supervisor privilege level associated with the first data stack. 25. The machine-readable medium of item 24, further comprising program code for causing the machine to perform the following operations:
Claims
1. a plurality of registers for storing a plurality of Shadow Stack Pointers (SSPs), each SSP being associated with a different event priority; an event processing circuit for selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers in response to receiving a first event associated with a first event priority level, the first SSP being usable to identify a top of a first shadow stack; a verification and usage check circuit for determining whether the first SSP has been previously verified; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and ensure that the first SSP is not in use, the series of atomic operations using a locking operation to lock data until the series of atomic operations is completed; If the first SSP has been previously validated, the processor revalidates the first SSP to ensure that the first SSP has not been used without the locking operation.
2. 2. The processor of claim 1, wherein the plurality of SSPs includes a plurality of supervisor SSPs, including the first SSP, that point to corresponding plurality of supervisor shadow stacks associated with supervisor privilege levels.
3. 3. The processor of claim 2, wherein the plurality of SSPs further comprises at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level.
4. The processor of claim 1 , wherein the first event comprises a first interrupt or a first exception associated with the first event priority level.
5. The processor of claim 4 , wherein the plurality of SSPs are associated with a corresponding plurality of event priority levels.
6. 6. The processor of claim 1, wherein verifying that the first SSP is not in use comprises checking a value of a busy bit associated with the first SSP.
7. 7. The processor of claim 6, wherein validating and revalidating the first SSP comprises comparing the first SSP to a first token value stored at a top of the first shadow stack.
8. an execution circuit for executing one or more instructions at a first supervisor privilege level associated with the first data stack using a first data stack associated with the first shadow stack; The processor of claim 7 further comprising:
9. 9. The processor of claim 8, wherein the event processing circuitry and the validation and usage check circuitry comprise portions of an instruction execution pipeline of the processor, the validation and usage check circuitry comprising a first portion of the instruction execution pipeline for executing a first series of instructions related to SSP validation and usage check, and the event processing circuitry comprising a second portion of the instruction execution pipeline for executing a second series of instructions related to event processing.
10. storing a plurality of shadow stack pointers (SSPs) in a corresponding plurality of registers, each SSP being associated with a different event priority; selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers in response to receiving a first event associated with a first event priority level, the first SSP being operable to identify a top of a first shadow stack; determining whether the first SSP has been previously verified; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and ensure that the first SSP is not in use, the series of atomic operations using a locking operation that locks data until the series of atomic operations is completed; if the first SSP has been previously verified, re-verifying the first SSP to ensure that the first SSP has not been used without using the locking operation; The method includes:
11. 11. The method of claim 10, wherein the plurality of SSPs includes a plurality of supervisor SSPs, including the first SSP, that point to corresponding plurality of supervisor shadow stacks associated with a supervisor privilege level.
12. 12. The method of claim 11, wherein the plurality of SSPs further comprises at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level.
13. The method of any one of claims 10 to 12, wherein the first event comprises a first interrupt or a first exception associated with the first event priority level.
14. The method of claim 13 , wherein the multiple SSPs are associated with a corresponding multiple event priority levels.
15. The method according to any one of claims 10 to 14, wherein verifying that the first SSP is not in use comprises checking a value of a busy bit associated with the first SSP.
16. 16. The method of claim 15, wherein the steps of validating and revalidating the first SSP include comparing the first SSP to a first token value stored at the top of the first shadow stack.
17. executing one or more instructions at a first supervisor privilege level associated with the first data stack using a first data stack associated with the first shadow stack; 20. The method of claim 16, further comprising:
18. On the computer, storing a plurality of shadow stack pointers (SSPs) in a corresponding plurality of registers, each SSP being associated with a different event priority; selecting a first SSP of the plurality of SSPs from a first register of the plurality of registers in response to receiving a first event associated with a first event priority level, the first SSP being operable to identify a top of a first shadow stack; determining whether the first SSP has been previously verified; if the first SSP has not been previously validated, initiating a series of atomic operations to validate the first SSP and ensure that the first SSP is not in use, the series of atomic operations using a locking operation that locks data until the series of atomic operations is completed; if the first SSP has been previously validated, revalidating the first SSP to ensure that the first SSP has not been used without using the locking operation; A program that executes the following.
19. 20. The program of claim 18, wherein the plurality of SSPs includes a plurality of supervisor SSPs, including the first SSP, that point to corresponding plurality of supervisor shadow stacks associated with a supervisor privilege level.
20. 20. The program of claim 19, wherein the plurality of SSPs further comprises at least one user-level SSP that points to a user-level shadow stack associated with a user privilege level.
21. The program product of any one of claims 18 to 20, wherein the first event comprises a first interrupt or a first exception associated with the first event priority level.
22. 22. The program of claim 21, wherein the plurality of SSPs are associated with a corresponding plurality of event priority levels.
23. 23. The program of claim 18, wherein the step of verifying that the first SSP is not in use comprises checking a value of a busy bit associated with the first SSP.
24. 24. The program of claim 23, wherein the steps of validating and revalidating the first SSP include comparing the first SSP to a first token value stored at the top of the first shadow stack.
25. The computer includes: executing one or more instructions at a first supervisor privilege level associated with the first data stack using a first data stack associated with the first shadow stack; The program according to claim 24, further comprising:
26. A non-transitory machine-readable medium storing the program according to any one of claims 18 to 25.
Citation Information
Patent Citations
Method of pushing data on stack inside memory in digital computor and circuit executing stack operation in digital computor havingcommand and memory to be pipe-lined
JP1991206523A
Method and system for multiprocessing
JP2002312190A
Method for managing memory in digital computing device
JP2008542933A
Processor extensions to protect stacks during ring transitions
US20200089871A1
