Equipment access method, storage medium and electronic equipment

By determining whether the virtual central processor needs to switch between kernel and user state when accessing the configuration space of virtual peripheral component interconnection devices, the problem of increasing overhead by performing additional simulation actions by the virtual machine monitor is solved, and the effect of reducing simulation overhead is achieved.

CN119690865AActive Publication Date: 2025-03-25HANGZHOU ALICLOUD FEITIAN INFORMATION TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202311240637.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-09-22
Publication Date
2025-03-25
Estimated Expiration
2043-09-22

AI Technical Summary

Technical Problem

In a virtualized scenario, when the virtual central processor reads and writes the configuration space of the virtual peripheral component interconnection device, it needs to exit the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions and increase simulation overhead.

Method used

By obtaining the storage address of the virtual central processor accessing the configuration space of the virtual peripheral component interconnection device, it is determined whether it is necessary to switch between the kernel state and the user state to simulate read and write operations, and access in a determined simulation manner, thereby reducing the switching between the kernel state and the user state when there is no need to switch.

Benefits of technology

Reduces unnecessary simulation overhead and improves the performance and efficiency of accessing virtual PCI device configuration space.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690865A_ABST
    Figure CN119690865A_ABST
Patent Text Reader

Abstract

The invention discloses a device access method, a storage medium and an electronic device, and relates to the technical field of computers. The method comprises the steps that an access address is obtained, and the access address is used for accessing a configuration space of virtual equipment through a virtual processor thread; based on the access address, determining a simulation mode corresponding to the configuration space, the simulation mode being used for determining whether to pass state transition between a kernel state and a user state, and simulating a content read-write operation on the configuration space; and accessing the configuration space according to the simulation mode. According to the method and the device, the technical problem that the simulation overhead is relatively high due to the fact that the virtual machine monitor executes an additional simulation action when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnection equipment in the related technology and quits to the virtual machine monitor for simulation is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a device access method, a storage medium, and an electronic device. Background Art

[0002] Virtualization technology is a technology that abstracts physical resources into virtual resources so that multiple virtual environments can share physical resources. In a virtualization scenario, when a virtual central processing unit (VCPU) reads and writes the configuration space of a virtual peripheral component interconnect (PCI) device, it usually exits to the virtual machine monitor (Hypervisor) for simulation. During the simulation process of the Hypervisor, a long simulation path may also need to switch between kernel mode and user mode, so that the Hypervisor can obtain a higher privilege level when needed and monitor and control the virtual machine. However, the above solution will cause the Hypervisor to perform additional simulation actions, increasing the simulation overhead of the Hypervisor layer.

[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0004] The embodiments of the present application provide a device access method, a storage medium, and an electronic device to at least solve the technical problem in the related art that when a virtual central processing unit reads and writes the configuration space of a virtual peripheral component interconnect device, it exits to a virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions and resulting in high simulation overhead.

[0005] According to one aspect of an embodiment of the present application, a device access method is provided, including: obtaining an access address, wherein the access address is used to access the configuration space of a virtual device through a virtual processor thread; based on the access address, determining a simulation mode corresponding to the configuration space, wherein the simulation mode is used to determine whether to simulate read and write operations on the content of the configuration space through a state transition between a kernel state and a user state; and accessing the configuration space according to the simulation mode.

[0006] According to another aspect of an embodiment of the present application, a device access method is also provided, including: obtaining an access address, wherein the access address is used to access the configuration space of a virtual device through a virtual processor thread; in response to determining based on the access address that there is no need to simulate the read and write operations on the contents of the configuration space through a state transition between kernel state and user state, accessing the configuration space in kernel state.

[0007] According to another aspect of an embodiment of the present application, a device access system is also provided, including: a virtual processor, a virtual device and a virtual machine monitor; the virtual machine monitor is used to convert states between kernel state and user state to perform simulation operations corresponding to an access address, wherein the access address is used to access the configuration space of the virtual device; the virtual processor is used to determine the simulation mode corresponding to the configuration space based on the access address, so as to access the configuration space in the simulation mode.

[0008] According to another aspect of an embodiment of the present application, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored executable program, wherein when the executable program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned device access methods.

[0009] According to another aspect of an embodiment of the present application, an electronic device is further provided, including: a memory storing an executable program; and a processor for running the program, wherein any one of the above-mentioned device access methods is executed when the program is running.

[0010] In an embodiment of the present application, the storage address of the virtual PCI device configuration space to be accessed by the VCPU, i.e., the access address, is obtained. According to the access address of the configuration space, it is determined whether it is necessary to perform a switching operation between the kernel state and the user state when performing a read and write access operation on the configuration space, i.e., the simulation mode corresponding to the configuration space is determined. Finally, the configuration space is accessed in accordance with the simulation mode, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, so that when the switching operation between the kernel state and the user state is not required, the switching between the kernel state and the user state is reduced, and the technical effect of reducing unnecessary simulation overhead is achieved, thereby solving the technical problem that when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnect device in the related art, it will exit to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, and the simulation overhead is high.

[0011] It is easy to notice that the above general description and the following detailed description are only for the purpose of exemplifying and explaining the present application, and do not constitute a limitation of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0013] Figure 1 It is a schematic diagram of PCI device configuration space in the related art;

[0014] Figure 2 is a flow chart of accessing a virtual PCI device configuration space in the related art;

[0015] Figure 3 A hardware structure block diagram of a computer terminal (or mobile device) for implementing a device access method according to Embodiment 1 of the present application;

[0016] Figure 4 is a flow chart of a device access method according to Embodiment 1 of the present application;

[0017] Figure 5 is a flow chart of another device access method according to Embodiment 1 of the present application;

[0018] Figure 6 is a flow chart of a device access method according to Embodiment 2 of the present application;

[0019] Figure 7 is a structural diagram of an apparatus for accessing a virtual device configuration space according to Embodiment 4 of the present application;

[0020] Figure 8 is a structural diagram of another apparatus for accessing a virtual device configuration space according to Embodiment 4 of the present application;

[0021] Fig. 9 It is a structural block diagram of a computer terminal according to Example 5 of the present application. DETAILED DESCRIPTION

[0022] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution 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. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0023] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising 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.

[0024] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following explanations:

[0025] Virtual Central Processing Unit (VCPU): In a virtualized scenario, a virtual processor refers to a logical processor simulated in a virtual machine. A virtual processor is implemented by virtualization software (such as a virtual machine monitor) dividing and allocating the computing resources of a physical processor to multiple virtual machines. In the embodiments of the present application, a virtual central processor is also called a virtual processor, denoted as VCPU.

