A memory management method, device and electronic device for a virtual machine
The virtual machine manager establishes the mapping relationship between the virtual machine physical address and the secure memory space in the nested page table, which solves the pressure problem of the secure processor when allocating secure memory and configuring the nested page table, and reduces resource consumption and virtualization The time overhead of the machine access memory improves system performance.
Patent Information
- Application Number
- CN202210509186.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-11
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2042-05-11
AI Technical Summary
In virtual machines, security processors have greater pressure to process data when allocating secure memory and configuring nested page tables, resulting in increased resource consumption, especially in multi-core environments, the time overhead for virtual machines to access memory is increased.
The virtual machine manager sends a secure memory space allocation request to the secure processor. The secure processor allocates space in the pre-allocated secure memory, and the virtual machine manager calls instructions to establish the virtual machine physical address and security in the nested page table. The mapping relationship of memory space reduces the burden on the secure processor.
It effectively reduces the resource consumption of the secure processor and the time overhead of virtual machines accessing memory, and improves system performance.
Smart Images

Figure CN114880074B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a memory management method, device, electronic device and readable storage medium for a virtual machine. Background Art
[0002] With the development of cloud technology, most service programs run in virtual machines in the cloud. As a carrier of user data, the data security of the virtual machine itself is increasingly valued. To protect the security of user data, the virtual machine memory, namely the secure memory, is isolated so that the virtual machine manager cannot access the secure memory. In this way, the data of the virtual machine can be placed in the secure memory. The secure memory of the virtual machine is jointly managed by the virtual machine and the security processor. When the virtual machine is running, a nested page table fault occurs. The virtual machine manager sends a request to the security processor, which allocates memory pages and configures nested page tables. The virtual machine then accesses the memory according to the configured page table. In this process, the security processor is under great pressure to process data. Summary of the invention
[0003] In view of this, embodiments of the present application provide a memory management method, device, electronic device and readable storage medium for a virtual machine, which can reduce the pressure on a security processor to process data.
[0004] In a first aspect, an embodiment of the present application provides a memory management method for a virtual machine, comprising: a virtual machine manager sends a secure memory space allocation request to a security processor; the security processor allocates a secure memory space of a predetermined size for the virtual machine in a pre-allocated secure memory based on the secure memory space allocation request, and sends the address of the allocated secure memory space to the virtual machine manager; the virtual machine accesses the memory and generates a nested page table page fault interrupt; the virtual machine manager calls a first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in a nested page table through the first instruction.
[0005] According to a specific implementation manner of an embodiment of the present application, before the virtual machine accesses the memory and generates a nested page table page fault interrupt, the method also includes: configuring the secure memory size; wherein the secure memory size is determined according to the management data size of each virtual machine.
[0006] According to a specific implementation method of an embodiment of the present application, the virtual machine manager calls a first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in a nested page table through the first instruction, including: the virtual machine manager calls the first instruction, and passes the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level to which the address of the secure memory space is to be linked to the first instruction; the level is a specified level of the nested page table except the last level; the first instruction links the address of the secure memory space into the level based on the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level to which the address of the secure memory space is to be linked, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space.
[0007] According to a specific implementation method of an embodiment of the present application, after establishing a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space, the method also includes: the virtual machine manager sends a normal memory space allocation request to the operating system; the operating system allocates a predetermined size of normal memory space for the virtual machine in the normal memory based on the normal memory space allocation request, and sends the address of the allocated normal memory space to the virtual machine manager; the virtual machine manager calls a second instruction, and links the address of the normal memory space to the last level of the nested page table through the second instruction.
[0008] According to a specific implementation method of an embodiment of the present application, it is characterized in that after the virtual machine manager calls a second instruction and links the address of the ordinary memory space into the last level of the nested page table through the second instruction, the method also includes: setting the last level of the nested page table to a suspended state.
[0009] According to a specific implementation method of an embodiment of the present application, it is characterized in that after setting the last level of the nested page table to a suspended state, the method also includes: the virtual machine issues an access memory instruction, converts the first virtual machine physical address into the address of the first ordinary memory space through the nested page table, and determines whether the last level of the nested page table where the address of the first ordinary memory space is located is in a suspended state; if the last level of the nested page table where the address of the first ordinary memory space is located is in a suspended state, an exception information is sent to the virtual machine; the exception information includes the first virtual machine physical address; the virtual machine determines whether the address of the first ordinary memory space is private memory or shared memory based on the encrypted bits of the first virtual machine physical address in the page table; wherein the page table includes the correspondence between the host virtual machine virtual address and the virtual machine physical address and the encrypted bits corresponding to the virtual machine physical address; if the address of the first ordinary memory space is private memory, the virtual machine calls a third instruction to initialize the content in the address of the first ordinary memory space, and calculates the first hash value of the initialized content.
[0010] According to a specific implementation manner of an embodiment of the present application, after calculating the first hash value of the initialized content, the method also includes: the virtual machine issues a read instruction; wherein the read instruction includes the first virtual machine physical address; converting the first virtual machine physical address into the address of the first ordinary memory space through the nested page table; reading content from the address of the first ordinary memory space, and calculating a second hash value of the read content; comparing the first hash value and the second hash value; and determining whether the content corresponding to the address of the first ordinary memory space has been tampered with based on whether the first hash value and the second hash value are consistent.
[0011] In a second aspect, an embodiment of the present application provides a memory management device for a virtual machine, comprising: a sending module, used to send a secure memory space allocation request to a security processor through a virtual machine manager; an allocation module, used to allocate a secure memory space of a predetermined size to the virtual machine in a pre-allocated secure memory based on the secure memory space allocation request through the security processor, and send the address of the allocated secure memory space to the virtual machine manager; a generating module, used to generate a nested page table page fault interrupt when accessing memory through the virtual machine; and an establishing module, used to call a first instruction through the virtual machine manager, and establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table through the first instruction.
[0012] According to a specific implementation method of an embodiment of the present application, the device also includes: a configuration module, used to configure the secure memory size before the sending module sends a secure memory space allocation request to the security processor through the virtual machine manager; wherein the secure memory size is determined according to the management data size of each virtual machine.
[0013] According to a specific implementation method of an embodiment of the present application, the establishment module includes: a first calling sub-module, used to call the first instruction through the virtual machine manager, and pass the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level to which the address of the secure memory space is to be linked to the first instruction; the level is a specified level of the nested page table before the last level; a linking sub-module, used to link the address of the secure memory space into the level based on the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level to which the address of the secure memory space is to be linked through the first instruction, and establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space.
[0014] According to a specific implementation method of an embodiment of the present application, the device also includes: a first sending module, which is used to send a normal memory space allocation request to the operating system through the virtual machine manager after the link-in submodule establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space; an allocation module, which is used to allocate a predetermined size of normal memory space for the virtual machine in the normal memory based on the normal memory space allocation request through the operating system, and send the address of the allocated normal memory space to the virtual machine manager; a second calling module, which is used to call a second instruction through the virtual machine manager, and link the address of the normal memory space into the last level of the nested page table through the second instruction.
[0015] According to a specific implementation method of an embodiment of the present application, the device also includes: a suspension module, which is used to call a second instruction through the virtual machine manager after the second calling sub-module calls the second instruction, and after the address of the ordinary memory space is linked to the last level of the nested page table through the second instruction, the last level of the nested page table is set to a suspended state.
[0016] According to a specific implementation method of an embodiment of the present application, the device also includes: a first judgment module, which is used for, after the suspension module sets the last level of the nested page table to a suspended state, the virtual machine issues an access memory instruction, converts the first virtual machine physical address into the address of the first ordinary memory space through the nested page table, and judges whether the last level of the nested page table where the address of the first ordinary memory space is located is in a suspended state; a second sending module, which is used for sending exception information to the virtual machine if the last level of the nested page table where the address of the first ordinary memory space is located is in a suspended state; the exception information includes the first virtual machine physical address; a second judgment module, which is used for judging whether the address of the first ordinary memory space is private memory or shared memory according to the encrypted bits of the first virtual machine physical address in the page table through the virtual machine; wherein the page table includes the correspondence between the virtual address of the host virtual machine and the physical address of the virtual machine and the encrypted bits corresponding to the physical address of the virtual machine; an initialization module, which is used for, if the address of the first ordinary memory space is private memory, calling a third instruction through the virtual machine to initialize the content in the address of the first ordinary memory space, and calculating the first hash value of the initialized content.
[0017] According to a specific implementation method of an embodiment of the present application, the device also includes: an issuing module, which is used to issue a read instruction through the virtual machine after the initialization module calculates the first hash value of the initialized content; wherein the read instruction includes the first virtual machine physical address; a conversion module, which is used to convert the first virtual machine physical address into the address of the first ordinary memory space through the nested page table; a calculation module, which is used to read content from the address of the first ordinary memory space and calculate the second hash value of the read content; a comparison module, which is used to compare the first hash value and the second hash value; a determination module, which is used to determine whether the content corresponding to the address of the first ordinary memory space has been tampered with according to whether the first hash value and the second hash value are consistent.
[0018] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a shell, a processor, a memory, a circuit board and a power supply circuit, wherein the circuit board is placed inside the space enclosed by the shell, and the processor and the memory are arranged on the circuit board; the power supply circuit is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory is used to store executable program code; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the memory management method of the virtual machine described in any of the aforementioned implementation methods.
[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores one or more programs, and the one or more programs can be executed by one or more processors to implement the memory management method of the virtual machine described in any of the aforementioned implementation methods.
[0020] In the memory management method, device, electronic device and readable storage medium of the virtual machine of the present embodiment, the virtual machine manager sends a secure memory space allocation request to the security processor. The security processor allocates a secure memory space of a predetermined size for the virtual machine in the pre-allocated secure memory based on the secure memory space allocation request, and sends the address of the allocated secure memory space to the virtual machine manager. The virtual machine accesses the memory and generates a nested page table page fault interrupt. The virtual machine manager calls the first instruction and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table through the first instruction. Since the security processor applies for secure memory space from the pre-allocated secure memory for the virtual machine, when the virtual machine accesses the memory and generates a nested page table page fault interrupt, the virtual machine manager calls the first instruction and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table. In this process, the security processor is responsible for applying for the secure memory space. The mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table is established by the virtual machine manager calling the first instruction, thereby reducing the pressure on the security processor to process data. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. 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 paying creative work.
[0022] Figure 1 A schematic diagram of a SPOT table protecting virtual machine memory data in the prior art;
[0023] Figure 2 A schematic diagram of the correspondence between entries in a SPOT table and memory intervals in the prior art;
[0024] Figure 3 A schematic diagram of a flow chart of a virtual machine accessing memory in the prior art;
[0025] Figure 4 A flowchart of a memory management method for a virtual machine provided in a specific embodiment of the present application;
[0026] Figure 5A schematic diagram of the entry structure of a SPOT table according to an embodiment;
[0027] Figure 6 A schematic diagram of a virtual machine image loading process according to an embodiment of the present application;
[0028] Figure 7 A schematic diagram of the configuration page and register page loading process of an embodiment of the present application;
[0029] Figure 8 A flowchart of a memory management method for a virtual machine provided in a specific embodiment of the present application;
[0030] Fig. 9 A schematic diagram of the structure of a memory management device for a virtual machine provided in one embodiment of the present application;
[0031] Fig.10 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0032] The embodiments of the present application are described in detail below in conjunction with the accompanying drawings. It should be clear that the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0033] To ensure the data security of the virtual machine, see Figure 1 and Figure 2 A secure page owner table (SPOT table) can be added to the bus on which the virtual machine accesses the memory. The owner refers to the virtual machine ID. For example, a storage interval (such as SRAM) can be added to the bus. The SPOT table is stored in this storage space. The table defines the owner of each memory interval. Before accessing the memory, the hardware determines whether the memory accessor matches the memory owner. If they match, access is allowed.
[0034] When a virtual machine accesses memory, the conversion from the virtual machine virtual address (GVA, Guest Virtual Address) to the host physical address (HPA, Host Physical Address) is completed inside the central processing unit (CPU). The CPU first translates the virtual machine virtual address GVA into the virtual machine physical address (GPA, Guest Physical Address) through the page table inside the virtual machine, and then translates the GPA into the host physical address HPA through the virtual machine nested page table. The CPU sends the virtual machine ID and HPA to the address bus. After verification of the SPOT table, if the memory address allows the virtual machine to access, the memory bus inside the CPU continues to send the memory read and write request to the memory controller. If the address does not allow the virtual machine to access, the memory bus does not forward the memory read and write request to the memory controller, and directly returns the fixed mode content to the CPU. The SPOT table is the core data for realizing the memory security of the securely isolated virtual machine. The security of SPOT itself must be guaranteed. Therefore, it is necessary to restrict the virtual machine manager (VMM, Virtual Machine Monitor) and the operating system (OS, Operating System) from accessing and modifying the SPOT table. Only the security processor has the authority to configure the SPOT table.
[0035] In addition, as mentioned in the background art, see Figure 3 When the secure isolated virtual machine is running, a nested page table fault occurs. The virtual machine exits and enters the VMM. The VMM sends a request to the security processor, which allocates memory pages, configures the nested page table, and configures the SPOT table. The VMM resumes the execution of the virtual machine. After the virtual machine accesses the nested page table, it obtains the HPA and accesses the memory. The HPA has been configured in the SPOT table, and the bus allows access. The virtual machine successfully accesses the memory.
[0036] It can be seen from the secure isolation virtual machine access memory flow chart that when the virtual machine triggers a page fault, it needs to enter the security processor to complete the secure memory allocation, nested page table establishment, and SPOT table establishment processes, which increases the operating pressure and resource consumption of entering the security processor. In a multi-core environment, multiple main CPUs cannot enter the security processor at the same time, which increases the time overhead of the virtual machine accessing memory.
[0037] Based on this, the present application proposes a memory management method for a virtual machine, which can reduce the resource consumption of the security processor to a certain extent.
[0038] In order to enable those skilled in the art to better understand the technical concept, implementation plan and beneficial effects of the embodiments of the present application, specific embodiments are described in detail below.
[0039] An embodiment of the present application provides a memory management method for a virtual machine, including: a virtual machine manager sends a secure memory space allocation request to a security processor; the security processor allocates a secure memory space of a predetermined size to the virtual machine in a pre-allocated secure memory based on the secure memory space allocation request, and sends the address of the allocated secure memory space to the virtual machine manager; a nested page table page fault interrupt is generated when the virtual machine accesses the memory; the virtual machine manager calls a first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in a nested page table through the first instruction, thereby reducing the pressure on the security processor to process data.
[0040] Figure 4 A flowchart of a memory management method for a virtual machine provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the memory management method of the virtual machine of this embodiment may include:
[0041] S101. The virtual machine manager sends a secure memory space allocation request to the security processor.
[0042] Virtual Machine Manager (VMM) is a virtual machine monitor that is mainly used to manage virtual machines.
[0043] After the virtual machine is started, the virtual machine manager detects that the virtual machine has been started and sends a secure memory space allocation request to the security processor. In some examples, the virtual machine manager sends an SMR_ALLOC command to the security processor. In some examples, the virtual machine manager also sends the VMID of the virtual machine to the security processor.
[0044] The security processor may be a dedicated processor other than a general-purpose processor and specifically used for managing security policies, and has an independent RAM.
[0045] S102: The security processor allocates a secure memory space of a predetermined size for the virtual machine in the pre-allocated secure memory based on the secure memory space allocation request, and sends the address of the allocated secure memory space to the virtual machine manager.
[0046] The security processor configures a secure memory space of a predetermined size in the pre-allocated secure memory, and sends the address of the allocated secure memory space to the virtual machine manager.
[0047] A virtual machine (VM) is a computer system with complete hardware system functions that is simulated by software.
[0048] The virtual machine of this embodiment may be a secure isolation virtual machine (SIV, Secure IsolationVirtualization). The secure isolation virtual machine protects memory by defining a SPOT table that defines the owner of each memory interval, and judging whether the memory accessor matches the memory owner. Access is allowed only if they match.
[0049] In the related art, since the SPOT table is stored on the memory bus access path and is located inside the system-on-a-Chip (SoC), the storage space occupied by the SPOT table cannot be too large due to the area of the SoC. For example, if the physical machine's memory is 64G, the memory page is 4K, and the virtual machine ID is 2 bytes, if the SPOT table is configured for each memory page, the SPOT space needs to be 64G / 4K×2=32M. Obviously, the internal storage of the SoC cannot support storage of such a scale. Therefore, it is necessary to increase the memory granularity that the SPOT table can manage, that is, to increase the minimum unit value of the SPOT table to manage memory. If the internal storage of the SoC can support 512K, the minimum unit managed by the SPOT table is 64G / (512K / 2)=256K.
[0050] However, the SPOT table controls access to physical memory, and the physical space must be continuous, which conflicts with the method of managing memory in 4K pages in the virtual machine manager or operating system. The longer the operating system runs, the more fragmented the memory becomes. On a long-running operating system, it is difficult to have more than two pages of continuous physical memory.
[0051] In order to meet the granularity of SPOT table memory management, a portion of memory is reserved on the physical memory according to the size of all the data of the virtual machine before the operating system is started, which is dedicated to the secure isolation virtual machine. However, this portion of memory cannot be time-shared with the operating system. Before the virtual machine is started, the utilization rate of this portion of memory is 0; during the operation of the virtual machine, this portion of memory may only be partially used; in addition, if the host can run multiple virtual machines, memory must be reserved for all the data of multiple virtual machines. However, if only some of the virtual machines are started, only part of the reserved memory is used, and the unused secure memory cannot be used by the operating system, resulting in low utilization of the entire physical memory of the host.
[0052] To improve the utilization rate of the entire physical memory of the host, in one embodiment, before the virtual machine manager sends a secure memory space allocation request to the security processor, the method may further include:
[0053] Configure the secure memory size.
[0054] In this embodiment, the size of the secure memory is determined according to the size of the management data of each virtual machine.
[0055] A virtual machine may include management data and other data, which can be referred to as management data pages and other data pages in memory. Management data pages may include configuration data pages, register pages, and nested page table pages. Since the management data page accounts for a very low proportion, the upper limit can be calculated in advance and part of the memory, namely, secure memory, can be reserved in the physical memory. This part of the memory is still protected by the SPOT table.
[0056] This embodiment calculates the reserved memory based on the virtual machine management data. Since the management data is only a small part of the virtual machine's data, the memory reserved based on the management data is smaller. The other memory in the host memory except the reserved smaller memory can be time-shared by the operating system, thereby improving memory utilization.
[0057] The calculation of the size of virtual machine management data is described below with reference to a specific embodiment.
[0058] In this embodiment, the virtual machine management data includes configuration data, registers and nested page tables, and the sizes of the configuration data page, register page and nested page table page are calculated accordingly, wherein:
[0059] (1) Secure virtual machine register page:
[0060] Assuming that the virtual machine ID is 8 bits, that is, a maximum of 256 secure virtual machines, each virtual machine supports a maximum of 128 vCPUs, then the secure virtual machine register page requires 256*128*4K=128M.
[0061] (2) Secure virtual machine configuration page:
[0062] Assuming that the virtual machine ID is 8 bits, that is, a maximum of 256 secure virtual machines, each virtual machine supports a maximum of 128 vCPUs, then the secure virtual machine configuration page requires 256*128*4K=128M.
[0063] (3) Secure virtual machine nested page table page:
[0064] Assuming that the maximum memory supported by the secure virtual machine is 1T and the nested page table is 4 levels, the required nested page table space is about 1G.
[0065] Add the sizes of the above-mentioned pages together. If there are a maximum of 256 secure virtual machines on a host that supports 1TB of physical memory, 2GB of secure virtual machine memory space needs to be allocated as secure memory. If other expenses are taken into consideration, a margin can be added to 2GB, such as reserving 4GB of secure memory.
[0066] Assuming that the physical address of the reserved secure memory is [P, P+4G], the management memory range of the SPOT table can be set to P~P+4G by configuring the register.
[0067] In some examples, after configuring the secure memory size, the size of the secure memory managed by each entry in the SPOT table can be calculated by using the preset secure memory size. For example, if the SPOT table supports a maximum of 8192 entries, each entry manages 4G / 8192=512K memory.
[0068] When the host physical address of the reserved secure memory on the host is determined, the physical address of the secure memory can be divided into address intervals equal to the number of entries in the SPOT table, and the size of each interval is equal. Afterwards, a one-to-one correspondence can be established between each entry of the SPOT table and each address interval.
[0069] See also Figure 5 ,The SPOT entry consists of 2 bytes, the lowest bit uses one bit to indicate whether the entry is valid, and the other bits indicate the virtual machine ID.
[0070] When establishing a one-to-one correspondence between each entry of the SPOT table and each address range, the bit corresponding to the validity bit and the virtual machine ID in each entry of the SPOT table can be empty. When applying for a secure memory page corresponding to the virtual machine, the entry of the SPOT table corresponding to the requested secure memory page can be determined based on the address of the requested secure memory page and the address range corresponding to the SPOT table entry, and the virtual machine ID is added to the bit corresponding to the virtual machine ID of the entry, and the valid bit is set to 1.
[0071] In some examples, the predetermined size of the secure memory space allocated by the security processor may be the size of the secure memory that can be managed by each entry in the SPOT table. For example, each entry in the SPOT table manages 512K of memory. The security processor configures 512K of memory in the pre-allocated secure memory and sends the secure memory physical address P and length 512K to the virtual machine manager. Further, the SPOT table entry corresponding to the address of the allocated secure memory space may be determined, and the entry may be configured as a VMID and the valid bit flag may be configured as 1.
[0072] S103: The virtual machine accesses the memory and generates a nested page table page fault interrupt.
[0073] A nested page table fault (NPF) may be a page fault generated due to an incomplete nested page table.
[0074] When the virtual machine needs to interact with the memory for data, if the address range of the memory data is not included in the current nested page table, the virtual machine generates a nested page table page fault interrupt and exits.
[0075] S104: The virtual machine manager calls a first instruction and establishes a mapping relationship between a virtual machine physical address of the virtual machine and an address of the secure memory space in a nested page table through the first instruction.
[0076] The nested page table (NPT) can translate the virtual machine physical address GPA into a table of the host physical address HPA.
[0077] After the virtual machine manager receives the address of the secure memory space sent by the security processor, it can call the first instruction, which can establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space, and establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table for the virtual machine.
[0078] In this embodiment, the virtual machine manager sends a secure memory space allocation request to the security processor. The security processor allocates a secure memory space of a predetermined size for the virtual machine in the pre-allocated secure memory based on the secure memory space allocation request, and sends the address of the allocated secure memory space to the virtual machine manager. When the virtual machine accesses the memory and a nested page table page fault interrupt is generated, the virtual machine manager calls the first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table through the first instruction. Since the security processor applies for secure memory space from the pre-allocated secure memory for the virtual machine, when the virtual machine accesses the memory and a nested page table page fault interrupt is generated, the virtual machine manager calls the first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table. In this process, the security processor is responsible for applying for the secure memory space, and the mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table is established by the virtual machine manager calling the first instruction, thereby reducing the pressure on the security processor to process data. In addition, it is beneficial to improve the performance of the entire system.
[0079] Another embodiment of the present application is basically the same as the above embodiment, except that the virtual machine manager of the present embodiment calls the first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table through the first instruction (S104), which may include:
[0080] S104a. The virtual machine manager calls the first instruction and passes the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level to which the address of the secure memory space is to be linked to the first instruction.
[0081] The level in this embodiment is a designated level before the last level of the nested page table.
[0082] For example, if the number of levels of the nested page table is 4, then the level before the last level can be 1, 2, or 3.
[0083] S104b. The first instruction links the address of the secure memory space into the hierarchy based on the virtual machine identifier, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the hierarchy to which the address of the secure memory space is to be linked, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space.
[0084] In this embodiment, the first instruction can link the address of the secure memory space into a hierarchy based on the virtual machine's identifier, the virtual machine's virtual machine physical address, the address of the secure memory space, and the hierarchy to which the address of the secure memory space is to be linked, thereby establishing a mapping relationship between the virtual machine's virtual machine physical address and the address of the secure memory space.
[0085] In some examples, the first instruction may be a dedicated instruction, specifically SIVNPTADD VMID GPA HPALEVEL, which creates a page table at level LEVEL for the GPA page of the virtual machine VMID, and the physical address of the page table is HPA. The instruction requires four input parameters, namely, the secure virtual machine ID, the secure virtual machine physical address GPA, the physical machine address HPA, and the NPT level LEVEL.
[0086] The instruction flow is as follows:
[0087] A1, determine whether LEVEL exceeds the maximum level of the page table. If so, the instruction exits. If not, execute A2;
[0088] A2. Determine whether the HPA passed in is the memory managed by the SPOT table. If it is not within the management range of the SPOT table, the instruction exits. If it is within the management range of the SPOT table, execute A3.
[0089] A3. Determine whether the SPOT entry where the HPA is passed in is assigned to the VMID. If not, the instruction exits. If assigned to the VMID, execute A4.
[0090] A4, traverse the NPT page table entry of VMID according to the GPA passed in. If LEVEL>0, if the 0-LEVEL-1 layer of the NPT page table entry corresponding to the GPA is not established, the instruction exits. If LEVEL>0, if the 0-(LEVEL-1) layer of the NPT page table entry corresponding to the GPA is established, execute A5;
[0091] A5, traverse the NPT page table of VMID according to the GPA passed in. If the LEVEL layer of the NPT page table entry corresponding to the GPA has been established, the instruction exits. If not, execute A6;
[0092] A6, search the GPA page table to see if HPA has been mapped to other locations in NPT. If so, the instruction exits. If not, execute A7.
[0093] A7. Link HPA to the LEVEL layer of the NPT page table corresponding to GPA, and the instruction is completed.
[0094] To improve the security of secure memory, the functions of steps A1-A7 above may be implemented by hardware. The secure virtual machine ID in the incoming instruction may be placed in the data register RAX; the secure virtual machine physical address GPA may be placed in the data register RBX; and the physical machine address HPA may be placed in the data register RCX.
[0095] In order to conveniently delete the nested page table except the last level, in some examples, the virtual machine manager can call SIVNPTDEL VMID GPA LEVEL to delete the page table of the LEVEL level corresponding to the GPA of the virtual machine VMID. The instruction requires three input parameters, namely the secure virtual machine ID, the secure virtual machine physical address GPA and the NPT level LEVEL.
[0096] The instruction flow is as follows:
[0097] B1, determine whether LEVEL exceeds the maximum level of the page table. If so, the instruction exits. If not, execute B2;
[0098] B2, determine whether the HPA passed in is secure memory. If it is not within the secure memory range, the instruction exits. If it is within the secure memory range, execute B3;
[0099] B3, determine whether the SPOT entry where the HPA is passed in is assigned to VMID. If not, the instruction exits. If assigned to VMID, execute B4.
[0100] B4, traverse the NPT page table of VMID according to the GPA passed in. If the 0-LEVEL layer of the NPT page table entry corresponding to the GPA is not established, the instruction exits. If it is established, execute B5;
[0101] B5. Delete the LEVEL layer of the NPT page table corresponding to the GPA chain, and the instruction is completed.
[0102] To improve the security of secure memory, the functions of steps B1-B5 above can be implemented by hardware. The secure virtual machine ID in the incoming instruction is placed in RAX; the secure virtual machine physical address GPA is placed in RBX; and the NPT level LEVEL.
[0103] In order to access data other than the secure memory corresponding to the virtual machine through the nested page table, it is necessary to establish a complete nested page table with the last level pointing to the ordinary memory address. Another embodiment of the present application is basically the same as the above embodiment, except that after establishing a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space, the method may further include:
[0104] S105: The virtual machine manager sends a common memory space allocation request to the operating system.
[0105] When page tables at other levels except the last level of the nested page table have been established, the virtual machine manager sends a normal memory space allocation request to the operating system to apply for a normal memory page for the last level of the nested page table.
[0106] In some examples, the allocation request may include an identifier of the virtual machine.
[0107] S106: The operating system allocates a normal memory space of a predetermined size to the virtual machine in the normal memory based on the normal memory space allocation request, and sends the address of the allocated normal memory space to the virtual machine manager.
[0108] The operating system may allocate a predetermined size of ordinary memory space to the virtual machine according to the ordinary memory space allocation request and in combination with the ordinary memory usage. After allocating the predetermined size of ordinary memory space, the address of the allocated ordinary memory space may be sent to the virtual machine manager.
[0109] S107: The virtual machine manager calls a second instruction, and links the address of the common memory space into the last first level of the nested page table through the second instruction.
[0110] The address of the ordinary memory space is linked to the last level of the nested page table, thereby establishing a complete mapping relationship between the virtual machine physical address of the virtual machine and the address of the ordinary memory space, so that the virtual machine can access the ordinary memory using the mapping relationship.
[0111] In some examples, the virtual machine manager calls the second instruction to link the address of the normal memory space into the last first level of the nested page table through the second instruction, which may include:
[0112] The virtual machine manager calls the second instruction and passes the identifier of the virtual machine, the virtual machine physical address of the virtual machine, and the address of the common memory space to the second instruction;
[0113] The second instruction links the address of the common memory space into the last first level of the nested page table based on the identifier of the virtual machine, the virtual machine physical address of the virtual machine and the address of the common memory space.
[0114] In some examples, the second instruction may be a dedicated instruction, specifically SIVPAGEADD VMID GPA HPA, which establishes a mapping between GPA and HPA in NPT. The instruction requires three input parameters, namely, secure virtual machine ID, secure virtual machine physical address GPA, and physical machine address HPA.
[0115] The instruction flow is as follows:
[0116] C1, determine whether HPA is the memory managed by the SPOT table, if so, exit, if not, execute C2;
[0117] C2, traverse the nested page table of VMID according to the GPA passed in. If the page table entry before the last level is not established, the instruction exits. If it is established, execute C3;
[0118] C3, traverse the nested page table of VMID according to the GPA passed in. If the last level entry (PTE, Page Table Entry) of the nested page table corresponding to the GPA has been configured, the instruction exits. If not, execute C4;
[0119] C4, search the nested page table of VIMD to see if HPA has been mapped to other locations. If so, the instruction exits. If not, execute C5.
[0120] C5. Link the HPA address into the nested page table, set the PTE item to the pending state (after confirmation by the secure virtual machine, the PTE is converted to the valid state (validated)), and the instruction is completed.
[0121] When the above instructions are completed, an error code may be generated, and 0 indicates success.
[0122] To improve the security of secure memory, the functions of steps C1-C5 above can be implemented by hardware. The secure virtual machine ID of the incoming instruction can be placed in RAX; the secure virtual machine physical address GPA can be placed in RBX; and the physical machine address HPA can be placed in RCX. When the hardware completes the above instruction, RAX stores the error code, and 0 indicates success.
[0123] In order to facilitate the release of the normal memory of the virtual machine, in some examples, SIVPAGEDEL VMID GPA can be called through the virtual machine manager. This command releases the normal memory for the virtual machine and sets the corresponding nested page table PTE entry to non-existent. This command requires two input parameters, namely the secure virtual machine ID and the secure virtual machine physical address GPA. This command requires two output parameters: the instruction error code and the host physical address, where an error code of 0 indicates success; the host physical address is output only when the instruction returns correctly.
[0124] The instruction flow is as follows:
[0125] D1. Traverse the NPT page table of VMID according to the GPA passed in. If the NPT page table entry corresponding to the GPA is not configured, the instruction exits and sets a non-zero error code. If it is configured, execute D2.
[0126] D2. Set the error code to 0, output the address in the page table PTE where the GPA is located, and set the PTE to non-present.
[0127] To improve the security of secure memory, the functions of steps D1-D2 above can be implemented by hardware, and the secure virtual machine ID in the input parameter is placed in RAX; the secure virtual machine physical address GPA is placed in RBX.
[0128] The two parameter instruction error codes output can be stored in RAX. When the instruction returns correctly, the obtained HPA is stored in RCX.
[0129] In the memory corresponding to the virtual machine, ordinary memory except secure memory can be divided into private memory and shared memory. Among them, private memory is memory that the virtual machine can access but the virtual machine manager cannot access, and shared memory is memory that both the virtual machine and the virtual machine manager can access.
[0130] Since private memory data is data that the virtual machine manager or other devices are not allowed to modify, during the research process, the inventors found that if the VMM / device modifies the private memory of the virtual machine, the hash value of the private memory storage data will also change. In this way, the virtual machine can calculate the corresponding hash value when writing and reading data, and perform verification based on the two hash values. If the data is modified, an exception will be generated during the verification, so that the integrity of the memory data can be verified.
[0131] To facilitate initialization of the private memory and then integrity verification, in some examples, after the virtual machine manager calls the second instruction and links the address of the common memory space into the last level of the nested page table through the second instruction (S107), the method may further include:
[0132] S108. Set the last level of the nested page table to a suspended state.
[0133] Furthermore, in some examples, after setting the last level of the nested page table to a suspended state (S108), the method may further include:
[0134] S109, the virtual machine issues a memory access instruction, converts the first virtual machine physical address into the address of the first common memory space through the nested page table, and determines whether the last level of the nested page table where the address of the first common memory space is located is in a suspended state.
[0135] S110: If the last level of the nested page table where the address of the first common memory space is located is in a suspended state, an exception message is sent to the virtual machine.
[0136] If the last level of the nested page table where the address of the first common memory space is located is in a suspended state, exception information is sent to the virtual machine. The exception information in this embodiment may include the physical address of the first virtual machine.
[0137] S111. The virtual machine determines whether the address of the first common memory space is private memory or shared memory according to the encrypted bits of the first virtual machine physical address in the page table.
[0138] In this embodiment, the page table may include the correspondence between the virtual address of the host virtual machine and the physical address of the virtual machine and the encryption bit corresponding to the physical address of the virtual machine. In some examples, the encryption bit c-bit is 0 for no encryption and 1 for encryption, generally at bit 47 in the address. By judging by the encryption bit of the physical address of the first virtual machine, if encryption is indicated, the address of the first ordinary memory space is private memory, and if no encryption is indicated, the address of the first ordinary memory space is shared memory.
[0139] S112: If the address of the first common memory space is a private memory, the virtual machine calls a third instruction to initialize the content in the address of the first common memory space, and calculates a first hash value of the initialized content.
[0140] If the address of the first common memory space is private memory, the virtual machine calls the third instruction to initialize the content in the address of the first common memory space and calculates the first hash value of the initialized content. In some examples, the content of the initialized page can be set to all zeros.
[0141] In some examples, the third instruction may be a dedicated instruction, specifically SIVSECVALIDATE GPA, which is a command for the virtual machine to confirm that GPA is private memory and initialize the page data to all 0. The instruction requires a physical address GPA passed into the virtual machine.
[0142] The command operation is as follows:
[0143] E1. The virtual machine determines that this GPA is private memory, sets the PTE of NPT to validated, and initializes the content of the page to all 0s to generate the initial hash value of the memory.
[0144] To improve the security of the secure memory, the function of the above step E1 can be implemented by hardware, and the physical address of the incoming virtual machine is stored in RAX.
[0145] When the virtual machine determines that the GPA is shared memory, it can call SIVNSVALIDATE GPA, which is a command for the secure virtual machine to confirm that the GPA is shared memory. This instruction requires a physical address GPA passed into the virtual machine.
[0146] The instruction operation is as follows: the secure virtual machine sets the PTE of NPT to validated.
[0147] To improve the security of secure memory, the functions of the above steps can be implemented by hardware, and the physical address of the incoming virtual machine is stored in RAX.
[0148] In order to promptly detect whether the content in the private memory has been tampered with, in some examples, after calculating the first hash value of the initialized content, the method may further include:
[0149] S113. The virtual machine issues a read instruction.
[0150] In this embodiment, the read instruction may include the physical address of the first virtual machine. The read instruction may be an instruction issued by the virtual machine to read the content in the physical address of the first virtual machine.
[0151] S114. Convert the first virtual machine physical address into an address of the first common memory space through a nested page table.
[0152] The first virtual machine physical address is converted into the address of the first common memory space through the nested page table obtained by the above-mentioned embodiment.
[0153] S115. Read content from the address of the first common memory space, and calculate a second hash value of the read content.
[0154] In this embodiment, the memory controller may calculate the second hash value of the read content.
[0155] S116: Compare the first Hash value and the second Hash value.
[0156] S117. Determine whether the content corresponding to the address of the first common memory space has been tampered with according to whether the first hash value and the second hash value are consistent.
[0157] If the first hash value and the second hash value are consistent, the content corresponding to the address of the first common memory space has not been tampered with; if the first hash value and the second hash value are inconsistent, the content corresponding to the address of the first common memory space has been tampered with.
[0158] Since private memory is accessible to virtual machines but not to virtual machine managers, in certain application scenarios, in order to allow the virtual machine manager to access part of the original private memory, or to no longer allow the virtual machine manager to access part of the original shared memory,
[0159] The virtual machine can control whether the virtual machine physical address is private memory or shared memory by controlling the encryption bit of the virtual machine's internal page table. In some examples, the virtual machine changes the encryption bit in the virtual machine's internal page table from 1 to 0, and the private memory is converted to shared memory; the secure virtual machine changes the encryption bit in the virtual machine's physical address from 0 to 1, and the shared memory is converted to private memory.
[0160] If a private page is converted to a shared page, the page no longer requires integrity protection by the memory controller; if shared memory is converted to private memory, the page requires memory integrity protection.
[0161] After modifying the encryption bit of the internal page table, the virtual machine can call the fourth instruction to delete the TLB in the CPU core and set the PTE corresponding to the virtual machine page to the pending state.
[0162] The fourth instruction may be SIVINVALIDATE GPA, which is a command to set the PTE of the NPT of the GPA of the virtual machine to pending. The instruction needs to pass in the physical address (GPA) of the virtual machine as a parameter.
[0163] The command operation is as follows:
[0164] The virtual machine sets the PTE of NPT to pending and deletes the TLB of all CPU cores.
[0165] In order to improve the security of secure memory, the functions of the above steps can be implemented by hardware, and the physical address of the incoming virtual machine is stored in RAX.
[0166] In some examples, after the above steps, the PTE is in pending state, and an exception is triggered. The virtual machine calls SIVSECVALIDATE GPA to reinitialize the private memory and calculate the hash value, or calls SIVNSVALIDATE GPA without initialization or hash value calculation.
[0167] To perform integrity checks on virtual machines when starting them, in some examples, see Figure 6 , using the memory management method of the virtual machine of the embodiment of the present application, the initial image verification and loading process of the virtual machine needs to be adaptively adjusted, and the specific process is as follows:
[0168] 1. VMM copies the initial image of the secure virtual machine to memory and clears the initial image cache;
[0169] 2. The VMM sends the initial image physical address to the security processor to request integrity verification;
[0170] 3. The security processor hashes the initial image page by page to obtain the complete hash value of the initial image;
[0171] 4. Determine whether the hash value is correct;
[0172] 5. If the hash value is correct, the security processor encrypts the initial image page by page and generates a data hash value, which is stored in the memory based on the error correction code (ECC);
[0173] 6. The security processor creates a page table for the initial image;
[0174] 7. The initial image of the virtual machine is loaded;
[0175] 8. If the hash value is incorrect, the virtual machine initial image verification fails.
[0176] See also Figure 7 , the configuration page and register page loading process in the virtual machine management data in the above embodiment is as follows:
[0177] 1. VMM copies the virtual machine configuration page / register page to memory;
[0178] 2. VMM clears the configuration page / register page cache;
[0179] 3. The VMM sends the virtual machine configuration page / register page physical memory to the security processor;
[0180] 4. The security processor copies the configuration page / register page to secure memory;
[0181] 5. The security processor generates memory data hash values for the configuration page / register page and saves them in the ECC.
[0182] The solution of the present application is described in detail below with a specific embodiment.
[0183] See also Figure 8 The memory management method of the virtual machine of this embodiment may include:
[0184] 1. The virtual machine accesses memory, generating a nested page table fault interrupt NPF;
[0185] 2. Get the security page and call SIVNPTADD to create a page table for GPA, and get the page from OS and call SIVPAGEADD to create a PTE entry for GPA and a nested page table NPT;
[0186] 4. The memory bus generates memory hash values for each level before the last level of NPT, and generates memory hash values for the last level;
[0187] 5. The virtual machine receives a PENDING_PAGE exception. If the HPA corresponding to the GPA that triggered the exception is private memory, SIVSECVALIDATE is called to initialize the content in the HPA and calculate the initialized hash value corresponding to the HPA.
[0188] 6. If the GPA that triggers the exception is shared memory, call SIVNSVALIDATE.
[0189] In specific applications, the method provided in this embodiment is used to enhance the system architecture and system software, and the memory controller can be used to protect the memory integrity. The virtual machine can obtain secure memory through special instructions to store the virtual machine's configuration page, register page and nested page table page, and the data of the secure memory is managed by the SPOT table, while other data can be allocated memory from the operating system in pages. The memory controller integrity mechanism is used to ensure the security of data pages, the security of the secure memory remains unchanged, and there is no need to reserve a large amount of memory when the system starts, which improves memory utilization and reduces the resource overhead of the security processor.
[0190] An embodiment of the present application provides a memory management device for a virtual machine, comprising: a sending module, used to send a secure memory space allocation request to a security processor through a virtual machine manager; an allocation module, used to allocate a secure memory space of a predetermined size to the virtual machine in a pre-allocated secure memory based on the secure memory space allocation request through the security processor, and send the address of the allocated secure memory space to the virtual machine manager; a generating module, used to generate a nested page table page fault interrupt when the virtual machine accesses the memory; and an establishing module, used to call a first instruction through the virtual machine manager, and establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table through the first instruction, thereby reducing the pressure on the security processor to process data.
[0191] Fig. 9 A schematic diagram of the structure of a memory management device for a virtual machine provided in an embodiment of the present application is shown in FIG. Fig. 9As shown, the memory management device of the virtual machine of this embodiment may include: a sending module 11, which is used to send a secure memory space allocation request to the security processor through the virtual machine manager; an allocation module 12, which is used to allocate a secure memory space of a predetermined size to the virtual machine in a pre-allocated secure memory based on the secure memory space allocation request through the security processor, and send the address of the allocated secure memory space to the virtual machine manager; a generating module 13, which is used to generate a nested page table page fault interrupt by accessing the memory through the virtual machine; an establishing module 14, which is used to call a first instruction through the virtual machine manager, and establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table through the first instruction
[0192] The device of this embodiment can be used to perform Figure 4 The technical solution of the method embodiment shown has similar implementation principles and technical effects, which will not be repeated here.
[0193] In the device of this embodiment, the virtual machine manager sends a secure memory space allocation request to the security processor. The security processor allocates a secure memory space of a predetermined size for the virtual machine in the pre-allocated secure memory based on the secure memory space allocation request, and sends the address of the allocated secure memory space to the virtual machine manager. When the virtual machine accesses the memory and a nested page table page fault interrupt is generated, the virtual machine manager calls the first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table through the first instruction. Since the security processor applies for secure memory space from the pre-allocated secure memory for the virtual machine, when the virtual machine accesses the memory and a nested page table page fault interrupt is generated, the virtual machine manager calls the first instruction, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table. In this process, the security processor is responsible for applying for the secure memory space, and the establishment of the mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in the nested page table is completed by the virtual machine manager calling the first instruction, which can reduce the pressure on the security processor to process data.
[0194] As an optional implementation, the device also includes: a configuration module, used to configure the secure memory size before the sending module sends a secure memory space allocation request to the security processor through the virtual machine manager; wherein the secure memory size is determined according to the management data size of each virtual machine.
[0195] As an optional implementation, the establishment module includes: a first calling sub-module, used to call the first instruction through the virtual machine manager, and pass the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level to which the address of the secure memory space is to be linked to the first instruction; the level is a specified level of the nested page table before the last level; a linking sub-module, used to link the address of the secure memory space into the level based on the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level to which the address of the secure memory space is to be linked through the first instruction, and establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space.
[0196] As an optional implementation, the device also includes: a first sending module, which is used to send a normal memory space allocation request to the operating system through the virtual machine manager after the link-in submodule establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space; an allocation module, which is used to allocate a predetermined size of normal memory space for the virtual machine in the normal memory based on the normal memory space allocation request through the operating system, and send the address of the allocated normal memory space to the virtual machine manager; a second calling module, which is used to call a second instruction through the virtual machine manager, and link the address of the normal memory space into the last level of the nested page table through the second instruction.
[0197] As an optional implementation, the device also includes: a suspension module, which is used to set the last level of the nested page table to a suspended state after the second calling submodule calls the second instruction through the virtual machine manager and links the address of the ordinary memory space into the last level of the nested page table through the second instruction.
[0198] As an optional implementation, the device also includes: a first judgment module, which is used for, after the suspension module sets the last level of the nested page table to a suspended state, the virtual machine issues an access memory instruction, converts the first virtual machine physical address into the address of the first common memory space through the nested page table, and determines whether the last level of the nested page table where the address of the first common memory space is located is in a suspended state; a second sending module, which is used for sending exception information to the virtual machine if the last level of the nested page table where the address of the first common memory space is located is in a suspended state; the exception information includes the physical address of the first virtual machine; a second judgment module, which is used for judging whether the address of the first common memory space is private memory or shared memory according to the encrypted bits of the first virtual machine physical address in the page table through the virtual machine; wherein the page table includes the correspondence between the virtual address of the host virtual machine and the physical address of the virtual machine and the encrypted bits corresponding to the physical address of the virtual machine; an initialization module, which is used for, if the address of the first common memory space is private memory, calling a third instruction through the virtual machine to initialize the content in the address of the first common memory space, and calculating the first hash value of the initialized content.
[0199] As an optional implementation, the device also includes: an issuing module, used to issue a read instruction through the virtual machine after the initialization module calculates the first hash value of the initialized content; wherein the read instruction includes the first virtual machine physical address; a conversion module, used to convert the first virtual machine physical address into the address of the first ordinary memory space through the nested page table; a calculation module, used to read content from the address of the first ordinary memory space and calculate a second hash value of the read content; a comparison module, used to compare the first hash value and the second hash value; a determination module, used to determine whether the content corresponding to the address of the first ordinary memory space has been tampered with according to whether the first hash value and the second hash value are consistent.
[0200] The device of the above embodiment can be used to execute the technical solution of the above method embodiment. Its implementation principle and technical effect are similar and will not be repeated here.
[0201] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Fig.10As shown, it may include: a shell 61, a processor 62, a memory 63, a circuit board 64 and a power circuit 65, wherein the circuit board 64 is placed inside the space enclosed by the shell 61, and the processor 62 and the memory 63 are arranged on the circuit board 64; the power circuit 65 is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory 63 is used to store executable program codes; the processor 62 runs the program corresponding to the executable program code by reading the executable program code stored in the memory 63, and is used to execute any one of the memory management methods of the virtual machine provided in the aforementioned embodiments, so that the corresponding beneficial technical effects can also be achieved, which have been described in detail in the previous text and will not be repeated here.
[0202] The above electronic devices exist in many forms, including but not limited to:
[0203] (1) Mobile communication devices: These devices are characterized by their mobile communication functions and their main purpose is to provide voice and data communications. These terminals include: smart phones (such as iPhone), multimedia phones, functional phones, and low-end phones.
[0204] (2) Ultra-mobile personal computer devices: These devices fall into the category of personal computers, have computing and processing capabilities, and generally also have mobile Internet access features. These terminals include: PDA, MID and UMPC devices, such as iPad.
[0205] (3) Server: A device that provides computing services. The server consists of a processor, hard disk, memory, system bus, etc. The server is similar to a general computer architecture, but because it needs to provide highly reliable services, it has higher requirements in terms of processing power, stability, reliability, security, scalability, and manageability.
[0206] (4) Other electronic devices with data interaction functions.
[0207] Correspondingly, an embodiment of the present application also provides a computer-readable storage medium, which stores one or more programs. The one or more programs can be executed by one or more processors to implement the memory management method of any virtual machine provided in the aforementioned embodiments, thereby also being able to achieve the corresponding technical effects, which have been described in detail above and will not be repeated here.
[0208] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
[0209] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
[0210] In particular, for the device 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.
[0211] For the convenience of description, the above device is described by dividing the functions into various units / modules. Of course, when implementing the present application, the functions of each unit / module can be implemented in the same or multiple software and / or hardware.
[0212] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0213] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A memory management method for a virtual machine, characterized in that: include: The virtual machine manager sends a secure memory space allocation request to the secure processor; The security processor allocates a secure memory space of a predetermined size for the virtual machine in a pre-allocated secure memory based on the secure memory space allocation request, and sends the address of the allocated secure memory space to the virtual machine manager; The virtual machine accesses the memory and generates a nested page table page fault interrupt; The virtual machine manager calls a first instruction, and establishes a mapping relationship between a virtual machine physical address of the virtual machine and an address of the secure memory space in a nested page table through the first instruction.
2. The memory management method according to claim 1, characterized in that: Before the virtual machine manager sends a secure memory space allocation request to the secure processor, the method further includes: Configure the secure memory size; wherein the secure memory size is determined according to the management data size of each virtual machine.
3. The memory management method according to claim 1, characterized in that: The virtual machine manager calls a first instruction, and establishes a mapping relationship between a virtual machine physical address of the virtual machine and an address of the secure memory space in a nested page table through the first instruction, including: The virtual machine manager calls a first instruction and passes the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space, and the level at which the address of the secure memory space is to be linked to the first instruction; the level is a specified level of the nested page table except the last level; The first instruction links the address of the secure memory space into the level based on the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space and the level to which the address of the secure memory space is to be linked, and establishes a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space.
4. The memory management method according to claim 3, characterized in that: After establishing a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space, the method further includes: The virtual machine manager sends a normal memory space allocation request to the operating system; The operating system allocates a predetermined size of ordinary memory space for the virtual machine in ordinary memory based on the ordinary memory space allocation request, and sends the address of the allocated ordinary memory space to the virtual machine manager; The virtual machine manager calls a second instruction, and links the address of the common memory space into the last level of the nested page table through the second instruction.
5. The memory management method according to claim 4, characterized in that: After the virtual machine manager calls the second instruction and links the address of the common memory space into the last level of the nested page table through the second instruction, the method further includes: The last level of the nested page table is set to a suspended state.
6. The memory management method according to claim 5, characterized in that: After setting the last level of the nested page table to a suspended state, the method further includes: The virtual machine issues a memory access instruction, converts the first virtual machine physical address into the address of the first common memory space through the nested page table, and determines whether the last level of the nested page table where the address of the first common memory space is located is in a suspended state; If the last level of the nested page table where the address of the first common memory space is located is in a suspended state, sending an exception message to the virtual machine; the exception message includes the physical address of the first virtual machine; The virtual machine determines whether the address of the first common memory space is private memory or shared memory according to the encrypted bit of the first virtual machine physical address in the page table; wherein the page table includes the correspondence between the host virtual machine virtual address and the virtual machine physical address and the encrypted bit corresponding to the virtual machine physical address; If the address of the first common memory space is a private memory, the virtual machine calls a third instruction to initialize the content in the address of the first common memory space, and calculates a first hash value of the initialized content.
7. The memory management method according to claim 6, characterized in that: After calculating the first hash value of the initialized content, the method further includes: The virtual machine issues a read instruction; wherein the read instruction includes the physical address of the first virtual machine; Converting the first virtual machine physical address into the address of the first common memory space through the nested page table; Reading content from the address of the first common memory space, and calculating a second hash value of the read content; Comparing the first Hash value with the second Hash value; According to whether the first hash value is consistent with the second hash value, it is determined whether the content corresponding to the address of the first common memory space is tampered with.
8. A memory management device for a virtual machine, characterized in that: include: A sending module, used for sending a secure memory space allocation request to the secure processor through the virtual machine manager; an allocation module, configured to allocate, through the security processor, a secure memory space of a predetermined size for the virtual machine in a pre-allocated secure memory based on the secure memory space allocation request, and send an address of the allocated secure memory space to the virtual machine manager; A generating module, used for generating a nested page table page fault interrupt by accessing the memory through the virtual machine; An establishing module is used to call a first instruction through the virtual machine manager, and establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space in a nested page table through the first instruction.
9. The memory management device according to claim 8, characterized in that: The device also includes: A configuration module is used to configure the secure memory size before the sending module sends a secure memory space allocation request to the secure processor through the virtual machine manager; wherein the secure memory size is determined according to the management data size of each virtual machine.
10. The memory management device according to claim 8, characterized in that: The establishment module includes: a first calling submodule, configured to call a first instruction through the virtual machine manager, and to pass to the first instruction an identifier of the virtual machine, a virtual machine physical address of the virtual machine, an address of the secure memory space, and a level at which the address of the secure memory space is to be linked; the level being a specified level of the nested page table except for the last level; A link-in submodule is used to link the address of the secure memory space into the level based on the identifier of the virtual machine, the virtual machine physical address of the virtual machine, the address of the secure memory space and the level to which the address of the secure memory space is to be linked through the first instruction, so as to establish a mapping relationship between the virtual machine physical address of the virtual machine and the address of the secure memory space.
11. The memory management device according to claim 10, characterized in that: The device also includes: A first sending module, configured to send a normal memory space allocation request to an operating system through a virtual machine manager after the link-in submodule establishes a mapping relationship between a virtual machine physical address of the virtual machine and an address of the secure memory space; an allocation module, configured to allocate a predetermined size of ordinary memory space for the virtual machine in ordinary memory based on the ordinary memory space allocation request through the operating system, and send the address of the allocated ordinary memory space to the virtual machine manager; The second calling module is used to call a second instruction through the virtual machine manager, and link the address of the common memory space into the last level of the nested page table through the second instruction.
12. The memory management device according to claim 11, characterized in that: The device also includes: A suspension module is used to call a second instruction through the virtual machine manager when the second calling submodule calls the second instruction, and after the address of the ordinary memory space is linked to the last level of the nested page table through the second instruction, set the last level of the nested page table to a suspended state.
13. The memory management device according to claim 12, characterized in that: The device also includes: A first judgment module is used for, after the suspend module sets the last level of the nested page table to a suspended state, the virtual machine issues a memory access instruction, converts the first virtual machine physical address into an address of a first common memory space through the nested page table, and judges whether the last level of the nested page table where the address of the first common memory space is located is in a suspended state; A second sending module is used to send exception information to the virtual machine if the last level of the nested page table where the address of the first common memory space is located is in a suspended state; the exception information includes the physical address of the first virtual machine; A second judgment module is used to judge whether the address of the first common memory space is private memory or shared memory according to the encrypted bits of the physical address of the first virtual machine in the page table through the virtual machine; wherein the page table includes the correspondence between the virtual address of the host virtual machine and the physical address of the virtual machine and the encrypted bits corresponding to the physical address of the virtual machine; An initialization module is used to call a third instruction through the virtual machine to initialize the content in the address of the first common memory space if the address of the first common memory space is private memory, and calculate a first hash value of the initialized content.
14. The memory management device according to claim 13, characterized in that: The device also includes: An issuing module, configured to issue a read instruction through the virtual machine after the initialization module calculates a first hash value of the initialized content; wherein the read instruction includes a physical address of the first virtual machine; A conversion module, configured to convert the first virtual machine physical address into an address of the first common memory space through the nested page table; A calculation module, used for reading content from the address of the first common memory space, and calculating a second hash value of the read content; A comparison module, configured to compare the first Hash value with the second Hash value; A determination module is used to determine whether the content corresponding to the address of the first common memory space has been tampered with according to whether the first hash value and the second hash value are consistent.
15. An electronic device, characterized in that: The electronic device comprises: a housing, a processor, a memory, a circuit board and a power supply circuit, wherein the circuit board is placed inside the space enclosed by the housing, and the processor and the memory are arranged on the circuit board; the power supply circuit is used to supply power to various circuits or devices of the above-mentioned electronic device; the memory is used to store executable program codes; the processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, so as to execute the method described in any one of the preceding claims 1-7.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the method according to any one of claims 1 to 7.
