A method of executing instructions in a virtual machine and a virtual machine monitor

CN116225765BActive Publication Date: 2026-09-11ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310227996.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-06
Publication Date
2026-09-11
Estimated Expiration
2043-03-06

AI Technical Summary

Technical Problem

从而,提供了一种新的虚拟化方案,克服了依赖硬件辅助技术的虚拟化方案存在的例如不支持热升级方式、以及消耗大量计算资源的问题

Benefits of technology

[0036] By utilizing one or more of the methods, virtual machine monitors, systems, devices, and media mentioned above, a software-based virtual machine monitor can receive, forward, or process system call instructions or exceptions executed by virtual machine user processes or the virtual machine kernel, while the virtual machine kernel handles system call instructions typically initiated by virtual machine user processes. This provides a novel virtualization scheme that does not require hardware-assisted virtualization technology, overcoming problems inherent in hardware-dependent virtualization schemes, such as lack of support for hot upgrades and excessive consumption of computing resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116225765B_ABST
    Figure CN116225765B_ABST
Patent Text Reader

Abstract

The method for executing instructions in a virtual machine provided by the embodiments of the present application comprises: intercepting a first exception triggered by a first instruction executed by a virtual machine kernel running in a host user state or a first user process in a virtual machine, and sending the first exception to a virtual machine monitor running in a host kernel state; processing the first exception according to a trigger source of the first exception by the virtual machine monitor, wherein if the executor of the first instruction is the virtual machine kernel, the virtual machine monitor obtains an execution context of the first instruction from exception information of the first exception; and simulating the execution of the first instruction according to the execution context of the first instruction to obtain a first execution result, and sending the first execution result to the virtual machine kernel.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to one or more embodiments in the field of virtual machines, and more particularly to a method for executing instructions in a virtual machine and a virtual machine monitor. Background Technology

[0002] In recent years, with the popularization of cloud computing technology, virtualization technology, as its core technological foundation, has received increasing attention. In actual production environments, application service providers often purchase / rent public cloud servers for their business operation environments due to cost considerations. Currently, cloud providers often offer cloud servers through virtual machine solutions, and these virtual machine solutions are typically based on hardware-assisted virtualization (HAL) technology. To run virtual machines on cloud servers, hardware support for nested HAL features is required, and these HAL features must be enabled during virtual machine runtime.

[0003] However, in some scenarios, cloud providers wish to disable the nested assisted virtualization features of hardware for performance and security reasons. In such cases, relying on hardware-assisted technologies makes it difficult to provide support for running virtual machines in cloud hosts. Summary of the Invention

[0004] The embodiments in this specification aim to provide a method for executing instructions in a virtual machine. This method allows for the reception and handling of exceptions caused by virtual machine user processes or the virtual machine kernel solely through a software-based virtual machine monitor. The virtual machine monitor receives and forwards system call instructions executed by virtual machine user processes or the virtual machine kernel, and the virtual machine kernel handles system call instructions typically initiated by virtual machine user processes, without the need for virtualization hardware assistance technologies. Therefore, a new virtualization scheme is provided, overcoming the problems of hardware-assisted virtualization schemes, such as lack of support for hot upgrades and excessive consumption of computing resources.

[0005] According to the first aspect, a method for executing instructions in a virtual machine is provided, including:

[0006] Intercept the first exception triggered by the execution of the first instruction by the first user process in the virtual machine kernel running in the host machine user mode, or in the virtual machine, and send the first exception to the virtual machine monitor running in the host machine kernel mode;

[0007] The virtual machine monitor processes the first exception based on the triggering source of the first exception. If the triggering source of the first exception is the virtual machine kernel, the virtual machine monitor obtains the execution context of the first instruction from the exception information of the first exception; and, based on the execution context of the first instruction, simulates the execution of the first instruction to obtain a first execution result, and sends the first execution result to the virtual machine kernel.

[0008] In one possible implementation, the method further includes:

