[go: up one dir, main page]

CN118819732A - Interrupt virtualization processing method, device, equipment, and storage medium - Google Patents

Interrupt virtualization processing method, device, equipment, and storage medium Download PDF

Info

Publication number
CN118819732A
CN118819732A CN202410915927.1A CN202410915927A CN118819732A CN 118819732 A CN118819732 A CN 118819732A CN 202410915927 A CN202410915927 A CN 202410915927A CN 118819732 A CN118819732 A CN 118819732A
Authority
CN
China
Prior art keywords
virtual machine
target virtual
target
interrupt
control structure
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410915927.1A
Other languages
Chinese (zh)
Inventor
何星
陈杰
白丹
黄�俊
王超
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Chang'an Technology Co ltd
Original Assignee
Chongqing Chang'an Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing Chang'an Technology Co ltd filed Critical Chongqing Chang'an Technology Co ltd
Priority to CN202410915927.1A priority Critical patent/CN118819732A/en
Publication of CN118819732A publication Critical patent/CN118819732A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45575Starting, stopping, suspending or resuming virtual machine instances

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Memory System Of A Hierarchy Structure (AREA)

Abstract

本发明涉及一种中断虚拟化处理方法、装置、设备、存储介质,包括将进入中断处理的目标虚拟机的目标虚拟机标识和当前状态信息写入虚拟机控制结构;在控制目标虚拟机启动时,将目标虚拟机的虚拟机控制结构的当前状态信息写入与目标虚拟机标识对应的目标影子寄存器中;控制目标虚拟机从目标影子寄存器中读取目标虚拟机的当前状态信息,以使目标虚拟机根据当前状态信息恢复回中断处理前的状态。本发明实施例提高了并发处理能力。

The present invention relates to an interrupt virtualization processing method, device, equipment, and storage medium, including writing a target virtual machine identifier and current state information of a target virtual machine entering interrupt processing into a virtual machine control structure; when controlling the target virtual machine to start, writing the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identifier; and controlling the target virtual machine to read the current state information of the target virtual machine from the target shadow register, so that the target virtual machine is restored to the state before the interrupt processing according to the current state information. The embodiment of the present invention improves the concurrent processing capability.

Description

中断虚拟化处理方法、装置、设备、存储介质Interrupt virtualization processing method, device, equipment, and storage medium

技术领域Technical Field

本发明涉及虚拟化技术领域,具体涉及一种中断虚拟化处理方法、装置、设备、存储介质。The present invention relates to the field of virtualization technology, and in particular to an interrupt virtualization processing method, device, equipment, and storage medium.

背景技术Background Art

在具体实现中,当外围设备(如键盘、鼠标、打印机、网络接口卡等)需要物理设备中的CPU(Central Processing Unit,中央处理单元)的处理其需求时进入中断处理,从而CPU暂停当前正在执行的任务,使得外围设备的需求能够得到及时满足。举例来说,假设CPU当前正在执行电脑硬件扫描的任务,当用户按下键盘上的一个按键时,键盘控制器会发送一个中断请求,通知CPU有键盘的输入数据需要处理,此时CPU暂停当前电脑硬件扫描的任务,进入中断处理。In the specific implementation, when peripheral devices (such as keyboards, mice, printers, network interface cards, etc.) need the CPU (Central Processing Unit) in the physical device to process their needs, they enter interrupt processing, so that the CPU suspends the currently executing task so that the needs of the peripheral devices can be met in time. For example, assuming that the CPU is currently executing a computer hardware scanning task, when the user presses a key on the keyboard, the keyboard controller will send an interrupt request to notify the CPU that there is keyboard input data that needs to be processed. At this time, the CPU suspends the current computer hardware scanning task and enters interrupt processing.

其中,当中断处理是在虚拟化环境中实现时,中断处理可以称为中断虚拟化处理。虚拟化环境是指的包括一个或多个虚拟机(VM,Virtual Machine)的计算环境,虚拟机由虚拟机监控器(VMM,Virtual Machine Monitor)创建和管理。在虚拟化环境中,响应外围设备触发中断处理的事件,需要引起虚拟机监控器分配给虚拟机的vCPU(Virtual CentralProcessing Unit,虚拟中央处理单元)的注意,则vCPU进入中断处理,以便vCPU优先执行外围设备的事件。然而,传统的中断处理方法可能会导致虚拟机的物理设备(宿主机)性能瓶颈,尤其是在多个虚拟机的中断同时发生时。Among them, when interrupt processing is implemented in a virtualized environment, interrupt processing can be called interrupt virtualization processing. A virtualized environment refers to a computing environment that includes one or more virtual machines (VMs), which are created and managed by a virtual machine monitor (VMM). In a virtualized environment, in response to an event in which an interrupt processing is triggered by a peripheral device, the attention of the vCPU (Virtual Central Processing Unit) assigned to the virtual machine by the virtual machine monitor needs to be attracted. The vCPU then enters interrupt processing so that the vCPU can prioritize the execution of peripheral device events. However, traditional interrupt processing methods may cause performance bottlenecks in the physical device (host machine) of the virtual machine, especially when interrupts to multiple virtual machines occur simultaneously.

发明内容Summary of the invention

本发明的目的在于提供一种中断虚拟化处理方法,在多个虚拟机的中断同时发生,可以减少中断处理对物理设备的虚拟机性能的影响。The object of the present invention is to provide an interrupt virtualization processing method, which can reduce the impact of interrupt processing on the virtual machine performance of a physical device when interrupts of multiple virtual machines occur simultaneously.

为了实现上述目的,本发明实施例提供一种中断虚拟化处理方法,应用于物理设备,所述物理设备包括虚拟机监控器,所述物理设备的每个虚拟机配置有影子寄存器,所述虚拟机分别具有对应的虚拟机标识,所述方法包括:In order to achieve the above object, an embodiment of the present invention provides an interrupt virtualization processing method, which is applied to a physical device, wherein the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and the virtual machines respectively have corresponding virtual machine identifiers, and the method includes:

将进入中断处理的目标虚拟机的目标虚拟机标识和当前状态信息写入所述虚拟机控制结构;Writing the target virtual machine identifier and current state information of the target virtual machine entering the interrupt processing into the virtual machine control structure;

在控制所述目标虚拟机启动时,将所述目标虚拟机的所述虚拟机控制结构的所述当前状态信息写入与所述目标虚拟机标识对应的目标影子寄存器中;When controlling the target virtual machine to start, writing the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identifier;

控制所述目标虚拟机从所述目标影子寄存器中读取所述目标虚拟机的所述当前状态信息,以使所述目标虚拟机根据所述当前状态信息恢复回中断处理前的状态。The target virtual machine is controlled to read the current state information of the target virtual machine from the target shadow register, so that the target virtual machine is restored to a state before interrupt processing according to the current state information.

可选地,所述将进入中断处理的目标虚拟机的目标虚拟机标识和当前状态信息写入所述虚拟机控制结构,包括:Optionally, writing the target virtual machine identifier and current state information of the target virtual machine entering the interrupt processing into the virtual machine control structure includes:

在通过所述虚拟机监控器触发目标虚拟机进行中断处理时,控制所述目标虚拟机退出前将所述目标虚拟机的当前状态信息写入到所述目标虚拟机的虚拟机控制结构中,以及将所述目标虚拟机的目标虚拟机标识和当前状态信息写入所述虚拟机控制结构。When the target virtual machine is triggered to perform interrupt processing through the virtual machine monitor, the current status information of the target virtual machine is written into the virtual machine control structure of the target virtual machine before the target virtual machine exits, and the target virtual machine identifier and current status information of the target virtual machine are written into the virtual machine control structure.

可选地,所述在通过所述虚拟机监控器触发目标虚拟机进行中断处理时,控制所述目标虚拟机退出前将所述目标虚拟机的当前状态信息写入到所述目标虚拟机的虚拟机控制结构中,以所述目标虚拟机的目标虚拟机标识写入所述虚拟机控制结构,包括:Optionally, when the target virtual machine is triggered to perform interrupt processing through the virtual machine monitor, controlling the target virtual machine to write the current state information of the target virtual machine into the virtual machine control structure of the target virtual machine before exiting, and writing the target virtual machine identifier of the target virtual machine into the virtual machine control structure includes:

在所述虚拟机执行的过程中,若目标虚拟机接收到所述虚拟机监控器发送的中断信号,触发所述目标虚拟机从虚拟机模式切换至虚拟机监控器模式;During the execution of the virtual machine, if the target virtual machine receives an interrupt signal sent by the virtual machine monitor, the target virtual machine is triggered to switch from the virtual machine mode to the virtual machine monitor mode;

在控制所述目标虚拟机退出前,将所述目标虚拟机的当前状态信息保存到虚拟机控制结构中,以及所述目标虚拟机的目标虚拟机标识写入所述虚拟机控制结构。Before controlling the target virtual machine to exit, the current state information of the target virtual machine is saved in a virtual machine control structure, and the target virtual machine identifier of the target virtual machine is written into the virtual machine control structure.

可选地,所述将所述目标虚拟机的当前状态信息保存到虚拟机控制结构中,以及将所述目标虚拟机的目标虚拟机标识写入所述虚拟机控制结构,包括:Optionally, the step of saving the current state information of the target virtual machine into a virtual machine control structure, and writing a target virtual machine identifier of the target virtual machine into the virtual machine control structure, comprises:

将所述目标虚拟机的当前状态信息保存到虚拟机控制结构的客户状态区域中,以及将所述目标虚拟机的目标虚拟机标识写入所述虚拟机控制结构的中断信息字段寄存器。The current state information of the target virtual machine is saved in the client state area of the virtual machine control structure, and the target virtual machine identifier of the target virtual machine is written into the interrupt information field register of the virtual machine control structure.

可选地,所述方法还包括:Optionally, the method further comprises:

配置所述虚拟机的所述虚拟机控制结构。The virtual machine control structure of the virtual machine is configured.

可选地,所述配置所述虚拟机的所述虚拟机控制结构,包括:Optionally, the virtual machine control structure of configuring the virtual machine includes:

配置所述虚拟机的所述虚拟机控制结构的控制域;configuring a control domain of the virtual machine control structure of the virtual machine;

配置所述虚拟机的所述虚拟机控制结构的所述客户状态区域。The guest state area of the virtual machine control structure of the virtual machine is configured.

