Data processing method and computer device
By constructing a control memory and a dynamic radix tree to manage the physical page state, and employing atomic operation automata and MMU authentication, the problems of low efficiency and security risks in communication between external services and the kernel under the microkernel architecture are solved, and an efficient and secure communication method is achieved.
Patent Information
- Application Number
- PCT/CN2025/087212
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-07-09
- Filing Date
- 2025-04-03
- Publication Date
- 2026-01-15
AI Technical Summary
In existing technologies, communication between external services and the kernel under a microkernel architecture is inefficient, has poor scalability, and poses security risks. In particular, the shared memory approach may lead to kernel information leakage or crashes.
By constructing a control memory and dynamic radix tree to manage physical page states, efficient communication between off-kernel services and kernel-mode processes is achieved. Atomic automata are used for lock-free page type conversion, and MMU authentication is combined to ensure security and flexibility.
It reduces the communication overhead between off-kernel services and kernel-mode processes, improves communication flexibility and security, ensures that kernel information is not leaked, and keeps kernel complexity from increasing.
Smart Images

Figure CN2025087212_15012026_PF_FP_ABST
Abstract
Description
A data processing method and computer device
[0001] This application claims priority to Chinese Patent Application No. CN202410916827.0, filed on July 9, 2024, entitled "A Data Processing Method and Computer Equipment", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of computer data processing, and more particularly to a data processing method and a computer device. Background Technology
[0003] In operating systems, off-kernel services (i.e., user processes running outside the operating system kernel) generally function as service modules of the operating system, providing services to user programs. For monolithic kernels, some important services, such as the Secure Shell Daemon (SSHD), exist as off-kernel services. For microkernels, due to policy, mechanism separation, or security considerations, critical modules such as memory services, file system services, network services, and driver services can all exist as off-kernel services.
[0004] For services outside the kernel, especially those of critical modules in a microkernel architecture, efficient and secure communication with the kernel is essential. Currently, communication between the kernel and services outside the kernel is typically accomplished through system calls or shared memory.
[0005] However, both of the above methods have drawbacks: 1) System calls require switching execution contexts, and transferring large amounts of data requires cross-domain copying and processing results. Furthermore, system calls are inefficient and have poor scalability. 2) Shared memory addresses the issue of multiple context switches required for communication between user processes and system service processes under the system call method by passing relevant shared memory addresses between kernels. However, this introduces security risks to the kernel. Firstly, mutual exclusion between the two processes is required, but mutual exclusion between external programs and the kernel may block the kernel. Secondly, simultaneous read / write operations between external services and the kernel may lead to kernel information leakage or kernel crashes, and fine-grained control over the operations allowed by the kernel and external services is not possible. These shortcomings arise because shared memory is one of the simplest ways for two processes to communicate. Both processes need to provide a segment of virtual memory, which is then mapped to the same physical memory. Both processes can read and write to this physical memory through the corresponding virtual memory. When one process changes the content in the corresponding physical memory, the other process can immediately detect it. Therefore, a mechanism is needed to ensure mutual exclusion and prevent kernel information leakage, but current technologies are insufficient to guarantee this. Summary of the Invention
[0006] This application provides a data processing method and computer device to reduce the communication overhead between a system service process in kernel mode (i.e., the first process) and an off-kernel service in user mode (i.e., the second process) (because system calls are not used, context switching is unnecessary). Specifically, communication between the two processes is achieved through a constructed control memory and a dynamically generated radix tree (used to manage physical page states). This allows the off-kernel service to operate on the constructed control memory based on appropriate permissions, thereby ensuring the independence of the off-kernel service without increasing kernel complexity, making the off-kernel service more flexible and secure.
[0007] Based on this, the embodiments of this application provide the following technical solutions:
[0008] Firstly, this application provides a data processing method applied to a computer device, on which a first process in kernel mode and a second process in user mode are running. The method specifically includes: First, during the kernel startup phase, setting the status of all physical pages included in the physical memory of the computer device and creating a dynamic radix tree. A leaf node in the dynamic radix tree represents the physical page metadata corresponding to a physical page. The physical page metadata can also be called a data management structure, and each physical page metadata may include metadata such as physical page type and reference radix. Then, obtaining first information transmitted by the second process, the first information includes the second process requesting control memory of a first type, first permission, and first length from the kernel mode. The first type is a physical page type, the first permission is the permission required by the second process, and the control memory is a memory region used to control shared memory. Both the shared memory and the control memory belong to the physical memory of the computer device. Next, it will be further determined whether the first permission contained in the first information belongs to the target permission. If so, it means that the mapping of the second process to the required physical page specifies the correct permission. Based on this, control memory is created for the second process according to the dynamic radix tree created above, so that the second process can operate on the control memory based on the first permission. The target permission is the permission pre-configured for the first type in kernel mode. Finally, the second information passed by the second process is obtained, and the control memory is released according to the second information. The second information includes the second process requesting the kernel mode to release the control memory after using it.
[0009] In the above embodiments of this application, the communication overhead between the system service process in kernel mode (i.e., the first process) and the off-kernel service in user mode (i.e., the second process) is reduced because system calls are not used, thus eliminating the need for context switching. Specifically, communication between the two processes is achieved through a constructed control memory and a dynamically generated radix tree (used to manage physical page states). This allows the off-kernel service to operate on the constructed control memory based on appropriate permissions, thereby ensuring the independence of the off-kernel service without increasing kernel complexity, making the off-kernel service more flexible and secure.
[0010] In one possible implementation of the first aspect, after obtaining the first information transmitted by the second process, the method may further include: if the physical page type of the target physical page (one or more) does not belong to the first type claimed above, converting the current second type of the target physical page to the first type by means of an atomic operation automaton in kernel mode, wherein the target physical page is one or more of the physical pages included in the computer device, and the target physical page belongs to the physical page required by the second process.
[0011] In the above embodiments of this application, if all or part of the physical pages required by the second process are not of the first type requested by the second process, the type conversion of these physical pages (i.e., the target physical pages) can be performed without locks by an atomic automaton in the kernel mode. By designing a physical page state management method based on atomic operations and a lock-free page type conversion algorithm, the large overhead of context switching caused by system calls during traditional user-mode and kernel-mode communication is solved, while ensuring high scalability and wide applicability of communication between user-mode and kernel-mode, and making it more flexible.
[0012] In one possible implementation of the first aspect, the method may further include: after the control memory has been used up, converting the current first type of the target physical page back to the original second type via an atomic operation automaton.
[0013] In the above embodiments of this application, after the control memory is used up, if the original target physical page has been converted to a different page type, the page type needs to be converted back to the original type after the control memory is used up, so as to facilitate the use of other off-kernel services and ensure that kernel information is not leaked.
[0014] In one possible implementation of the first aspect, the first process manages the physical metadata of each physical page through the dynamic radix tree, wherein different levels of physical page metadata are used to manage different sizes of physical memory on the computer device.
[0015] In the above embodiments of this application, it is specifically explained that a dynamic radix tree is used to manage the metadata of each physical page. Each level of physical metadata manages physical memory of different sizes, thereby reducing the amount of physical metadata data stored and reducing complexity.
[0016] In one possible implementation of the first aspect, the first information further includes: the physical memory address of the physical page required by the second process, and / or the virtual memory address that the second process needs to map.
[0017] In the above embodiments of this application, additional information that may be included in the first information is specifically described, with the aim of ensuring the advantages of the original kernel architecture without increasing kernel complexity.
[0018] In one possible implementation of the first aspect, after releasing the control memory according to the second information, the method may further include: notifying the second process of the physical memory address of the required physical page and the virtual memory address mapped to the physical memory address.
[0019] In the above embodiments of this application, after the kernel mode releases the control memory, it is also necessary to notify the user mode to reclaim the physical memory address and the mapped virtual memory address to ensure that kernel information is not leaked and to ensure the security of the kernel itself.
[0020] In one possible implementation of the first aspect, one way to obtain the first information transmitted by the second process is to obtain the first information transmitted by the second process through a system call.
[0021] In the above embodiments of this application, the transmission of the first information can be carried out through system calls, which is feasible and universal.
[0022] In one possible implementation of the first aspect, after creating control memory for the second process based on a dynamic radix tree, the method may further include: if the first permission is read-only or read-write, authentication is performed through a memory management unit (MMU) so that the second process can read the control memory on demand and / or write to the control memory on demand.
[0023] In the above embodiments of this application, based on shared memory, fast authentication is achieved through the MMU, allowing user space to read kernel objects or write directly writable kernel objects, thus ensuring the security of access for both parties.
[0024] In one possible implementation of the first aspect, after creating control memory for the second process based on a dynamic radix tree, the method may further include: if the first process has read-only permissions but there is a write requirement, the second process can be triggered to enter the kernel via a system call and verify the legality of the operation. For example, the legality of the operation can be verified by checking whether the corresponding virtual address memory is mapped and whether the mapped physical page is of the specified page type. This allows the second process to use or modify the control memory if the operation is legal, and to synchronize using lock-free or asymmetric locks.
[0025] In the above embodiments of this application, synchronization of shared memory between kernel and off-kernel services is achieved by determining whether the virtual memory address is mapped in the page table and the specific permissions for mapping under specific physical page type restrictions.
[0026] In one possible implementation of the first aspect, one way to verify the legality of an operation is to perform authentication verification of the operation through an MMU.
[0027] In the above embodiments of this application, the legality of the operation can also be verified using the MMU, which is feasible.
[0028] A second aspect of this application provides a computer device having the function of implementing the method of the first aspect or any possible implementation thereof. This function can be implemented by hardware or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-described function.
[0029] A third aspect of this application provides a computer device that may include a memory, a processor, and a bus system. The memory is used to store a computer program (also referred to as a program or computer-readable instructions), and the processor is used to invoke the program stored in the memory to execute the method of the first aspect of the embodiments of this application or any possible implementation of the first aspect.
[0030] A fourth aspect of this application provides a computer-readable storage medium storing instructions that, when executed on a computer, enable the computer to perform the methods described in the first aspect or any possible implementation thereof.
[0031] The fifth aspect of this application provides a computer program or a computer program product containing instructions that, when the computer program or computer program product is run on a computer, causes the computer to perform the method described in the first aspect or any possible implementation of the first aspect.
[0032] A sixth aspect of this application provides a chip including at least one processor and at least one interface circuit coupled to the processor. The interface circuit performs transceiver functions and sends instructions to the at least one processor. The at least one processor runs a computer program or instructions, having the functionality to implement the methods described in the first aspect or any possible implementation of the first aspect. This functionality can be implemented in hardware, software, or a combination of hardware and software, including one or more modules corresponding to the described functions. Furthermore, the interface circuit is used to communicate with other modules outside the chip.
[0033] In some implementations of this application, some of the one or more processors may implement some steps of the above method through dedicated hardware. For example, the processing involving neural network models may be implemented by a dedicated neural network processor or graphics processor.
[0034] The method provided in this application embodiment can be implemented by a single chip or by multiple chips working together. Attached Figure Description
[0035] Figure 1 is a schematic diagram of the system architecture provided in an embodiment of this application;
[0036] Figure 2 is another schematic diagram of the system architecture provided in the embodiment of this application;
[0037] Figure 3 is a flowchart illustrating a data processing method provided in an embodiment of this application.
[0038] Figure 4 is a schematic diagram of a process for setting the physical page state initialization according to an embodiment of this application;
[0039] Figure 5 is a schematic flowchart of the application control memory provided in an embodiment of this application;
[0040] Figure 6 is a flowchart illustrating the operation control memory provided in an embodiment of this application;
[0041] Figure 7 is a schematic diagram of a process for releasing control memory provided in an embodiment of this application;
[0042] Figure 8 is a schematic diagram of the core structure provided in an embodiment of this application;
[0043] Figure 9 is a schematic diagram of a computer device provided in an embodiment of this application;
[0044] Figure 10 is a schematic diagram of a computer device provided in an embodiment of this application. Detailed Implementation
[0045] This application provides a data processing method and computer device to reduce the communication overhead between a first process in kernel mode and a second process in user mode (because context switching is unnecessary). Specifically, communication between the two processes in a separate state is achieved by constructing control memory and combining it with a dynamically generated radix tree (used to manage physical page states). This allows external services to operate on the constructed control memory based on appropriate permissions, thus maintaining the advantages of the original kernel structure without increasing kernel complexity, while ensuring that kernel information is not leaked, thereby improving the kernel's security. Furthermore, this communication method makes synchronization between the kernel and external services more flexible.
[0046] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0047] To better understand the solutions of the embodiments of this application, the relevant terms and concepts that may be involved in the embodiments of this application will be introduced below. It should be understood that the explanations of the relevant terms and concepts may be limited due to the specific circumstances of the embodiments of this application, but this does not mean that this application can only be limited to that specific circumstance. The specific circumstances of different embodiments may also differ, and no specific limitation is made here.
[0048] (1) Extranuclear services
[0049] User processes that run outside the operating system kernel.
[0050] (2) Bandwidth
[0051] The amount of data transmitted per unit of time by kernel and off-kernel services.
[0052] (3) Scalability
[0053] The algorithm is extended to the ability to run on multiple cores.
[0054] (4) Atomic operations
[0055] Indivisible operations performed by the processor.
[0056] (5) Automaton
[0057] A logical machine that determines the next state based on the current state and the input.
[0058] (6) Lock-free algorithm
[0059] Without using locks, a concurrency-safe algorithm is ensured through proper design.
[0060] (7) Control Memory
[0061] The memory region used to control shared memory, also known simply as ctrlmem.
[0062] (8) Page Table Walk
[0063] Page Table Walk is a process that translates virtual memory addresses (VA) into physical memory addresses (PA) for virtual memory management. Through multi-level page table lookups, the operating system can locate the corresponding physical memory address based on the virtual memory address.
[0064] (9) Radix Tree
[0065] In computer science, a radix tree, also known as a compressed prefix tree, can be viewed as a trie tree with binary bit strings as keys, and is a multi-branch tree structure. For each node in a radix tree, if the node is a definite subtree, it is merged with its parent node. Radix trees can be used to construct associative arrays, for IP routing, etc. In the embodiments of this application, a leaf node in the radix tree represents the physical page metadata corresponding to a physical page; physical page metadata can also be referred to as a data management structure.
[0066] The embodiments of this application will now be described with reference to the accompanying drawings. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are equally applicable to similar technical problems.
[0067] First, the system architecture and overall process applied in the method of this application embodiment will be described. Please refer to Figure 1 for details. Figure 1 is a schematic diagram of the system architecture provided in the embodiment of this application. The system architecture may include: an external service 101 in user mode and a system service process 102 in kernel mode (which may be referred to as kernel 102). There are three main processes between the external service 101 and the kernel 102:
[0068] 1) External service 101 requests to establish a communication path with kernel 102, namely control memory (also known as ctrlmem). During this process, kernel 102 performs security checks and changes the page state of physical pages (if there are cases where the type of physical page needs to be converted). After that, kernel 102 further verifies the mapping permissions and establishes the mapping, thereby constructing control memory that external service 101 can use.
[0069] 2) External service 101 performs related operations using the allocated control memory. During read and write operations, the MMU can quickly authenticate permissions by checking if a mapping has been established in the page table. For cases where external service 101 operates on read-only kernel objects but also requires writing, the ctrlmem_write system call can be used. During this process, the PA corresponding to the VA can be found using the MMU's AT (Attention) instruction (taking the ARM platform as an example) or Page Table Walk, thus authenticating the operation of external service 101. For each physical page type, external service 101 has different operation permissions and scopes, thus enabling fine-grained, asymmetric permission management for kernel 102 and external service 101.
[0070] 3) After using the control memory, the off-kernel service 101 will request the release of the control memory from the kernel 102. During this process, the kernel 102 will also perform security checks and page state changes for physical pages (if there are cases where the physical page type needs to be converted).
[0071] It should be noted that, for ease of management of kernel 102, the above three core processes can be implemented through one or more additional modules within kernel 102. Referring to Figure 2, as an example, a physical page state management module 1001 and a control memory module 1002 can be configured within kernel 102. Specifically, in the first core process, kernel 102 can perform security checks and physical page state changes through the physical page state management module 1001. Then, kernel 102 further verifies mapping permissions and establishes mappings through the control memory module 1002, thereby constructing control memory usable by the external service 101. In the second core process, after finding the PA corresponding to the VA through MMU AT commands or Page Table Walk, the physical page state management module 1001 authenticates the operations of the external service 101. In the third core process, kernel 102 performs security checks and changes the physical page state through the physical page state management module 1001.
[0072] It should be noted that, in this embodiment of the application, in addition to deploying two modules in the kernel 102 (as shown in Figure 2), the above process can also be achieved by deploying one module or three or more modules. Figure 2 is only for illustration, and this application does not limit the number of modules deployed.
[0073] It should also be noted that in the embodiments of this application, the system architectures of Figures 1 and 2 are only illustrative, and this application does not limit the deployment method of each unit / module.
[0074] Based on the above system architecture and in conjunction with the three core processes described above, the data processing method provided in this application embodiment is introduced. This method is applied to a computer device, where a first process in kernel mode and a second process in user mode run on the computer device. Please refer to Figure 3 for details. Figure 3 is a flowchart illustrating the data processing method provided in this application embodiment. The method may specifically include the following steps:
[0075] The code segment running in the first process is used to perform the following operations:
[0076] 301. Set the status of the physical pages included in the computer device and create a dynamic radix tree based on the set status.
[0077] First, during the kernel startup phase, the state of all physical pages included in the physical memory of the computer device is set, and a dynamic radix tree is created. For example, the physical page state management module 1001 mentioned above can be initialized to complete the initial state setting of all physical pages and create a dynamic radix tree. A leaf node in this dynamic radix tree represents the physical page metadata corresponding to a physical page. Physical page metadata can also be called a data management structure, and each piece of physical page metadata can include metadata such as physical page type and reference radix.
[0078] It should be noted that, in the embodiments of this application, a dynamic radix tree refers to a radix tree whose leaf nodes are not fixed. As the external services have different requirements for physical pages (e.g., different requirements for physical page types), the physical metadata corresponding to one or more leaf nodes may change. When such changes occur, the leaf nodes of the radix tree can be adjusted, hence the name dynamic radix tree.
[0079] It should be noted that in some embodiments of this application, the first process manages the physical metadata of each physical page through this dynamic radix tree. Different levels of physical page metadata are used to manage different sizes of physical memory on the computer device. The last level of physical page metadata manages 4K pages, which is the smallest granularity of a physical page, meaning the page size is 4KB, hence the abbreviation 4K page. For example, specifically, the physical page state management module 1001 described above can manage the metadata of each physical page through this dynamic radix tree. This dynamic radix tree can dynamically adjust whether the last level of physical page metadata is linearly arranged based on memory usage.
[0080] To facilitate understanding of the above initialization and dynamic radix tree creation process, Figure 4 is used as an example for illustration. Figure 4 is a schematic flowchart of the physical page state initialization settings provided in an embodiment of this application, which may include the following steps:
[0081] Step ①: Initialize the multi-way tree.
[0082] First, the system will initialize the multi-branch tree upon startup.
[0083] Step 2: Determine if it is a leaf node. If yes, proceed to step 3; otherwise, proceed to step 8.
[0084] Next, determine in turn whether each node of the multi-way tree is a leaf node. If it is, proceed to step ③; otherwise, proceed to step ⑧.
[0085] Step 3: Determine if it is a large page. If yes, proceed to step 4; otherwise, proceed to step 5.
[0086] Next, determine whether the leaf node is a big page. If not, proceed to step ④; otherwise, proceed to step ⑤. In this embodiment, a big page refers to a page size that is more than 4K (because the default page size is generally 4K). For example, a big page can be 2048K.
[0087] Step 4: Identify it as a large leaf node and proceed to step 9.
[0088] Step 5: Determine if the leaf node is in low noise mode. If yes, proceed to step 6; otherwise, proceed to step 7.
[0089] Step 6: Determine the nonlinear arrangement of leaf nodes and proceed to step 9.
[0090] Step 7: Determine the linear arrangement of the leaf nodes and proceed to step 9.
[0091] Step 8: Determine the leaf node as the intermediate node and proceed to step 9.
[0092] Step 9: Determine if the traversal has ended. If yes, the initialization is complete. If not, return to step 2.
[0093] 302. Obtain the first information passed by the second process. The first information includes the second process requesting control memory of the first type, the first permission, and the first length from the kernel mode. The first type is a physical page type, and the first permission is the permission required by the second process.
[0094] Subsequently, specific information transmitted by the second process is obtained. For example, this specific information can be obtained through a system call, and this information can be referred to as the first information. Specifically, the first information may include: the second process requesting control memory of a specified type (referred to as the first type), required permissions (referred to as the first permission), and required length (referred to as the first length) from the kernel as needed. The first type is one of the physical page types. In this embodiment, there can be multiple physical page types, such as normal type, pgtbl type, etc., which will not be elaborated here. In this embodiment, the control memory is a memory region used to control shared memory. Both the shared memory and the control memory requested by the second process belong to the physical memory of the computer device.
[0095] It should be noted that in some other embodiments of this application, the first information may include, but is not limited to: the physical memory address of the physical page required by the second process, and / or, the virtual memory address that the second process wants the corresponding physical memory address to be mapped to itself.
[0096] As an example, if the kernel can directly allocate the physical memory address of the corresponding physical page required by the second process, then the first information, in addition to including the first type, first permission and first length of control memory requested by the second process from the kernel mode, may only include the virtual memory address that the second process wants the corresponding physical memory address to be mapped to itself.
[0097] As another example, if the kernel cannot directly allocate the physical memory address of the corresponding physical page for the second process, then the first information, in addition to including the control memory of the first type, first permission, and first length requested by the second process from the kernel, may also include the physical memory address of the physical page required by the second process and the virtual memory address that the second process wants the corresponding physical memory address to be mapped to itself. Specifically, this application does not limit the additional content that the first information needs to include.
[0098] It should also be noted that in some other embodiments of this application, if all or part of the physical pages required by the second process are not of the first type requested by the second process, then the type conversion of these physical pages (which may be referred to as target physical pages) needs to be performed by an atomic operation automaton in kernel mode. Specifically, when the physical page type of one or more target physical pages does not belong to the first type requested above, the current type (which may be referred to as the second type) of the target physical page is converted to the first type by an atomic operation automaton in kernel mode. Here, the target physical page is one or more of the physical pages included in the computer device, and the target physical page belongs to the physical pages required by the second process.
[0099] As an example, the atomic operation automaton in the physical page state management module 1001 described above can be used to complete the type conversion of the target physical page (e.g., from normal type to pgtbl type) without locks through atomic operations.
[0100] It should be noted that in the embodiments of this application, the atomic operation automaton refers to a series of operations of the automaton that do not require locking (because they are all atomic operations), thereby saving some steps. It is a lock-free operation with high concurrency, hence the name atomic operation automaton.
[0101] 303. If the first permission belongs to the target permission, create control memory for the second process based on the dynamic radix tree so that the second process can operate on the control memory based on the first permission. The target permission is the permission that was configured for the first type in the kernel mode in advance.
[0102] Next, it will be further determined whether the first permission contained in the first information belongs to the target permission. If so, it means that the mapping of the second process to the required physical page specifies the correct permission. Based on this, control memory is created for the second process based on the dynamic radix tree created above. The second process can then operate on the control memory based on the first permission it has applied for.
[0103] It should be noted that in this embodiment, the target permission is the permission pre-configured for the first type in kernel mode, which may include one or more permissions. The first permission may be one of the target permissions, multiple of the target permissions, or simply the target permission itself, depending on the permissions requested by the second thread. This application does not limit this.
[0104] Similarly, to facilitate understanding of the above process of applying for memory control, Figure 5 is used as an example for illustration below. Figure 5 is a schematic flowchart of applying for memory control provided in an embodiment of this application, which may specifically include the following steps:
[0105] Step ①: The atomic automaton performs page type conversion on the target physical page.
[0106] First, if one or more target physical pages requested by the second process do not have a page type that meets the first type requested, the kernel will perform page type conversion on one or more target physical pages through an atomic automaton, because the current page type of the target physical page is the second type, which does not meet the first type requested by the second process.
[0107] Step 2: Determine if the conversion is complete. If yes, proceed to step 3; otherwise, proceed to step 4.
[0108] Next, it is determined whether the page type conversion is complete. If yes, step ③ is executed; otherwise, step ④ is executed.
[0109] Step 3: Check if the type of permissions is correct. If yes, proceed to step 5; otherwise, proceed to step 4.
[0110] Next, check if the mapping of services outside the kernel has been assigned the correct permissions. If yes, proceed to step ⑤; otherwise, proceed to step ④.
[0111] Step 4: Operation failed.
[0112] Return the failed request result to the second process.
[0113] Step 5: Establish the mapping and proceed to step 6.
[0114] The mapping between the two has been successfully established, and the process proceeds to step 6.
[0115] Step 6: Return to operation completed.
[0116] Return the completed request result to the second process.
[0117] In this embodiment, after creating control memory for the second process based on the dynamic radix tree, it means that the second process has successfully requested a block of control memory with the correct permissions. The kernel and external services can then operate on this control memory according to their respective permissions and needs. For example, the second process can operate on the control memory based on its first permissions. The operations on the control memory will differ depending on the first permissions, which will be explained below:
[0118] (1) The first permission is read-only permission, or read-write permission.
[0119] If the first permission is only read-only, or if the first permission is read-write, then fast authentication can be performed through the MMU, allowing the second process to read the control memory as needed, and / or write to the control memory as needed.
[0120] (2) The first permission is read-only, but there is a need to write.
[0121] If the first process has read-only permissions but there is a write requirement, a second process can be triggered to enter the kernel via a system call and verify the legality of the operation. For example, the legality of the operation can be verified by checking whether the corresponding virtual address memory is mapped and whether the mapped physical page is of the specified page type. If the operation is legal, the second process can use or modify the control memory and synchronize through lock-free or asymmetric locks (kernel trylock to external service lock).
[0122] It should be noted that in some embodiments of this application, the legality of the above operations can also be verified by authentication through the MMU.
[0123] Similarly, to facilitate understanding of the above-described process of controlling memory, Figure 6 is used as an example for explanation. Figure 6 is a flowchart illustrating the operation of controlling memory according to an embodiment of this application, which may specifically include the following steps (described from the perspective of a second process):
[0124] Step 1: Determine if it is a write operation. If yes, proceed to step 2; otherwise, proceed to step 3.
[0125] First, determine whether the current memory operation is a write operation. If yes, proceed to step ②; otherwise, proceed to step ③.
[0126] Step 2: Determine if write permissions are granted. If yes, proceed to step 3; otherwise, proceed to step 4.
[0127] Next, it is further determined whether the first permission obtained is write permission. If yes, step ③ is executed; otherwise, step ④ is executed.
[0128] Step 3: Perform the operation.
[0129] Perform the corresponding operation.
[0130] Step 4: Enter the kernel via a system call.
[0131] Step 5: Verify the mapping and proceed to step 6.
[0132] You can check whether the corresponding virtual address memory is mapped using the MMU's AT commands (taking the ARM platform as an example) or Page Table Walk.
[0133] Step 6: Check the page type and proceed to step 7.
[0134] Verify that the mapped physical page is of the specified page type.
[0135] Step 7: Determine whether the test is passed. If yes, proceed to step 3; otherwise, proceed to step 8.
[0136] Finally, determine whether the checks in steps ⑤ and ⑥ above have passed. If yes, proceed to step ③; otherwise, proceed to step ⑧.
[0137] Step 8: Interception operation.
[0138] Intercept the corresponding operation.
[0139] 304. Obtain the second information passed by the second process, and release the control memory according to the second information.
[0140] Finally, after using the control memory, the off-kernel service can request its release from the kernel. Therefore, the second process will send a message to the kernel, called the second message, which includes the second process's request to the kernel to release the control memory. Thus, after receiving the second message from the second process, the control memory can be released based on that message.
[0141] It should be noted that in some embodiments of this application, if the type of the target physical page has been converted before the control memory is created, then after the control memory is used up, it is necessary to convert the page type of the target physical page back through an atomic operation automaton, that is, to convert the current first type of the target physical page back to the original second type.
[0142] It should also be noted that in some other embodiments of this application, if the first information includes, in addition to the second process requesting control memory of the first type, first permission, and first length from the kernel, the physical memory address of the physical page required by the second process, and / or the second process wants the corresponding physical memory address to be mapped to its own virtual memory address, then after releasing the control memory, it is also necessary to notify the off-kernel service to reclaim the physical memory address and the mapped virtual memory address, that is, to notify the second process to reclaim the physical memory address of the required physical page and the virtual memory address mapped by the physical memory address.
[0143] Similarly, to facilitate understanding of the above process of releasing control memory, Figure 7 is used as an example for illustration. Figure 7 is a schematic flowchart of releasing control memory provided in an embodiment of this application, which may specifically include the following steps:
[0144] Step ①: The atomic automaton performs page type conversion on the target physical page.
[0145] First, if the type of the target physical page was converted before the control memory was created, then after the control memory is used, the current page type of the target physical page needs to be converted back to the original page type through an atomic operation automaton. Specifically, the current first type of the target physical page is converted back to the original second type.
[0146] Step 2: Determine if the conversion is complete. If yes, proceed to step 3; otherwise, proceed to step 4.
[0147] Next, it is determined whether the page type conversion is complete. If yes, step ③ is executed; otherwise, step ④ is executed.
[0148] Step 3: Unmap and proceed to step 5.
[0149] The mapping between the two was successfully removed, and the process proceeds to step ⑤.
[0150] Step 4: Operation failed.
[0151] Return the failed request result to the second process.
[0152] Step 5: Return to operation completed.
[0153] Return the completed request result to the second process.
[0154] In summary, based on the system architecture described in Figure 2 and the implementation methods described in Figures 3-7, the core architecture diagram shown in Figure 8 can be obtained. As can be seen from Figure 8, it mainly consists of two parts:
[0155] (1) Physical Page State Management Module
[0156] This is used for atomic automata and dynamic radix trees based on page state to implement physical page state management. It can atomically perform process safety checks on physical pages and transition the state of physical pages.
[0157] (2) Control memory module
[0158] Shared memory allows both user mode and kernel mode to read kernel objects, and the ctrlmem_write system call, implemented by controlling memory, assists user mode in operating read-only kernel objects and user mode in writing writable kernel objects.
[0159] Based on the corresponding embodiments described above, in order to better implement the above-described solutions of this application, related devices for implementing the above-described solutions are also provided below. Specifically, refer to Figure 9, which is a schematic diagram of a computer device provided in an embodiment of this application. The computer device 900 runs a first process in kernel mode and a second process in user mode. The computer device 900 includes: a first creation module 901, an acquisition module 902, a second creation module 903, and a release module 904. The first creation module 901 is used to set the state of the physical pages included in the computer device and create a dynamic radix tree based on the set state. A leaf node in the dynamic radix tree represents the physical page metadata corresponding to a physical page. The acquisition module 902 is used to acquire the first information transmitted by the second process. The first information includes the second process requesting a first type, a first permission, and a first... The control memory has a length, the first type is a physical page type, the first permission is the permission required by the second process, and the control memory is a memory region used to control shared memory. Both the shared memory and the control memory belong to the physical memory of the computer device. The second creation module 903 is used to create the control memory for the second process based on the dynamic radix tree when the first permission is the target permission, so that the second process can operate on the control memory based on the first permission. The target permission is the permission pre-configured for the first type in the kernel mode. The release module 904 is used to obtain the second information passed by the second process and release the control memory according to the second information. The second information includes the second process requesting the kernel mode to release the control memory.
[0160] In one possible design, the computer device 900 further includes a type conversion module 905, which, after the acquisition module 902 acquires the first information transmitted by the second process, converts the current second type of the target physical page to the first type through an atomic operation automaton in the kernel state if the type of the target physical page does not belong to the first type. The target physical page is one or more of the physical pages included in the computer device and the target physical page belongs to the physical page required by the second process.
[0161] In one possible design, the type conversion module 905 is also used to: after the control memory has been used up, convert the current first type of the target physical page back to the second type through the atomic operation automaton.
[0162] In one possible design, the first process manages the physical page metadata of each physical page through the dynamic radix tree, where different levels of the physical page metadata are used to manage physical memory of different sizes.
[0163] In one possible design, the first information may also include: the physical memory address of the physical page required by the second process; and / or, the virtual memory address that the second process needs to map.
[0164] In one possible design, the release module 904 is further configured to: after releasing the control memory according to the second information, notify the second process to reclaim the physical memory address of the required physical page and the virtual memory address mapped by the physical memory address.
[0165] In one possible design, module 902 is specifically used to: obtain the first information passed by the second process through a system call.
[0166] In one possible design, the second creation module 903 is further configured to: after creating the control memory for the second process based on the dynamic radix tree, authenticate via the MMU if the first permission is read-only or read-write, so that the second process can read the control memory as needed, and / or write the control memory as needed.
[0167] In one possible design, the second creation module 903 is further configured to: after creating the control memory for the second process based on the dynamic radix tree, if the first permission is read-only but there is a write requirement, trigger the second process to enter the kernel through a system call and verify the legality of the operation, so that the second process can use or modify the control memory if the operation is legal.
[0168] In one possible design, verifying the legitimacy of an operation includes: verifying the legitimacy of the operation through authentication via the MMU.
[0169] It should be noted that the information interaction and execution process between the modules / units in the computer device 900 are based on the same concept as the method embodiments corresponding to Figures 3 to 8 in this application. For details, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.
[0170] The following describes a computer device provided in an embodiment of this application. Please refer to Figure 10, which is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device 1000 may be equipped with the modules described in the embodiment corresponding to Figure 9, used to implement the functions of the computer device 900 in the embodiment corresponding to Figure 9. Specifically, the computer device 1000 is implemented by one or more servers. The computer device 1000 may vary considerably due to different configurations or performance, and may include one or more central processing units (CPUs) 1022 and memory 1032, and one or more storage media 1030 (e.g., one or more mass storage devices) for storing application programs 1042 or data 1044. The memory 1032 and storage media 1030 may be temporary storage or persistent storage. The program stored in the storage media 1030 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the computer device 1000. Furthermore, the central processing unit 1022 can be configured to communicate with the storage medium 1030 and execute a series of instruction operations in the storage medium 1030 on the computer device 1000.
[0171] Computer device 1000 may also include one or more power supplies 1026, one or more wired or wireless network interfaces 1050, one or more input / output interfaces 1058, and / or one or more operating systems 1041, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0172] In this embodiment, the central processing unit 1022 is used to execute the steps in the above method embodiments. The specific implementation of the above steps by the central processing unit 1022 is based on the same concept as the above method embodiments in this application, and the resulting technical effects are also the same as those in the above embodiments of this application. For details, please refer to the description in the method embodiments shown above in this application, which will not be repeated here.
[0173] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0174] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by the corresponding hardware, and the specific hardware structure used to implement the same function can also be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product, or a combination of a software product and a hardware product. The computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk, etc., including several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0175] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product.
[0176] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A data processing method, characterized in that, Applied to a computer device, wherein a first process in kernel mode and a second process in user mode are running on the computer device, the method includes: The code segment is executed through the first process to perform the following operations: The physical pages included in the computer device are configured with a state, and a dynamic radix tree is created based on the configured state. A leaf node in the dynamic radix tree represents the physical page metadata corresponding to a physical page. Obtain the first information transmitted by the second process. The first information includes the second process requesting control memory of a first type, a first permission, and a first length from the kernel mode. The first type is a physical page type, the first permission is the permission required by the second process, and the control memory is a memory area used to control shared memory. Both the shared memory and the control memory belong to the physical memory of the computer device. If the first permission belongs to the target permission, the control memory is created for the second process based on the dynamic radix tree, so that the second process can operate on the control memory based on the first permission. The target permission is the permission that is configured in advance for the first type in the kernel mode. The second information transmitted by the second process is obtained, and the control memory is released according to the second information, wherein the second information includes the second process requesting the release of the control memory from the kernel mode.
2. The method according to claim 1, characterized in that, After obtaining the first information transmitted by the second process, the method further includes: If the type of the target physical page does not belong to the first type, the current second type of the target physical page is converted to the first type by the atomic operation automaton in the kernel state. The target physical page is one or more of the physical pages included in the computer device, and the target physical page belongs to the physical page required by the second process.
3. The method according to claim 2, characterized in that, The method further includes: After the control memory is used up, the atomic operation automaton converts the current first type of the target physical page back to the second type.
4. The method according to any one of claims 1-3, characterized in that, The first process manages the physical page metadata of each physical page through the dynamic radix tree, wherein the physical page metadata at different levels is used to manage physical memory of different sizes.
5. The method according to any one of claims 1-4, characterized in that, The first information also includes: The physical memory address of the physical page required by the second process; And / or, The virtual memory address that the second process needs to map.
6. The method according to claim 5, characterized in that, After releasing the control memory based on the second information, the method further includes: The second process is notified of the physical memory address of the required physical page and the virtual memory address mapped to the physical memory address.
7. The method according to any one of claims 1-6, characterized in that, The step of obtaining the first information transmitted by the second process includes: The first information passed by the second process is obtained through a system call.
8. The method according to any one of claims 1-7, characterized in that, After creating the control memory for the second process based on the dynamic radix tree, the method further includes: When the first permission is read-only or read-write, authentication is performed through the memory management unit (MMU) so that the second process can read the control memory as needed and / or write to the control memory as needed.
9. The method according to any one of claims 1-8, characterized in that, After creating the control memory for the second process based on the dynamic radix tree, the method further includes: If the first permission is read-only but there is a write requirement, the second process is triggered to enter the kernel through a system call and verify the legality of the operation, so that the second process can use or modify the control memory if the operation is legal.
10. The method according to claim 9, characterized in that, The legality of the inspection operation includes: The legality of the operation is verified through the MMU (Member of Authentication and Authorization).
11. A computer device, characterized in that, The computer device runs a first process in kernel mode and a second process in user mode. The computer device includes: The first creation module is used to set the status of the physical pages included in the computer device and create a dynamic radix tree based on the set status. A leaf node in the dynamic radix tree represents the physical page metadata corresponding to a physical page. The acquisition module is used to acquire the first information transmitted by the second process. The first information includes the second process requesting control memory of a first type, a first permission, and a first length from the kernel mode. The first type is a physical page type, the first permission is the permission required by the second process, and the control memory is a memory area used to control shared memory. Both the shared memory and the control memory belong to the physical memory of the computer device. The second creation module is used to create the control memory for the second process based on the dynamic radix tree when the first permission belongs to the target permission, so that the second process can operate on the control memory based on the first permission, wherein the target permission is the permission pre-configured for the first type in the kernel mode; The release module is used to obtain the second information transmitted by the second process and release the control memory according to the second information, wherein the second information includes the second process requesting the kernel mode to release the control memory.
12. The device according to claim 11, characterized in that, The computer device also includes: A type conversion module is used to convert the current second type of the target physical page to the first type through an atomic operation automaton in the kernel state after the acquisition module acquires the first information transmitted by the second process, when the type of the target physical page does not belong to the first type. The target physical page is one or more of the physical pages included in the computer device, and the target physical page belongs to the physical page required by the second process.
13. The device according to claim 12, characterized in that, The type conversion module is also used for: After the control memory is used up, the atomic operation automaton converts the current first type of the target physical page back to the second type.
14. The device according to any one of claims 11-13, characterized in that, The first process manages the physical page metadata of each physical page through the dynamic radix tree, wherein the physical page metadata at different levels is used to manage physical memory of different sizes.
15. The device according to any one of claims 11-14, characterized in that, The first information also includes: The physical memory address of the physical page required by the second process; And / or, The virtual memory address that the second process needs to map.
16. The device according to claim 15, characterized in that, The release module is also used for: After releasing the control memory based on the second information, the second process is notified to reclaim the physical memory address of the required physical page and the virtual memory address mapped by the physical memory address.
17. The device according to any one of claims 11-16, characterized in that, The acquisition module is specifically used for: The first information passed by the second process is obtained through a system call.
18. The device according to any one of claims 11-17, characterized in that, The second creation module is also used for: After creating the control memory for the second process based on the dynamic radix tree, if the first permission is read-only or read-write, authentication is performed through the memory management unit (MMU) so that the second process can read the control memory as needed and / or write to the control memory as needed.
19. The device according to any one of claims 11-18, characterized in that, The second creation module is also used for: After creating the control memory for the second process based on the dynamic radix tree, if the first permission is read-only but there is a write requirement, the second process is triggered to enter the kernel through a system call and verify the legality of the operation, so that the second process can use or modify the control memory if the operation is legal.
20. The device according to claim 19, characterized in that, The legality of the inspection operation includes: The legality of the operation is verified through the MMU (Member of Authentication and Authorization).
21. A computer device comprising a processor and a memory, the processor being coupled to the memory, characterized in that, The memory is used to store programs; The processor is configured to execute a program in the memory, causing the computer device to perform the method as described in any one of claims 1-10.
22. A computer storage medium, characterized in that, The device stores computer-readable instructions, which, when executed by a processor, implement the method as described in any one of claims 1-10.
23. A computer program product, characterized in that, The computer program product includes computer-readable instructions that, when executed by a processor, implement the method as described in any one of claims 1-10.
24. A chip, the chip comprising a processor and a data interface, characterized in that, The processor reads instructions stored in the memory through the data interface and executes the method as described in any one of claims 1-10.
Citation Information
Patent Citations
MPK technology-based inter-microkernel-module communication method and system, and medium
CN111949596A
Data interaction method and device for Linux kernel mode and user mode
CN114356598A
Memory management method and device, computer equipment and storage medium
CN116302491A
Shared memory processing method and device, computer equipment and storage medium
CN116302598A
Page Protection Layer
US20200081847A1