Instruction execution method and device
By setting preset conditions in the processor, ensuring that the read memory instructions are executed after the branch instruction is parsed, the problem of poor defense of Cache delay-side channel attack based on inferred memory access in the existing technology is solved, and efficient Attack defense and reduces performance losses.
Patent Information
- Application Number
- CN201880091562.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-04-21
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2038-04-21
AI Technical Summary
The existing processors have poor defense effects when facing Cache delay-side channel attacks based on speculative memory access, and existing emergency evasion solutions will damage system performance.
By setting preset conditions in instruction execution, we ensure that out-of-order branch instructions are executed only after the specific control dependency resolution is completed, thereby avoiding changes in the Cache microstructure state caused by misinferencing execution, and thus defending against attacks.
Effective defense against Cache delay-side channel attacks based on inferred memory access improves data security, while at the same time, performance losses are small compared to the existing technology.
Smart Images

Figure CN111936968B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and in particular to an instruction execution method and device. Background Art
[0002] At present, speculative out-of-order execution is the basic technology for modern processors to develop instruction-level parallelism. The correct execution of any instruction must meet two points: first, the control dependency is satisfied, that is, the instruction is on the correct branch path; second, the data dependency is satisfied, that is, the source operand of the instruction is correctly obtained. Speculative out-of-order execution means that when the control dependency of an instruction has not been resolved, as long as its data dependency is determined to be satisfied, the instruction is speculatively executed. Of course, if the speculation is wrong, the instruction may be on the wrong branch path. After that, when the processor detects a speculation error, it cancels the instruction that was executed by mistake and re-executes it from the correct path, thereby ensuring the correctness of the program semantics.
[0003] On a processor with speculative out-of-order execution, instructions executed by mis-speculation will not change any architecturally defined software-visible state, but will change the micro-architectural state, such as physical register files and caches, and this micro-architectural state change will not be revoked when the mis-speculated instructions are revoked. In normal use of the system, since any micro-architectural state is not used and invisible to software, the micro-architectural state change caused by mis-speculation will not cause software operation errors. However, with the development of hacker technology, a method called "Cache Delay Side Channel Attack" can accurately detect changes in the cache micro-architectural state, resulting in a very threatening attack method against existing processors: Cache delay side channel attack based on speculative memory access. This type of attack, such as the Spectre attack, mainly uses mis-speculated memory access instructions to implement the attack. In principle, it is roughly divided into two steps: the first step is to construct a branch misprediction scenario so that the mis-speculated Load instruction on the wrong branch path accesses the data in the protected area; the second step is to use the data to construct an address index to access the cache, which will cause the cache microstructure state to change (for example, the corresponding cache line access changes from miss to hit), and then detect this change through the cache delay side channel to steal the protected data content. The current processors using speculative out-of-order execution technology are generally unable to resist cache delay side channel attacks based on speculative memory access in hardware.
[0004] In the prior art, the above attacks are mainly defended by the following two emergency avoidance solutions: In one solution, the system software, such as the operating system (OS), explicitly clears the branch target buffer (BTB) when the process switches to prevent attacks, but this solution will greatly damage the system performance. In another solution, binary code with branch barrier characteristics is generated for recompilation and for specific sensitive code segments. Since the industry has not yet released a compiler that automatically identifies sensitive code, programmers need to modify the source code to explicitly point out the sensitive code segments, but this is difficult to ensure that all programs and all sensitive code segments in the program are identified and recompiled.
[0005] In summary, the emergency avoidance solution adopted in the prior art has problems in terms of defense completeness and performance loss, and cannot effectively defend against cache delay side channel attacks based on speculative memory access. Summary of the invention
[0006] The embodiments of the present application provide an instruction execution method and device for effectively defending against cache latency side channel attacks based on speculative memory access.
[0007] In the first aspect, an instruction execution method is provided, in which an instruction execution device obtains a first instruction, determines each second instruction that meets a preset condition, the first instruction is an instruction to read memory, and the second instruction is a branch instruction for out-of-order execution. After determining that each second instruction that meets the preset condition has been parsed, the first instruction is executed. Since after each second instruction that meets the preset condition has been parsed, the erroneous speculation of executing the first instruction can be avoided, and thus the Cache microstructure state change caused by the erroneous speculation of executing the first instruction will not occur, therefore, the attacker cannot steal the data in the protected area through the Cache microstructure state change, thereby achieving effective defense against the Cache delay side channel attack based on speculative memory access.
[0008] In a possible design, in order to meet different levels of defense requirements, it can be achieved by setting different preset conditions. Optionally, the preset condition includes a control dependency relationship of a preset type with the first instruction. In this case, after the second instructions that have a control dependency relationship of a preset type with the first instruction are parsed, the first instruction can be executed without waiting for all the second instructions that have a control dependency relationship with the first instruction to be parsed. In order to meet higher-level defense requirements and further avoid erroneous speculation of executing the first instruction, optionally, the preset condition is that there is a control dependency relationship with the first instruction. In this case, it is necessary to wait for all the second instructions that have a control dependency relationship with the first instruction to be parsed before executing the first instruction.
[0009] In a possible design, before determining that the parsing of each second instruction that meets the preset condition is completed, it also includes: determining the value of the first variable according to the serial number of each second instruction that meets the preset condition; determining the value of the second variable according to the serial number of the unparsed second instruction or the value of the first variable in each second instruction that meets the preset condition. Further, the determination that the parsing of each second instruction that meets the preset condition is completed includes: if the value of the first variable is less than the value of the second variable, then determining that the parsing of each second instruction that meets the preset condition is completed. If the value of the first variable is greater than or equal to the value of the second variable, then determining that the parsing of each second instruction that meets the preset condition is not completed. In this way, it is possible to explicitly determine whether the first instruction has a control dependency risk based on the value of the first variable and the value of the second variable, and through a small amount of judgment logic before executing the first instruction, and then it can be ensured that the first instruction is executed when there is no control dependency risk in the first instruction, thereby effectively defending against cache delay side channel attacks based on speculative memory access.
[0010] In a possible design, in a third implementation of the first aspect, the value of the first variable is determined according to the sequence number of each second instruction that meets the preset condition, including: determining the sequence number of the second instruction with the largest sequence number among the second instructions that meet the preset condition as the value of the first variable; the value of the second variable is determined according to the sequence number of the unresolved second instruction or the value of the first variable among the second instructions that meet the preset condition, including: determining the sequence number of the second instruction with the smallest sequence number and unresolved among the second instructions that meet the preset condition as the value of the second variable; or, if it is determined that there is no unresolved second instruction among the second instructions that meet the preset condition, then adding one to the value of the first variable as the value of the second variable. In this way, by comparing the value of the first variable with the value of the second variable, it can be accurately determined whether each second instruction that meets the preset condition has been resolved, and then the first instruction is executed after each second instruction that meets the preset condition has been resolved, thereby effectively defending against cache delay side channel attacks based on speculative memory access.
[0011] In a possible design, the determination of the serial number of the second instruction with the smallest serial number and which has not been resolved among the second instructions that meet the preset conditions as the value of the second variable includes: after the second instruction with the smallest serial number and which has not been resolved is resolved, the serial number of the unresolved second instruction that is located after the second instruction with the smallest serial number and which has not been resolved is used as the value of the second variable. In this way, the value of the second variable is dynamically updated so that the value of the second variable always indicates the second instruction with the smallest serial number and which has not been resolved among the second instructions that meet the preset conditions, thereby ensuring the accuracy of determining whether the second instructions that meet the preset conditions have been resolved.
[0012] In a second aspect, an instruction execution device is provided, comprising an instruction fetcher, a decoder, a pre-execution buffer, a scheduler and an executor; the instruction fetcher is used to fetch instructions from an instruction cache; the decoder is used to decode the instructions and obtain a decoding result of the instructions; the decoding result includes an instruction type; the pre-execution buffer is used to store the instructions and the decoding results of the instructions; the scheduler is used to: if a first instruction is obtained from the pre-execution buffer, then: determine each second instruction that meets a preset condition, and after determining that the second instructions that meet the preset condition are parsed, send the first instruction to the executor; the first instruction is an instruction to read memory; the second instruction is a branch instruction for out-of-order execution; if a second instruction is obtained from the pre-execution buffer, send the second instruction to the executor; the executor is used to execute the first instruction and the second instruction.
[0013] The instruction execution device may be at least one processing element or chip.
[0014] In one possible design, the preset condition includes a control dependency relationship with the first instruction.
[0015] In one possible design, the preset condition includes a control dependency of a preset type with the first instruction.
[0016] In one possible design, the scheduler is also used to: determine the value of the first variable according to the serial numbers of each second instruction that meets the preset conditions; determine the value of the second variable according to the serial numbers of unparsed second instructions among the second instructions that meet the preset conditions or the value of the first variable; if the value of the first variable is less than the value of the second variable, it is determined that the parsing of the second instructions that meet the preset conditions is completed.
[0017] In one possible design, the scheduler is specifically used to: determine the serial number of the second instruction with the largest serial number among the second instructions that meet the preset conditions, as the value of the first variable; determine the serial number of the second instruction with the smallest serial number and unresolved among the second instructions that meet the preset conditions, as the value of the second variable; or, if it is determined that there are no unresolved second instructions among the second instructions that meet the preset conditions, then add one to the value of the first variable and use the value as the value of the second variable.
[0018] In one possible design, the scheduler is specifically used to: after the unresolved second instruction with the smallest serial number is resolved, use the serial number of the unresolved second instruction located after the unresolved second instruction with the smallest serial number as the value of the second variable.
[0019] In a third aspect, a chip is provided, which is connected to a memory and is used to read and execute a software program stored in the memory to implement the method described in the first aspect or any possible design.
[0020] In a fourth aspect, a readable storage medium is provided, wherein instructions are stored in the readable storage medium, and when the readable storage medium is run on a computer, the computer executes the method described in the first aspect or any possible design described above. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 A schematic diagram of a system architecture of a network device provided in an embodiment of the present application;
[0022] Figure 2 A schematic diagram of a possible processor structure provided in an embodiment of the present application;
[0023] Figure 3 A schematic diagram of a possible scheduler structure provided in an embodiment of the present application;
[0024] Figure 4 A flowchart of an instruction execution method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0025] The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application.
[0026] The present application provides a method for executing an instruction, which can be applied to Figure 1 The network device system architecture shown in Figure 1 is shown in Figure 1. Figure 1 As shown, a system architecture of a network device provided by an embodiment of the present application is shown. Figure 1 As shown, the system architecture 100 includes a memory 110, a processor 120 and a communication interface 130; wherein the memory 110, the processor 120 and the communication interface 130 are connected to each other.
[0027] The memory 110 may include a volatile memory, such as a random-access memory (RAM); the memory may also include a non-volatile memory, such as a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); the memory 110 may also include a combination of the above types of memory.
[0028] The processor 120 may be a central processing unit (CPU), a network processor (NP) or a combination of a CPU and a NP. The processor 120 may further include a hardware chip. The hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
[0029] The communication interface 130 may be a wired communication access port, a wireless communication interface or a combination thereof, wherein the wired communication interface may be, for example, an Ethernet interface. The Ethernet interface may be an optical interface, an electrical interface or a combination thereof. The wireless communication interface may be a WLAN interface.
[0030] Based on the above Figure 1 As shown in the system architecture, the instruction execution method provided in the present application can be implemented by some components in the processor 120.
[0031] In one possible design, the above Figure 1 The processor 120 shown may include various components. Figure 1 The system architecture shown in Figure 2 As shown in FIG. 1 , a possible processor structure diagram is provided in an embodiment of the present application. Figure 2 As shown, the processor 120 includes an instruction cache (Icache) 210, a pre-execution buffer 220, an instruction fetcher 230, a decoder 240, a scheduler 250, an executor 260, and an intermediate register 270. The intermediate register 270 is used to store the result of the speculatively executed instruction.
[0032] Among them, the instruction cache 210 stores various types of instructions, such as branch instructions, memory access instructions, and other types of instructions. The instruction fetcher 230 sequentially fetches instructions from the instruction cache 210 and passes them to the decoder 240. The decoder 240 obtains the type of each instruction, and then stores the instruction and its decoding information in the pre-execution buffer 220. For example, the decoder 240 decodes the four instructions fetched in sequence, and the decoding results are: the first instruction is a branch instruction, the second instruction is a memory access instruction, the third instruction is a branch instruction, and the fourth instruction is a memory access instruction.
[0033] Scheduler 250 may obtain instructions and their types from pre-execution buffer 220. After obtaining the instructions, scheduler 250 may also send each instruction to executor 260 for executing the instruction. Figure 1 As shown, the executor 260 includes other pipelines 261 and a memory access 262. The memory access 262 includes a memory access instruction queue 263. In a specific application, the memory access instruction includes two types: load instruction and store instruction, so the memory access instruction queue can also be called a Load / Store queue.
[0034] Specifically, if the instruction acquired by the scheduler 250 is a branch instruction, the branch instruction is sent to the other pipeline 261 for execution. If the instruction acquired by the scheduler 250 is a memory access instruction, the memory access instruction is sent to the memory access 262 for execution.
[0035] Since there are control dependencies and data dependencies between instructions, if the data dependency is not satisfied, the memory access instruction will not be executed. Therefore, the present application assumes that the data dependency is satisfied. When only the control dependency is considered, if the control dependency of a memory access instruction is not resolved, a cache delay side channel attack based on speculative memory access may occur during the speculative out-of-order execution process. In order to avoid such an attack, in the embodiment provided by the present application, if the instruction obtained by the scheduler 250 is a memory access instruction, after the parsing of each branch instruction with control dependency on the memory access instruction is completed, the memory access instruction is sent to the memory access 262 for execution. Optionally, if there are unresolved branch instructions in each branch instruction with control dependency on the memory access instruction, the memory access instruction is first stored in the pre-execution buffer 220 until the parsing of each branch instruction with control dependency on the memory access instruction is completed, and then the memory access instruction is scheduled from the pre-execution buffer 220 and sent to the memory access 262 for execution.
[0036] After receiving the memory access instruction, the memory access device 262 may store the memory access instruction in the Load / Store queue, and execute each memory access instruction out of order when both the data dependency and the control dependency are satisfied.
[0037] For an instruction, after the processing of the above-mentioned instruction fetcher 230, decoder 240, scheduler 250, executor 260, etc., a pipeline including multiple pipeline stages is formed, and the pipeline includes pipeline stages such as instruction fetch, decoding, scheduling and execution. Among them, the instruction fetcher 230 corresponds to the instruction fetch pipeline stage, the decoder 240 corresponds to the decoding pipeline stage, the scheduler 250 corresponds to the distribution pipeline stage, and the executor 260 corresponds to the execution pipeline stage. Optionally, the pipeline can also include Figure 2 The rename, issue, write back, command, etc. pipeline stages shown (not shown in Figure 1 One or more of the devices related to the water flow section are shown in the figure.
[0038] Based on the above Figure 2 In the embodiment of the present application, the instruction execution method is executed by the scheduler 250 in the processor 120. Figure 3 As shown, it is a schematic diagram of a scheduler structure provided in an embodiment of the present application.
[0039] like Figure 3 As shown, the scheduler 250 includes an acquisition module 310, a determination module 320 and an execution module 330. Among them:
[0040] The acquisition module 310 is used to acquire instructions from the pre-execution buffer 220. Optionally, the acquired instructions include branch instructions, memory access instructions and other types of instructions.
[0041] The determination module 320 is used to determine a second instruction that meets a preset condition after the acquisition module 310 acquires the first instruction, wherein the first instruction is an instruction to read memory, and the second instruction is a branch instruction for out-of-order execution.
[0042] The execution module 330 is used to execute the first instruction after the scheduler 250 determines that the parsing of each second instruction that meets the preset condition is completed.
[0043] Combined with the above Figure 1 , Figure 2 and Figure 3 , the following is a detailed description of the instruction execution method provided in this application.
[0044] Based on the above description, Figure 4 An instruction execution method flow provided by the present application is exemplarily shown.
[0045] like Figure 4 As shown in the figure, the process specifically includes:
[0046] Step 401: the scheduler 250 obtains a first instruction, which is an instruction for reading a memory.
[0047] In the embodiment of the present application, the acquisition module 310 in the scheduler 250 acquires the first instruction, which may also be referred to as a load instruction, ie, a Load instruction.
[0048] In step 402 , the scheduler 250 determines each second instruction that meets a preset condition, where the second instruction is a branch instruction that is executed out of order.
[0049] Each second instruction is dispatched by the scheduler 250 to other pipelines 261 for out-of-order execution. During the execution of the second instruction, the scheduler 250 continues to dispatch subsequent instructions that arrive at the scheduler 250. The second instructions in other pipelines 261 can be executed out of order and do not need to be executed in the order of instruction fetching and decoding. For example, the three second instructions are second instruction 1, second instruction 2, and second instruction 3 in the order of instruction fetching and decoding. The execution in other pipelines 261 is as follows: if second instruction 1 is not executed, second instruction 2 and second instruction 3 can be executed first.
[0050] Step 403 , after the scheduler 250 determines that the parsing of each second instruction that meets the preset condition is completed, the first instruction is executed.
[0051] When the first instruction arrives at the scheduler 250, the determination module 320 in the scheduler 250 needs to determine whether the second instructions that meet the preset conditions have been parsed. If so, the first instruction is executed. The execution action refers to the execution module 330 in the scheduler 250 sending the first instruction to the register 262; if not, that is, there are unparsed second instructions, it is necessary to wait until the second instructions that meet the preset conditions are parsed before executing the first instruction.
[0052] For a first instruction, the first instruction is executed after the second instructions that meet the preset conditions are parsed. If there are multiple first instructions that need to be executed, the multiple first instructions can be executed out of order. For example, the second instructions that meet the preset conditions are first instruction A, first instruction B, and first instruction C in the order of arriving at the scheduler 250. After the first instruction A is sent to the memory access 262, the first instruction B is not parsed, but the first instruction C is parsed. Then the first instruction C is executed first, and after the first instruction B, the first instruction B is executed.
[0053] Through the solution provided by the above embodiment, since the erroneous speculation and execution of the first instruction can be avoided after the parsing of each second instruction that meets the preset conditions is completed, the cache microstructure state change caused by the erroneous speculation and execution of the first instruction will not occur. Therefore, the attacker cannot steal the data in the protected area through the cache microstructure state change, thereby achieving effective defense against cache delay side channel attacks based on speculative memory access.
[0054] In an optional implementation, the preset condition includes a control dependency relationship with the first instruction. That is, after the scheduler determines that each second instruction that has a control dependency relationship with the first instruction is parsed, the first instruction is executed.
[0055] It should be noted that, in addition to satisfying the condition that the control dependency has been resolved, whether the first instruction is executed also needs to satisfy the condition that the data dependency has been resolved. Since the correct source operand cannot be obtained when the data dependency of the first instruction is not resolved, the first instruction cannot be executed. Therefore, in the embodiment of the present application, the first instruction is executed by default, that is, the condition that the data dependency has been resolved is satisfied.
[0056] Combination Figure 2 As well as the above embodiments, a specific example of the instruction execution process is provided below.
[0057] For example, the instruction cache includes four instructions, namely instruction 1, instruction 2, instruction 3 and instruction 4.
[0058] First, the above four instructions are taken out from the instruction cache in sequence, and the decoding results are: instruction 1 is a branch instruction, instruction 2 is a Load instruction, instruction 3 is a branch instruction, and instruction 4 is a Load instruction.
[0059] Then, the above four instructions enter the scheduler 250 in sequence. When the scheduler 250 receives instruction 1, it sends the instruction 1 to other pipelines 261 for execution. When the scheduler 250 receives instruction 2, it finds that instruction 1 has been parsed at this time, that is, instruction 1 has been executed in other pipelines 261 and the execution result is obtained. At this time, instruction 2 is sent to the memory access 262. When the scheduler 250 receives instruction 3, it sends it to other pipelines 261 for execution. When the scheduler 250 receives instruction 4, it finds that instruction 3 is not parsed, that is, the control dependency of instruction 4 is not parsed at this time. Then how to process instruction 4? The following is a different description of the solution adopted by this application and the solution adopted by the prior art:
[0060] In the solution of the prior art, the control dependency of instruction 4 is not resolved at this time, and the scheduler 250 directly sends instruction 4 to the memory access device 262 for execution. If instruction 4 is executed by mis-speculation, the micro-structure state in the cache will be changed. The attacker can find the internal data through the changed micro-structure state, resulting in internal data leakage, posing a data security risk.
[0061] In the solution of the present application, the control dependency of instruction 4 is not resolved at this time, and the scheduler 250 will suspend the issuance of instruction 4. For example, instruction 4 can be stored in the pre-execution buffer 220 until instruction 3 is resolved, and the scheduler 250 then issues instruction 4 to the access register 262 for execution. During the suspension of the issuance of instruction 4, the execution of other instructions after instruction 4 will not be affected. Compared with the solution in the prior art, the solution of the present application can greatly improve data security. Although the efficiency of instruction execution will be reduced compared to the speculative out-of-order execution solution in the prior art, the impact of this performance reduction is far less than the solution for defending against attacks given in the background technology.
[0062] In order to meet different levels of defense requirements, this can be achieved by setting different preset conditions.
[0063] In an optional implementation, the preset condition includes a preset type of control dependency relationship with the first instruction, which can be a control dependency of a direct conditional branch jump, an indirect conditional branch jump, or other types of control dependency.
[0064] For example, only the control dependency of direct conditional branch jumps is tracked, that is, when the scheduler 250 determines that the branch instruction with direct conditional branch jump control dependency is parsed, the first instruction can be executed without waiting for all branch instructions with control dependency relationship with the first instruction to be parsed. In this case, variant 1 "boundary detection attack" of Spectre attack can be defended.
[0065] Another example is to only track the control dependency of indirect conditional branch jumps. That is to say, when the scheduler 250 receives the second instruction, if it is determined that the second instruction is a second instruction that meets the preset condition, that is, it is determined that the second instruction is a branch instruction that has a control dependency on the first instruction that has an indirect conditional branch jump, then it will track whether each branch instruction that has a control dependency on the first instruction that has an indirect conditional branch jump has been resolved. After the scheduler 250 determines that the branch instruction that has a control dependency on the first instruction that has an indirect conditional branch jump has been resolved, the first instruction can be executed without waiting for all branch instructions that have a control dependency relationship with the first instruction to be resolved. In this case, variant 2 "branch target injection" of the Spectre attack can be defended.
[0066] In order to meet higher-level defense requirements and further avoid the mis-speculation of the execution of the first instruction, optionally, the preset condition is that there is a control dependency relationship with the first instruction. In this case, it is necessary to wait for all second instructions that have a control dependency relationship with the first instruction to be parsed before the first instruction can be executed. Compared with the previous implementation, in this embodiment, it is necessary to determine whether all second instructions that have a control dependency relationship with the first instruction have been parsed. The number of second instructions that need to be tracked is greater than the number of second instructions of preset types that are only tracked, so the effect of defending against attacks is better.
[0067] In the embodiment of the present application, an optional implementation of the above Figure 4 The specific method is to set a memory access filter (Load Filter) in the scheduler 250, and to enable the filtering function of the Load Filter to defend against cache delay side channel attacks based on speculative memory access. Specifically, when different defense levels need to be set, the filtering functions corresponding to each defense level can be set. For example, by narrowing the types of branch instructions tracked by the Load Filter in the embodiment of the present application, the defense level can be adjusted as needed. Of course, the filtering function of the LoadFilter can also be turned off when there is no need to defend against cache delay side channel attacks based on speculative memory access. In this way, the second instruction that has a control dependency on the first instruction will not be tracked, and no logical impact will be generated on the pipeline.
[0068] Optionally, based on step 403 of the above embodiment, before determining that the parsing of each second instruction that meets the preset condition is completed, the scheduler 250 determines the value of the first variable according to the sequence number of each second instruction that meets the preset condition, and determines the value of the second variable according to the sequence number of the unparsed second instruction in each second instruction that meets the preset condition or the value of the first variable. Then, the scheduler 250 determines whether the parsing of each second instruction that meets the preset condition is completed according to the value of the first variable and the value of the second variable. Specifically, if the value of the first variable is less than the value of the second variable, the scheduler 250 determines that the parsing of each second instruction that meets the preset condition is completed. If the value of the first variable is not less than the value of the second variable, it is determined that the parsing of each second instruction that meets the preset condition is not completed. Optionally, the sequence number is determined according to the decoding order of each second instruction that meets the preset condition.
[0069] Through this optional embodiment, the scheduler 250 can explicitly determine whether the first instruction has a control dependency risk based on the value of the first variable and the value of the second variable, as well as through a small amount of judgment logic before executing the first instruction, and thus can ensure that the first instruction is executed when there is no control dependency risk for the first instruction, thereby effectively defending against cache delay side channel attacks based on speculative memory access.
[0070] Optionally, the scheduler 250 determines the value of the first variable according to the sequence numbers of the second instructions that meet the preset conditions, specifically including: the scheduler 250 determines the sequence number of the second instruction with the largest sequence number among the second instructions that meet the preset conditions as the value of the first variable. The scheduler 250 determines the value of the second variable according to the sequence number of the unparsed second instruction or the value of the first variable among the second instructions that meet the preset conditions, including any of the following two methods:
[0071] In a first approach, the scheduler 250 determines the sequence number of the second instruction with the smallest sequence number and which has not been resolved among the second instructions that meet the preset condition, and uses the sequence number as the value of the second variable.
[0072] In a second method, if the scheduler 250 determines that there is no unresolved second instruction among the second instructions satisfying the preset condition, the value of the first variable is increased by 1 to be used as the value of the second variable.
[0073] If there is an unparsed second instruction among the second instructions that meet the preset condition, the determination module 320 in the scheduler 250 determines the value of the second variable according to method 1, and if there is no unparsed second instruction among the second instructions that meet the preset condition, the determination module 320 in the scheduler 250 determines the value of the second variable according to method 2. Through the above embodiment, the determination module 320 in the scheduler 250 can accurately determine whether the second instructions that meet the preset condition are parsed by comparing the value of the first variable with the value of the second variable, and then execute the first instruction after the second instructions that meet the preset condition are parsed, thereby effectively defending against cache latency side channel attacks based on speculative memory access.
[0074] Optionally, based on the above-mentioned method 1, the scheduler 250 determines the serial number of the second instruction with the smallest serial number and which has not been resolved among the second instructions that meet the preset conditions as the value of the second variable, which specifically includes: after the second instruction with the smallest serial number and which has not been resolved is resolved, the determination module 320 in the scheduler 250 uses the serial number of the unresolved second instruction located after the second instruction with the smallest serial number and which has not been resolved as the value of the second variable. In this way, by dynamically updating the value of the second variable, the value of the second variable always indicates the second instruction with the smallest serial number and which has not been resolved among the second instructions that meet the preset conditions, thereby ensuring the accuracy of determining whether the second instructions that meet the preset conditions have been resolved.
[0075] In a specific embodiment of the present application, two globally accessible registers can be added to the processor for speculative out-of-order execution to track the parsing status of each second instruction, where the parsing status includes parsed and unparsed. The following takes the first instruction as a Load instruction and the second instruction as a branch instruction as an example, and describes it in detail in combination with a specific embodiment.
[0076] To implement the solution in this application, the pipeline logic added to each pipeline stage of processing instructions is shown in Table 1 below.
[0077] Table 1
[0078]
[0079] As shown in Table 1, the pipeline includes eight pipeline stages: fetch, decode, rename, dispatch, issue, execute, write back, and commit.
[0080] First, two globally accessible registers are added to the processor 120 for speculative out-of-order execution, and their functions are:
[0081] The first register maintains a first variable in the dispatch pipeline stage. The first variable records the latest dispatched branch sequence number (LBrSN). Whenever a branch instruction is dispatched, the value of LBrSN is increased by 1.
[0082] The second register maintains a second variable in the execution pipeline stage, and the second variable records the oldest unresolved branch sequence number (NRBrSN). If the branch order buffer (BOB) is empty, or all branch instructions that meet the preset conditions have been resolved, the value of NRBrSN is equal to the value of LBrSN plus one; if a branch instruction that meets the preset conditions is found in the BOB and is not resolved, NRBrSN points to the oldest unresolved branch number.
[0083] In specific applications, as the branch instruction parsing is completed, the NRBrSN value will continue to be updated for multiple cycles.
[0084] For example, in the current cycle, if the branch instruction currently pointed to by NRBrSN has been resolved, then search backwards along the BOB until the next unresolved branch instruction is found. If the next unresolved branch instruction is far away, such as across multiple BOB entries, the next unresolved branch instruction may not be found in the current cycle. For example, at the end of the current cycle, the 20th branch instruction in the BOB has been found and the branch instruction has been resolved, then the next cycle can continue to search backwards from the 21st branch instruction in the BOB until the unresolved branch instruction is found or the end of the BOB is reached.
[0085] If NRBrSN does not point to an unresolved branch instruction during the above multiple cycles of searching for unresolved branch instructions, this will not cause functional errors, but will only delay the issuance of the corresponding Load instruction for a few cycles, that is, it is necessary to wait until all branch instructions related to the Load instruction are resolved before execution.
[0086] Secondly, as shown in Table 1, for each Load instruction, logic maintenance load.BrSN is added to the Load instruction in the distribution pipeline stage, and the value of LBrSN is assigned to load.BrSN.
[0087] If the value of load.BrSN corresponding to the Load instruction is less than NRBrSN, it means that all branch instructions that have a control dependency relationship with the Load instruction have been resolved, and there is no control dependency risk when executing the Load instruction.
[0088] Again, in the emission pipeline stage, an explicit judgment on whether the control dependency has been resolved is added to the emission logic of the Load instruction, that is, the value of load.BrSN of the Load instruction is less than the value of NRBrSN, and it is determined that the control dependency of the Load instruction has been resolved.
[0089] The issuing logic of the Load instruction in the prior art is: if the data dependency is resolved, that is, the register dependency and the write-read dependency are satisfied, the Load instruction is issued.
[0090] In the embodiment of the present application, the issuing logic of the Load instruction needs to satisfy not only that the data dependency has been resolved, but also that the control dependency has been resolved, such as the issuing logic in Table 1: if (reg_dep_ok&mem dep ok&load.BrSN<NRBrSN)issue load.
[0091] In this way, the speculative access of the Load no longer has the risk of control dependency, which is sufficient to resist cache latency side channel attacks based on speculative memory access, such as Spectre attacks. Moreover, when the pipeline is flushed, such as pipeline flushing caused by branch misprediction, the above LBrSN, NRBrSN and load.BrSN do not require additional recovery logic, and will not affect the processing efficiency of instructions.
[0092] In combination with Table 1 and the above embodiments, a specific embodiment is provided below.
[0093] For example, assuming that when Load instruction A is scheduled, the three instructions distributed before Load instruction A are distributed in the following order: branch instruction 1, branch instruction 2, and branch instruction 3, among which branch instruction 1 has been resolved, branch instruction 2 has not been resolved, and branch instruction 3 has been resolved.
[0094] The update status of LBrSN value is as follows: when branch instruction 1 enters the distribution pipeline stage, LBrSN=1; when branch instruction 2 enters the distribution pipeline stage, LBrSN=2; when branch instruction 3 enters the distribution pipeline stage, LBrSN=3; when memory access instruction A enters the distribution pipeline stage, load.BrSN=3.
[0095] The value of NRBrSN is updated as follows:
[0096] When Load instruction A is scheduled, since branch instruction 1 has been resolved, branch instruction 2 has not been resolved, and branch instruction 3 has been resolved, NRBrSN = 2. Therefore, it can be directly determined that the control dependency of Load instruction A has not been resolved based on the value of load.BrSN being greater than the value of NRBrSN, and the execution of Load instruction A is suspended.
[0097] When branch instruction 2 is parsed, since branch instruction 3 has been parsed and there is no branch instruction after branch instruction 3 that has a control dependency relationship with the Load instruction A, NRBrSN = 4. Therefore, it can be directly determined that the control dependency of the Load instruction A has been parsed based on load.BrSN being less than load.BrSN, and the Load instruction A is executed.
[0098] Through the above-mentioned embodiments, only a small amount of pipeline logic needs to be added to the processor of speculative out-of-order execution. There is no need to rely on programmers and compilers to recompile programs, and there is no need to clear the branch target buffer (BTB) during the software switching process. Therefore, compared with the solutions provided in the prior art, it can not only effectively defend against cache delay side channel attacks based on speculative memory access, but also significantly reduce performance losses.
[0099] In the implementation of the present application, the above-mentioned processor can also be a chip, which is connected to the memory and is used to read and execute the software program stored in the memory to implement the execution method in any of the above-mentioned embodiments.
[0100] The embodiments of the present application also provide a computer storage medium for storing computer software instructions used for executing the above instructions, which includes program codes designed for executing the above method embodiments.
[0101] Those skilled in the art should understand that the embodiments of the present application can be provided as methods, devices (equipment), computer-readable storage media or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware, which are collectively referred to as "modules" or "systems" herein.
[0102] The present application is described with reference to the flowcharts and / or block diagrams of the methods, apparatuses (devices) and computer program products of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0103] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0104] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0105] Although the present invention has been described in conjunction with specific features and embodiments thereof, it is apparent that various modifications and combinations may be made thereto without departing from the spirit and scope of the present invention. Accordingly, this specification and the accompanying drawings are merely exemplary illustrations of the present invention as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of the present invention. Obviously, those skilled in the art may make various modifications and variations to the present invention without departing from the spirit and scope of the present invention. Thus, the present invention is intended to include such modifications and variations if they fall within the scope of the claims of the present invention and their equivalents.
Claims
1. A method for executing an instruction, characterized in that: include: Get the first instruction; The first instruction is an instruction for reading memory; Determine each second instruction that meets a preset condition; the second instruction is a branch instruction that is executed out of order; the preset condition includes a control dependency relationship with the first instruction; After determining that the parsing of each second instruction that meets the preset condition is completed, executing the first instruction.
2. The method according to claim 1, characterized in that The preset condition includes a control dependency relationship of a preset type with the first instruction.
3. The method according to claim 1, characterized in that Before determining that the parsing of each second instruction that meets the preset condition is completed, the method further includes: Determining the value of the first variable according to the sequence number of each second instruction that meets the preset condition; Determining the value of the second variable according to the sequence number of the unresolved second instruction or the value of the first variable among the second instructions that meet the preset condition; The step of determining that the parsing of each second instruction satisfying the preset condition is completed includes: If the value of the first variable is less than the value of the second variable, it is determined that the parsing of each second instruction that meets the preset condition is completed.
4. The method according to claim 3, characterized in that Determining the value of the first variable according to the sequence numbers of the second instructions that meet the preset condition includes: Determine the sequence number of the second instruction with the largest sequence number among the second instructions that meet the preset condition, as the value of the first variable; The determining the value of the second variable according to the sequence number of the unresolved second instruction or the value of the first variable among the second instructions that meet the preset condition comprises: Determine the serial number of the second instruction with the smallest serial number and which has not been resolved among the second instructions that meet the preset conditions, and use it as the value of the second variable; or, if it is determined that there is no unresolved second instruction among the second instructions that meet the preset conditions, add one to the value of the first variable, and use it as the value of the second variable.
5. The method according to claim 4, characterized in that The step of determining the sequence number of the second instruction with the smallest sequence number and which has not been resolved among the second instructions that meet the preset condition as the value of the second variable includes: After the unresolved second instruction with the smallest serial number is resolved, the serial number of the unresolved second instruction after the unresolved second instruction with the smallest serial number is used as the value of the second variable.
6. An instruction execution device, characterized in that: Includes instruction fetcher, decoder, pre-execution buffer, scheduler and executor; The instruction fetcher is used to fetch instructions from the instruction cache; The decoder is used to decode the instruction to obtain a decoding result of the instruction; the decoding result includes an instruction type; The pre-execution buffer is used to store the instruction and the decoding result of the instruction; The scheduler is used to: If the first instruction is obtained from the pre-execution buffer, then: determine each second instruction that meets the preset condition, and after determining that the second instructions that meet the preset condition are parsed, send the first instruction to the executor; the first instruction is an instruction to read the memory; the second instruction is a branch instruction for out-of-order execution; the preset condition includes a control dependency relationship with the first instruction; If a second instruction is obtained from the pre-execution buffer, sending the second instruction to the executor; The executor is used to execute the first instruction and the second instruction.
7. The device according to claim 6, characterized in that The preset condition includes a control dependency relationship of a preset type with the first instruction.
8. The device according to claim 6, characterized in that The scheduler is also used to: Determining the value of the first variable according to the sequence number of each second instruction that meets the preset condition; Determining the value of the second variable according to the sequence number of the unresolved second instruction or the value of the first variable among the second instructions that meet the preset condition; If the value of the first variable is less than the value of the second variable, it is determined that the parsing of each second instruction that meets the preset condition is completed.
9. The device according to claim 8, characterized in that The scheduler is specifically used for: Determine the sequence number of the second instruction with the largest sequence number among the second instructions that meet the preset condition, as the value of the first variable; Determine the serial number of the second instruction with the smallest serial number and which has not been resolved among the second instructions that meet the preset conditions, and use it as the value of the second variable; or, if it is determined that there is no unresolved second instruction among the second instructions that meet the preset conditions, add one to the value of the first variable, and use it as the value of the second variable.
10. The device according to claim 9, characterized in that The scheduler is specifically used for: After the unresolved second instruction with the smallest serial number is resolved, the serial number of the unresolved second instruction after the unresolved second instruction with the smallest serial number is used as the value of the second variable.
11. A chip, characterized in that: The chip is connected to a memory and is used to read and execute a software program stored in the memory to implement the method according to any one of claims 1 to 5.
12. A computer storage medium, characterized in that: The method comprises computer-readable instructions, and when a computer reads and executes the computer-readable instructions, the computer is caused to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
System and method for issuing instruction, processor and design method thereof
CN101706714A
System and method of selectively committing a result of an executed instruction
CN101965554A
Facilitating rapid progress while speculatively executing code in scout mode
US20050223201A1
Method and apparatus for updating global branch history information
US20060149951A1
Confidence threshold-based opposing branch path execution for branch prediction
US20140201508A1
