Device access methods, storage medium and electronic device
By determining in the virtualization scenario whether the kernel state and user state need to switch to simulate the configuration space read and write operations of the virtual peripheral component interconnection device, the problem of the virtual machine monitor performing additional simulation actions increases overhead, and the effect of reducing simulation overhead is achieved.
Patent Information
- Application Number
- PCT/CN2024/102974
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-09-22
- Filing Date
- 2024-07-01
- Publication Date
- 2025-03-27
AI Technical Summary
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.
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 according to the determined simulation method.
Without performing switching between kernel state and user state, the switching between kernel state and user state is reduced, unnecessary simulation overhead is reduced, and access efficiency is improved.
Smart Images

Figure CN2024102974_27032025_PF_FP_ABST
Abstract
Description
Device access method, storage medium, and electronic device
[0001] Cross-reference
[0002] This disclosure claims priority to a Chinese patent application filed with the Patent Office of China on September 22, 2023, with priority number 202311240637.3 and invention name “Device Access Method, Storage Medium and Electronic Device”, the entire contents of which are incorporated by reference into this disclosure. Technical Field
[0003] The present disclosure relates to the field of computer technology, and in particular to a device access method, a storage medium, and an electronic device. Background Art
[0004] Virtualization technology abstracts physical resources into virtual resources, enabling multiple virtual environments to share physical resources. In virtualized scenarios, when a virtual central processing unit (VCPU) reads and writes the configuration space of a virtual peripheral component interconnect (PCI) device, it typically exits to the virtual machine monitor (Hypervisor) for simulation. During the Hypervisor simulation process, the long simulation path may also require switching between kernel mode and user mode, allowing the Hypervisor to obtain higher privilege levels when needed and monitor and control virtual machines. However, the above solution causes the Hypervisor to perform additional simulation actions, increasing the simulation overhead at the Hypervisor layer.
[0005] To address the above-mentioned problems, no effective solutions have been proposed so far.
[0006] Summary of the Invention
[0007] The embodiments of the present disclosure provide a device access method, storage medium, and electronic device to at least solve the technical problem in related technologies 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.
[0008] According to one aspect of an embodiment of the present disclosure, 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 kernel mode and user mode; and accessing the configuration space according to the simulation mode.
[0009] According to another aspect of an embodiment of the present disclosure, 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 read and write operations on the content of the configuration space through a state transition between kernel state and user state, accessing the configuration space in kernel state.
[0010] According to another aspect of an embodiment of the present disclosure, a device access system is also provided, including: a virtual processor, a virtual device and a virtual machine monitor; the virtual machine monitor is configured to switch 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 configured 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.
[0011] According to another aspect of an embodiment of the present disclosure, a computer-readable storage medium is further provided, which includes a stored executable program, wherein when the executable program runs, the device where the computer-readable storage medium is located is controlled to execute any one of the above-mentioned device access methods.
[0012] According to another aspect of an embodiment of the present disclosure, an electronic device is provided, including: a memory storing an executable program; and a processor configured to run the program, wherein any one of the above-mentioned device access methods is executed when the program is run.
[0013] In the embodiment disclosed herein, the storage address of the virtual PCI device configuration space that the VCPU is about to access, i.e., the access address, is obtained. Based on the access address of the configuration space, it is determined whether it is necessary to perform a switching operation between kernel state and user state when performing read and write access operations 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, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between kernel state and user state when accessing the virtual PCI device configuration space, thereby reducing the switching between kernel state and user state when it is not necessary to perform a switching operation between kernel state and user state, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art 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.
[0014] It is easy to note that the above general description and the following detailed description are only for the purpose of exemplifying and explaining the present disclosure, and do not constitute a limitation of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] The drawings described herein are used to provide a further understanding of the present disclosure and constitute a part of the present disclosure. The exemplary embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation of the present disclosure. In the drawings:
[0016] FIG1 is a schematic diagram of a PCI device configuration space in the related art;
[0017] FIG2 is a flow chart of accessing a virtual PCI device configuration space in the related art;
[0018] FIG3 is 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 disclosure;
[0019] FIG4 is a flow chart of a device access method according to Embodiment 1 of the present disclosure;
[0020] FIG5 is a flow chart of another device access method according to Embodiment 1 of the present disclosure;
[0021] FIG6 is a flow chart of a device access method according to Embodiment 2 of the present disclosure;
[0022] 7 is a schematic structural diagram of an apparatus for accessing a virtual device configuration space according to Embodiment 4 of the present disclosure;
[0023] FIG8 is a schematic structural diagram of another apparatus for accessing a virtual device configuration space according to Embodiment 4 of the present disclosure;
[0024] FIG9 is a structural block diagram of a computer terminal according to Embodiment 5 of the present disclosure. DETAILED DESCRIPTION
[0025] In order to enable those skilled in the art to better understand the solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the embodiments described are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments of the present disclosure, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present disclosure.
[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are set to distinguish similar objects, and are not necessarily set to describe a specific order or sequence. It should be understood that the numbers used in this way are interchangeable where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0027] First, some nouns or terms that appear in the description of the embodiments of the present disclosure are appropriately explained as follows:
[0028] Virtual Central Processing Unit (VCPU): In a virtualized environment, a virtual processor is a logical processor emulated within a virtual machine. Virtual processors are implemented by virtualization software (such as a virtual machine monitor) that divides and allocates the computing resources of a physical processor across multiple virtual machines. In the disclosed embodiments, a virtual central processor is also referred to as a virtual processor, denoted as a VCPU.
[0029] Hypervisor: Software that creates, runs, and manages virtual machines (VMs). Hypervisor functions include resource management, creation, destruction, and management of virtual machines, and communication and data transfer between virtual machines and physical computers. By creating a virtualization layer on a physical computer, a hypervisor partitions the physical computer's hardware resources (such as processors, memory, and storage) into multiple virtual machines, providing each virtual machine with an independent virtual hardware environment.
[0030] 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 (Host). The guest context refers to the state and environment of a virtual machine when it is 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 (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. When the host CPU is executing the code of the host, it is in the host context. Through these two contexts, the virtualization environment achieves the isolation and management of virtual machines.
[0031] Fast path: A fast forwarding path refers to the path within a network device (such as a switch or router) that quickly forwards packets from an input port to an output port by directly using known routing information. A fast path typically consists of the optimal path between network devices and routers to reduce delays and packet loss during packet transmission, providing faster transmission speeds and more stable connection quality.
[0032] Kernel state: This refers to the privileged mode in which the operating system runs, giving it the highest permissions and access to system resources. In kernel state, the operating system can execute privileged instructions, access all memory spaces and devices, and directly control and manage hardware.
[0033] User mode: This refers to applications or user code running in non-privileged mode, with limited access to 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 that switches to kernel mode, executes the relevant kernel code, and returns the result to user mode.
[0034] By dividing the operating system's functions and permissions into kernel mode and user mode, system security and stability can be effectively protected. Kernel mode has higher permissions and more system resources, and is set up to manage and control the entire system. User mode, on the other hand, can only access restricted resources, ensuring isolation and security between applications.
[0035] Peripheral Component Interconnect (PCI) devices: devices that use the PCI bus interface. PCI devices have three memory spaces: memory address space, input / output (I / O) address space, and configuration space.
[0036] Configuration Space of PCI device: It is a specific memory area in PCI device, which is set 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 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 disclosure, PCI device refers to PCI device and Peripheral Component Interconnect Express (PCIE) device.
[0037] FIG1 is a schematic diagram of a PCI device configuration space in the related art. As shown in FIG1 , 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 field, capabilities pointer, max_lat, min_gnt, IRQ pin, and IRQ line.
[0038] The Device ID identifies the model or type of the device and is assigned by the device manufacturer. The Vendor ID identifies the manufacturer of the device and is assigned by the PCI device manufacturer.
[0039] Status is used to reflect the current status of the device.
[0040] Command is used to control some behaviors of the device, such as enabling the device and enabling interrupts.
[0041] Class Code is used to describe the type and function of the device.
[0042] Revision ID is used to identify the version information of the device.
[0043] BIST is a function in the PCI device configuration space that is used for self-diagnosis and self-testing.
[0044] Header type is used to identify the configuration space type of the device.
[0045] Latency timer is used to set the delay time for the device to respond to the host.
[0046] Cache line size is used to set the cache line size of the device.
[0047] Base Address Registers are used to describe the base addresses of I / O ports, memory areas, or other resources used by the device.
[0048] 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.
[0049] Subsystem ID and Subsystem Vendor ID are used to identify the subsystem to which a device belongs.
[0050] Expansion ROM Base Address is used to specify the base address of the device's expansion ROM.
[0051] Expansion ROM is a type of firmware stored on the device that can contain device drivers, BIOS extensions, etc. This field specifies the starting address of the expansion ROM in physical memory.
[0052] Reserved refers to some fields in the PCI device configuration space that are reserved for future specification extensions or other purposes.
[0053] The Capabilities Pointer is used to indicate the location of the extended capabilities structure in the device configuration space.
[0054] 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.
[0055] Min_Gnt is an 8-bit field that indicates the minimum time a PCI device must release the bus.
[0056] IRQ Pin is a 4-bit field that indicates the interrupt pin number used by the PCI device.
[0057] IRQ Line is used to indicate the interrupt request line number used by the device.
[0058] Figure 2 is a flowchart of accessing the virtual PCI device configuration space in the related art. As shown in Figure 2, 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 usually exits to the Hypervisor for simulation, that is, the VCPU switches to the Hypervisor user state.
[0059] 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.
[0060] After the user-mode emulation is complete, the VCPU switches back to kernel mode and executes some common processing steps related to entering the guest context, preparing to enter the virtual machine's execution environment. Finally, the VCPU returns to the guest context and continues executing the next instruction, completing the read and write operations on the virtual PCI device configuration space.
[0061] In the related art, the method for accessing the virtual PCI device configuration space has the following defects.
[0062] Defect 1: Because most reads and writes to the virtual PCI device configuration space simply modify or read the content, no additional emulation is required by the hypervisor. In related art, switching between kernel mode and user mode when reading and writing the virtual PCI device configuration space causes the hypervisor to perform additional emulation, increasing emulation overhead at the hypervisor level.
[0063] With respect to the above-mentioned defects, no effective solution has been proposed before the present disclosure.
[0064] Example 1
[0065] According to an embodiment of the present disclosure, 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.
[0066] The method embodiment provided in the first embodiment of the present disclosure can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 3 shows a hardware structure block diagram of a computer terminal (or mobile device) for implementing a device access method. As shown in Figure 3, the computer terminal 30 (or mobile device) may include one or more (302a, 302b, ..., 302n are used in the figure 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 configured to store data, and a transmission device 306 configured to have a communication function. 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 will be understood by those skilled in the art that the structure shown in Figure 3 is only illustrative and does not limit the structure of the above-mentioned electronic device. For example, the computer terminal 30 may also include more or fewer components than shown in Figure 3, or have a configuration different from that shown in Figure 3.
[0067] 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 circuitry." The data processing circuitry may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. Furthermore, the data processing circuitry may be a single, independent processing module, or may be incorporated in whole or in part into any of the other components of the computer terminal 30 (or mobile device). As described in the embodiments of the present disclosure, the data processing circuitry serves as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0068] The memory 304 can be configured to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the device access method in the embodiment of the present disclosure. The processor 302 executes various functional applications and data processing by running the software programs and modules stored in the memory 304, that is, implementing 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 instances, the memory 304 may further include a memory remotely located 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.
[0069] Transmission device 306 is configured to receive or transmit data via a network. A specific example of the aforementioned network may include a wireless network provided by the communications provider of computer terminal 30. In one embodiment, transmission device 306 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, transmission device 306 may be a radio frequency (RF) module configured to communicate with the Internet wirelessly.
[0070] 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).
[0071] In the above operating environment, the present disclosure provides a device access method as shown in Figure 4. Figure 4 is a flow chart of a device access method according to embodiment 1 of the present disclosure. As shown in Figure 4, the method may include the following steps:
[0072] 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;
[0073] 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 by switching between kernel mode and user mode;
[0074] Step S43: Access the configuration space in a simulation manner.
[0075] 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.
[0076] 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 disclosure, the virtual device is described as a virtual PCI device as an example.
[0077] The configuration space is configured to record configuration information of the virtual device. The configuration space can be understood as a memory area that is configured to record and configure properties, functions, and operations of the virtual PCI device.
[0078] 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 set to represent various types of PCI devices emulated by the virtual PCI device, including a network adapter, a storage controller, a graphics card, etc. The virtual PCI device identifier is set to uniquely identify the device in a virtualized environment.
[0079] 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.
[0080] The operations of the virtual PCI device include: configuring the virtual PCI device (such as setting the configuration space of the virtual PCI device, etc.), initializing the virtual PCI device (such as initializing the device's registers, interrupt and DMA settings, etc.), reading the configuration space of the virtual PCI device (such as 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 (such as modifying relevant configurations of the device, such as interrupt number, resource allocation, etc.), reading and writing the registers of the virtual PCI device (such as 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 (such as implementing data transmission and exchange), responding to interrupts of the virtual PCI device (such as interrupt processing and execution of interrupt service programs), and other operations.
[0081] In a virtualized scenario, a virtual processor thread 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. By accessing the configuration space, a virtual processor thread can initialize, configure, and manage virtual devices.
[0082] The simulation mode can be understood as a variety of read and write modes for reading or modifying configuration parameters of the configuration space when the VCPU accesses the access address of the configuration space. In the embodiments of the present disclosure, the simulation mode can, for example, include a mode of switching between kernel mode and user mode to simulate read and write operations. The simulation mode can also include a mode of performing read and write operations directly in kernel mode without switching between kernel mode and user mode.
[0083] It is understandable that when accessing the virtual PCI device configuration space, it may be necessary to perform a switching operation between kernel mode and user mode to simulate content read and write operations, but performing the switching operation between kernel mode and user mode will increase the simulation overhead.
[0084] Therefore, in the disclosed embodiments, determining the simulation mode corresponding to the configuration space can be understood as determining whether a switch operation between kernel mode and user mode is required when accessing the configuration space. Based on the access address, it can be determined whether a switch operation between kernel mode and user mode is required when the VCPU accesses the configuration space corresponding to the access address, thereby enabling the appropriate selection of the corresponding simulation mode. When a switch operation is not required, switching between kernel mode and user mode can be reduced, thereby reducing unnecessary simulation overhead.
[0085] In the disclosed embodiment, the storage address of the virtual PCI device configuration space to be accessed by the VCPU, i.e., the access address, is obtained. Based on the access address of the configuration space, it is determined whether a switch operation between kernel mode and user mode is required when performing read and write access operations 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, thereby reducing the switching between kernel mode and user mode when the switching operation between kernel mode and user mode is not required, thereby reducing unnecessary simulation overhead.
[0086] The above-mentioned device access method provided by the embodiment of the present disclosure can be, but is not limited to, set 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.
[0087] According to the embodiment of the present disclosure, 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 kernel state and user state when performing read and write access operations 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, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between kernel state and user state when accessing the virtual PCI device configuration space, thereby reducing the switching between kernel state and user state when the switching operation between kernel state and user state is not required, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art 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.
[0088] 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:
[0089] Step S421: Perform field parsing on the access address to obtain preset field content, wherein the preset field content is set to determine whether to perform content read and write operations on the configuration space through user mode simulation;
[0090] Step S422: Determine the simulation mode corresponding to the configuration space based on the preset field content.
[0091] Understandably, whether or not a virtual PCI device's configuration space can be read and written without user-mode emulation depends on the emulation of each virtual PCI device. Some virtual PCI devices require user-mode emulation to read and write Base Address Registers fields, for example, by establishing a memory mapping that the virtual machine can directly read and write, or by creating a virtual MSIX interrupt table. Other virtual PCI devices, however, do not require emulation for Base Address Registers reading and writing operations, as they have no specific meaning.
[0092] 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 to perform content read and write operations on the configuration space through user mode emulation, that is, whether to switch between kernel mode and user mode.
[0093] By performing field parsing on the access address of the configuration space, the preset field content can be determined, and then 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.
[0094] 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:
[0095] Step S4221 , in response to determining through the preset field content that it is not necessary to perform content read and write operations 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 operations on the configuration space in the kernel mode.
[0096] 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 simulate read and write operations without the need for user mode simulation.
[0097] If, based on the contents of the preset fields, it is determined that a kernel-mode to user-mode switch is not necessary, i.e., if a switch to user mode for emulation is not necessary, then the configuration space can be accessed in kernel mode. Therefore, the emulation method corresponding to the configuration space is determined to be to perform read and write operations on the configuration space in kernel mode, thereby avoiding unnecessary emulation overhead.
[0098] Optionally, kernel-mode read and write operations on the configuration space can use a fast path to execute read and write operations, enabling faster data transfers and improving read and write access performance and efficiency. 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.
[0099] In an optional embodiment, in step S43, accessing the configuration space in a simulation manner includes the following method steps:
[0100] Step S431 , in response to the simulation mode being to simulate the read and write operations on the configuration space in the kernel state, the configuration space is accessed in the kernel state.
[0101] 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.
[0102] In an optional embodiment, the device access method further includes the following method steps:
[0103] Step S432: In response to the completion of the read and write operations on the configuration space, the virtual machine operating environment is returned to execute subsequent operation instructions.
[0104] Returning to the virtual machine running environment can be understood as returning to the Guest context, thereby continuing to execute the next instruction.
[0105] After completing the read and write operations on the configuration space in a simulated manner, the guest context can be returned to continue executing the next instruction.
[0106] 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:
[0107] Step S4222, in response to determining that the content read and write operations are performed on the configuration space in a user mode simulation mode according to the preset field content, it is determined that the simulation mode corresponding to the configuration space is to simulate the content read and write operations on the configuration space in the user mode.
[0108] If the contents of the preset fields indicate that a kernel-mode to user-mode switch is required, i.e., if a switch to user mode is required for simulation, then the configuration space can be accessed in user mode. Therefore, the simulation method for this configuration space is determined to be to perform read and write operations on the configuration space in kernel mode, thereby ensuring the correctness of the read and write operations.
[0109] In an optional embodiment, in step S43, accessing the configuration space in a simulation manner includes the following method steps:
[0110] Step S431 , in response to the simulation mode being to simulate the read and write operations on the configuration space in the user mode, switching from the kernel mode to the user mode;
[0111] Step S432: simulating a virtual device in user mode to perform read and write operations on the configuration space content to obtain read and write results, wherein the read and write results are set to record the content reading result or content modification result of the configuration space.
[0112] 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 user mode, the system switches from kernel mode to user mode, thereby performing the read and write operations on the content of the configuration space by simulating a virtual PCI device in user mode, and obtaining the read and write results set to record the content reading results or content modification results of the configuration space.
[0113] In an optional embodiment, the device access method further includes the following method steps:
[0114] Step S433, performing corresponding simulation actions based on the read and write results;
[0115] Step S434, in response to the completion of the simulation action, switching from user mode back to kernel mode;
[0116] Step S435: In kernel mode, return to the virtual machine operating environment to execute subsequent operation instructions.
[0117] In user mode, read and write operations are performed on the configuration space. After obtaining the read and write results, corresponding simulation actions can be performed based on the read and write results, such as virtual interrupt simulation and device reset. After the simulation action is completed, it is necessary to switch from user mode back to kernel mode and return to the guest context to execute subsequent operation instructions.
[0118] As shown in FIG5 , FIG5 is a flow chart of another device access method according to embodiment 1 of the present disclosure.
[0119] The VCPU accesses the configuration space of a virtual PCI device by reading and writing specific memory addresses. When accessing the configuration space of a virtual PCI device, the VCPU first determines whether it can take the fast path—that is, whether it needs to switch between kernel mode and user mode. If the fast path is acceptable, the switch is omitted and the virtual PCI device's content is read and written in kernel mode. After the read and write operations are completed, the VCPU returns to the guest context to execute subsequent instructions.
[0120] If the fast path is not feasible, a switch operation is executed from kernel mode to user mode. In user mode, the corresponding virtual PCI device processing callback function is found based on the address accessed by the VCPU. This function is executed to simulate read and write operations and perform corresponding processing on the configuration space of the virtual PCI device. For different configuration space access addresses, the virtual PCI device processing callback function may perform different simulation operations, such as simulating an interrupt or device reset.
[0121] After the user-mode emulation is complete, the VCPU switches back to kernel mode and executes some common processing steps related to entering the guest context, preparing to enter the virtual machine's execution environment. Finally, the VCPU returns to the guest context and continues executing the next instruction, completing the read and write operations on the virtual PCI device configuration space.
[0122] It is easy to understand that the beneficial effects of the device access method provided by the present disclosure include the following points.
[0123] 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 performs 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.
[0124] 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.
[0125] 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 set for analysis, stored data, displayed data, etc.) involved in this disclosure 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 relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0126] 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 the present disclosure is not limited by the order of the actions described, because according to the present disclosure, 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 the present disclosure.
[0127] 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 the necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the technical solution of the present disclosure, 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, magnetic disk, optical disk), and includes a number of 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 disclosure.
[0128] Example 2
[0129] In the operating environment as in Example 1, the present disclosure provides a device access method as shown in FIG6 . FIG6 is a flowchart of a device access method according to Example 2 of the present disclosure. As shown in FIG6 , the method includes:
[0130] 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;
[0131] 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 configuration space through state transition between kernel state and user state, the configuration space is accessed in kernel state.
[0132] The access address can be understood as an address accessed by the VCPU, that is, a storage address of the virtual PCI device configuration space, which is set to access the configuration space of the virtual device through a virtual processor thread in a virtualization scenario.
[0133] 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 disclosure, the virtual device is described as a virtual PCI device as an example.
[0134] The configuration space is configured to record configuration information of the virtual device. The configuration space can be understood as a memory area that is configured to record and configure properties, functions, and operations of the virtual PCI device.
[0135] 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 set to represent various types of PCI devices emulated by the virtual PCI device, including a network adapter, a storage controller, a graphics card, etc. The virtual PCI device identifier is set to uniquely identify the device in a virtualized environment.
[0136] 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.
[0137] The operations of the virtual PCI device include: configuring the virtual PCI device (such as setting the configuration space of the virtual PCI device, etc.), initializing the virtual PCI device (such as initializing the device's registers, interrupt and DMA settings, etc.), reading the configuration space of the virtual PCI device (such as 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 (such as modifying relevant configurations of the device, such as interrupt number, resource allocation, etc.), reading and writing the registers of the virtual PCI device (such as 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 (such as implementing data transmission and exchange), responding to interrupts of the virtual PCI device (such as interrupt processing and execution of interrupt service programs), and other operations.
[0138] In a virtualized scenario, a virtual processor thread 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. By accessing the configuration space, a virtual processor thread can initialize, configure, and manage virtual devices.
[0139] 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 required, the switching between kernel state and user state can be reduced, thereby reducing unnecessary simulation overhead.
[0140] If it is determined based on the access address that there is no need to simulate the read and write operations on the configuration space through state transitions between kernel state and user state, the configuration space is accessed in kernel state, thereby avoiding unnecessary simulation overhead.
[0141] The above-mentioned device access method provided by the embodiment of the present disclosure can be, but is not limited to, set 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.
[0142] By adopting the embodiment of the present disclosure, by obtaining the access address of the configuration space of the virtual device accessed through the virtual processor thread, and 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, thereby achieving the purpose of reasonably choosing whether to perform the switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, thereby reducing the switching between the kernel state and the user state when there is no need to perform the switching operation between the kernel state and the user state, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art 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 high simulation overhead.
[0143] It should be noted that the preferred implementation of this embodiment can be found in the relevant description in Example 1 and will not be repeated here.
[0144] Example 3
[0145] In an operating environment as in Example 1, the present disclosure provides a device access system, which includes: a virtual processor, a virtual device and a virtual machine monitor; the virtual machine monitor is configured to switch 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 configured 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.
[0146] A virtual processor is a logical processor emulated in a virtual machine in a virtualization scenario.
[0147] A virtual device can be understood as a virtual PCI device, which is a simulated PCI device created in a virtualized environment.
[0148] A hypervisor is set up to manage and run virtual machines.
[0149] The configuration space of the virtual device is set to record the configuration information of the virtual device. The configuration space can be understood as a memory area, which is set to record and configure the properties, functions and operations of the virtual PCI device.
[0150] The access address can be understood as the address for accessing the configuration space of the virtual device.
[0151] It is understandable that the virtual processor can access the configuration space by accessing the access address of the virtual device configuration space, thereby accessing the configuration space and performing read and write operations on the configuration parameters of the configuration space.
[0152] 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.
[0153] The simulation mode corresponding to the configuration space may include executing switching between kernel mode and user mode to perform simulated read and write operations in user mode, and not executing switching between kernel mode and user mode to perform simulated read and write operations in kernel mode.
[0154] In an embodiment of the present disclosure, 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 a switching operation between kernel state and user state needs to be performed by determining the simulation mode corresponding to the configuration space. If the simulation mode indicates that a switching operation needs to be performed between kernel state and user state, the virtual machine monitor performs simulation, switches from kernel state to user state, and performs simulated read and write operations on the configuration space in user state. If the simulation mode indicates that a switching operation does not need to be performed between kernel state and user state, the virtual processor directly performs simulated read and write operations on the configuration space in kernel state, thereby reducing the switching between kernel state and user state, and further reducing unnecessary simulation overhead.
[0155] The application scenarios of the above-mentioned device access system provided by the embodiments of the present disclosure 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, such as: 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.
[0156] The device access system using the embodiment of the present disclosure 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.
[0157] In an 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 determine a simulation method corresponding to the configuration space based on the preset field content, wherein the preset field content is configured to determine whether to perform content read and write operations on the configuration space through a user-mode simulation method.
[0158] It's understandable that whether a virtual device's configuration space requires switching between kernel and user mode, meaning that it doesn't require user-mode emulation for content read and write operations, depends on the emulation of each virtual device. For some virtual devices, reading and writing Base Address Registers in their configuration space requires user-mode emulation, for example, to establish a memory mapping that the virtual machine can directly read and write, or to create a virtual MSIX interrupt table. For other virtual devices, reading and writing Base Address Registers in their configuration space doesn't have any specific meaning and therefore doesn't require emulation.
[0159] 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 to perform content read and write operations on the configuration space through user mode emulation, that is, whether to switch between kernel mode and user mode.
[0160] By performing field parsing on the access address of the configuration space, the preset field content can be determined, and then 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.
[0161] It should be noted that the preferred implementation of this embodiment can be found in the relevant description in Example 1 and will not be repeated here.
[0162] Example 4
[0163] According to an embodiment of the present disclosure, an embodiment of an apparatus for implementing the above-mentioned access to a virtual device configuration space is also provided. FIG7 is a schematic structural diagram of an apparatus for accessing a virtual device configuration space according to embodiment 4 of the present disclosure. As shown in FIG7 , the apparatus includes:
[0164] 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;
[0165] The 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 by switching between kernel mode and user mode;
[0166] The access module 703 accesses the configuration space in a simulation manner.
[0167] Optionally, the above-mentioned determination module 702 is also configured to: perform field parsing on the access address to obtain preset field content, wherein the preset field content is configured 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.
[0168] Optionally, the above-mentioned determination module 702 is also configured to: 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 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.
[0169] Optionally, the determining module 702 is further configured to: 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, access the configuration space in the kernel state.
[0170] Optionally, it further includes: a first returning module, configured to return to the virtual machine operating environment to execute subsequent operation instructions in response to completion of the content reading and writing operations of the configuration space.
[0171] Optionally, the determination module 702 is further configured to: in response to determining that content read and write operations are performed on the configuration space through user-mode simulation according to preset field content, 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.
[0172] Optionally, the above-mentioned access module 703 is also configured to: in response to the simulation mode being to simulate the content reading and writing operations on 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 content reading and writing operations on the configuration space to obtain the reading and writing results, wherein the reading and writing results are set to record the content reading results or content modification results of the configuration space.
[0173] Optionally, it also includes: a second return module, configured to: execute corresponding simulation actions based on the read and write results; switch back to kernel state from user state in response to completion of the simulation action; and return to the virtual machine operating environment in kernel state to execute subsequent operation instructions.
[0174] Optionally, the configuration space is configured to record configuration information of a virtual device, wherein the configuration information is configured to configure properties, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnect device.
[0175] According to the embodiment of the present disclosure, 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 kernel state and user state when performing read and write access operations 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, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between kernel state and user state when accessing the virtual PCI device configuration space, thereby reducing the switching between kernel state and user state when the switching operation between kernel state and user state is not required, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art 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.
[0176] It should be noted that the acquisition module 701, determination module 702, and access module 703 described above correspond to steps S41 to S43 in Example 1. The examples and application scenarios implemented by the three modules and the corresponding steps are the same, but are not limited to the contents disclosed in Example 1. It should be noted that the modules or units described above may be hardware components or software components stored in a memory and processed by one or more processors, and the modules may also run on a server.
[0177] According to an embodiment of the present disclosure, another embodiment of a device configured to implement the above-mentioned access to a virtual device configuration space is also provided. FIG8 is a schematic structural diagram of another device for accessing a virtual device configuration space according to embodiment 4 of the present disclosure. As shown in FIG8 , the device includes:
[0178] 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;
[0179] 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 configuration space through state transitions between the kernel state and the user state.
[0180] By adopting the embodiment of the present disclosure, by obtaining the access address of the configuration space of the virtual device accessed through the virtual processor thread, and 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, thereby achieving the purpose of reasonably choosing whether to perform the switching operation between the kernel state and the user state when accessing the virtual PCI device configuration space, thereby reducing the switching between the kernel state and the user state when there is no need to perform the switching operation between the kernel state and the user state, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art 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 high simulation overhead.
[0181] It should be noted that the acquisition module 801 and access module 802 correspond to steps S61 and S62 in Example 2. 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 Example 3. It should be noted that the modules or units can be hardware components or software components stored in a memory and processed by one or more processors, and the modules can also run on a server.
[0182] It should be noted that the preferred implementation scheme involved in the above embodiments of the present disclosure is the same as the solution provided in Example 1, as well as the application scenario and implementation process, but is not limited to the solution provided in Example 1.
[0183] Example 5
[0184] The embodiment of the present disclosure 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.
[0185] Optionally, in this embodiment, the computer terminal may be located in at least one network device among a plurality of network devices of a computer network.
[0186] 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.
[0187] Optionally, Figure 9 is a structural block diagram of a computer terminal according to Embodiment 5 of the present disclosure. As shown in Figure 9, 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.
[0188] Among them, the memory can be configured 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 disclosure. 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 located 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.
[0189] 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; 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.
[0190] Optionally, the above-mentioned processor can also execute the program code of the following steps: perform field parsing on the access address to obtain preset field content, wherein the preset field content is set 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.
[0191] 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, determining that the simulation method corresponding to the configuration space is to simulate content read and write operations on the configuration space in kernel mode.
[0192] 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.
[0193] 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.
[0194] Optionally, the processor may also execute the following program code: in response to determining through the preset field content that content read and write operations are performed on the configuration space through a user-mode simulation method, determining that the simulation method corresponding to the configuration space is to simulate content read and write operations on the configuration space in user mode.
[0195] Optionally, the above-mentioned processor can also execute the 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 user state, switching from the kernel state to the user state; simulating 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 set to record the content reading results or content modification results of the configuration space.
[0196] 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.
[0197] Optionally, the configuration space is configured to record configuration information of a virtual device, wherein the configuration information is configured to configure properties, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnect device.
[0198] The processor can call the information and application stored in the memory through the transmission device to perform the following steps: obtaining 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, the configuration space is accessed in the kernel state.
[0199] According to the embodiment of the present disclosure, 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 kernel state and user state when performing read and write access operations 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, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between kernel state and user state when accessing the virtual PCI device configuration space, thereby reducing the switching between kernel state and user state when the switching operation between kernel state and user state is not required, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art 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.
[0200] Those skilled in the art will appreciate that the structure shown in FIG9 is merely illustrative, and that the computer terminal 9 may also be a smartphone (e.g., an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile internet device (MID), a PAD, or other terminal device. FIG9 does not limit the structure of the aforementioned electronic devices. For example, the computer terminal 9 may include more or fewer components (e.g., a network interface, a display device, etc.) than those shown in FIG9 , or may have a configuration different from that shown in FIG9 .
[0201] A person skilled in the art will 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, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0202] Example 6
[0203] The embodiment of the present disclosure further provides a computer-readable storage medium. Optionally, in this embodiment, the computer-readable storage medium may be configured to store the program code executed by the device access method provided in the first embodiment.
[0204] Optionally, in this embodiment, the computer-readable storage medium may be located in any computer terminal in a computer terminal group in a computer network, or in any mobile terminal in a mobile terminal group.
[0205] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code configured to perform 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; 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 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.
[0206] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code configured to execute the following steps: performing field parsing on the access address to obtain preset field content, wherein the preset field content is configured to determine whether to perform content read and write operations on the configuration space through a user-mode simulation method; based on the preset field content, determining the simulation method corresponding to the configuration space.
[0207] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code configured to execute 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-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 kernel mode.
[0208] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code configured to execute 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.
[0209] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code configured to execute 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.
[0210] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code configured to execute the following steps: in response to determining through preset field content that content read and write operations are performed on the configuration space through a user-mode simulation method, determining that the simulation method corresponding to the configuration space is to simulate content read and write operations on the configuration space in user mode.
[0211] Optionally, in this embodiment, a computer-readable storage medium is configured to store program code configured to execute 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 set to record the content reading results or content modification results of the configuration space.
[0212] Optionally, in this embodiment, the computer-readable storage medium is configured to store program code configured to perform 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.
[0213] Optionally, in this embodiment, the configuration space is configured to record configuration information of a virtual device, wherein the configuration information is configured to configure properties, functions and operations of the virtual device, and the virtual device includes: a virtual peripheral component interconnect device.
[0214] The serial numbers of the above-mentioned embodiments of the present disclosure are for description only and do not represent the advantages or disadvantages of the embodiments.
[0215] In the above embodiments of the present disclosure, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0216] In the several embodiments provided in the present disclosure, 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.
[0217] The units described as separate components may or may not be physically separate, and 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 these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0218] In addition, the functional units in the various embodiments of the present disclosure may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0219] 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 invention is essentially 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 for enabling 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 invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0220] The above is only a preferred embodiment of the present disclosure. 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 disclosure. These improvements and modifications should also be regarded as within the scope of protection of the present disclosure. Industrial Applicability
[0221] In the embodiment disclosed herein, the storage address of the virtual PCI device configuration space that the VCPU is about to access, i.e., the access address, is obtained. Based on the access address of the configuration space, it is determined whether it is necessary to perform a switching operation between kernel state and user state when performing read and write access operations 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, thereby achieving the purpose of reasonably selecting whether to perform a switching operation between kernel state and user state when accessing the virtual PCI device configuration space, thereby reducing the switching between kernel state and user state when it is not necessary to perform a switching operation between kernel state and user state, achieving the technical effect of reducing unnecessary simulation overhead, and further solving the technical problem in the related art 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.
Claims
1. A device access method, wherein: 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, wherein: 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 set 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, wherein: Based on the preset field content, determining the simulation mode corresponding to the configuration space 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, wherein: 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, wherein: 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, wherein: Based on the preset field content, determining the simulation mode corresponding to the configuration space 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, wherein: According to the simulation method, accessing the configuration space includes: In response to the simulation mode being to simulate the internal configuration space in the user state Allowing read and write operations, 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 set to record content reading results or content modification results of the configuration space.
8. The method according to claim 7, wherein: 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, wherein: The configuration space is configured to record configuration information of the virtual device, wherein the configuration information is configured 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, wherein: 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, wherein: include: Virtual processors, virtual devices, and virtual machine monitors; The virtual machine monitor is configured to switch between kernel state and user state to perform a simulation operation corresponding to an access address, wherein the access address is used to access a configuration space of the virtual device; The virtual processor is configured to determine a 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, wherein: The virtual processor is further configured to perform field parsing on the access address to obtain preset field content, and determine a simulation method corresponding to the configuration space based on the preset field content, wherein the preset field content is configured to determine whether to perform content read and write operations on the configuration space through a user mode simulation method.
13. A computer-readable storage medium, wherein: 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, wherein: include: A memory storing an executable program; A processor is configured to run the program, wherein the program executes the rights requirement when it is run. Request a device access method as described in any one of 1 to 10.
Citation Information
Patent Citations
Establishing method of kernel state virtual network equipment and packet transmitting and receiving methods thereof
CN102497434A
Method and device for processing exception of virtual machine
CN105468434A
DATA PROCESSING METHOD, device AND TERMINAL device
CN109408226A
Computer equipment, exception processing method and interrupt processing method
CN114077379A
Data writing method and device
WO2016078313A1