A method for processing virtual machine exception, electronic equipment and storage medium

By monitoring virtual machine runtime in real time through the central processing unit and triggering exit when a preset threshold is reached, virtual machine anomalies can be resolved, processing time can be shortened, host machine can be prevented from freezing, and host machine reliability and robustness can be improved.

CN115061776BActive Publication Date: 2026-04-14HANGZHOU WANGSU TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HANGZHOU WANGSU TECH CO LTD
Filing Date
2022-05-31
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

When a virtual machine encounters an anomaly while executing microcode, causing the CPU to become unresponsive for an extended period, it can lead to the entire host machine freezing. Traditional solutions are outdated and affect the normal use of the virtual machine.

Method used

The central processing unit monitors the runtime in real time. When a preset time threshold is reached, a virtual machine exit process is generated, which triggers the virtual machine to pause its operation and collects relevant information to reclaim resources, including CPU resources.

Benefits of technology

Timely detection of virtual machine anomalies can shorten processing time, prevent host machine crashes, and improve host machine reliability and robustness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115061776B_ABST
    Figure CN115061776B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of cloud computing, and discloses a virtual machine exception processing method, an electronic device and a storage medium. In the application, the virtual machine exception processing method comprises the following steps: a central processing unit reads a preset time threshold stored in a host computer, and performs real-time monitoring on the running time of the central processing unit in a non-root mode; in the case that the running time reaches the preset time threshold, the central processing unit generates a preset virtual machine exit process, and triggers the virtual machine to suspend running; the host computer collects relevant information of the virtual machine, and recovers the resources occupied by the virtual machine; wherein the resources occupied by the virtual machine include the resources of the central processing unit occupied by the virtual machine. The application can shorten the time required for processing the virtual machine exception, and improve the reliability and robustness of the host computer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cloud computing technology, and in particular to a method for handling virtual machine anomalies, an electronic device, and a storage medium. Background Technology

[0002] With the booming development of the cloud computing market, cloud computing technology has attracted increasing attention. Virtualization technology has significant advantages such as improving network resource utilization and effectively protecting the network environment, and has now become an indispensable support in the development of cloud computing technology.

[0003] When a virtual machine executes some microcode, it closes the event window, during which time the central processing unit (CPU) becomes unresponsive to certain events. These events include normal interrupts, non-maskable interrupts (NMIs), and system management interrupts (SMIs). If an exception occurs during the execution of microcode, the CPU running it may become unable to respond to all events for an extended period, causing it to freeze. At this time, the CPU also cannot respond to notification messages sent to it by other CPUs, leading to a continuous stream of messages from other CPUs and ultimately causing the entire host machine to freeze.

[0004] When a virtual machine freezes while executing certain microcode, the traditional solution is to add processing instructions specifically for that microcode, allowing the virtual machine to avoid problems during execution. However, this approach has a significant time lag, and the virtual machine may still be difficult to use normally even after the problem is resolved. Summary of the Invention

[0005] The purpose of this invention is to provide a method, electronic device, and storage medium for handling virtual machine anomalies, so as to shorten the time required to handle virtual machine anomalies and improve the reliability and robustness of the host machine.

[0006] To achieve the above objectives, embodiments of the present invention provide a method for handling virtual machine anomalies, comprising: the central processing unit (CPU) reading a preset time threshold stored in the host machine and monitoring the CPU's running time in non-root mode in real time; when the running time reaches the preset time threshold, the CPU generates a preset virtual machine exit process to trigger the virtual machine to suspend operation; the host machine collects relevant information about the virtual machine and reclaims the resources occupied by the virtual machine; wherein, the resources occupied by the virtual machine include the CPU resources occupied by the virtual machine.

[0007] Embodiments of the present invention also provide a server, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the above-described virtual machine exception handling method.

[0008] Embodiments of the present invention also provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method for handling virtual machine exceptions.