[0009] If the first exception is triggered by the first user process, the virtual machine monitor forwards the first exception to the virtual machine kernel.

[0010] In one possible implementation, the first instruction is a kernel-mode privileged instruction.

[0011] In one possible implementation, the execution of the first instruction is simulated according to the execution context of the first instruction to obtain a first execution result, including:

[0012] The execution context of the first instruction is sent to the host kernel running in the host kernel mode, and the first execution result is obtained from the host kernel.

[0013] In one possible implementation, the method further includes:

[0014] Intercept the system call instruction from the second user process in the virtual machine to call the host kernel, and send the system call instruction to the virtual machine monitor;

[0015] The virtual machine monitor forwards the system call instruction to the virtual machine kernel, receives the second execution result returned by the virtual machine kernel for the system call instruction, and returns the second execution result to the user process.

[0016] In one possible implementation, the method further includes:

[0017] In response to a hypercall instruction directed to the virtual machine monitor executed by the virtual machine kernel, the hypercall instruction is sent to the virtual machine monitor, the hypercall instruction being used to indicate a second instruction;

[0018] The virtual machine monitor simulates the execution of the second instruction, obtains a third execution result, and returns the third execution result to the virtual machine kernel.

[0019] In one possible implementation, the virtual machine monitor simulates the execution of the second instruction to obtain a third execution result, including:

[0020] The virtual machine monitor sends the second instruction to the host kernel running in the host kernel mode and obtains the third execution result from the host kernel.

[0021] In one possible implementation, the second instruction includes a sensitive non-privileged instruction.

[0022] In one possible implementation, the sensitive non-privileged instruction includes the Flag Transfer Instruction (POPF).

[0023] In one possible implementation, the second instruction includes instructions other than sensitive non-privileged instructions.

[0024] In one possible implementation, the other instructions include one of the system register write instruction WRMSR or the system register read instruction RDMSR.

[0025] According to the second aspect, a virtual machine monitor is provided, comprising:

[0026] The receiving unit is configured to receive a first exception triggered by the execution of a first instruction by a virtual machine kernel running in the user mode of the host machine or a first user process in the virtual machine.

[0027] The processing unit is configured such that the virtual machine monitor processes the first exception based on the triggering source of the first exception, wherein if the triggering source of the first exception is the virtual machine kernel, the virtual machine monitor obtains the execution context of the first instruction from the exception information of the first exception; and, based on the execution context of the first instruction, simulates the execution of the first instruction to obtain a first execution result, and sends the first execution result to the virtual machine kernel.

[0028] In one possible implementation, the receiving unit is further configured to receive a system call instruction from a second user process in a virtual machine to invoke the host kernel;

[0029] The processing unit is further configured to forward the system call instruction to the virtual machine kernel, receive the second execution result returned by the virtual machine kernel for the system call instruction, and return the second execution result to the user process.

[0030] In one possible implementation, the receiving unit is further configured to receive a hypercall instruction directed to the virtual machine monitor executed by the virtual machine kernel, the hypercall instruction being used to indicate a second instruction;

[0031] The processing unit is further configured to simulate the execution of the second instruction, obtain a third execution result, and return the third execution result to the virtual machine kernel.

[0032] In one possible implementation, the second instruction includes a sensitive non-privileged instruction.

[0033] According to a third aspect, a virtual machine system is provided, including the virtual machine monitor described in the second aspect.

[0034] According to a fourth aspect, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method described in the first aspect.

[0035] According to a fifth aspect, a computing device is provided, including a memory and a processor, characterized in that the memory stores executable code, and when the processor executes the executable code, it implements the method described in the first aspect.

[0036] By utilizing one or more of the methods, virtual machine monitors, systems, devices, and media mentioned above, a software-based virtual machine monitor can receive, forward, or process system call instructions or exceptions executed by virtual machine user processes or the virtual machine kernel, while the virtual machine kernel handles system call instructions typically initiated by virtual machine user processes. This provides a novel virtualization scheme that does not require hardware-assisted virtualization technology, overcoming problems inherent in hardware-dependent virtualization schemes, such as lack of support for hot upgrades and excessive consumption of computing resources. Attached Figure Description