可选地,在控制所述目标虚拟机退出前,所述方法还包括:Optionally, before controlling the target virtual machine to exit, the method further includes:

所述目标虚拟机识别中断源,并根据所述中断源确定中断类型号;The target virtual machine identifies an interrupt source and determines an interrupt type number according to the interrupt source;

根据所述中断类型号从所述影子寄存器的中断描述符表中查询对应的中断服务程序的入口地址,以根据所述入口地址跳转到所述中断服务程序进行中断处理。According to the interrupt type number, the entry address of the corresponding interrupt service program is queried from the interrupt descriptor table of the shadow register, so as to jump to the interrupt service program for interrupt processing according to the entry address.

可选地,所述方法还包括:Optionally, the method further comprises:

改造所述虚拟机的虚拟机启动指令;在执行改造的虚拟机启动指令时,从启动的所述虚拟机的虚拟机控制结构中读取虚拟机标识。The virtual machine startup instruction of the virtual machine is modified; when the modified virtual machine startup instruction is executed, the virtual machine identifier is read from the virtual machine control structure of the started virtual machine.

可选地,所述在控制所述目标虚拟机启动时,从所述目标虚拟机的所述虚拟机控制结构中读取所述目标虚拟机的目标虚拟机标识,包括:Optionally, when controlling the target virtual machine to start, reading the target virtual machine identifier of the target virtual machine from the virtual machine control structure of the target virtual machine includes:

在执行改造后的所述虚拟机启动指令控制所述目标虚拟机启动时,触发所述目标虚拟机从虚拟机监控器模式切换至虚拟机模式;When executing the modified virtual machine startup instruction to control the startup of the target virtual machine, triggering the target virtual machine to switch from the virtual machine monitor mode to the virtual machine mode;

从所述目标虚拟机的所述虚拟机控制结构中读取所述目标虚拟机的目标虚拟机标识。A target virtual machine identifier of the target virtual machine is read from the virtual machine control structure of the target virtual machine.

可选地,所述从所述目标虚拟机的所述虚拟机控制结构中读取所述目标虚拟机的目标虚拟机标识,包括:Optionally, reading the target virtual machine identifier of the target virtual machine from the virtual machine control structure of the target virtual machine includes:

执行虚拟机读取指令从所述目标虚拟机的所述虚拟机控制结构的中断信息字段寄存器中读取所述目标虚拟机的目标虚拟机标识。The virtual machine read instruction is executed to read the target virtual machine identifier of the target virtual machine from the interrupt information field register of the virtual machine control structure of the target virtual machine.

可选地,在所述将所述目标虚拟机的所述虚拟机控制结构的所述当前状态信息写入与所述目标虚拟机标识对应的目标影子寄存器中之后,所述方法还包括:Optionally, after writing the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identifier, the method further includes:

将所述目标虚拟机的所述虚拟机控制结构的其他内容写入对应的其他寄存器中;所述其他内容至少包括段寄存器的内容。Writing other contents of the virtual machine control structure of the target virtual machine into corresponding other registers; the other contents at least include the contents of the segment register.

可选地,所述目标虚拟机为一个或者多个,所述影子寄存器为一个或者多个。Optionally, the number of the target virtual machines is one or more, and the number of the shadow registers is one or more.

本发明实施例还公开了一种中断虚拟化处理装置,应用于物理设备,所述物理设备包括虚拟机监控器,所述物理设备的每个虚拟机配置有影子寄存器,所述虚拟机分别具有对应的虚拟机标识,所述装置用于实现如本发明实施例所述的方法。An embodiment of the present invention also discloses an interrupt virtualization processing device, which is applied to a physical device, wherein the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and each virtual machine has a corresponding virtual machine identifier. The device is used to implement the method described in the embodiment of the present invention.

本发明实施例还公开了一种电子设备,包括至少一个处理器与所述至少一个处理器通信连接的存储器;An embodiment of the present invention further discloses an electronic device, comprising at least one processor and a memory communicatively connected to the at least one processor;

所述存储器,用于存放计算机程序;The memory is used to store computer programs;

所述处理器,用于执行存储器上所存放的程序时,实现如本发明实施例所述的方法。The processor is used to implement the method described in the embodiment of the present invention when executing the program stored in the memory.

本发明实施例还公开了一种计算机可读存储介质,其上存储有计算机程序,当由一个或多个处理器执行时,使得所述处理器执行如本发明实施例所述的方法。The embodiment of the present invention further discloses a computer-readable storage medium on which a computer program is stored. When executed by one or more processors, the processors are enabled to execute the method described in the embodiment of the present invention.

本发明的有益效果:Beneficial effects of the present invention:

本发明实施例应用于物理设备,物理设备包括虚拟机监控器,物理设备的每个虚拟机配置有影子寄存器,虚拟机分别具有对应的虚拟机标识,在一个或者多个虚拟机触发中断处理时,将进入中断处理的虚拟机作为目标虚拟机,将目标虚拟机的当前状态信息和目标虚拟机标识写入虚拟机控制结构;在控制目标虚拟机启动时,将目标虚拟机的虚拟机控制结构的当前状态信息写入与目标虚拟机标识对应的目标影子寄存器中,控制目标虚拟机从目标影子寄存器中读取目标虚拟机的当前状态信息,以使目标虚拟机根据当前状态信息恢复回中断处理前的状态。本发明实施例通过为物理设备的每个虚拟机的处理器分别配置物理的影子寄存器,在一个或者多个虚拟机进入中断处理时,可以分别通过其对应的影子寄存器来并行恢复至中断处理前的状态,提高了物理设备的并发处理能力,减少了中断处理对物理设备的虚拟机性能的影响。The embodiment of the present invention is applied to a physical device, the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and the virtual machines have corresponding virtual machine identifiers. When one or more virtual machines trigger interrupt processing, the virtual machine entering the interrupt processing is used as the target virtual machine, and the current state information of the target virtual machine and the target virtual machine identifier are written into the virtual machine control structure; when the target virtual machine is controlled to start, the current state information of the virtual machine control structure of the target virtual machine is written into the target shadow register corresponding to the target virtual machine identifier, and the target virtual machine is controlled to read the current state information of the target virtual machine from the target shadow register, so that the target virtual machine is restored to the state before the interrupt processing according to the current state information. The embodiment of the present invention configures physical shadow registers for the processors of each virtual machine of the physical device respectively, and when one or more virtual machines enter the interrupt processing, they can be restored to the state before the interrupt processing in parallel through their corresponding shadow registers, thereby improving the concurrent processing capability of the physical device and reducing the impact of the interrupt processing on the performance of the virtual machines of the physical device.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

图1为一种Arm架构中传统外围设备的中断产生方法示意图;FIG1 is a schematic diagram of a method for generating interrupts of a conventional peripheral device in an Arm architecture;

图2为一种Arm架构中新的外围设备的中断产生方法示意图;FIG2 is a schematic diagram of a method for generating interrupts of a new peripheral device in an Arm architecture;

图3为一种x86下硬件中断处理过程的示意图;FIG3 is a schematic diagram of a hardware interrupt processing process under x86;

图4为一种x86下硬件辅助虚拟化技术的实现示意图;FIG4 is a schematic diagram of an implementation of hardware-assisted virtualization technology under x86;

图5为一种目前多虚拟机的中断虚拟化的实现示意图;FIG5 is a schematic diagram of a current implementation of interrupt virtualization of multiple virtual machines;

图6为本发明实施例中提供的一种中断虚拟化处理方法的步骤流程图;FIG6 is a flowchart of a method for processing interrupt virtualization provided in an embodiment of the present invention;

图7为本发明实施例中提供的一种多虚拟机并行中断虚拟化的实现示意图;7 is a schematic diagram of an implementation of parallel interrupt virtualization of multiple virtual machines provided in an embodiment of the present invention;

图8为本发明实施例中提供的一种VMCS的区域的示意图;FIG8 is a schematic diagram of a region of a VMCS provided in an embodiment of the present invention;

图9为本发明实施例中提供的一种VMCS的控制域配置的示意图之一;FIG9 is a schematic diagram of a control domain configuration of a VMCS provided in an embodiment of the present invention;

图10为本发明实施例中提供的一种VMCS的控制域配置的示意图之二;FIG10 is a second schematic diagram of a control domain configuration of a VMCS provided in an embodiment of the present invention;

图11为本发明实施例中提供的一种GUEST STATE AREA区域的示意图;FIG11 is a schematic diagram of a GUEST STATE AREA provided in an embodiment of the present invention;

图12为本发明实施例提供的一种电子设备的结构示意图。FIG. 12 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

具体实施方式DETAILED DESCRIPTION

以下将参照附图和优选实施例来说明本发明的实施方式,本领域技术人员可由本说明书中所揭露的内容轻易地了解本发明的其他优点与功效。本发明还可以通过另外不同的具体实施方式加以实施或应用,本说明书中的各项细节也可以基于不同观点与应用,在没有背离本发明的精神下进行各种修饰或改变。应当理解,优选实施例仅为了说明本发明,而不是为了限制本发明的保护范围。The following will describe the embodiments of the present invention with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention, not for limiting the scope of protection of the present invention.

参照图1,是本发明实施例中提供的一种Arm架构中传统外围设备的中断产生方法示意图,外围设备(Peripheral)通过中断连接线与中断控制器(interrupt controller)进行连接,外围设备通过向中断控制器发送interrupt signal(中断信号)触发中断。其中,IRQ为Interrupt Request,即中断请求,FIQ为Fast Interrupt Request,即快速中断请求,特权执行(Privileged Execution,PE)可以用于执行IRQ和FIQ等特权。Referring to Fig. 1, it is a schematic diagram of an interrupt generation method of a traditional peripheral device in an Arm architecture provided in an embodiment of the present invention, wherein the peripheral device is connected to an interrupt controller via an interrupt connection line, and the peripheral device triggers an interrupt by sending an interrupt signal to the interrupt controller. Among them, IRQ is Interrupt Request, i.e., interrupt request, FIQ is Fast Interrupt Request, i.e., fast interrupt request, and Privileged Execution (PE) can be used to execute privileges such as IRQ and FIQ.