[0009] In this embodiment of the invention, the central processing unit (CPU) first reads a preset time threshold stored in the host machine and monitors the CPU's running time in non-root mode in real time, i.e., monitors the virtual machine's running time in real time. If the running time reaches the preset time threshold, it indicates that the virtual machine has been running for too long and has failed to exit normally, possibly resulting in a freeze. The CPU then generates a preset virtual machine exit process to trigger the virtual machine to pause. Compared to traditional methods of diagnosing and specifically handling virtual machine anomalies, this approach can detect virtual machine anomalies more promptly and shorten the time required to handle them. Furthermore, the host machine collects relevant information about the virtual machine and reclaims the resources it occupies, enabling the CPU resources used by the virtual machine to resume responding to communication messages from other CPUs on the host machine. This avoids serious problems such as host machine freezes caused by other CPUs continuously sending communication requests to the abnormal CPU, effectively improving the reliability and robustness of the host machine. Attached Figure Description

[0010] One or more embodiments are illustrated by way of example with the corresponding pictures in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.

[0011] Figure 1 This is a schematic flowchart of a virtual machine exception handling method according to an embodiment of the present invention.

[0012] Figure 2 This is a schematic diagram of the virtual machine operation process according to another embodiment of the present invention;

[0013] Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0014] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the various embodiments of the present invention will be described in detail below with reference to the accompanying drawings. However, those skilled in the art will understand that many technical details have been presented in the various embodiments of the present invention to facilitate a better understanding of this application. However, the technical solutions claimed in this application can be implemented even without these technical details and various changes and modifications based on the following embodiments.

[0015] The traditional solution to virtual machine (VM) crashes caused by executing certain microcode is to discover vulnerabilities and then have system administrators add corresponding processing instructions to these microcodes. This allows the VM to perform the added actions when executing these microcodes, thus preventing it from crashing. However, this approach to resolving VM crashes is clearly time-consuming and still impacts the normal operation of the VM.

[0016] One embodiment of the present invention relates to a method for handling virtual machine anomalies. In this embodiment, the central processing unit (CPU) reads a preset time threshold stored in the host machine and monitors the CPU's running time in non-root mode in real time; when the running time reaches the preset time threshold, the CPU generates a preset virtual machine exit process, triggering the virtual machine to suspend operation; the host machine collects relevant information about the virtual machine and reclaims the resources occupied by the virtual machine; wherein, the resources occupied by the virtual machine include the CPU resources occupied by the virtual machine.

[0017] The following details the implementation of the virtual machine exception handling method in this embodiment. This content is only for understanding the implementation details of this solution and is not essential for its implementation. The specific process is as follows: Figure 1 As shown, the steps may include the following:

[0018] Step 101: The central processing unit reads the preset time threshold stored in the host machine and monitors the running time of the central processing unit in non-root mode in real time.

[0019] Generally, the CPU runs in non-root mode while the virtual machine is running, and exits non-root mode when the virtual machine stops. Therefore, the CPU monitors the time the virtual machine spends in non-root mode in real time, i.e., it monitors the virtual machine's runtime in real time. This real-time monitoring allows for timely intervention if the virtual machine's runtime becomes excessively long.

[0020] Understandably, the CPU reading the preset time threshold stored in the host machine can be specifically described as follows: when the CPU switches to non-root mode, it reads the preset time threshold corresponding to the currently running virtual machine stored in the host machine. When multiple virtual machines exist on the host machine, the CPU can use the preset time threshold corresponding to the currently running virtual machine to constrain the running time of that virtual machine.

[0021] It is also worth mentioning that different preset time thresholds can be set for different virtual machines running on the host machine, which can be used to independently judge the running anomalies of the virtual machines using different time thresholds.

[0022] In one example, before the central processing unit reads the preset time threshold stored in the host machine, the process may further include: the host machine receiving the preset time threshold set by the user through a user-mode program, based on the time configuration interface in the user-mode program. Understandably, in this example, the user can independently set the preset time threshold of the virtual machine through the host machine's user-mode program, ensuring that the set preset time threshold specifically meets the actual operational needs of the virtual machine.

[0023] The host machine receiving the preset time threshold based on the time configuration interface can specifically include: first checking the preset time threshold set by the user and determining whether the preset time threshold is greater than 0; if the preset time threshold is greater than 0, storing the preset time threshold.

[0024] It is worth mentioning that, in order to better implement the method provided by this invention and ensure that the central processing unit (CPU) cannot properly exit non-root mode when the virtual machine malfunctions, before the CPU reads the preset time threshold stored in the host machine, the method may further include: detecting whether the CPU has a mechanism for periodically exiting non-root mode. If the CPU has a mechanism for periodically exiting non-root mode, the host machine stores the preset time threshold for the CPU to read.