[0037] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0038] Figure 1 This diagram illustrates the principle of a method for executing instructions in a virtual machine according to an embodiment of this specification.

[0039] Figure 2 A flowchart illustrating a method for executing instructions in a virtual machine according to an embodiment of this specification;

[0040] Figure 3 A schematic diagram illustrating a method for executing instructions in a virtual machine according to an embodiment of this specification;

[0041] Figure 4 A schematic diagram illustrating a method for executing instructions in a virtual machine according to another embodiment of this specification;

[0042] Figure 5 A schematic diagram illustrating a method for executing instructions in a virtual machine according to yet another embodiment of this specification is shown.

[0043] Figure 6 A schematic diagram illustrating a method for executing instructions in a virtual machine according to another embodiment of this specification is shown.

[0044] Figure 7 A structural diagram of a virtual machine monitor according to an embodiment of this specification is shown. Detailed Implementation

[0045] The solution provided in this invention will now be described with reference to the accompanying drawings.

[0046] As mentioned earlier, with the popularization of cloud computing in recent years, virtualization technology, as a core technological cornerstone, has been increasingly used. In actual production environments, application service providers often purchase / rent cloud machines as their business operating environment due to cost considerations. Current cloud providers often rely on hardware-assisted virtual machine solutions to provide cloud host services. If virtual machines are to be nested within a cloud host, the hardware needs to support nested assisted virtualization features, and these features must be enabled during virtual machine runtime. However, hardware-assisted virtualization solutions often have the following problems: First, because the cloud host itself can be a virtual machine, an anomaly in a nested virtual machine within the cloud host can lead to a direct exit to the host machine, followed by a host machine-simulated injection back into the cloud host. This results in a long and inefficient anomaly handling path. Second, in public cloud scenarios, enabling nested virtualization can affect the performance of cloud hosts that do not require nested virtualization support, thus impacting the overall performance of cloud services. Third, when hardware security vulnerabilities occur in hardware-assisted technologies, they can be fixed either by updating the hardware or by executing microcode. Neither hardware updates nor microcode fixes (even microcode fixes require a hardware system reboot) can be achieved through hot upgrades that only update virtual machine software, making cloud service security maintenance difficult. Therefore, some cloud providers, for service performance and security reasons, wish to disable hardware-assisted virtualization features. In this case, hardware-assisted virtualization solutions struggle to provide virtualization support. For example, KVM (Kernel-based Virtual Machine) is a native virtualization implementation of the Linux kernel, loaded as a kernel module at runtime. Its streamlined architecture, tight integration with the kernel, and high performance through reusing Linux kernel subsystems (such as the scheduling and memory management subsystems) are crucial. However, KVM relies on hardware-assisted technologies for isolation and switching between the host and guest (virtual machine) systems, failing to meet the aforementioned virtualization requirements of cloud service providers.

[0047] To address the aforementioned technical problems, embodiments of this specification provide a method for executing instructions in a virtual machine. To more clearly illustrate the scheme for executing instructions in a virtual machine provided by the embodiments of this specification, the conventional virtualization scheme will be described first. Conventionally, the operating system kernel manages hardware resources and can run in kernel mode and execute privileged kernel-mode instructions. If the virtual machine kernel also runs directly in the host kernel mode, then the virtual machine kernel can directly execute privileged instructions, potentially damaging the host machine and causing security issues. Hardware-assisted techniques solve this problem by adding a host machine state dimension. Conventionally, the host machine state has only one dimension, namely kernel mode or user mode (or, in other words, the host CPU state only has kernel mode or user mode; for convenience, the host machine state can be simply referred to as kernel mode or user mode). Hardware-assisted techniques add another state dimension, namely guest mode or host mode. That is, the host machine can be in one of the following four states: guest user mode, host user mode, guest kernel mode, or host kernel mode. This causes the virtual machine kernel to run in guest kernel mode, preventing it from directly executing privileged instructions that could cause security issues on the host machine. Then, based on the aforementioned service performance and security maintenance factors, the nested auxiliary virtualization feature of the hardware is disabled. Without hardware assistance, to ensure host machine security, running the virtual machine kernel in user mode would lead to problems such as failure to execute privileged kernel instructions.

