Virtual machine interrupt direct delivery method and device based on SW architecture privileged firmware and storage medium

By introducing privileges on the Shenwei architecture, the direct delivery method of virtual machine interruption is realized, and the problem of low processing efficiency of virtual machine interruption caused by VM-EXIT frequently caused by VM-EXIT has achieved more efficient interrupt processing and performance optimization. Essence

CN119336449APending Publication Date: 2025-01-21WUXI ADVANCED TECH RES INST
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411506782.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-28
Publication Date
2025-01-21

AI Technical Summary

Technical Problem

In the prior art, VM-Exit is required to trigger each injection of interrupt, resulting in low efficiency in virtual machine interrupt processing and high virtualization overhead, especially in Shenwei architecture, there is a lack of hardware-assisted interrupt virtualization support.

Method used

By introducing privileges on the Shenwei architecture to realize the direct delivery method of virtual machine interrupts, use the VCPUCB structure and interrupt position status position diagram IRQS_PENDING and other data structures, and directly process interruption under the virtual machine mode to reduce the occurrence of VM-EXIT.

Benefits of technology

Effectively reduce the VM-EXIT in the interrupt processing process of the virtual machine, reduce the interrupt processing delay, improve the efficiency of interrupt treatment, and optimize the overall performance of the virtual machine.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336449A_ABST
    Figure CN119336449A_ABST
Patent Text Reader

Abstract

The invention provides a virtual machine interrupt direct delivery method and device based on SW architecture privileged firmware and a storage medium, and belongs to the field of virtual machine interrupt control. The method comprises the steps that after an interrupt source generates interrupt, a KVM obtains an interrupted target virtual CPU and interrupt information, the interrupt information is registered to IRQSPENING of the target virtual CPU, and the KVM checks the operation mode of a physical CPU where the target virtual CPU is located; if the physical CPU is in the virtual machine mode, the KVM sends a notification interrupt to the physical CPU and executes a virtual machine interrupt direct delivery process, that is, after the virtual machine receives the notification interrupt, VM-Exit is not triggered, and interrupt injection and processing can be directly completed in the virtual machine mode. According to the method, under the condition that no hardware support exists, virtual machine interrupt control of similar hardware is achieved through the virtual machine interrupt direct delivery process, VM-Exit in the virtual machine interrupt processing process is reduced, and the virtual machine interrupt processing process is optimized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method, a device and a storage medium for directly delivering virtual machine interrupts based on Shenwei architecture privileged firmware, and belongs to the field of virtual machine interrupt control. Background Art

[0002] In the current software-based virtual machine interrupt control scheme, the timing of injecting interrupts into the virtual machine is at VM-Entry. Only at VM-Entry can the CPU in virtual machine mode evaluate the interrupt. Therefore, each interrupt injection into the virtual machine requires a VM-Exit. The frequent and long-path context switching between the physical machine mode and the virtual machine mode caused by this brings great virtualization overhead and interrupt processing delay. Therefore, in order to reduce the context switching overhead caused by virtual machine interrupt injection, processor manufacturers such as Intel have designed hardware-assisted virtual machine interrupt control schemes such as APICv and Posted-Interrupt, which realize interrupt evaluation in virtual machine mode and direct delivery of virtual machine interrupts to the CPU in virtual machine mode, reducing VM-Exit caused by virtual machine interrupt injection and improving virtual machine interrupt processing efficiency.

[0003] As a processor product with completely independent intellectual property rights in my country, the current Shenwei processor lacks corresponding hardware-assisted interrupt virtualization support and still uses the above-mentioned virtual machine interrupt control solution that is completely based on software. At the same time, unlike other architectures that use APICv, GICv and other hierarchical virtual interrupt controllers, the Shenwei virtual machine interrupt control system adopts a flat design. Therefore, a solution to improve the efficiency of virtual machine interrupt processing for the Shenwei architecture is urgently needed to make up for the defects of Shenwei virtualization in interrupt control to a certain extent.

[0004] The Shenwei architecture privileged firmware is a collection of privileged programs that runs in hardware mode and can be used to replace some hardware functions, or implement some atomic operations that cannot be interrupted, or implement virtualization management, etc. Summary of the invention

[0005] The purpose of the present invention is to overcome the deficiencies in the prior art and provide a method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware, which solves the problem that each interrupt injection needs to trigger VM-Exit, affecting the efficiency of virtual machine interrupt processing and causing large virtualization overhead.

[0006] To achieve the above object, the present invention is implemented by adopting the following technical solutions:

[0007] In the first aspect, a physical machine based on the Shenwei architecture includes: a VCPUCB structure; the VCPUCB structure is used to save the status information of each virtual CPU and communicate between the virtual machine monitor VMM and the privileged firmware; the VCPUCB structure includes: an interrupt setting state bitmap IRQS_PENDING and VCPU_IRQ; the interrupt setting state bitmap IRQS_PENDING is used to record the setting state of all types of interrupts in the virtual CPU; the VCPU_IRQ is used to record all interrupt types in the virtual CPU; the present invention provides a virtual machine interrupt direct delivery method based on the Shenwei architecture privileged firmware, including:

[0008] In response to an interrupt source of the virtual machine generating an interrupt that needs to be delivered to the virtual machine, the KVM obtains a target virtual CPU and interrupt information of the interrupt, and registers the interrupt information into an interrupt setting state bitmap IRQS_PENDING of the target virtual CPU;

[0009] KVM checks the operating mode of the physical CPU where the target virtual CPU is located;

[0010] In response to the operating mode of the physical CPU being the virtual machine mode, the KVM sends a notification interrupt to the physical CPU to notify the virtual machine of an interrupt to be processed, and executes a virtual machine interrupt direct delivery process;

[0011] In response to the operating mode of the physical CPU being the physical machine mode, the target virtual CPU is awakened or scheduled to execute a traditional virtual machine interrupt processing flow.

[0012] Furthermore, the virtual machine interrupt direct delivery process includes:

[0013] In response to the physical CPU receiving the notification interrupt in the hardware mode where the privileged firmware is located, checking the operation mode of the physical CPU again;

[0014] In response to the operating mode of the physical CPU being the virtual machine mode, clearing the interrupt request for the notification interrupt in the physical machine interrupt status register, extracting the pending interrupt information from the IRQS_PENDING of the target virtual CPU, and registering the interrupt information into the VCPU_IRQ in the VCPUCB structure for recording the interrupt type;

[0015] In response to the operating mode of the physical CPU being the physical machine mode, the interrupt request regarding the notification interrupt in the physical machine interrupt status register is cleared and the program returns.

[0016] Furthermore, the virtual machine interrupt direct delivery process further includes: after registering the interrupt information into the VCPU_IRQ in the VCPUCB structure for recording the interrupt type, checking the interrupt enable state of the virtual machine;

[0017] In response to the virtual machine interrupt enable, the interrupt information in VCPU_IRQ is saved to the stack, and the set state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and then jumps to the virtual machine kernel interrupt processing entry;

[0018] In response to the virtual machine interrupt disabling, the virtual machine interrupt enabling is waited for, and after the virtual machine interrupt enabling, the privileged firmware virtual machine mode interrupt evaluation process is first entered, and then the interrupt processing entry of the virtual machine kernel is directly jumped to in the virtual machine mode.

[0019] Furthermore, the privileged firmware virtual machine mode interrupt evaluation process includes: when the virtual machine turns on the interrupt enable, the virtual machine falls into the hardware mode where the privileged firmware is located, and after the interrupt enable bit is set, checks whether the interrupt information to be processed is registered in VCPU_IRQ;

[0020] In response to the interrupt information to be processed registered in VCPU_IRQ, the interrupt information in VCPU_IRQ is saved to the stack, and the set state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and the interrupt processing entry of the virtual machine kernel is jumped;

[0021] In response to the fact that the pending interrupt information is not registered in VCPU_IRQ, checking whether IRQS_PENDING is set;

[0022] In response to a setting in IRQS_PENDING, the pending interrupt information is extracted and registered in VCPU_IRQ, and then the interrupt information in VCPU_IRQ is saved to the stack, and the setting state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and the virtual machine kernel interrupt processing entry is jumped;

[0023] In response to IRQS_PENDING not being set, return directly.

[0024] Furthermore, after jumping to the virtual machine kernel interrupt processing entry, the method further includes: the virtual machine kernel interrupt processing function calls a processing function corresponding to the interrupt type to perform interrupt processing according to the interrupt information in the stack.

[0025] In a second aspect, the present invention provides an electronic device comprising: a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware as described in the first aspect is implemented.

[0026] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware as described in the first aspect is implemented.

[0027] Compared with the prior art, the present invention has the following beneficial effects:

[0028] (1) The present invention can realize hardware-like virtual machine interrupt control through the virtual machine interrupt direct delivery process without hardware support, complete the direct delivery of virtual machine interrupts, reduce VM-Exit in the virtual machine interrupt processing process, optimize the virtual machine interrupt processing process, thereby reducing interrupt processing delay, improving the interrupt processing efficiency of various interrupts delivered to virtual machines under the Shenwei architecture, and improving the overall performance of virtual machines;

[0029] (2) After the present invention adds interrupt evaluation support for the virtual machine mode in the privileged firmware, even when the virtual machine receives a notification interrupt or VM-Entry, the interrupt registered in the VCPU_IRQ cannot be processed immediately due to interrupt prohibition. However, the interrupt can be injected into the virtual machine immediately at the moment the interrupt is enabled and the virtual machine can directly process the interrupt without VM-Exit and waiting for the next VM-Entry, thereby reducing the overhead caused by VM-Exit and increasing the opportunity for virtual machine interrupt processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 A flowchart of traditional virtual machine interrupt processing in the Shenwei architecture virtualization environment provided in Example 1 of the present invention;

[0031] Figure 2 This is a flowchart of a method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware provided in Example 2 of the present invention. DETAILED DESCRIPTION

[0032] The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices. The technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments.

[0033] It should be noted that KVM (Kernel-based Virtual Machine) is a virtualization technology based on the Linux kernel. VM-Entry operation and VM-Exit operation are used to describe the mutual conversion between processor operating environments in virtualization scenarios. VM-Entry operation switches the CPU from physical machine mode to virtual machine mode to run the client operating system instructions; if sensitive instructions are executed or an interrupt occurs in the virtual machine mode, VM-Exit will be triggered and the system will switch back to physical machine mode to run the virtual machine monitor VMM. Example

[0034] The present invention provides a method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware, the method comprising:

[0035] Step 1: After the interrupt source of the virtual machine generates an interrupt that needs to be delivered to the virtual machine, the KVM obtains the target virtual CPU and interrupt information of the interrupt, and registers the interrupt information into the interrupt setting state bitmap IRQS_PENDING of the target virtual CPU.

[0036] Specifically, the Shenwei architecture physical machine includes: a VCPUCB structure; the VCPUCB structure is used to save the status information of each virtual CPU and communicate between the virtual machine monitor VMM and the privileged firmware; the VCPUCB structure includes: an interrupt set status bitmap IRQS_PENDING and VCPU_IRQ; the interrupt set status bitmap IRQS_PENDING is used to record the set status of all types of interrupts in the virtual CPU; the VCPU_IRQ is used to record all interrupt types in the virtual CPU.

[0037] Step 2: KVM checks the operating mode of the physical CPU where the target virtual CPU is located. If the operating mode of the physical CPU is the physical machine mode, the target virtual CPU is awakened or scheduled to execute the traditional virtual machine interrupt processing process; if the operating mode of the physical CPU is the virtual machine mode, KVM sends a notification interrupt to the physical CPU to notify the virtual machine of the interrupt to be processed, and executes the virtual machine interrupt direct delivery process.

[0038] Among them, Figure 1 As shown in the figure, the traditional virtual machine interrupt processing process includes:

[0039] Step 211: Check the setting status in the interrupt setting status bitmap IRQS_PENDING, and extract the information of the pending interrupt from it.

[0040] Step 212: The KVM checks the interrupt enable status of the virtual machine.

[0041] Specifically, if the virtual machine interrupt is enabled, the interrupt information in IRQS_PENDING is written into VCPU_IRQ, and the set state of the corresponding bit in IRQS_PENDING is cleared; if the virtual machine interrupt is disabled, it is necessary to wait for the next VM-Entry in which the virtual machine interrupt is enabled to process the interrupt information in IRQS_PENDING.

[0042] Step 213: Check the interrupt enable state of the virtual machine again in the hardware mode where the privileged firmware is located.

[0043] Specifically, if the virtual machine interrupt is enabled, the interrupt information in VCPU_IRQ is saved to the stack, VCPU_IRQ is cleared, and then jumps to the virtual machine kernel interrupt processing entry; if the virtual machine interrupt is disabled, wait until the next VM-Entry interrupt is enabled before processing.

[0044] It should be noted that the notification interrupt is a specific physical core interrupt, which is specially used for virtual machine interrupt notification events. The virtual machine does not exit after receiving the notification interrupt.

[0045] Step 3: The virtual machine kernel interrupt processing function calls the processing function corresponding to the interrupt type to perform interrupt processing according to the interrupt information in the stack.

[0046] Example 2

[0047] Based on Example 1, this example provides steps for a virtual machine interrupt direct delivery process.

[0048] like Figure 2 As shown in the figure, the virtual machine interrupt direct delivery process includes:

[0049] Step 221: After the physical CPU receives the notification interrupt in the hardware mode where the privileged firmware is located, the operation mode of the physical CPU is checked again.

[0050] Specifically, if the current operating mode of the physical CPU is the virtual machine mode, clear the interrupt request for the notification interrupt in the physical machine interrupt status register, extract the pending interrupt information from the IRQS_PENDING of the target virtual CPU, and register the interrupt information in the VCPU_IRQ in the VCPUCB structure for recording the interrupt type.

[0051] Step 222: After registering the interrupt information into VCPU_IRQ in the VCPUCB structure for recording the interrupt type, check the interrupt enable status of the virtual machine.

[0052] Specifically, if the virtual machine interrupt is enabled, the interrupt information in VCPU_IRQ is saved to the stack, and the set state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and then jump to the virtual machine kernel interrupt processing entry; if the virtual machine interrupt is disabled, wait for the virtual machine interrupt to be enabled, and after the virtual machine interrupt is enabled, first enter the privileged firmware virtual machine mode interrupt evaluation process, and then directly jump to the virtual machine kernel interrupt processing entry in the virtual machine mode.

[0053] More specifically, the privileged firmware virtual machine mode interrupt assessment process includes:

[0054] When the virtual machine turns on the interrupt enable, the virtual machine falls into the hardware mode where the privileged firmware is located. After the interrupt enable bit is set, it checks whether the pending interrupt information is registered in VCPU_IRQ.

[0055] If there is pending interrupt information registered in VCPU_IRQ, the interrupt information in VCPU_IRQ is saved in the stack, and the set state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and the interrupt processing entry of the virtual machine kernel is jumped to.

[0056] If the pending interrupt information is not registered in VCPU_IRQ, check whether there is a set bit in IRQS_PENDING. If there is a set bit in IRQS_PENDING, extract the pending interrupt information and register it in VCPU_IRQ, then save the interrupt information in VCPU_IRQ to the stack, clear the set state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ, and jump to the virtual machine kernel interrupt processing entry; if there is no set bit in IRQS_PENDING, return directly.

[0057] In addition, if the current operation mode of the physical CPU is the physical machine mode, the interrupt request for the notification interrupt in the physical machine interrupt status register is cleared and the interrupt information in IRQS_PENDING is processed at the next VM-Entry.

[0058] Example 3

[0059] The present embodiment provides an electronic device, including: a processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware as described in Example 1 or Example 2 is implemented.

[0060] Example 4

[0061] This embodiment provides a computer storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware as described in Example 1 or Example 2 is implemented.

[0062] The storage medium may include, for example, a storage component of a tablet computer, a hard disk of a computer, a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a portable compact disk read-only memory (CD-ROM), a USB memory, or any combination of the above storage media. The computer storage medium may be any combination of one or more computer storage media.

[0063] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware, characterized in that: The Shenwei architecture physical machine includes: a VCPUCB structure; the VCPUCB structure is used to store the status information of each virtual CPU and communicate between the virtual machine monitor VMM and the privileged firmware; The VCPUCB structure includes: an interrupt setting state bitmap IRQS_PENDING and VCPU_IRQ; the interrupt setting state bitmap IRQS_PENDING is used to record the setting state of all types of interrupts in the virtual CPU; the VCPU_IRQ is used to record all interrupt types in the virtual CPU; The method comprises: In response to an interrupt source of the virtual machine generating an interrupt that needs to be delivered to the virtual machine, the KVM obtains a target virtual CPU and interrupt information of the interrupt, and registers the interrupt information into an interrupt setting state bitmap IRQS_PENDING of the target virtual CPU; KVM checks the operating mode of the physical CPU where the target virtual CPU is located; In response to the operating mode of the physical CPU being the virtual machine mode, the KVM sends a notification interrupt to the physical CPU to notify the virtual machine of an interrupt to be processed, and executes a virtual machine interrupt direct delivery process; In response to the operating mode of the physical CPU being the physical machine mode, the target virtual CPU is awakened or scheduled to execute a traditional virtual machine interrupt processing flow.

2. The method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware according to claim 1, characterized in that: The virtual machine interrupt direct delivery process includes: In response to the physical CPU receiving the notification interrupt in the hardware mode where the privileged firmware is located, checking the operation mode of the physical CPU again; In response to the operating mode of the physical CPU being the virtual machine mode, clearing the interrupt request for the notification interrupt in the physical machine interrupt status register, extracting the pending interrupt information from the IRQS_PENDING of the target virtual CPU, and registering the interrupt information into the VCPU_IRQ in the VCPUCB structure for recording the interrupt type; In response to the operating mode of the physical CPU being the physical machine mode, the interrupt request regarding the notification interrupt in the physical machine interrupt status register is cleared and the program returns.

3. The method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware according to claim 2, characterized in that: The virtual machine interrupt direct delivery process also includes: After registering the interrupt information into VCPU_IRQ in the VCPUCB structure for recording the interrupt type, checking the interrupt enable state of the virtual machine; In response to the virtual machine interrupt enable, the interrupt information in VCPU_IRQ is saved to the stack, and the set state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and then jumps to the virtual machine kernel interrupt processing entry; In response to the virtual machine interrupt disabling, the virtual machine interrupt enabling is waited for, and after the virtual machine interrupt enabling, the privileged firmware virtual machine mode interrupt evaluation process is first entered, and then the interrupt processing entry of the virtual machine kernel is directly jumped to in the virtual machine mode.

4. The method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware according to claim 3 is characterized in that: The privileged firmware virtual machine mode interruption assessment process includes: When the virtual machine turns on the interrupt enable, the virtual machine falls into the hardware mode where the privileged firmware is located. After the interrupt enable bit is set, it checks whether the pending interrupt information is registered in VCPU_IRQ; In response to the interrupt information to be processed registered in VCPU_IRQ, the interrupt information in VCPU_IRQ is saved to the stack, and the set state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and the interrupt processing entry of the virtual machine kernel is jumped; In response to the fact that the pending interrupt information is not registered in VCPU_IRQ, checking whether IRQS_PENDING is set; In response to a setting in IRQS_PENDING, the pending interrupt information is extracted and registered in VCPU_IRQ, and then the interrupt information in VCPU_IRQ is saved to the stack, and the setting state of the corresponding bit in IRQS_PENDING and the interrupt information in VCPU_IRQ are cleared, and the virtual machine kernel interrupt processing entry is jumped; In response to IRQS_PENDING not being set, return directly.

5. The method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware according to claim 4 is characterized in that: After jumping to the virtual machine kernel interrupt processing entry, the method further includes: the virtual machine kernel interrupt processing function calls a processing function corresponding to the interrupt type to perform interrupt processing according to the interrupt information in the stack.

6. An electronic device, characterized in that: include: A processor and a memory, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, a method for directly delivering virtual machine interrupts based on Shenwei architecture privileged firmware according to any one of claims 1 to 5 is implemented.

7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, the method for direct delivery of virtual machine interrupts based on Shenwei architecture privileged firmware as described in any one of claims 1 to 5 is implemented.

Citation Information

Cited By

  • Interrupt multi-distribution method of Xen platform

    CN121455601A