[0025] In a specific embodiment where the virtual machine is a KVM virtual machine, after receiving the preset time threshold, the KVM virtual machine kernel module checks whether the current CPU supports periodically exiting non-root mode. If it does not support it, it directly reports an error; if it supports it, it writes the value of the preset time threshold into the Virtual Machine Control Structure (VMCS) corresponding to the KVM virtual machine in the host machine (specifically, it can be written into the NOTIFY_WINDOW field of the VMCS), thereby activating the periodic exit function of the CPU.

[0026] Because the preset time thresholds for each virtual machine are stored in their respective VMCS, the exception handling capabilities of each virtual machine are independent. The freezing of any virtual machine will not affect the normal operation of other virtual machines.

[0027] Furthermore, to prevent the virtual machine from being incorrectly reclaimed during normal operation due to an excessively low preset time threshold, a minimum value for the preset time threshold can be pre-set. After receiving the preset time threshold set by the user through a user-mode program, the system may also include: if the received user-set preset time threshold is less than the minimum preset time threshold, the host machine sends a reset reminder to the user, or updates the preset time threshold to the minimum time threshold.

[0028] Step 102: When the running time reaches a preset time threshold, the central processing unit generates a preset virtual machine exit process, triggering the virtual machine to pause operation.

[0029] Generally, the CPU will automatically exit non-root mode after running for a certain period of time. Therefore, if the CPU runs in non-root mode for a preset time threshold, it indicates that the virtual machine has been running for too long and has failed to exit normally, possibly resulting in a virtual machine freeze. Therefore, in this step, the CPU generates a preset virtual machine exit process to promptly trigger the virtual machine to stop running and proceed with subsequent steps.

[0030] It's worth noting that after generating the preset virtual machine exit process, the following can also be included: the central processing unit generates virtual machine abnormal alarm information on the host machine. Generating alarm information on the host machine can remind the host machine's maintenance personnel to take timely protection measures, ensuring the safe operation of the host machine in the event of a virtual machine crash.

[0031] In addition, to shorten virtual machine downtime, after reclaiming the resources used by the virtual machine, the process can also include: triggering a virtual machine restart via the CPU. It's worth noting that this virtual machine restart trigger can automatically restart the virtual machine according to the original configuration, based on user needs.

[0032] Step 103: The host machine collects relevant information about the virtual machine and reclaims the resources occupied by the virtual machine; the resources occupied by the virtual machine include the resources of the central processing unit occupied by the virtual machine.

[0033] Because the default virtual machine exit process differs from the regular virtual machine exit process, the kernel module controlling the virtual machine in the host machine captures this event when the CPU generates the default virtual machine exit process. To ensure that the resources occupied by the virtual machine can be released and reused, the host machine reclaims these resources. The resources occupied by the virtual machine here include not only CPU resources but also memory, disk space, and other transparently accessible device resources.

[0034] It is worth noting that the virtual machine-related information involved in this step may include: the virtual machine's software version, the virtual machine control structure (VMCS), and virtual central processing unit (VCPU) information. It is also worth mentioning that this embodiment does not impose specific restrictions on the virtual machine-related information that the host machine needs to collect; the virtual machine-related information may include other information related to the virtual machine and its operation that needs to be collected.

[0035] In addition, after collecting relevant information about the virtual machine, these information files can be packaged and stored in a fixed location on the host machine for easy access by technical personnel.

[0036] In this embodiment, the central processing unit (CPU) first reads a preset time threshold stored in the host machine and monitors the CPU's running time in non-root mode in real time, i.e., the virtual machine's running time is monitored in real time. If the running time reaches the preset time threshold, it indicates that the virtual machine has been running for too long and has failed to exit normally, possibly resulting in a freeze. The CPU then generates a preset virtual machine exit process to trigger the virtual machine to pause. Compared to traditional methods of diagnosing and handling virtual machine anomalies after they occur, this approach can detect virtual machine anomalies more promptly and shorten the time required to handle them. Furthermore, the host machine collects relevant information about the virtual machine and reclaims the resources it occupies. This allows the CPU resources used by the virtual machine to resume responding to communication messages from other CPUs on the host machine, preventing serious problems such as host machine freezes caused by other CPUs continuously sending communication requests to the abnormal CPU. This effectively improves the reliability and robustness of the host machine.