[0048] Figure 1 This diagram illustrates the principle of a method for executing instructions in a virtual machine according to an embodiment of this specification. Figure 1As shown, the core idea of ​​this method is to run a virtual machine operating system kernel (hereinafter referred to as the virtual machine kernel for convenience) in the host machine's user space. Exceptions (such as internal exceptions or external interrupts) generated by the user process or the virtual machine kernel while executing privileged kernel instructions are intercepted, and these exceptions are handled by a virtual machine monitor running in the host machine's kernel space (specifically, in one example, the processing result can be returned to the user process or the virtual machine kernel via an exception return instruction (iret)). In one embodiment, calls to the host machine kernel by the user process via system call instructions (syscall) can also be intercepted and sent to the virtual machine monitor, which forwards the call to the virtual machine kernel for processing and returns the processing result to the user process via the virtual machine monitor (specifically, the processing result can be returned to the user process via a sysret instruction). In one embodiment, in response to a hypercall instruction executed by the virtual machine kernel pointing to the virtual machine monitor, the virtual machine monitor executes the operation indicated by the hypercall instruction and returns the operation result to the virtual machine kernel. The above method allows exceptions caused by virtual machine user processes / virtual machines to be received and handled solely through a software-based virtual machine monitor. This overcomes the problem of running a virtual machine kernel in user mode causing failures, such as the execution of privileged kernel-mode instructions. Furthermore, by receiving and forwarding system call instructions executed by virtual machine user processes through the virtual machine monitor, these system call instructions are processed by the virtual machine kernel, rather than through the conventional host kernel system. Therefore, a new, highly efficient virtualization solution is provided without the need for hardware-assisted technologies. This also overcomes the problems of hardware-assisted virtualization solutions, such as the lack of support for hot upgrades and the consumption of large amounts of computing resources.

[0049] The specific process of this method will be further explained below.

[0050] Figure 2 A flowchart illustrating a method for executing instructions in a virtual machine according to an embodiment of this specification is shown. Figure 2 As shown, the method includes at least the following steps:

[0051] Step S21: Intercept the first exception triggered by the execution of the first instruction by the virtual machine kernel running in the host machine user mode or the first user process in the virtual machine, and send the first exception to the virtual machine monitor running in the host machine kernel mode.

[0052] Step S23: The virtual machine monitor processes the first exception according to the triggering source of the first exception; if the triggering source of the first exception is the virtual machine kernel, the virtual machine monitor obtains the execution context of the first instruction from the exception information of the first exception, and simulates the execution of the first instruction according to the execution context of the first instruction to obtain a first execution result, and sends the first execution result to the virtual machine kernel.

[0053] First, in step S21, the first exception triggered by the execution of the first instruction by the virtual machine kernel running in the host user mode or the first user process in the virtual machine is intercepted, and the first exception is sent to the virtual machine monitor running in the host kernel mode.

[0054] A virtual machine (VM) is generally a simulated computer system built using software. For example, it can be a computer system with complete hardware functionality, running in a completely isolated environment, and supporting the execution of an operating system (OS). The operating system installed on the VM is called the VM operating system, and the kernel of the VM operating system is called the VM kernel. Typically, VMs can be installed on a physical machine, also known as the host machine. A Virtual Machine Monitor (VMM) is a software layer installed on the physical machine (host machine), which allows multiple VMs to run and be managed on the physical machine.