参照图2,是本发明实施例中提供的一种Arm架构中新的外围设备的中断产生方法示意图,外围设备通过消息的方式(发送中断消息(interrupt message))传递中断,消息传递到总线中。2 is a schematic diagram of a new interrupt generation method for a peripheral device in an Arm architecture provided in an embodiment of the present invention, wherein the peripheral device transmits an interrupt by means of a message (sending an interrupt message), and the message is transmitted to the bus.

上述新的方案的改进点是将虚拟设备产生的虚拟中断以物理中断的方式传递给中断控制器,但是为了达到此目的,新增了一个硬件设备,此设备就是将虚拟定时器(vTimer)的中断信息转换成物理的中断信号,然后通过消息机制发送给中断控制器,中断控制器再发送给vCPU(Virtual Central Processing Unit,虚拟中央处理单元)实现中断,此方案缺陷如下:第一,需要增加新的硬件设备,增加虚拟化成本;第二,中断虚拟化本身的运行机制并没有改变,不同虚拟机同时运行虚拟中断,中断处理程序依旧只能串行执行,硬件虚拟机制的实现本身制约着中断虚拟化的性能。The improvement of the above new solution is to pass the virtual interrupt generated by the virtual device to the interrupt controller in the form of a physical interrupt. However, in order to achieve this goal, a new hardware device is added. This device converts the interrupt information of the virtual timer (vTimer) into a physical interrupt signal, and then sends it to the interrupt controller through a message mechanism. The interrupt controller then sends it to the vCPU (Virtual Central Processing Unit) to implement the interrupt. The defects of this solution are as follows: First, new hardware devices need to be added, which increases the virtualization cost; second, the operating mechanism of the interrupt virtualization itself has not changed. Different virtual machines run virtual interrupts at the same time, and the interrupt handler can only be executed serially. The implementation of the hardware virtualization mechanism itself restricts the performance of interrupt virtualization.

参照图3,是本发明实施例中提供的一种x86下硬件中断处理过程的示意图,具体过程包括:3 is a schematic diagram of a hardware interrupt processing process under x86 provided in an embodiment of the present invention, and the specific process includes:

1)CPU执行某条指令;2)发生中断,CPU内部产生中断信号;3)CPU内部判断中断来源,产生中断类型码N;4)当前CS/IP/PSW压栈;5)清除IF和TF;6)取CS/IP新值(通过IDT);7)转入中断服务程序;8)开放中断;9)IRET指令使旧的CS/IP/PSW弹出堆栈;10)返回被中断的程序。其中,CPU中包括CS:代码段寄存器;IP:Instruction Pointer,指令指针,IP也称为EIP;FLAGS:标志寄存器,其中,标志寄存器包括进位标志(CF)、零标志(ZF)、符号标志(SF)、中断标志(IF)、调试标志(TF)等。PSW为Program Status Word,程序状态字。IRET指令是从异常处理程序或中断服务例程(ISR)返回的指令。1) The CPU executes an instruction; 2) An interrupt occurs, and an interrupt signal is generated inside the CPU; 3) The CPU determines the source of the interrupt and generates an interrupt type code N; 4) The current CS/IP/PSW is pushed onto the stack; 5) IF and TF are cleared; 6) The new value of CS/IP is obtained (via IDT); 7) Enter the interrupt service routine; 8) Open the interrupt; 9) The IRET instruction pops the old CS/IP/PSW off the stack; 10) Return to the interrupted program. Among them, the CPU includes CS: code segment register; IP: Instruction Pointer, IP is also called EIP; FLAGS: flag register, among which the flag register includes carry flag (CF), zero flag (ZF), sign flag (SF), interrupt flag (IF), debug flag (TF), etc. PSW is Program Status Word. The IRET instruction is an instruction to return from an exception handler or interrupt service routine (ISR).

在实际中,物理设备实现中断处理流程具体为:1.关中断:CPU关闭中断响应,即不再接收其他外部中断请求;2.保存断点:将发生中断处的指令地址压入堆栈,以使中断处理完后能正确地返回;3.识别中断源:CPU识别中断的来源,确定中断类型号,通过中断描述符表(IDT,Interrupt Descriptor Table)从而找到相应的中断服务程序的入口地址;4.保护现场:将发生中断处的有关寄存器(中断服务程序中要使用的寄存器)以及标志寄存器的内容压入堆栈;5.执行中断服务程序:转到中断服务程序的入口地址开始执行,可在适当时刻重新开放中断,以便允许相应较高优先级的外部中断;6.恢复现场并返回:把“保护现场”时压入堆栈的信息弹回原寄存器,然后返回执行中断返回指令,从而返回主程序继续运行;In practice, the interrupt handling process implemented by physical devices is as follows: 1. Turn off interrupts: the CPU turns off interrupt response, that is, it no longer receives other external interrupt requests; 2. Save breakpoints: push the instruction address where the interrupt occurs into the stack so that it can return correctly after the interrupt is processed; 3. Identify the interrupt source: the CPU identifies the source of the interrupt, determines the interrupt type number, and finds the entry address of the corresponding interrupt service program through the interrupt descriptor table (IDT); 4. Protect the scene: push the relevant registers where the interrupt occurs (registers to be used in the interrupt service program) and the contents of the flag register into the stack; 5. Execute the interrupt service program: jump to the entry address of the interrupt service program to start execution, and reopen the interrupt at an appropriate time to allow corresponding higher priority external interrupts; 6. Restore the scene and return: bounce the information pushed into the stack when "protecting the scene" back to the original register, and then return to execute the interrupt return instruction, thereby returning to the main program to continue running;

其中,中断服务程序的存放地址位于IDT(中断描述符表)当中,通过中断传给CPU的中断向量号(中断类型号),找到对应的ISR(Interrupt Service Routine,中断服务程序),其中,IDT是全局唯一的,所有CPU共用一个IDT,多核CPU接收到中断后都会去IDT当中查询对应的ISR(中断服务程序),因为整个X86硬件的中断服务程序是所有CPU上运行的内核程序共享的,并且对同一个中断的处理方式是相同的。Among them, the storage address of the interrupt service program is located in the IDT (interrupt descriptor table). The interrupt vector number (interrupt type number) transmitted to the CPU by the interrupt finds the corresponding ISR (Interrupt Service Routine). Among them, IDT is globally unique. All CPUs share one IDT. After receiving an interrupt, the multi-core CPU will query the corresponding ISR (interrupt service program) in the IDT, because the interrupt service program of the entire X86 hardware is shared by the kernel programs running on all CPUs, and the same interrupt is handled in the same way.

传统的硬件辅助虚拟化实现是通过中断注入的方式实现的,虽然相比纯软件的实现方式来说性能较高,但是仍然存在性能瓶颈,以X86中断注入虚拟化为例,参照图4,是本发明实施例中提供的一种x86下硬件辅助虚拟化技术的实现示意图,具体过程包括:Traditional hardware-assisted virtualization is implemented by interrupt injection. Although the performance is higher than that of pure software implementation, there is still a performance bottleneck. Taking X86 interrupt injection virtualization as an example, referring to FIG4 , which is a schematic diagram of an implementation of a hardware-assisted virtualization technology under x86 provided in an embodiment of the present invention, the specific process includes:

第一步:虚拟中断控制器通过核间中断(IPI,Inter-Processor Interrupt),使虚拟机从Guest模式(虚拟机模式)退回到主机模式(VMM虚拟机监控器模式),虚拟机此时进入了Hypervisor(虚拟机监控器)模式;Step 1: The virtual interrupt controller uses the inter-processor interrupt (IPI) to return the virtual machine from the guest mode (virtual machine mode) to the host mode (VMM virtual machine monitor mode). The virtual machine now enters the hypervisor (virtual machine monitor) mode.

第二步:将中断向量信息,主要是中断向量表vector信息写入vmcs(虚拟机控制结构区域,Virtual Machine Control Structure Region)区域;Step 2: Write the interrupt vector information, mainly the interrupt vector table vector information, into the vmcs (Virtual Machine Control Structure Region) area;

第三步:通过vmresume或vmlaunch指令启动虚拟机;其中,vmresume或vmlaunch是x86架构中用于虚拟化技术的指令,由虚拟机监控器(Hypervisor)或虚拟机管理器(VMM,Virtual Machine Monitor)使用,用于启动和管理。Step 3: Start the virtual machine through the vmresume or vmlaunch instruction; vmresume or vmlaunch is an instruction used for virtualization technology in the x86 architecture, and is used by a virtual machine monitor (Hypervisor) or a virtual machine manager (VMM) for startup and management.

以上为虚拟中断的注入过程,影响虚拟机性能的因素如下:1、首先虚拟机因为虚拟中断要退出;2、虚拟中断注入的实现需要向VMCS寄存器指向的内存区域interruptionfield中写入中断向量相关的信息;3、然后需要通过操作系统的进程调度,调度到虚拟机下次运行的时候,才可以执行中断注入,中断注入,首先要将VMCS中GUEST STATE AREA(客户状态区域)区域的内容恢复到物理CPU寄存器当中,其中,与中断相关的是IDTR(InterruptDescriptor Table Register,中断描述符表寄存器)寄存器,然后再通过IDTR和vector找到中断服务程序,执行对应的中断服务程序进行中断处理。The above is the injection process of virtual interrupts. The factors that affect the performance of the virtual machine are as follows: 1. First, the virtual machine needs to exit due to the virtual interrupt; 2. The implementation of virtual interrupt injection requires writing interrupt vector-related information to the interruptionfield in the memory area pointed to by the VMCS register; 3. Then it is necessary to schedule the interrupt injection through the operating system's process scheduling until the next time the virtual machine runs. For interrupt injection, the content of the GUEST STATE AREA (customer status area) in VMCS must first be restored to the physical CPU register, among which the IDTR (Interrupt Descriptor Table Register) register is related to the interrupt, and then the interrupt service program is found through IDTR and vector, and the corresponding interrupt service program is executed to handle the interrupt.