[0026] Hypervisor: A software that creates, runs, and manages virtual machines. It is used to manage and run virtual machines (VMs). The main functions of Hypervisor include resource management, creation, destruction, and management of virtual machines, communication and data transmission between virtual machines and physical computers, etc. Hypervisor divides the hardware resources of a physical computer (such as processors, memory, storage, etc.) into multiple virtual machines by creating a virtualization layer on the physical computer, and provides an independent virtual hardware environment for each virtual machine.

[0027] Guest context and Host context: are two concepts used in a virtualization environment to describe the different execution environments between a virtual machine (Guest) and a host (Host). Guest context refers to the state and environment of a virtual machine when it is running in its own execution environment, and Host context refers to the execution environment of the operating system and virtualization software running on the host (that is, the physical machine running the virtual machine). For example, when the host central processing unit (CPU) is executing the code of the virtual machine, it is in the Guest context, and when the host CPU is executing the code of the host, it is in the Host context. Through these two contexts, the virtualization environment implements the isolation and management of virtual machines.

[0028] Fast Path: Fast forwarding path refers to the path in network devices (such as switches and routers) that quickly forwards data packets from input ports to output ports by directly using known routing information. Fast paths usually consist of the best paths between network devices and routers to reduce the possibility of delays and packet loss during data packet transmission, providing faster transmission speeds and more stable connection quality.

[0029] Kernel state: refers to the operating system running in privileged mode, with the highest permissions and the ability to access system resources. In kernel state, the operating system can execute privileged instructions, access all memory spaces and devices, and directly control and manage hardware.

[0030] User state: refers to the application or user code running in non-privileged mode and can only access restricted resources. In user state, the application cannot directly access hardware devices and system resources, but requests kernel state to provide services through system calls. System calls are special function calls used to switch to kernel state, execute related kernel code, and return results to user state.

[0031] By dividing the functions and permissions of the operating system into kernel state and user state, the security and stability of the system can be effectively protected. Kernel state has higher permissions and more system resources for managing and controlling the entire system. User state can only access restricted resources to ensure isolation and security between applications.

[0032] Peripheral Component Interconnect (PCI) device: refers to a device that uses the PCI bus interface. PCI devices have three spaces: memory address space, input / output (I / O) address space, and configuration space.

[0033] Configuration Space of PCI Device: It is a specific memory area in PCI device, which is used to describe and configure the properties, functions and operations of PCI device. The configuration space contains various properties and configuration registers of PCI device. These configuration registers include the manufacturer identification (identifier, ID) of the device, device ID, category and subcategory of the device, interrupt number, I / O resource allocation, memory resource allocation, interrupt line, etc. By accessing the configuration space of PCI device, the configuration information of PCI device can be read and modified. In the embodiment of the present application, PCI device refers to PCI device and Peripheral Component Interconnect Express (PCIE) device.

[0034] Figure 1 It is a schematic diagram of PCI device configuration space in related technology, such as Figure 1As shown, the PCI device configuration space includes: Device ID, Vendor ID, Status, Command, Class Code, Revision ID, BIST (Built-In Self-Test), Header type, Latency timer, Cache line size, Base Address Registers, Cardbus Address Registers, Subsystem ID, Subsystem Vendor ID, Expansion ROM Base Address, Reserved, Capabilities Pointer, Max_Lat, Min_Gnt, IRQ Pin and IRQ Line.

[0035] The Device ID is used to identify the model or type of the device, and the parameters are assigned by the device manufacturer. The Vendor ID is used to identify the manufacturer of the device, and the parameters are assigned by the manufacturer of the PCI device.

[0036] Status is used to reflect the current status of the device.

[0037] Command is used to control some behaviors of the device, such as enabling the device, enabling interrupts, etc.

[0038] Class Code is used to describe the type and function of the device.

[0039] Revision ID is used to identify the version information of the device.

[0040] BIST is a function in the PCI device configuration space that is used for self-diagnosis and self-testing.

[0041] Header type is used to identify the configuration space type of the device.

[0042] Latency timer is used to set the delay time for the device to respond to the host.

[0043] Cache line size is used to set the cache line size of the device.

[0044] Base Address Registers are used to describe the base addresses of I / O ports, memory areas, or other resources used by the device.

[0045] Cardbus Address Registers are a set of registers in the PCI device configuration space that are used to store the address information of Cardbus devices.

[0046] Subsystem ID and Subsystem Vendor ID are used to identify the subsystem to which the device belongs.

[0047] Expansion ROM Base Address is used to specify the base address of the expansion ROM of the device.

[0048] Expansion ROM is a firmware stored on the device, which can contain device drivers, BIOS extensions, etc. This field specifies the starting address of the expansion ROM in physical memory.

[0049] Reserved refers to some fields in the PCI device configuration space that are reserved for future specification extensions or other purposes.

[0050] The Capabilities Pointer is used to indicate the location of the extended capabilities structure in the device configuration space.

[0051] Max_Lat is an 8-bit field that indicates the maximum time that a PCI device needs to occupy the bus in order to complete the currently executing transaction.

[0052] Min_Gnt is an 8-bit field that indicates the minimum time that a PCI device releases the bus.

[0053] IRQ Pin is a 4-bit field that indicates the interrupt pin number used by the PCI device.

[0054] IRQ Line is used to indicate the number of the interrupt request line used by the device.

[0055] Figure 2 is a flowchart of accessing the virtual PCI device configuration space in the related art, such as Figure 2 As shown, the VCPU accesses the configuration space of the virtual PCI device by reading and writing a specific memory address. When accessing the configuration space of the virtual PCI device, the VCPU usually exits to the Hypervisor for simulation, that is, the VCPU switches to the Hypervisor user state.

[0056] In user mode, the corresponding virtual PCI device processing callback function can be found according to the address accessed by the VCPU, and by executing the function, the read and write operations are simulated to perform corresponding processing on the configuration space of the virtual PCI device.

[0057] After the user mode simulation is completed, the VCPU will switch back to the kernel mode and execute some common processing procedures related to entering the guest context to prepare for entering the virtual machine's execution environment. Finally, the VCPU will return to the guest context again and continue to execute the next instruction to complete the read and write operations on the virtual PCI device configuration space.

[0058] In the related art, the method for accessing the virtual PCI device configuration space has the following defects.

[0059] Defect 1: Since the reading and writing of most areas of the virtual PCI device configuration space only involves modifying or reading the content, the Hypervisor does not need to perform additional simulation actions. In the related art, when reading and writing the configuration space of the virtual PCI device, switching between kernel mode and user mode is performed, which causes the Hypervisor to perform additional simulation actions, thereby increasing the simulation overhead of the Hypervisor layer.

[0060] With respect to the above-mentioned defects, no effective solution has been proposed before the present application.

[0061] Example 1