[0055] The operating system (OS) kernel is typically the core of an operating system. It's a top-level software extension based on the hardware, providing the most basic functions of the operating system. Generally, it's responsible for managing system processes, memory, device drivers, files, and network systems. Typically, the OS kernel runs in the host CPU's kernel mode, or simply host kernel mode. Ordinary applications run in the host CPU's user mode, or simply host user mode. In contrast, the virtual machine kernel in this step is not the host operating system's kernel running in the host kernel mode. Instead, it's an operating system kernel running in the host user mode, independent of hardware virtualization technology. This kernel may not implement all the functions of the host kernel; it may only implement a portion of the host kernel's functionality.

[0056] In this step, an exception (e.g., a first exception) triggered when the virtual machine kernel or user process (e.g., the first user process) executes instructions can be intercepted and forwarded to the virtual machine monitor. The virtual machine kernel or user process runs in the host machine's user mode, while the virtual machine monitor runs in the host machine's kernel mode. In one embodiment, the exception may include an internal exception. Internal exceptions are typically caused by internal CPU events, such as instruction execution errors or memory access errors. In one embodiment, the exception may also include an external interrupt, which is typically a level-controlled interrupt caused by external hardware events; "external" usually refers to events outside the CPU. In different examples, external interrupts may originate from various external devices, such as timer chips, peripherals (keyboard, mouse, etc.), I / O ports (serial, parallel, etc.), disk drives, CMOS clocks, or expansion cards (sound cards, video cards, etc.). Generally, whether it's an internal exception or an external interrupt, the execution of the processor's current instruction is interrupted, jumping to, for example, the exception handler in the host OS kernel, and returning to the original instruction stream after exception handling. In contrast, this step intercepts the exception and sends it to the virtual machine monitor running in the host kernel mode.

[0057] Since both user processes and the virtual machine kernel run in the host machine's user mode, if the virtual machine kernel or the user process executes an instruction that can only be executed successfully in the host machine's kernel mode—that is, a kernel-mode privileged instruction—an exception will be thrown. Therefore, in one embodiment, the first instruction can be a kernel-mode privileged instruction. In different specific embodiments, the kernel-mode privileged instruction can be different specific instructions, and this specification does not limit this.

[0058] In different embodiments, exceptions triggered by the virtual machine kernel or user processes can be intercepted in different specific ways, and this specification does not limit this. In one embodiment, exceptions triggered by the virtual machine kernel or user processes can be intercepted, for example, through hook functions.

[0059] Subsequently, in step S23, the virtual machine monitor processes the first exception based on the triggering source of the first exception.

[0060] In this step, the virtual machine monitor determines how to handle the first exception based on the triggering source of the first exception received in step S31 (e.g., the virtual machine kernel or a user process). Specifically, if the triggering source of the first exception is the virtual machine kernel, the execution context of the first instruction is obtained from the exception information of the first exception. Then, based on the execution context of the first instruction, the execution of the first instruction is simulated to obtain a simulated execution result (e.g., a first execution result), and the first execution result is sent to the virtual machine kernel. Figure 3 This diagram illustrates a method for executing instructions in a virtual machine according to one embodiment of this specification. Figure 3 As shown, for the exception (exception1 / interrupt1) thrown by the virtual machine kernel, the virtual machine monitor can send the exception handling result (first execution result) to the virtual machine kernel through the exception return instruction iret. Figure 4 This diagram illustrates a method for executing instructions in a virtual machine according to one embodiment of this specification. In one embodiment, if the triggering source of the first exception is the first user process, the virtual machine monitor can forward the first exception to the virtual machine kernel. Figure 3 As shown, for exceptions (exception2 / interrupt2) thrown by a user process, the virtual machine monitor can forward the exception to the virtual machine kernel for handling. In different specific embodiments, the virtual machine kernel handles the received forwarded exception in different ways. In one example, the virtual machine kernel can terminate the user process.

