Disclosure of Invention
The embodiment of the invention provides a light-weight virtualization implementation method and device, which are used for solving the problems that the existing virtualization scheme cannot be applied in a resource-limited environment, the real-time performance of a virtual machine cannot be ensured, and a real-time operating system or a bare computer program cannot be directly operated.
According to a first aspect of an embodiment of the present invention, there is provided a lightweight virtualization implementation method applied to an apparatus deployed with a pre-built user interaction tool, a system driver, and virtual machine management firmware, including:
Loading a client configuration file through a pre-built user interaction tool in response to the enabling of the virtualization function, wherein the user interaction tool runs in a host client operating system;
Based on the configuration information in the client configuration file, the virtual machine management firmware is controlled to isolate physical hardware resources of each client through system call, and a shared memory for communication between the clients is provided for each client to realize the creation of the clients and communication between the clients;
When the virtualization function is enabled, the main client and the sub client are virtual machines, and when the virtualization function is disabled, the main client is an independent operating system.
Further, the method directly provides hardware resources used by the client through hardware isolation.
The system call is performed through a user interaction tool, the system call generates a super call through a system driver, the virtual machine management firmware is loaded to the memory for running through the super call, and the loaded virtual machine management firmware isolates the physical hardware to different clients.
Further, the shared memory adopts a one-to-one model, and an independent shared memory is commonly declared for communication between any two clients.
Further, the virtual machine management firmware operates at a particular processor privilege level, for x86 architecture, the virtual machine management firmware operates at a kernel mode privilege level of the root mode, for ARM architecture, the virtual machine management firmware operates at a virtualization mode privilege level, for RISC-V architecture, the virtual machine management firmware operates at a virtual machine monitor mode privilege level.
Further, the virtual machine management firmware specifically executes the following processing procedures that configuration information and commands from a driver are received, and then the processing is performed according to the command types, wherein:
for enabling and creating commands, initializing the state of a corresponding CPU according to the received configuration information, creating a corresponding memory page table, realizing the resource allocation and hardware isolation of memories and CPUs of different clients, and managing the configuration information of each client through a linked list;
and for disabling, deleting, modifying and inquiring commands, carrying out corresponding processing by inquiring the configuration information of the corresponding client, and returning a processing result.
Further, the user interaction tool specifically performs the following processing procedures:
receiving command input of a user;
When the command is input as an enabling or creating command, reading and analyzing a preset configuration file, sending an analysis result and a corresponding command to a system driver to execute corresponding processing, and receiving and displaying a processing result;
When the command is input as disable, delete or view, the command is directly sent to the system driver to execute corresponding processing, and the processing result is received and displayed.
Further, the system driver specifically executes the following processing procedures of receiving configuration information and commands from a user interaction tool, copying the content of the configuration information from a user space to a system space for enabling and creating commands, after verification processing, sending the verified configuration information and corresponding commands to virtual machine management firmware for processing and returning results, creating corresponding maintenance nodes in a pre-built management linked list after hardware resources are successfully isolated, mapping the maintenance nodes back to a host client machine so that the host client machine can maintain other clients, and for inquiring commands, finding corresponding client machine information by directly traversing the existing management linked list and then returning to the user interaction tool.
Further, the client running operating system types include Linux, android, windows, real-time operating system, and bare metal programs.
According to a second aspect of the embodiment of the invention, a lightweight virtualization device is provided, which comprises a hardware module and a software module, wherein the hardware module comprises a CPU, a memory and an IO device, the software module comprises a main client operating system, a user interaction tool, a system driver and a virtual machine management firmware, and the lightweight virtualization implementation method is executed based on the software module.
The one or more of the above technical solutions have the following beneficial effects:
The invention provides a light-weight virtualization implementation method and device, wherein the scheme reduces dependence on hardware resources by multiplexing an existing operating system (namely a main client operating system), simplifies virtualization complexity, directly uses hardware isolated by hardware for a virtual machine, and ensures high real-time performance of each client (namely the virtual machine). From the perspective of a user, the scheme of the invention takes the whole virtualization process as an application program of the current operating system, and does not increase any resource consumption after the virtualization is started, so that the method is light enough and the performance requirement is reduced. The scheme of the invention directly provides hardware resources for the client through hardware isolation, thereby ensuring the real-time requirement of the client and directly running various real-time operating systems. Additional aspects of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the invention.
Detailed Description
It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the invention. Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.
It is noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of exemplary embodiments according to the present invention.
Embodiments of the invention and features of the embodiments may be combined with each other without conflict.
As shown in fig. 1 and 2, an object of the present embodiment is to provide a lightweight virtualization implementation method, where implementation of the method is based on a user interaction tool, a system driver and virtual management firmware, which are built in advance, and specifically includes the following processing procedures:
The method comprises the steps of 1, responding to the enabling of a virtualization function, loading a client configuration file through a pre-built user interaction tool, wherein the user interaction tool runs in a host client operating system, and the client configuration file comprises hardware resources distributed to a host client and a plurality of sub clients and shared memory declarations used for communication among the clients;
The user interaction tool is used as a man-machine interaction interface for a user to manage the virtual machine (namely, the client machine), and the functions of checking the state of the existing virtual machine, creating a new virtual machine, deleting the existing virtual machine and the like are realized through the user interaction tool.
The user interaction tool is essentially a common application in the host client operating system for loading client configuration files given by the user, and most of its commands need to be sent to the system driver via system calls, taking into account the permission constraints of the operating system.
In a specific implementation, as shown in fig. 3, a user executes a specific command in the host client operating system by using a user interaction tool to enable or disable the virtualization function, and after the user enables the virtualization function, the virtual machine management firmware automatically isolates the current system into a virtualization environment, and after the user closes the virtualization function, the user can restore to the original system.
In the virtualization result of the solution in this embodiment, the virtual machine includes a main client and a plurality of sub-clients, where the main client is used as a virtualization management center, and its overall architecture is shown in fig. 1, and when virtualization is not enabled, only the main client is operated, and becomes an independent operating system, as shown in fig. 3, and when virtualization needs to be enabled, the relevant operation shown in fig. 2 needs to be executed in the main client.
In contrast to Type II, in the solution described in this embodiment, the Host client is also essentially a virtual machine, but the Host OS Host client of Type II is not a virtual machine, and in contrast to Type I, both the Host client and the sub-client of the solution described in this embodiment can directly access hardware resources, and the client of Type I needs to go through the VMM to access hardware.
The user interaction tool, the system driver and the virtual machine management firmware are all executable programs which can be independently used. Due to the design of modern CPU instruction set architecture, various operations are classified into different authority levels, and thus, the operations of different authorities are processed by the executable program respectively.
In a specific implementation, the virtual machine management is performed by the host client for the entire virtualization management, and therefore, user interaction tools, system drivers, and virtual machine management firmware need to be installed in the host client, as shown in fig. 2.
It should be noted here that the virtualization management may be performed on any client, but in order to reduce complexity, the solution described in this embodiment limits the management operations in the sub-clients. It will be appreciated that in further embodiments, the virtualization management may be performed on sub-clients other than the main client, which is not described herein.
In one or more embodiments, the virtualization implementation described in this embodiment supports three mainstream chip instruction set architectures of x86, ARM, RISC-V, where the working positions of the user interaction tool, the system driver, and the virtual machine management firmware in the three chip instruction set architectures of x86, ARM, RISC-V are shown in fig. 4. It should be noted that, in the three chip instruction set architecture, the user interaction tool, the system driver, and the virtual machine management firmware only run at the corresponding privilege level have the right to execute the corresponding operation.
The virtualization method can be directly deployed on the hardware device, and also supports the existing operating system of the multiplexing device.
After the virtualization is started, the user performs operations such as creating a new client, checking the state of an existing client, or deleting an unnecessary client through a command corresponding to a user interaction tool in the main client operating system, as shown in fig. 4, which illustrates a specific example after creating the new client.
In the solution described in this embodiment, the whole virtualization implementation uses the existing operating system of the device as a core, and management of all clients is performed in the master client.
In a specific implementation, the user interaction tool specifically performs the following processing procedures:
receiving command input of a user;
When the command is input as an enabling or creating command, reading and analyzing a preset configuration file, sending an analysis result and a corresponding command to a system driver to execute corresponding processing, and receiving and displaying a processing result;
When the command is input as disable, delete or view, the command is directly sent to the system driver to execute corresponding processing, and the processing result is received and displayed.
Specifically, the user interaction tool is an executable program for man-machine interaction in the user space, and provides commands such as enabling, disabling, creating, deleting, viewing and the like for carrying out virtualization management.
And for the enabling and creating command, the contents of the configuration file are read and analyzed, the format of the analyzed contents, the validity of the configuration item and the like are preliminarily checked, the checked contents are sent to the system driver, a return result of the system driver is received, and the return result is displayed to a user. The configuration file is essentially a text file which is convenient for a user to read and write, and the memory, the CPU, various peripheral hardware resources and the like which are needed to be used by the virtual machine and the shared memory statement for communication among different virtual machines are recorded.
For sub-commands such as disabling, deleting, checking and the like, the method directly sends the corresponding command to the driver, waits for the driver to return the corresponding result, and then displays the returned result to the user;
It should be noted that, since the virtualization operation belongs to a privileged operation, and the user interaction tool is essentially a user-state tool, which does not have virtualization rights (the rights of different architectures are classified as shown in fig. 4), all operations thereof need to be processed by the system call routing system driver. The reason is that the chip instruction set architecture design does not allow the user space privilege level to be directly switched to the virtual machine management privilege level, as shown in fig. 4, the user interaction tool, the system driver, and the virtual machine management firmware in the scheme described in this embodiment correspond to three different privilege levels of the user privilege level, the system privilege level, and the virtual machine privilege level, respectively.
Step 2, based on the configuration information in the client configuration file, controlling the virtual machine management firmware to isolate physical hardware resources of each client through system call, and providing a shared memory for communication among clients for each client to realize creation of the clients and communication among the clients, wherein the virtual machine management firmware runs in the memory;
When the virtualization function is enabled, the main client and the sub client are virtual machines, and when the virtualization function is disabled, the main client is an independent operating system.
In a specific implementation, the virtual machine management firmware is controlled to isolate physical hardware resources of different clients through system call, specifically, the system call is generated by a system driver through system call, the virtual machine management firmware is loaded to a memory for running through the super call, and the loaded virtual machine management firmware isolates the physical hardware to different clients.
The system driver is used for loading the virtual machine management firmware and responding to the interaction command from the user interaction tool, and also manages and maintains the basic information of each client, and is a kernel module of the operating system, loaded into the kernel of the operating system by a user, and requires a special privilege level for the virtualization related processing, so that partial commands need to be sent to the virtual machine management firmware through super call to be realized.
Further, the system driver specifically executes the following processing procedures:
Receiving configuration information and commands from a user interaction tool;
And for the enabling and creating commands, copying the content of the configuration information from the user space to the system space, and after verification processing, sending the verified configuration information and the corresponding commands to the virtual machine management firmware.
Specifically, checking processing is performed on the received configuration information or command from the user interaction tool;
after the verification is finished, copying the content of the configuration information from the user space to the system space for the enabling and creating command, then further verifying the version, the identifier, the availability of description resources and the like of the configuration information, and after the verification is finished, managing the configuration information of each client in a linked list form;
The configuration information after verification is sent to the virtual machine management firmware, and the virtual machine management firmware performs the allocation of hardware resources of each client and the hardware isolation operation according to the configuration information, wherein the description needs higher authority for the creation, the enabling and the disabling of commands (the authority grading of different architectures is shown in fig. 4), so that a driver can load the virtual machine management firmware into a memory for execution, and then send certain privileged operations to the virtual machine management firmware for processing through super-calling and return the result.
After successfully isolating the hardware resources, the system driver also needs to create corresponding maintenance nodes and map the maintenance nodes back to the host client to facilitate maintenance of other clients by the host client.
For the inquiry command, the existing management linked list can be traversed directly, corresponding client information is found, and then the client information is returned to the user interaction tool.
In a specific implementation, the virtual machine management firmware is used for isolating physical hardware resources to different clients, so that the different clients only use the visible hardware resources, and the virtual machine management firmware is essentially a section of special binary code which is loaded into a memory by a system driver for running.
In a specific implementation, the hardware isolation function of the virtual machine management firmware is the core of the whole virtualization scheme, and the hardware isolation function is realized by using the hardware virtualization characteristics provided by the processor, so that the implementation method is different for different hardware platforms, specifically as shown in fig. 4, the virtual machine management firmware operates at a specific processor privilege level, the virtual machine management firmware operates at a kernel Mode Ring0 privilege level of a Root Mode for an x86 architecture, the virtual machine management firmware operates at a virtualization Mode EL2 privilege level for an ARM architecture, and the virtual machine management firmware operates at a Hypervisor Mode privilege level for a RISC-V architecture.
In specific implementation, the virtual machine management firmware is used for receiving configuration information and commands from a system driver, carrying out allocation and hardware isolation of hardware resources of different clients according to the configuration information for enabling and creating commands, wherein the configuration information of each client is managed in a linked list form;
Specifically, the virtual machine management firmware is essentially an executable program that receives configuration information and commands from a driver and then processes the commands according to the command types, respectively, wherein:
for enabling and creating commands, initializing the state of a corresponding CPU according to the received configuration information, creating a corresponding memory page table, realizing the resource allocation and hardware isolation of memories and CPUs of different clients, and managing the configuration information of each client through a linked list;
For example, by taking memory isolation as an example, through the extended page table or nested page table technology supported by the hardware virtualization characteristics of the processor, the virtual machine management firmware can directly set the memory mapping of the virtual machine, so as to ensure that each virtual machine can only access the own memory space without passing through a system driver.
It will be appreciated that the allocation of hardware resources and hardware isolation may include other hardware devices such as I/O devices, storage devices, graphics cards, etc., in addition to memory and CPU.
It should be noted that when a new client is created or deleted, the virtual machine management firmware will update synchronization between all existing virtual machines because the virtual machine management firmware needs to suspend all other clients while performing hardware quarantine to ensure security and reliability.
For commands such as disabling, deleting, modifying and inquiring, the virtual machine management firmware inquires the configuration information of the corresponding client machine by traversing the linked list, carries out corresponding processing, and returns a processing result.
In further embodiments, the virtual machine management firmware is further configured to manage shared memory between clients for communication between clients. Wherein the shared memory is defined in the configuration file of each client.
Further, when creating a client, the virtual machine management firmware initializes the resources that can be used by the client only according to the configuration information in the configuration file, and when the client accesses the non-isolated resources, an exception is generated.
In an implementation, the virtual machine management firmware also provides a shared memory for communication between different clients, where the shared memory adopts a one-to-one model, i.e., a shared memory for communication needs to be declared together when any two clients communicate.
Specifically, the shared memory in the scheme described in this embodiment is defined by the configuration files corresponding to each client, and when two clients define the same shared memory in the configuration files, the two clients can communicate through the shared memory.
It should be noted here that, although there is shared memory in both Type I and Type II architectures, their shared memory is directly defined by the VMM, and the user needs to implement the shared memory by configuring the VMM.
The setting of the shared memory according to the scheme of the embodiment can meet the following application requirements:
The host client is typically a non-real time operating system, while the other clients are real time operating systems, in which application the host client acts as a user interaction interface to handle most tasks, whereas for real time tasks the host client is presented with real time operating system information and results of the processing, in this case via communication between the clients. For example, in industrial control, a host client provides a UI interface, while a client with a real-time operating system is responsible for handling various industrial controls with high real-time requirements, and parameters and control results of the controls need to be shared to the host client, so as to be convenient for a user to view.
Furthermore, the setting of the shared memory in this embodiment also allows different clients to share the same device.
In one or more embodiments, the system operated by the client may be a system such as a traditional Linux, android system or various real-time operating systems, and meanwhile, since the scheme in this embodiment is direct physical resource isolation, the bare metal program may also be directly operated.
In one or more embodiments, a lightweight virtualization apparatus is provided, including a hardware module and a software module, where the hardware module includes a CPU, a memory, and an IO device, the software module includes a main guest operating system, a user interaction tool, a system driver, and a virtual machine management firmware, and a lightweight virtualization implementation method as described above is performed based on the software module.
In a specific implementation, when an operating system exists on a certain device, the existing operating system can be selected to be directly multiplexed as a main client, and the user interaction tool, the driver and the virtual mechanism management firmware are installed into the existing operating system as a tool kit for use.
When the device has no operating system, the pre-constructed user interaction tool, driver, virtual machine management firmware and client configuration files can be packaged in the device, then the current virtualization scheme is directly deployed through the system installation tool, and after deployment, the structure of a main client and a plurality of client systems is formed.
In this embodiment, whether deployed directly or with an existing operating system, the user needs to manage (including adding, deleting, modifying, looking up) all clients in the host client and enable or disable the virtualization functionality.
Those of ordinary skill in the art will appreciate that the elements of the various examples described in connection with the present embodiments, i.e., the algorithm steps, can be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The above description is only of the preferred embodiments of the present invention and is not intended to limit the present invention, but various modifications and variations can be made to the present invention by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.