[0062] According to an embodiment of the present application, a device access method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0063] The method embodiment provided in the first embodiment of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 3 FIG. 1 shows a hardware structure block diagram of a computer terminal (or mobile device) for implementing a device access method. Figure 3As shown, the computer terminal 30 (or mobile device) may include one or more (302a, 302b, ..., 302n are used to illustrate) processors 302 (the processor 302 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 304 for storing data, and a transmission device 306 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 3 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 3 More or fewer components as shown, or with Figure 3 Different configurations are shown.

[0064] It should be noted that the one or more processors 302 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 30 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0065] The memory 304 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the device access method in the embodiment of the present application. The processor 302 executes various functional applications and data processing by running the software programs and modules stored in the memory 304, that is, realizing the above-mentioned device access method. The memory 304 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 304 may further include a memory remotely arranged relative to the processor 302, and these remote memories may be connected to the computer terminal 30 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0066] The transmission device 306 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 30. In one example, the transmission device 306 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 306 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0067] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 30 (or mobile device).

[0068] Under the above operating environment, this application provides Figure 4 Device access method shown. Figure 4 1 is a flow chart of a device access method according to Embodiment 1 of the present application. Figure 4 As shown, the method may include the following steps:

[0069] Step S41, obtaining an access address, wherein the access address is used to access the configuration space of the virtual device through the virtual processor thread;

[0070] Step S42, determining a simulation mode corresponding to the configuration space based on the access address, wherein the simulation mode is used to determine whether to simulate a read and write operation on the content of the configuration space through a state transition between a kernel state and a user state;

[0071] Step S43: access the configuration space in a simulation manner.

[0072] The access address can be understood as the address accessed by the VCPU, that is, the storage address of the virtual PCI device configuration space.

[0073] The virtual device can be understood as a virtual PCI device or a virtual PCIE device, which is not limited here. In the embodiment of the present application, the virtual device is taken as a virtual PCI device as an example for explanation.

[0074] The configuration space is used to record the configuration information of the virtual device. The configuration space can be understood as a memory area used to record and configure the properties, functions and operations of the virtual PCI device.

[0075] Exemplarily, the properties of the virtual PCI device may include a virtual PCI device type and a virtual PCI device identifier, etc., wherein the virtual PCI device type is used to indicate various types of PCI devices simulated by the virtual PCI device, including a network adapter, a storage controller, a graphics display card, etc. The virtual PCI device identifier is used to uniquely identify the device in a virtualized environment.

[0076] The functions of the virtual PCI device include various functions of the real PCI device simulated by the virtual PCI device, such as data transmission, interrupt processing, DMA control, etc.