[0061] Since the virtual machine monitor runs in the host kernel mode, in the embodiment where the first instruction is a kernel-mode privileged instruction, the virtual machine monitor itself can simulate, for example, the execution of a kernel-mode privileged instruction. In one example, the virtual machine monitor can also send the execution context of the first instruction to the host kernel running in the host kernel mode and obtain the first execution result from the host kernel.

[0062] In some scenarios, due to the lack of hardware assistance, user processes within a virtual machine can execute system call (syscall) instructions that invoke the host kernel. These system call instructions can be intercepted and sent to the virtual machine monitor, which then forwards them to the virtual machine kernel running in user mode on the host machine for execution, obtaining the corresponding execution result. Therefore, in one embodiment, a system call instruction from a second user process within the virtual machine to invoke the host kernel can be intercepted and sent to the virtual machine monitor. The virtual machine monitor forwards the system call instruction to the virtual machine kernel, receives the second execution result returned by the virtual machine kernel for the system call instruction, and returns the second execution result to the user process. Figure 4 A schematic diagram illustrating a method for executing instructions in a virtual machine according to another embodiment of this specification is shown. Figure 4As shown, it is possible to intercept the syscall instruction of the host kernel called by the user process in the virtual machine and send it to the virtual machine monitor. The virtual machine monitor forwards the syscall instruction to the virtual machine kernel and receives the system return instruction (sysret) indicating the execution result, and forwards the sysret instruction to the user process.

[0063] In other scenarios, when the virtual machine kernel executes sensitive non-privileged instructions, no exception is raised. However, the result of these instructions running in user mode (host machine) differs from the expected result in kernel mode; that is, the result in user mode can be incorrect. The virtual machine kernel can execute a super-call instruction that directly points to the virtual machine monitor (VM). This super-call instruction can instruct, for example, a pre-defined second instruction. By executing the super-call instruction, the virtual machine kernel itself does not execute the second instruction but instructs the VM to simulate its execution. Since the VM runs in kernel mode, upon receiving the super-call instruction, the VM can simulate the execution of the second instruction, obtain and return the correct execution result (e.g., a third execution result) to the virtual machine kernel. Figure 5 This diagram illustrates a method for executing instructions in a virtual machine according to yet another embodiment of this specification. Figure 5 In the illustrated embodiment, the virtual machine monitor receives a hypercall instruction initiated by the virtual machine kernel. After executing the instruction indicated by the hypercall instruction, it can send the execution result back to the virtual machine kernel, for example, via a hyperreturn instruction (hret instruction). In one example, the second instruction could, for example, indicate a sensitive non-privileged instruction, such as... Figure 6 As shown. In different embodiments, the specific instructions included in the sensitive non-privileged instructions can vary. In one example, it may include a flag transfer instruction (POPF instruction, or flag pop instruction), which can be executed in both user mode and kernel mode, but will only produce the correct execution result in kernel mode. Similar to the simulated execution of privileged instructions in kernel mode, in one embodiment, the virtual machine monitor can also send the sensitive non-privileged instructions to the host kernel running in the host kernel mode and obtain a third execution result from the host kernel.

[0064] Besides sensitive non-privileged instructions, supercall instructions can also be used to instruct other instructions. For example, in some scenarios, to improve operational efficiency and reduce the computational resource consumption caused by intercepted instructions, the virtual machine kernel can execute the supercall instruction instructing other instructions, the virtual machine monitor can execute the other instructions instructed by the supercall instruction, and return the operation result. In different embodiments, the other instructions instructed by the supercall instruction can be different. In one example, it may include either the system register write instruction WRMSR or the system register read instruction RDMSR.