综上,在上述中断虚拟化中,其中对性能产生严重影响的问题在于(虚拟机中断串行化,即,虚拟机只能依次进行中断处理),示例性地,参照图5,为一种目前多虚拟机的中断虚拟化的实现示意图,IDTR寄存器(物理CPU-IDTR)是个全局的寄存器,相当于每次只能有一个虚拟机(vCPU-IDTR)或者说宿主机占用,也就是说,当一个虚拟机在使用IDTR寄存器的时候,其余的虚拟机或者宿主机只能等待下一次运行的时候使用,尤其如果宿主机频繁有中断产生,会导致虚拟机需要频繁的退出,虚拟机需要频繁等待中断服务程序的运行,影响了虚拟机性能。由于IDTR寄存器是CPU物理全局的寄存器,只有一个,因此当多个虚拟机触发中断处理时,多CPU核心中只有一个虚拟机能够进行中断处理,将并行转化为串行,哪怕不同CPU核上运行的是不同虚拟机,也就是说多个虚拟机的多个虚拟中断同时发生,这些虚拟中断也是依次进行。In summary, in the above interrupt virtualization, the problem that has a serious impact on performance is (virtual machine interrupt serialization, that is, virtual machines can only process interrupts in sequence). For example, referring to FIG5, a schematic diagram of the implementation of interrupt virtualization of multiple virtual machines at present is shown. The IDTR register (physical CPU-IDTR) is a global register, which is equivalent to only one virtual machine (vCPU-IDTR) or host machine occupying it at a time. That is to say, when a virtual machine uses the IDTR register, the remaining virtual machines or host machines can only wait for the next operation to use it. In particular, if the host machine frequently has interrupts, it will cause the virtual machine to exit frequently, and the virtual machine needs to frequently wait for the operation of the interrupt service program, which affects the performance of the virtual machine. Since the IDTR register is a physical global register of the CPU, there is only one. Therefore, when multiple virtual machines trigger interrupt processing, only one virtual machine in the multiple CPU cores can process the interrupt, converting parallel to serial, even if different virtual machines are running on different CPU cores, that is, multiple virtual interrupts of multiple virtual machines occur at the same time, these virtual interrupts are also performed in sequence.

针对上述问题,本发明实施例提供了一种针对多虚拟机的中断虚拟化处理方法,给物理设备的每个虚拟机的CPU(vCPU)设置一个IDTR的影子寄存器,即,在物理设备上设置一组IDTR寄存器集合,这样即使多个虚拟机的中断同时发生,能保证同时执行虚拟中断,保证并发性,提升性能。In response to the above problems, an embodiment of the present invention provides an interrupt virtualization processing method for multiple virtual machines, which sets an IDTR shadow register for the CPU (vCPU) of each virtual machine of the physical device, that is, sets a set of IDTR register sets on the physical device. In this way, even if interrupts of multiple virtual machines occur at the same time, the virtual interrupts can be executed simultaneously, thereby ensuring concurrency and improving performance.

参照图6,示出了本发明实施例中提供的一种中断虚拟化处理方法的步骤流程图,应用于物理设备,所述物理设备包括虚拟机监控器,所述物理设备的每个虚拟机配置有影子寄存器,所述虚拟机分别具有对应的虚拟机标识,具体包括如下步骤:6, a flowchart of a method for processing interrupt virtualization provided in an embodiment of the present invention is shown, which is applied to a physical device, wherein the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and each virtual machine has a corresponding virtual machine identifier, and specifically includes the following steps:

步骤601、将进入中断处理的目标虚拟机的目标虚拟机标识和当前状态信息写入所述虚拟机控制结构。Step 601: Write the target virtual machine identifier and current state information of the target virtual machine entering interrupt processing into the virtual machine control structure.

在本发明实施例中,参照图7,为本发明实施例中提供的一种多虚拟机并行中断虚拟化的实现示意图,物理设备(宿主机)上可以包括多个虚拟机,每个虚拟机分别具有其对应的vCPU(处理器),给每个虚拟机的vCPU设置一个物理存在的影子寄存器(IDTR Shadow),每个虚拟机或者vCPU具有对应的虚拟机标识(CPUID),基于虚拟机标识可以唯一查找到物理设备中对应的虚拟机。具体地,影子寄存器为IDTR(Interrupt Descriptor TableRegister,中断描述符表寄存器),是x86架构中的一个特殊寄存器,用于存储中断描述符表(Interrupt Descriptor Table,IDT)的基地址和界限,其中,中断描述符表是一个关键的数据结构,是操作系统内核用来管理中断和异常处理的关键组件,可以用于存储中断服务程序(Interrupt Service Routine,ISR)的入口地址,当虚拟机通过虚拟机监控器触中断处理时,使用IDT来查找对应的入口地址以跳转到行相应的中断服务程序。可见,本发明实施例的影子寄存器是一组IDTR寄存器的集合,并且是每个虚拟机分别对应的,如此,即使多个虚拟机的中断处理同时发生,能保证同时执行虚拟机的中断处理,保证并发性,提升性能。In an embodiment of the present invention, referring to FIG. 7, a schematic diagram of a multi-virtual machine parallel interrupt virtualization implementation provided in an embodiment of the present invention is provided. A physical device (host machine) may include multiple virtual machines, each virtual machine has its corresponding vCPU (processor), and a physically existing shadow register (IDTR Shadow) is set for the vCPU of each virtual machine. Each virtual machine or vCPU has a corresponding virtual machine identifier (CPUID), and the corresponding virtual machine in the physical device can be uniquely found based on the virtual machine identifier. Specifically, the shadow register is IDTR (Interrupt Descriptor Table Register), which is a special register in the x86 architecture, used to store the base address and limit of the interrupt descriptor table (Interrupt Descriptor Table, IDT), wherein the interrupt descriptor table is a key data structure, a key component used by the operating system kernel to manage interrupts and exception handling, and can be used to store the entry address of the interrupt service routine (Interrupt Service Routine, ISR). When the virtual machine triggers interrupt processing through the virtual machine monitor, the IDT is used to find the corresponding entry address to jump to the corresponding interrupt service routine. It can be seen that the shadow register of the embodiment of the present invention is a set of IDTR registers, and corresponds to each virtual machine respectively. In this way, even if the interrupt processing of multiple virtual machines occurs at the same time, the interrupt processing of the virtual machines can be executed at the same time, thereby ensuring concurrency and improving performance.

可选地,虚拟机监控器可以是type2-hypervisor(第二类虚拟机监控器),type2-hypervisor是一种运行在操作系统之上的虚拟化软件,与Type 1Hypervisor(第一类虚拟机监控器)不同,Type 2Hypervisor不是直接运行在物理设备的硬件上,而是作为物理设备的操作系统上的一个应用程序运行。Optionally, the virtual machine monitor may be a type 2-hypervisor, which is a virtualization software running on top of an operating system. Unlike a Type 1 Hypervisor, a Type 2 Hypervisor does not run directly on the hardware of a physical device, but runs as an application on the operating system of the physical device.

虚拟机具有VMCS(Virtual Machine Control Structure,虚拟机控制结构),是x86架构中的一个关键数据结构,用于存储和管理虚拟机的状态信息。VMCS是虚拟机监控器用来控制虚拟机执行的机制,允许虚拟机监控器在虚拟机和宿主机之间高效地切换,同时保持虚拟机的状态隔离和完整性。其中,VMCS包含包括多个域(区域),参照图8,具体可以包括以下几个区域:CONTROL FIELDS(控制域):包含了多个控制字段,用于配置虚拟机的执行行为,如虚拟中断控制、虚拟机退出控制等;其中,CONTROL FIELDS包括VM-EXIT CONTROLFIELDS(虚拟机退出控制字段)和VM-EXIT INFORMATION FIELDS(虚拟机退出信息字段),其中,VM-EXIT CONTROL FIELDS用于控制虚拟机退出的行为,VM-EXIT INFORMATION FIELDS用于存储虚拟机退出时的相关信息。当然,VMCS还可以包括如下的区域:GUEST STATE AREA区域(客户状态区域):存储了虚拟机(Guest)在执行时的状态信息,状态信息可以包括通用寄存器、段寄存器、标志寄存器、指令指针、栈指针等信息,基于这些状态信息可以恢复至中断处理前的状态。当虚拟机退出到虚拟机监控器状态时,虚拟机的当前的当前状态信息会被保存到VMCS中;VM Entry Controls(虚拟机进入控制域):包含了控制虚拟机进入的设置,如是否启用虚拟中断、是否允许特定的指令执行等。VMCS通过一系列的指令来操作,这些指令允许虚拟机监控器读取和写入VMCS中的数据,从而可以基于VMCS中的数据(例如虚拟机的状态信息)以及控制虚拟机的执行。The virtual machine has a VMCS (Virtual Machine Control Structure), which is a key data structure in the x86 architecture and is used to store and manage the state information of the virtual machine. VMCS is a mechanism used by the virtual machine monitor to control the execution of the virtual machine, allowing the virtual machine monitor to efficiently switch between the virtual machine and the host machine while maintaining the state isolation and integrity of the virtual machine. Among them, VMCS includes multiple domains (areas), referring to Figure 8, which can specifically include the following areas: CONTROL FIELDS (control domain): contains multiple control fields for configuring the execution behavior of the virtual machine, such as virtual interrupt control, virtual machine exit control, etc.; among them, CONTROL FIELDS includes VM-EXIT CONTROLFIELDS (virtual machine exit control field) and VM-EXIT INFORMATION FIELDS (virtual machine exit information field), among which VM-EXIT CONTROL FIELDS is used to control the behavior of the virtual machine exit, and VM-EXIT INFORMATION FIELDS is used to store relevant information when the virtual machine exits. Of course, VMCS can also include the following areas: GUEST STATE AREA area (guest state area): stores the state information of the virtual machine (Guest) during execution. The state information may include general registers, segment registers, flag registers, instruction pointers, stack pointers and other information. Based on this state information, it can be restored to the state before interrupt processing. When the virtual machine exits to the virtual machine monitor state, the current state information of the virtual machine will be saved in VMCS; VM Entry Controls (virtual machine entry control domain): contains settings for controlling the entry of the virtual machine, such as whether to enable virtual interrupts, whether to allow specific instructions to execute, etc. VMCS operates through a series of instructions that allow the virtual machine monitor to read and write data in VMCS, so that it can be based on the data in VMCS (such as the state information of the virtual machine) and control the execution of the virtual machine.

在本发明的一种实施例中,所述步骤601、将进入中断处理的目标虚拟机的目标虚拟机标识和当前状态信息写入所述虚拟机控制结构,包括:In one embodiment of the present invention, the step 601 of writing the target virtual machine identifier and current state information of the target virtual machine entering the interrupt processing into the virtual machine control structure includes:

在通过所述虚拟机监控器触发目标虚拟机进行中断处理时,控制所述目标虚拟机退出前将所述目标虚拟机的当前状态信息写入到所述目标虚拟机的虚拟机控制结构中,以及将所述目标虚拟机的目标虚拟机标识写入所述虚拟机控制结构。When the target virtual machine is triggered to perform interrupt processing through the virtual machine monitor, the current state information of the target virtual machine is written into the virtual machine control structure of the target virtual machine before the target virtual machine exits, and the target virtual machine identifier of the target virtual machine is written into the virtual machine control structure.

在本发明实施例中,在通过虚拟机监控器(VMM)触发一个或者多个虚拟机进行中断处理时,将进入中断处理的虚拟机作为目标虚拟机,控制各个目标虚拟机退出前将其的当前状态信息写入到其VMCS中,同时,将目标虚拟机的目标虚拟机标识(CPUID)写入其VMCS。In an embodiment of the present invention, when one or more virtual machines are triggered to perform interrupt processing through a virtual machine monitor (VMM), the virtual machine entering the interrupt processing is used as the target virtual machine, and the current state information of each target virtual machine is controlled to be written into its VMCS before exiting. At the same time, the target virtual machine identifier (CPUID) of the target virtual machine is written into its VMCS.

步骤602、在控制所述目标虚拟机启动时,将所述目标虚拟机的所述虚拟机控制结构的所述当前状态信息写入与所述目标虚拟机标识对应的目标影子寄存器中。Step 602: When controlling the target virtual machine to start, write the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identifier.

在本发明实施例中,在控制目标虚拟机启动,例如在对应的中断服务程序完成中断处理后,可以从该目标虚拟机的VMCS中独权到目标虚拟机退出前保存的目标虚拟机标识(CPUID),另外,将目标虚拟机的VMCS的当前状态信息写入与目标虚拟机标识(CPUID)对应的目标影子寄存器中。In an embodiment of the present invention, when controlling the startup of the target virtual machine, for example, after the corresponding interrupt service program completes interrupt processing, the target virtual machine identifier (CPUID) saved before the target virtual machine exits can be obtained from the VMCS of the target virtual machine. In addition, the current state information of the VMCS of the target virtual machine is written into the target shadow register corresponding to the target virtual machine identifier (CPUID).

步骤603、控制所述目标虚拟机从所述目标影子寄存器中读取所述目标虚拟机的所述当前状态信息,以使所述目标虚拟机根据所述当前状态信息恢复回中断处理前的状态。Step 603: Control the target virtual machine to read the current state information of the target virtual machine from the target shadow register, so that the target virtual machine is restored to the state before the interrupt processing according to the current state information.

在本发明实施例中,根据前述可知,在目标虚拟机的目标影子寄存器已经保存了从VMCS中读取的目标虚拟机的当前状态信息,此时,可以控制目标虚拟机从目标影子寄存器中读取到目标虚拟机的当前状态信息,随后,就可以基于当前状态信息恢复回中断处理前的状态。In the embodiment of the present invention, according to the foregoing, the target shadow register of the target virtual machine has saved the current state information of the target virtual machine read from the VMCS. At this time, the target virtual machine can be controlled to read the current state information of the target virtual machine from the target shadow register, and then, the state before the interrupt processing can be restored based on the current state information.

本发明实施例应用于物理设备,物理设备包括虚拟机监控器,物理设备的每个虚拟机配置有影子寄存器,虚拟机分别具有对应的虚拟机标识,在一个或者多个虚拟机触发中断处理时,将进入中断处理的虚拟机作为目标虚拟机,将目标虚拟机的当前状态信息和目标虚拟机标识写入虚拟机控制结构;在控制目标虚拟机启动时,将目标虚拟机的虚拟机控制结构的当前状态信息写入与目标虚拟机标识对应的目标影子寄存器中,控制目标虚拟机从目标影子寄存器中读取目标虚拟机的当前状态信息,以使目标虚拟机根据当前状态信息恢复回中断处理前的状态。本发明实施例通过为物理设备的每个虚拟机的处理器分别配置物理的影子寄存器,在一个或者多个虚拟机进入中断处理时,可以分别通过其对应的影子寄存器来并行恢复至中断处理前的状态,提高了物理设备的并发处理能力,减少了中断处理对物理设备的虚拟机性能的影响。The embodiment of the present invention is applied to a physical device, the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and the virtual machines have corresponding virtual machine identifiers. When one or more virtual machines trigger interrupt processing, the virtual machine entering the interrupt processing is used as the target virtual machine, and the current state information of the target virtual machine and the target virtual machine identifier are written into the virtual machine control structure; when the target virtual machine is controlled to start, the current state information of the virtual machine control structure of the target virtual machine is written into the target shadow register corresponding to the target virtual machine identifier, and the target virtual machine is controlled to read the current state information of the target virtual machine from the target shadow register, so that the target virtual machine is restored to the state before the interrupt processing according to the current state information. The embodiment of the present invention configures physical shadow registers for the processors of each virtual machine of the physical device respectively, and when one or more virtual machines enter the interrupt processing, they can be restored to the state before the interrupt processing in parallel through their corresponding shadow registers, thereby improving the concurrent processing capability of the physical device and reducing the impact of the interrupt processing on the performance of the virtual machines of the physical device.

在本发明的一种实施例中,所述在通过所述虚拟机监控器触发目标虚拟机进行中断处理时,控制所述目标虚拟机退出前将所述目标虚拟机的当前状态信息写入到所述目标虚拟机的虚拟机控制结构中,以及将所述目标虚拟机的目标虚拟机标识写入所述虚拟机控制结构,包括:In an embodiment of the present invention, when the target virtual machine is triggered to perform interrupt processing by the virtual machine monitor, controlling the target virtual machine to write the current state information of the target virtual machine into the virtual machine control structure of the target virtual machine before exiting, and writing the target virtual machine identifier of the target virtual machine into the virtual machine control structure, comprises:

在所述虚拟机执行的过程中,若目标虚拟机接收到所述虚拟机监控器发送的中断信号,触发所述目标虚拟机从虚拟机模式切换至虚拟机监控器模式;During the execution of the virtual machine, if the target virtual machine receives an interrupt signal sent by the virtual machine monitor, the target virtual machine is triggered to switch from the virtual machine mode to the virtual machine monitor mode;

在控制所述目标虚拟机退出前,将所述目标虚拟机的当前状态信息保存到虚拟机控制结构中,以及将所述目标虚拟机标识写入所述虚拟机控制结构。Before controlling the target virtual machine to exit, the current state information of the target virtual machine is saved in a virtual machine control structure, and the target virtual machine identifier is written into the virtual machine control structure.

在本发明实施例中,在虚拟机在物理设备中执行的过程中,若某一个或者多个虚拟机(即目标虚拟机)接收到虚拟机监控器(VMM)发送的中断信号,将触发目标虚拟机从虚拟机模式(Guset模式)切换至虚拟机监控器模式(kernel模式),其中,在控制目标虚拟机退出前,可以将目标虚拟机的当前状态信息保存到VMCS中,以及,将目标虚拟机的目标虚拟机标识(CPUID)写入VMCS。In an embodiment of the present invention, during the execution of a virtual machine in a physical device, if one or more virtual machines (i.e., the target virtual machine) receives an interrupt signal sent by a virtual machine monitor (VMM), the target virtual machine will be triggered to switch from virtual machine mode (Guset mode) to virtual machine monitor mode (kernel mode), wherein, before controlling the target virtual machine to exit, the current state information of the target virtual machine can be saved in the VMCS, and the target virtual machine identifier (CPUID) of the target virtual machine can be written into the VMCS.

在上述示例中,在目标虚拟机退出前将其当前状态信息(即寄存器、段寄存器、标志寄存器、指令指针、栈指针等信息)保存到VMCS中,如此,在虚拟机再次被恢复执行时,可以从利用VMCS和影子寄存器恢复其状态,使得虚拟机能够无缝地继续之前的执行流程,提高了虚拟化环境的稳定性。In the above example, before the target virtual machine exits, its current state information (i.e., registers, segment registers, flag registers, instruction pointer, stack pointer, etc.) is saved to VMCS. In this way, when the virtual machine is resumed again, its state can be restored by using VMCS and shadow registers, so that the virtual machine can seamlessly continue the previous execution process, thereby improving the stability of the virtualization environment.

在本发明的一种实施例中,所述将所述目标虚拟机的当前状态信息保存到虚拟机控制结构中,以及将所述目标虚拟机标识写入所述虚拟机控制结构,包括:In an embodiment of the present invention, the step of saving the current state information of the target virtual machine into a virtual machine control structure and writing the target virtual machine identifier into the virtual machine control structure comprises:

将所述目标虚拟机的当前状态信息保存到虚拟机控制结构的客户状态区域中,以及将所述目标虚拟机标识写入所述虚拟机控制结构的中断信息字段寄存器。The current state information of the target virtual machine is saved in the client state area of the virtual machine control structure, and the target virtual machine identifier is written into the interrupt information field register of the virtual machine control structure.

具体地,在本发明实施例中,将目标虚拟机的当前状态信息保存到VMCS的GUESTSTATE AREA区域中,以及将目标虚拟机的CPUID写入VMCS VM-Entry的interruption-information field(中断信息字段寄存器)。Specifically, in the embodiment of the present invention, the current state information of the target virtual machine is saved in the GUESTSTATE AREA area of the VMCS, and the CPUID of the target virtual machine is written into the interruption-information field (interruption information field register) of the VMCS VM-Entry.

在本发明的一种实施例中,所述方法还可以包括:In one embodiment of the present invention, the method may further include:

配置所述虚拟机的所述虚拟机控制结构。The virtual machine control structure of the virtual machine is configured.

