Method, system, device and medium for establishing shared memory between virtual machines
By coordinating between the initiating client and the receiving client under the virtualization platform, shared memory between virtual machines is dynamically established, which solves the problem of inflexible use of shared memory in the existing technology and realizes the flexibility of adding shared memory after running.
Patent Information
- Application Number
- CN202511037597.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-28
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2045-07-28
AI Technical Summary
In the prior art, the strategy for sharing memory between virtual machines stipulates the shared memory before the guest operating system runs, resulting in inflexible use of the shared memory and inability to add shared memory after the guest operating system runs normally.
The initiating client sends a memory message to the receiving client. The virtualization platform saves the client physical address of the initiating client and suspends operation to establish the second-stage address table when all physical cores of the receiving client share the same second-stage address table. After resuming operation, the establishment of the first-stage address table is completed to realize shared memory between virtual machines.
The shared memory can be dynamically established after both client operating systems are running, making the establishment of the shared memory more flexible.
Smart Images

Figure CN120540876B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of memory sharing technology, and in particular to a method, system, device, and medium for establishing shared memory between virtual machines. Background Art
[0002] Currently, in embedded systems with a hypervisor, the memory management unit (MMU) performs a two-stage address translation. The first stage is the translation of the guest virtual address (GVAGuestVirtual Address) to the guest physical address (GPAGuest Physical Address), and the second stage is the translation of the guest physical address to the physical address (PA Physical Address). Both stages of address translation require an address translation table to provide the translation relationship. The first-stage address table is created by the guest operating system (Guest OS), and the second-stage address table is created by the hypervisor for the guest operating system (Guest OS).
[0003] Since shared memory means two guest operating systems (Guest OS) access the same physical memory space, the virtualization platform (hypervisor) needs to create a second-stage address table for this physical memory space, that is, the GPA to PA conversion, and this address translation table is added to the two guest operating systems (Guest OS) respectively; since the address translation relationship strategy is consistent in the virtualization platform (hypervisor), the GPA obtained by the guest operating system (Guest OS) is exactly the same; after the guest operating system (Guest OS) obtains the GPA, each establishes the first-stage address table, that is, the GVA to GPA conversion according to its own address translation relationship strategy; from then on, the guest operating system (Guest OS) can access the shared memory space through the GVA.
[0004] In the current shared memory strategy, before the two guest operating systems (Guest OS) are running, the two guest operating systems (Guest OS) agree on a certain physical memory space as shared memory. The address translation table from GPA to PA is also established before the two guest operating systems (Guest OS) are running. This method makes the use of shared memory inflexible. In other words, after the guest operating system (Guest OS) is running normally, it is impossible to add a piece of shared memory. Summary of the Invention
[0005] In view of this, the present application provides a method, system, device and medium for establishing shared memory between virtual machines, aiming to solve or partially solve the problems existing in the background technology.
[0006] A first aspect of the present application provides a method for establishing shared memory between virtual machines, the method comprising:
[0007] Determine whether a two-stage address table of the initiating client is established, send a memory message to the receiving client through the initiating client, and save the client physical address of the initiating client in the virtualization platform;
[0008] In response to the memory message, initiating a first request to the virtualization platform through a first physical core, where the first physical core is the physical core that receives the memory message;
[0009] In a case where all physical cores of the receiving client share the same second-stage address table, in response to the first request, controlling the receiving client to suspend execution in a second physical core, and establishing a second-stage address table for the receiving client based on the stored client physical address, the second physical core being a physical core that has not received the memory message;
[0010] When the second-stage address table is established, controlling the receiving client to resume operation in the second physical core and sending a completion message to the receiving client;
[0011] In response to the completion message, the corresponding mapping interface is called to complete the establishment of the first-stage address table of the virtual machine, thereby realizing the establishment of shared memory between virtual machines.
[0012] A second aspect of the present application provides a system for establishing shared memory between virtual machines, the system comprising a virtualization platform, an initiating client and a receiving client located in the same hardware device;
[0013] The initiating client is used to determine whether the two-stage address table of the initiating client is established, send a memory message to the receiving client, and save its own client physical address on the virtualization platform;
[0014] The receiving client is configured to initiate a first request to the virtualization platform through a first physical core in response to the memory message, where the first physical core is the physical core that receives the memory message;
[0015] The virtualization platform is configured to, in response to the first request, control the receiving client to suspend execution in a second physical core when all physical cores of the receiving client share the same second-stage address table, and establish a second-stage address table for the receiving client based on the stored client physical address, the second physical core being a physical core that has not received the memory message;
[0016] The virtualization platform is configured to control the receiving client to resume operation in the second physical core and send a completion message to the receiving client when the establishment of the second-stage address table is completed;
[0017] The receiving client is used to call the corresponding mapping interface to complete the establishment of its own first-stage address table in response to the completion message, thereby realizing the establishment of shared memory between virtual machines.
[0018] The third aspect of the present application provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and running on the processor, wherein when the computer program is executed by the processor, the steps in the method for establishing shared memory between virtual machines as described in the first aspect of the present application are implemented.
[0019] The fourth aspect of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the method for establishing shared memory between virtual machines as described in the first aspect of the present application are implemented.
[0020] The method for establishing shared memory between virtual machines provided in this application has the following advantages:
[0021] The present application provides a method for establishing shared memory between virtual machines. The method comprises the following steps: determining whether a two-stage address table of an initiating client is established, sending a memory message to a receiving client via the initiating client, and saving the client physical address of the initiating client on a virtualization platform; in response to the memory message, initiating a first request to the virtualization platform via a first physical core, where the first physical core is the physical core that receives the memory message; in the case where all physical cores of the receiving client share the same second-stage address table, in response to the first request, controlling the receiving client to suspend operation in a second physical core, and establishing a second-stage address table for the receiving client based on the saved client physical address, where the second physical core is the physical core that has not received the memory message; in the case where the establishment of the second-stage address table is completed, controlling the receiving client to resume operation in the second physical core, and sending a completion message to the receiving client; in response to the completion message, calling a corresponding mapping interface to complete the establishment of its own first-stage address table, thereby achieving the establishment of shared memory between virtual machines. Thus, the method for establishing shared memory between virtual machines provided by the present application can achieve the establishment of shared memory even after both client operating systems are running, thereby making the establishment of shared memory more flexible. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following is a brief introduction to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0023] Figure 1 A schematic diagram of an ARM security domain architecture in a method for establishing shared memory between virtual machines, according to one embodiment of the present application;
[0024] Figure 2 This is a schematic diagram illustrating the operation of a memory management unit in a method for establishing shared memory between virtual machines according to an embodiment of the present application;
[0025] Figure 3 This is a flowchart of a method for establishing shared memory between virtual machines according to an embodiment of the present application;
[0026] Figure 4 This is a flowchart of establishing a single second-stage address table in a method for establishing shared memory between virtual machines, as shown in one embodiment of the present application;
[0027] Figure 5 This is a flowchart of establishing multiple second-stage address tables in a method for establishing shared memory between virtual machines, as shown in one embodiment of the present application;
[0028] Figure 6 A schematic diagram of a system for establishing shared memory between virtual machines is shown in accordance with an embodiment of the present application. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0030] Before describing the method for establishing shared memory between virtual machines provided by this application, various technical terms involved are explained, as well as the background of this application:
[0031] Non-Secure World
[0032] Secure World
[0033] Hypervisor: Virtualization platform, or virtualized operating system
[0034] VM: virtual machine, virtual machine, virtual hardware
[0035] Guest OS: The guest operating system running on the VM
[0036] APP: Application running on the operating system
[0037] MMU: memory manager unit, memory management unit
[0038] GVA: Virtual Address on Guest OS
[0039] GPA: Physical Address on Guest OS
[0040] PA: Physical Address, corresponding to the real physical address
[0041] like Figure 1 As shown in the figure, on the ARMv8-A IP core, there are 4 EL levels, namely EL0, EL1, EL2 and EL3. EL3 runs security monitoring. The secure world has 3 EL levels. The EL3 level is divided into two worlds, namely the secure world and the non-secure world. In the non-secure world, there are 3 EL levels, namely EL0, EL1 and EL2. EL0 runs rich environment applications (Rich Environment APP), EL1 runs the guest operating system (Guest OS), and EL2 runs the virtualization platform (hypervisor). In the secure world, there is no EL2 level. EL1 runs the trusted operating system (Trust OS) and EL0 runs the trusted application (Trust APP).
[0042] Currently, in embedded systems with a hypervisor, the two-stage address translation of the memory management unit (MMU) is enabled, such as Figure 2 As shown, Figure 2The figure shows how the memory management unit works; the first stage is the conversion of the guest virtual address (GVA Guest Virtual Address) to the guest physical address (GPA Guest Physical Address), and the second stage is the conversion of the guest physical address to the physical address (PA Physical Address). The address conversion in the above two stages requires an address translation table to provide the conversion relationship; the address table in the first stage is established by the guest operating system (Guest OS), and the address table in the second stage is established by the virtualization platform (hypervisor) for the guest operating system (Guest OS).
[0043] Since shared memory means two guest operating systems (Guest OS) access the same physical memory space, the virtualization platform (hypervisor) needs to create a second-stage address table for this physical memory space, that is, the GPA to PA conversion, and this address translation table is added to the two guest operating systems (Guest OS) respectively; since the address translation relationship strategy is consistent in the virtualization platform (hypervisor), the GPA obtained by the guest operating system (Guest OS) is exactly the same; after the guest operating system (Guest OS) obtains the GPA, each establishes the first-stage address table, that is, the GVA to GPA conversion according to its own address translation relationship strategy; from then on, the guest operating system (Guest OS) can access the shared memory space through the GVA.
[0044] In current shared memory strategies, both guest operating systems (OSs) agree on a block of physical memory space for shared memory before they run. The GPA to PA address translation table is also established before both guest operating systems (OSs) run. This approach makes shared memory inflexible. In other words, adding shared memory after the guest operating systems (OSs) are running is impossible. To address this issue, this application proposes a method for establishing shared memory between virtual machines.
[0045] The following implementation discusses deployments within the non-secure world at the EL1 and EL2 levels. In current embedded systems, operating systems run on multiple cores in hardware, each with its own non-secure worlds of EL1 and EL2. Therefore, the hypervisor runs in the non-secure world of EL2 on all cores, while the guest OS runs in the non-secure world of EL1 on some cores. The hypervisor creates a second-stage address table for each physical core hosting the guest OS. Each guest OS creates a first-stage address table for all its cores. There are two options for creating the second-stage translation table for the guest OS's physical cores. One approach is to use the same second-stage translation table for each guest OS's physical core, storing the second-stage address table for each core in the same physical space. Alternatively, each physical core in the guest OS uses a different second-stage translation table. This means that each core's second-stage address table is stored in a different physical space, while these different physical spaces store the same address translation relationships. The following discusses how to dynamically establish shared memory while the guest OS is running, taking these two scenarios into account.
[0046] refer to Figure 3 , Figure 3 This is a flow chart showing a method for establishing shared memory between virtual machines according to an embodiment of the present application. Figure 3 As shown, the method includes:
[0047] Step S1: determine whether the two-stage address table of the initiating client is established, send a memory message to the receiving client through the initiating client, and save the client physical address of the initiating client in the virtualization platform.
[0048] In this embodiment, the initiating client is the guest operating system that initiates memory sharing, and the receiving client is the guest operating system that establishes shared memory in response to a corresponding request. The initiating client first determines whether its own two-stage address table has been successfully established. If so, the initiating client sends a memory message to the receiving client via the virtualization platform. Simultaneously, the initiating client saves its guest physical address (GPA Guest Physical Address) to the virtualization platform for subsequent establishment of a second-stage address table for the receiving client. The guest operating system is the GuestOS, the virtualization platform is the hypervisor, the first-stage address table is a GVA address to GPA address translation table, and the second-stage address table is a GPA address to PA address translation table.
[0049] Step S2: In response to the memory message, a first request is initiated to the virtualization platform through a first physical core, where the first physical core is the physical core that receives the memory message.
[0050] In this embodiment, when a receiving client receives a memory message sent by an initiating client, the receiving client responds to the memory message by invoking an instruction via a first physical core that traps from the privilege level (i.e., EL1) to the virtualization monitoring layer (EL2) and initiates a first request to the virtualization platform to establish a second-stage address table for the receiving client. The first physical core is the physical core assigned to the receiving client and the physical core that received the memory message.
[0051] Step S3: When all physical cores of the receiving client share the same second-stage address table, in response to the first request, the receiving client is controlled to suspend operation in the second physical core, and a second-stage address table is established for the receiving client based on the saved client physical address. The second physical core is the physical core that has not received the memory message.
[0052] In this embodiment, all physical cores of the receiving client share the same second-stage address table, which means that when each physical core assigned to the receiving client runs the receiving client, each physical core will share the same second-stage address table stored in the same physical space location, and the second-stage address table is established for the receiving client. In the case where all physical cores of the receiving client share the same second-stage address table, the virtualization platform will control the receiving client to suspend operation in each second physical core in response to a first request received from the receiving client via the first physical core, and establish a second-stage address table for the receiving client based on the guest physical address (GPA Guest Physical Address) of the initiating client saved in step S1. The second physical core is a physical core that has not received the memory message and is also a physical core assigned to the receiving client.
[0053] In this embodiment, when all physical cores of the receiving client share the same second-stage address table established for the receiving client, all physical cores of the initiating client also share the same second-stage address table established for the initiating client.
[0054] Step S4: When the establishment of the second-stage address table is completed, the receiving-end client is controlled to resume operation in the second physical core, and a completion message is sent to the receiving-end client.
[0055] In this embodiment, when the virtualization platform completes the establishment of the second-stage address table for the receiving client, the virtualization platform will control the receiving client to resume operation in the second physical core that was previously paused, and send a completion message to the receiving client to complete the establishment of the second-stage address table.
[0056] Step S5: In response to the completion message, the corresponding mapping interface is called to complete the establishment of the first-stage address table of the virtual machine, thereby realizing the establishment of shared memory between virtual machines.
[0057] In this embodiment, in response to the completion message sent by the virtualization platform, the receiving client will call the mapping interface of the guest virtual address (GVA Guest Virtual Address) to the guest physical address (GPA Guest Physical Address) to complete the establishment of the first-stage address table of the receiving client itself, thereby realizing the establishment of shared memory between the virtual machines where the initiating client and the receiving client are located.
[0058] The present application provides a method for establishing shared memory between virtual machines. The method comprises the following steps: determining whether a two-stage address table of an initiating client is established, sending a memory message to a receiving client via the initiating client, and saving the client physical address of the initiating client on a virtualization platform; in response to the memory message, initiating a first request to the virtualization platform via a first physical core, where the first physical core is the physical core that receives the memory message; in the case where all physical cores of the receiving client share the same second-stage address table, in response to the first request, controlling the receiving client to suspend operation in a second physical core, and establishing a second-stage address table for the receiving client based on the saved client physical address, where the second physical core is the physical core that has not received the memory message; in the case where the establishment of the second-stage address table is completed, controlling the receiving client to resume operation in the second physical core, and sending a completion message to the receiving client; in response to the completion message, calling a corresponding mapping interface to complete the establishment of its own first-stage address table, thereby achieving the establishment of shared memory between virtual machines. Thus, the method for establishing shared memory between virtual machines provided by the present application can achieve the establishment of shared memory even after both client operating systems are running, thereby making the establishment of shared memory more flexible.
[0059] In combination with the above embodiments, in one embodiment, the present application also provides a method for establishing shared memory between virtual machines. In the method for establishing shared memory between virtual machines, step S3 may include steps S31 to S33:
[0060] Step S31: In response to the first request, query the second physical cores allocated to the receiving client through the first physical core, and send a second request to each second physical core through the first physical core.
[0061] In this embodiment, if Figure 4 As shown, if all physical cores of a receiving client share the same second-stage address table, the virtualization platform, in response to a first request received from the receiving client via a first physical core, queries the second physical cores allocated to the receiving client via the first physical core and sends a second request to each second physical core via the first physical core. After sending the second request to each second physical core, the virtualization platform waits for feedback from all second physical cores.
[0062] Step S32: In response to the second request, each of the second physical cores kicks the currently running receiving client task out of the scheduling queue, switches to the subsequent non-receiving client task, and feeds back a first response message.
[0063] In this embodiment, after receiving the second request sent by the virtualization platform through the first physical core, each second physical core, in response to the second request, removes the currently running receiving client task from the scheduling queue and switches to a subsequent non-receiving client task. After the second physical core switches to the non-receiving client task, it returns its own first response message. The first response message returned by each second physical core indicates that it has currently suspended execution of the receiving client.
[0064] Step S33: In response to the received first response messages fed back by all second physical cores, a second-stage address table is established for the receiving-end client based on the stored client physical address.
[0065] In this embodiment, when the virtualization platform receives the first response message fed back by all the second physical cores, it indicates that the second physical cores currently allocated to the receiving-end client have suspended the operation of the receiving-end client. At this time, in response to the first response message fed back by all the received second physical cores, the virtualization platform establishes a second-stage address table for the receiving-end client through the first physical core based on the saved client physical address of the initiating client. The second-stage address table is: when each physical core allocated to the receiving-end client runs the receiving-end client, each physical core will share the same second-stage address table stored in the same physical space.
[0066] In combination with the above embodiments, in one embodiment, the present application also provides a method for establishing shared memory between virtual machines. In the method for establishing shared memory between virtual machines, step S4 may include steps S41 to S43:
[0067] Step S41: When the second-stage address table is established, a third request is sent to each of the second physical cores through the first physical core.
[0068] In this embodiment, if Figure 4 As shown, after the virtualization platform completes establishing the second-stage address table for the receiving client, the virtualization platform sends a third request to each second physical core through the first physical core to resume operation of the receiving client. After sending the third request to each second physical core, the virtualization platform waits for feedback messages from all second physical cores.
[0069] Step S42: In response to the third request, each of the second physical cores adds the task of the receiving client to the scheduling queue and feeds back a second response message.
[0070] In this embodiment, after receiving the third request sent by the virtualization platform through the first physical core, each second physical core, in response to the third request, adds the receiving client's task to its own scheduling queue. After adding the receiving client's task to its own scheduling queue, the second physical core returns its own second response message. The second response message returned by each second physical core indicates that it has resumed operation for the receiving client.
[0071] In this embodiment, the second response message fed back by the second physical core indicates that it has currently resumed the operation of the receiving client, which means that through the control of the virtualization platform, the receiving client's task is added to the scheduling queue of the corresponding second physical core. The receiving client's task has a running time slice, but it still needs to return to the privilege level (i.e., EL1 level) to actually run the task.
[0072] Step S43: In response to the second response messages received from all second physical cores, a completion message is sent to the receiving client through the first physical core, and instructions from the virtualization monitoring layer level to the privileged level are called, and the privileged level is returned to run the receiving client.
[0073] In this embodiment, when the virtualization platform receives second response messages from all second physical cores, indicating that all second physical cores currently assigned to the receiving client have resumed the receiving client's operation, the virtualization platform, in response to the second response messages received from all second physical cores, sends a completion message to the receiving client via the first physical core, completing the second-stage address table establishment. Simultaneously, the virtualization platform invokes instructions from the virtualization monitoring layer level (i.e., EL2) to the privileged level (i.e., EL1), returning to the privileged level to resume the receiving client's operation, thereby enabling the receiving client to truly execute its tasks.
[0074] In combination with the above embodiments, in one embodiment, the embodiment of the present application further provides a method for establishing shared memory between virtual machines. In the method for establishing shared memory between virtual machines, step S32 may include: when the second physical core is an exclusive core, in response to the received second request, the second physical core kicks the currently running task of the receiving client out of the scheduling queue, switches to an idle task, and feeds back a first response message; when the second physical core is a shared core, in response to the received second request, the second physical core determines the type of task currently running; when the currently running task type is the task of the receiving client, the currently running task of the receiving client is kicked out of the scheduling queue, switched to the subsequent task of the initiating client, and the first response message is fed back; when the currently running task type is the task of the initiating client, the first response message is fed back.
[0075] In this embodiment, when allocating physical cores to guest operating systems, there are two scenarios: a single physical core is allocated to one guest operating system; and a single physical core is allocated to two guest operating systems simultaneously. When a single physical core is allocated to one guest operating system, it is called an exclusive core; when a single physical core is allocated to two guest operating systems simultaneously, it is called a shared core.
[0076] In this embodiment, when the second physical core is an exclusive core, the scheduling queue of the second physical core is full of tasks of the client operating system to which it belongs, and the second physical core is a physical core allocated to the receiving client, so the scheduling queue of the second physical core is full of tasks of the receiving client. Therefore, after receiving the second request, the second physical core will respond to the second request by kicking the currently running task of the receiving client out of the scheduling queue and switching it to an idle task (i.e., an idle task, which is used to ensure that the CPU remains running when there are no other tasks to run, thereby preventing the system from idling). After the scheduling queue of the second physical core is switched to an idle task, its own first response message is fed back to the virtualization platform of the first physical core.
[0077] In this embodiment, when the second physical core is a shared core, the scheduling queue of the second physical core will contain both the tasks of the initiating client and the tasks of the receiving client. Figure 4 As shown, after receiving the second request, the second physical core responds to the second request and determines the type of task currently running. When the type of task currently running is the task of the receiving-end client, the second physical core will kick the currently running task of the receiving-end client out of the scheduling queue and switch to the subsequent task of the initiating-end client. After the scheduling queue of the second physical core switches to the subsequent task of the initiating-end client, it feeds back its own first response message to the virtualization platform of the first physical core. When the type of task currently running is the task of the initiating-end client, the currently running task of the initiating-end client will not affect the virtualization platform's establishment of the second-stage address table for the receiving-end client. At this time, the second physical core will directly feed back the first response message.
[0078] In this embodiment, when all physical cores of the receiving-end client share the same second-stage address table, the virtualization platform only establishes one second-stage address table for the receiving-end client. During the establishment process, if other second physical cores continue to run the receiving-end client, it will affect the establishment of the second-stage address table. Therefore, this application will suspend the second physical core from running the receiving-end client, and the virtualization platform will establish the second-stage address table for the receiving-end client through the first physical core.
[0079] In conjunction with the above embodiments, in one implementation, an embodiment of the present application further provides a method for establishing shared memory between virtual machines. In this method for establishing shared memory between virtual machines, the method further includes: establishing a second-stage address table for the initiating client before the initiating client is started, when all physical cores of the receiving client share the same second-stage address table; and while the initiating client is running, making a memory request at a privilege level to establish its own first-stage address table.
[0080] In this embodiment, when all physical cores of the receiving client share the same second-stage address table, the initiating client's first-stage address table and second-stage address table are established as follows: before the initiating client is started, the virtualization platform establishes the second-stage address table for the initiating client. When the initiating client is operating normally, the initiating client applies for memory at the privilege level (i.e., EL1) (for example, by calling a function such as malloc), thereby establishing the first-stage address table for the initiating client. This completes the establishment of the first-stage address table and the second-stage address table for the initiating client.
[0081] In conjunction with the above embodiments, in one implementation, the present application also provides a method for establishing shared memory between virtual machines. In the method for establishing shared memory between virtual machines, the method further includes:
[0082] Step S6: In the case where each physical core of the receiving-end client uses its own corresponding second-stage address table, in response to the first request, a second-stage address table corresponding to each receiving-end physical core is established for the receiving-end client based on the saved client physical address, and the receiving-end physical core is the physical core allocated to the receiving-end client.
[0083] In this embodiment, each physical core of the receiving client uses its own corresponding second-stage address table. This means that each physical core assigned to the receiving client will use its own second-stage address table when running the receiving client. That is, each physical core assigned to the receiving client will have a corresponding second-stage address table. Each second-stage address table is stored in a different physical space, and all of these second-stage address tables are established for the receiving client. Although each receiving physical core calls a different second-stage address table, the contents recorded in each second-stage address table are identical. When each physical core of the receiving client uses its own corresponding second-stage address table, in response to a first request received from the receiving client via a first physical core, the virtualization platform will establish a second-stage address table corresponding to each receiving physical core for the receiving client. In other words, the virtualization platform will establish as many second-stage address tables for the receiving client as there are receiving physical cores assigned to the receiving client. Each receiving physical core has a corresponding second-stage address table, and when a receiving physical core runs the receiving client, it uses the second-stage address table corresponding to that receiving physical core. The receiving-end physical core refers to a physical core allocated to the receiving-end client, and the receiving-end physical core includes a first physical core and a second physical core allocated to the receiving-end client.
[0084] Step S7: When all the second-stage address tables are created, a completion message is sent to the receiving client.
[0085] In this embodiment, when the virtualization platform completes the establishment of the second-stage address table corresponding to each receiving-end physical core through step S6, the virtualization platform sends a completion message of completing the establishment of the second-stage address table to the receiving-end client.
[0086] Step S8: In response to the completion message, the corresponding mapping interface is called to complete the establishment of the first-stage address table of the virtual machine, thereby realizing the establishment of shared memory between virtual machines.
[0087] In this embodiment, in response to the completion message sent by the virtualization platform, the receiving client will call the mapping interface of the guest virtual address (GVA Guest Virtual Address) to the guest physical address (GPA Guest Physical Address) to complete the establishment of the first-stage address table of the receiving client itself, thereby realizing the establishment of shared memory between the virtual machines where the initiating client and the receiving client are located.
[0088] In combination with the above embodiments, in one embodiment, the embodiment of the present application further provides a method for establishing shared memory between virtual machines. In the method for establishing shared memory between virtual machines, step S6 may include: in response to the first request, based on the saved client physical address, establishing a second-stage address table corresponding to the first physical core for the receiving client through the first physical core; in response to the first request, querying the second physical core allocated to the receiving client through the first physical core, and sending a fourth request to each second physical core respectively through the first physical core; in response to the received fourth request, establishing a second-stage address table corresponding to the second physical core for the receiving client through the second physical core, and feeding back a third response message.
[0089] In this embodiment, if Figure 5 As shown, in the case where each physical core of the receiving client uses its own corresponding second-stage address table, in response to a first request received from the receiving client via the first physical core, the virtualization platform establishes a second-stage address table corresponding to the first physical core for the receiving client based on the stored client physical address of the initiating client. Simultaneously, in response to the first request received from the receiving client via the first physical core, the virtualization platform queries the second physical core assigned to the receiving client via the first physical core and sends a fourth request to each second physical core via the first physical core to establish a second-stage address table for the receiving client.
[0090] In this embodiment, since each second physical core responds to the fourth request in the same way after receiving it, the response of a second physical core is taken as an example for explanation: after the second physical core receives the fourth request, in response to the fourth request, the virtualization platform establishes a second-stage address table corresponding to the second physical core for the receiving client through the second physical core, and feeds back a third response message to the first physical core through the second physical core, and the third response message is used to indicate that the second physical core has completed the establishment of its own corresponding second-stage address table. Through the same implementation method, each second physical core will establish its own corresponding second-stage address table through the virtualization platform, and feed back its own corresponding third response message to the first physical core. It should be understood that the second-stage address table established by each second physical core through the virtualization platform is established for the receiving client.
[0091] In conjunction with the above embodiments, in one implementation, the present application also provides a method for establishing shared memory between virtual machines. In this method for establishing shared memory between virtual machines, step S7 may include: in response to the third response messages received from all second physical cores, sending a completion message to the receiving client via the first physical core; and invoking an instruction from the virtualization monitoring layer level to the privileged level, returning to the privileged level to execute the receiving client.
[0092] In this embodiment, if Figure 5 As shown, after the virtualization platform receives the third response message from all second physical cores via the first physical core, indicating that each second physical core has completed the establishment of the corresponding second-stage address table, the virtualization platform, in response to the third response messages received from all second physical cores, sends a completion message to the receiving client via the first physical core, confirming the completion of the second-stage address table establishment. Simultaneously, after sending this completion message, the virtualization platform invokes an instruction from the virtualization monitoring layer level (i.e., EL2 level) to the privileged level (i.e., EL1 level), returning to the privileged level to execute the receiving client, thereby enabling the receiving client to actually execute its task.
[0093] In conjunction with the above embodiments, in one implementation, an embodiment of the present application further provides a method for establishing shared memory between virtual machines. In the method for establishing shared memory between virtual machines, the method further includes: before the initiating client is started, establishing a second-stage address table corresponding to each initiating physical core for the initiating client, where each physical core of the receiving client uses its own corresponding second-stage address table; the initiating physical core is a physical core assigned to the initiating client; and when the initiating client is running, making a memory request at a privilege level to implement the establishment of its own first-stage address table.
[0094] In this embodiment, while each physical core of the receiving client uses its own corresponding second-stage address table, the initiating client's first-stage address table and second-stage address table are established as follows: before the initiating client starts, the virtualization platform establishes a second-stage address table corresponding to each initiating physical core for the initiating client. Specifically, the virtualization platform establishes as many second-stage address tables for the initiating client as there are initiating physical cores assigned to the initiating client. Each initiating physical core has a corresponding second-stage address table. When the initiating physical core runs the initiating client, it uses the second-stage address table corresponding to that initiating physical core. The initiating physical core refers to the physical core assigned to the initiating client. When the initiating client begins normal operation, it requests memory at the privilege level (i.e., EL1) (e.g., calling functions such as malloc) to establish the first-stage address table. This completes the establishment of the first-stage address table and the second-stage address table for the initiating client.
[0095] In this embodiment, after the virtualization platform is built, it can only establish the second-stage address table for the receiving client in one of two ways, and cannot select one of the two ways to complete the establishment of the second-stage address table for the receiving client after it is built. The two ways are: establishing a master second-stage address table for the receiving client; and establishing multiple second-stage address tables for the receiving client, each of which corresponds to each physical core allocated to the receiving client. In this method, each second-stage address table is stored in a different physical space.
[0096] Based on the same inventive concept, an embodiment of the present application provides a system for establishing shared memory between virtual machines, such as Figure 6 As shown, the system 600 for establishing shared memory between virtual machines includes: a virtualization platform 601, an initiating client 602 and a receiving client 603 located in the same hardware device, wherein the hardware device includes: a personal computer, a server, a mobile device (such as a mobile phone, a tablet), etc.;
[0097] The initiating client 602 is used to determine whether the two-stage address table of the initiating client is established, send a memory message to the receiving client, and save its own client physical address in the virtualization platform;
[0098] The receiving client 603 is configured to initiate a first request to the virtualization platform through a first physical core in response to the memory message, where the first physical core is the physical core that receives the memory message;
[0099] The virtualization platform 601 is configured to, in response to the first request, control the receiving client to suspend execution in a second physical core when all physical cores of the receiving client share the same second-stage address table, and establish a second-stage address table for the receiving client based on the stored client physical address, where the second physical core is a physical core that has not received the memory message;
[0100] The virtualization platform 601 is configured to control the receiving client to resume operation in the second physical core and send a completion message to the receiving client when the establishment of the second-stage address table is completed;
[0101] The receiving client 603 is used to call the corresponding mapping interface to complete the establishment of its own first-stage address table in response to the completion message, thereby realizing the establishment of shared memory between virtual machines.
[0102] Optionally, the virtualization platform 601 is configured to, in response to the first request, query, through the first physical core, a second physical core allocated to the receiving client, and send, through the first physical core, a second request to each second physical core;
[0103] Each of the second physical cores is configured to, in response to the second request, kick the task of the receiving client currently being run by the second physical core out of the scheduling queue, switch to a subsequent task of the non-receiving client, and feed back a first response message;
[0104] The virtualization platform 601 is configured to establish a second-stage address table for the receiving client based on the stored client physical address in response to the received first response messages fed back by all second physical cores.
[0105] Optionally, the virtualization platform 601 is configured to send a third request to each of the second physical cores through the first physical core when the establishment of the second-stage address table is completed;
[0106] Each of the second physical cores is configured to add the receiving client's task to a scheduling queue in response to the third request, and feed back a second response message;
[0107] The virtualization platform 601 is used to respond to the second response messages fed back by all the second physical cores received, send a completion message to the receiving client through the first physical core, call instructions from the virtualization monitoring layer level to the privileged level, and return to the privileged level to run the receiving client.
[0108] Optionally, the second physical core is configured to, when being an exclusive core, in response to receiving the second request, kick the currently running task of the receiving client out of the scheduling queue, switch it to an idle task, and feed back a first response message;
[0109] The second physical core is used to determine the type of the currently running task in response to the second request received when it is a shared core; and, when the type of the currently running task is the task of the receiving-end client, kick the currently running task of the receiving-end client out of the scheduling queue, switch to the subsequent task of the initiating-end client, and feed back a first response message; and, when the type of the currently running task is the task of the initiating-end client, feed back the first response message.
[0110] Optionally, the virtualization platform 601 is configured to establish a second-stage address table for the initiating client before the initiating client is started, in the case where all physical cores of the receiving client share the same second-stage address table;
[0111] The initiator client 602 is used to apply for memory at a privilege level when the initiator client is running, so as to establish its own first-stage address table.
[0112] Optionally, the virtualization platform 601 is configured to, in response to the first request, establish, based on the stored client physical address, a second-stage address table corresponding to each receiving-end physical core for the receiving-end client, when each physical core of the receiving-end client uses its own corresponding second-stage address table, where the receiving-end physical core is a physical core allocated to the receiving-end client;
[0113] The virtualization platform 601 is used to send a completion message to the receiving client when all the second-stage address tables are established;
[0114] The receiving client 603 is used to call the corresponding mapping interface to complete the establishment of its own first-stage address table in response to the completion message, thereby realizing the establishment of shared memory between virtual machines.
[0115] Optionally, the virtualization platform 601 is configured to establish, in response to the first request, a second-stage address table corresponding to the first physical core for the receiving-end client based on the stored client physical address through the first physical core;
[0116] The virtualization platform 601 is configured to query, through the first physical core, the second physical core allocated to the receiving client in response to the first request, and send, through the first physical core, a fourth request to each second physical core;
[0117] The virtualization platform 601 is configured to, in response to the received fourth request, establish a second-stage address table corresponding to the second physical core for the receiving client through the second physical core, and feed back a third response message.
[0118] Optionally, the virtualization platform 601 is used to send a completion message to the receiving client through the first physical core in response to the third response message received from all second physical cores; and to call instructions from the virtualization monitoring layer level to the privileged level, and return to the privileged level to run the receiving client.
[0119] Optionally, the virtualization platform 601 is configured to establish, for the initiating client before the initiating client is started, a second-stage address table corresponding to each initiating-end physical core, in a case where each physical core of the receiving-end client uses its own corresponding second-stage address table. The initiating-end physical core is a physical core allocated to the initiating client.
[0120] The initiator client 602 is used to apply for memory at a privilege level when the initiator client is running, so as to establish its own first-stage address table.
[0121] Based on the same inventive concept, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a computer program stored on the memory and running on the processor. When the computer program is executed by the processor, it implements the steps in a method for establishing shared memory between virtual machines as described in the first aspect of the present application.
[0122] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps in the method for establishing shared memory between virtual machines as described in the first aspect of the present application are implemented.
[0123] As for the system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0124] It should be noted that for the 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 embodiments of the present application are not limited by the order of the actions described, because according to the embodiments of the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions involved are not necessarily required by the embodiments of the present application.
[0125] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0126] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the embodiments of the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the embodiments of the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0127] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the steps in the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0128] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0129] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0130] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0131] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.
[0132] The above is a detailed introduction to the method, system, device and medium for establishing shared memory between virtual machines provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for establishing shared memory between virtual machines, characterized in that: The method comprises: Determine whether a two-stage address table of the initiating client is established, send a memory message to the receiving client through the initiating client, and save the client physical address of the initiating client in the virtualization platform; In response to the memory message, initiating a first request to the virtualization platform through a first physical core, where the first physical core is the physical core that receives the memory message; In a case where all physical cores of the receiving client share the same second-stage address table, in response to the first request, controlling the receiving client to suspend execution in a second physical core, and establishing a second-stage address table for the receiving client based on the stored client physical address, the second physical core being a physical core that has not received the memory message, wherein the second-stage address table is a translation table from client physical addresses to physical addresses; When the second-stage address table is established, controlling the receiving client to resume operation in the second physical core and sending a completion message to the receiving client; In response to the completion message, the corresponding mapping interface is called to complete the establishment of its own first-stage address table, thereby realizing the establishment of shared memory between virtual machines, wherein the first-stage address table is a translation table from guest virtual address to guest physical address.
2. The method for establishing shared memory between virtual machines according to claim 1, wherein: In response to the first request, controlling the receiving client to suspend execution in the second physical core, and establishing a second-stage address table for the receiving client based on the stored client physical address, including: In response to the first request, querying, through the first physical core, a second physical core allocated to the receiving client, and sending, through the first physical core, a second request to each second physical core; In response to the second request, each of the second physical cores kicks the currently running task of the receiving client out of the scheduling queue, switches to a subsequent task of a non-receiving client, and feeds back a first response message; In response to the received first response messages fed back by all the second physical cores, a second-stage address table is established for the receiving-end client based on the stored client physical address.
3. The method for establishing shared memory between virtual machines according to claim 1, wherein: When the second-stage address table is established, controlling the receiving client to resume operation in the second physical core and sending a completion message to the receiving client includes: When the second-stage address table is established, sending a third request to each of the second physical cores through the first physical core; In response to the third request, each of the second physical cores adds the task of the receiving client to a scheduling queue and feeds back a second response message; In response to the second response messages received from all second physical cores, a completion message is sent to the receiving client through the first physical core, and instructions from the virtualization monitoring layer level to the privileged level are called, and the privileged level is returned to run the receiving client.
4. The method for establishing shared memory between virtual machines according to claim 2, wherein: In response to the second request, each of the second physical cores kicks the currently running receiving client task out of the scheduling queue, switches to a subsequent non-receiving client task, and feeds back a first response message, including: When the second physical core is an exclusive core, in response to receiving the second request, the second physical core kicks the currently running task of the receiving client out of the scheduling queue, switches it to an idle task, and feeds back a first response message; In a case where the second physical core is a shared core, in response to receiving the second request, the second physical core determines a type of a currently running task; When the currently running task type is a task of a receiving client, the currently running task of the receiving client is kicked out of the scheduling queue, switched to the subsequent task of the initiating client, and the first response message is fed back; When the currently running task type is a task of the initiating client, a first response message is fed back.
5. The method for establishing shared memory between virtual machines according to claim 1, wherein: The method further comprises: In the case where all physical cores of the receiving client share the same second-stage address table, before the initiating client is started, establishing the second-stage address table for the initiating client; When the initiator client is running, a memory request is made at a privilege level to establish its own first-stage address table.
6. The method for establishing shared memory between virtual machines according to claim 1, wherein: The method further comprises: In a case where each physical core of the receiving client uses its own corresponding second-stage address table, in response to the first request, establishing a second-stage address table corresponding to each receiving-end physical core for the receiving client based on the stored client physical address, the receiving-end physical core being a physical core allocated to the receiving client; When all second-stage address tables are established, a completion message is sent to the receiving client; In response to the completion message, the corresponding mapping interface is called to complete the establishment of the first-stage address table of the virtual machine, thereby realizing the establishment of shared memory between virtual machines.
7. The method for establishing shared memory between virtual machines according to claim 6, wherein: In response to the first request, based on the stored client physical address, establishing a second-stage address table corresponding to each receiving-end physical core for the receiving-end client, including: In response to the first request, based on the stored client physical address, establish, by the first physical core, a second-stage address table corresponding to the first physical core for the receiving-end client; In response to the first request, querying, through the first physical core, a second physical core allocated to the receiving client, and sending, through the first physical core, a fourth request to each second physical core; In response to the received fourth request, a second-stage address table corresponding to the second physical core is established for the receiving-end client through the second physical core, and a third response message is fed back.
8. The method for establishing shared memory between virtual machines according to claim 7, wherein: After all second-stage address table creation is completed, a completion message is sent to the receiving client, including: In response to the received third response messages from all second physical cores, sending a completion message to the receiving client through the first physical core; Call instructions from the virtualization monitoring layer level to the privileged level and return to the privileged level to run the receiving client.
9. The method for establishing shared memory between virtual machines according to claim 6, wherein: The method further comprises: In a case where each physical core of the receiving client uses its own corresponding second-stage address table, before the initiating client is started, a second-stage address table corresponding to each initiating physical core is established for the initiating client, where the initiating physical core is the physical core allocated to the initiating client; When the initiator client is running, a memory request is made at a privilege level to establish its own first-stage address table.
10. A system for establishing shared memory between virtual machines, characterized in that: The system includes a virtualization platform, an initiating client and a receiving client located in the same hardware device; The initiating client is used to determine whether the two-stage address table of the initiating client is established, send a memory message to the receiving client, and save its own client physical address on the virtualization platform; The receiving client is configured to initiate a first request to the virtualization platform through a first physical core in response to the memory message, where the first physical core is the physical core that receives the memory message; The virtualization platform is configured to, in response to the first request, control the receiving client to suspend execution in a second physical core when all physical cores of the receiving client share the same second-stage address table, and establish a second-stage address table for the receiving client based on the stored client physical address, wherein the second physical core is a physical core that has not received the memory message, wherein the second-stage address table is a translation table from client physical addresses to physical addresses; The virtualization platform is configured to control the receiving client to resume operation in the second physical core and send a completion message to the receiving client when the establishment of the second-stage address table is completed; The receiving client is used to respond to the completion message and call the corresponding mapping interface to complete the establishment of its own first-stage address table, thereby realizing the establishment of shared memory between virtual machines, wherein the first-stage address table is a translation table from client virtual address to client physical address.
11. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and running on the processor, wherein when the computer program is executed by the processor, the steps in the method for establishing shared memory between virtual machines as described in any one of claims 1 to 9 are implemented.
12. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the method for establishing shared memory between virtual machines according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Virtual machine communication method based on shared memory
CN101667144A
Technologies for secure inter-virtual-machine shared memory communication
US20160048464A1