[0037] Another embodiment of the present invention relates to a method for handling virtual machine anomalies. It is worth noting that the main difference between this embodiment and the previous embodiment is that, in this embodiment, when the virtual machine is suspended, a judgment program is used to determine whether the virtual machine exit process is a preset virtual machine exit process.

[0038] Furthermore, it is worth noting that the technical details disclosed in the previous embodiment remain valid in this embodiment, and will not be repeated here to reduce repetition.

[0039] The following details the implementation of the virtual machine exception handling method in this embodiment. This content is only for understanding the implementation details of this solution and is not essential for its implementation. The flowchart of virtual machine operation involved in this embodiment can be as follows: Figure 2 As shown.

[0040] Step 201: The virtual machine starts running. Understandably, the virtual machine involved in this embodiment is pre-configured with a corresponding preset time threshold to limit its runtime.

[0041] Step 202: The timer starts counting down, and the running time of the virtual machine is monitored in real time by using the timer's timing.

[0042] It is worth noting that in this embodiment, a timer is used to monitor the virtual machine's runtime in real time. Since monitoring the virtual machine's runtime can be achieved by monitoring the CPU's runtime in non-root mode in real time, the specific technical means involved in this step can be as follows: when the CPU switches to non-root mode, a timer is triggered to start counting, and the CPU's runtime in non-root mode is monitored in real time by measuring the timer's duration.

[0043] Step 203: The virtual machine is paused.

[0044] Step 204: Determine whether the virtual machine exit process is the preset virtual machine exit process.

[0045] Virtual machine (VM) exit processes can occur in many situations, causing the VM to pause. Even during normal procedures such as accessing privileged commands or virtual hardware, VM exit processes can occur, pausing the VM. Therefore, to ensure that exception handling is only performed when a pre-defined VM exit process occurs, and to avoid wasting processing resources and affecting subsequent normal VM operation by reclaiming VM resources during normal exits, it is necessary to determine whether the current exit process is a pre-defined VM exit process after the VM pauses.

[0046] Step 205: The host machine collects relevant information about the virtual machine and reclaims the resources occupied by the virtual machine.

[0047] When the virtual machine exits via the default exit process, the host machine collects relevant information about the virtual machine and reclaims the resources it occupies, releasing those resources. This allows the CPU resources used by the virtual machine to resume responding to communication messages from other CPUs on the host machine, preventing serious problems such as host machine crashes caused by other CPUs continuously sending communication requests to the malfunctioning CPU. This effectively improves the reliability and robustness of the host machine.

[0048] Step 206: Reset the timer to zero.

[0049] When the virtual machine exit process is not the default virtual machine exit process, it indicates that the virtual machine has not experienced any abnormalities during this period, and no exception handling is required. Instead, a timer reset operation is performed, that is, the timer duration is cleared to zero. This ensures that when the processor enters non-root mode again, the timer can restart, preventing timing errors that could incorrectly trigger the default virtual machine exit process and affect the normal operation of the virtual machine.

[0050] It can be seen that implementing the method provided by this invention does not affect the normal operation of the virtual machine. Therefore, tools and management software related to running the virtual machine do not need to be modified, ensuring good compatibility of electronic devices implementing this method. Furthermore, since the virtual machine exit process is pre-generated by the central processing unit, it will not interfere with the virtual machine's performance.

[0051] Furthermore, the steps in the above method are relatively loosely coupled, and the steps after the central processing unit generates the preset virtual machine exit process can be flexibly customized according to the actual needs of different scenarios.

[0052] It is worth noting that, in addition to virtual machine crashes caused by microcode anomalies mentioned above, the virtual machine anomaly handling method provided by this invention is also applicable to crashes caused by other virtual machines occupying central processing unit resources for extended periods. The virtual machine anomaly handling method provided by this invention requires no modification to the virtual machine system, and can enhance the availability and robustness of the cloud platform without the user's awareness.

[0053] The steps in the above methods are only for clarity of description. In implementation, they can be combined into one step or some steps can be split into multiple steps. As long as they contain the same logical relationship, they are all within the scope of protection of this patent. Adding insignificant modifications or introducing insignificant designs to the algorithm or process, but without changing the core design of the algorithm and process, are also within the scope of protection of this patent.