在具体实现中,虚拟机的VMCS原先并不会执行本发明实施例的诸如存储CPUID、将虚拟机得到当前状态信息写入到影子寄存器中等处理,因此,本发明实施例可以在虚拟机进行中断处理之前,可以配置虚拟机的VMCS,从而使其可以实现本发明实施例的多虚拟机并行执行中断处理的逻辑。可以理解,由于只需要配置虚拟机的VMCS,因此本发明实施例无需耗费过多的研发成本。In a specific implementation, the VMCS of the virtual machine does not originally perform the processing of the embodiment of the present invention, such as storing the CPUID and writing the current state information of the virtual machine into the shadow register. Therefore, the embodiment of the present invention can configure the VMCS of the virtual machine before the virtual machine performs interrupt processing, so that it can implement the logic of multiple virtual machines executing interrupt processing in parallel in the embodiment of the present invention. It can be understood that since only the VMCS of the virtual machine needs to be configured, the embodiment of the present invention does not need to consume too much research and development costs.

在本发明的一种实施例中,所述配置所述虚拟机的所述虚拟机控制结构,包括:In one embodiment of the present invention, the virtual machine control structure of configuring the virtual machine includes:

配置所述虚拟机的所述虚拟机控制结构的控制域。A control domain of the virtual machine control structure of the virtual machine is configured.

在本发明实施例中,配置虚拟机的所述虚拟机控制结构可以包括配置中断控制域(控制域),示例性地,中断控制域的中断向量配置内容可以包括:In an embodiment of the present invention, configuring the virtual machine control structure of the virtual machine may include configuring an interrupt control domain (control domain). Exemplarily, the interrupt vector configuration content of the interrupt control domain may include:

1)首先配置对VMCS的控制域,通过VMREAD、VMWRITE指令来对vmcs进行操作:具体地,参照图9,通过VMREAD、VMWRITE指令来对VMCS的相关域进行操作,图中配置的是vmcs的控制域,所以[11:10]处设置为0,服务器对应的处理器为64bit,所以[14:13]配置为1。1) First, configure the control domain of VMCS, and operate the vmcs through the VMREAD and VMWRITE instructions: Specifically, referring to Figure 9, the relevant domains of VMCS are operated through the VMREAD and VMWRITE instructions. The control domain of vmcs is configured in the figure, so [11:10] is set to 0. The processor corresponding to the server is 64bit, so [14:13] is configured to 1.

2)配置将要注入到虚拟机当中的中断向量号:具体地,参照图10,当执行中断注入的时候,将需要虚拟机执行的中断向量号写到VMCS VM-Entry的interruption-information field寄存器的0-7bit,[10:8]bit指定为1,代表为外部中断。2) Configure the interrupt vector number to be injected into the virtual machine: Specifically, referring to Figure 10, when interrupt injection is performed, the interrupt vector number that the virtual machine needs to execute is written to the 0-7 bits of the interruption-information field register of the VMCS VM-Entry, and the [10:8] bit is specified as 1, representing an external interrupt.

由于影子寄存器的IDT(影子页表/中断描述符表)的存在,需要将VMCS的GUESTSTATE AREA区域的内容加载到虚拟机(vCPU)的影子页表当中,等于说每个虚拟机对应一个IDT,因此需要明确中断对应的是哪一个vCPU,因此这里需要对原有的寄存器进行改造,改造后的形式如下表所示:Due to the existence of the shadow register IDT (shadow page table/interrupt descriptor table), the content of the VMCS GUESTSTATE AREA area needs to be loaded into the shadow page table of the virtual machine (vCPU), which means that each virtual machine corresponds to an IDT. Therefore, it is necessary to clarify which vCPU the interrupt corresponds to. Therefore, the original registers need to be modified. The modified form is shown in the following table:

其中,位置[30:26]对应了逻辑CPU的CPUID,因此,此VMCS对应的GUEST STATEAREA中的IDTR寄存器加载到对应CPUID的物理CPU的影子寄存器的IDTR影子页表当中。Among them, the position [30:26] corresponds to the CPUID of the logical CPU. Therefore, the IDTR register in the GUEST STATEAREA corresponding to this VMCS is loaded into the IDTR shadow page table of the shadow register of the physical CPU corresponding to the CPUID.

在本发明的一种实施例中,所述配置所述虚拟机的所述虚拟机控制结构,包括:In one embodiment of the present invention, the virtual machine control structure of configuring the virtual machine includes:

配置所述虚拟机的所述虚拟机控制结构的所述客户状态区域。The guest state area of the virtual machine control structure of the virtual machine is configured.

在本发明实施例中,配置虚拟机的所述虚拟机控制结构可以包括配置客户状态区域,示例性地,VMCS中GUEST STATE AREA(客户状态区域)区域中内容的配置可以包括:In an embodiment of the present invention, configuring the virtual machine control structure of the virtual machine may include configuring a guest state area. Exemplarily, the configuration of the content in the guest state area in the VMCS may include:

参照图11,是本发明实施例中提供的一种GUEST STATE AREA区域的示意图,通过vmwrite指令配置VMCS当中的GUEST STATE AREA区域,比如寄存器cs(Code Segment,代码段寄存器),ss(Stack Segment,栈段寄存器),ds(Data Segment,数据段寄存器),es(ExtraSegment,附加段寄存器)等寄存器,这些寄存器不是全局唯一,其中寄存器还可以包括IDTR寄存器,以上寄存器都是宿主机上对应的一块内存地址,用宿主机内存地址填充IDTR寄存器地址,当执行vmalunch指令的时候,会将保存在VMCS内存地址中GUEST STATE AREA中的寄存器内容填充到物理CPU对应的寄存器当中。Referring to Figure 11, it is a schematic diagram of a GUEST STATE AREA area provided in an embodiment of the present invention. The GUEST STATE AREA area in the VMCS is configured by the vmwrite instruction, such as registers cs (Code Segment), ss (Stack Segment), ds (Data Segment), es (ExtraSegment) and other registers. These registers are not globally unique. The registers may also include an IDTR register. The above registers are all corresponding to a memory address on the host machine. The IDTR register address is filled with the host machine memory address. When the vmalunch instruction is executed, the register content in the GUEST STATE AREA stored in the VMCS memory address is filled into the register corresponding to the physical CPU.

在本发明的一种实施例中,在控制所述目标虚拟机退出前,所述方法还包括:In an embodiment of the present invention, before controlling the target virtual machine to exit, the method further includes:

所述目标虚拟机识别中断源,并根据所述中断源确定中断类型号;The target virtual machine identifies an interrupt source and determines an interrupt type number according to the interrupt source;

根据所述中断类型号从所述影子寄存器的中断描述符表中查询对应的中断服务程序的入口地址,以根据所述入口地址跳转到所述中断服务程序进行中断处理。According to the interrupt type number, the entry address of the corresponding interrupt service program is queried from the interrupt descriptor table of the shadow register, so as to jump to the interrupt service program for interrupt processing according to the entry address.

在本发明实施例中,当目标虚拟机接收到VMM的中断信号时,目标虚拟机首先需要识别中断源,其中,中断源可以外部设备、定时器、软件异常等等,然后基于中断源可以确定中断类型号,中断类型号(中断向量号)是一个唯一标识,利用中断类型号可以在对应的影子寄存器的中断描述符表(IDT)中索引相应的中断服务程序(ISR)的入口地址,随后,跳转到相应的ISR,执行中断处理逻辑。在上述实施例中,目标虚拟机通过识别中断源和确定中断类型号,使得虚拟机能够精确地处理不同中断源,确保中断都能得到对应的响应处理。In an embodiment of the present invention, when the target virtual machine receives an interrupt signal from the VMM, the target virtual machine first needs to identify the interrupt source, where the interrupt source can be an external device, a timer, a software exception, etc., and then the interrupt type number can be determined based on the interrupt source. The interrupt type number (interrupt vector number) is a unique identifier. The interrupt type number can be used to index the entry address of the corresponding interrupt service routine (ISR) in the interrupt descriptor table (IDT) of the corresponding shadow register, and then jump to the corresponding ISR to execute the interrupt processing logic. In the above embodiment, the target virtual machine identifies the interrupt source and determines the interrupt type number, so that the virtual machine can accurately handle different interrupt sources and ensure that the interrupts can receive corresponding response processing.

在本发明的一种实施例中,所述方法还可以包括:In one embodiment of the present invention, the method may further include:

改造所述虚拟机的虚拟机启动指令;在执行改造的虚拟机启动指令时,从启动的所述虚拟机的虚拟机控制结构中读取虚拟机标识。The virtual machine startup instruction of the virtual machine is modified; when the modified virtual machine startup instruction is executed, the virtual machine identifier is read from the virtual machine control structure of the started virtual machine.

在具体实现中,虚拟机启动指令(vmlaunch指令)只能启动虚拟机的执行,其中,vmlaunch指令可以由虚拟机监控器(VMM)发送至虚拟机以控制虚拟机的执行流程,本发明实施例通过改造vmlaunch指令,使得在本发明实施例中在基于vmlaunch指令启动虚拟机时,可以将虚拟机的VMCS中存储的CPUID在写入影子寄存器中写入VMCS中存储的当前状态信息,以实现虚拟机的中断恢复。In a specific implementation, a virtual machine startup instruction (vmlaunch instruction) can only start the execution of a virtual machine, wherein the vmlaunch instruction can be sent by a virtual machine monitor (VMM) to a virtual machine to control the execution process of the virtual machine. The embodiment of the present invention transforms the vmlaunch instruction so that in the embodiment of the present invention, when a virtual machine is started based on the vmlaunch instruction, the CPUID stored in the VMCS of the virtual machine can be written into the write shadow register to the current state information stored in the VMCS to achieve interrupt recovery of the virtual machine.

具体地,改造后的vmlauch指令,将执行如下操作:Specifically, the modified vmlauch instruction will perform the following operations:

1、CPU从kernel模式切换到guest模式;2、通过vmread指令读取VMCS VM-Entry(虚拟机恢复执行)的interruption-information field(中断信息字段寄存器)当中的[30:26]CPUID;3、将VMCS当中的GUEST STATE AREA中的内容加载到物理cpu相应的寄存器当中,比如cs加载到物理cpu的cs段选择寄存器,ss加载到物理CPU的栈选择寄存器当中,其中有所改变的是根据上文中的CPUID,将VMCS的GUEST STATE AREA区域中的IDTR中的内容加载到虚拟机所映射的物理CPU核的影子寄存器中,从而可以基于影子寄存器实现多虚拟机的中断处理。1. The CPU switches from kernel mode to guest mode; 2. The interruption-information field [30:26] CPUID of VMCS VM-Entry (virtual machine resumes execution) is read through the vmread instruction; 3. The contents of the GUEST STATE AREA in VMCS are loaded into the corresponding registers of the physical CPU, such as cs is loaded into the cs segment selection register of the physical CPU, and ss is loaded into the stack selection register of the physical CPU. The change is that according to the CPUID mentioned above, the contents of the IDTR in the GUEST STATE AREA area of VMCS are loaded into the shadow register of the physical CPU core mapped by the virtual machine, so that interrupt processing of multiple virtual machines can be implemented based on the shadow register.

