CN-119690865-B - Device access method, storage medium and electronic device
Abstract
The application discloses a device access method, a storage medium and electronic equipment, and relates to the technical field of computers. The method comprises the steps of obtaining an access address, determining a simulation mode corresponding to a configuration space based on the access address, wherein the access address is used for accessing the configuration space of virtual equipment through a virtual processor thread, determining whether the simulation mode is used for determining whether to simulate content read-write operation of the configuration space through state conversion between a kernel mode and a user mode, and accessing the configuration space according to the simulation mode. The application solves the technical problems that the virtual machine monitor executes additional simulation actions and the simulation cost is high when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnection device in the related technology and exits to the virtual machine monitor for simulation.
Inventors
- ZHENG XIANG
Assignees
- 杭州阿里云飞天信息技术有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20230922
Claims (13)
- 1. A method of device access, comprising: Obtaining an access address, wherein the access address is used for accessing a configuration space of a virtual device through a virtual processor thread, and the configuration space is used for recording and configuring the attribute, the function and the operation of the virtual device; Determining a simulation mode corresponding to the configuration space based on the access address, wherein the simulation mode is used for determining whether to simulate the content read-write operation of the configuration space through state transition between a kernel mode and a user mode, and determining based on preset field content obtained by field analysis of the access address, wherein the preset field content is used for determining whether to execute the content read-write operation of the configuration space through the user mode simulation mode; and accessing the configuration space according to the simulation mode.
- 2. The method of claim 1, wherein determining the simulation corresponding to the configuration space based on the preset field content comprises: And responding to the preset field content to determine that the content read-write operation is not required to be executed on the configuration space in the user mode simulation mode, and determining that the simulation mode corresponding to the configuration space is to simulate the content read-write operation on the configuration space in the kernel mode.
- 3. The method of claim 2, wherein accessing the configuration space in the simulated manner comprises: And responding to the simulation mode to simulate the content read-write operation of the configuration space in the kernel mode, and accessing the configuration space in the kernel mode.
- 4. A method according to claim 3, characterized in that the method further comprises: And responding to the completion of the execution of the read-write operation of the content of the configuration space, and returning to the virtual machine running environment to execute the subsequent operation instruction.
- 5. The method of claim 1, wherein determining the simulation corresponding to the configuration space based on the preset field content comprises: and responding to the preset field content to determine that the content read-write operation is executed on the configuration space in the user state simulation mode, and determining that the simulation mode corresponding to the configuration space is to simulate the content read-write operation on the configuration space in the user state.
- 6. The method of claim 5, wherein accessing the configuration space in the analog manner comprises: Responding to the simulation mode to simulate the content read-write operation of the configuration space in the user mode, and switching from the kernel mode to the user mode; And simulating the virtual equipment in the user state to execute the content read-write operation of the configuration space to obtain a read-write result, wherein the read-write result is used for recording the content reading result or the content modifying result of the configuration space.
- 7. The method of claim 6, wherein the method further comprises: Executing corresponding simulation actions based on the read-write result; Switching back to the kernel mode from the user mode in response to completion of the execution of the simulated action; And in the kernel mode, returning to the virtual machine running environment to execute the subsequent operation instruction.
- 8. The method of claim 1, wherein the virtual device comprises a virtual peripheral component interconnect device.
- 9. A method of device access, comprising: Obtaining an access address, wherein the access address is used for accessing a configuration space of a virtual device through a virtual processor thread, and the configuration space is used for recording and configuring the attribute, the function and the operation of the virtual device; Performing field analysis on the access address to obtain preset field content, wherein the preset field content is used for determining whether to execute content read-write operation on the configuration space in a user state simulation mode; And responding to the preset field content to determine that the content read-write operation of the configuration space is not required to be simulated through state transition between a kernel mode and a user mode, and accessing the configuration space in the kernel mode.
- 10. A device access system is characterized by comprising a virtual processor, a virtual device and a virtual machine monitor; the virtual machine monitor is used for performing state transition between a kernel state and a user state to execute simulation operation corresponding to an access address, wherein the access address is used for accessing a configuration space of the virtual device, and the configuration space is used for recording and configuring the attribute, the function and the operation of the virtual device; The virtual processor is configured to determine, based on the access address, a simulation mode corresponding to the configuration space, so as to access the configuration space according to the simulation mode, where the simulation mode is determined based on preset field content obtained by performing field analysis on the access address, and the preset field content is used to determine whether to perform content read-write operation on the configuration space in a user state simulation mode.
- 11. The system of claim 10, wherein the virtual processor is further configured to perform field parsing on the access address to obtain a preset field content, and determine a simulation mode corresponding to the configuration space based on the preset field content, where the preset field content is used to determine whether to perform a content read-write operation on the configuration space in a user mode simulation mode.
- 12. A computer-readable storage medium, characterized in that the computer-readable storage medium comprises a stored executable program, wherein the executable program, when run, controls a device in which the computer-readable storage medium is located to perform the device access method according to any one of claims 1 to 9.
- 13. An electronic device, comprising: A memory storing an executable program; A processor for executing the program, wherein the program when executed performs the device access method of any one of claims 1 to 9.
Description
Device access method, storage medium and electronic device Technical Field The present application relates to the field of computer technologies, and in particular, to a device access method, a storage medium, and an electronic device. Background Virtualization technology is a technology that abstracts physical resources into virtual resources so that multiple virtual environments can share the physical resources. In a virtualization scenario, when a virtual central processing unit (Virtual Central Processing Unit, VCPU) reads and writes a configuration space of a virtual peripheral component interconnect (PERIPHERAL COMPONENT INTERCONNECT, PCI) device, the virtual central processing unit generally exits to a virtual machine monitor (Hypervisor) for simulation, and in the process of simulating the Hypervisor, a longer simulation path may also need to be switched between a kernel mode and a user mode, so that the Hypervisor can acquire a higher privilege level when needed, and monitor and control a virtual machine. However, the above solution may cause the Hypervisor to perform additional simulation actions, increasing the simulation overhead of the Hypervisor layer. In view of the above problems, no effective solution has been proposed at present. Disclosure of Invention The embodiment of the application provides a device access method, a storage medium and electronic equipment, which at least solve the technical problems that a virtual Central Processing Unit (CPU) in the related art can exit to a virtual machine monitor for simulation when reading and writing configuration space of virtual peripheral component interconnection devices, so that the virtual machine monitor executes additional simulation actions and the simulation cost is high. According to one aspect of the embodiment of the application, a device access method is provided, which comprises the steps of obtaining an access address, determining a simulation mode corresponding to a configuration space based on the access address, wherein the simulation mode is used for determining whether to simulate content read-write operation of the configuration space through state transition between a kernel mode and a user mode, and accessing the configuration space according to the simulation mode. According to another aspect of the embodiment of the application, a device access method is provided, which comprises the steps of obtaining an access address, wherein the access address is used for accessing a configuration space of a virtual device through a virtual processor thread, and simulating content read-write operation of the configuration space without state transition between a kernel mode and a user mode based on the access address, and accessing the configuration space in the kernel mode. According to another aspect of the embodiment of the application, a device access system is provided, which comprises a virtual processor, a virtual device and a virtual machine monitor, wherein the virtual machine monitor is used for performing state conversion between a kernel state and a user state so as to execute simulation operation corresponding to an access address, the access address is used for accessing a configuration space of the virtual device, and the virtual processor is used for determining a simulation mode corresponding to the configuration space based on the access address so as to access the configuration space in a simulation mode. According to another aspect of the embodiments of the present application, there is further provided a computer readable storage medium, where the computer readable storage medium includes a stored executable program, and when the executable program runs, a device in which the computer readable storage medium is located is controlled to execute any one of the above device access methods. According to another aspect of the embodiment of the application, there is also provided an electronic device, including a memory storing an executable program, and a processor for running the program, wherein the program executes any one of the above device access methods when running. In the embodiment of the application, the storage address, namely the access address, of the virtual PCI device configuration space to be accessed by the VCPU is obtained. And determining whether switching operation is required to be executed between a kernel mode and a user mode when the configuration space is subjected to read-write access operation according to the access address of the configuration space, namely determining a simulation mode corresponding to the configuration space. Finally, the configuration space is accessed according to the simulation mode, so that the purpose of reasonably selecting whether to execute the switching operation of the kernel mode and the user mode when the configuration space of the virtual PCI device is accessed is achieved, the switching between the kernel mode and the user mode can be reduced when the swit