Device access method, storage medium, and electronic device
By determining the simulation method for the virtual central processing unit to access the configuration space of the virtual peripheral interconnect device in the virtualization scenario, unnecessary switching between kernel mode and user mode is avoided, the problem of high simulation overhead of the virtual machine monitor is solved, and more efficient access is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HANGZHOU ALICLOUD FEITIAN INFORMATION TECH CO LTD
- Filing Date
- 2023-09-22
- Publication Date
- 2026-05-12
AI Technical Summary
In a virtualization scenario, when the virtual central processing unit reads or writes the configuration space of the virtual peripheral interconnect device, it needs to exit to the virtual machine monitor for simulation, which causes the virtual machine monitor to perform additional simulation actions and increases simulation overhead.
By obtaining the access address, it can be determined whether a switch operation needs to be performed between kernel mode and user mode. The appropriate simulation method can be selected to directly access the configuration space in kernel mode, avoiding unnecessary state transitions.
It reduces the switching between kernel mode and user mode, lowers unnecessary emulation overhead, and improves access performance and efficiency.
Smart Images

Figure CN119690865B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a device access method, a storage medium, and an electronic device. Background Technology
[0002] Virtualization technology abstracts physical resources into virtual resources, enabling multiple virtual environments to share physical resources. In a virtualization scenario, when a Virtual Central Processing Unit (VCPU) reads or writes the configuration space of a Virtual Peripheral Component Interconnect (PCI) device, it typically exits to the Hypervisor for simulation. During this simulation process, the relatively long simulation path may require switching between kernel mode and user mode, allowing the Hypervisor to obtain higher privilege levels when needed and monitor and control the virtual machines. However, this approach results in the Hypervisor performing additional simulation actions, increasing the simulation overhead at the Hypervisor layer.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] This application provides a device access method, storage medium, and electronic device to at least solve the technical problem in the related art where, when a virtual central processing unit reads or writes the configuration space of a virtual peripheral interconnect device, it exits to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, resulting in high simulation overhead.
[0005] According to one aspect of the embodiments of this application, a device access method is provided, comprising: obtaining an access address, wherein the access address is used to access the configuration space of a virtual device through a virtual processor thread; 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 read and write operations on the contents of the configuration space through state transition between kernel mode and user mode; and accessing the configuration space according to the simulation mode.
[0006] According to another aspect of the embodiments of this 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; and responding to determine, based on the access address, that the configuration space can be accessed in kernel mode without simulating read / write operations on the contents of the configuration space through state transitions between kernel mode and user mode.
[0007] According to another aspect of the embodiments of this 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 for state transitions between kernel mode and user mode to execute a simulation operation 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 method corresponding to the configuration space based on the access address, so as to access the configuration space according to the simulation method.
[0008] According to another aspect of the embodiments of this 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, it controls the device where the computer-readable storage medium is located to perform any of the above-described device access methods.
[0009] According to another aspect of the embodiments of this application, an electronic device is also provided, including: a memory storing an executable program; and a processor for running the program, wherein the program executes any of the above-described device access methods during runtime.
[0010] In this embodiment, the storage address (i.e., the access address) of the virtual PCI device configuration space to be accessed by the VCPU is obtained. Based on the access address, it is determined whether a switch between kernel mode and user mode is required when performing read / write access operations on the configuration space, thus determining the corresponding simulation mode for that configuration space. Finally, the configuration space is accessed according to the simulation mode. This achieves the goal of rationally selecting whether to perform a switch between kernel mode and user mode when accessing the virtual PCI device configuration space. This reduces the need for kernel-user mode switching, thereby reducing unnecessary simulation overhead. Furthermore, it solves the technical problem in related technologies where the virtual CPU exits to the virtual machine monitor for simulation when reading or writing the configuration space of the virtual peripheral interconnect device, causing the virtual machine monitor to perform additional simulation actions and resulting in high simulation overhead.
[0011] It is worth noting that the general description above and the detailed description that follow are merely for illustrative purposes and do not constitute a limitation on this application. Attached Figure Description
[0012] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0013] Figure 1 This is a schematic diagram of the PCI device configuration space in related technologies;
[0014] Figure 2 This is a flowchart of accessing the configuration space of a virtual PCI device in related technologies;
[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 this application;
[0016] Figure 4 This is a flowchart of a device access method according to Embodiment 1 of this application;
[0017] Figure 5 This is a flowchart of another device access method according to Embodiment 1 of this application;
[0018] Figure 6 This is a flowchart of a device access method according to Embodiment 2 of this application;
[0019] Figure 7 This is a schematic diagram of a device for accessing a virtual device configuration space according to Embodiment 4 of this application;
[0020] Figure 8 This is a schematic diagram of another device for accessing virtual device configuration space according to Embodiment 4 of this application;
[0021] Figure 9 This is a structural block diagram of a computer terminal according to Embodiment 5 of this application. Detailed Implementation
[0022] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort 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, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0024] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows:
[0025] Virtual Central Processing Unit (VCPU): In a virtualization scenario, a virtual processor refers to a logical processor simulated within a virtual machine. A virtual processor is implemented by virtualization software (such as a virtual machine monitor) that partitions and allocates the computing resources of a physical processor to multiple virtual machines. In this embodiment, the virtual central processing unit is also referred to as a virtual processor, denoted as VCPU.
[0026] A hypervisor is software used to create, run, and manage virtual machines (VMs). Its main functions include resource management, VM creation, destruction, and management, and communication and data transfer between VMs and the physical computer. Hypervisors create a virtualization layer on the physical computer, dividing the computer's hardware resources (such as processors, memory, and storage) into multiple VMs and providing each VM with an independent virtual hardware environment.
[0027] Guest context and Host context are two concepts used in virtualization environments to describe the different execution environments between a virtual machine (Guest) and a host machine. The Guest context refers to the state and environment of the virtual machine running in its own execution environment, while the Host context refers to the execution environment of the operating system and virtualization software running on the host machine (i.e., the physical machine running the virtual machine). For example, when the host Central Processing Unit (CPU) is executing the virtual machine's code, it is in the Guest context; when the host CPU is executing the host's code, it is in the Host context. Through these two contexts, the virtualization environment achieves the isolation and management of virtual machines.
[0028] Fast path: Also known as a fast forwarding path, this refers to the path taken by network devices (such as switches and routers) to quickly forward data packets from input ports to output ports by directly using known routing information. Fast paths typically consist of the optimal path between network devices and routers to reduce latency and packet loss during transmission, providing faster speeds and more stable connection quality.
[0029] Kernel mode: refers to the operating system running in privileged mode, possessing the highest level of privileges and the ability to access system resources. In kernel mode, the operating system can execute privileged instructions, access all memory space and devices, and directly control and manage hardware.
[0030] User mode refers to the non-privileged mode in which applications or user code can only access limited resources. In user mode, applications cannot directly access hardware devices and system resources; instead, they request services from kernel mode through system calls. A system call is a special function call used to switch to kernel mode, execute relevant kernel code, and return the result to user mode.
[0031] By dividing the functions and permissions of the operating system into kernel mode and user mode, the security and stability of the system can be effectively protected. Kernel mode has higher privileges and more system resources, used to manage and control the entire system. User mode, on the other hand, can only access limited resources to ensure isolation and security between applications.
[0032] Peripheral Component Interconnect (PCI) devices: These are devices that use the PCI bus interface. PCI devices have three address spaces: memory address space, input / output (I / O) address space, and configuration space.
[0033] The PCI device's configuration space is a specific memory area within the PCI device used to describe and configure the device's attributes, functions, and operations. The configuration space contains various attributes and configuration registers for the PCI device. These registers include the device's identifier (ID), device ID, device category and subcategory, interrupt number, I / O resource allocation, memory resource allocation, interrupt lines, etc. By accessing the PCI device's configuration space, the device's configuration information can be read and modified. In this embodiment, "PCI device" broadly refers to PCI devices and Peripheral Component Interconnect Express (PCIE) devices.
[0034] Figure 1 This is a schematic diagram of the PCI device configuration space in related technologies, such as... Figure 1As shown, the PCI device configuration space includes: Device ID, Vendor ID, Status, Command, ClassCode, 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 fields, Capabilities Pointer, Max_Lat, Min_Gnt, Interrupt Pin, and IRQ Line.
[0035] The Device ID identifies the device's model or type, and its parameters are assigned by the device manufacturer. The Vendor ID identifies the device's manufacturer, and its parameters are assigned by the PCI device manufacturer.
[0036] Status is used to reflect the current status of the device.
[0037] Commands are used to control certain behaviors of a device, such as enabling the device or enabling interrupts.
[0038] Class Code is used to describe the type and function of a device.
[0039] Revision ID is used to identify the version information of a device.
[0040] BIST is a feature in the PCI device configuration space used for self-testing and self-detection.
[0041] The header type is used to identify the configuration space type of the device.
[0042] The Latency timer is used to set the delay time for the device to respond to the host.
[0043] The 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 regions, or other resources used by a device.
[0045] Cardbus Address Registers are a set of registers in the PCI device configuration space 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] The Expansion ROM Base Address is used to specify the base address of the device's extended ROM.
[0048] Extended ROM is a type of firmware stored on a device that can contain device drivers, BIOS extensions, etc. This field specifies the starting address of the extended ROM in physical memory.
[0049] Reserved refers to fields in the PCI device configuration space that are reserved for future specification extensions or other purposes.
[0050] Capabilities Pointer is used to indicate the location of expansion capability structures in the device configuration space.
[0051] Max_Lat is an 8-bit field that indicates the maximum time a PCI device needs to occupy the bus in order to complete the currently executing transaction.
[0052] Min_Gnt is an 8-bit field used to indicate the minimum time a PCI device must release the bus.
[0053] The IRQ Pin is a 4-bit field used to indicate the number of interrupt pins used by a PCI device.
[0054] IRQ Line is used to indicate the number of the interrupt request line used by the device.
[0055] Figure 2 This is a flowchart of accessing the configuration space of a virtual PCI device in related technologies, such as... Figure 2 As shown, VCPU accesses the configuration space of virtual PCI devices by reading and writing specific memory addresses. When accessing the configuration space of virtual PCI devices, VCPU usually exits to the Hypervisor for simulation, that is, VCPU switches to Hypervisor user mode.
[0056] In user space, the corresponding virtual PCI device processing callback function can be found based on the address accessed by the VCPU. By executing this function, read and write operations are simulated to process the configuration space of the virtual PCI device accordingly.
[0057] After the user-mode emulation is complete, the VCPU switches back to kernel mode and executes some common processing flows 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, thereby completing the read and write operations on the virtual PCI device's configuration space.
[0058] The methods for accessing the configuration space of virtual PCI devices in related technologies have the following drawbacks.
[0059] Defect 1: Since most read and write operations in the virtual PCI device's configuration space are simply modification or retrieval of content, the Hypervisor does not need to perform additional emulation actions. In related technologies, switching between kernel mode and user mode is performed when reading and writing to the virtual PCI device's configuration space, which causes the Hypervisor to perform additional emulation actions, thereby increasing the emulation overhead of the Hypervisor layer.
[0060] To address the aforementioned deficiencies, no effective solution has been proposed prior to this application.
[0061] Example 1
[0062] According to an embodiment of this application, a device access method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0063] The method embodiment provided in Embodiment 1 of this application can be executed on a mobile terminal, computer terminal, or similar computing device. Figure 3 A hardware block diagram of a computer terminal (or mobile device) for implementing a device access method is shown. Figure 3As shown, the computer terminal 30 (or mobile device) may include one or more processors 302 (shown as 302a, 302b, ..., 302n in the figure) (processor 302 may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.), 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 a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 3 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, computer terminal 30 may also include... Figure 3 The more or fewer components shown, or having the same Figure 3 The different configurations shown.
[0064] It should be noted that the aforementioned one or more processors 302 and / or other data processing circuits are generally referred to herein as "data processing circuits". These data processing circuits may be embodied, in whole or in part, in software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuits may be a single, independent processing module, or may be integrated, in whole or in part, into any other element within the computer terminal 30 (or mobile device). As involved in the embodiments of this application, the data processing circuits serve as a processor control mechanism (e.g., selection of a variable resistor termination path connected to an interface).
[0065] The memory 304 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the device access method in this embodiment. The processor 302 executes various functional applications and data processing by running the software programs and modules stored in the memory 304, thereby realizing the aforementioned device access method. The memory 304 may include high-speed random access memory, and may also include 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 304 may further include memory remotely located relative to the processor 302, and these remote memories can be connected to the computer terminal 30 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0066] The transmission device 306 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 30. In one example, the transmission device 306 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 306 may be a Radio Frequency (RF) module, used for wireless communication with the Internet.
[0067] The display may be, for example, a touchscreen liquid crystal display (LCD) that allows the user to interact with the user interface of the computer terminal 30 (or mobile device).
[0068] Under the aforementioned operating environment, this application provides the following: Figure 4 The device access method is shown. Figure 4 This is a flowchart of a device access method according to Embodiment 1 of this application. Figure 4 As shown, the method may include the following steps:
[0069] Step S41, obtain the 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: Based on the access address, determine the simulation method corresponding to the configuration space. The simulation method is used to determine whether to simulate read and write operations on the configuration space through state transition between kernel mode and user mode.
[0071] Step S43: Access the configuration space in a simulated 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] A virtual device can be understood as a virtual PCI device or a virtual PCIE device, and this is not a limitation. In this embodiment, a virtual PCI device is used as an example for illustration.
[0074] The configuration space is used to record the configuration information of virtual devices. The configuration space can be understood as a memory area used to record and configure the attributes, functions and operations of virtual PCI devices.
[0075] For example, the attributes of a virtual PCI device may include a virtual PCI device type and a virtual PCI device identifier, wherein the virtual PCI device type is used to indicate the various types of PCI devices emulated by the virtual PCI device, including network adapters, storage controllers, graphics cards, etc. The virtual PCI device identifier is used to uniquely identify the device in the virtualization environment.
[0076] The functions of a virtual PCI device include all the functions that a virtual PCI device simulates in a real PCI device, such as data transfer, interrupt handling, DMA control, etc.
[0077] Operations on virtual PCI devices include: configuring the virtual PCI device (e.g., setting the configuration space of the virtual PCI device), initializing the virtual PCI device (e.g., initializing the device's registers, interrupts, and DMA settings), reading the configuration space of the virtual PCI device (e.g., obtaining relevant device information such as vendor ID, device ID, device class code, interrupt number, and resource allocation), writing to the configuration space of the virtual PCI device (e.g., modifying relevant device configurations such as interrupt number and resource allocation), reading and writing the registers of the virtual PCI device (e.g., implementing device control and configuration, such as opening / closing the device and setting the device status), performing DMA operations on the virtual PCI device (e.g., implementing data transfer and exchange), and responding to interrupts of the virtual PCI device (e.g., interrupt handling and execution of interrupt service routines).
[0078] In a virtualization scenario, virtual processor threads can read and modify device configuration parameters, such as interrupt enable, data transfer mode, and device address, by reading and writing registers in the configuration space. Through access to the configuration space, virtual processor threads can initialize, configure, and manage virtual devices.
[0079] Simulation methods can be understood as various read / write methods used by the VCPU to read or modify configuration parameters in the configuration space when accessing the access address of the configuration space. In this embodiment, for example, simulation methods may include switching between kernel mode and user mode to simulate read / write operations. Simulation methods may also include not switching between kernel mode and user mode, thus directly performing read / write operations in kernel mode.
[0080] It is understandable that when accessing the configuration space of a virtual PCI device, it may be necessary to perform a switching operation between kernel mode and user mode to simulate content read and write operations. However, performing the switching operation between kernel mode and user mode will increase the simulation overhead.
[0081] Therefore, in this embodiment, determining the simulation method corresponding to the configuration space can be understood as determining whether a switching operation between kernel mode and user mode is needed when accessing the configuration space. Based on the access address, it can be determined whether a switching operation between kernel mode and user mode is needed when the VCPU accesses the configuration space corresponding to that access address. This allows for the reasonable selection of the corresponding simulation method. When a switching operation is not needed, the switching between kernel mode and user mode can be reduced, thereby reducing unnecessary simulation overhead.
[0082] In this embodiment, the storage address (i.e., the access address) of the virtual PCI device configuration space to be accessed by the VCPU is obtained. Based on the access address of the configuration space, it is determined whether a switch between kernel mode and user mode is required when performing read / write access operations on the configuration space, i.e., the corresponding simulation method for the configuration space is determined. Finally, the configuration space is accessed according to the simulation method, thereby reducing the switching between kernel mode and user mode when no switch between kernel mode and user mode is required, and thus reducing unnecessary simulation overhead.
[0083] The device access method provided in this application embodiment can be applied, but is not limited to, to application scenarios involving access to virtual device configuration space in fields such as e-commerce services, education services, legal services, medical services, conference services, social networking services, financial product services, logistics services, and navigation services. For example, scenarios involving access to virtual device configuration space in e-commerce services, scenarios involving access to virtual device configuration space in academic services, scenarios involving access to virtual device configuration space in medical services, etc., are not limited here.
[0084] In this embodiment, the storage address (i.e., the access address) of the configuration space of the virtual PCI device to be accessed by the VCPU is obtained. Based on the access address, it is determined whether a switch between kernel mode and user mode is required when performing read / write access operations on the configuration space, thus determining the corresponding simulation mode for that configuration space. Finally, the configuration space is accessed according to the simulation mode. This achieves the goal of rationally selecting whether to perform a switch between kernel mode and user mode when accessing the virtual PCI device configuration space. This reduces the need for kernel-user mode switching, thereby reducing unnecessary simulation overhead. Furthermore, it solves the technical problem in related technologies where, when the virtual CPU reads or writes the configuration space of the virtual peripheral interconnect device, it exits to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, resulting in high simulation overhead.
[0085] In an optional embodiment, in step S42, the simulation method corresponding to the configuration space is determined based on the access address, including the following method steps:
[0086] Step S421: Parse the access address to obtain 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 user-mode simulation.
[0087] Step S422: Based on the preset field content, determine the simulation method corresponding to the configuration space.
[0088] Understandably, whether the configuration space of a virtual PCI device does not require user-mode emulation for content read / write operations depends on the emulation details of each virtual PCI device. Some virtual PCI devices require user-mode emulation for reading and writing the Base Address Registers field, such as establishing memory mappings that the virtual machine can directly read and write, or creating virtual MSIX interrupt tables. Other virtual PCI devices, however, do not require emulation for reading and writing the Base Address Registers field because it has no specific meaning.
[0089] Therefore, the preset field content can be the content of fields 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, whether it is necessary to perform a switch operation between kernel mode and user mode.
[0090] By parsing the access address of the configuration space, the content of preset fields can be determined. Based on the content of these preset fields, the simulation method corresponding to the configuration space can be determined, so as to access the configuration space reasonably and avoid unnecessary simulation overhead.
[0091] In an optional embodiment, in step S422, the simulation method corresponding to the configuration space is determined based on the preset field content, including the following method steps:
[0092] Step S4221: The response determines, through the content of the preset field, that there is no need to perform content read / write operations on the configuration space through user-mode simulation, and determines that the simulation method corresponding to the configuration space is to simulate content read / write operations on the configuration space in 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. The simulation method of the configuration space that only requires reading and writing the configuration space content and does not require additional simulation operations is determined to be accessible in kernel mode, that is, the simulation method is one that does not require simulated read and write operations through user mode simulation.
[0094] If, based on the preset field content, it is determined that no switching operation between kernel mode and user mode is required, i.e., no switching to user mode for simulation is necessary, then this access to the configuration space can be performed in kernel mode. Therefore, the simulation method corresponding to this configuration space is determined to be performing read and write operations on the configuration space in kernel mode, thereby avoiding unnecessary simulation overhead.
[0095] Optionally, in kernel mode, read and write operations on the configuration space can be performed using the fast path, thereby enabling faster data transfer and improving the performance and efficiency of read and write access. For example, if the configuration space address of a virtual PCI device is base, and only operations on the Base Address Registers are simulated, then both [base,base+0x10) and [base+0x28,base+0x3c) can use the fast path.
[0096] In an optional embodiment, in step S43, the configuration space is accessed in a simulated manner, including the following method steps:
[0097] Step S431: In response to the simulation mode being to simulate read and write operations on the configuration space in kernel mode, the configuration space is accessed in kernel mode.
[0098] For example, when the simulation method is determined to be simulating read and write operations on the configuration space in kernel mode, the read and write operations can be performed by taking the fast path in kernel mode.
[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 / write operation of the configuration space, return to the virtual machine runtime environment to execute subsequent operation instructions.
[0101] Returning to the virtual machine runtime environment can be understood as returning to the Guest context, so that the next instruction can be executed.
[0102] After performing read and write operations on the configuration space in a simulated manner, you can return to the Guest context and continue executing the next instruction.
[0103] In an optional embodiment, in step S422, the simulation method corresponding to the configuration space is determined based on the preset field content, including the following method steps:
[0104] Step S4222: The response determines, through the content of the preset field, that the configuration space is simulated to perform content read and write operations in user mode, and determines that the simulation method corresponding to the configuration space is to simulate content read and write operations in user mode.
[0105] If the preset field content determines that a switch between kernel mode and user mode is required, i.e., a switch to user mode for simulation, then this access to the configuration space can be performed in user mode. Therefore, the simulation method corresponding to this configuration space is determined to be performing read and write operations on the configuration space in 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 simulated manner, including the following method steps:
[0107] Step S431: In response to the simulation mode being to simulate read and write operations on the configuration space in user mode, switch from kernel mode to user mode;
[0108] Step S432: Simulate a virtual device in user mode to perform read and write operations on the configuration space and obtain read and write results. The read and write results are used to record the content reading results or content modification results of the configuration space.
[0109] For example, when the simulation mode is determined to be simulating read and write operations on the configuration space in user mode, the kernel mode is switched to user mode, so that in user mode, the read and write operations on the configuration space are performed by simulating a virtual PCI device, thereby obtaining read and write results for recording the content read 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: Execute the corresponding simulated action based on the read / write result;
[0112] Step S434: In response to the completion of the simulation action, switch back from user mode to kernel mode;
[0113] Step S435: In kernel mode, return to the virtual machine runtime environment to execute subsequent operation instructions.
[0114] In user mode, read and write operations on the configuration space are performed. After obtaining the results, corresponding simulated actions can be executed based on these results, such as virtual interrupt simulation or device reset. After the simulated actions are 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 flowchart of another device access method according to Embodiment 1 of this application.
[0116] The VCPU accesses the configuration space of a virtual PCI device by reading and writing to specific memory addresses. When accessing the configuration space of a virtual PCI device, the VCPU first determines whether a fast path can be used, i.e., whether a switch between kernel mode and user mode is required. If a fast path can be used, no switch is performed, and the read / write operations on the virtual PCI device are performed in kernel mode. After the read / write operations are completed, the VCPU returns to the Guest context to execute subsequent operation instructions.
[0117] If it is determined that the fast path cannot be used, a switch operation is performed, switching from kernel mode to user mode. In user mode, the corresponding virtual PCI device handling callback function can be found based on the address accessed by the VCPU. By executing this function, read and write operations are simulated to process the configuration space of the virtual PCI device accordingly. The virtual PCI device handling callback function may perform different simulated operations for different configuration space access addresses, such as simulating interrupts or device resets.
[0118] After the user-mode simulation is complete, the VCPU switches back to kernel mode and executes some common processing flows 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, thereby completing the read and write operations on the virtual PCI device's configuration space.
[0119] It is easy to understand that the beneficial effects of the device access method provided in this application include the following points.
[0120] Beneficial effect (1): By determining whether the fast path can be taken, virtual PCI devices that can access the configuration space through the fast path can perform read and write access operations on the configuration space in kernel mode. That is, the virtual PCI device configuration space is partially simulated without going through the common simulation process of the virtualization layer, thereby reducing the switching operation between kernel mode and user mode, reducing the overhead of the virtualization layer, and thus saving CPU resources.
[0121] Beneficial effect (2): By taking the fast read path to perform read and write access operations on the configuration space, data transmission can be performed quickly, improving the performance and efficiency of read and write access, thereby improving the virtual machine's access performance to the virtual PCI device configuration space.
[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, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0123] Furthermore, it should be noted that, for the sake of simplicity, the aforementioned method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Secondly, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0124] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, they can also be implemented by hardware. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0125] Example 2
[0126] In the operating environment as described in Example 1, this application provides as follows: Figure 6 The method shown is a device access method. Figure 6 This is a flowchart of a device access method according to Embodiment 2 of this application, as follows: Figure 6 As shown, the method includes:
[0127] Step S61: Obtain the 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: The response determines that there is no need to simulate read / write operations on the configuration space through state transitions between kernel mode and user mode based on the access address, and the configuration space is accessed in kernel mode.
[0129] 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, which is used to access the configuration space of the virtual device through the virtual processor thread in the virtualization scenario.
[0130] A virtual device can be understood as a virtual PCI device or a virtual PCIE device, and this is not a limitation. In this embodiment, a virtual PCI device is used as an example for illustration.
[0131] The configuration space is used to record the configuration information of virtual devices. The configuration space can be understood as a memory area used to record and configure the attributes, functions and operations of virtual PCI devices.
[0132] For example, the attributes of a virtual PCI device may include a virtual PCI device type and a virtual PCI device identifier, wherein the virtual PCI device type is used to indicate the various types of PCI devices emulated by the virtual PCI device, including network adapters, storage controllers, graphics cards, etc. The virtual PCI device identifier is used to uniquely identify the device in the virtualization environment.
[0133] The functions of a virtual PCI device include all the functions that a virtual PCI device simulates in a real PCI device, such as data transfer, interrupt handling, DMA control, etc.
[0134] Operations on virtual PCI devices include: configuring the virtual PCI device (e.g., setting the configuration space of the virtual PCI device), initializing the virtual PCI device (e.g., initializing the device's registers, interrupts, and DMA settings), reading the configuration space of the virtual PCI device (e.g., obtaining relevant device information such as vendor ID, device ID, device class code, interrupt number, and resource allocation), writing to the configuration space of the virtual PCI device (e.g., modifying relevant device configurations such as interrupt number and resource allocation), reading and writing the registers of the virtual PCI device (e.g., implementing device control and configuration, such as opening / closing the device and setting the device status), performing DMA operations on the virtual PCI device (e.g., implementing data transfer and exchange), and responding to interrupts of the virtual PCI device (e.g., interrupt handling and execution of interrupt service routines).
[0135] In a virtualization scenario, virtual processor threads can read and modify device configuration parameters, such as interrupt enable, data transfer mode, and device address, by reading and writing registers in the configuration space. Through access to the configuration space, virtual processor threads can initialize, configure, and manage virtual devices.
[0136] Based on the access address, it can be determined whether the VCPU needs to perform a switch operation between kernel mode and user mode when accessing the configuration space corresponding to the access address. This allows for a reasonable selection of whether to perform the switch operation based on simulation. When a switch operation is not required, the switching between kernel mode and user mode 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 read and write operations on the configuration space through state transitions between kernel mode and user mode, then accessing the configuration space in kernel mode can avoid unnecessary simulation overhead.
[0138] The device access method provided in this application embodiment can be applied, but is not limited to, to application scenarios involving access to virtual device configuration space in fields such as e-commerce services, education services, legal services, medical services, conference services, social networking services, financial product services, logistics services, and navigation services. For example, scenarios involving access to virtual device configuration space in e-commerce services, scenarios involving access to virtual device configuration space in academic services, scenarios involving access to virtual device configuration space in medical services, etc., are not limited here.
[0139] By employing the embodiments of this application, the access address of the configuration space of the virtual device accessed through the virtual processor thread is obtained. Based on the access address, it is determined that when there is no need to simulate read / write operations on the configuration space through state transitions between kernel mode and user mode, the configuration space is accessed in kernel mode. This achieves the purpose of reasonably selecting whether to perform kernel mode and user mode switching operations when accessing the configuration space of the virtual PCI device. Thus, when it is not necessary to perform kernel mode and user mode switching operations, the switching between kernel mode and user mode is reduced, achieving the technical effect of reducing unnecessary simulation overhead. This solves the technical problem in related technologies where when the virtual central processing unit reads or writes the configuration space of the virtual peripheral interconnect device, it exits to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, resulting in high simulation overhead.
[0140] It should be noted that the preferred implementation of this embodiment can be found in the relevant description in Embodiment 1, and will not be repeated here.
[0141] Example 3
[0142] In the operating environment described in Example 1, this 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 for state transitions between kernel mode and user mode to execute 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 method corresponding to the configuration space based on the access addresses, so as to access the configuration space according to the simulation method.
[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] Virtual machine monitors are used to manage and run virtual machines.
[0146] The configuration space of a 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 attributes, functions and operations of the virtual PCI device.
[0147] An access address can be understood as the address for accessing the configuration space of a virtual device.
[0148] It is understandable that a virtual processor can access the configuration space by accessing the access address of the virtual device configuration space, and thus perform read and write operations on the configuration parameters of the configuration space.
[0149] The simulated operation corresponding to the access address executed 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 user mode.
[0150] The simulation methods corresponding to the configuration space can include switching between kernel mode and user mode to perform simulated read and write operations in user mode, or not switching between kernel mode and user mode to perform simulated read and write operations in kernel mode.
[0151] In this embodiment, when the virtual processor accesses the access address of the virtual device configuration space, it can determine whether the virtual machine monitor needs to perform simulated read / write operations, i.e., whether a switch between kernel mode and user mode is required, by determining the simulation mode corresponding to the configuration space. If the simulation mode indicates that a switch between kernel mode and user mode is required, the virtual machine monitor performs the simulation, switching from kernel mode to user mode, and performing simulated read / write operations on the configuration space in user mode. If the simulation mode indicates that a switch between kernel mode and user mode is not required, the virtual processor directly performs simulated read / write operations on the configuration space in kernel mode, thereby reducing the switch between kernel mode and user mode and thus reducing unnecessary simulation overhead.
[0152] The application scenarios of the device access system provided in this application embodiment may include, but are not limited to, application scenarios involving access to virtual device configuration space in fields such as e-commerce services, education services, legal services, medical services, conference services, social networking services, financial product services, logistics services, and navigation services. For example, scenarios involving access to virtual device configuration space in e-commerce services, scenarios involving access to virtual device configuration space in academic services, scenarios involving access to virtual device configuration space in medical services, etc., are not limited here.
[0153] The device access system using the embodiments of this application can determine whether it is necessary to switch from kernel mode to user mode to perform simulated read and write operations when the virtual processor accesses the configuration space of the virtual device. This reduces the switching between kernel mode and user mode when it is not necessary to perform kernel mode and user mode switching operations, thereby achieving the technical effect of reducing unnecessary simulation overhead. This solves the technical problem in related technologies where when the virtual central processing unit reads and writes the configuration space of the virtual peripheral 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 one optional embodiment, the device accesses a virtual processor in the system and is further configured to perform field parsing on the access address to obtain preset field content, and to determine the 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 / write operations on the configuration space through user-mode simulation.
[0155] Understandably, whether a virtual device's configuration space requires no switching between kernel mode and user mode—that is, whether it doesn't need to perform read / write operations via user-mode emulation—depends on the specific emulation of each virtual device. For some virtual devices, reading and writing the Base Address Registers field in the configuration space requires user-mode emulation; for example, establishing memory mappings that the virtual machine can directly read and write, or creating a virtual MSIX interrupt table. However, reading and writing the Base Address Registers field in the configuration space of other virtual devices has no specific meaning and therefore does not require emulation.
[0156] Therefore, the preset field content can be the content of fields 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, whether it is necessary to perform a switch operation between kernel mode and user mode.
[0157] By parsing the access address of the configuration space, the content of preset fields can be determined. Based on the content of these preset fields, the simulation method corresponding to the configuration space can be determined, so as to access the configuration space reasonably and avoid unnecessary simulation overhead.
[0158] It should be noted that the preferred implementation of this embodiment can be found in the relevant description in Embodiment 1, and will not be repeated here.
[0159] Example 4
[0160] According to an embodiment of this application, an embodiment of an apparatus for implementing the above-described access to virtual device configuration space is also provided. Figure 7 This is a schematic diagram of a device for accessing a virtual device configuration space according to Embodiment 4 of this application, as shown below. Figure 7 As shown, the device includes:
[0161] Module 701 is used to obtain the access address, which is used to access the configuration space of the virtual device through the virtual processor thread.
[0162] The determination module 702 determines the simulation method corresponding to the configuration space based on the access address. The simulation method is used to determine whether to simulate read and write operations on the configuration space through state transition between kernel mode and user mode.
[0163] Access module 703 accesses the configuration space in a simulated manner.
[0164] Optionally, the determination module 702 is further configured to: parse the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read / write operations on the configuration space through user-mode simulation; and determine the simulation method corresponding to the configuration space based on the preset field content.
[0165] Optionally, the aforementioned determining module 702 is further configured to: respond to the determination by preset field content that it is not necessary to perform content read / write operations on the configuration space through user-mode simulation, and determine that the simulation method corresponding to the configuration space is to simulate content read / write operations on the configuration space in kernel mode.
[0166] Optionally, the determining module 702 is further configured to: in response to the simulation mode being to simulate read and write operations on the configuration space in kernel mode, access the configuration space in kernel mode.
[0167] Optionally, it also includes: a first return module, used to return to the virtual machine runtime environment to execute subsequent operation instructions in response to the completion of the content read / write operation in the configuration space.
[0168] Optionally, the aforementioned determining module 702 is further configured to: respond to the determination of the content of the configuration space by the preset field content to perform content read and write operations on the configuration space in user mode, and determine that the simulation method 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 further configured to: switch from kernel mode to user mode in response to the simulation mode being to simulate reading and writing operations on the configuration space in user mode; simulate a virtual device in user mode to perform reading and writing operations on the configuration space and obtain reading and writing results, wherein the reading and writing 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, used to: execute the corresponding simulated action based on the read / write result; switch from user mode back to kernel mode in response to the completion of the simulated action; and return to the virtual machine runtime environment in kernel mode to execute subsequent operation instructions.
[0171] Optionally, the configuration space is used to record the configuration information of the virtual device, wherein the configuration information is used to configure the attributes, functions and operations of the virtual device, and the virtual device includes: virtual peripheral component interconnection device.
[0172] In this embodiment, the storage address (i.e., the access address) of the configuration space of the virtual PCI device to be accessed by the VCPU is obtained. Based on the access address, it is determined whether a switch between kernel mode and user mode is required when performing read / write access operations on the configuration space, thus determining the corresponding simulation mode for that configuration space. Finally, the configuration space is accessed according to the simulation mode. This achieves the goal of rationally selecting whether to perform a switch between kernel mode and user mode when accessing the virtual PCI device configuration space. This reduces the need for kernel-user mode switching, thereby reducing unnecessary simulation overhead. Furthermore, it solves the technical problem in related technologies where, when the virtual CPU reads or writes the configuration space of the virtual peripheral interconnect device, it exits to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, resulting in high simulation overhead.
[0173] It should be noted that the acquisition module 701, determination module 702, and access module 703 mentioned above correspond to steps S41 to S43 in Embodiment 1. The three modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 1. It should be noted that the above modules or units can be hardware or software components stored in memory and processed by one or more processors, and the above modules can also run in a server.
[0174] According to an embodiment of this application, another embodiment of an apparatus for implementing the above-described access to virtual device configuration space is also provided. Figure 8 This is a schematic diagram of another device for accessing virtual device configuration space according to Embodiment 4 of this application, as shown below. Figure 8 As shown, the device includes:
[0175] Module 801 is used to obtain the access address, which is used to access the configuration space of the virtual device through the virtual processor thread.
[0176] Access module 802 responds based on the access address and does not require state transitions between kernel mode and user mode to simulate read and write operations on the configuration space. It accesses the configuration space in kernel mode.
[0177] By employing the embodiments of this application, the access address of the configuration space of the virtual device accessed through the virtual processor thread is obtained. Based on the access address, it is determined that when there is no need to simulate read / write operations on the configuration space through state transitions between kernel mode and user mode, the configuration space is accessed in kernel mode. This achieves the purpose of reasonably selecting whether to perform kernel mode and user mode switching operations when accessing the configuration space of the virtual PCI device. Thus, when it is not necessary to perform kernel mode and user mode switching operations, the switching between kernel mode and user mode is reduced, achieving the technical effect of reducing unnecessary simulation overhead. This solves the technical problem in related technologies where when the virtual central processing unit reads or writes the configuration space of the virtual peripheral interconnect device, it exits to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, resulting in high simulation overhead.
[0178] It should be noted that the acquisition module 801 and access module 802 mentioned above correspond to steps S61 and S62 in Embodiment 2. The two modules and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in Embodiment 3. It should be noted that the above modules or units can be hardware or software components stored in memory and processed by one or more processors, and the above modules can also run in a server.
[0179] It should be noted that the preferred implementation schemes involved in the above embodiments of this application are the same as the schemes, application scenarios and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0180] Example 5
[0181] Embodiments of this application may provide a computer terminal, which may be any computer terminal device in a group of computer terminals. Optionally, in this embodiment, the aforementioned computer terminal may also be replaced by a mobile terminal or other terminal device.
[0182] Optionally, in this embodiment, the computer terminal may be located in at least one of a plurality of network devices in a computer network.
[0183] In this embodiment, the computer terminal described above can execute the program code for 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; determining the simulation method corresponding to the configuration space based on the access address, wherein the simulation method is used to determine whether to simulate read and write operations on the contents of the configuration space through state transitions between kernel mode and user mode; and accessing the configuration space according to the simulation method.
[0184] Optionally, Figure 9 This is a structural block diagram of a computer terminal according to Embodiment 5 of this application. Figure 9 As shown, the computer terminal 9 may include: one or more (only one is shown in the figure) processors 902, memory 904, memory controller, and peripheral interfaces, wherein the peripheral interfaces are connected to a radio frequency module, an audio module, and a display.
[0185] 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 this application embodiment. The processor executes various functional applications and data processing by running the stored software programs and modules, thereby realizing the aforementioned device access method. The memory may include high-speed random access memory, and may also include 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 memory remotely located relative to the processor, and these remote memories can be connected to the computer terminal 9 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0186] The processor can invoke information and applications stored in memory through a 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 a virtual processor thread; determine the simulation method corresponding to the configuration space based on the access address, wherein the simulation method is used to determine whether to simulate read and write operations on the contents of the configuration space through state transitions between kernel mode and user mode; and access the configuration space according to the simulation method.
[0187] Optionally, the processor may also execute program code that performs the following steps: parsing the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read / 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 program code that performs the following steps: the response determines that there is no need to perform content read / write operations on the configuration space through user-mode simulation based on the content of a preset field, and determines that the simulation method corresponding to the configuration space is to simulate content read / write operations on the configuration space in kernel mode.
[0189] Optionally, the processor may also execute program code that performs the following steps: in response to the simulation mode simulating read and write operations on the configuration space in kernel mode, accessing the configuration space in kernel mode.
[0190] Optionally, the processor may also execute program code that performs the following steps: in response to the completion of read / write operations on the configuration space, returns to the virtual machine runtime environment to execute subsequent operation instructions.
[0191] Optionally, the processor may also execute program code that performs the following steps: the response determines, through the content of a preset field, that the configuration space is simulated for reading and writing in user mode, and determines that the simulation method corresponding to the configuration space is to simulate reading and writing the configuration space in user mode.
[0192] Optionally, the processor may also execute program code that performs the following steps: in response to the simulation mode of simulating read and write operations on 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 configuration space and 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 program code that performs the following steps: performs the corresponding simulated action based on the read / write result; switches from user mode back to kernel mode in response to the completion of the simulated action; and returns to the virtual machine runtime environment in kernel mode to execute subsequent operation instructions.
[0194] Optionally, the configuration space is used to record the configuration information of the virtual device, wherein the configuration information is used to configure the attributes, functions and operations of the virtual device, and the virtual device includes: virtual peripheral component interconnection device.
[0195] The processor can invoke information and applications stored in memory via a transfer 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 a virtual processor thread; and determine, based on the access address, to access the configuration space in kernel mode without simulating read / write operations on the contents of the configuration space through state transitions between kernel mode and user mode.
[0196] In this embodiment, the storage address (i.e., the access address) of the configuration space of the virtual PCI device to be accessed by the VCPU is obtained. Based on the access address, it is determined whether a switch between kernel mode and user mode is required when performing read / write access operations on the configuration space, thus determining the corresponding simulation mode for that configuration space. Finally, the configuration space is accessed according to the simulation mode. This achieves the goal of rationally selecting whether to perform a switch between kernel mode and user mode when accessing the virtual PCI device configuration space. This reduces the need for kernel-user mode switching, thereby reducing unnecessary simulation overhead. Furthermore, it solves the technical problem in related technologies where, when the virtual CPU reads or writes the configuration space of the virtual peripheral interconnect device, it exits to the virtual machine monitor for simulation, causing the virtual machine monitor to perform additional simulation actions, resulting in high simulation overhead.
[0197] Those skilled in the art will understand that Figure 9 The structure shown is for illustrative purposes only. Computer terminal 9 can also be a smartphone (such as an Android phone, iOS phone, etc.), tablet computer, handheld computer, mobile Internet device (MID), PAD and other terminal devices. Figure 9 This does not limit the structure of the aforementioned electronic device. For example, computer terminal 9 may also include components that are more... Figure 9 The more or fewer components shown (such as network interfaces, display devices, etc.), or having the same Figure 9 The different configurations shown.
[0198] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0199] Example 6
[0200] Embodiments of this application also provide 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 Embodiment 1.
[0201] Optionally, in this embodiment, the computer-readable storage medium may be located in any computer terminal in a group of computer terminals in a computer network, or in any mobile terminal in a group of mobile terminals.
[0202] Optionally, in this embodiment, the 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 the virtual device through a virtual processor thread; determining the simulation method corresponding to the configuration space based on the access address, wherein the simulation method is used to determine whether to simulate read / write operations on the contents of the configuration space through state transitions between kernel mode and user mode; and accessing the configuration space according to the simulation method.
[0203] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: parsing the access address to obtain preset field content, wherein the preset field content is used to determine whether to perform content read / 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.
[0204] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: responding to a determination by default field content that it is not necessary to perform content read / write operations on the configuration space through user-mode simulation, and determining that the simulation method corresponding to the configuration space is to simulate content read / write operations on the configuration space in kernel mode.
[0205] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: accessing the configuration space in kernel mode in response to the simulation mode simulating read and write operations on the contents of the configuration space in kernel mode.
[0206] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: in response to the completion of the content read / write operation of the configuration space, returning to the virtual machine runtime environment to execute subsequent operation instructions.
[0207] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: responding to a determination by a preset field content that a content read / write operation is performed on the configuration space in a user-mode simulation, and determining that the simulation mode corresponding to the configuration space is to simulate a content read / write operation on the configuration space in user mode.
[0208] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code for performing the following steps: switching from kernel mode to user mode in response to simulating read and write operations on the configuration space in user mode; simulating a virtual device in user mode to perform read and write operations on the configuration space and 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 a corresponding simulated action based on the read / write result; switching from user mode back to kernel mode in response to the completion of the simulated action; and returning to the virtual machine runtime environment in kernel mode to execute subsequent operation instructions.
[0210] Optionally, in this embodiment, the configuration space is used to record the configuration information of the virtual device, wherein the configuration information is used to configure the attributes, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnection device.
[0211] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0212] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions 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. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0214] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0215] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0216] If the integrated unit is implemented as 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 this 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. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0217] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A device access method, characterized in that, include: Obtain an access address, wherein the access address is used to access the configuration space of the virtual device through a virtual processor thread, and the configuration space is used to record and configure the attributes, functions and operations of the virtual device; Based on the access address, the simulation method corresponding to the configuration space is determined, wherein the simulation method is used to determine whether to simulate the read and write operation of the configuration space through the state transition between kernel mode and user mode. The simulation method is determined based on the preset field content obtained by parsing the access address. The preset field content is used to determine whether to perform the read and write operation of the configuration space through the user mode simulation method. Access the configuration space according to the simulation method described above.
2. The method according to claim 1, characterized in that, Based on the content of the preset fields, the simulation method corresponding to the configuration space is determined as follows: The response determines, based on the content of the preset field, that there is no need to perform content read / write operations on the configuration space through the user-mode simulation method, and determines that the simulation method corresponding to the configuration space is to simulate content read / write operations on the configuration space in the kernel mode.
3. The method according to claim 2, characterized in that, Accessing the configuration space according to the simulation method includes: In response to the simulation method, the configuration space is accessed in the kernel mode by simulating read and write operations on the contents of the configuration space.
4. The method according to claim 3, characterized in that, The method further includes: Once the read / write operation of the configuration space is completed, the system returns to the virtual machine runtime environment to execute subsequent operation instructions.
5. The method according to claim 1, characterized in that, Based on the content of the preset fields, the simulation method corresponding to the configuration space is determined as follows: The response determines, through the content of the preset field, that the configuration space is subjected to content read / write operations in the user-mode simulation, and determines that the simulation mode corresponding to the configuration space is to simulate content read / write operations in the configuration space under the user mode.
6. The method according to claim 5, characterized in that, Accessing the configuration space according to the simulation method includes: In response to the simulation method of simulating read and write operations on the configuration space in the user space, the kernel mode is switched to the user mode; In the user mode, the virtual device is simulated to perform read and write operations on the configuration space and 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.
7. The method according to claim 6, characterized in that, The method further includes: Execute the corresponding simulated action based on the read / write results; In response to the completion of the simulated action, the system switches back from user mode to kernel mode; In the kernel mode, the virtual machine runtime environment is returned to execute subsequent operation instructions.
8. The method according to claim 1, characterized in that, The virtual device includes: a virtual peripheral component interconnection device.
9. A device access method, characterized in that, include: Obtain an access address, wherein the access address is used to access the configuration space of the virtual device through a virtual processor thread, and the configuration space is used to record and configure the attributes, functions and operations of the virtual device; The access address is parsed to obtain preset field content, wherein the preset field content is used to determine whether to perform content read / write operations on the configuration space through user-mode simulation. The response determines, based on the content of the preset field, that there is no need to simulate read / write operations on the configuration space through state transitions between kernel mode and user mode, and accesses the configuration space in kernel mode.
10. A device access system, characterized in that, include: Virtual processors, virtual devices, and virtual machine monitors; The virtual machine monitor is used for state transitions between kernel mode and user mode to execute simulated operations corresponding to access addresses, wherein the access addresses are used to access the configuration space of the virtual device, and the configuration space is used to record and configure the attributes, functions and operations of the virtual device; The virtual processor is configured to determine the simulation method corresponding to the configuration space based on the access address, so as to access the configuration space according to the simulation method. The simulation method is determined based on the preset field content obtained by parsing the access address. The preset field content is used to determine whether to perform content read / write operations on the configuration space through user-mode simulation.
11. The system according to claim 10, characterized in that, The virtual processor is further configured to parse the access address to obtain preset field content, and based on the preset field content, determine the simulation mode corresponding to the configuration space, wherein the preset field content is used to determine whether to perform content read / write operations on the configuration space through user-mode simulation.
12. 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, it controls the device on which the computer-readable storage medium is located to perform the device access method according to any one of claims 1 to 9.
13. An electronic device, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, performs the device access method according to any one of claims 1 to 9.