在本发明的一种实施例中,所述在控制所述目标虚拟机启动时,从所述目标虚拟机的所述虚拟机控制结构中读取所述目标虚拟机的目标虚拟机标识,包括:In an embodiment of the present invention, when controlling the target virtual machine to start, reading the target virtual machine identifier of the target virtual machine from the virtual machine control structure of the target virtual machine includes:

在执行改造后的所述虚拟机启动指令控制所述目标虚拟机启动时,触发所述目标虚拟机从虚拟机监控器模式切换至虚拟机模式;When executing the modified virtual machine startup instruction to control the startup of the target virtual machine, triggering the target virtual machine to switch from the virtual machine monitor mode to the virtual machine mode;

从所述目标虚拟机的所述虚拟机控制结构中读取所述目标虚拟机的目标虚拟机标识。A target virtual machine identifier of the target virtual machine is read from the virtual machine control structure of the target virtual machine.

在本发明实施例中,在执行改造的vmlauch指令控制虚拟机启动时,将使得原来的vmlaunch指令如下操作:CPU(虚拟机)从kernel模式切换到guest模式,通过vmread指令读取VMCS中的CPUID,随后,本发明实施例将根据从VMCS中读取的CPUID,将VMCS的GUESTSTATE AREA区域中的IDTR中的内容加载到虚拟机所映射的物理CPU核CPUID对应的影子寄存器中。In an embodiment of the present invention, when the modified vmlauch instruction is executed to control the startup of the virtual machine, the original vmlaunch instruction will be operated as follows: the CPU (virtual machine) switches from kernel mode to guest mode, and the CPUID in the VMCS is read through the vmread instruction. Subsequently, the embodiment of the present invention will load the content in the IDTR in the GUESTSTATE AREA area of the VMCS into the shadow register corresponding to the physical CPU core CPUID mapped by the virtual machine according to the CPUID read from the VMCS.

在本发明的一种实施例中,所述从所述目标虚拟机的所述虚拟机控制结构中读取所述目标虚拟机的目标虚拟机标识,包括:In an embodiment of the present invention, the step of reading the target virtual machine identifier of the target virtual machine from the virtual machine control structure of the target virtual machine includes:

执行虚拟机读取指令从所述目标虚拟机的所述虚拟机控制结构的中断信息字段寄存器中读取所述目标虚拟机的目标虚拟机标识。The virtual machine read instruction is executed to read the target virtual machine identifier of the target virtual machine from the interrupt information field register of the virtual machine control structure of the target virtual machine.

具体地,CPU(虚拟机)从kernel模式切换到guest模式,通过vmread指令读取VMCSVM-Entry(虚拟机恢复执行)的interruption-information field(中断信息字段寄存器)当中的[30:26]CPUID。Specifically, the CPU (virtual machine) switches from kernel mode to guest mode, and reads [30:26]CPUID in the interruption-information field (interrupt information field register) of VMCSVM-Entry (virtual machine resume execution) through the vmread instruction.

在本发明的一种实施例中,在所述将所述目标虚拟机的所述虚拟机控制结构的所述当前状态信息写入与所述目标虚拟机标识对应的目标影子寄存器中之后,所述方法还包括:In an embodiment of the present invention, after writing the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identifier, the method further includes:

将所述目标虚拟机的所述虚拟机控制结构的其他内容写入对应的其他寄存器中;所述其他内容至少包括段寄存器的内容。Writing other contents of the virtual machine control structure of the target virtual machine into corresponding other registers; the other contents at least include the contents of the segment register.

在本发明实施例中,可以将VMCS当中的GUEST STATE AREA中除了当前状态信息和CPUID的其他内容加载到物理CPU相应的寄存器中,比如cs加载到物理CPU的cs段选择寄存器,ss加载到物理CPU的栈选择寄存器中。In an embodiment of the present invention, other contents in the GUEST STATE AREA in the VMCS except the current state information and CPUID can be loaded into the corresponding registers of the physical CPU, such as cs is loaded into the cs segment selection register of the physical CPU, and ss is loaded into the stack selection register of the physical CPU.

需要说明的是,对于方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本发明实施例并不受所描述的动作顺序的限制,因为依据本发明实施例,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作并不一定是本发明实施例所必须的It should be noted that, for the sake of simplicity, the method embodiments are described as a series of action combinations, but those skilled in the art should be aware that the embodiments of the present invention are not limited by the order of the actions described, because according to the embodiments of the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present invention.

本发明实施例还公开了一种中断虚拟化处理装置,应用于物理设备,所述物理设备包括虚拟机监控器,所述物理设备的每个虚拟机配置有影子寄存器,所述虚拟机分别具有对应的虚拟机标识,所述装置用于执行上述的方法实施例的步骤。An embodiment of the present invention also discloses an interrupt virtualization processing device, which is applied to a physical device, wherein the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and the virtual machines respectively have corresponding virtual machine identifiers, and the device is used to execute the steps of the above-mentioned method embodiment.

本发明实施例应用于物理设备,物理设备包括虚拟机监控器,物理设备的每个虚拟机配置有影子寄存器,虚拟机分别具有对应的虚拟机标识,在通过虚拟机监控器触发目标虚拟机进行中断处理时,控制目标虚拟机退出前将目标虚拟机的当前状态信息写入到目标虚拟机的虚拟机控制结构中,以及将目标虚拟机的目标虚拟机标识写入虚拟机控制结构;在控制目标虚拟机启动时,从目标虚拟机的虚拟机控制结构中读取目标虚拟机的目标虚拟机标识;将目标虚拟机的虚拟机控制结构的当前状态信息写入与目标虚拟机标识对应的目标影子寄存器中;控制目标虚拟机从目标影子寄存器中读取目标虚拟机的当前状态信息,以使目标虚拟机根据当前状态信息恢复回中断处理前的状态。本发明实施例通过为物理设备的每个虚拟机的处理器分别配置物理的影子寄存器,在多个虚拟机进入中断处理时,可以分别通过其对应的影子寄存器来并行恢复至中断处理前的状态,提高了物理设备的并发处理能力,减少了中断处理对物理设备的虚拟机性能的影响。The embodiment of the present invention is applied to a physical device, the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and the virtual machines respectively have corresponding virtual machine identifiers. When the target virtual machine is triggered to perform interrupt processing through the virtual machine monitor, the current state information of the target virtual machine is written into the virtual machine control structure of the target virtual machine before the target virtual machine is controlled to exit, and the target virtual machine identifier of the target virtual machine is written into the virtual machine control structure; when the target virtual machine is controlled to start, the target virtual machine identifier of the target virtual machine is read from the virtual machine control structure of the target virtual machine; the current state information of the virtual machine control structure of the target virtual machine is written into the target shadow register corresponding to the target virtual machine identifier; the target virtual machine is controlled to read the current state information of the target virtual machine from the target shadow register, so that the target virtual machine is restored to the state before the interrupt processing according to the current state information. The embodiment of the present invention configures physical shadow registers for the processors of each virtual machine of the physical device respectively, and when multiple virtual machines enter interrupt processing, they can be restored to the state before the interrupt processing in parallel through their corresponding shadow registers, thereby improving the concurrent processing capability of the physical device and reducing the impact of interrupt processing on the performance of the virtual machines of the physical device.

对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

本发明实施例还提供了一种电子设备,如图12所示,包括处理器801、设备接口802、存储器The embodiment of the present invention also provides an electronic device, as shown in FIG12, including a processor 801, a device interface 802, and a memory.

803和总线804;803 and bus 804;

存储器803,用于存放计算机程序;Memory 803, used for storing computer programs;

处理器801,用于执行存储器803上所存放的程序时,实现如下步骤:The processor 801 is used to execute the program stored in the memory 803, and implements the following steps:

在通过所述虚拟机监控器触发目标虚拟机进行中断处理时,控制所述目标虚拟机退出前将所述目标虚拟机的当前状态信息写入到所述目标虚拟机的虚拟机控制结构中,以及将进入中断处理的目标虚拟机的目标虚拟机标识和当前状态信息写入所述虚拟机控制结构;When the target virtual machine is triggered to perform interrupt processing through the virtual machine monitor, the current state information of the target virtual machine is written into the virtual machine control structure of the target virtual machine before the target virtual machine exits, and the target virtual machine identifier and current state information of the target virtual machine entering the interrupt processing are written into the virtual machine control structure;

在控制所述目标虚拟机启动时,从所述目标虚拟机的所述虚拟机控制结构中读取所述目标虚拟机的目标虚拟机标识;When controlling the target virtual machine to start, reading the target virtual machine identifier of the target virtual machine from the virtual machine control structure of the target virtual machine;

将所述目标虚拟机的所述虚拟机控制结构的所述当前状态信息写入与所述目标虚拟机标识对应的目标影子寄存器中;Writing the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identifier;

控制所述目标虚拟机从所述目标影子寄存器中读取所述目标虚拟机的所述当前状态信息,以使所述目标虚拟机根据所述当前状态信息恢复回中断处理前的状态。The target virtual machine is controlled to read the current state information of the target virtual machine from the target shadow register, so that the target virtual machine is restored to a state before interrupt processing according to the current state information.

上述终端提到的总线可以是外设部件互连标准(Peripheral ComponentInterconnect,简称PCI)总线或扩展工业标准结构(Extended Industry StandardArchitecture,简称EISA)总线等。该总线可以分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

存储器可以包括随机存取存储器(Random Access Memory,简称RAM),也可以包括非易失性存储器(non-volatile memory),例如至少一个磁盘存储器。可选的,存储器还可以是至少一个位于远离前述处理器的存储装置。The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

