A method for configuring address translation relationship and a computer system
By transferring the address translation relationship from the VM's IPA to PA in the computer system, the problem of high memory mapping complexity of SPM under the multi-TEEos architecture is solved, a simplified address mapping process is realized, and the efficiency is improved.
Patent Information
- Application Number
- CN202011265320.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-12
- Publication Date
- 2024-10-11
- Estimated Expiration
- 2040-11-12
AI Technical Summary
In a multi-TEEos architecture, when SPM establishes memory mapping between VMs and SPs, the code complexity and amount of code are high. Especially when there are a large number of VMs/SPs, discrete physical addresses need to be processed for continuous IPA mapping. , leading to increased complexity.
The first address translation relationship is passed to SPM through the VMM, including the address translation relationship from the intermediate physical address IPA assigned by the VM to the physical address PA. SPM can directly reuse the address translation relationship from IPA to PA, simplifying SPM's transmission of data to the VM. address mapping process.
It simplifies the process of SPM establishing the address mapping relationship from IPA to VA, reduces the code complexity and code volume of memory address mapping configuration, and improves efficiency.
Smart Images

Figure CN114490450B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the computer field, and in particular to a configuration method for address translation relations and a computer system. Background Art
[0002] In order to ensure the security of terminal devices, terminal device security frameworks represented by ARM (advanced RISC machines) have emerged (the full name of RISC in English is reduced instruction set computer). Under the ARM framework, system-level security is achieved by dividing the software and hardware resources of the system on chips (SoC) into two worlds. These two worlds are the normal world and the secure world (also called the security domain and the non-security domain), which correspond to the rich execution environment (REE) and the trusted execution environment (TEE) respectively. REE and TEE run on the same physical device, each running a set of operating systems. REE runs client applications (CA) with low security requirements; TEE runs trusted applications (TA) whose security needs to be guaranteed, and provides a secure execution environment for authorized trusted applications TA. CA and TA communicate through the provided communication mechanism, just like a client and a server.
[0003] With the continuous development of TrustZone technology, major manufacturers have adopted their own trusted operating system (TEEos). In the v8.4 version, ARM introduced the new CPU working mode SEL2 to support hardware virtualization technology on the TEE side. Based on this technology, the TEE side can build a virtualized environment similar to the REE side, creating multiple secure partitions (SP), and each SP can run a TEEos. The multi-TEEos architecture can solve the two problems of TEEos fragmentation and support for multiple VMs on the REE side.
[0004] The current design of TEEos driver (tzdriver) (TrusZone driver, working on the non-secure side and used to communicate with the secure side) is to deploy a tzdriver in each virtual machine (VM). The shared memory between VM and SP is requested by tzdriver. In this way, there is a shared memory between each pair of VM and SP. The traditional method of establishing shared memory between VM and SP is: EL2 VMM (such as Hypervisor) passes the possibly discrete physical address (PA) corresponding to the shared memory to SEL2 SP management (secure partition monitor, SPM), and SPM maps PA to SP's IPA space. Here, the mapped IPA is required to be continuous. Finally, TEEos in SP maps IPA to continuous VA, so that the shared memory between VM and SP is established. However, the PA passed by VMM to SPM is usually a discrete address. SPM needs to map the discrete PA to a continuous IPA. When there are a large number of VMs / SPs, the code complexity and code volume required by SPM for memory mapping are very high. Summary of the invention
[0005] In a first aspect, the present application provides a method for configuring an address translation relationship, the method being applied to a computer system, on which a rich execution environment REE and a trusted execution environment TEE are deployed, the REE is deployed with a virtual machine VM and a virtual machine manager VMM, the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM, wherein the method comprises: the VMM transfers a first address translation relationship to the SPM, the first address translation relationship comprising an address translation relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transfers data from the SP to the VM, the SPM performs an address translation from IPA to PA based on the first address translation relationship, where PA is a memory address.
[0006] Among them, the address sent by the operating system in the kernel space or the user program in the user program space can be called VA, or the address visible to the operating system or user program is VA; the real address of the memory chip is called PA, and the addresses used in the process of mapping VA to PA can be called IPA.
[0007] After receiving the VA, the MMU can map the VA sent by the operating system in the kernel space or the user program in the user program space to the IPA during the first-level memory address translation (stage-1); during the second-level memory address translation (stage-2), the MMU can map the IPA to the PA.
[0008] In the second stage of address translation, the base address of the translation table used by the MMU is specified in the first vttbr_el2. For example, a continuous address space at the bottom of the memory is specified in the first vttbr_el2 as the base address in the translation table.
[0009] In the second stage of address translation, a portion of the internal storage address translation rules used by the MMU are specified in the first vtcr_el2. The first vtcr_el2 is configured with address translation attributes for performing the second-level memory address translation on the REE side. The address translation attributes can specify but are not limited to the size of the memory page, etc. The address translation attributes can be specified by some bits in vtcr_el2, such as PS, TG0, SHO, IRGN0, ORGN0, RES0, SL0, T0SZ and other bits.
[0010] In an embodiment of the present application, the PA obtained by converting the IPA assigned to the VM through the address conversion rules can be used as a shared memory between the VM and the SP. In order to enable the SP side to also use the above-mentioned shared memory, after the VM side applies for the shared memory, the PA of the shared memory should be passed to the SP side, so that the SP side can interact with the VM based on the memory corresponding to the same PA. In the existing implementation, the hypervisor can pass the PA directly to the SPM on the SP side, and then the SPM configures the mapping of the IPA to the PA on the SP side. In an embodiment of the present application, the hypervisor can pass the first address conversion relationship to the SPM, and the first address conversion relationship includes the address conversion relationship from the intermediate physical address IPA assigned to the VM to the physical address PA, so that the SPM performs address conversion from IPA to PA based on the first address conversion relationship when transferring data from the SP to the VM, and the PA is a memory address. That is to say, in this embodiment, the SPM on the TEE side directly uses the IPA to PA address mapping relationship (first address translation relationship) configured on the VM side as the address translation relationship on the SP side itself. When subsequently interacting with the VM, during the second-level memory address translation (stage-2), the IPA to PA mapping can be directly performed based on the first address translation relationship, without the need for the SPM to re-construct the PA to IPA address translation relationship.
[0011] On the one hand, the shared memory (physical address PA) that can be used by different VM / SP pairs configured on the VM side is isolated. In the embodiment of the present application, SPM can reuse the address conversion relationship from IPA to PA on the VM side, so as to isolate the shared memory during the data interaction between different SP / VMs; on the other hand, since SPM directly reuses the address conversion relationship from IPA to PA on the VM side, it simplifies the process of SPM establishing the address mapping relationship from IPA to VA.
[0012] In a possible implementation, the IPA assigned to the VM is a continuous address, and the PA obtained after address conversion of the IPA assigned to the VM through the first address conversion relationship is a discrete address. Usually, the PA transmitted by the VMM to the SPM is a discrete address, and the SPM needs to map the discrete PA to a continuous IPA. When there are a large number of VMs / SPs, the code complexity and amount required by the SPM when performing memory mapping are very high. In this embodiment, since the SPM directly reuses the address conversion relationship from IPA to PA on the VM side, the process of the SPM establishing the address mapping relationship from IPA to VA is simplified.
[0013] In a possible implementation, the REE is deployed with a first virtualization translation table base address register vttbr_el2 and a first control register vtcr_el2, and the first address conversion relationship includes: the base address of the page table configured in the first vttbr_el2 for performing the second-level memory address translation (stage 2 translation) on the REE side, the address conversion attribute configured in the first vtcr_el2 for performing the second-level memory address translation on the REE side, and the IPA assigned to the VM, wherein the IPA assigned to the VM can be converted into PA based on the base address and the memory conversion rules expressed by the address conversion attributes.
[0014] In a possible implementation, the method further includes: the SPM transfers the IPA assigned to the VM to the SP, and the SP is used to establish a second address mapping relationship based on the IPA assigned to the VM, and the second address conversion relationship includes an address conversion relationship from a virtual address VA to IPA, so that when the SP transfers data to the VM, it performs address conversion from VA to IPA based on the second address mapping relationship.
[0015] SP can establish the page table mapping of the first-layer memory address translation Stage-1 corresponding to the shared memory based on the IPA assigned to the VM in the first address mapping relationship, and set the ns bit in the page table entry to 1, to ensure that when the VA corresponding to the shared memory goes through the MMU translation, Stage-2 will automatically select the second vttbr_el2 as the page table base address register, thereby using the non-secure Stage-2 page table for translation. When TEEos in SP needs to access secure memory, since the ns bit in the corresponding Stage-1 page table entry is set to 0, the address translation of Stage-2 will automatically select vsttbr_el2 as the base address.
[0016] In a possible implementation, the TEE is deployed with a second vttbr_el2 and a second vtcr_el2; the method also includes: the SPM writes the base address to the second vttbr_el2, and writes the address conversion attribute to the second vtcr_el2, so that when the SPM transfers data from the SP to the VM, it performs address conversion from IPA to PA based on the base address stored in the second vttbr_el2 and the address conversion attribute stored in the second vtcr_el2.
[0017] In an embodiment of the present application, the TEE is deployed with a second vttbr_el2 and a second vtcr_el2; the SPM can write the base address to the second vttbr_el2, and write the address conversion attribute to the second vtcr_el2, so that when the SPM transfers data from the SP to the VM, it performs address conversion from IPA to PA based on the base address stored in the second vttbr_el2 and the address conversion attribute stored in the second vtcr_el2.
[0018] In one implementation, after the VM on the REE side is started, in order to start the SP corresponding to the VM on the TEE side, the SPM can receive a start request sent by the hypervisor. In addition to instructing the start of the SP on the TEE side, the start request is also used to instruct the SPM to start the SP, and when starting the SP, the base address is written to the second vttbr_el2, and the address translation attribute is written to the second vtcr_el2.
[0019] In one implementation, after applying for a continuous IPA for use by the VM (specifically, it can be tzdriver), the VM passes it to the SPM through a general register, and the SPM writes the base address to the second vttbr_el2 and the address translation attribute to the second vtcr_el2.
[0020] In a possible implementation, before the SPM writes the base address to the second vttbr_el2 and writes the address translation attribute to the second vtcr_el2, the method further includes: the SPM receives a startup request sent by the VMM, the startup request is used to instruct the SPM to start the SP, and when starting the SP, writes the base address to the second vttbr_el2 and writes the address translation attribute to the second vtcr_el2.
[0021] In a possible implementation, the VMM transmits the first address translation relationship to the SPM, including:
[0022] The VMM writes the first address translation relationship into a general register, and triggers the SPM to obtain the first address translation relationship from the general register based on an SMC instruction.
[0023] Specifically, the hypervisor may write the base address of the page table configured in the first vttbr_el2 for performing the second-layer memory address translation on the REE side, the address translation attribute configured in the first vtcr_el2 for performing the second-layer memory address translation on the REE side, and the IPA allocated to the VM into a general register, and trigger the SPM to obtain the above information from the general register based on the SMC instruction. How the SPM obtains the first address translation relationship from the general register based on the triggering of the SMC instruction can be based on existing implementations and will not be repeated here.
[0024] In one implementation, before establishing shared memory on the TEE side, the hypervisor may write the base address of the page table configured in the first vttbr_el2 for performing the second-level memory address translation on the REE side and the address conversion attributes configured in the first vtcr_el2 for performing the second-level memory address translation on the REE side into a general register, and trigger the SPM to obtain the above information from the general register based on the SMC instruction.
[0025] More specifically, the base address and address translation attributes can be passed to the SPM through general registers when the hypervisor sends a start request to the SP when the REE-side VM starts. Alternatively, the VM (specifically, the tzdriver) passes the base address and address translation attributes to the SPM through general registers after applying for a continuous IPA for use by the VM.
[0026] In a second aspect, the present application provides a computer system, on which a rich execution environment REE and a trusted execution environment TEE are deployed, the REE is deployed with a virtual machine VM and a virtual machine manager VMM, the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM, wherein:
[0027] The VMM is used to pass a first address translation relationship to the SPM, where the first address translation relationship includes an address translation relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transfers data from the SP to the VM, it performs an address translation from IPA to PA based on the first address translation relationship, where PA is a memory address.
[0028] In a possible implementation, the IPA assigned to the VM is a continuous address, and the PA obtained after performing address conversion on the IPA assigned to the VM through the first address conversion relationship is a discrete address.
[0029] In a possible implementation, the REE is deployed with a first virtualization translation table base address register vttbr_el2 and a first control register vtcr_el2, and the first address conversion relationship includes: the base address of the page table configured in the first vttbr_el2 for performing the second-level memory address translation (stage 2 translation) on the REE side, the address conversion attribute configured in the first vtcr_el2 for performing the second-level memory address translation on the REE side, and the IPA assigned to the VM, wherein the IPA assigned to the VM can be converted into PA based on the base address and the memory conversion rules expressed by the address conversion attributes.
[0030] In a possible implementation, the SPM is used to transfer the IPA assigned to the VM to the SP, and the SP is used to establish a second address mapping relationship based on the IPA assigned to the VM, where the second address conversion relationship includes an address conversion relationship from a virtual address VA to IPA, so that when the SP transfers data to the VM, it performs address conversion from VA to IPA based on the second address mapping relationship.
[0031] In a possible implementation, the TEE is deployed with a second vttbr_el2 and a second vtcr_el2; the SPM is used to write the base address to the second vttbr_el2, and write the address conversion attribute to the second vtcr_el2, so that when the SPM transfers data from the SP to the VM, it performs address conversion from IPA to PA based on the base address stored in the second vttbr_el2 and the address conversion attribute stored in the second vtcr_el2.
[0032] In a possible implementation, the SPM is used to receive a startup request sent by the VMM, where the startup request is used to instruct the SPM to start the SP, and when starting the SP, write the base address to the second vttbr_el2, and write the address translation attribute to the second vtcr_el2.
[0033] In a possible implementation, the VMM is used to write the first address translation relationship into a general register, and trigger the SPM to obtain the first address translation relationship from the general register based on an SMC instruction.
[0034] In a third aspect, the present application provides a computer system, which includes a memory and a processor, wherein the memory is used to store computer-readable instructions (or computer programs), and the processor is used to read the computer-readable instructions to implement the method provided by any of the aforementioned implementations.
[0035] In a fourth aspect, the present application provides a computer storage medium, which may be non-volatile. The computer storage medium stores computer-readable instructions, which, when executed by a processor, implement the method provided by any of the aforementioned implementations.
[0036] In a fifth aspect, the present application provides a computer program product, which includes computer-readable instructions. When the computer-readable instructions are executed by a processor, the method provided by any of the aforementioned implementations is implemented.
[0037] The embodiment of the present application provides a method for configuring an address translation relationship, the method being applied to a computer system, on which a rich execution environment REE and a trusted execution environment TEE are deployed, the REE is deployed with a virtual machine VM and a virtual machine manager VMM, the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM, wherein the method comprises: the VMM transmits a first address translation relationship to the SPM, the first address translation relationship comprising an address translation relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transmits data from the SP to the VM, the SPM performs an address translation from IPA to PA based on the first address translation relationship, wherein PA is a memory address. In the above manner, the process of the SPM establishing an address mapping relationship from IPA to VA is simplified, thereby reducing the code complexity and amount required for the SPM to configure memory address mapping. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A schematic diagram of a hardware architecture provided for an embodiment of the present application;
[0039] Figure 2 It is a schematic diagram of the execution of kernel mode instructions;
[0040] Figure 3 This is a schematic diagram of an ARM architecture server structure;
[0041] Figure 4 The structure of a smart terminal is shown in FIG.
[0042] Figure 5 This is an illustration of the exception levels defined in the ARM processor;
[0043] Figure 6 A flowchart of a method for configuring an address translation relationship provided in an embodiment of the present application;
[0044] Figure 7 This is a schematic diagram of the memory address translation process;
[0045] Figure 8 An illustration of an address conversion attribute provided in an embodiment of the present application;
[0046] Fig. 9 A flowchart of a method for configuring an address translation relationship provided in an embodiment of the present application;
[0047] Fig.10 A flowchart of a method for configuring an address translation relationship provided in an embodiment of the present application;
[0048] Fig.11 A schematic diagram of the structure of a computer system provided in this embodiment;
[0049] Fig.12 The following is a schematic diagram of the structure of an NPU provided in this embodiment. DETAILED DESCRIPTION
[0050] The following describes the embodiments of the present application in conjunction with the accompanying drawings. Obviously, the described embodiments are only embodiments of a part of the present application, rather than all embodiments. It is known to those skilled in the art that with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0051] The terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described here can be implemented in an order other than that illustrated or described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices. The naming or numbering of steps in this application does not mean that the steps in the method flow must be executed in the time / logical sequence indicated by the naming or numbering. The process steps that have been named or numbered can change the execution order according to the technical purpose to be achieved, as long as the same or similar technical effects can be achieved.
[0052] In addition, in the description of the present invention, unless otherwise specified, "plurality" means two or more. The term "and / or" or the character " / " in this application is only a description of the association relationship of associated objects, indicating that there may be three relationships, for example, A and / or B, or A / B, can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0053] The rapid development of smart mobile terminals has brought great convenience to our lives. Most mobile terminals run on ARM central processing units (CPUs). With the continuous improvement of ARM CPU performance, ARM CPUs have begun to be widely used in servers. Nowadays, smart terminals and cloud servers carry more and more user personal information, and users are paying more and more attention to the security of their devices. On ARM CPUs, the current mainstream system-level solution is TrustZone technology.
[0054] ARM TrustZone technology was first introduced in the ARMv6 version as a security extension. It divides the hardware resources into two worlds, the non-secure world (rich execution environment (REE) side) and the secure world (trusted execution environment (TEE) side). The operating system, which is closely related to the user, works in the non-secure world, and TrustZone, as a hardware security feature, works in the secure world. The non-secure world does not mean that the operating system or software running in it is malicious, but that the security of the environment it is in is lower than that of the secure world. Because when the CPU works in the non-secure world, the resources of the secure world (such as registers, memory, cache, peripherals, etc.) are prohibited from access. Once the CPU tries to access these resources, the system will crash directly. For example, TrustZone can set sensitive memory to Secure Memory by configuring the TZASC (TrustZone Address Space Contoller) register and the TZMA (TrustZone Memory Adapter) register, so that the non-secure world cannot access this memory. When the CPU works in the secure world, it can access resources in both the secure world and the non-secure world. Because it has higher permissions than the operating system in the non-secure world, TrustZone can serve as a trusted root to provide a higher level of security protection for the operating system in the non-secure world.
[0055] Figure 1Describes the hardware architecture of ARMv7. The left side is the architecture of the non-secure world. In order to support CPU hardware virtualization, ARM has added the HYP mode based on the two CPU modes of user mode (USR mode) and kernel mode (SVC mode). The operating system that is closely connected to the user runs in the user mode and kernel mode of the non-secure world, and the hypervisor runs in the newly added HYP mode. HYP mode is the CPU mode with the highest authority in the non-secure world. When the CPU works in this mode, it can access all hardware resources in user mode, kernel mode and HYP mode; but when the CPU runs in the other two modes, it cannot access HYP-related hardware resources. Therefore, the hypervisor has higher authority than the operating system. Like the non-secure world, the secure world on the right also includes two CPU working modes: user mode and kernel mode. On ARMv7, the secure world does not support hardware virtualization, so it does not include the HYP mode, but in the latest ARMv8.4 architecture, the secure world begins to support hardware virtualization. The secure world also includes a special CPU mode with the highest authority: monitor mode. Monitor mode is the highest privilege mode of the CPU. When the CPU works in this mode, it can access all hardware resources in the secure world as well as all hardware resources in the non-secure world. TrustZone can configure the control registers related to the Hypervisor in monitor mode to initialize and activate the Hypervisor. Monitor mode is also a gateway for the non-secure world to enter the secure world. In the kernel mode or HYP mode of the non-secure world, the SMC (Secure Monitor Call) instruction can be executed to actively switch from the non-secure world to the monitor mode of the secure world. When the ERET instruction is executed in monitor mode, the CPU decides whether to return to the non-secure world or continue to stay in the secure world by checking the NS (non-secure) bit of the SCR (Secure Control Register) register. When the NS bit is 1, the return operation in monitor mode returns to the kernel of the non-secure world and performs the world switch operation; when the NS bit is 0, the return operation in monitor mode returns to the kernel of the secure world and does not perform the world switch operation.
[0056] Hypervisor, as a virtualization extension of ARM, was first introduced in the ARMv7 version. Figure 1As shown in Figure 1, the non-secure world contains three privilege levels: PL0, PL1, and PL2. The hypervisor works at PL2, which is the highest privilege level in the non-secure world. Executing the HVC (Hypervisor Call) instruction in kernel mode in the non-secure world is a common way to enter the hypervisor; executing the ERET instruction in HYP mode to return to kernel mode (such as Figure 2 As shown). To support memory virtualization, ARM introduced the second-level memory address translation (Stage-2 translation) memory virtualization technology. With this technology, the common one-level memory address translation from virtual address to physical address (VA->PA) is transformed into two-level memory address translation from virtual address to intermediate physical address IPA, and then from intermediate physical address to physical address (VA->IPA->PA). The second-level memory address translation (IPA->PA) process is completely controlled by the Hypervisor and is transparent to the operating system. In the eyes of the operating system, IPA is the "physical address" it uses.
[0057] In terms of memory virtualization support, the design of the TEE side is slightly different from that of the REE side. There are two base address registers for Stage-2 on the TEE side: vttbr_el2 and vsttbr_el2, while there is only one base address register for Stage-2, vttbr_el2, on the REE side. During the Stage-1 translation process, if the NS bit in the page table entry is 1, the memory management unit (MMU) will select vttbr_el2 as the base address register when performing Stage-2 translation; if the NS bit in the page table entry is 0, the MMU will select vsttbr_el2 as the base address register for Stage-2 translation. This process is completed automatically by the MMU and does not require software participation. The purpose of designing the two registers vttbr_el2 and vsttbr_el2 is that when the CPU works on the TEE side, it may access secure memory or non-secure memory, and secure memory and non-secure memory can be distinguished by these two sets of Stage-2 page tables. Through configuration, the system can ensure that the physical address translated from the Stage-2 page table pointed to by vttbr_el2 falls on the non-secure memory; the physical address translated from the page table of vsttbr_el2 falls on the secure memory.
[0058] Next, the scenario architecture of this application is described.
[0059] This application can be applied to servers based on ARM architecture. In the ARM server scenario, both the rich execution environment REE and the trusted execution environment TEE support hardware virtualization features. Tenants will establish multiple VMs on the REE side. In order to provide each tenant with TEE trusted execution environment support, when the VM is started, a security isolation zone SP will be started on the TEE side accordingly, and TEEos will be started in SP to support security services in the VM. Its architecture is as follows: Figure 3 As shown. At runtime, the CA in the VM (a client application running on the REE side that can call TEE services) requests the security services of the TA in the SP (a trusted application running on the TEE side).
[0060] The present application can also be applied to intelligent terminals (such as portable devices such as smart phones), such as Figure 4 As shown in the figure, in the scenario of smart terminals, although there is no strong demand for REE and TEE to start multiple VMs / SPs, when the memory virtualization features on the REE and TEE sides are turned on, the client system Guest OS (such as Android OS) on the REE side can be considered to be running in the VM, and the TEEos on the TEE side can be considered to be running in the SP.
[0061] The present application can be used in the above-mentioned servers and intelligent terminals, and can be specifically applied to the process of configuring the memory address translation relationship of the TEE side SPM when configuring the shared memory of the VM and SP.
[0062] The above-mentioned server and intelligent terminal (which may also be referred to as a computer system in the embodiment of the present application) may include a processor and a memory. The processor may also be referred to as a central processing unit (CPU) or a central processing unit.
[0063] An example of a processor in the computer system is an Advanced RISC-based instruction set (ARM) processor. An example of a memory in the computer is a random access memory (RAM) or a flash memory (Flash). RAM may also be referred to as main memory or memory. The memory has access rights attributes, such as read-only, writable, executable, and inaccessible.
[0064] The processor of the computer system uses virtualization technology. Virtualization technology can hide the underlying physical hardware in the computer, so that multiple independently running operating systems (operator systems, OS) can transparently use and share the hardware resources of the computer. Simply put, virtualization technology can enable the computer to run multiple OS concurrently.
[0065] The processor in the computer provides different permission levels for program codes to access resources in the computer to protect data in the computer and prevent malicious behavior from occurring in the computer, thereby ensuring the security of the computer.
[0066] For example, Figure 5 As shown, four exception levels (EL) can be defined in the ARM processor, namely EL0, EL1, EL2 and EL3. Among them, the higher the level of the exception level, the smaller the value, the lower the level of the exception level. For example, the level of EL0 is lower than the level of EL1, the level of EL1 is lower than the level of EL2, and the level of EL2 is lower than the level of EL3. Of course, it can also be that the larger the value, the lower the level of the exception level, and the smaller the value, the higher the level of the exception level, which is not limited in the embodiments of the present application.
[0067] Different levels of exception levels correspond to different levels of operating space. The division of exception levels or the division of operating space provides logically separated execution permissions for software in all operating states in the processor. It should be understood that the exception levels mentioned in this application are similar to the common hierarchical protection domains in computer science and support the concepts involved in hierarchical protection domains.
[0068] Examples of software running at each of the four exception levels are as follows. Ordinary user applications run in the runtime corresponding to EL0; operating system kernels, such as Linux or Windows, can run in the runtime corresponding to EL1, and operating system kernels are generally considered privileged; hypervisors run in the runtime corresponding to EL2; low-level firmware, such as security monitors, run in the runtime corresponding to EL3. Hypervisors can also be called super managers. When enabled, hypervisors can provide virtualization services for one or more operating system kernels.
[0069] Firmware (such as ARM trusted firmware) is the first thing that runs when the processor starts. Firmware provides many services, such as platform initialization, installation of trusted operating systems, and routing of commands for security monitors. In the processor of this computer, the CPU execution unit can manage or access memory through the memory management unit (MMU). For example, the MMU can perform operations such as address mapping and providing memory access authorization.
[0070] In the processor, when the program code running in the running space corresponding to different exception levels accesses the memory, the MMU performs different address mapping and different memory access authorization processes.
[0071] Reference Figure 5 , Figure 5 The flowchart of a method for configuring an address translation relationship provided in an embodiment of the present application is shown. The method for configuring an address translation relationship provided in an embodiment of the present application can be applied to a computer system, such as Figure 6 As shown, a rich execution environment REE and a trusted execution environment TEE may be deployed on the computer system provided by the present application, and the REE may be deployed with a virtual machine VM and a virtual machine manager VMM (for example, Figure 6 The hypervisor shown in the figure, the following embodiments are also described by taking VMM as the hypervisor as an example), and the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM.
[0072] Among them, VMM is equivalent to hypervisor or other types of virtual monitoring devices in the virtualization architecture. VMM can be deployed inside the host operating system or separately from the host operating system. VMM = responsible for managing one or more virtual machines running on it.
[0073] A virtual machine (VM) includes a client operating system (Guest OS) and multiple applications (including CA). A virtual machine VM may contain a container, which is equivalent to an application. In some other embodiments, the virtualization layer is implemented by lightweight virtualization technology, such as libOS. A libOS usually contains an application, and the entire libOS is one or more libraries, which are linked to the application into a single address space image. The embodiments of the present application generally take a virtual machine implemented by traditional virtualization technology as an example, and other types of virtualization architectures can refer to the implementation of virtual machines.
[0074] In version v8.4, ARM introduced a new CPU working mode, SEL2, to support hardware virtualization technology on the TEE side. Based on this technology, the TEE side can build a virtualized environment similar to the REE side, creating multiple SPs (SecurePartitions), and each SP can run a TEEos and TA.
[0075] There are many forms of VM and SP creation process, for example, each time a VM is started on the REE side, a corresponding SP is started on the TEE side, and the VM and the corresponding SP interact at runtime, or the TEE side starts multiple SPs first, and the REE then starts the VM, and at runtime, the VM selects one of the SPs to interact. Regardless of the creation method, the interaction between the CA in the VM and the TA in the SP at runtime needs to use shared memory to transmit and receive data.
[0076] The method for configuring the address translation relationship provided in the embodiment of the present application may include:
[0077] 501. The VMM transfers a first address translation relationship to the SPM, where the first address translation relationship includes an address translation relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transfers data from the SP to the VM, the SPM performs an address translation from IPA to PA based on the first address translation relationship, where PA is a memory address.
[0078] In the embodiment of the present application, after the computer system is powered on, the ARM trusted firmware (ATF) in the computer system can be initialized first. After the ATF initialization is completed, it can jump to SEL2 and complete the initialization of SPM (it should be noted that ARM implements an SPM in the form of software in EL3, and SPM can support the running of two TEEos on the TEE side). After the SEL2 initialization is completed, it can return to the REE side to initialize the EL2 hypervisor.
[0079] After the initialization of the hypervisor is completed, the address conversion rules from IPA to PA can be established. When the VM wants to apply for shared memory for interaction with the SP, the tzdriver in the Guest OS of the VM can apply for shared memory between the VM and the SP, so that there is a shared memory between each pair of VM and SP. The shared memories between different pairs of VM / SP are isolated from each other. The tzdriver is the driver of TrusZone, which works in REE and is used to communicate with the security side. One tzdriver can be deployed in each VM. Specifically, the tzdriver can apply for a continuous IPA as the IPA assigned to the VM. In the subsequent data interaction between the VM and the corresponding SP, the IPA assigned to the VM can be converted to PA, and the converted PA is used as the shared memory between the VM and the SP.
[0080] In an embodiment of the present application, after tzdriver obtains a continuous IPA for the VM in which it is located, the hypervisor can determine that the continuous IPA is allocated to the VM, and can determine that the PA obtained after the conversion is used as the shared memory between the VM and the SP. The Guest OS can further configure the address conversion relationship from VA to IPA during the first-level memory address translation process. Specifically, the Guest OS can map the continuous IPA obtained by tzdriver to VA to establish the address conversion relationship from VA to IPA. In the process of VM passing data to SP, the MMU can obtain the corresponding IPA through the first-level memory address translation based on the VA sent by the Guest OS in the kernel space or the user program in the user program space, and obtain the corresponding PA through the second-level memory address translation, and use the PA as the shared memory between the VM and the SP to realize data transfer to the SP.
[0081] Among them, the address sent by the operating system in the kernel space or the user program in the user program space can be called VA, or the address visible to the operating system or user program is VA; the real address of the memory chip is called PA, and the addresses used in the process of mapping VA to PA can be called IPA.
[0082] More specifically, the REE is deployed with a first virtualization translation table base register (virtualizationtranslation table base register, vttbr)_el2 and a first control register vtcr_el2. The hypervisor can configure the base address of the page table for performing the second-level memory address translation (stage 2translation) on the REE side in the first vttbr_el2, and configure the address translation attributes for performing the second-level memory address translation on the REE side in the first vtcr_el2. During the second-level memory address translation process, the hypervisor can translate the IPA to be translated into the corresponding PA based on the base address and the address translation attributes.
[0083] like Figure 7 As shown, after receiving VA, the MMU can map the VA sent by the operating system in the kernel space or the user program in the user program space to IPA during the first-level memory address translation (stage-1); during the second-level memory address translation (stage-2), the MMU can map IPA to PA.
[0084] In the second stage of address translation, the base address of the translation table used by the MMU is specified in the first vttbr_el2. For example, a continuous address space at the bottom of the memory is specified in the first vttbr_el2 as the base address in the translation table.
[0085] In the second stage of address translation, a portion of the internal storage address translation rules used by the MMU are specified in the first vtcr_el2. The first vtcr_el2 is configured with address translation attributes for performing the second-level memory address translation on the REE side. The address translation attributes can specify but are not limited to the size of the memory page, etc., such as Figure 8 As shown, the address translation attributes can be specified by some bits in vtcr_el2, for example Figure 8 The bits (PS, TG0, SHO, IRGN0, ORGN0, RES0, SL0, T0SZ) shown.
[0086] In an embodiment of the present application, the PA obtained by converting the IPA assigned to the VM through the address conversion rules can be used as a shared memory between the VM and the SP. In order to enable the SP side to also use the above-mentioned shared memory, after the VM side applies for the shared memory, the PA of the shared memory should be passed to the SP side, so that the SP side can interact with the VM based on the memory corresponding to the same PA. In the existing implementation, the hypervisor can pass the PA directly to the SPM on the SP side, and then the SPM configures the mapping of the IPA to the PA on the SP side. In an embodiment of the present application, the hypervisor can pass the first address conversion relationship to the SPM, and the first address conversion relationship includes the address conversion relationship from the intermediate physical address IPA assigned to the VM to the physical address PA, so that the SPM performs address conversion from IPA to PA based on the first address conversion relationship when transferring data from the SP to the VM, and the PA is a memory address.
[0087] That is to say, in this embodiment, the SPM on the TEE side directly uses the IPA to PA address mapping relationship (first address translation relationship) configured on the VM side as the address translation relationship on the SP side itself. When subsequently interacting with the VM, during the second-level memory address translation (stage-2), the IPA to PA mapping can be directly performed based on the first address translation relationship, without the need for the SPM to re-construct the PA to IPA address translation relationship.
[0088] Next, it is described how the hypervisor transmits the first address translation relationship to the SPM, and how the SPM configures the translation page table related to the second-level memory address translation (stage-2) based on the first address translation relationship after receiving the first address translation relationship.
[0089] In one implementation, the hypervisor may write the first address translation relationship into a general register, and trigger the SPM to obtain the first address translation relationship from the general register based on an SMC instruction.
[0090] In an embodiment of the present application, the first address conversion relationship includes: the base address of the page table configured in the first vttbr_el2 for performing the second-level memory address translation on the REE side, the address conversion attribute configured in the first vtcr_el2 for performing the second-level memory address translation on the REE side, and the IPA assigned to the VM. The IPA assigned to the VM can be converted into PA based on the base address and the memory conversion rules expressed by the address conversion attributes.
[0091] Specifically, the hypervisor may write the base address of the page table configured in the first vttbr_el2 for performing the second-layer memory address translation on the REE side, the address translation attribute configured in the first vtcr_el2 for performing the second-layer memory address translation on the REE side, and the IPA allocated to the VM into a general register, and trigger the SPM to obtain the above information from the general register based on the SMC instruction. How the SPM obtains the first address translation relationship from the general register based on the triggering of the SMC instruction can be based on existing implementations and will not be repeated here.
[0092] In one implementation, before establishing shared memory on the TEE side, the hypervisor may write the base address of the page table configured in the first vttbr_el2 for performing the second-level memory address translation on the REE side and the address conversion attributes configured in the first vtcr_el2 for performing the second-level memory address translation on the REE side into a general register, and trigger the SPM to obtain the above information from the general register based on the SMC instruction.
[0093] More specifically, the base address and address translation attributes can be passed to the SPM through general registers when the hypervisor sends a start request to the SP when the REE-side VM starts. Alternatively, the VM (specifically, the tzdriver) passes the base address and address translation attributes to the SPM through general registers after applying for a continuous IPA for use by the VM.
[0094] Next, the configuration of the translation page table related to the second-level memory address translation (stage-2) performed by the hypervisor based on the first address translation relationship is described.
[0095] In an embodiment of the present application, the TEE is deployed with a second vttbr_el2 and a second vtcr_el2; the SPM can write the base address to the second vttbr_el2, and write the address conversion attribute to the second vtcr_el2, so that when the SPM transfers data from the SP to the VM, it performs address conversion from IPA to PA based on the base address stored in the second vttbr_el2 and the address conversion attribute stored in the second vtcr_el2.
[0096] In one implementation, after the VM on the REE side is started, in order to start the SP corresponding to the VM on the TEE side, the SPM can receive a start request sent by the hypervisor. In addition to instructing the start of the SP on the TEE side, the start request is also used to instruct the SPM to start the SP, and when starting the SP, the base address is written to the second vttbr_el2, and the address translation attribute is written to the second vtcr_el2.
[0097] In one implementation, after applying for a continuous IPA for use by the VM (specifically, it can be tzdriver), the VM passes it to the SPM through a general register, and the SPM writes the base address to the second vttbr_el2 and the address translation attribute to the second vtcr_el2.
[0098] In the embodiment of the present application, the base address of the second vttbr_el2 of the SP on the TEE side and the first vttbr_el2 of the corresponding VM on the REE side are configured to be the same, so that the SP and the VM share the non-secure Stage-2 page table. The IPA passed to the SP in the VM can be directly applied by the SP, so that the address translation of the IPA-PA in the SP is consistent with the memory address translation rules of the IPA-PA in the VM.
[0099] In the present application, refer to Fig. 9, the SPM may transfer the IPA assigned to the VM to the SP, and the SP is used to establish a second address mapping relationship based on the IPA assigned to the VM, and the second address translation relationship includes an address translation relationship from a virtual address VA to IPA, so that when the SP transfers data to the VM, it performs address translation from VA to IPA based on the second address mapping relationship. The SP may establish a page table mapping of the first-layer memory address translation Stage-1 corresponding to the shared memory based on the IPA assigned to the VM in the first address mapping relationship, and set the ns bit in the page table entry to 1, so as to ensure that when the VA corresponding to the shared memory goes through the MMU translation, Stage-2 will automatically select the second vttbr_el2 as the page table base address register, thereby using the non-secure Stage-2 page table for translation. When the TEEos in the SP needs to access secure memory, since the ns bit in the corresponding Stage-1 page table entry is set to 0, the address translation of Stage-2 will automatically select vsttbr_el2 as the base address.
[0100] In addition, in order to share the Stage-2 page table, the second vtcr_el2 in the SP also needs to have the same configuration as the first vtcr_el2 in the VM. This requires that the EL2 hypervisor can also pass the value (address translation attribute) of the first vtcr_el2 of the VM to the SPM so that the SPM writes the address translation attribute to the second vtcr_el2.
[0101] It should be understood that during the configuration of the second vtcr_el2, the two bits NSA and NSW on the second vtcr_el2 are of little significance to the VM on the REE side, but have the following meanings for the SP on the TEE side: when NSA is 0, the physical address translated from the page table pointed to by the second vttbr_el2 falls in the secure memory; and when NSA is 1, the translated physical address falls in the non-secure memory. For the scenarios in the embodiments of the present application, the NSA in the second vtcr_el2 on the TEE side needs to be configured to 1. When NSW is 0, the page table pointed to by the second vttbr_el2 needs to be stored in the secure memory; and when NSW is 1, the page table needs to be stored in the non-secure memory. Similarly, for the scenarios in the embodiments of the present application, the NSW in the second vtcr_el2 on the TEE side needs to be configured to 1. Therefore, in addition to configuring the address translation attribute of the second vtcr_el2 register of the SP to be the same as the first vtcr_el2 of the corresponding VM, it is also necessary to set the two bits NSA in vtcr_el2 and NSW in vtcr_el2 to 1.
[0102] In one implementation, the IPA assigned to the VM is a continuous address, and the PA obtained after performing address conversion on the IPA assigned to the VM through the first address conversion relationship is a discrete address.
[0103] Reference Fig.10 , the Stage-2 MMU on the TEE side has two base address registers, the second vttbr_el2 and the second vsttbr_el2 (marked as vttbr_el2 and vsttbr_el2 in the figure), the second vttbr_el2 and the second vsttbr_el2 correspond to the non-secure and secure address translations respectively, the physical memory obtained by the vttbr_el2 translation falls into the non-secure memory, and the physical memory obtained by the vsttbr_el2 translation falls into the secure memory. In the process of VM passing data to SP, in the stage 1 stage, the MMU can perform address translation based on ttbr0_el1 and ttbr1_el1 on the REE side, and in the stage 2 stage, the MMU can perform address translation based on vttbr_el2 on the REE side. In the process of SP passing data to VM, in the stage 1 stage, the address translation can be based on ttbr0_el1 and ttbr1_el1 on the TEE side, and in the stage 2 stage, the address translation can be based on vttbr_el2 on the TEE side.
[0104] In the embodiment of the present application, on the one hand, the shared memory (physical address PA) that can be used by different VM / SP pairs configured on the VM side is isolated. In the embodiment of the present application, SPM can reuse the address conversion relationship from IPA to PA on the VM side, so as to isolate the shared memory during the data interaction between different SP / VMs; on the other hand, since SPM directly reuses the address conversion relationship from IPA to PA on the VM side, it simplifies the process of SPM establishing the address mapping relationship from IPA to VA.
[0105] The embodiment of the present application provides a method for configuring an address translation relationship, the method is applied to a computer system, a rich execution environment REE and a trusted execution environment TEE are deployed on the computer system, the REE is deployed with a virtual machine VM and a virtual machine manager VMM, the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM, wherein the method comprises: the VMM transmits a first address translation relationship to the SPM, the first address translation relationship comprises an address translation relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transmits data from the SP to the VM, the address translation from IPA to PA is performed based on the first address translation relationship, and the PA is a memory address. In the above manner, the process of the SPM establishing an address mapping relationship from IPA to VA is simplified.
[0106] An embodiment of the present application also provides a computer system, on which a rich execution environment REE and a trusted execution environment TEE are deployed, the REE is deployed with a virtual machine VM and a virtual machine manager VMM, and the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM, wherein the VMM is used to pass a first address conversion relationship to the SPM, and the first address conversion relationship includes an address conversion relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transfers data from the SP to the VM, it performs address conversion from IPA to PA based on the first address conversion relationship, and the PA is a memory address.
[0107] In a possible implementation, the IPA assigned to the VM is a continuous address, and the PA obtained after performing address conversion on the IPA assigned to the VM through the first address conversion relationship is a discrete address.
[0108] In a possible implementation, the REE is deployed with a first virtualization translation table base address register vttbr_el2 and a first control register vtcr_el2, and the first address conversion relationship includes: the base address of the page table configured in the first vttbr_el2 for performing the second-level memory address translation (stage 2 translation) on the REE side, the address conversion attribute configured in the first vtcr_el2 for performing the second-level memory address translation on the REE side, and the IPA assigned to the VM, wherein the IPA assigned to the VM can be converted into PA based on the base address and the memory conversion rules expressed by the address conversion attributes.
[0109] In a possible implementation, the SPM is used to transfer the IPA assigned to the VM to the SP, and the SP is used to establish a second address mapping relationship based on the IPA assigned to the VM, where the second address conversion relationship includes an address conversion relationship from a virtual address VA to IPA, so that when the SP transfers data to the VM, it performs address conversion from VA to IPA based on the second address mapping relationship.
[0110] In a possible implementation, the TEE is deployed with a second vttbr_el2 and a second vtcr_el2; the SPM is used to write the base address to the second vttbr_el2, and write the address conversion attribute to the second vtcr_el2, so that when the SPM transfers data from the SP to the VM, it performs address conversion from IPA to PA based on the base address stored in the second vttbr_el2 and the address conversion attribute stored in the second vtcr_el2.
[0111] In a possible implementation, the SPM is used to receive a startup request sent by the VMM, where the startup request is used to instruct the SPM to start the SP, and when starting the SP, write the base address to the second vttbr_el2, and write the address translation attribute to the second vtcr_el2.
[0112] In a possible implementation, the VMM is used to write the first address translation relationship into a general register, and trigger the SPM to obtain the first address translation relationship from the general register based on an SMC instruction.
[0113] The relevant description of the computer system in this embodiment can refer to the above embodiment. Figures 1 to 10 The description of the related embodiments will not be repeated here.
[0114] The present application also provides a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium contains computer instructions, and when the computer instructions are executed by a computer, the interrupt processing method in the above embodiment can be implemented.
[0115] Please refer to Fig.11 , is a schematic diagram of the structure of a computer system provided in this embodiment. The computer system may be a terminal device (or referred to as an intelligent terminal) or a server. As shown in the figure, the computer system includes a communication module 810, a sensor 820, a user input module 830, an output module 840, a processor 850, an audio and video input module 860, a memory 870, and a power supply 880. Furthermore, the computer system provided in this embodiment may also include an NPU 890.
[0116] The communication module 810 may include at least one module that enables the computer system to communicate with a communication system or other computer systems. For example, the communication module 810 may include one or more of a wired network interface, a broadcast receiving module, a mobile communication module, a wireless Internet module, a local area communication module, and a location (or positioning) information module. These various modules are all implemented in various ways in the prior art, and this application will not describe them one by one.
[0117] The sensor 820 may sense the current state of the system, such as an open / closed state, a position, whether there is contact with a user, a direction, and acceleration / deceleration, and the sensor 820 may generate a sensing signal for controlling the operation of the system.
[0118] The user input module 830 is used to receive input digital information, character information or contact touch operation / contactless gesture, and receive signal input related to user settings and function control of the system, etc. The user input module 830 includes a touch panel and / or other input devices.
[0119] The output module 840 includes a display panel for displaying information input by the user, information provided to the user, or various menu interfaces of the system. Optionally, the display panel can be configured in the form of a liquid crystal display (LCD) or an organic light-emitting diode (OLED). In some other embodiments, the touch panel can cover the display panel to form a touch display screen. In addition, the output module 840 can also include an audio output module, an alarm, and a tactile module.
[0120] The audio and video input module 860 is used to input audio signals or video signals. The audio and video input module 860 may include a camera and a microphone.
[0121] The power supply 880 may receive external power and internal power under the control of the processor 850 and provide power required for the operation of various components of the system.
[0122] The processor 850 includes one or more processors. For example, the processor 850 may include a central processing unit and a graphics processing unit. The central processing unit in this application has multiple cores and belongs to a multi-core processor. These multiple cores can be integrated on the same chip or each can be an independent chip.
[0123] The memory 870 stores computer programs, which include an operating system program 872 and an application program 871. Typical operating systems include Microsoft's Windows, Apple's MacOS, and other systems for desktops or notebooks, and systems for mobile terminals such as the Android system developed by Google. The method provided in the above embodiment can be implemented by software and can be considered as a specific implementation of the operating system program 872. The memory 870 can be one or more of the following types: flash memory, hard disk type memory, micro multimedia card type memory, card memory (such as SD or XD memory), random access memory (random access memory, RAM), static random access memory (static RAM, SRAM), read only memory (read only memory, ROM), electrically erasable programmable read-only memory (electrically erasable programmable read-only memory, EEPROM), programmable read-only memory (programmable ROM, PROM), rollback protection storage block (replay protected memoryblock, RPMB), magnetic storage, disk or optical disk. In some other embodiments, the memory 870 may also be a network storage device on the Internet, and the system may perform operations such as updating or reading on the memory 870 on the Internet.
[0124] The processor 850 is used to read the computer program in the memory 870 and then execute the method defined by the computer program. For example, the processor 850 reads the operating system program 872 to run the operating system and implement various functions of the operating system on the system, or reads one or more application programs 871 to run applications on the system.
[0125] The memory 870 also stores other data 873 in addition to the computer program.
[0126] NPU 890 is mounted on the main processor 850 as a coprocessor to execute the tasks assigned to it by the main processor 850. In this embodiment, NPU 890 can be called by one or more sub-threads of face recognition TA to implement some complex algorithms involved in face recognition. Specifically, the sub-threads of face recognition TA run on multiple cores of the main processor 850, and then the main processor 850 calls NPU 890, and the results implemented by NPU 890 are returned to the main processor 850.
[0127] The connection relationship between the above modules is only an example. The configuration method of the address conversion relationship provided in any embodiment of the present application can also be applied to terminal devices or servers with other connection methods, for example, all modules are connected through a bus.
[0128] Fig.12 9 is a schematic diagram of the structure of an NPU 900 provided in this embodiment. The NPU 900 is connected to a main processor and an external memory. The core part of the NPU 900 is an operation circuit 903, which is controlled by a controller 904 to extract data from the memory and perform mathematical operations.
[0129] In some implementations, the operation circuit 903 includes multiple processing engines (PEs) inside. In some implementations, the operation circuit 903 is a two-dimensional systolic array. The operation circuit 903 can also be a one-dimensional systolic array or other electronic circuits capable of performing mathematical operations such as multiplication and addition. In other implementations, the operation circuit 903 is a general-purpose matrix processor.
[0130] For example, assume there is an input matrix A, a weight matrix B, and an output matrix C. The operation circuit 903 takes the corresponding data of the matrix B from the weight memory 902 and caches it on each PE of the operation circuit 903. The operation circuit 903 takes the matrix A data from the input memory 901 and performs a matrix operation with the matrix B, and the partial result or the final result of the matrix is stored in the accumulator 908.
[0131] The unified memory 906 is used to store input data and output data. The weight data is directly transferred to the weight memory 902 through the storage unit access controller 905 (eg, direct memory access controller, DMAC).
[0132] The input data is also transferred to the unified memory 906 through the storage unit access controller 905 .
[0133] The bus interface unit 910 (BIU) is used for the interaction between the AXI (advanced extensible interface) bus and the storage unit access controller 905 and the instruction fetch buffer 909 (instruction fetch buffer).
[0134] The bus interface unit 910 is used for the instruction fetch memory 909 to obtain instructions from the external memory, and is also used for the storage unit access controller 905 to obtain the original data of the input matrix A or the weight matrix B from the external memory.
[0135] The storage unit access controller 905 is mainly used to transfer input data in the external memory to the unified memory 906 or transfer weight data to the weight memory 902 or transfer input data to the input memory 901 .
[0136] The vector calculation unit 907 generally includes a plurality of operation processing units, and performs further processing on the output of the operation circuit 903 when necessary, such as vector multiplication, vector addition, exponential operation, logarithmic operation, and / or size comparison, etc.
[0137] In some implementations, the vector calculation unit 907 can store the processed vector in the unified memory 906. For example, the vector calculation unit 907 can apply a nonlinear function to the output of the operation circuit 903, such as a vector of accumulated values, to generate an activation value. In some implementations, the vector calculation unit 907 generates a normalized value, a merged value, or both. In some implementations, the processed vector can be used as an activation input of the operation circuit 903.
[0138] The instruction fetch memory 909 connected to the controller 904 is used to store instructions used by the controller 904 .
[0139] The unified memory 906, the input memory 901, the weight memory 902 and the instruction fetch memory 909 are all on-chip memories. The external memory in the figure is independent of the NPU hardware architecture.
[0140] It should be noted that the method for configuring the address translation relationship provided in this embodiment can also be applied to non-terminal computer devices, such as cloud servers.
[0141] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0142] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0143] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0144] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0145] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, server, or other network device, etc.) to execute the present application. Figure 5 All or part of the steps of the method described in the embodiment. The aforementioned storage medium includes: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0146] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for configuring an address translation relationship, It is characterized in that The method is applied to a computer system, on which a rich execution environment REE and a trusted execution environment TEE are deployed, the REE is deployed with a virtual machine VM and a virtual machine manager VMM, and the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM, wherein the method comprises: The VMM passes a first address translation relationship to the SPM, wherein the first address translation relationship includes an address translation relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transfers data from the SP to the VM, it performs an address translation from IPA to PA based on the first address translation relationship, where PA is a memory address.
2. The method according to claim 1, It is characterized in that The IPA assigned to the VM is a continuous address, and the PA obtained after address conversion is performed on the IPA assigned to the VM through the first address conversion relationship is a discrete address.
3. The method according to claim 1 or 2, It is characterized in that The REE is deployed with a first virtualization translation table base address register vttbr_el2 and a first control register vtcr_el2, and the first address translation relationship includes: a base address of a page table configured in the first vttbr_el2 for performing a second-level memory address translation (stage 2 translation) on the REE side, an address translation attribute configured in the first vtcr_el2 for performing a second-level memory address translation on the REE side, and an IPA assigned to the VM, wherein the IPA assigned to the VM can be converted into a PA based on a memory translation rule expressed by the base address and the address translation attribute.
4. The method according to claim 3, It is characterized in that The method further comprises: The SPM transfers the IPA assigned to the VM to the SP, and the SP is used to establish a second address mapping relationship based on the IPA assigned to the VM, wherein the second address conversion relationship includes an address conversion relationship from a virtual address VA to IPA, so that when the SP transfers data to the VM, the SP performs address conversion from VA to IPA based on the second address mapping relationship.
5. The method according to claim 3 or 4, It is characterized in that The TEE is deployed with a second vttbr_el2 and a second vtcr_el2; the method further includes: The SPM writes the base address to the second vttbr_el2 and the address translation attribute to the second vtcr_el2, so that when the SPM transfers data from the SP to the VM, it performs address translation from IPA to PA based on the base address stored in the second vttbr_el2 and the address translation attribute stored in the second vtcr_el2.
6. The method according to claim 5, It is characterized in that Before the SPM writes the base address into the second vttbr_el2 and writes the address translation attribute into the second vtcr_el2, the method further comprises: The SPM receives a startup request sent by the VMM, where the startup request is used to instruct the SPM to start the SP, and when starting the SP, writes the base address into the second vttbr_el2 and writes the address translation attribute into the second vtcr_el2.
7. The method according to any one of claims 3 to 6, It is characterized in that The VMM transmits the first address translation relationship to the SPM, including: The VMM writes the first address translation relationship into a general register, and triggers the SPM to obtain the first address translation relationship from the general register based on an SMC instruction.
8. A computer system, wherein a rich execution environment REE and a trusted execution environment TEE are deployed on the computer system, the REE is deployed with a virtual machine VM and a virtual machine manager VMM, the TEE is deployed with a secure isolation zone SP and a secure isolation zone manager SPM, in, The VMM is used to pass a first address translation relationship to the SPM, where the first address translation relationship includes an address translation relationship from an intermediate physical address IPA assigned to the VM to a physical address PA, so that when the SPM transfers data from the SP to the VM, it performs an address translation from IPA to PA based on the first address translation relationship, where PA is a memory address.
9. The computer system according to claim 8, It is characterized in that The IPA assigned to the VM is a continuous address, and the PA obtained after address conversion is performed on the IPA assigned to the VM through the first address conversion relationship is a discrete address.
10. The computer system according to claim 8 or 9, It is characterized in that The REE is deployed with a first virtualization translation table base address register vttbr_el2 and a first control register vtcr_el2, and the first address translation relationship includes: a base address of a page table configured in the first vttbr_el2 for performing a second-level memory address translation (stage2translation) on the REE side, an address translation attribute configured in the first vtcr_el2 for performing a second-level memory address translation on the REE side, and an IPA assigned to the VM, wherein the IPA assigned to the VM can be converted into a PA based on a memory translation rule expressed by the base address and the address translation attribute.
11. The computer system according to claim 10, It is characterized in that The SPM is used to transfer the IPA assigned to the VM to the SP, and the SP is used to establish a second address mapping relationship based on the IPA assigned to the VM, wherein the second address conversion relationship includes an address conversion relationship from a virtual address VA to IPA, so that when the SP transfers data to the VM, the SP performs address conversion from VA to IPA based on the second address mapping relationship.
12. The computer system according to claim 10 or 11, It is characterized in that The TEE is deployed with a second vttbr_el2 and a second vtcr_el2; the SPM is used to write the base address to the second vttbr_el2, and write the address conversion attribute to the second vtcr_el2, so that when the SPM transfers data from the SP to the VM, it performs address conversion from IPA to PA based on the base address stored in the second vttbr_el2 and the address conversion attribute stored in the second vtcr_el2.
13. The computer system according to claim 12, It is characterized in that The SPM is used to receive a startup request sent by the VMM, where the startup request is used to instruct the SPM to start the SP, and when starting the SP, write the base address into the second vttbr_el2, and write the address translation attribute into the second vtcr_el2.
14. A computer system according to any one of claims 10 to 13, It is characterized in that The VMM is used to write the first address translation relationship into a general register, and trigger the SPM to obtain the first address translation relationship from the general register based on an SMC instruction.
15. A computer system, It is characterized in that comprising a memory and a processor, wherein: The memory is used to store computer-readable instructions; the processor is used to read the computer-readable instructions and implement the method according to any one of claims 1 to 7.
16. A computer storage medium, It is characterized in that Computer-readable instructions are stored, and when the computer-readable instructions are executed by a processor, the method according to any one of claims 1 to 7 is implemented.