[0077] The operations of the virtual PCI device include: configuring the virtual PCI device (e.g., setting the configuration space of the virtual PCI device, etc.), initializing the virtual PCI device (e.g., initializing the device's registers, interrupt and DMA settings, etc.), reading the configuration space of the virtual PCI device (e.g., obtaining relevant information of the device, such as vendor ID, device ID, device category code, interrupt number, resource allocation, etc.), writing to the configuration space of the virtual PCI device (e.g., modifying relevant configurations of the device, such as interrupt number, resource allocation, etc.), reading and writing the registers of the virtual PCI device (e.g., implementing control and configuration of the device, such as turning on / off the device, setting the device status, etc.), performing DMA operations of the virtual PCI device (e.g., implementing data transmission and exchange), responding to interrupts of the virtual PCI device (e.g., interrupt processing and execution of interrupt service programs), and other operations.

[0078] In a virtualized scenario, a virtual processor thread can read and modify device configuration parameters, such as interrupt enable, data transfer mode, device address, etc., by reading and writing registers in the configuration space. By accessing the configuration space, a virtual processor thread can initialize, configure, and manage virtual devices.

[0079] The simulation mode can be understood as a variety of read and write modes for reading or modifying the configuration parameters of the configuration space when the VCPU accesses the access address of the configuration space. In the embodiment of the present application, illustratively, the simulation mode may include switching between the kernel state and the user state to simulate the read and write operation. The simulation mode may also include not switching between the kernel state and the user state to directly perform the read and write operation in the kernel state.

[0080] It is understandable that when accessing the virtual PCI device configuration space, it may be necessary to perform a switching operation between kernel state and user state to simulate content read and write operations, but performing a switching operation between kernel state and user state will increase the simulation overhead.

[0081] Therefore, in the embodiment of the present application, determining the simulation mode corresponding to the configuration space can be understood as determining whether it is necessary to perform a switching operation between the kernel state and the user state when accessing the configuration space. Based on the access address, it can be determined whether it is necessary to perform a switching operation between the kernel state and the user state when the VCPU accesses the configuration space corresponding to the access address, so that the corresponding simulation mode can be reasonably selected. When the switching operation does not need to be performed, the switching between the kernel state and the user state can be reduced, thereby reducing unnecessary simulation overhead.

[0082] In an embodiment of the present application, the storage address of the virtual PCI device configuration space to be accessed by the VCPU, i.e., the access address, is obtained. According to the access address of the configuration space, it is determined whether it is necessary to perform a switching operation between the kernel state and the user state when performing a read and write access operation on the configuration space, i.e., the simulation mode corresponding to the configuration space is determined. Finally, the configuration space is accessed according to the simulation mode, so that when the switching operation between the kernel state and the user state is not required, the switching between the kernel state and the user state can be reduced, thereby reducing unnecessary simulation overhead.

[0083] The above-mentioned device access method provided in the embodiment of the present application can be applied to, but is not limited to, application scenarios involving access to virtual device configuration space in the fields of e-commerce services, educational services, legal services, medical services, conference services, social network services, financial product services, logistics services and navigation services, for example: scenarios of accessing virtual device configuration space in e-commerce services, scenarios of accessing virtual device configuration space in academic services, scenarios of accessing virtual device configuration space in medical services, etc., which are not limited here.

[0084] According to the embodiment of the present application, the storage address of the virtual PCI device configuration space to be accessed by the VCPU, that is, the access address, is obtained. According to the access address of the configuration space, it is determined whether it is necessary to perform a switching operation between the kernel state and the user state when performing a read and write access operation on the configuration space, that is, the simulation mode corresponding to the configuration space is determined. Finally, the configuration space is accessed in accordance with the simulation mode, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, so that when the switching operation between the kernel state and the user state is not required, the switching between the kernel state and the user state can be reduced, achieving the technical effect of reducing unnecessary simulation overhead, thereby solving the technical problem that when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnect device in the related art, it will exit to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, and the simulation overhead is high.

[0085] In an optional embodiment, in step S42, determining the simulation mode corresponding to the configuration space based on the access address includes the following method steps:

[0086] Step S421, performing field parsing on the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read and write operations on the configuration space in a user mode simulation manner;

[0087] Step S422: Determine the simulation mode corresponding to the configuration space based on the preset field content.

[0088] It is understandable that whether the configuration space of the virtual PCI device does not need to perform content read and write operations through user-mode simulation depends on the simulation of each virtual PCI device. Because some virtual PCI devices need to be simulated in user mode to read and write the Base Address Registers field, such as establishing a memory mapping that the virtual machine can directly read and write, creating a virtual MSIX interrupt table, etc. For other virtual PCI devices, there is no specific meaning for reading and writing the Base Address Registers field, so simulation is not required.

[0089] Therefore, the preset field content can be the field content in the configuration space, such as the Base Address Registers field content. Based on the preset field content, it can be determined whether it is necessary to perform content read and write operations on the configuration space through user mode simulation, that is, it can be determined whether it is necessary to perform a kernel mode and user mode switching operation.

[0090] By performing field parsing on the access address of the configuration space, the preset field content can be determined, and based on the preset field content, the simulation method corresponding to the configuration space can be determined, so as to reasonably access the configuration space to avoid unnecessary simulation overhead.

[0091] In an optional embodiment, in step S422, determining a simulation mode corresponding to the configuration space based on the preset field content includes the following method steps:

[0092] Step S4221, in response to determining through the preset field content that there is no need to perform content read and write operations on the configuration space through the user mode simulation mode, determine that the simulation mode corresponding to the configuration space is to simulate the content read and write operations on the configuration space in the kernel mode.

[0093] When determining the simulation method corresponding to the configuration space based on the preset field content, it is possible to determine whether the preset field content corresponding to the virtual PCI device configuration space only requires read and write operations, and determine that the simulation method of the configuration space that only requires reading and writing the configuration space content and does not require additional simulation operations can be accessed in kernel mode, that is, the simulation method is to perform simulated read and write operations without the need for user mode simulation.

[0094] If it is determined based on the preset field content that there is no need to perform a switch operation between the kernel state and the user state, that is, there is no need to switch to the user state for simulation, then this access to the configuration space can be performed in the kernel state. Therefore, it is determined that the simulation method corresponding to the configuration space is to perform read and write operations on the content of the configuration space in the kernel state, thereby avoiding unnecessary simulation overhead.

[0095] Optionally, in kernel mode, read and write operations on the content of the configuration space can be performed using a fast path, so that data transfer can be performed quickly, improving the performance and efficiency of read and write access. For example, if the configuration space address of a virtual PCI device is base, only the operations of the Base Address Registers are simulated accordingly, then [base, base+0x10) and [base+0x28, base+0x3c) can both take the fast path.

[0096] In an optional embodiment, in step S43, the configuration space is accessed in a simulation manner, including the following method steps:

[0097] Step S431 , in response to the simulation mode being to simulate the read and write operations on the content of the configuration space in the kernel state, the configuration space is accessed in the kernel state.

[0098] Exemplarily, when it is determined that the simulation mode is to simulate the content read and write operations on the configuration space in the kernel state, the content read and write operations may be performed in the kernel state using a fast path.

[0099] In an optional embodiment, the device access method further includes the following method steps:

[0100] Step S432, in response to the completion of the read and write operations of the configuration space content, return to the virtual machine running environment to execute subsequent operation instructions.

[0101] Returning to the virtual machine running environment can be understood as returning to the Guest context, thereby continuing to execute the next instruction.

[0102] After the read and write operations on the configuration space are completed in a simulated manner, the guest context can be returned to continue executing the next instruction.

[0103] In an optional embodiment, in step S422, determining a simulation mode corresponding to the configuration space based on the preset field content includes the following method steps:

[0104] Step S4222, in response to determining through the preset field content that the content read and write operation is performed on the configuration space through the user mode simulation mode, it is determined that the simulation mode corresponding to the configuration space is to simulate the content read and write operation on the configuration space in the user mode.

[0105] If it is determined based on the preset field content that a kernel mode-user mode switching operation needs to be performed, that is, it is necessary to switch to the user mode for simulation, then this access to the configuration space can be performed in the user mode. Therefore, it is determined that the simulation method corresponding to the configuration space is to perform read and write operations on the content of the configuration space in the kernel mode, thereby ensuring the correctness of the read and write operations.

[0106] In an optional embodiment, in step S43, the configuration space is accessed in a simulation manner, including the following method steps:

[0107] Step S431, in response to the simulation mode being to simulate the read and write operation of the content of the configuration space in the user mode, switching from the kernel mode to the user mode;

[0108] Step S432, simulating a virtual device in user mode to perform read and write operations on the content of the configuration space to obtain read and write results, wherein the read and write results are used to record the content reading results or content modification results of the configuration space.

[0109] Exemplarily, when it is determined that the simulation method is to simulate the read and write operations on the content of the configuration space in the user state, the switch is made from the kernel state to the user state, thereby performing the read and write operations on the content of the configuration space by simulating a virtual PCI device in the user state, and then obtaining the read and write results for recording the content reading results or content modification results of the configuration space.

[0110] In an optional embodiment, the device access method further includes the following method steps:

[0111] Step S433, performing corresponding simulation actions based on the read and write results;

[0112] Step S434, in response to the completion of the simulation action, switching from the user state back to the kernel state;

[0113] Step S435, in kernel mode, returning to the virtual machine operating environment to execute subsequent operation instructions.

[0114] In user mode, read and write operations are performed on the content of the configuration space. After the read and write results are obtained, corresponding simulation actions can be performed based on the read and write results, such as virtual interrupt simulation, device reset, etc. After the simulation action is completed, it is necessary to switch back from user mode to kernel mode and return to the Guest context to execute subsequent operation instructions.

[0115] like Figure 5 As shown, Figure 5 This is a flow chart of another device access method according to Example 1 of the present application.

[0116] The VCPU accesses the configuration space of the virtual PCI device by reading and writing specific memory addresses. When accessing the configuration space of the virtual PCI device, the VCPU will first determine whether it can take the fast path, that is, whether it needs to perform a switch operation between the kernel state and the user state. If it is determined that the fast path can be taken, the switch operation is not performed, and the content read and write access operations are performed on the virtual PCI device in the kernel state. After the read and write operations are completed, the guest context is returned to execute subsequent operation instructions.

[0117] If it is determined that the fast path cannot be taken, a switching operation is performed, switching from kernel mode to user mode. In user mode, the corresponding virtual PCI device processing callback function can be found according to the address accessed by the VCPU, and by executing the function, the read and write operations are simulated to perform corresponding processing on the configuration space of the virtual PCI device. Among them, for different configuration space access addresses, the virtual PCI device processing callback function may perform different simulation operations, such as simulated interruption, device reset, etc.

[0118] After the user mode simulation is completed, the VCPU switches back to the kernel mode and executes some common processing procedures related to entering the guest context to prepare for entering the virtual machine's execution environment. Finally, the VCPU returns to the guest context again and continues to execute the next instruction to complete the read and write operations on the virtual PCI device configuration space.

[0119] It is easy to understand that the beneficial effects of the device access method provided by the present application include the following points.

[0120] Beneficial effect (1): by judging whether a fast path can be taken, the virtual PCI device that can access the configuration space through the fast path can perform read and write access operations on the content of the configuration space in the kernel state, that is, the partial simulation of the virtual PCI device configuration space does not follow the common simulation process of the virtualization layer, thereby reducing the switching operations between the kernel state and the user state, reducing the overhead of the virtualization layer, and thus saving CPU resources.

[0121] Beneficial effect (2): by executing read and write access operations on the content of the configuration space through a fast read path, data transmission can be performed quickly, the performance and efficiency of read and write access are improved, and the access performance of the virtual machine to the virtual PCI device configuration space is thereby improved.

[0122] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0123] In addition, it should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, 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 and modules involved are not necessarily required by this application.