上述的处理器可以是通用处理器,包括中央处理器(Central Processing Unit,简称CPU)、网络处理器(Network Processor,简称NP)等;还可以是数字信号处理器(Digital Signal Processing,简称DSP)、专用集成电路(Application SpecificIntegrated Circuit,简称ASIC)、现场可编程门阵列(Field-Programmable Gate Array,简称FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件。The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

本发明还提供了一种存储介质,当存储介质中的指令由电子设备的处理器执行时,使得电子设备能够执行前述实施例的中断虚拟化处理方法。The present invention also provides a storage medium. When the instructions in the storage medium are executed by the processor of the electronic device, the electronic device can execute the interrupt virtualization processing method of the above embodiment.

对于装置实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

在此提供的算法和显示不与任何特定计算机、虚拟装置或者其他设备固有相关。根据上面的描述,构造这类装置所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The algorithm and display provided herein are not inherently related to any particular computer, virtual device or other equipment. According to the above description, it is obvious that the structure required for constructing this type of device is. In addition, the present invention is not directed to any specific programming language. It should be understood that various programming languages can be utilized to realize the content of the present invention described herein, and the description of the above specific language is to disclose the best mode of the present invention.

在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

类似地,应当理解,为了精简本发明并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图,或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than those expressly recited in each claim. Rather, as reflected in the claims below, inventive aspects lie in less than all of the features of the individual embodiments disclosed above. Therefore, the claims that follow the detailed description are hereby expressly incorporated into the detailed description, with each claim itself serving as a separate embodiment of the present invention.

本领域那些技术人员可以理解,可以对实施例中的设备中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个设备中。可以把实施例中的模块或单元或组件组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者单元中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的的替代特征来代替。Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and/or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明的排序设备中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in the sorting device according to the present invention. The present invention may also be implemented as a device or apparatus program for executing part or all of the methods described herein. Such a program for implementing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的装置、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices, apparatuses and units can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

以上所述仅为本发明的较佳实施例而已,并不用以限制本发明,凡在本发明的精神和原则之内所做的任何修改、等同替换和改进等,均应包含在本发明的保护范围之内。The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.

以上所述,仅为本发明的具体实施方式,但本发明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本发明揭露的技术范围内,可轻易想到变化或替换,都应涵盖在本发明的保护范围之内。因此,本发明的保护范围应以权利要求的保护范围为准。The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

需要说明的是,本申请实施例中获取各种数据相关过程,都是在遵照所在地国家相应的数据保护法规政策的前提下,并获得由相应装置所有者给予授权的情况下进行的。It should be noted that the various data-related processes in the embodiments of the present application are all carried out in compliance with the corresponding data protection laws and policies of the country where the device is located, and with the authorization given by the owner of the corresponding device.

Claims (15)

1. An interrupt virtualization processing method, which is applied to a physical device, wherein the physical device comprises a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and the virtual machines respectively have corresponding virtual machine identifiers, and the method comprises:
Writing a target virtual machine identifier and current state information of a target virtual machine entering interrupt processing into the virtual machine control structure;
when the target virtual machine is controlled to start, writing the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identifier;
And controlling the target virtual machine to read the current state information of the target virtual machine from the target shadow register so as to enable the target virtual machine to recover the state before interrupt processing according to the current state information.
2. The method of claim 1, wherein writing the target virtual machine identification and current state information of the target virtual machine entering interrupt processing to the virtual machine control structure comprises:
When the virtual machine monitor triggers a target virtual machine to perform interrupt processing, the current state information of the target virtual machine is controlled to be written into a virtual machine control structure of the target virtual machine before the target virtual machine exits, and a target virtual machine identifier of the target virtual machine is controlled to be written into the virtual machine control structure.
3. The method according to claim 2, wherein controlling the writing of current state information of a target virtual machine into a virtual machine control structure of the target virtual machine before the target virtual machine exits and writing a target virtual machine identification of the target virtual machine into the virtual machine control structure when a target virtual machine is triggered by the virtual machine monitor for interrupt processing includes:
In the process of executing the virtual machine, if the target virtual machine receives an interrupt signal sent by the virtual machine monitor, triggering the target virtual machine to switch from a virtual machine mode to a virtual machine monitor mode;
Before the target virtual machine is controlled to exit, the current state information of the target virtual machine is stored in a virtual machine control structure, and a target virtual machine identification of the target virtual machine is written in the virtual machine control structure.
4. The method of claim 3, wherein the saving of the current state information of the target virtual machine into a virtual machine control structure and the writing of the target virtual machine identification of the target virtual machine into the virtual machine control structure comprises:
storing the current state information of the target virtual machine into a client state area of a virtual machine control structure, and writing a target virtual machine identification of the target virtual machine into an interrupt information field register of the virtual machine control structure.
5. The method according to claim 4, wherein the method further comprises:
and configuring the virtual machine control structure of the virtual machine.
6. The method of claim 5, wherein said configuring the virtual machine control structure of the virtual machine comprises:
configuring a control domain of the virtual machine control structure of the virtual machine;
The guest state area of the virtual machine control structure of the virtual machine is configured.
7. The method of claim 1, wherein prior to controlling the target virtual machine to exit, the method further comprises:
the target virtual machine identifies an interrupt source and determines an interrupt type number according to the interrupt source;
And inquiring an entry address of a corresponding interrupt service routine from an interrupt descriptor table of the shadow register according to the interrupt type number so as to jump to the interrupt service routine according to the entry address to perform interrupt processing.
8. The method according to claim 1, wherein the method further comprises:
modifying a virtual machine starting instruction of the virtual machine; and when the modified virtual machine starting instruction is executed, reading a virtual machine identifier from a virtual machine control structure of the started virtual machine.
9. The method of claim 8, wherein the reading the target virtual machine identification of the target virtual machine from the virtual machine control structure of the target virtual machine when controlling the target virtual machine to boot comprises:
triggering the target virtual machine to switch from a virtual machine monitor mode to a virtual machine mode when the virtual machine starting instruction after the modification is executed controls the target virtual machine to start;
and reading a target virtual machine identification of the target virtual machine from the virtual machine control structure of the target virtual machine.
10. The method of claim 9, wherein the reading the target virtual machine identification of the target virtual machine from the virtual machine control structure of the target virtual machine comprises:
And executing a virtual machine reading instruction to read a target virtual machine identification of the target virtual machine from an interrupt information field register of the virtual machine control structure of the target virtual machine.
11. The method of claim 1, wherein after the writing of the current state information of the virtual machine control structure of the target virtual machine into a target shadow register corresponding to the target virtual machine identification, the method further comprises:
Writing other contents of the virtual machine control structure of the target virtual machine into corresponding other registers; the other content includes at least the content of the segment register.
12. The method of claim 1, wherein the target virtual machine is one or more and the shadow register is one or more.
13. Interrupt virtualization processing apparatus, applied to a physical device, where the physical device includes a virtual machine monitor, each virtual machine of the physical device is configured with a shadow register, and each virtual machine has a corresponding virtual machine identifier, and the apparatus is configured to perform an interrupt virtualization processing method according to any one of claims 1 to 12.
14. An electronic device, comprising:
A processor;
A memory for storing processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the interrupt virtualization processing method of any one of claims 1 to 12.
15. A computer readable storage medium, characterized in that instructions in said storage medium, when executed by a processor of a mobile terminal, enable the mobile terminal to perform the interrupt virtualization processing method according to any one of claims 1 to 12.
CN202410915927.1A 2024-07-09 2024-07-09 Interrupt virtualization processing method, device, equipment, and storage medium Pending CN118819732A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410915927.1A CN118819732A (en) 2024-07-09 2024-07-09 Interrupt virtualization processing method, device, equipment, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410915927.1A CN118819732A (en) 2024-07-09 2024-07-09 Interrupt virtualization processing method, device, equipment, and storage medium

Publications (1)

Publication Number Publication Date
CN118819732A true CN118819732A (en) 2024-10-22

Family

ID=93069883

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410915927.1A Pending CN118819732A (en) 2024-07-09 2024-07-09 Interrupt virtualization processing method, device, equipment, and storage medium

Country Status (1)

Country Link
CN (1) CN118819732A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121070572A (en) * 2025-11-04 2025-12-05 北京开源芯片研究院 Interrupt source switching method, device, electronic equipment and computer readable storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN121070572A (en) * 2025-11-04 2025-12-05 北京开源芯片研究院 Interrupt source switching method, device, electronic equipment and computer readable storage medium

Similar Documents

Publication Publication Date Title
JP7538950B2 (en) COMPUTER DEVICE, EXCEPTION PROCESSING METHOD, AND INTERRUPT PROCESSING METHOD - Patent application
US7209994B1 (en) Processor that maintains virtual interrupt state and injects virtual interrupts into virtual machine guests
US7356735B2 (en) Providing support for single stepping a virtual machine in a virtual machine environment
US7707341B1 (en) Virtualizing an interrupt controller
US9442868B2 (en) Delivering interrupts directly to a virtual processor
RU2265880C2 (en) New processor mode for limiting functioning of guest software, executed at virtual machine, supported by virtual machine monitor
JP5969550B2 (en) Virtualization of performance counters
JP6006248B2 (en) Instruction emulation processor, method and system
JP7592858B2 (en) Chip system, virtual interrupt processing method and corresponding device - Patents.com
US8572604B2 (en) Method and apparatus to support virtualization with code patches
US12367062B1 (en) Virtualization extension modules
US20050081199A1 (en) Systems and methods for using synthetic instructions in a virtual machine
US10049064B2 (en) Transmitting inter-processor interrupt messages by privileged virtual machine functions
KR102877874B1 (en) Devices and methods for handling exceptions
JP4437155B2 (en) Support for nested faults in virtual machine environments
Lazarev et al. Sabre:{Hardware-Accelerated} snapshot compression for serverless {MicroVMs}
CN118819732A (en) Interrupt virtualization processing method, device, equipment, and storage medium
US20230161650A1 (en) Method and apparatus for inter-process communication, and computer storage medium
WO2023169289A1 (en) Method and apparatus for switching execution status of process
US11726811B2 (en) Parallel context switching for interrupt handling
CN116893894A (en) Synchronous microthreading
CN109960567B (en) Semiconductor Equipment
US20240086219A1 (en) Transmitting interrupts from a virtual machine (vm) to a destination processing unit without triggering a vm exit
Zabaljáuregui Hardware assisted virtualization intel virtualization technology
US20230418509A1 (en) Switching memory consistency models in accordance with execution privilege level

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination