Memory access method and apparatus, computer device, and storage medium
By obtaining address translation information using the bus instance identification as index in the UB system, the problem of low memory access efficiency caused by excessive entry of downstream tables on large-scale networking is solved, and efficient memory access is achieved.
Patent Information
- Application Number
- PCT/CN2025/072312
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-02-29
- Filing Date
- 2025-01-14
- Publication Date
- 2025-09-04
AI Technical Summary
In the case of large-scale networking, in the prior art, the number of flow table entrances is affected by the number of devices, resulting in a reduced memory access efficiency and cannot support efficient memory access.
By obtaining address translation information with the bus instance's identification as index, the problem of excessive flow table entrances caused by the device as index is avoided. The identification of the bus instance is used to obtain address translation information, which is suitable for large-scale networking environments.
It realizes efficient memory access under large-scale networking, improves memory access efficiency, reduces the number of stream table entrances, and is suitable for computer equipment in UB system.
Smart Images

Figure CN2025072312_04092025_PF_FP_ABST
Abstract
Description
Memory access method, device, computer equipment and storage medium
[0001] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office on February 29, 2024, with application number 202410235135.X and application name “Memory Access Method, Device, Computer Equipment and Storage Medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of memory management technology, and in particular to a memory access method, apparatus, computer equipment, and storage medium. Background Art
[0003] Currently, in computer devices, the input-output memory management unit (IOMMU) or the system memory management unit (SMMU) can be used to translate the virtual addresses in the direct memory access (DMA) requests or remote direct memory access (RDMA) requests of peripheral devices and perform access permission control.
[0004] In the related art, a computer device stores flow table entries corresponding to each authorized peripheral device connected to it, and the flow table entries store address conversion information corresponding to the memory area that the peripheral device can access. Based on this, after receiving a DMA request or an RDMA request, the IOMMU or SMMU can use the device identifier of the peripheral device that sent the request as an index to obtain the flow table entry of the peripheral device, and then implement permission control and address conversion for the peripheral device based on the address conversion information stored in the flow table entry. It can be seen from this that in the related art, the computer device must allocate different flow table entries for different peripheral devices. In this way, the number of flow table entries will be affected by the scale of the network, which is not conducive to efficient memory access in large-scale networks. Summary of the Invention
[0005] The present application provides a memory access method, apparatus, computer equipment, and storage medium, which can improve the efficiency of memory access in large-scale networking.
[0006] To achieve the above objectives, this application adopts the following technical solutions:
[0007] In a first aspect, a memory access method is provided, which is applied to a first device, and the method includes: receiving a memory access request from a second device, the memory access request including a first identifier and a unified bus address UBA of a target memory unit to be accessed, the first identifier being an identifier of a target bus instance, and the target bus instance corresponding to a first memory area; based on the first identifier, obtaining first address conversion information corresponding to the target bus instance; and accessing the target memory unit based on the first address conversion information and the UBA.
[0008] The target bus instance corresponding to the first memory area may mean that the target bus instance is a bus instance for accessing the first memory area, or may also be referred to as the target bus instance being an entry for accessing the first memory area.
[0009] In the present application, the memory access request of the second device includes the UBA and the first identifier of the target memory unit to be accessed, wherein the first identifier is the identifier of the target bus instance in the first device, and the target bus instance corresponds to the first memory area in the first device. Based on this, the first address translation information corresponding to the target bus instance is obtained according to the first identifier, and then the target memory unit is accessed based on the first address translation information and the UBA. It can be seen that in the present application, the second device can obtain the address translation information of the memory area corresponding to the bus instance by the identifier of the bus instance of the destination to be accessed, without having to use the identifier of the second device as an index to obtain the address translation information. On this basis, since the number of bus instances of the destination is related to the number of divisions of the memory area of the destination, but has nothing to do with the number of devices connected to the destination, compared with the method of accessing memory using devices as indexes, there will be no problem of a large number of flow table entries due to a large number of devices. It can be seen that the memory access method provided by the embodiment of the present application will not be affected by the number of devices connected to the destination, that is, it will not be affected by the scale of the network, which is conducive to efficient memory access in large-scale networks.
[0010] Optionally, the first device includes a first controller, which may be a UB controller or a controller of other standard architectures. The first controller includes at least one bus instance, and the at least one bus instance includes the target bus instance.
[0011] Optionally, the first device includes N controllers, which may specifically be UB controllers. The target bus instance includes the N controllers, where N is a positive integer.
[0012] In this application, bus instances are obtained based on the controller in the first device. Therefore, the number of bus instances is related to the controller in the first device, that is, the number of bus instances is not affected by the number of devices connected to the first device. Furthermore, using the bus instance identifier as an index to obtain address translation information facilitates efficient memory access in large-scale networks.
[0013] In addition, in the present application, multiple controllers can be used as a bus instance, so that the memory area corresponding to the bus instance can be accessed through the multiple controllers, realizing multi-plane memory access.
[0014] Optionally, the first memory area is a memory area allocated to a first entity in the first device, and the first entity is a host operating system or a virtual instance running on the first device.
[0015] In the present application, the first memory area corresponding to the target bus instance is the memory area used and managed by the first entity, and the target bus instance corresponds to the first memory area. Therefore, it can be seen that the target bus instance is actually a bus instance allocated to the first entity, that is, the target bus instance is a bus instance used to access the first memory area used and managed by the first entity.
[0016] The first entity can be a host operating system or a virtual instance running on the first device. Therefore, the target bus instance can be allocated to the host operating system for use or to a virtual instance for use. Furthermore, in this application, a bus instance is allocated to one entity for use. In this case, when multiple virtual instances are running on the first device, different virtual instances correspond to different bus instances. On this basis, address translation information is obtained based on the identifier of the bus instance, thereby isolating address translation information between different virtual instances.
[0017] Optionally, the implementation process of accessing the target memory unit based on the first address conversion information and the UBA may include: searching for the physical address corresponding to the UBA from the first address conversion information; if the physical address corresponding to the UBA is found, accessing the target memory unit based on the physical address corresponding to the UBA, wherein the first memory area includes the target memory unit.
[0018] In this application, after finding the corresponding first address translation information based on the identifier of the target bus instance, if the physical address corresponding to the UBA can be found in the first address translation information, it means that the target memory unit is a memory unit in the first memory area corresponding to the target bus instance. In this case, the target memory unit can be accessed based on the physical address. If the physical address corresponding to the UBA cannot be found, it means that the UBA may be incorrect or the target memory unit may not belong to the first memory area. In this case, access to the target memory unit fails.
[0019] Optionally, the memory access request also includes a first token identifier; the implementation process of obtaining the first address conversion information corresponding to the target bus instance based on the first identifier may include: based on the first identifier, obtaining the entry information of the first configuration table corresponding to the target bus instance, the first configuration table including multiple table entries corresponding one-to-one to multiple token identifiers, each table entry being used to store the entry information of the address conversion table corresponding to the corresponding token identifier; determining the first configuration table based on the entry information of the first configuration table; searching for the first table entry corresponding to the first token identifier from the first configuration table; and obtaining the first address conversion information based on the entry information of the address conversion table stored in the first table entry.
[0020] In this application, the first token identifier can be an identifier pre-assigned by the first device to the second device for accessing the target memory unit. On this basis, the identifier of the target bus instance is used as the first-level entry point for searching address translation information, and the first token identifier is used as the second-level entry point for searching address translation information. In this way, while searching for address translation information, permission control of the device is achieved.
[0021] Optionally, the memory access request also includes second access permission information, and each table entry in the first configuration table is also used to store entry information of the access permission table corresponding to the corresponding token identifier. The method also includes: obtaining first access permission information based on the entry information of the access permission table stored in the first table entry; verifying the second access permission information based on the first access permission information; if the verification of the second access permission information is passed, executing the step of accessing the target memory unit based on the first address conversion information and the UBA.
[0022] In the present application, the memory access request may also include second access permission information. On this basis, the first table entry corresponding to the first token identifier also stores the first access permission information assigned by the first device and the second device for accessing the target memory unit. On this basis, by comparing the first access permission information and the second access permission information, the access permission of the second device is further verified to improve the security of memory access.
[0023] Optionally, the method further includes: acquiring the first identifier; storing entry information of the first configuration table based on the first identifier; and sending the first identifier to the second device.
[0024] In the present application, the first device can obtain the identifier of the target bus instance, and configure the entry information corresponding to the address translation information of the first memory area corresponding to the target bus instance based on the identifier of the target bus instance, and then send the identifier of the target bus instance to the second device so that the second device can access the first memory area based on the identifier of the target bus instance.
[0025] Optionally, the method also includes: receiving a memory request from the second device, the memory request including the first identifier and the UBA of the target memory unit; obtaining the first token identifier based on the UBA of the target memory unit; determining a first address translation table based on the UBA of the target memory unit, the first address translation table including address conversion information for converting the UBA of the target memory unit into a corresponding physical address; based on the first identifier, assigning a corresponding first table entry to the first token identifier in the first configuration table, and writing entry information of the first address translation table in the first table entry; sending the first token identifier to the second device.
[0026] In the present application, after receiving a memory application from a second device, the first device assigns a first token identifier to the second device based on the identifier of the target bus instance in the memory application, and determines the first address translation table based on the UBA of the target memory unit applied for by the second device. Thereafter, in the first configuration table corresponding to the first identifier, an entry for storing entry information of the first address translation table is assigned to the first token identifier, thereby realizing the configuration of the address translation information of the UBA of the target memory unit.
[0027] Optionally, the method further includes: allocating first access permission information to the second device; determining a first access permission table, the first access permission table including the first access permission information; writing entry information of the first access permission table into the first table entry; and sending the first access permission information to the second device.
[0028] In the present application, the first device can also write the entry information of the first access permission information allocated to the second device in the table entry corresponding to the first token identifier, so that when the second device subsequently accesses the memory of the first device, it can search for the access permission information based on the first token identifier to perform access permission control on the second device.
[0029] In a second aspect, a memory access device is provided, the memory access device comprising at least one module, and the at least one module is configured to execute the memory access method described in the first aspect.
[0030] In a third aspect, a computer device is provided, comprising a processor, a memory management unit, a controller, and a memory, wherein the memory management unit and the controller are configured to execute at least one program instruction or code stored in the memory to implement the memory access method described in the first aspect. The memory management unit may be a unified bus memory management unit (UMMU) or a memory management unit of another standard, and the controller may be a UB controller or a controller of another standard architecture.
[0031] In a fourth aspect, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer device, the computer device executes the memory access method described in the first aspect.
[0032] In a fifth aspect, a computer program product comprising instructions is provided. When the computer program product is run on a computer device, the computer device executes the memory access method described in the first aspect.
[0033] The technical effects obtained in the above-mentioned second to fifth aspects are similar to the technical effects obtained by the corresponding technical means in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] FIG1 is a diagram illustrating an implementation architecture of a memory access method according to an embodiment of the present application;
[0035] FIG2 is an implementation architecture diagram of another memory access method provided in an embodiment of the present application;
[0036] FIG3 is an implementation architecture diagram of another memory access method provided in an embodiment of the present application;
[0037] FIG4 is a flowchart of configuring entry information and address conversion information corresponding to an identifier of a bus instance provided by an embodiment of the present application;
[0038] FIG5 is a schematic diagram of a target bus instance and a corresponding first entity provided in an embodiment of the present application;
[0039] FIG6 is a schematic diagram of another target bus instance and a corresponding first entity provided in an embodiment of the present application;
[0040] FIG7 is a flowchart of a memory access method provided in an embodiment of the present application;
[0041] FIG8 is a schematic diagram of obtaining address translation information and access permission information based on a bus instance identifier and a token identifier according to an embodiment of the present application;
[0042] FIG9 is a diagram illustrating an effect of multiple UB devices accessing the memory of a first device through a memory access method provided by an embodiment of the present application;
[0043] FIG10 is a schematic structural diagram of a memory access device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0044] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0045] Before explaining the embodiments of the present application in detail, the application scenarios involved in the embodiments of the present application are first introduced.
[0046] Currently, in bus systems such as compute express link (CXL) and peripheral component interconnect express (PCIe), the device connection architecture adopts a master-slave architecture. In this case, the host can scan the devices connected to it and assign corresponding identifiers to the devices after the scan is passed. Afterwards, the host can create corresponding flow table entries based on the identifiers of different devices. In this way, after the subsequent host's IOMMU or SMMU receives a request from a device to access the host's memory, it can use the identifier of the device carried in the request as an index to access the corresponding flow table entry to obtain the corresponding address conversion information, thereby enabling the device to access the host's memory.
[0047] However, in the UB system, the relationship between the various devices interconnected through the UB is equal. For example, the CPU of the host is connected to the UB device through the UB. At this time, the relationship between the CPU of the host and the UB device is equal, and there is no subordinate relationship. Under this peer-to-peer architecture provided by the UB system, the scale of devices interconnected through the UB will expand. On this basis, if different identifiers are still assigned to different devices and flow table entries are created based on the identifiers of the devices, it will result in a large number of flow table entries, thereby reducing memory access efficiency. It can be seen that in the UB system, the method of assigning different flow table entries to different devices cannot support efficient memory access under large-scale networking. Based on this, an embodiment of the present application provides a memory access method, in which the identifier of the bus instance of the destination end to be accessed by the device is used as the entry to obtain address conversion information, and the number of bus instances at the destination end will not be affected by the scale of the network. Therefore, it is conducive to efficient memory access in the case of large-scale networking.
[0048] Next, the implementation architecture involved in the memory access method provided in the embodiment of the present application is introduced.
[0049] The memory access method provided in the embodiment of the present application can be applied to a computer device integrated with a UB device. For example, referring to Figure 1, the computer device 10 may include a first device and a second device, wherein the first device includes a processor 101, a memory 102, a UMMU 103, an internal system bus 104 and a UB controller 105, and the second device includes a UB switch device 106, a UB device 107 and a UB 108. In this case, the computer device 10 can be called a supercomputer device. The processor 101, the memory 102 and the UMMU 103 can be connected via the internal system bus 104. In addition, the UMMU 103 and the UB controller 105, the UB controller 105 and the UB switch device 106, and the UB switch device 106 and the UB device 107 can be connected via the UB 108. It should be noted that the device structure shown in Figure 1 does not constitute a limitation on the computer device. The computer device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. The embodiment of the present application does not limit this. The following is a detailed introduction to the various components of the computer device in conjunction with Figure 1:
[0050] The processor 101 is the control center of the computer device and can be a single processor or a collective term for multiple processing elements. For example, the processor 101 can be a general-purpose central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of the program of the present application, such as one or more microprocessors (digital signal processors, DSPs), or one or more field programmable gate arrays (FPGAs). The processor 101 can perform various functions of the computer device by running or executing software programs stored in the memory 102 and calling data stored in the memory 102.
[0051] As an embodiment, the processor 101 may include one or more CPUs.
[0052] As an example, a computer device may include multiple processors. Each of these processors may be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor. The processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).
[0053] The memory 102 is an internal memory that directly exchanges data with the processor 101. The memory 102 can be a read-only memory (ROM) or other type of static storage device that can store static information and instructions, a random access memory (RAM) or other type of dynamic storage device that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, an optical disc storage (including a compact disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited to these. Among them, the memory 102 is used to store the software program that executes the solution provided in the embodiment of the present application, and is controlled and executed by the UMMU 104 and the processor 101.
[0054] UMMU 103 is used to translate the address of the data to be accessed carried in the memory access request from UB device 107 based on the memory access method provided in the embodiments of this application. Furthermore, UMMU 103 can also be used to restrict the memory access request from UB device 107 to the physical address space of the virtual instance corresponding to the UB device, thereby achieving address isolation of the virtual instance. A virtual instance can be a virtual machine, container, or the like running on a computer device.
[0055] The internal system bus 104 is used to transfer information between internal components of the computer device, such as the processor 101, the memory 102, and the UMMU 103. The internal system bus 104 can be a network on chip (NoC) bus, an advanced microcontroller bus architecture (AMBA) bus, etc.
[0056] The UB controller 105 is the operation entry of the UB 108 and is used to provide interfaces such as data loading and storing, message sending and receiving, hot plugging events in the hardware system, power consumption management, etc. The computer device 10 may include one or more UB controllers 105 .
[0057] It should be noted that, in an embodiment of the present application, the computer device 10 can create a bus instance based on the UB controller 105 and generate an identifier for the bus instance. The identifier of the bus instance can be used to uniquely identify the bus instance and is the identity identifier of the bus instance. For example, the identifier of the bus instance can be a UB entity identifier (EID), and the so-called UB EID refers to the identity identifier of the entity participating in the communication in the UB system. A bus instance can be assigned to an entity in the computer device 10 for use, for example, it can be assigned to the host operating system of the computer device 10 for use, or assigned to a virtual instance running on the computer device 10 for use. Accordingly, a bus instance will uniquely correspond to the memory area managed and used by the corresponding entity. In addition, in an embodiment of the present application, the identifier of the bus instance is used as an index for UMMU103 to search for address conversion information, thereby realizing address conversion during memory access.
[0058] As an example, the computer device 10 includes N UB controllers, and the N UB controllers can be used as a bus instance, and an identifier for identifying the bus instance can be generated based on the globally unique identifier (GUID) of the N UB controllers. Wherein, N is a positive integer. For example, the value of the type field of the GUID of a UB controller among the N UB controllers can be modified and used as the identifier of the bus instance. Alternatively, a new GUID can be generated as the identifier of the bus instance using an algorithm for generating a GUID. It should be noted that when multiple UB controllers are used as a bus instance, the entity using the bus instance will be able to simultaneously utilize the physical bandwidth of the multiple UB controllers.
[0059] As another example, for any USB controller, the computer device 10 can virtualize the USB controller using a virtualization software stack to generate at least one virtual controller. Each virtual controller can be assigned to a virtual instance running on the computer device 10 as a bus instance. In this case, the bus instance identifier can be generated using current methods for generating globally unique identifiers.
[0060] The UB switch 106 has routing functionality, primarily used to expand the number of UB ports and provide an interface for enumerating UB devices and establishing routing relationships among them. It should be noted that in some possible implementations, the computer device 10 may not include the UB switch 106. In this case, the UB device 107 may be directly connected to the UB controller 105. That is, in the example of Figure 1 , the UB switch 106 is an optional device.
[0061] The UB device 107 can provide extended functional services for the computer device 10. For example, the UB device 107 can provide extended storage resources, network resources, etc. for the computer device 10. For example, the UB device 107 can be a network card, a disk, a data processing unit (DPU), a graphics processing unit (GPU), etc.
[0062] The UB 108 is used to transmit information between the UMMU 103 , the UB controller 105 , the UB switch device 106 and the UB device 107 .
[0063] In another possible implementation, referring to FIG2 , the memory access method provided in the embodiment of the present application can also be applied to a system including a computer device 20 and a UB device 21 located outside the computer device. That is, the UB device 21 can also be independent of the computer device 20 and located outside or remote from the computer device 20. For example, referring to FIG2 , the computer device 20 can be connected to the UB device 21 through a UB switching device 22 and a UB 23 located outside the computer device 20. In this case, the UB device 21 is equivalent to a host in status. When the UB device 21 accesses the memory of the computer device 20, the UMMU of the computer device 20 can convert the address to be accessed by the UB device 21 through the memory access method provided in the embodiment of the present application. Among them, the various components in the internal structure of the computer device 20 can refer to the introduction of the corresponding components in the computer device 10.
[0064] In another possible implementation, the memory access method provided by the embodiment of the present application can also be applied to a cluster including multiple computer devices. For example, referring to Figure 3, the cluster may include computer device 30 and computer device 31, wherein the structures of computer device 30 and computer device 31 can refer to the computer device 10 shown in Figure 1. In this case, when a UB device integrated in computer device 31, such as UB device 311, wants to access the memory of computer device 30, the UMMU of computer device 30 can convert the UBA of the memory area to be accessed by UB device 311 through the memory access method provided by the embodiment of the present application. Alternatively, when a UB device integrated in computer device 30, such as UB device 301, wants to access the memory of computer device 31, the UMMU of computer device 31 can also convert the UBA of the memory area to be accessed by UB device 301 through the memory access method provided by the embodiment of the present application.
[0065] It should be noted that the above-mentioned computer device can be a general-purpose computer device or a special-purpose computer device. For example, it can be a desktop computer, a portable computer, a network server, etc., and this embodiment of the application does not limit this.
[0066] The above primarily describes three exemplary system architecture diagrams for the memory access method when applied to a USB system. In some possible implementations, the memory access method provided in the embodiments of this application can also be applied to computer systems using other bus protocols, such as PCIe systems and CXL systems. The following describes the specific implementation process using the memory access method applied to a USB system as an example. The implementation process for other system architectures is similar to the following examples.
[0067] In an embodiment of the present application, the UMMU in the computer device can use the identifier of the bus instance in the computer device as an index to obtain address translation information to achieve address translation, and a bus instance can be assigned to an entity in the computer device for use. On this basis, the address translation information that can be obtained using the identifier of a bus instance as an entry is the address translation information of the memory area managed by the entity using the bus instance. Based on this, before explaining the memory access method provided in the embodiment of the present application in detail, the process of configuring the entry information and address translation information corresponding to the identifier of the bus instance by the first device is first introduced, wherein the first device can be the first device included in the supercomputer device 10 shown in Figure 1, and accordingly, the second device in the following embodiment can be the second device in the supercomputer device 10 shown in Figure 1, or the first device can also be the computer device 20 shown in Figure 2, and accordingly, the second device is the UB device 21 shown in Figure 2, or the first device can also be the computer device 30 shown in Figure 3, and accordingly, the second device is any UB device in the computer device 31 shown in Figure 3, or the first device is the computer device 31 shown in Figure 3, and accordingly, the second device can be any UB device in the computer device 30 shown in Figure 3. Exemplarily, referring to FIG4 , the process may include the following steps:
[0068] Step 401: Obtain a first identifier.
[0069] In the embodiment of the present application, the first device may include at least one UB controller. Based on the at least one UB controller, the first device may obtain at least one bus instance and generate an identifier of each bus instance.
[0070] As an example, the first device includes a first USB controller. The first device can virtualize the first USB controller to obtain at least one virtual controller, and use each virtual controller as a bus instance. In this case, the first USB controller will include at least one bus instance. In this case, for the at least one bus instance included in the first USB controller, the first device can generate an identifier for identifying each bus instance based on the GUID of the first USB controller. For example, the value of the type field of the GUID of the first USB controller can be modified to obtain the identifier of the bus instance. Alternatively, the first device can directly generate a new GUID as the identifier of the bus instance.
[0071] As another example, a first device includes N USB controllers, where N is a positive integer. The first device can use these N USB controllers as a bus instance. In this case, the bus instance includes N USB controllers. In this case, the first device can generate an identifier for the bus instance based on the GUID of any of the N USB controllers, or directly generate a new GUID to serve as the identifier for the bus instance.
[0072] After the first device creates the first entity, the UMMU may select a target bus instance from bus instances that are not currently allocated to other entities and obtain an identifier of the target bus instance, i.e., a first identifier. In this case, the target bus instance is the bus instance allocated to the first entity.
[0073] As an example, when the first entity is a host operating system of a first device, the UMMU may allocate a bus instance including one or more USB controllers as a target bus instance to the host operating system for use. For example, referring to FIG5 , the first device includes two USB controllers, and these two USB controllers may be allocated as a bus instance to the host operating system of the first device for use.
[0074] As another example, when the first entity is a virtual instance running on the first device, the UMMU can select a virtual controller as the target bus instance. For example, referring to Figure 6 , the first device includes a USB controller, which the first device virtualizes to obtain two virtual controllers, vcontroller1 and vcontroller2. In this case, after creating virtual machines 1 and 2, vcontroller1 can be assigned to virtual machine 1 as bus instance 1, and vcontroller2 can be assigned to virtual machine 2 as bus instance 2.
[0075] Step 402: Based on the first identifier, store entry information of the first configuration table.
[0076] After obtaining the first identifier, the UMMU can assign a corresponding second table entry to the first identifier in the second configuration table. The second configuration table includes table entries corresponding to the identifiers of each bus instance in the first device. The second table entry corresponding to the first identifier is used to store the entry information of the first configuration table corresponding to the target bus instance. The first configuration table is used to store the entry information of the address conversion information of the first memory area corresponding to the target bus instance, and the first memory area is the memory area managed and used by the first entity using the target bus instance. In addition, the first configuration table can also be used to store the entry information of the access permission information of the first memory area. It should be noted that in an embodiment of the present application, the entry information of a certain information can be used to indicate the storage location of the information, for example, it can include the physical address of the storage area where the information is stored. The physical address refers to an address in the address space actually possessed by a hardware storage device such as an internal memory.
[0077] In one possible implementation, the addresses of the various table entries contained in the second configuration table are continuous. In this case, the UMMU can read the base address of the second configuration table from the designated register. Afterwards, the UMMU can determine the physical address corresponding to the first identifier based on the base address of the second configuration table, the size of the table entry corresponding to the identifier of each bus instance, and the first identifier. Afterwards, the table entry at the physical address corresponding to the first identifier is used as the second table entry, wherein the physical address corresponding to the first identifier is the base address of the second table entry. The base address can also be referred to as the starting physical address.
[0078] It should be noted that in the second configuration table, the entries corresponding to the identifiers of the various bus instances can be arranged in ascending order of the identifiers of the various bus instances, and the sizes of the entries can be equal. Based on this, the UMMU can calculate an address offset based on the order of the first identifier among the identifiers of the multiple bus instances and the size of the entry in the second configuration table, and then determine the physical address corresponding to the first identifier based on the base address of the second configuration table and the address offset.
[0079] For example, there are 10 bus instances in the first device. Assuming that the identifiers of each bus instance are arranged in ascending order, the first identifier is the 5th identifier among the 10 identifiers. Then, the size of the entry in the second configuration table can be multiplied by 4 to obtain the address offset, and then the base address of the second configuration table and the address offset can be added to obtain the physical address corresponding to the first identifier.
[0080] In another possible implementation, the addresses of the entries included in the second configuration table may be discontinuous. Based on this, the UMMU may use any unassigned entry in the second configuration table as the second entry corresponding to the first identifier and store the physical address of the second entry in a designated register. In this case, if the designated register also stores the physical addresses of entries corresponding to the identifiers of other bus instances, the physical addresses of the entries corresponding to the corresponding identifiers may be stored in ascending or descending order according to the identifiers of the bus instances.
[0081] After allocating the corresponding second table entry to the first identifier, the UMMU may further initialize the second table entry.
[0082] As can be seen from the preceding description, the second table entry is used to store the entry information of the first configuration table corresponding to the target bus instance. Based on this, as an example, the UMMU can request a second memory area for storing the first configuration table corresponding to the target bus instance and, based on this second memory area, determine the entry information of the first configuration table. The UMMU can then write the entry information of the first configuration table into the second table entry to initialize the second table entry.
[0083] For example, the UMMU may obtain the starting physical address of the second memory area, and write the starting physical address of the second memory area into the second entry in the second configuration table as entry information of the first configuration table.
[0084] Optionally, after the UMMU writes the entry information of the first configuration table in the second table entry, it can also set an identifier for the entry information of the first configuration table in the second table entry to indicate whether the entry information of the first configuration table has taken effect. Since the UMMU has just allocated the second table entry for the first identifier and the first configuration table has not yet been created, the first identifier can be set for the entry information of the current first configuration table to indicate that the entry information of the first configuration table has not yet taken effect. In this way, if a memory access request containing the first identifier is currently received from a certain UB device, it can be determined based on the first identifier that the entry information of the first configuration table has not yet taken effect. In this case, the UMMU can end the operation, thereby avoiding continuing to obtain address conversion information based on the entry information of the first configuration table and causing access errors.
[0085] As another example, the second table entry can be used not only to store the entry information of the first configuration table, but also to store the address translation information of the first memory area or other attribute information of the access permission information. For example, the second table entry can also be used to store the address translation mode of the first entity using the target bus instance, and the address translation mode can be used to indicate the address translation stage required by the UB device when accessing the first memory area managed by the first entity. For example, when the first entity is a virtual machine, the address translation mode may include two address translation stages, namely stage 1 and stage 2. Among them, in stage 1, the guest virtual address (GVA) is converted to the guest physical address (GPA), and in stage 2, the GPA is converted to the host physical address (HPA). When the first entity is a host operating system, the address translation mode may include stage 2, and in stage 2, the input output virtual address (IOVA) is converted to the physical address (PA). Based on this, the UMMU may also determine the address translation mode of the first entity using the target bus instance, and then write indication information indicating the address translation mode into the second table entry to initialize the second table entry.
[0086] The above are two possible examples of initializing the second table entry given in the embodiments of the present application. When the second table entry also stores other information, the UMMU can also initialize other information that may be stored in the second table entry. The embodiments of the present application will not go into details about this.
[0087] Step 403: Send the first identifier to the second device.
[0088] After obtaining the first identifier, the first device can send the first identifier to at least one USB device, including the second device. The at least one USB device can be the USB device corresponding to the first entity using the target bus instance. In other words, for the target bus instance identified by the first identifier, at least one USB device can access the first memory area corresponding to the target bus instance through the target bus instance.
[0089] For example, when the first entity is a virtual instance such as a virtual machine or a container, the at least one UB device may be a UB device corresponding to the virtual instance.
[0090] After allocating the second table entry to the first identifier in the above manner and sending the first identifier to the second device, if the second device wants to access the target memory unit in the first memory area managed by the first entity, the second device can send a memory request to the first device. Accordingly, the first device can execute the following steps 404 to 407 to implement the configuration of the first configuration table and the first address translation table containing the address translation information of the target memory unit.
[0091] Step 404: Receive a memory request from the second device, where the memory request includes a first identifier and a UBA of a target memory unit.
[0092] In an embodiment of the present application, after the second device receives the first identifier sent by the first device, if the second device wants to use the target memory unit in the first memory area managed by the first entity, the second device can send a memory request to the first device to apply for the target memory unit, and accordingly, the first device receives the memory request.
[0093] Among them, the memory request includes a first identifier and the UBA of the target memory unit. It should be noted that UBA refers to the index of data used by the data user when performing memory access operations on the data owner. Among them, UBA is a virtual address, and the so-called virtual address refers to the address provided to the application or virtual instance after remapping the physical address. Specifically, UBA can be GVA or GPA or IOVA. Among them, GPA can refer to the address provided to the operating system of the virtual machine after the host maps the physical address, GVA can refer to the address provided to the application on the virtual machine after the operating system of the virtual machine remaps the GPA, and IOVA can refer to the address provided to the IO device after the host maps the physical address.
[0094] In addition, it is worth noting that, as described above, in the embodiments of this application, a bus instance can be assigned to a single entity. In this case, the bus instance uniquely corresponds to the memory area managed and used by the entity. However, memory cells in different memory areas corresponding to different bus instances may correspond to the same UBA.
[0095] Step 405: Obtain a first token identifier based on the UBA of the target memory unit.
[0096] After receiving a memory request from a second device, the first device can determine a first token identifier corresponding to a target memory unit for the second device in kernel mode. The first token identifier, along with the first identifier and the UBA of the target memory unit carried in the memory request, can be sent to the UMMU for configuration by the UMMU of information such as a first configuration table and an address translation table. In response, the UMMU receives the first identifier and the first token identifier.
[0097] It should be noted that in some possible scenarios, different USB devices may request the same memory unit. In this case, in one possible implementation, the token identifiers for a memory unit determined for different USB devices can be different. In this way, a single memory unit may correspond to multiple token identifiers. Based on this, in response to a memory request sent by a second device, the first device can directly generate a first token identifier for the second device in kernel mode for accessing the target memory unit.
[0098] As an example, the first device can generate a first token identifier based on the token identifier most recently generated for the UB device. For example, the first token identifier can be obtained by adding a specified value to the token identifier most recently generated for the UB device for accessing a memory unit managed by the first entity. For example, if the specified value is 1 and the token identifier most recently assigned to the UB device is 001, the first token identifier can be 002. In this way, the value of any token identifier can indicate its ranking position among the multiple token identifiers corresponding to the first memory area managed by the first entity.
[0099] In another possible implementation, for a memory unit, the token identifier of the memory unit determined for different UB devices can be the same, so that one memory unit corresponds to one token identifier. In this case, when the first device receives the memory application sent by the second device, it can first detect whether the first token identifier corresponding to the target memory unit already exists. If no other UB device has applied for the target memory unit, the first token identifier corresponding to the target memory unit will not exist in the first device, so the first device can generate the first token identifier in the kernel state. If other UB devices have already applied for the target memory unit, the first token identifier corresponding to the target memory unit will exist in the first device, and the first device can obtain the first token identifier.
[0100] As an example, in the case where one memory unit corresponds to one token identifier, the first device can generate a first token identifier based on the position of the target memory unit in the multiple memory units included in the first memory area managed by the first entity. That is, the first token identifier can be used to indicate the position of the target memory unit in the multiple memory units. For example, if the target memory unit is the first memory unit among the multiple memory units managed by the first entity, the generated first token identifier can be 001. If the target memory unit is the second memory unit among the multiple memory units managed by the first entity, the generated first token identifier can be 002. Alternatively, the first device can also refer to the method described above and generate the first token identifier based on the most recently generated token identifier. In this case, the numerical value of any token identifier can indicate the sorting position of the token identifier among the multiple token identifiers corresponding to the first memory area managed by the first entity.
[0101] Optionally, the first device may further allocate first access permission information for accessing the target memory unit to the second device in the user state, and send the first access permission information to the UMMU.
[0102] It should be noted that if different UB devices are assigned different token identifiers for accessing the same memory unit, the access rights information for the same memory unit assigned to the different UB devices may be partially identical, partially different, or completely different. If different UB devices are assigned the same token identifier for accessing the same memory unit, the access rights information for the memory unit assigned to the different UB devices is the same.
[0103] Exemplarily, the first access permission information may include a first token value used by the second device to access the target memory unit. Optionally, the first access permission information may also include operation permission information of the second device for the target memory unit. For example, the operation permission information may be read permission, write permission, or read-write permission.
[0104] Step 406: Based on the UBA of the target memory unit, determine a first address translation table, where the first address translation table includes address translation information for converting the UBA of the target memory unit into a corresponding physical address.
[0105] After receiving the first token identifier, the first identifier and the UBA of the target memory unit, the UMMU can first detect whether a first address translation table containing address translation information corresponding to the UBA of the target memory unit already exists. If the first address translation table does not exist, the UMMU can create a first address translation table and execute the following step 407. Optionally, if the first address translation table already exists, the UMMU can directly execute the following step 407. Alternatively, the UMMU may not detect whether a first address translation table containing address translation information corresponding to the UBA of the target memory unit already exists, but directly create the first address translation table. The address translation information corresponding to the UBA of the target memory unit may include information for converting the UBA of the target memory unit into a corresponding physical address.
[0106] It should be noted that, when creating the first address translation table, the UMMU may first create an empty first address translation table. Thereafter, the UMMU obtains the address translation information corresponding to the UBA of the target memory unit and writes the address translation information corresponding to the UBA of the target memory unit into the first address translation table.
[0107] It is worth noting that, as described in the aforementioned step 402, the address translation mode of the first entity may include two address translation stages or one address translation stage. Based on this, when the address translation mode of the first entity includes one address translation stage, the first address translation table will store address translation information of one address translation stage of the target memory unit. When the address translation mode of the first entity includes two address translation stages, the first address translation table may include a first sub-table and a second sub-table, wherein the first sub-table is used to store the address translation information of stage 1 of the target memory unit, and the second sub-table is used to store the address translation information of stage 2.
[0108] Optionally, after creating an empty first address translation table, the UMMU may temporarily not write the address translation information into the first address translation table, but may first execute step 407, and then write the address translation information into the first address translation table after executing step 407. This embodiment of the present application is not limited to this.
[0109] Optionally, when the UMMU also receives the first access permission information for accessing the target memory unit from the second device, if different UB devices are assigned different token identifiers for accessing the same memory unit, the UMMU may further create a first access permission table, obtain a base address of the first access permission table, and use the base address of the first access permission table as entry information for the access permission information corresponding to the first token identifier. The first access permission table is used to store the first access permission information.
[0110] The UMMU may first create an empty first access permission table, and then the UMMU may write the UBA of the target memory unit and the corresponding first access permission information into the first access permission table.
[0111] If the token identifiers assigned to different UB devices for accessing the same memory unit are the same, the UMMU can first search whether there is a first access permission table that contains the UBA of the target memory unit and the corresponding access permission information. If the first access permission table does not exist, the UMMU can create the first access permission table with reference to the method described above. If the first access permission table already exists, the base address of the first access permission table is obtained, and the base address of the first access permission table is used as the entry information of the access permission information corresponding to the first token identifier.
[0112] Step 407: Based on the first identifier, a corresponding first table entry is allocated to the first token identifier in the first configuration table, and entry information of the first address translation table is written into the first table entry.
[0113] After determining the first address translation table, the UMMU can search for the entry information of the first configuration table based on the first identifier. If the entry information of the first configuration table is found, the UMMU searches for the first configuration table based on the entry information of the first configuration table. If the first configuration table is found, the first corresponding table entry can be assigned to the first token identifier in the first configuration table, and the entry information of the address translation information corresponding to the target memory unit identified by the first token identifier can be written into the first table entry. Among them, the first configuration table includes table entries assigned to different token identifiers, and the table entries corresponding to different token identifiers store the entry information of the address translation information corresponding to the memory unit identified by the corresponding token identifier. It should be noted that, since the token identifier actually identifies a memory unit, the address translation information corresponding to the token identifier is actually the address translation information corresponding to the memory unit identified by the token identifier.
[0114] In the first case, if the first address translation table is the address translation table created for the first time after the second table entry is assigned to the first identifier, then since the second table entry corresponding to the first identifier may have the entry information of the first configuration table written into it during initialization, or may not have the entry information of the first configuration table written into it, the UMMU may or may not be able to find the entry information of the first configuration table based on the first identifier. Based on this, if the UMMU finds the entry information of the first configuration table according to the first identifier, since the entry information of the first configuration table can indicate the location of the second memory area where the first configuration table is stored, the UMMU can create a first configuration table including an empty table entry in the second memory area indicated by the entry information of the first configuration table, and then assign the corresponding first table entry to the first token identifier in the first configuration table, and write the entry information of the address translation information corresponding to the target memory unit in the first table entry. Among them, the UMMU can assign the corresponding first table entry to the first token identifier in the following three ways.
[0115] Method 1: The UMMU can select an empty table entry from the first configuration table as the first table entry, and obtain the entry information of the address conversion information corresponding to the target memory unit identified by the first token identifier based on the first address table, and then write the first token identifier and the entry information of the corresponding address conversion information into the first table entry. For example, the UMMU can obtain the entry information of the first address conversion table, and write the entry information of the first address conversion table as the entry information of the address conversion information corresponding to the target memory unit into the first table entry. The entry information of the first address conversion table may be the base address of the first address conversion table. Optionally, in the case where the first address conversion table includes a first sub-table and a second sub-table, the entry information of the first address conversion table may include the base address of the first sub-table and the base address of the second sub-table.
[0116] Optionally, when the UMMU also generates a first access permission table including the first access permission information, the UMMU may further write entry information of the first access permission information into the first table entry. For example, the entry information of the first access permission information may be entry information of the first access permission table, wherein the entry information of the first access permission table may be the base address of the first access permission table.
[0117] Method 2: If the first device assigns the same token identifier to different UB devices for accessing the same memory unit, the UMMU can create a corresponding empty table entry in the second memory area for each memory unit managed by the first entity, thereby obtaining a first configuration table. In this case, the number of empty table entries included in the first configuration table is equal to the number of memory units included in the first memory area managed by the first entity. The UMMU can then determine the empty table entry corresponding to the target memory unit from the first configuration table, use this empty table entry as the first table entry corresponding to the first token identifier, and write the entry information of the address translation information corresponding to the target memory unit and the entry information of the first access permission information into the first table entry.
[0118] In the first example, if the token identifier is generated based on the position of the memory unit in the aforementioned step 405, that is, the token identifier can indicate the position of the corresponding memory unit among the multiple memory units managed by the first entity, then the UMMU can determine the empty table entry corresponding to the target memory unit from the first configuration table based on the position of the target memory unit among the multiple memory units.
[0119] For example, if the first token identifier is 002, it means that the target memory unit is the second memory unit among the multiple memory units managed by the first entity, and the UMMU can use the second empty entry in the first configuration table as the first entry corresponding to the first token identifier.
[0120] In the second example, if the numerical value of the token identifier can indicate the sorting position of the token identifier among the multiple token identifiers corresponding to the first memory area managed by the first entity, the UMMU can determine the table entry at the sorting position indicated by the first token identifier from the first configuration table based on the numerical value of the first token identifier, and the table entry is the table entry corresponding to the first token identifier. For example, if the first token identifier is the first token identifier generated for the memory unit managed by the first entity, the first empty table entry in the first configuration table can be used as the first table entry corresponding to the first token identifier.
[0121] Method three: If the first device allocates different token identifiers to different UB devices for accessing the same memory unit, the numerical value of the token identifier can indicate the sorting position of the token identifier among the multiple token identifiers corresponding to the first memory area managed by the first entity. Based on this, the UMMU can refer to the relevant implementation method in method two to allocate the corresponding first table entry for the first token identifier.
[0122] Optionally, if the UMMU fails to locate the entry information for the first configuration table based on the first identifier, the UMMU may first apply for a second memory area for the first configuration table, then create the first configuration table in the second memory area according to the implementation method described above, and allocate a first table entry for the first token identifier in the first configuration table. The UMMU may then determine the entry information for the first configuration table based on the second memory area, locate the corresponding second table entry based on the first identifier, and write the entry information for the first configuration table into the second table entry.
[0123] In the second case, if the first address translation table is not the first address translation table created after the second table entry is assigned to the first identifier, the second memory area allocated for the first configuration table will store the already created first configuration table. In this case, the UMMU will be able to find the first configuration table based on the entry information of the first configuration table. After finding the first configuration table, the first table entry can be assigned to the first token identifier in the following two cases.
[0124] Case 1: If the first device allocates the same token identifier to different UB devices for accessing the same memory unit, the UMMU may search the first configuration table to see if a first entry corresponding to the first token identifier already exists. If so, the operation ends. If not, a first entry corresponding to the first token identifier may be allocated, and entry information for the address translation information corresponding to the target memory unit and entry information for the first access permission information may be written into the first entry.
[0125] If the UMMU uses the above-mentioned method 1 to assign a corresponding table entry to the token identifier, the UMMU can search the first configuration table for an entry containing the first token identifier. If the entry is found, the found entry is the first entry. If the entry is not found, it means that the first table entry corresponding to the first token identifier does not exist in the first configuration table. In this case, the UMMU can refer to the above-mentioned method 1 to assign the first table entry to the first token identifier.
[0126] If the UMMU uses the above-mentioned method 2 to assign a corresponding table entry to the token identifier, the UMMU can refer to the method of assigning the first table entry to the first token identifier in the above-mentioned method 2, search the first table entry corresponding to the first token identifier in the first configuration table, and detect whether the first table entry is an empty table entry. If it is an empty table entry, the UMMU writes the address translation information corresponding to the first token identifier and the entry information of the first access permission information into the empty table entry. If it is not an empty table entry, the UMMU can end the operation.
[0127] Case 2: If the first device allocates different token identifiers for different UB devices to access the same memory unit, the UMMU may allocate the first entry for the first token identifier with reference to the above-mentioned method 1 or method 3.
[0128] After creating the first configuration table, when the UMMU receives the token identifiers assigned by the first device to different UB devices, it can refer to the method described in step 406 above to determine the address translation table and access permission table of the memory unit applied for by the corresponding UB device, and assign the corresponding table entry to the token identifier of the UB device in the first configuration table through the method described in step 407 above. In this way, the first configuration table will contain table entries corresponding to the token identifiers assigned to each UB device, and the table entries corresponding to each token identifier store the entry information of the address translation information and access permission information of the memory unit identified by the corresponding token identifier. Among them, if the token identifiers assigned to different UB devices for accessing the same memory unit are the same, then the table entry corresponding to the token identifier will store the entry information of the same address translation information and access permission information corresponding to these UB devices. If different UB devices are assigned different token identifiers for accessing the same memory unit, since different UB devices access the same memory unit and the same memory unit has the same address translation information, the entry information of the address translation information in different table entries corresponding to different token identifiers used to access the same memory unit may be the same. However, since different UB devices may have different access permission information for the same memory unit, the entry information of the access permission information in different table entries corresponding to different token identifiers used to access the memory unit may be different.
[0129] Step 408: Send the first token identifier to the second device.
[0130] After determining the first token identifier for the second device, the first device can send the first token identifier to the second device so that the second device can subsequently access the target memory unit in the first memory area managed by the first entity based on the first identifier and the first token identifier.
[0131] The above is an exemplary implementation of the entry information and address conversion information corresponding to the identifier of the configuration bus instance given in the embodiment of the present application. In some possible cases, after the UMMU obtains the first identifier according to the method described in step 401 above, it can also refer to the method described in step 402 to allocate a second table entry for the first identifier. Unlike step 402 above, the second table entry is not used to store the entry information of the first configuration table, but is used to store the entry information of the address conversion information and access permission information of the first memory area managed by the first entity. In this case, after allocating the second table entry for the first identifier, the UMMU can create an address conversion table and access permission information table for the first memory area managed by the first entity, and write the address conversion information and access permission information therein. Afterwards, the UMMU can use the base address of the address conversion table as the entry information of the address conversion information, and the base address of the access permission information table as the entry information of the access permission information, and write it to the second table entry. On this basis, when each UB device subsequently applies for a memory unit in the first memory area managed by the first entity, the first device no longer allocates a token identifier for each UB device, and the access permission information issued to each UB device is the same.
[0132] After creating address translation information with the bus instance identifier as the entry through the above method, the first device can then perform address translation and permission control through the memory access method shown in Figure 7 below upon receiving a memory access request from the second device, thereby achieving memory access. For example, referring to Figure 7, the process includes the following steps:
[0133] Step 701: Receive a memory access request from a second device, the memory access request including a UBA of a target memory unit to be accessed and a first identifier, the first identifier being an identifier of a target bus instance corresponding to a first memory area.
[0134] In an embodiment of the present application, the second device may send a memory access request to a USB controller corresponding to a target bus instance in the first device via the USB bus.
[0135] The UB controller corresponding to the target bus instance may refer to any UB controller included in the target bus instance, or a UB controller including the target bus instance. The memory access request may be a write request, a read request, or a send request. The memory access request may include memory access parameters. Furthermore, if the memory access request is a write request, the memory access request may also include data to be written. In addition, the memory access parameters include the UBA and a first identifier of the target memory unit to be accessed, and the first identifier is the identifier of the target bus instance. Since the target bus instance is the bus instance used by the first entity, and the memory area managed by the first entity is the first memory area, the target bus instance corresponds to the first memory area.
[0136] Optionally, the memory access parameter may further include a first token identifier pre-allocated by the first device to the second device for accessing the target memory unit. Optionally, the memory access parameter may further include second access permission information for accessing the target memory unit, for example, the second access permission information may be a second token value.
[0137] After receiving the memory access request, the UB controller in the first device may send the memory access parameters in the memory access request to the UMMU of the first device. Correspondingly, the UMMU receives the memory access parameters.
[0138] Step 702: Based on the first identifier, obtain first address translation information corresponding to the target bus instance.
[0139] In an embodiment of the present application, as can be seen from the foregoing introduction, the second table entry corresponding to the first identifier can be used to store the entry information of the first configuration table, and can also be used to store the entry information of the address translation table and the access permission table of the first memory area managed by the first entity. Based on this, if the second table entry stores the entry information of the first configuration table, the UMMU can obtain the first address translation information through the following method 1. If the second table entry stores the entry information of the address translation table and the access permission table of the first memory area managed by the first entity, the UMMU can obtain the first address translation information through the following method 2.
[0140] Method 1: The UMMU can obtain the entry information of the first configuration table corresponding to the target bus instance based on the first identifier in the memory access parameter, and determine the first configuration table based on the entry information of the first configuration table; based on the first token identifier in the memory access parameter, search the entry information of the address conversion information corresponding to the first token identifier from the first configuration table; based on the entry information of the address conversion information corresponding to the first token identifier, obtain the first address conversion information.
[0141] In the first example, the UMMU may read the base address of the second configuration table from the designated register. The UMMU may then determine the second table entry corresponding to the first identifier based on the base address of the second configuration table, the size of each table entry in the second configuration table, and the first identifier, and then read the entry information of the first configuration table in the second table entry.
[0142] As described in step 402 above, in the second configuration table, the entries corresponding to the identifiers of the various bus instances can be arranged sequentially from smallest to largest, and the sizes of the entries can be equal. Based on this, the UMMU can calculate an address offset based on the order of the first identifier among the identifiers of the multiple bus instances and the size of the entries in the second configuration table. Thereafter, the UMMU can determine the base address of the second entry corresponding to the first identifier based on the base address of the second configuration table and the address offset, and then read the entry information of the second entry in the first configuration table based on the base address of the second entry.
[0143] In the second example, the base address of the second table entry corresponding to the first identifier is stored in the designated register. Based on this, the UMMU can read the base address of the second table entry corresponding to the first identifier from the designated register, and then read the entry information of the first configuration table in the second table entry based on the base address of the second table entry.
[0144] The designated register may store base addresses of table entries corresponding to different bus instance identifiers, and the base addresses of the table entries corresponding to the respective identifiers may be stored in ascending or descending order. Based on this, the UMMU may obtain the base address of the second table entry corresponding to the first identifier from the designated register based on the order of the first identifier among the identifiers of the multiple bus instances.
[0145] Since the entry information of the first configuration table can indicate the storage location of the first configuration table, the UMMU can determine the first configuration table based on the entry information of the first configuration table read. Afterwards, the UMMU can search the first table entry corresponding to the first token identifier from the first configuration table according to the first token identifier carried in the memory access parameter, and read the entry information of the address conversion information corresponding to the first token identifier from the first table entry, wherein the address conversion information corresponding to the first token identifier is the address conversion information corresponding to the target memory unit identified by the first token identifier.
[0146] It should be noted that, based on the implementation method of allocating a corresponding table entry to a token identifier introduced in the aforementioned step 407, there are three implementation methods for the UMMU to search for the corresponding first table entry based on the first token identifier.
[0147] Method 1A: The table entry corresponding to any token identifier in the first configuration table will store the entry information of the token identifier and the address translation information corresponding to the token identifier. Based on this, the UMMU can search for the table entry containing the first token identifier from the various table entries in the first configuration table. The table entry is the first table entry corresponding to the first token identifier. Afterwards, the UMMU can read the entry information of the address translation information stored in the first table entry. The entry information of the address translation information is the entry information of the address translation information of the target memory unit identified by the first token identifier.
[0148] Method 1B: The table entry corresponding to any token identifier in the first configuration table is allocated according to the position of the memory unit identified by the token identifier in the multiple memory units managed by the first entity. In this case, the UMMU can determine the corresponding first table entry in the first configuration table based on the position of the target memory unit identified by the first token identifier in the multiple memory units.
[0149] For example, if the first token identifier is 002, it means that the target memory unit is the second memory unit among the multiple memory units managed by the first entity. Therefore, the second entry in the first configuration table is the first entry corresponding to the first token identifier.
[0150] Method 1C: The table entry corresponding to any token identifier in the first configuration table is allocated based on the sorting position of the token identifier among the multiple token identifiers corresponding to the first memory area managed by the first entity. In this case, the UMMU can determine the table entry at the corresponding sorting position in the first configuration table based on the sorting position of the first token identifier among the multiple token identifiers. The table entry is the first table entry corresponding to the first token identifier.
[0151] For example, if the first token identifier is 002, it means that the first token identifier is the second token identifier among the multiple token identifiers corresponding to the first memory area managed by the first entity. Therefore, the second entry in the first configuration table is the first entry corresponding to the first token identifier.
[0152] After finding the first table entry in the first configuration table, the UMMU can read the entry information of the address conversion information corresponding to the target memory unit identified by the first token identifier from the first table entry. The entry information can indicate the storage location of the address conversion information corresponding to the target memory unit. For example, the entry information can be the base address of the first address conversion table that includes the address conversion information of the target memory unit. Based on this, the UMMU can determine the first address conversion table based on the entry information of the address conversion information corresponding to the target memory unit, and then obtain the address conversion information contained in the first address conversion table. At this time, the address conversion information obtained is the first address conversion information.
[0153] Optionally, as can be seen from the introduction in the aforementioned step 407, the first table entry may also store entry information of the access permission information corresponding to the first token identifier. In this case, the memory access parameters of the second device may also include second access permission information. Based on this, the UMMU may also read the entry information of the access permission information corresponding to the first token identifier from the first table entry. The entry information may indicate the storage location of the access permission information. For example, the entry information may be the base address of the first access permission table that includes the access permission information of the target memory unit. Based on this, the UMMU may determine the first access permission table based on the entry information of the access permission information corresponding to the first token identifier, and then obtain the access permission information corresponding to the UBA of the target memory unit from the first access permission table. At this time, the access permission information obtained is the first access permission information.
[0154] Exemplarily, Figure 8 is a schematic diagram of an embodiment of the present application showing a method of obtaining first address conversion information and first access permission information based on a first identifier and a first token identifier. As shown in Figure 8, the UMMU can determine the second configuration table based on the base address adr1 of the second configuration table read from the designated register, and find the corresponding second table entry from the second configuration table according to the first identifier 0011. The base address adr2 of the first configuration table is stored in the second table entry. The UMMU reads adr2 and determines the first configuration table based on adr2. The first configuration table stores table entries corresponding to different token identifiers. Based on this, the UMMU can determine the first table entry corresponding to the first token identifier based on the first token identifier 002, and the first table entry stores the base address adr3 of the first address conversion table and the base address adr4 of the first access permission table. Based on this, UMMU can read adr3 and adr4, find the first address translation table based on adr3, obtain the address translation information in the first address translation table, obtain the first address translation information, find the first access permission table based on adr4, obtain the access permission information corresponding to the UBA of the target memory unit in the first access permission table, and obtain the first access permission information.
[0155] Method 2: The UMMU may determine the second table entry corresponding to the first identifier, and read the entry information of the address translation information of the first memory region managed by the first entity from the second table entry. The UMMU may then obtain the first address translation information based on the read entry information of the address translation information.
[0156] It should be noted that, in this implementation, the second table entry stores entry information of the address translation information of the first memory area managed by the first entity. The entry information of the address translation information can indicate the storage address of the address translation information of the first memory area. Therefore, the UMMU can read the address translation information of the first memory area managed by the first entity at the corresponding storage location according to the entry information, and the read address translation information is the first address translation information.
[0157] Optionally, the second table entry may also store entry information of the access permission information of the first memory area managed by the first entity. The entry information of the access permission information may indicate the storage address of the access permission information of the first memory area. Therefore, the UMMU may search for the access permission information corresponding to the UBA of the target memory unit from the corresponding storage location based on the entry information, and the access permission information found is the first access permission information.
[0158] Step 703: Access the target memory unit based on the first address translation information and the UBA of the target memory unit.
[0159] After obtaining the first address conversion information, UMMU can search for the physical address corresponding to the UBA of the target memory unit to be accessed from the first address conversion information. If found, the target memory unit can be accessed based on the physical address. If not found, it means that the UBA is incorrect or the target memory unit may not belong to the first memory area managed by the first entity or the token identifier corresponding to the target memory unit is not the first token identifier. In this case, UMMU determines that the second device has failed to access the target memory unit.
[0160] It should be noted that if the physical address corresponding to the UBA of the target memory unit is found, the UMMU can send the physical address to the UB controller corresponding to the target bus instance, so that the UB controller corresponding to the target bus instance accesses the target memory unit based on the physical address.
[0161] Optionally, if the memory access parameters include the second access permission information and the UMMU obtains the first access permission information, the UMMU may first compare the first access permission information with the second access permission information. If the first access permission information and the second access permission information are consistent, the UMMU may determine that the access permission verification for the second device has succeeded. The UMMU then sends the physical address corresponding to the UBA of the target memory unit to the UBA controller corresponding to the target bus instance.
[0162] For example, as described in the aforementioned step 407, the first access permission information may include a first token value generated by the first device when the second device applies for the target memory unit. The second access permission information carried in the memory access parameter may be a second token value. Based on this, the UMMU may compare the first token value and the second token value to determine whether they are identical. If they are identical, the second access permission information is the access permission information assigned by the first device to the second device. Therefore, it can be determined that the access permission verification for the second device has been successful.
[0163] Optionally, the first access permission information may also include first operation permission information for indicating operation permissions. In this case, the UMMU may also determine the request type of the memory access request of the second device, which may be a read request, a write request, or a send request. The UMMU may then detect whether the request type of the memory access request of the second device complies with the first operation permission information. If so, and the first token value and the second token value are the same, the access permission verification for the second device is determined to be successful.
[0164] For example, if the request type of the memory access request of the second device is a read request or a send request, and the first operation permission information includes read permission, or if the request type of the memory access request of the second device is a write request, and the first operation permission information includes write permission, then it means that the request type of the memory access request complies with the first operation permission information.
[0165] In an embodiment of the present application, the memory access parameters of the second device include the UBA and the first identifier of the target memory unit to be accessed, wherein the first identifier is the identifier of the target bus instance, and the target bus instance corresponds to the first memory area. Based on this, the UMMU obtains the first address conversion information corresponding to the target bus instance according to the first identifier, and then accesses the target memory unit based on the first address conversion information and the UBA. It can be seen that in the embodiment of the present application, the UMMU uses the identifier of the bus instance of this end as the entry to obtain the address conversion information of the memory unit to be accessed, and the bus instance of this end corresponds to the memory area of this end. Therefore, the number of bus instances of this end will not be affected by the number of UB devices connected to this end, that is, it will not be affected by the scale of the network. Therefore, it is conducive to efficient memory access in the case of large-scale networking.
[0166] In addition, in an embodiment of the present application, the second device may be a UB device integrated in the first device, or a UB device located outside the first device. Accordingly, the memory access request of the second device may be a request from a local UB device or a request from a remote UB device. Therefore, whether it is a request from a local UB device or a remote UB device, the UBA of the target memory unit to be accessed and the identifier of the target bus instance of the destination end where the target memory unit is located can be used to access the memory of the first device through the method provided in the embodiment of the present application. Therefore, the memory access method provided in the embodiment of the present application realizes the normalization of the memory access mechanism. Moreover, at present, in the related art, when processing the memory access request of the remote device, for example, when processing the RDMA request, a first-level address translation table and an access permission table are set on the local device connected to the RDMA device, wherein the address translation table can be used to realize the conversion of the host virtual address (HVA) to IOVA, and the access permission table can be used to realize the permission check of the RDMA device. Based on this, after converting the HVA in the RDMA request to IOVA, the local device will send the IOVA to the IOMMU or SMMU for the second-level address conversion. In the memory access method provided in the embodiment of the present application, the UMMU can directly perform first-level address translation and permission verification for requests from remote UB devices. Therefore, it can be seen that the memory access method provided in the embodiment of the present application can process memory access requests from remote UB devices, which can reduce the first-level page table and address translation compared to related technologies, thereby reducing memory overhead and address translation latency overhead.
[0167] Finally, in an embodiment of the present application, multiple USB controllers can be used as a bus instance. In this way, the same memory area can be accessed through the multiple USB controllers, realizing multi-plane memory access. In addition, in an embodiment of the present application, the first device can also create multiple bus instances and assign the multiple bus instances to different virtual instances. In this way, address translation information is configured based on the identification of the bus instance, which can achieve isolation of address translation information of different virtual instances.
[0168] Based on the memory access method introduced in the above embodiment, the embodiment of the present application provides a rendering of a plurality of UB devices accessing the memory of a first device through the memory access method provided by the embodiment of the present application. Referring to FIG9 , the UB controller 90 in the first device includes three bus instances, wherein the entity identifier of the bus instance 901 is EID-1, which is allocated to the virtual machine 95 for use; the instance identifier of the bus instance 902 is EID-2, which is allocated to the virtual machine 96 for use; and the entity identifier of the bus instance 903 is EID-3, which is allocated to the virtual machine 97 for use. Based on this, when accessing the memory of the first device, UB devices 92 to UB devices 94, which are connected to UB controller 90 via UB switch device 91, can carry the UBA of the memory area to be accessed and the identifier of the bus instance corresponding to the virtual machine that manages the memory area in the memory access request. For example, when UB device 92 accesses the memory area managed by virtual machine 95, the memory access request carries EID-1 and the UBA of the accessed memory area. In this way, after UB controller 90 sends the EID-1 and UBA in the data access request to the UMMU, the UMMU can search for address translation information based on EID-1 and convert the UBA based on the found address translation information, thereby achieving access to the memory area managed by virtual machine 95. Similarly, UB devices 93 and UB devices 94 can also access the memory areas managed by virtual machines 96 and 97 by sending memory access requests carrying EID-2 and EID-3, respectively.
[0169] Next, the memory access device provided in the embodiment of the present application is introduced.
[0170] Figure 10 is a structural diagram of a memory access device provided in an embodiment of the present application. The memory access device can be deployed in the first device of the aforementioned embodiment. Referring to Figure 10, the memory access device 1000 may include: a receiving module 1001, an acquisition module 1002 and an access module 1003.
[0171] The receiving module 1001 is used to execute step 701 in the aforementioned embodiment; the acquiring module 1002 is used to execute step 702 in the aforementioned embodiment; and the accessing module 1003 is used to execute step 703 in the aforementioned embodiment.
[0172] Optionally, the first device includes a first controller, the first controller includes at least one bus instance, and the at least one bus instance includes a target bus instance. The controller may be a UB controller or a controller under other system architectures.
[0173] Optionally, the first device includes N controllers, and the target bus instance includes N controllers, where N is a positive integer.
[0174] Optionally, the first memory area is a memory area allocated to a first entity in the first device, and the first entity is a host operating system or a virtual instance running on the first device.
[0175] Optionally, the access module 1003 is specifically configured to: search for a physical address corresponding to the UBA from the first address translation information; if the physical address corresponding to the UBA is found, access the target memory unit based on the physical address corresponding to the UBA, wherein the first memory area includes the target memory unit.
[0176] Optionally, the memory access request also includes a first token identifier; the acquisition module 1002 is specifically used to: based on the first identifier, obtain entry information of a first configuration table corresponding to the target bus instance, the first configuration table including multiple table entries corresponding one-to-one to multiple token identifiers, each table entry being used to store entry information of an address translation table corresponding to a corresponding token identifier; based on the entry information of the first configuration table, determine the first configuration table; search for a first table entry corresponding to the first token identifier from the first configuration table; and obtain first address translation information based on the entry information of the address translation table stored in the first table entry.
[0177] Optionally, the memory access request also includes second access permission information, and each table entry in the first configuration table is also used to store the entry information of the access permission table corresponding to the corresponding token identifier. The acquisition module 1002 is also used to: obtain the first access permission information based on the entry information of the access permission table stored in the first table entry; verify the second access permission information based on the first access permission information; if the verification of the second access permission information is passed, trigger the access module 1003 to execute the step of accessing the target memory unit based on the first address conversion information and UBA.
[0178] Optionally, the memory access apparatus further includes: a configuration module 1004 for acquiring a first identifier; storing entry information of a first configuration table based on the first identifier; and a sending module 1005 for sending the first identifier to the second device.
[0179] Optionally, the receiving module 1001 is also used to receive a memory request from a second device, the memory request including a first identifier and the UBA of a target memory unit; the configuration module 1004 is also used to obtain a first token identifier based on the UBA of the target memory unit; based on the UBA of the target memory unit, determine a first address translation table, the first address translation table including address translation information for converting the UBA of the target memory unit into a corresponding physical address; based on the first identifier, assign a corresponding first table entry to the first token identifier in the first configuration table, and write entry information of the first address translation table into the first table entry; the sending module 1005 is also used to send the first token identifier to the second device.
[0180] Optionally, the configuration module 1004 is also used to assign first access permission information to the second device; determine a first access permission table, the first access permission table includes the first access permission information; write entry information of the first access permission table in the first table item; the sending module 1005 is also used to send the first access permission information to the second device.
[0181] In an embodiment of the present application, the memory access request of the second device includes the UBA and the first identifier of the target memory unit to be accessed, wherein the first identifier is the identifier of the target bus instance in the first device, and the target bus instance corresponds to the first memory area in the first device. Based on this, the first address conversion information corresponding to the target bus instance is obtained according to the first identifier, and then the target memory unit is accessed based on the first address conversion information and the UBA. It can be seen that in this application, the address conversion information of the memory unit to be accessed is obtained by using the identifier of the bus instance of the access destination as an index, and the number of bus instances of the access destination is independent of the number of UB devices connected to the access destination. Therefore, it will not be affected by the scale of the network, which is conducive to efficient memory access in the case of large-scale networking.
[0182] It should be noted that the module division in the memory access device provided in the above embodiment is illustrative and is merely a logical functional division. In actual implementation, other division methods may be used. Furthermore, the functional modules in the various embodiments of the present application may be integrated into a single processor, exist physically separately, or two or more modules may be integrated into a single module. The aforementioned integrated modules may be implemented in the form of hardware or software functional modules.
[0183] If the integrated module is implemented in the form of a software functional module 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 embodiment 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 enabling a computer device to execute all or part of the steps of the method of each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as 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.
[0184] In addition, the memory access device and the memory access method provided in the above embodiments belong to the same concept, and their specific implementation processes are detailed in the method embodiments, which will not be repeated here.
[0185] In the above embodiments, all or part of the embodiments can be implemented by software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (eg, a floppy disk, a hard disk, a magnetic tape), an optical medium (eg, a digital versatile disc (DVD)), or a semiconductor medium (eg, a solid state disk (SSD)).
[0186] In the various embodiments of the present application, unless otherwise specified or logically conflicting, the terms and / or descriptions between different embodiments are consistent and can be referenced to each other. The technical features in different embodiments can be combined to form new embodiments based on their inherent logical relationships. In the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. In the textual description of the embodiments of the present application, the character " / " generally indicates that the related objects before and after are in an "or" relationship. In the present application, "first", "second" and various numerical numbers are only used to distinguish for the convenience of description and are not used to limit the scope of the embodiments of the present application. For example, to distinguish different messages, etc., rather than to describe a specific order or sequence.
[0187] It is understood that the various numbers used in the embodiments of the present application are only used for ease of description and are not intended to limit the scope of the embodiments of the present application. The order of the sequence numbers of the above-mentioned processes does not necessarily indicate the order in which they are executed. The order in which the processes are executed should be determined by their functions and internal logic.
[0188] Finally, it should be noted that the above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A memory access method, characterized in that: Applied to a first device, the method includes: Receive a memory access request from a second device, the memory access request including a first identifier and a unified bus address (UBA) of a target memory unit to be accessed, the first identifier being an identifier of a target bus instance, and the target bus instance corresponding to a first memory area; Based on the first identifier, obtaining first address translation information corresponding to the target bus instance; The target memory unit is accessed based on the first address translation information and the UBA.
2. The method according to claim 1, characterized in that The first device includes a first controller, the first controller includes at least one bus instance, and the at least one bus instance includes the target bus instance.
3. The method according to claim 1, characterized in that The first device includes N controllers, and the target bus instance includes the N controllers, where N is a positive integer.
4. The method according to claim 2 or 3, characterized in that The first memory area is a memory area allocated to a first entity in the first device, and the first entity is a host operating system or a virtual instance running on the first device.
5. The method according to any one of claims 1 to 4, characterized in that: The accessing the target memory unit based on the first address translation information and the UBA includes: Searching for a physical address corresponding to the UBA from the first address translation information; If the physical address corresponding to the UBA is found, the target memory unit is accessed based on the physical address corresponding to the UBA, and the first memory area includes the target memory unit.
6. The method according to any one of claims 1 to 5, characterized in that: The memory access request further includes a first token identifier; The acquiring, based on the first identifier, first address translation information corresponding to the target bus instance includes: Based on the first identifier, obtaining entry information of a first configuration table corresponding to the target bus instance, the first configuration table including a plurality of table entries corresponding one-to-one to a plurality of token identifiers, each table entry being used to store entry information of an address translation table corresponding to a corresponding token identifier; Determining the first configuration table based on the entry information of the first configuration table; Searching the first table entry corresponding to the first token identifier from the first configuration table; The first address translation information is obtained based on the entry information of the address translation table stored in the first table entry.
7. The method according to claim 6, characterized in that The memory access request further includes second access permission information, each entry in the first configuration table is further used to store entry information of an access permission table corresponding to a corresponding token identifier, and the method further includes: acquiring first access permission information based on entry information of the access permission table stored in the first entry; verifying the second access permission information based on the first access permission information; If the verification of the second access permission information is successful, the step of accessing the target memory unit based on the first address translation information and the UBA is performed.
8. The method according to claim 6 or 7, characterized in that The method further comprises: Obtaining the first identifier; Based on the first identifier, storing entry information of the first configuration table; Send the first identifier to the second device.
9. The method according to claim 8, characterized in that The method further comprises: receiving a memory request from the second device, the memory request including the first identifier and the UBA of the target memory unit; Obtaining the first token identifier based on the UBA of the target memory unit; Determining a first address translation table based on the UBA of the target memory unit, the first address translation table including address translation information for converting the UBA of the target memory unit into a corresponding physical address; Based on the first identifier, assigning a corresponding first table entry to the first token identifier in the first configuration table, and writing entry information of the first address translation table into the first table entry; Send the first token identifier to the second device.
10. The method according to claim 9, characterized in that The method further comprises: allocating first access permission information to the second device; determining a first access permission table, where the first access permission table includes the first access permission information; Writing entry information of the first access permission table into the first entry; Send the first access permission information to the second device.
11. A memory access device, characterized in that: The device includes at least one module, and the at least one module is used to execute the memory access method according to any one of claims 1 to 10.
12. A computer device, characterized in that: The computer device includes a memory, a memory management unit and a controller, wherein the memory management unit and the controller are used to execute at least one program instruction or code stored in the memory to implement the memory access method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed on a computer device, the computer device executes the memory access method according to any one of claims 1 to 10.
14. A computer program product comprising instructions, characterized in that When the computer program product is run on a computer device, the computer device is enabled to execute the memory access method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Request processing method, device and system
CN116010296A
Memory access method and device based on MCAL and multi-core chip
CN116126776A
Memory sharing method and device
CN117076347A
Managing wait states for memory access
US20140281156A1