[0124] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, disk, CD), including several instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0125] Example 2

[0126] In the operating environment as in Example 1, the present application provides Figure 6 A device access method is shown. Figure 6 is a flow chart of a device access method according to Embodiment 2 of the present application, such as Figure 6 As shown, the method includes:

[0127] Step S61, obtaining an access address, wherein the access address is used to access the configuration space of the virtual device through the virtual processor thread;

[0128] Step S62, in response to determining based on the access address that there is no need to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state, the configuration space is accessed in the kernel state.

[0129] The access address can be understood as an address accessed by the VCPU, that is, a storage address of a virtual PCI device configuration space, which is used to access the configuration space of a virtual device through a virtual processor thread in a virtualization scenario.

[0130] The virtual device can be understood as a virtual PCI device or a virtual PCIE device, which is not limited here. In the embodiment of the present application, the virtual device is taken as a virtual PCI device as an example for explanation.

[0131] The configuration space is used to record the configuration information of the virtual device. The configuration space can be understood as a memory area used to record and configure the properties, functions and operations of the virtual PCI device.

[0132] Exemplarily, the properties of the virtual PCI device may include a virtual PCI device type and a virtual PCI device identifier, etc., wherein the virtual PCI device type is used to indicate various types of PCI devices simulated by the virtual PCI device, including a network adapter, a storage controller, a graphics display card, etc. The virtual PCI device identifier is used to uniquely identify the device in a virtualized environment.

[0133] The functions of the virtual PCI device include various functions of the real PCI device simulated by the virtual PCI device, such as data transmission, interrupt processing, DMA control, etc.

