Data access method and related equipment
By mapping the virtual address space of kernel-mode data to the private or shared address space of user-mode, the problem of low cross-security domain data transmission performance is solved and efficient and secure data access is achieved.
Patent Information
- Application Number
- CN202310319097.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-21
- Publication Date
- 2024-09-24
AI Technical Summary
The existing cross-security domain data transmission mechanism has low performance, frequent system calls and data copy overhead, and cannot achieve efficient data transmission and secure access.
By mapping the virtual address space of kernel state data to the private or shared address space of user state, data copying between kernel state and user state is reduced, and the user state memory security mechanism and page attachment mechanism are used to achieve direct access and security protection of data. .
It improves data access efficiency, reduces system overhead, and achieves secure data access and high-performance transmission in user mode.
Smart Images

Figure CN118689795A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data access method and related equipment. Background Art
[0002] In traditional technology, data in computer systems are often stored in areas with different security levels. For example, data in the kernel state of the operating system is shared by all processes and protected by the kernel state hardware mechanism. The local data of the process in the user state is private and can only be accessed by the process itself. Data transmission across security domains is a frequent operation during the operation of computer systems. The data transmission mechanism across security domains generally has the following five requirements: shared data read consistency, local data modification isolation, shared data write consistency, limited access to shared data storage space, and high data transmission performance. Shared data read consistency means: shared domain data may be read by multiple processes at the same time, and the data transmission mechanism across security domains must ensure that the data read by different processes at the same time is consistent; local data modification isolation means: when data enters the process private domain from the shared domain, the process may modify the data, and the data transmission mechanism across security domains must ensure that the modifications after the data enters the process private domain are invisible to other processes holding the data; shared data write consistency means: when data successfully enters the shared domain from the process private domain, other processes can obtain the latest version of the data at the first time; restricted access to shared data storage space means: in order to protect the data in the shared domain from being tampered with at will, the data transmission mechanism across security domains must ensure that the process can only access the shared domain through established interfaces; high data transmission performance means: since data transmission across security domains is a frequently occurring operation, the data transmission mechanism across security domains must be as efficient as possible to reduce system overhead.
[0003] The existing cross-security domain data transmission mechanism generally implements cross-security domain data transmission by executing system calls. Data needs to be copied between the process private domain and the shared domain. The data transmission performance is poor and it will generate large system overhead. Summary of the invention
[0004] In view of this, it is necessary to provide a data access method that can solve the problem of low performance of existing cross-security domain data transmission.
[0005] A first aspect of an embodiment of the present application discloses a data access method, which is applied to an electronic device. The electronic device is installed with an operating system, and the operating system includes a user state and a kernel state. The data access method includes: in response to a request from a first process to access first data, obtaining a first virtual address space of the first data, a mapping relationship is established between the first virtual address space and the first physical address space, and the first data is located in the kernel state; allocating a second virtual address space to the first data, the second virtual address space being a part of a shared address space allocated to all processes in the user state or a part of a private address space allocated to the first process in the user state; establishing a mapping relationship between the first virtual address space and the second virtual address space; and accessing the first data based on the mapping relationship.
[0006] By adopting the above technical solution, when a first process accesses first data located in kernel state (for example, data located in page cache), the physical address space mapped by the first virtual address space of the first data is mapped to the private address space of the first process in user state, or mapped to the shared address space shared by all processes in user state, so that the first process can directly perform read or write operations on the first data in user state, which can reduce the copy overhead of data transmission between kernel state and user state, thereby avoiding the frequent system calls that exist in the prior art when accessing data located in kernel state, which can effectively reduce the system overhead when accessing data and improve data access efficiency.
[0007] In some embodiments, the data access method further includes: dividing a first part of the private address space from the private address space of each created process based on a preset division rule; and aggregating the first part of the private address space of each process to obtain a shared address space.
[0008] By adopting the above technical solution, a part of the private address space is divided from the private address space of each currently created process to form a shared address space shared by all processes. The shared address space is used as the "page cache" of the user state to establish a shared page table in the user state, so that each process can access the data in the shared domain without having to enter the kernel state through a system call to access the kernel page table.
[0009] In some embodiments, the data access method further includes: setting access rights for the shared address space based on a user-mode memory security mechanism.
[0010] By adopting the above technical solution, the access security of the shared address space is protected through the user-mode memory security mechanism, and the security of the data in the shared domain can be guaranteed without triggering a system call.
[0011] In some embodiments, access permissions are set for a shared address space based on a user-mode memory security mechanism, including: creating a shared page table for the shared address space; saving the access permissions of the shared page table in a memory protection key (MPK) permission register, and setting the access permissions of the shared page table to non-readable and non-writable in the MPK permission register.
[0012] By adopting the above technical solution, for the shared page table of the shared address space, the security of the shared page table is guaranteed by saving the access rights of the shared page table in the MPK permission register, and the access rights of the shared address space can be enabled or disabled by modifying the value of the MPK permission register in the user state.
[0013] In some embodiments, in response to a request from a first process to access first data, a first virtual address space of the first data is obtained, including: in response to the request from the first process to access the first data, the access permission of the shared page table is modified from non-readable and writable to readable and writable in the MPK permission register; if the first data exists, the first virtual address space of the first data is obtained; if the first data does not exist, the access permission of the shared page table is modified from readable and writable to non-readable and writable in the MPK permission register.
[0014] By adopting the above technical solution, when the first process accesses the first data, the access permission of the shared address space is first enabled by modifying the value of the MPK permission register, so that the first process can access the shared address space, which is convenient for the subsequent mapping of the physical address space mapped by the first virtual address space of the first data to the shared address space in the user state based on the page attachment mechanism. If the first data does not exist, it indicates that the access to the first data cannot be continued. In order to ensure the security of the shared address space, the access permission of the shared address space is closed again by modifying the value of the MPK permission register, so that each process cannot access the shared address space.
[0015] In some embodiments, after accessing the first data based on the mapping relationship, it also includes: modifying the access permission of the shared page table from readable and writable to non-readable and writable in the MPK permission register.
[0016] By adopting the above technical solution, after the first process completes access to the first data, in order to ensure the security of the shared address space, the access rights to the shared address space are closed by modifying the value of the MPK permission register, so that each process cannot access the shared address space.
[0017] In some embodiments, a mapping relationship between a first virtual address space and a second virtual address space is established, including: if the first process's access to the first data is a read operation, a mapping relationship between the first virtual address space and the second virtual address space is established, and the second virtual address space is a part of a private address space allocated to the first process in user mode; if the first process's access to the first data is a write operation, a mapping relationship between the first virtual address space and the second virtual address space is established, and the second virtual address space is a part of a shared address space.
[0018] By adopting the above technical scheme, if the first process's access to the first data is a read operation, by mapping the physical address space mapped by the first virtual address space of the first data to the private address space of the first process in the user state, the first process can directly read the first data in the user state, which can reduce the copy overhead of data transmission between the kernel state and the user state. If the first process's access to the first data is a write operation, by mapping the physical address space mapped by the first virtual address space of the first data to the shared address space shared by all processes in the user state, each process does not need to enter the kernel state through a system call to access the kernel page table, and can access the data in the shared domain, thereby avoiding the frequent system calls that exist in the prior art when accessing data in the kernel state, which can effectively reduce the system overhead when accessing data and improve the data access efficiency.
[0019] In some embodiments, accessing the first data based on the mapping relationship includes: if the access to the first data by the first process is a write operation, performing a write operation on the first data based on the mapping relationship and a copy-on-write mechanism.
[0020] By adopting the above technical solution, if the first process's access to the first data is a write operation, the copy overhead of data transmission between the shared domain and the process private domain can be reduced by mapping the physical address space mapped by the first virtual address space of the first data to the shared address space shared by all processes in the user state, and using the write-time copy mechanism to write the first data.
[0021] In some embodiments, establishing a mapping relationship between a first virtual address space and a second virtual address space includes: calling a page-attached interface in user mode to establish a mapping relationship between the first virtual address space and the second virtual address space, the input parameters of the page-attached interface include a source virtual address, a target virtual address, an address size of the source virtual address / target virtual address, and a mapping permission identifier, the address size of the source virtual address is the same as the address size of the target virtual address, and the mapping permission identifier includes access permission information for the source virtual address and / or the target virtual address.
[0022] By adopting the above technical scheme, the virtual address space can be divided into one or more virtual address segments, one virtual address segment can correspond to one virtual page, and a page dynamic mapping is established through a page-attached interface. The input parameters of the interface may include a target virtual address, a source virtual address, an address size, and a mapping permission identifier. The page-attached interface can be used to map the physical address mapped by the original virtual address to the target virtual address. The access rights of the target virtual address and the source virtual address can be configured as needed to achieve flexible permission control. After the dynamic mapping of the page is completed, the permission can be modified according to the input mapping permission identifier, including but not limited to readable and writable, read-only, and non-readable and writable.
[0023] In some embodiments, the first virtual address space and the second virtual address space both include N virtual pages, where N is a positive integer, and a mapping relationship between the first virtual address space and the second virtual address space is established, including: filling the mapping of the page table entries of each virtual page in the first virtual address space into the page table entries of each virtual page in the second virtual address space; and setting the access rights of each page table entry in the first virtual address space and each page table entry in the second virtual address space based on the mapping permission identifier.
[0024] By adopting the above technical scheme, the virtual address space can be divided into one or more virtual pages, and the physical address space can be divided into one or more physical pages. The mapping relationship between the first virtual address space and the second virtual address space can be established by filling the mappings in each page table entry of the source virtual address space (with the mappings of the physical pages) into each page table entry of the target virtual address space. After the mapping is established, the access rights of each page table entry in the first virtual address space and each page table entry in the second virtual address space can be set based on the mapping permission identifier to achieve flexible permission control.
[0025] In some embodiments, the mapping of page table entries of each virtual page in the first virtual address space is filled into the page table entries of each virtual page in the second virtual address space, including: obtaining the page table entry of the i-th page in the first virtual address space and the page table entry of the i-th page in the second virtual address space, i∈[1,N]; determining whether the mapping of the page table entry of the i-th page in the second virtual address space is empty; if the mapping of the page table entry of the i-th page in the second virtual address space is empty, filling the page table entry of the i-th page in the second virtual address space with the mapping in the page table entry of the i-th page in the first virtual address space; if the mapping of the page table entry of the i-th page in the second virtual address space is not empty, unmapping the page table entry of the i-th page in the second virtual address space, and filling the unmapped page table entry of the i-th page in the second virtual address space with the mapping in the page table entry of the i-th page in the first virtual address space.
[0026] By adopting the above technical scheme, the page table entries in the first virtual address space and the page table entries in the second virtual address space can be traversed starting from page 1. When it is determined that the mapping of the page table entry of a page in the second virtual address space is empty, the page table entry of the page is filled with the mapping in the page table entry of the corresponding page in the first virtual address space. When it is determined that the mapping of the page table entry of a page in the second virtual address space is not empty, the page table entry of the page is first demapped, and then the page table entry of the page is filled with the mapping in the page table entry of the corresponding page in the first virtual address space, thereby realizing the filling of the mapping in each page table entry of the source virtual address space into each page table entry of the target virtual address space.
[0027] In a second aspect, an embodiment of the present application provides a computer-readable storage medium, including computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the data access method described in the first aspect.
[0028] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, the memory is used to store instructions, and the processor is used to call the instructions in the memory, so that the electronic device executes the data access method described in the first aspect.
[0029] In a fourth aspect, an embodiment of the present application provides a computer program product. When the computer program product is executed on an electronic device (such as a computer), the electronic device executes the data access method described in the first aspect.
[0030] In a fifth aspect, a device is provided, wherein the device has the function of implementing the electronic device behavior in the method provided in the first aspect. The 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 functions.
[0031] It can be understood that the computer-readable storage medium described in the second aspect, the electronic device described in the third aspect, the computer program product described in the fourth aspect, and the device described in the fifth aspect all correspond to the method of the first aspect. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] Figure 1 A schematic diagram of the structure of an electronic device provided in one embodiment of the present application;
[0033] Figure 2 A schematic diagram of a software structure of an electronic device provided in one embodiment of the present application;
[0034] Figure 3 A schematic diagram of an application scenario of a data access method provided in an embodiment of the present application;
[0035] Figure 4 A schematic diagram of an architecture for implementing data access in an electronic device provided in an embodiment of the present application;
[0036] Figure 5 A schematic diagram of a process of accessing data by an electronic device according to an embodiment of the present application;
[0037] Figure 6 A schematic diagram of a flow chart of an electronic device providing an embodiment of the present application filling a mapping in a page table entry of a source virtual address into a page table entry of a target virtual address;
[0038] Figure 7 A schematic diagram of the architecture of file access by an APP provided in an embodiment of the present application;
[0039] Figure 8 A schematic diagram of a process of accessing a file based on a file system provided in an embodiment of the present application;
[0040] Fig. 9 A schematic diagram of the steps of a data access method provided in one embodiment of the present application. DETAILED DESCRIPTION
[0041] It should be noted that in this application, "at least one" means one or more, and "more than one" means two or more than two. "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. The terms "first", "second", "third", "fourth", etc. (if any) in the specification, claims and drawings of this application are used to distinguish similar objects, rather than to describe a specific order or sequence.
[0042] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0043] Operating System (OS): A computer program that manages computer hardware and software resources.
[0044] Kernel: It establishes a platform for communication between computer software and hardware. The kernel provides system services such as file management, virtual memory, and device input / output (I / O).
[0045] Process: It is an operation activity of a program with an independent function on a certain data set. The process is the basic unit of dynamic execution of the operating system. In the traditional operating system, the process is both the basic allocation unit and the basic execution unit. The process can be considered as an instance of a running program.
[0046] User state: also known as user space, the activity space of upper-level applications. The execution of applications depends on the resources provided by the kernel, such as CPU resources, storage resources, I / O resources, etc.
[0047] Kernel state: also known as kernel space, is used to control the computer's hardware resources and provide an environment for the running of upper-level applications.
[0048] Shared domain: The relationship between process and data is many-to-one, that is, multiple processes can access the same data. This type of data storage area is called a shared domain. Data can refer to numbers, text, images, files, or computer codes.
[0049] Private domain: The relationship between process and data is one-to-one, that is, the data is held by one process and can only be accessed by the process itself. This type of data storage area can be called a private domain.
[0050] System call: It is a means of communication between kernel space and user space. System call can be regarded as a set of "special interfaces" provided by the operating system for user programs to call. User programs can obtain system services provided by the operating system kernel through this set of "special interfaces". For example, users can request the system to open files, close files, or read and write files through file system related system calls. The fundamental reason why system services need to be provided to user space through system calls is to "protect" the system, because kernel space and user space run at different levels and are logically isolated from each other. Processes (running in user space) are usually not allowed to access kernel data or use kernel functions. They can only operate user data or call user functions. When a process needs to access kernel data (for example, access files), it uses the "special interface" provided by the system to the user, that is, to access kernel data through system calls. Specifically, the process's request is conveyed to the kernel. After the kernel space completes the request, the processing result is returned to the user space (equivalent to returning it to the process).
[0051] Security domain: An area where data is stored using different security policies. For example, a shared domain and a private domain can be called two different security domains.
[0052] Copy on write (COW): also known as copy on write, is an optimization strategy in the field of computer programming. Its core idea is: if multiple callers request the same resource at the same time, they will jointly obtain the same pointer to the same resource. Until a caller tries to modify the resource content, the system will actually copy a dedicated copy to the caller, while the original resource seen by other callers remains unchanged. This process is transparent to other callers. The main advantage of this approach is that if the caller does not modify the resource, no copy will be created, so multiple callers can share the same resource when they only read it.
[0053] File system: It is a method of storing and organizing computer data, which makes it easy to access and find computer data. The file system uses the abstract logical concepts of files and tree directories instead of the concept of data blocks used by physical devices such as hard disks and optical disks. Users use the file system to save data, and do not need to care about the address of the data block on the hard disk (or optical disk) where the data is actually saved. They only need to remember the directory and file name to which the file belongs. Before writing new data, users do not need to care about which block address on the hard disk is not in use. The storage space management (allocation and release, etc.) on the hard disk is automatically completed by the file system. Users only need to remember which file the data is written to.
[0054] Page table: used to store the correspondence between logical pages and physical page frames. The memory management unit (MMU) can use a multi-level page table to implement the index from virtual address to physical address.
[0055] Page fault: When the target page table entry being accessed is empty or marked as read-only, a page fault operation can be triggered to map a physical memory address to the corresponding page table entry.
[0056] Memory protection keys (MPK): A register is used in the CPU to save the access rights of the page table. The value of this register can be modified in user mode. Each page table entry can use two bits to record the key value (KEY) corresponding to the page table. Each time the page table is accessed, the KEY recorded in the page table entry is compared with the value in the register for authentication.
[0057] In order to solve the problem of low performance of existing cross-security domain data transmission, a feasible way is to map the data of the shared domain to the process private domain through system calls, so that the process can directly access the data of the shared domain through virtual addresses. For example, for data read operations, the data of the shared domain can be directly read through virtual addresses, and for data write operations, the data of the shared domain can be copied to a new page of the process private domain using the COW mechanism, and the write operation can be performed on the new page. This method enables different processes to read consistent data by mapping data to the private address space of different processes in a COW manner. At the same time, when a process writes to shared data (data in the shared domain), a page fault will be triggered, that is, the data is copied to the process private domain through the COW mechanism and then the write operation is performed, thereby ensuring the modification isolation of shared data between processes. Since data transmission across security domains is implemented based on the COW mechanism, the data transmission performance is efficient, but this method also has the following defects: the data in the process private domain cannot be synchronized to the shared domain through zero copy, that is, the write consistency of shared data cannot be achieved; all processes can access the shared domain without restriction, and the security of shared data cannot be guaranteed.
[0058] To solve the above technical problems, some embodiments of the present application provide a data access method. When a first process accesses first data located in the kernel state, the physical address space mapped to the first virtual address space of the first data is mapped to the private address space of the first process in the user state, or mapped to the shared address space shared by all processes in the user state, so that the first process can directly perform read or write operations on the first data in the user state, which can reduce the copy overhead of data transmission between the kernel state and the user state, can effectively reduce the system overhead when accessing data, and can improve data access efficiency.
[0059] The data access method provided in the embodiment of the present application can be applied to an electronic device, and the electronic device can communicate with other electronic devices or servers through a communication network. The electronic device of the present application may include a server or a terminal device. The terminal device includes but is not limited to a mobile phone, a foldable electronic device, a tablet computer, a personal computer (personal computer, PC), a laptop computer, a handheld computer, a notebook computer, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook, a cellular phone, a personal digital assistant (personal digital assistant, PDA), an augmented reality (augmented reality, AR) device, a virtual reality (virtual reality, VR) device, an artificial intelligence (artificial intelligence, AI) device, a wearable device, a smart home device, and at least one of smart city devices. The embodiment of the present application does not impose any special restrictions on the specific type of the electronic device. The communication network can be a wired network or a wireless network. For example, the communication network can be a local area network (local area networks, LAN) or a wide area network (wide area networks, WAN), such as the Internet. When the communication network is a local area network, exemplarily, the communication network may be a short-distance communication network such as a wireless fidelity (Wi-Fi) hotspot network, a Wi-Fi P2P network, a Bluetooth network, a Zigbee network, or a near field communication (NFC) network. When the communication network is a wide area network, exemplarily, the communication network may be a third-generation wireless telephone technology (3G) network, a fourth-generation mobile communication technology (4G) network, a fifth-generation mobile communication technology (5G) network, a future-evolved public land mobile network (PLMN) or the Internet.
[0060] In some embodiments, the electronic device may install one or more APPs (Applications). APP can be referred to as an application, which is a software program that can implement one or more specific functions. For example, communication applications, video applications, audio applications, image capture applications, cloud desktop applications, and the like. Among them, communication applications may include text messaging applications, for example. Image capture applications may include shooting applications (system cameras or third-party shooting applications). Video applications may include Huawei Video, for example. Audio applications may include Huawei Music. The applications mentioned in the following embodiments may be system applications installed on the electronic device when it leaves the factory, or they may be third-party applications downloaded from the Internet or obtained from other electronic devices by the user during the use of the electronic device.
[0061] Electronic equipment includes but is not limited to Windows Or other operating systems. Operating system or The operating system is used as an example for explanation.
[0062] Figure 1 A schematic structural diagram of an electronic device 10 is shown.
[0063] The electronic device 10 may include a processor 110, an external memory interface 120, an internal memory 121, an antenna 1, an antenna 2, a mobile communication module 130, a wireless communication module 140, an audio module 150, a sensor module 160, a camera module 170, a display screen 180, etc.
[0064] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 10. In other embodiments of the present application, the electronic device 10 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0065] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0066] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 may be a cache memory. The memory may store instructions or data that have been used or are frequently used by the processor 110. If the processor 110 needs to use the instructions or data, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0067] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc. The processor 110 may be connected to an audio module, a wireless communication module, a display, a camera, and other modules through at least one of the above interfaces.
[0068] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 10. In other embodiments of the present application, the electronic device 10 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0069] The wireless communication function of the electronic device 10 can be implemented through the antenna 1, the antenna 2, the mobile communication module 130, the wireless communication module 140, the modem processor and the baseband processor.
[0070] The mobile communication module 130 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to the electronic device 10. The mobile communication module 130 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. In some embodiments, at least some functional modules of the mobile communication module 130 may be set in the processor 110. In some embodiments, at least some functional modules of the mobile communication module 130 may be set in the same device as at least some modules of the processor 110.
[0071] The wireless communication module 140 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), Bluetooth low energy (BLE), ultra wide band (UWB), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the electronic device 10. The wireless communication module 140 can be one or more devices integrating at least one communication processing module.
[0072] In some embodiments, the electronic device 10 can communicate with the network and other electronic devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS may include global positioning system (GPS), global navigation satellite system (GLONASS), Beidou navigation satellite system (BDS), quasi-zenith satellite system (QZSS) and / or satellite based augmentation system (SBAS).
[0073] The electronic device 10 can realize the display function through a GPU, a display screen 180, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 180 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
[0074] The camera module 170 includes a camera. The display screen 180 is used to display images, videos, etc. The display screen 180 can be a touch screen. The display screen 180 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light emitting diode (QLED), etc. In some embodiments, the electronic device 10 may include one or more display screens 180.
[0075] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 10. The external memory card communicates with the processor 110 via the external memory interface 120 to implement a data storage function.
[0076] The internal memory 121 can be used to store computer executable program codes, which include instructions. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device 10, etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional methods or data processing of the electronic device 10 by running instructions stored in the internal memory 121, and / or instructions stored in a memory provided in the processor.
[0077] The audio module 150 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 150 can also be used to encode and decode audio signals. In some embodiments, the audio module 150 can be arranged in the processor 110, or some functional modules of the audio module 150 can be arranged in the processor 110.
[0078] The software system of the electronic device 10 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 10.
[0079] Figure 2 It is a software structure block diagram of the electronic device 10 according to an embodiment of the present application.
[0080] The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers, from top to bottom: application layer, application framework layer, Android runtime (ART) and native C / C++ library, hardware abstract layer (HAL) and kernel layer.
[0081] The application layer can include a series of application packages.
[0082] like Figure 2 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
[0083] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0084] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a resource manager, a notification manager, an activity manager, an input manager, and the like.
[0085] The window manager provides window management services (WMS). WMS can be used for window management, window animation management, surface management, and as a transfer station for the input system.
[0086] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0087] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0088] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0089] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0090] The activity manager can provide activity management services (AMS), which can be used to start, switch, and schedule system components (such as activities, services, content providers, and broadcast receivers) as well as manage and schedule application processes.
[0091] The input manager can provide input management services (IMS), which can be used to manage system input, such as touch screen input, key input, sensor input, etc. IMS takes events from input device nodes and distributes them to appropriate windows through interaction with WMS.
[0092] The Android runtime includes the core library and the Android runtime. The Android runtime is responsible for converting source code into machine code. The Android runtime mainly uses the ahead of time (AOT) compilation technology and the just in time (JIT) compilation technology.
[0093] The core library is mainly used to provide basic Java class library functions, such as basic data structures, mathematics, IO, tools, databases, networks, etc. The core library provides an API for users to develop Android applications.
[0094] The native C / C++ library can include multiple functional modules, such as surface manager, media framework, libc, OpenGL ES, SQLite, Webkit, etc.
[0095] Among them, the surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. The media framework supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc. OpenGL ES provides drawing and operation of 2D graphics and 3D graphics in applications. SQLite provides a lightweight relational database for applications of electronic device 10.
[0096] The hardware abstraction layer runs in user space, encapsulates kernel layer drivers, and provides a calling interface to the upper layer.
[0097] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0098] Combine the following Figure 3 , a schematic diagram of an application scenario that exemplarily introduces the data access method.
[0099] In this embodiment, the electronic device 10 is introduced by taking a mobile phone as an example. In this embodiment, the electronic device 10 is installed with an operating system. The electronic device 10 is also installed with one or more APPs. After the user clicks on an APP, the electronic device 10 can create a corresponding application process, and the application process can implement various functions of the corresponding APP. For example, when the user clicks on the Huawei Video APP icon, the electronic device creates a process of the Huawei Video APP, and the user can use the process of the Huawei Video APP to realize functions such as watching videos online in full screen or watching videos offline.
[0100] During the operation of Huawei Video APP, there may be a need for data access (read data / write data). The existing file system uses the page cache in the kernel to accelerate data access. The data will be copied and transmitted between the process private domain and the page cache. The data copy occupies a large amount of system resources, which has a great impact on system performance and affects the user experience. The electronic device 10 using the data writing method provided in the embodiment of the present application can achieve shared data (such as data in the page cache) read consistency, local data modification isolation, shared data write consistency, limited access to shared data storage space, and high performance of data transmission. The electronic device 10 supports mapping data in a shared domain in kernel state to a process private domain in user state, and supports mapping data in a process private domain to a shared domain through a page attachment mechanism, thereby reducing the copy overhead of data transmitted between the shared domain and the process private domain. By establishing a shared page table in user state, each process can access data in the shared domain without entering the kernel page table through a system call, and adopts a user state memory security mechanism to provide a lightweight protection mechanism for the shared page table, allowing a process to obtain access rights to the shared page table by modifying the value of the MPK permission register in user state, thereby reducing the overhead of system calls and ensuring the security of data in the shared domain.
[0101] Combine the following Figure 4 , exemplarily introduces an architectural diagram of an electronic device implementing data access provided by an embodiment of the present application.
[0102] In this embodiment, the operating system installed in the electronic device 10 may include a user state and a kernel state. One or more APPs may be run in the user state, and the user state may also include the following software modules: a storage service module 101, a page table security mechanism module 102, a shared page table 103, and a system call interface 104. The storage service module 101 may be used to provide data storage services for the processes of each APP, for example, the storage service module 101 may provide file system storage services, object storage services, etc. Each process may divide a portion of the private address space from its own private address space (also referred to as the user state address space) to form a shared address space. The private address space of a process is the virtual address space private to the process. The electronic device 10 may obtain a shared address space by aggregating a portion of the private address space divided from each process, and create a corresponding shared page table 103 for the shared address space, and the shared page table 103 is shared by all processes, so that the storage service module 101 may operate the data on the shared address space in the user state. The page table security mechanism module 102 is used to ensure the access security of the shared page table, for example, the page table security mechanism module 102 may achieve access security of the shared page table by providing a user state memory security mechanism. The user-mode memory security mechanism can be selected according to the implementation requirements, but it is necessary to ensure that the hardware device (such as memory) of the electronic device 10 can support it, for example, the user-mode memory security mechanism is the MPK mechanism. The system call interface 104 is used to provide a system call interface. Each process can initiate a system call through the system call interface 104 to pass the data processing request to the kernel to call the corresponding kernel function to complete the required processing.
[0103] In some embodiments, the private address space to be divided for each process or the division rule of the private address space may be predefined, and this application does not limit this. For example, after the first process is created, a part of the private address space may be divided based on the division rule, and the electronic device 10 may aggregate the part of the private address space divided from the private address space of the first process into the shared address space to implement the update of the shared address space.
[0104] The kernel state may include the following software modules: a system call security mechanism module 105, a virtual address management module 106, a page attachment mechanism module 107, and a driver module 108. The system call security mechanism module 105 is used to provide system calls for processes in the user state. The processes in the user state can use kernel functions (such as calling kernel functions) through system calls. The system call security mechanism module 105 ensures the security of accessing shared data in the kernel state by switching between user state page tables and kernel state page tables. The virtual address management module 106 is used to provide and manage virtual address space. When a process triggers access to a virtual address, the MMU can parse the page table to find the physical address corresponding to the virtual address. If the physical address does not exist, a page fault operation will be triggered. If the physical address exists, the corresponding data will be accessed based on the physical address. The driver module 108 is used to provide management of hardware devices, for example, including establishing a mapping between logical blocks and physical blocks, a processing mechanism for page fault operations, etc. The page attachment mechanism module 107 is used to implement dynamic page mapping (supporting mapping from a shared domain to a process private domain and mapping from a process private domain to a shared domain), so that data can be transferred between a process private domain and a page cache in a zero-copy manner. By exposing a page attachment interface (also referred to as an attach interface) to the user state for use by the user state, the user state process can map the physical address of the physical page mapped by the first segment of the virtual address space to the second segment of the virtual address space through the attach interface, and can set or modify the access rights of the target virtual address (the second segment of the virtual address space) and the source virtual address (the first segment of the virtual address space) according to actual needs. For example, the first segment of the virtual address space is a segment of the virtual address space in the private address space of the process, and the second segment of the virtual address space is a segment of the virtual address space in the shared address space.
[0105] The embodiments of the present application construct a shared address space in user state by aggregating part of the private address space of each process, and utilize the user state memory security mechanism to ensure the security of the shared address space, thereby ensuring the security of shared data without triggering a system state switch (switching between user state and kernel state), and realizing zero-copy transmission of data between the private address space of a process and the page cache through dynamic page mapping, while flexibly configuring page access permissions (for example, configurable as readable and writable, read-only, write-only, non-readable and writable, etc.).
[0106] For example, for a process's read operation on the first shared data, the physical address space mapped to the virtual address space of the first shared data (the physical address space includes one or more physical pages for storing the first shared data) can be mapped to a certain segment of virtual address space in the private address space of the process (the size of the segment of virtual address space is the same as the size of the virtual address space of the first shared data), so that the process can read the first shared data in user mode and the read consistency of the first shared data can be guaranteed. For a process's write operation on the second shared data, the physical address space mapped to the virtual address space of the second shared data (the physical address space includes one or more physical pages for storing the second shared data) can be mapped to a certain segment of virtual address space in the shared address space (the size of the segment of virtual address space is the same as the size of the virtual address space of the second shared data), and then a write operation is performed on the second shared data based on the COW mechanism, so that the process can write to the second shared data in user mode and the write consistency of the second shared data can be guaranteed.
[0107] In some embodiments, the page dependency mechanism module 107 may be implemented in the virtual address management module 106 and the driver module 108 , that is, the page dependency mechanism module 107 may be partially integrated in the virtual address management module 106 and the other part integrated in the driver module 108 .
[0108] Reference Figure 5 As shown, a schematic diagram of a flow chart of data access by an electronic device provided by an embodiment of the present invention is exemplarily introduced.
[0109] In this embodiment, the user state memory security mechanism is an MPK mechanism as an example for explanation. The data access process may include the following steps, the order of some steps in the following steps may be changed, and some steps may be executed in parallel:
[0110] S50 , in response to a request from the first process to access the first data, initializing a shared page table.
[0111] In some embodiments, the first process may refer to the process of the first APP, and the first APP may be an e-commerce application, a browser application, a video application, an instant messaging application, etc., which is not limited in this application. The first data may refer to data located in a shared domain in kernel state. For example, the first data may refer to data on a page cache. Initializing a shared page table may refer to creating a shared page table accessible to all processes in user state. A portion of the private address space may be divided out from the private address space of each process and aggregated into a shared address space. For the private address space divided out from each process, a corresponding page table may be created, and the page table is configured to be shared by all processes (also referred to as a shared page table), and all processes may access it. The first process accessing the first data may refer to a read operation on the first data, or a write operation on the first data.
[0112] S51, initialize the user state memory security mechanism.
[0113] In some embodiments, initializing the user-mode memory security mechanism may mean saving the access rights of the shared page table in the MPK permission register, setting the access rights of the shared page table to be non-readable and non-writable, and each subsequent time the process accesses the shared page table, it is necessary to compare the KEY recorded in the page table entry with the value in the register for authentication.
[0114] S52, enable access rights to the shared address space.
[0115] In some embodiments, the access rights (read / write rights) of the shared address space can be enabled by modifying the value of the MPK permission register in user mode. For example, the access rights of the shared address space stored in the MPK permission register can be set from non-readable and writable to readable and writable, so that the shared address space can be accessed. If the access rights of the shared address space are not enabled, since the access rights of the shared address space are non-readable and writable, a segmentation fault will be triggered when a process accesses the shared address space.
[0116] S53: Obtain a page index of the first data.
[0117] In some embodiments, the page index may refer to an index of a virtual page, and the virtual address may be divided into a page index and an offset relative to the page head address. The page index of the first data may be obtained based on the virtual address of the first data. After obtaining the page index of the first data, each virtual page corresponding to the first data may be determined based on the page index of the first data.
[0118] S54, performing a page attachment operation on the virtual page of the first data, so that the first process can access the first data.
[0119] In some embodiments, performing a page attachment operation on a virtual page of the first data may include attaching the virtual page of the first data to a private address space of the first process, or to a shared address space. If the virtual page of the first data is mapped to the private address space of the first process, the first process can read the first data in user mode. Since a mapping relationship is established between the virtual page of the first data and the physical page, after mapping the virtual page of the first data to the private address space of the first process, the first process can directly read the first data in user mode. If the virtual page of the first data is mapped to a shared address space, the first process can perform a write operation on the first data based on the COW mechanism. Since the virtual page of the first data is attached to the shared address space, the shared address space is shared by all processes, so that other processes can obtain the latest version of the first data at the first time, that is, achieve write consistency of the first data.
[0120] In some embodiments, a page attachment operation may refer to mapping a physical address mapped by a source virtual address to a target virtual address, which is implemented by copying the physical address in the page table entry of the source virtual address to the page table entry of the target virtual address. The page attachment operation may include four input parameters: a source virtual address, a target virtual address, an address size, and a mapping permission identifier. Among them, the source virtual address is the same size as the target virtual address, the address size may be the size of the source virtual address or the size of the target virtual address, and the mapping permission identifier includes access permission information for the source virtual address and / or the target virtual address.
[0121] like Figure 6 As shown, assuming that both the source virtual address and the target virtual address include N virtual pages, where N is a positive integer, the following steps can be used to fill the mapping (mapped physical address) in the page table entry of the source virtual address into the page table entry of the target virtual address:
[0122] S60, obtaining the page table entry of the i-th page in the source virtual address and the page table entry of the i-th page in the target virtual address (i starts from 1, i∈[1,N]).
[0123] S61, determining whether the mapping of the page table entry of the i-th page of the target virtual address is empty.
[0124] S62, if the mapping of the page table entry of the i-th page of the target virtual address is empty (ie, there is no physical address mapping of the physical page), fill the page table entry of the i-th page of the target virtual address with the mapping in the page table entry of the i-th page of the source virtual address.
[0125] For example, if it is determined that the mapping of the page table entry of page 1 of the target virtual address is empty, the physical address in the page table entry of page 1 of the source virtual address is copied to the page table entry of page 1 of the target virtual address, that is, the page table entry of page 1 of the target virtual address is filled with the mapping in the page table entry of page 1 of the source virtual address.
[0126] S63, if the mapping of the page table entry of the i-th page of the target virtual address is not empty (that is, the physical address mapping of the physical page already exists), unmap the page table entry of the i-th page of the target virtual address, and fill the unmapped page table entry of the i-th page of the target virtual address with the mapping in the page table entry of the i-th page of the source virtual address.
[0127] In some embodiments, if it is determined that the mapping of the page table entry of the i-th page of the target virtual address is not empty, it indicates that the page table entry of the i-th page of the target virtual address already has a physical address mapping of the physical page. By unmapping the page table entry of the i-th page of the target virtual address, the mapping of the page table entry of the i-th page of the target virtual address is made empty, and then the page table entry of the i-th page of the target virtual address is filled with the mapping in the page table entry of the i-th page of the source virtual address.
[0128] In some embodiments, the operation of unmapping the page table entry of the i-th page of the target virtual address further includes: reducing the number of references of the physical page originally mapped to the i-th page of the target virtual address by one.
[0129] S64, setting access permissions for the page table entry of the i-th page in the source virtual address and the page table entry of the i-th page in the target virtual address according to the mapping permission identifier.
[0130] For example, the access rights may include readable and writable, read-only, unreadable and writable, etc. In the embodiment of the present application, by repeatedly executing steps S60 to S64, the mapping in each page table entry in the source virtual address is filled into each page table entry of the target virtual address.
[0131] S55, close the access permission of the shared address space.
[0132] In some embodiments, after the first process accesses the first data, the access rights of the shared address space are closed so that each process cannot access the shared address space to improve the security of the shared address space. For example, the access rights of the shared address space can be closed by modifying the value of the MPK permission register in the user state, and the shared address space access rights stored in the MPK permission register are modified from readable and writable to non-readable and writable.
[0133] Combine the following Figure 7 , which exemplarily introduces the architectural diagram of an APP provided in an embodiment of the present application for accessing files based on a file system.
[0134] In this embodiment, the optimization of the file system using the page attachment mechanism and the user state memory security mechanism is used as an example for explanation. Multiple APPs can be installed on the electronic device 10, and the processes of each APP access the file data and file metadata stored in the memory through the file system. The file system may include a page attachment mechanism, a user state memory security mechanism, a data management module and a metadata management module. The data management module is used to manage file data, and the metadata management module is used to manage file metadata. The user state memory security mechanism allows the process to modify the value of the MPK permission register in the user state to obtain access to the shared address space. Compared with the existing file system that needs to operate the file metadata of the file data through system calls, the overhead of system calls can be reduced, and the security of the data in the shared domain can be guaranteed. The page attachment mechanism can realize zero-copy transmission of file data between the page cache in the user state and the kernel state. Compared with the existing file system that only uses the page cache in the kernel to accelerate file data access (file data needs to be transferred between the page cache in the user state and the kernel state by copying), the transmission performance of file data can be improved and the overhead of system copying file data can be reduced.
[0135] like Figure 8 As shown, the electronic device can implement file access based on the following steps:
[0136] S80: In response to a request from the first process to access the first file, enable access rights to the shared address space.
[0137] In some embodiments, the value of the MPK permission register can be modified based on the user-state memory security mechanism to obtain access rights to the shared address space. For example, the access rights to the shared address space stored in the MPK permission register can be changed from non-readable and writable to readable and writable, so that the shared address space can be accessed.
[0138] S81, determining whether the first file exists in the shared domain.
[0139] In some embodiments, it is possible to find out whether the first file exists in the shared domain through an identifier of the first file (eg, file name, extension, path, etc.).
[0140] S82: If the first file does not exist, close the access permission of the shared address space.
[0141] In some embodiments, if the first file does not exist, indicating that the first file cannot be accessed, the first process can output a preset prompt message, for example, the preset prompt message is information indicating that the first file does not exist. After determining that the first file does not exist, in order to ensure the security of the shared address space, the access rights of the shared address space must be closed so that each process cannot access the shared address space. For example, the access rights of the shared address space stored in the MPK permission register can be reset from readable and writable to non-readable and writable, so that the shared address space cannot be accessed.
[0142] S83: If the first file exists, create a file handle for the first file.
[0143] In some embodiments, if the first file exists, the operating system may allocate a file handle to the first file requested to be accessed by the first process. The file handle may be represented by a number, for example, the file handle may be: fd0, fd1 or fd2. The file handle is the only basis for the first process to identify the first file during the process of reading / writing the first file.
[0144] S84, determining a page index of the first file based on the file handle of the first file.
[0145] After the file handle of the first file is obtained, the page index of the first file may be searched based on the file handle of the first file.
[0146] S85, obtaining a virtual address of the Mth virtual page in the first file based on the page index of the first file (M is traversed starting from 1).
[0147] In some embodiments, each time a virtual address of a virtual page is found, the virtual address of the virtual page may be passed to step S86 or step S87 for processing until the virtual addresses of all virtual pages of the first file have been processed. For example, when the virtual address of the first virtual page in the first file is obtained, the virtual address of the first virtual page is passed to step S86 or step S87 for processing.
[0148] S86: If the first file is to be read, the physical address of the physical page mapped by the virtual address of the Mth virtual page is mapped to the private address space of the first process to read the first file.
[0149] In some embodiments, if a read operation is performed on the first file, the physical addresses of the physical pages mapped by the virtual addresses of each virtual page in the first file are mapped to the private address space of the first process, so that the first process can read the first file in user mode, thereby achieving read consistency.
[0150] In some embodiments, the page attachment operation includes four input parameters: a source virtual address (the virtual address of the Mth virtual page), a target virtual address (the virtual address of a virtual page in the private address space of the first process), an address size, and a mapping permission identifier. The mapping permission identifier includes access permission information for the source virtual address and / or the target virtual address. After mapping the physical address of the physical page mapped by the virtual address of the Mth virtual page to the private address space of the first process, the access permissions of the source virtual address and the target virtual address may also be set according to the mapping permission identifier.
[0151] In some embodiments, after the read operation on the first file is completed, in order to ensure the security of the shared address space, the access rights of the shared address space need to be closed so that each process cannot access the shared address space.
[0152] S87, if the write operation is performed on the first file, the physical address of the physical page mapped by the virtual address of the Mth virtual page is mapped to the shared address space, and the write operation is performed on the first file based on the COW mechanism.
[0153] In some embodiments, if a write operation is performed on the first file, the physical address of the physical page mapped by the virtual address of the Mth virtual page can be mapped to the shared address space. Since the shared address space is shared by all processes, other processes can obtain the latest version of the first file at the first time to achieve write consistency. For example, a write operation on the first file will trigger a COW page fault, and a COW copy of the first file is created using the COW mechanism, and the write operation is performed on the COW copy.
[0154] In some embodiments, the page attachment operation includes four input parameters: a source virtual address (the virtual address of the Mth virtual page), a target virtual address (the virtual address of a virtual page in the shared address space), an address size, and a mapping permission identifier. The mapping permission identifier includes access permission information for the source virtual address and / or the target virtual address. After mapping the physical address of the physical page mapped by the virtual address of the Mth virtual page to the shared address space, the access permissions of the source virtual address and the target virtual address may also be set according to the mapping permission identifier.
[0155] In some embodiments, after the write operation to the first file is completed, in order to ensure the security of the shared address space, the access rights to the shared address space need to be closed so that each process cannot access the shared address space.
[0156] Reference Fig. 9 As shown, an embodiment of the present application provides a data access method, which is applied to an electronic device 10. In this embodiment, the data access method may include:
[0157] Step S91, in response to a request from a first process to access first data, obtaining a first virtual address space of the first data.
[0158] In some embodiments, the first process may refer to the process of the first APP, and the first APP may be an e-commerce application, a browser application, a video application, an instant messaging application, etc., which is not limited in this application. During the operation of the first APP, there may be a need to access the first data. The electronic device 10 can respond to the request of the first process to access the first data and obtain the first virtual address space of the first data. The first data may refer to data located in a shared domain in the kernel state. A mapping relationship is established between the first virtual address space and the first physical address space, and the physical page corresponding to the first physical address space is used to store the first data.
[0159] Step S92: allocate a second virtual address space for the first data.
[0160] In some embodiments, the second virtual address space is a portion of a shared address space allocated to all processes in the user state or a portion of a private address space allocated to the first process in the user state. The size of the second virtual address space is the same as the size of the first virtual address space. For example, if the first process accesses the first data as a read operation, the second virtual address space is a portion of the private address space allocated to the first process in the user state; if the first process accesses the first data as a write operation, the second virtual address space is a portion of the shared address space allocated to all processes in the user state.
[0161] In some embodiments, a first part of the private address space can be divided from the private address space of each created process based on a preset division rule, and a shared address space is obtained by aggregating the first part of the private address space of each process. The preset division rule can be set according to actual needs, and this application is not limited to this. For the shared address space, access rights can be set for the shared address space based on the user state memory security mechanism to ensure the access security of the shared address space. For example, by creating a shared page table for the shared address space, saving the access rights of the shared page table to the MPK permission register, and setting the access rights of the shared page table to non-readable and non-writable in the MPK permission register, the access security of the shared address space is ensured. The value of the MPK permission register supports modification in the user state, so that the access rights of the shared address space can be turned on or off by modifying the value of the MPK permission register.
[0162] In some embodiments, the electronic device 10 may modify the access rights of the shared page table from non-readable and writable to readable and writable in the MPK permission register in response to a request from the first process to access the first data, so that the first process can access the shared address space, which is convenient for the subsequent mapping of the physical address space mapped by the first virtual address space of the first data to the shared address space in the user state based on the page attachment mechanism. If it is determined that the first data does not exist, it indicates that the access to the first data cannot be performed. In order to ensure the security of the shared address space, the access rights to the shared address space can be closed by modifying the value of the MPK permission register (from readable and writable to non-readable and writable), so that each process cannot access the shared address space. If it is determined that the first data exists, after the first process completes the access to the first data, in order to ensure the security of the shared address space, it is also necessary to modify the value of the MPK permission register (from readable and writable to non-readable and writable) to close the access rights to the shared address space, so that each process cannot access the shared address space.
[0163] Step S93: establishing a mapping relationship between the first virtual address space and the second virtual address space.
[0164] In some embodiments, if the first process accesses the first data as a read operation, a mapping relationship between the first virtual address space and the second virtual address space is established, and the second virtual address space is a part of the private address space allocated to the first process in the user state. If the first process accesses the first data as a write operation, a mapping relationship between the first virtual address space and the second virtual address space is established, and the second virtual address space is a part of the shared address space.
[0165] In some embodiments, a page-attached interface can be called in user mode to establish a mapping relationship between a first virtual address space and a second virtual address space. The input parameters of the page-attached interface may include a source virtual address, a target virtual address, an address size of the source virtual address / target virtual address, and a mapping permission identifier. The address size of the source virtual address is the same as the address size of the target virtual address. The mapping permission identifier includes access permission information for the source virtual address and / or the target virtual address, which can be pre-set according to actual needs.
[0166] Taking the example that both the first virtual address space and the second virtual address space include N pages (N is a positive integer) of virtual pages, establishing a mapping relationship between the first virtual address space and the second virtual address space can specifically include: filling the mapping of the page table entries of each virtual page in the first virtual address space into the page table entries of each virtual page in the second virtual address space; setting the access rights of each page table entry in the first virtual address space and each page table entry in the second virtual address space based on the mapping permission identifier, and the access rights include but are not limited to readable and writable, read-only, non-readable and writable, etc.
[0167] In some embodiments, the mapping in each page table entry of the source virtual address space can be filled into each page table entry of the target virtual address space in the following manner: obtain the page table entry of the i-th page in the first virtual address space and the page table entry of the i-th page in the second virtual address space, i∈[1,N]; determine whether the mapping of the page table entry of the i-th page in the second virtual address space is empty; if the mapping of the page table entry of the i-th page in the second virtual address space is empty, fill the page table entry of the i-th page in the second virtual address space with the mapping in the page table entry of the i-th page in the first virtual address space; if the mapping of the page table entry of the i-th page in the second virtual address space is not empty, unmap the page table entry of the i-th page in the second virtual address space, and fill the unmapped page table entry of the i-th page in the second virtual address space with the mapping in the page table entry of the i-th page in the first virtual address space.
[0168] Step S94: access the first data based on the mapping relationship.
[0169] In some embodiments, if the first process accesses the first data as a read operation, after mapping the physical address space mapped by the first virtual address space to the private address space of the first process, the first process can directly read the first data in the user state. If the first process accesses the first data as a write operation, after mapping the physical address space mapped by the first virtual address space to the shared address space shared by all processes, the first data can be written using the copy-on-write mechanism, which can reduce the copy overhead of data transmission between the shared domain and the process private domain.
[0170] In the electronic device 10 provided in the embodiment of the present application, the internal memory 121 can be used to store instructions, and the processor 110 can be used to call the instructions in the internal memory 121, so that the electronic device 10 executes the above-mentioned related method steps to implement the data access method in the above-mentioned embodiment.
[0171] An embodiment of the present application further provides a computer storage medium, in which computer instructions are stored. When the computer instructions are executed on the electronic device 10, the electronic device 10 executes the above-mentioned related method steps to implement the data access method in the above-mentioned embodiment.
[0172] The embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the above-mentioned related steps to implement the data access method in the above-mentioned embodiment.
[0173] In addition, an embodiment of the present application also provides a device, which can specifically be a chip, component or module, and the device may include a connected processor and memory; wherein the memory is used to store computer-executable instructions, and when the device is running, the processor can execute the computer-executable instructions stored in the memory so that the chip executes the data access method in the above-mentioned method embodiments.
[0174] Among them, the computer storage medium, computer program product or chip provided in the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0175] Through the description of the above implementation methods, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The module referred to in the embodiments of the present application can refer to a series of computer program instruction segments that can complete specific functions, or it can be a functional module formed by the cooperation of computer program instruction segments and hardware.
[0176] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are schematic. For example, the division of the modules or units is a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0177] The units described as separate components may or may not be physically separated, and the components shown as units may be one physical unit or multiple physical units, that is, they may be located in one place or distributed in multiple different places. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0178] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0179] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a 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 software product is stored in a storage medium, including a number of instructions to enable a device (which can be a single-chip microcomputer, chip, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), disk or optical disk and other media that can store program code.
[0180] The above description is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application.
Claims
1. A data access method, applied to an electronic device, wherein the electronic device is installed with an operating system, wherein the operating system includes a user state and a kernel state, wherein: The method comprises: In response to a request from a first process to access first data, a first virtual address space of the first data is acquired, a mapping relationship is established between the first virtual address space and a first physical address space, and the first data is located in the kernel state; Allocate a second virtual address space for the first data, where the second virtual address space is a part of a shared address space allocated to all processes in the user state or a part of a private address space allocated to the first process in the user state; Establishing a mapping relationship between the first virtual address space and the second virtual address space; The first data is accessed based on the mapping relationship.
2. The data access method according to claim 1, characterized in that: The method further comprises: Based on a preset partitioning rule, a first part of the private address space is partitioned from the private address space of each created process; The first part of the private address space of each process is aggregated to obtain the shared address space.
3. The data access method according to claim 2, characterized in that: The method further comprises: Access permissions are set for the shared address space based on a user-mode memory security mechanism.
4. The data access method according to claim 3, characterized in that: The step of setting access rights for the shared address space based on the user state memory security mechanism includes: Creating a shared page table for the shared address space; The access rights of the shared page table are saved in a memory protection key MPK permission register, and the access rights of the shared page table are set to be non-readable and non-writable in the MPK permission register.
5. The data access method according to claim 4, characterized in that: The step of obtaining a first virtual address space of the first data in response to a request by the first process to access the first data includes: In response to a request by the first process to access the first data, modifying the access permission of the shared page table from non-readable and writable to readable and writable in the MPK permission register; If the first data exists, obtaining a first virtual address space of the first data; If the first data does not exist, the access permission of the shared page table is modified from readable and writable to non-readable and writable in the MPK permission register.
6. The data access method according to claim 5, characterized in that: After accessing the first data based on the mapping relationship, the method further includes: The access permission of the shared page table is modified from readable and writable to non-readable and writable in the MPK permission register.
7. The data access method according to any one of claims 2 to 6, characterized in that: The establishing a mapping relationship between the first virtual address space and the second virtual address space includes: If the access of the first process to the first data is a read operation, a mapping relationship between the first virtual address space and the second virtual address space is established, where the second virtual address space is a part of the private address space allocated to the first process in the user state; If the access of the first process to the first data is a write operation, a mapping relationship between the first virtual address space and the second virtual address space is established, and the second virtual address space is a part of the shared address space.
8. The data access method according to claim 7, characterized in that: The accessing the first data based on the mapping relationship includes: If the access of the first process to the first data is a write operation, a write operation is performed on the first data based on the mapping relationship and the copy-on-write mechanism.
9. The data access method according to claim 7, characterized in that: The establishing a mapping relationship between the first virtual address space and the second virtual address space includes: A mapping relationship between the first virtual address space and the second virtual address space is established by calling a page attachment interface in user mode. The input parameters of the page attachment interface include a source virtual address, a target virtual address, an address size of the source virtual address / target virtual address, and a mapping permission identifier. The address size of the source virtual address is the same as the address size of the target virtual address. The mapping permission identifier includes access permission information of the source virtual address and / or the target virtual address.
10. The data access method according to claim 9, characterized in that: The first virtual address space and the second virtual address space both include N virtual pages, where N is a positive integer, and the establishing of a mapping relationship between the first virtual address space and the second virtual address space includes: Filling the mapping of the page table entries of each virtual page in the first virtual address space into the page table entries of each virtual page in the second virtual address space; The access rights of each page table entry in the first virtual address space and each page table entry in the second virtual address space are set based on the mapping permission identifier.
11. The data access method according to claim 10, characterized in that: The step of filling the mapping of the page table entries of each virtual page in the first virtual address space into the page table entries of each virtual page in the second virtual address space comprises: Obtain a page table entry of the i-th page in the first virtual address space and a page table entry of the i-th page in the second virtual address space, i∈[1,N]; Determine whether a mapping of a page table entry of the i-th page in the second virtual address space is empty; If the mapping of the page table entry of the i-th page in the second virtual address space is empty, fill the page table entry of the i-th page in the second virtual address space with the mapping in the page table entry of the i-th page in the first virtual address space; If the mapping of the page table entry of the i-th page in the second virtual address space is not empty, unmap the page table entry of the i-th page in the second virtual address space, and fill the unmapped page table entry of the i-th page in the second virtual address space with the mapping in the page table entry of the i-th page in the first virtual address space.
12. A computer-readable storage medium, characterized in that: The method comprises computer instructions, and when the computer instructions are executed on an electronic device, the electronic device executes the data access method according to any one of claims 1 to 11.
13. An electronic device, characterized in that: The electronic device comprises a processor and a memory, wherein the memory is used to store instructions, and the processor is used to call the instructions in the memory, so that the electronic device executes the data access method according to any one of claims 1 to 11.
14. A computer program product, characterized in that The method comprises computer instructions, which, when executed on a processor, enable the electronic device to execute the data access method according to any one of claims 1 to 11.
Citation Information
Cited By
Server component access method and system
CN120011275A
System memory management method and circuit and electronic equipment
CN121349917A
System calling method and apparatus
WO2026157582A1
Data sharing method and related device
WO2026214292A1