[0054] Another embodiment of the present invention relates to a server, such as Figure 3 As shown, it includes at least one processor 301; and a memory 302 communicatively connected to at least one processor 301; wherein the memory 302 stores instructions executable by at least one processor 301, the instructions being executed by at least one processor 301 to enable at least one processor 301 to perform the above-described virtual machine exception handling method.

[0055] The memory 302 and processor 301 are connected via a bus, which can include any number of interconnecting buses and bridges. The bus connects various circuits of one or more processors 301 and memory 302 together. The bus can also connect various other circuits, such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and therefore will not be described further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver can be a single element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by processor 301 is transmitted over a wireless medium via an antenna, which further receives data and transmits it to processor 301.

[0056] Processor 301 is responsible for managing the bus and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management, and other control functions. Memory 302 can be used to store data used by processor 301 during operation.

[0057] Another embodiment of the present invention relates to a computer-readable storage medium storing a computer program. When executed by a processor, the computer program implements an embodiment of the above-described method for handling virtual machine exceptions.

[0058] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. This program is stored in a storage medium and includes several instructions to cause a device (which may be a microcontroller, chip, etc.) or processor to execute all or part of the steps of the methods of the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0059] The above embodiments are provided for those skilled in the art to implement and use the present invention. Those skilled in the art can make various modifications or changes to the above embodiments without departing from the inventive concept of the present invention. Therefore, the protection scope of the present invention is not limited to the above embodiments, but should conform to the maximum scope of the innovative features mentioned in the claims.

Claims

1. A method for handling virtual machine exceptions, characterized in that, include: The central processing unit (CPU) reads a preset time threshold stored in the host machine and triggers a timer to start counting when the CPU switches to non-root mode. The CPU's running time in non-root mode is monitored in real time by the timer's timing. The preset time threshold is used to detect the time when the virtual machine fails to exit normally. If the running time reaches the preset time threshold, the central processing unit generates a preset virtual machine exit process, triggering the virtual machine to pause its operation; If the virtual machine is paused, determine whether the virtual machine exit process is the preset virtual machine exit process; When the virtual machine exit process is the preset virtual machine exit process, the host machine collects relevant information about the virtual machine and reclaims the resources of the central processing unit occupied by the virtual machine to restore the normal interrupt response capability of the central processing unit. When the virtual machine exit process is not a preset virtual machine exit process, the central processing unit will reset the timer to zero.

2. The virtual machine exception handling method according to claim 1, characterized in that, Before the central processing unit reads the preset time threshold stored in the host machine, the following steps are also included: The host machine receives the preset time threshold set by the user through the user-mode program based on the time configuration interface in the user-mode program.

3. The method for handling virtual machine exceptions according to claim 2, characterized in that, After receiving the preset time threshold set by the user through the user-mode program, the method further includes: If the preset time threshold set by the user is less than the minimum preset time threshold, the host machine sends a reset reminder to the user or updates the preset time threshold to the minimum time threshold.

4. The method for handling virtual machine exceptions according to claim 1, characterized in that, The central processing unit reads the preset time threshold stored in the host machine, including: When the central processing unit switches to non-root mode, it reads the preset time threshold corresponding to the currently running virtual machine stored in the host machine.

5. The method for handling virtual machine exceptions according to any one of claims 1 to 4, characterized in that, After generating the preset virtual machine exit process, the following is also included: The central processing unit generates virtual machine abnormal alarm information on the host machine; After reclaiming the resources occupied by the virtual machine, the following is also included: The central processing unit triggers the virtual machine to restart.

6. The method for handling virtual machine exceptions according to any one of claims 1 to 4, characterized in that, Before the central processing unit reads the preset time threshold stored in the host machine, the following steps are also included: Detect whether the central processing unit has a mechanism to periodically exit non-root mode; If the central processing unit has the mechanism for periodically exiting non-root mode, the host machine stores the preset time threshold for the central processing unit to read.

7. The method for handling virtual machine exceptions according to any one of claims 1 to 4, characterized in that, The relevant information of the virtual machine includes: the software version of the virtual machine, the virtual machine control structure VMCS, and virtual processor information.

8. An electronic device, characterized in that, include: At least one processor; as well as, A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform a virtual machine exception handling method as described in any one of claims 1 to 7.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the virtual machine exception handling method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Management method and system for virtual machine running in host mode and user mode

    CN114489941A