[0134] The operations of the virtual PCI device include: configuring the virtual PCI device (e.g., setting the configuration space of the virtual PCI device, etc.), initializing the virtual PCI device (e.g., initializing the device's registers, interrupt and DMA settings, etc.), reading the configuration space of the virtual PCI device (e.g., obtaining relevant information of the device, such as vendor ID, device ID, device category code, interrupt number, resource allocation, etc.), writing to the configuration space of the virtual PCI device (e.g., modifying relevant configurations of the device, such as interrupt number, resource allocation, etc.), reading and writing the registers of the virtual PCI device (e.g., implementing control and configuration of the device, such as turning on / off the device, setting the device status, etc.), performing DMA operations of the virtual PCI device (e.g., implementing data transmission and exchange), responding to interrupts of the virtual PCI device (e.g., interrupt processing and execution of interrupt service programs), and other operations.

[0135] In a virtualized scenario, a virtual processor thread can read and modify device configuration parameters, such as interrupt enable, data transfer mode, device address, etc., by reading and writing registers in the configuration space. By accessing the configuration space, a virtual processor thread can initialize, configure, and manage virtual devices.

[0136] Based on the access address, it can be determined whether the VCPU needs to perform a switching operation between kernel state and user state when accessing the configuration space corresponding to the access address, so that it can reasonably choose whether to perform the switching operation based on the simulation method. When the switching operation is not necessary, the switching between kernel state and user state can be reduced, thereby reducing unnecessary simulation overhead.

[0137] If it is determined based on the access address that there is no need to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state, the configuration space is accessed in the kernel state, thereby avoiding unnecessary simulation overhead.

[0138] The above-mentioned device access method provided in the embodiment of the present application can be applied to, but is not limited to, application scenarios involving access to virtual device configuration space in the fields of e-commerce services, educational services, legal services, medical services, conference services, social network services, financial product services, logistics services and navigation services, for example: scenarios of accessing virtual device configuration space in e-commerce services, scenarios of accessing virtual device configuration space in academic services, scenarios of accessing virtual device configuration space in medical services, etc., which are not limited here.

[0139] By adopting the embodiment of the present application, by obtaining the access address of the configuration space of the virtual device accessed through the virtual processor thread, based on the access address, it is determined that there is no need to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state, and the configuration space is accessed in the kernel state, thereby achieving the purpose of reasonably selecting whether to execute the switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, so that when the switching operation between the kernel state and the user state is not required, the switching between the kernel state and the user state can be reduced, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related technology that when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnect device, it will exit to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions and the simulation overhead is high.

[0140] It should be noted that the preferred implementation of this embodiment can refer to the relevant description in Example 1, which will not be repeated here.

[0141] Example 3

[0142] In an operating environment such as that in Example 1, the present application provides a device access system, which includes: a virtual processor, a virtual device and a virtual machine monitor; the virtual machine monitor is used to transition between kernel state and user state to perform simulation operations corresponding to an access address, wherein the access address is used to access the configuration space of the virtual device; the virtual processor is used to determine the simulation mode corresponding to the configuration space based on the access address, so as to access the configuration space in the simulation mode.

[0143] A virtual processor is a logical processor simulated in a virtual machine in a virtualization scenario.

[0144] A virtual device can be understood as a virtual PCI device, which is a simulated PCI device created in a virtualized environment.

[0145] A virtual machine monitor is used to manage and run virtual machines.

[0146] The configuration space of the virtual device is used to record the configuration information of the virtual device. The configuration space can be understood as a memory area used to record and configure the properties, functions and operations of the virtual PCI device.

[0147] The access address can be understood as the address for accessing the configuration space of the virtual device.

[0148] It is understandable that the virtual processor can access the configuration space by accessing the access address of the virtual device configuration space, and perform read and write operations on the configuration parameters of the configuration space.

[0149] The simulation operation corresponding to the access address performed by the virtual machine monitor can be understood as switching from kernel mode to user mode, thereby performing simulated read and write operations on the configuration space in the user mode.

[0150] The simulation mode corresponding to the configuration space may include executing the switching between the kernel state and the user state to perform the simulated read and write operations in the user state, and not executing the switching between the kernel state and the user state to perform the simulated read and write operations in the kernel state.

[0151] In an embodiment of the present application, when accessing the access address of the virtual device configuration space, the virtual processor can determine whether the virtual machine monitor needs to perform simulated read and write operations, that is, determine whether it is necessary to perform a switching operation between the kernel state and the user state by determining the simulation mode corresponding to the configuration space. If the simulation mode indicates that a switching operation needs to be performed between the kernel state and the user state, the virtual machine monitor performs simulation, switches from the kernel state to the user state, and performs simulated read and write operations on the configuration space in the user state. If the simulation mode indicates that a switching operation does not need to be performed between the kernel state and the user state, the virtual processor directly performs simulated read and write operations on the configuration space in the kernel state, thereby reducing the switching between the kernel state and the user state, and further reducing unnecessary simulation overhead.

[0152] The application scenarios of the above-mentioned device access system provided in the embodiments of the present application may include but are not limited to application scenarios involving access to virtual device configuration space in the fields of e-commerce services, educational services, legal services, medical services, conference services, social network services, financial product services, logistics services and navigation services, for example: scenarios of accessing virtual device configuration space in e-commerce services, scenarios of accessing virtual device configuration space in academic services, scenarios of accessing virtual device configuration space in medical services, etc., which are not limited here.

[0153] The device access system of the embodiment of the present application can determine whether it is necessary to switch from kernel state to user state to perform simulated read and write operations when a virtual processor accesses the virtual device configuration space. This can reduce the switching between kernel state and user state when there is no need to perform the switching operation between kernel state and user state, thereby achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art that when a virtual central processing unit reads and writes the configuration space of a virtual peripheral component interconnect device, it will exit to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions and resulting in high simulation overhead.

[0154] In an optional embodiment, the device accesses a virtual processor in the system, and is also used to perform field parsing on the access address to obtain preset field content, and determine the simulation method corresponding to the configuration space based on the preset field content, wherein the preset field content is used to determine whether to perform content read and write operations on the configuration space through a user-mode simulation method.

[0155] It is understandable that whether the configuration space of a virtual device does not need to switch between kernel mode and user mode, that is, whether it does not need to perform content read and write operations through user mode simulation, depends on the simulation of each virtual device. Because the reading and writing of the Base Address Registers field in the configuration space of some virtual devices requires user mode simulation, such as establishing a memory mapping that the virtual machine can directly read and write, creating a virtual MSIX interrupt table, etc., while the reading and writing of the Base Address Registers field in the configuration space of other virtual devices has no specific meaning, so no simulation is required.

[0156] Therefore, the preset field content can be the field content in the configuration space, such as the Base Address Registers field content. Based on the preset field content, it can be determined whether it is necessary to perform content read and write operations on the configuration space through user mode simulation, that is, it can be determined whether it is necessary to perform a kernel mode and user mode switching operation.

[0157] By performing field parsing on the access address of the configuration space, the preset field content can be determined, and based on the preset field content, the simulation method corresponding to the configuration space can be determined, so as to reasonably access the configuration space to avoid unnecessary simulation overhead.

[0158] It should be noted that the preferred implementation of this embodiment can refer to the relevant description in Example 1, which will not be repeated here.

[0159] Example 4

[0160] According to an embodiment of the present application, a device embodiment for implementing the above-mentioned access to the virtual device configuration space is also provided. Figure 7 is a schematic diagram of a structure of an apparatus for accessing a virtual device configuration space according to Embodiment 4 of the present application, such as Figure 7 As shown, the device comprises:

[0161] An acquisition module 701 acquires an access address, wherein the access address is used to access a configuration space of a virtual device through a virtual processor thread;

[0162] A determination module 702 determines a simulation mode corresponding to the configuration space based on the access address, wherein the simulation mode is used to determine whether to simulate a read and write operation on the content of the configuration space through a state transition between a kernel state and a user state;

[0163] The access module 703 accesses the configuration space in a simulation manner.

[0164] Optionally, the above-mentioned determination module 702 is also used to: perform field parsing on the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read and write operations on the configuration space through user-mode simulation; based on the preset field content, determine the simulation method corresponding to the configuration space.

[0165] Optionally, the determination module 702 is further used to: in response to determining through preset field content that there is no need to perform content read and write operations on the configuration space through user mode simulation, determine that the simulation mode corresponding to the configuration space is to simulate content read and write operations on the configuration space in kernel mode.

[0166] Optionally, the determination module 702 is further configured to: in response to the simulation mode being to simulate the read and write operations on the contents of the configuration space in the kernel state, access the configuration space in the kernel state.

[0167] Optionally, it also includes: a first return module, which is used to return to the virtual machine running environment to execute subsequent operation instructions in response to the completion of the content read and write operation of the configuration space.

[0168] Optionally, the determination module 702 is further used to: in response to determining through preset field content that content read and write operations are performed on the configuration space through user mode simulation, determine that the simulation mode corresponding to the configuration space is to simulate content read and write operations on the configuration space in user mode.

[0169] Optionally, the access module 703 is also used to: in response to the simulation mode being to simulate the read and write operations on the content of the configuration space in the user state, switch from the kernel state to the user state; simulate the virtual device in the user state to perform the read and write operations on the content of the configuration space to obtain the read and write results, wherein the read and write results are used to record the content reading results or content modification results of the configuration space.

[0170] Optionally, it also includes: a second return module, which is used to: execute corresponding simulation actions based on the read and write results; in response to the completion of the simulation action, switch back from user mode to kernel mode; in kernel mode, return to the virtual machine operating environment to execute subsequent operation instructions.

[0171] Optionally, the configuration space is used to record configuration information of a virtual device, wherein the configuration information is used to configure properties, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnect device.

[0172] According to the embodiment of the present application, the storage address of the virtual PCI device configuration space to be accessed by the VCPU, that is, the access address, is obtained. According to the access address of the configuration space, it is determined whether it is necessary to perform a switching operation between the kernel state and the user state when performing a read and write access operation on the configuration space, that is, the simulation mode corresponding to the configuration space is determined. Finally, the configuration space is accessed in accordance with the simulation mode, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, so that when the switching operation between the kernel state and the user state is not required, the switching between the kernel state and the user state can be reduced, achieving the technical effect of reducing unnecessary simulation overhead, thereby solving the technical problem that when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnect device in the related art, it will exit to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, and the simulation overhead is high.

[0173] It should be noted that the acquisition module 701, the determination module 702 and the access module 703 correspond to steps S41 to S43 in Example 1, and the three modules and the corresponding steps implement the same instances and application scenarios, but are not limited to the contents disclosed in the above-mentioned Example 1. It should be noted that the above-mentioned modules or units may be hardware components or software components stored in a memory and processed by one or more processors, and the above-mentioned modules may also run in a server.

[0174] According to an embodiment of the present application, another apparatus embodiment for implementing the above-mentioned access to the virtual device configuration space is also provided. Figure 8 is a schematic diagram of the structure of another apparatus for accessing a virtual device configuration space according to Embodiment 4 of the present application, such as Figure 8 As shown, the device comprises:

[0175] An acquisition module 801 acquires an access address, wherein the access address is used to access a configuration space of a virtual device through a virtual processor thread;

[0176] The access module 802 accesses the configuration space in the kernel state in response to determining based on the access address that there is no need to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state.

[0177] By adopting the embodiment of the present application, by obtaining the access address of the configuration space of the virtual device accessed through the virtual processor thread, based on the access address, it is determined that there is no need to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state, and the configuration space is accessed in the kernel state, thereby achieving the purpose of reasonably selecting whether to execute the switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, so that when the switching operation between the kernel state and the user state is not required, the switching between the kernel state and the user state can be reduced, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related technology that when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnect device, it will exit to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions and the simulation overhead is high.

[0178] It should be noted that the acquisition module 801 and the access module 802 correspond to step S61 and step S62 in Example 2, and the examples and application scenarios implemented by the two modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned Example 3. It should be noted that the above-mentioned modules or units may be hardware components or software components stored in a memory and processed by one or more processors, and the above-mentioned modules may also run in a server.

[0179] It should be noted that the preferred implementation scheme involved in the above embodiments of the present application is the same as the scheme provided in Example 1, as well as the application scenario and implementation process, but is not limited to the scheme provided in Example 1.

[0180] Example 5

[0181] The embodiment of the present application may provide a computer terminal, which may be any computer terminal device in a computer terminal group. Optionally, in this embodiment, the computer terminal may also be replaced by a terminal device such as a mobile terminal.

[0182] Optionally, in this embodiment, the computer terminal may be located in at least one network device among a plurality of network devices of the computer network.

[0183] In this embodiment, the above-mentioned computer terminal can execute the program code of the following steps in the device access method: obtaining an access address, wherein the access address is used to access the configuration space of the virtual device through a virtual processor thread; based on the access address, determining the simulation mode corresponding to the configuration space, wherein the simulation mode is used to determine whether to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state; and accessing the configuration space according to the simulation mode.

[0184] Optionally, Fig. 9 is a structural block diagram of a computer terminal according to Embodiment 5 of the present application. Fig. 9 As shown, the computer terminal 9 may include: one or more (only one is shown in the figure) processors 902, a memory 904, a storage controller, and a peripheral interface, wherein the peripheral interface is connected to a radio frequency module, an audio module, and a display.

[0185] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the device access method and apparatus in the embodiment of the present application. The processor executes various functional applications and data processing by running the stored software programs and modules, that is, realizing the above-mentioned device access method. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include a memory remotely arranged relative to the processor, and these remote memories may be connected to the computer terminal 9 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0186] The processor can call the information and application programs stored in the memory through the transmission device to perform the following steps: obtain an access address, wherein the access address is used to access the configuration space of the virtual device through the virtual processor thread; based on the access address, determine the simulation mode corresponding to the configuration space, wherein the simulation mode is used to determine whether to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state; and access the configuration space according to the simulation mode.

[0187] Optionally, the processor may also execute the following program code steps: performing field parsing on the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read and write operations on the configuration space through user-mode simulation; and determining the simulation method corresponding to the configuration space based on the preset field content.

[0188] Optionally, the processor may also execute the following program code: in response to determining through preset field content that there is no need to perform content read and write operations on the configuration space through user-mode simulation, determine that the simulation method corresponding to the configuration space is to simulate content read and write operations on the configuration space in kernel mode.

[0189] Optionally, the processor may further execute program code of the following steps: in response to the simulation mode being to simulate the read and write operations on the content of the configuration space in the kernel state, accessing the configuration space in the kernel state.

[0190] Optionally, the processor may further execute program code of the following steps: in response to completion of the read and write operations of the configuration space content, return to the virtual machine operating environment to execute subsequent operation instructions.

[0191] Optionally, the processor may also execute the following program code: in response to determining through preset field content that content read and write operations are performed on the configuration space through user-mode simulation, determining that the simulation mode corresponding to the configuration space is to simulate content read and write operations on the configuration space in user mode.

[0192] Optionally, the processor may also execute program code of the following steps: in response to the simulation mode being to simulate read and write operations on the contents of the configuration space in user mode, switching from kernel mode to user mode; simulating a virtual device in user mode to perform read and write operations on the contents of the configuration space to obtain read and write results, wherein the read and write results are used to record the content reading results or content modification results of the configuration space.

[0193] Optionally, the processor may also execute the following program code: executing corresponding simulation actions based on the read and write results; switching back from user mode to kernel mode in response to completion of the simulation actions; and returning to the virtual machine operating environment in kernel mode to execute subsequent operation instructions.

[0194] Optionally, the configuration space is used to record configuration information of a virtual device, wherein the configuration information is used to configure properties, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnect device.

[0195] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtain an access address, wherein the access address is used to access the configuration space of the virtual device through the virtual processor thread; in response to determining based on the access address that there is no need to simulate the read and write operations on the content of the configuration space through the state transition between the kernel state and the user state, access the configuration space in the kernel state.

[0196] According to the embodiment of the present application, the storage address of the virtual PCI device configuration space to be accessed by the VCPU, that is, the access address, is obtained. According to the access address of the configuration space, it is determined whether it is necessary to perform a switching operation between the kernel state and the user state when performing a read and write access operation on the configuration space, that is, the simulation mode corresponding to the configuration space is determined. Finally, the configuration space is accessed in accordance with the simulation mode, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, so that when the switching operation between the kernel state and the user state is not required, the switching between the kernel state and the user state can be reduced, achieving the technical effect of reducing unnecessary simulation overhead, thereby solving the technical problem that when the virtual central processing unit reads and writes the configuration space of the virtual peripheral component interconnect device in the related art, it will exit to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, and the simulation overhead is high.

[0197] It can be understood by those skilled in the art that Fig. 9 The structure shown is for illustration only, and the computer terminal 9 may also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, or other terminal devices. Fig. 9 The structure of the electronic device is not limited. For example, the computer terminal 9 may also include Fig. 9 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Fig. 9 Different configurations shown.

[0198] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, and the storage medium may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0199] Example 6