[0065] In summary, the method for executing instructions in a virtual machine provided in the embodiments of this specification offers several advantages. Firstly, it allows for the handling of exceptions thrown by the virtual machine program or kernel by the virtual machine monitor. Furthermore, the virtual machine monitor forwards system call instructions executed by the virtual machine user process, and the virtual machine kernel processes these system call instructions, providing a highly efficient virtualization scheme that requires no hardware assistance. Moreover, compared to virtualization schemes that rely on hardware assistance, this scheme significantly reduces computational resource consumption. Additionally, hardware-assisted virtualization schemes cannot control redundant state information (e.g., register information unrelated to the currently executing program) that is often stored during the state transitions between user mode and kernel mode executed by the hardware via microcode. Since it does not rely on hardware assistance, this scheme eliminates the need to retain redundant state information unrelated to the currently executing program during the state transitions between user mode and kernel mode, further reducing computational resource consumption. Secondly, it allows for the simulation of sensitive non-privileged instructions by the virtual machine monitor, thereby preventing execution errors caused by executing sensitive non-privileged instructions in user mode and improving the security of virtual machine operation. Finally, it allows for the execution of hypercall instructions by the virtual machine monitor, improving the operating efficiency of the virtual machine. Thirdly, this solution is a software-based virtualization solution, which can repair virtual machine failures through hot software upgrades, without requiring hardware updates or restarting the hardware system after updating and fixing hardware microcode. Furthermore, it allows reuse of operating system kernel functionality without the need to patch the operating system kernel.

[0066] According to another embodiment, a virtual machine monitor is also provided. Figure 7 This diagram illustrates a structural diagram of a virtual machine monitor according to an embodiment of this specification, such as... Figure 7 As shown, the device 700 includes:

[0067] The receiving unit 701 is configured to receive a first exception triggered by the execution of a first instruction by a virtual machine kernel running in the user mode of the host machine or a first user process in the virtual machine.

[0068] The processing unit 702 is configured to process the first exception according to the triggering source of the first exception, wherein if the triggering source of the first exception is the virtual machine kernel, the virtual machine monitor obtains the execution context of the first instruction from the exception information of the first exception, and simulates the execution of the first instruction according to the execution context of the first instruction to obtain a first execution result, and sends the first execution result to the virtual machine kernel.

[0069] In one embodiment, the receiving unit 701 may be further configured to receive a system call instruction from a second user process in the virtual machine to call the host kernel; the processing unit 702 may be further configured to forward the system call instruction to the virtual machine kernel, receive a second execution result returned by the virtual machine kernel for the system call instruction, and return the second execution result to the user process.

[0070] In one embodiment, the receiving unit 701 may be further configured to receive a hypercall instruction directed to the virtual machine monitor executed by the virtual machine kernel, the hypercall instruction being used to indicate a second instruction; the processing unit 702 may be further configured to simulate the execution of the second instruction, obtain a third execution result, and return the third execution result to the virtual machine kernel.

[0071] In one embodiment, the second instruction may include a sensitive non-privileged instruction.

[0072] According to another embodiment, a virtual machine system is also provided, which includes the virtual machine monitor described above.

[0073] Another aspect of this specification provides a computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform any of the methods described above.

[0074] This specification also provides a computing device, including a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements any of the methods described above.

[0075] It should be understood that the descriptions such as "first" and "second" in this article are merely for the sake of simplicity in description and to distinguish similar concepts, and do not have any other limiting function.

[0076] Those skilled in the art will recognize that, in one or more of the examples above, the functions described in this invention can be implemented using hardware, software, firmware, or any combination thereof. When implemented in software, these functions can be stored in a computer-readable medium or transmitted as one or more instructions or code on a computer-readable medium.

[0077] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made on the basis of the technical solution of the present invention should be included within the scope of protection of the present invention.

Claims

1. A method for executing instructions in a virtual machine, comprising: Intercept the first exception triggered by the execution of the first instruction by the first user process running in the host machine user mode virtual machine kernel or virtual machine, and send the first exception to the virtual machine monitor running in the host machine kernel mode; The virtual machine monitor processes the first exception based on its triggering source. If the triggering source of the first exception is the virtual machine kernel, the virtual machine monitor obtains the execution context of the first instruction from the exception information of the first exception, and simulates the execution of the first instruction based on the execution context of the first instruction to obtain a first execution result, and sends the first execution result to the virtual machine kernel. If the triggering source of the first exception is the first user process, the virtual machine monitor forwards the first exception to the virtual machine kernel.