[0200] The embodiment of the present application also provides a computer-readable storage medium. Optionally, in this embodiment, the computer-readable storage medium can be used to store the program code executed by the device access method provided in the first embodiment.

[0201] Optionally, in this embodiment, the computer-readable storage medium may be located in any one of the computer terminals in a computer terminal group in a computer network, or in any one of the mobile terminals in a mobile terminal group.

[0202] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code for performing the following steps: obtaining an access address, wherein the access address is used to access the configuration space of a virtual device through a virtual processor thread; based on the access address, determining a simulation mode corresponding to the configuration space, wherein the simulation mode is used to determine whether to simulate read and write operations on the content of the configuration space through a state transition between kernel state and user state; and accessing the configuration space according to the simulation mode.

[0203] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: performing field parsing on the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read and write operations on the configuration space through user-mode simulation; based on the preset field content, determining the simulation method corresponding to the configuration space.

[0204] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code for executing the following steps: in response to determining through preset field content that there is no need to perform content read and write operations on the configuration space through user-state simulation, determining that the simulation method corresponding to the configuration space is to simulate content read and write operations on the configuration space in kernel state.

[0205] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for executing the following steps: in response to the simulation mode being to simulate read and write operations on the content of the configuration space in kernel mode, accessing the configuration space in kernel mode.

[0206] Optionally, in this embodiment, the computer-readable storage medium is configured to store program codes for executing the following steps: in response to completion of the read and write operations of the configuration space content, returning to the virtual machine operating environment to execute subsequent operation instructions.

[0207] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code for executing the following steps: in response to determining through preset field content that content read and write operations are performed on a configuration space through a user-state simulation method, determining that a simulation method corresponding to the configuration space is to simulate content read and write operations on the configuration space in user state.

[0208] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code for executing the following steps: in response to the simulation mode being to simulate read and write operations on the content of the configuration space in user mode, switching from kernel mode to user mode; simulating a virtual device in user mode to perform read and write operations on the content of the configuration space to obtain read and write results, wherein the read and write results are used to record the content reading results or content modification results of the configuration space.

[0209] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: executing corresponding simulation actions based on the read and write results; in response to completion of the simulation action, switching back from user mode to kernel mode; in kernel mode, returning to the virtual machine operating environment to execute subsequent operation instructions.

[0210] Optionally, in this embodiment, the configuration space is used to record configuration information of the virtual device, wherein the configuration information is used to configure the properties, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnect device.

[0211] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0212] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0213] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0214] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0215] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0216] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.

[0217] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A device access method, characterized in that: include: Obtaining an access address, wherein the access address is used to access a configuration space of a virtual device through a virtual processor thread; Based on the access address, determining a simulation mode corresponding to the configuration space, wherein the simulation mode is used to determine whether to simulate a read and write operation on the content of the configuration space through a state transition between a kernel state and a user state; The configuration space is accessed according to the simulation method.

2. The method according to claim 1, characterized in that Determining, based on the access address, a simulation mode corresponding to the configuration space includes: Performing field parsing on the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read and write operations on the configuration space in a user mode simulation manner; Based on the preset field content, a simulation mode corresponding to the configuration space is determined.

3. The method according to claim 2, characterized in that Determining the simulation mode corresponding to the configuration space based on the preset field content includes: In response to determining through the preset field content that there is no need to perform content read and write operations on the configuration space through the user mode simulation mode, determining that the simulation mode corresponding to the configuration space is to simulate the content read and write operations on the configuration space in the kernel mode.

4. The method according to claim 3, characterized in that According to the simulation method, accessing the configuration space includes: In response to the simulation mode being to simulate the read and write operations on the content of the configuration space in the kernel state, the configuration space is accessed in the kernel state.

5. The method according to claim 4, characterized in that The method further comprises: In response to the completion of the read and write operations of the configuration space, the virtual machine operating environment is returned to execute subsequent operation instructions.

6. The method according to claim 2, characterized in that Determining the simulation mode corresponding to the configuration space based on the preset field content includes: In response to determining, through the preset field content, that the content read and write operation is performed on the configuration space through the user mode simulation mode, it is determined that the simulation mode corresponding to the configuration space is to simulate the content read and write operation on the configuration space in the user mode.

7. The method according to claim 6, characterized in that According to the simulation method, accessing the configuration space includes: In response to the simulation mode being to simulate the read and write operations on the content of the configuration space in the user state, switching from the kernel state to the user state; The virtual device is simulated in the user mode to perform read and write operations on the content of the configuration space to obtain read and write results, wherein the read and write results are used to record content reading results or content modification results of the configuration space.

8. The method according to claim 7, characterized in that The method further comprises: Execute corresponding simulation actions based on the read and write results; In response to completion of the simulation action, switching from the user state back to the kernel state; In the kernel state, return to the virtual machine operating environment to execute subsequent operation instructions.

9. The method according to claim 1, characterized in that: The configuration space is used to record configuration information of the virtual device, wherein the configuration information is used to configure properties, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnect device.

10. A device access method, characterized in that: include: Obtaining an access address, wherein the access address is used to access a configuration space of a virtual device through a virtual processor thread; In response to determining based on the access address that there is no need to simulate a read and write operation on the content of the configuration space through a state transition between a kernel state and a user state, the configuration space is accessed in the kernel state.

11. A device access system, characterized in that: include: Virtual processors, virtual devices, and virtual machine monitors; The virtual machine monitor is used for state transition between kernel state and user state to perform simulation operations corresponding to access addresses, wherein the access addresses are used to access the configuration space of the virtual device; The virtual processor is used to determine the simulation mode corresponding to the configuration space based on the access address, so as to access the configuration space according to the simulation mode.

12. The system according to claim 11, characterized in that The virtual processor is further used to perform field parsing on the access address to obtain preset field content, and to determine a simulation mode corresponding to the configuration space based on the preset field content, wherein the preset field content is used to determine whether to perform content read and write operations on the configuration space through a user-mode simulation mode.

13. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is executed, the device where the computer-readable storage medium is located is controlled to execute the device access method according to any one of claims 1 to 10.

14. An electronic device, characterized in that: include: A memory storing an executable program; A processor, configured to run the program, wherein the program executes the device access method according to any one of claims 1 to 10 when running.

Citation Information

Patent Citations

  • Method and device for processing read / write request in physical host

    CN106201349A

  • Application program-oriented privileged hardware resource access method and electronic equipment

    CN111737656A

  • Access address tracking method and equipment of PCI device, and computer readable storage medium

    CN114064212A

  • Computer equipment, exception processing method and interrupt processing method

    CN114077379A

  • Para-virtualization equipment configuration space direct access method and device, equipment and medium

    CN115658222A