2. The method of claim 1, wherein, The first instruction is a kernel-mode privileged instruction.

3. The method of claim 1, wherein, Based on the execution context of the first instruction, the execution of the first instruction is simulated to obtain a first execution result, including: The execution context of the first instruction is sent to the host kernel running in the host kernel mode, and the first execution result is obtained from the host kernel.

4. The method according to claim 1, further comprising: Intercept the system call instruction from the second user process in the virtual machine to call the host kernel, and send the system call instruction to the virtual machine monitor; The virtual machine monitor forwards the system call instruction to the virtual machine kernel, receives the second execution result returned by the virtual machine kernel for the system call instruction, and returns the second execution result to the second user process.

5. The method according to claim 1, further comprising: In response to a hypercall instruction directed to the virtual machine monitor executed by the virtual machine kernel, the hypercall instruction is sent to the virtual machine monitor, the hypercall instruction being used to indicate a second instruction; The virtual machine monitor simulates the execution of the second instruction, obtains a third execution result, and returns the third execution result to the virtual machine kernel.

6. The method of claim 5, wherein, The virtual machine monitor simulates the execution of the second instruction to obtain a third execution result, including: The virtual machine monitor sends the second instruction to the host kernel running in the host kernel mode and obtains the third execution result from the host kernel.

7. The method of claim 6, wherein, The second instruction includes sensitive non-privileged instructions.

8. The method of claim 7, wherein, The sensitive non-privileged instructions include the Flag Transfer Instruction (POPF).

9. The method according to claim 5, wherein, The second instruction includes instructions other than sensitive non-privileged instructions.

10. The method according to claim 9, wherein, The other instructions include either the system register write instruction WRMSR or the system register read instruction RDMSR.

11. A virtual machine monitor, comprising: The receiving unit is configured to receive a first exception triggered by the execution of a first instruction by a first user process running in the user mode of the host machine or in the virtual machine. The processing unit is configured to process the first exception according to the triggering source of the first exception, wherein if the triggering source of the first exception is the virtual machine kernel, the virtual machine monitor obtains the execution context of the first instruction from the exception information of the first exception, and simulates the execution of the first instruction according to the execution context of the first instruction to obtain a first execution result, and sends the first execution result to the virtual machine kernel. If the first exception is triggered by the first user process, the virtual machine monitor forwards the first exception to the virtual machine kernel.

12. The virtual machine monitor of claim 11, wherein, The receiving unit is further configured to receive system call instructions from the second user process in the virtual machine to invoke the host kernel; The processing unit is further configured to forward the system call instruction to the virtual machine kernel, receive the second execution result returned by the virtual machine kernel for the system call instruction, and return the second execution result to the second user process.

13. The virtual machine monitor of claim 11, wherein, The receiving unit is further configured to receive a super call instruction directed to the virtual machine monitor executed by the virtual machine kernel, wherein the super call instruction is used to indicate a second instruction; The processing unit is further configured to simulate the execution of the second instruction, obtain a third execution result, and return the third execution result to the virtual machine kernel.

14. The virtual machine monitor of claim 13, wherein, The second instruction includes sensitive non-privileged instructions.

15. A virtual machine system comprising a virtual machine monitor as described in any one of claims 11 to 14.

16. A computer-readable storage medium having a computer program stored thereon, which, when executed in a computer, causes the computer to perform the method of any one of claims 1-10.

17. A computing device comprising a memory and a processor, wherein the memory stores executable code, and the processor, when executing the executable code, implements the method of any one of claims 1-10.

Citation Information

Patent Citations

  • Asynchronous monitoring interception system and method of host behavior on the basis of virtualization

    CN105607945A

  • Interrupt virtualization processing method and system oriented to ARM (Advanced RISC Machines) architecture virtualization field

    CN112817690A