Address mapping relationship random generation method and system, and related device
By randomly generating address mapping relationships in the RISC-V system, the flexibility problem of virtual address to physical address mapping is solved, realizing fast and random address mapping to meet complex address translation verification requirements.
Patent Information
- Application Number
- CN202511167097.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-20
- Publication Date
- 2025-11-18
- Estimated Expiration
- 2045-08-20
AI Technical Summary
Existing technologies struggle to achieve flexible virtual-to-physical address mapping in RISC-V systems, especially without building page table structures. This makes it difficult to meet the complex requirements of address space partitioning and dynamic mapping, leading to inconvenience and limitations in verification work.
A method for randomly generating address mapping relationships is provided. By establishing a virtual address space, a client physical address space, and a real physical address space, address segments are randomly allocated and mapping relationships are established based on external parameters and paging mode configuration, thereby meeting the address translation requirements of the RISC-V specification.
It enables the rapid and random generation of one- or two-level address mapping relationships without constructing a complete set of page tables, supports page mapping with the same name, and meets the verification requirements of complex RISC-V address translation modules.
Smart Images

Figure CN120653587B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of processor technology, and in particular to a method, system and related equipment for randomly generating address mapping relationships. Background Technology
[0002] With the continuous improvement of the RISC-V instruction set architecture and the expansion of its application areas, the RISC-V architecture's support for virtual memory management has become increasingly rich. RISC-V employs a flexible Memory Management Unit (MMU) design, supporting single-level and two-level address mapping mechanisms to meet the needs of virtual-to-physical address translation in different application scenarios. The RISC-V standard defines various virtual memory management schemes, such as SV39 and SV48, suitable for systems with different bit widths and memory capacities, achieving efficient large-capacity memory space management. As system complexity increases, verification engineers urgently need to comprehensively and automatically verify the address translation function of the RISC-V MMU module during chip design and verification to ensure the correctness of address translation. To address this need, developing an efficient and flexible RISC-V random address mapping scheme will help improve verification coverage.
[0003] Currently, the virtual address to physical address mapping mechanism of RISC-V is becoming increasingly complex with the improvement of application requirements. However, existing technologies must rely on the operating system to establish a multi-level page table structure in order to establish the mapping relationship between virtual addresses and physical addresses. For verification scenarios that do not focus on the page table content and only need to establish the mapping relationship, existing verification methods often rely on manual static mapping, which is difficult to adapt to the diverse address space partitioning and dynamic mapping requirements. As a result, the flexibility of virtual address to physical address mapping cannot be fully guaranteed in the chip design and system verification process, and verification work is prone to inconvenience or limitations.
[0004] Therefore, there is an urgent need for a new method, system, and related equipment for randomly generating address mapping relationships to solve the above-mentioned technical problems. Summary of the Invention
[0005] This invention provides a method, system, and related equipment for randomizing address mapping relationships, aiming to automatically establish random physical address mapping relationships with a continuous virtual address space, while conforming to the RISC-V address translation specification.
[0006] In a first aspect, the present invention provides a method for randomly generating address mapping relationships, the method comprising the following steps:
[0007] S1. Establish the virtual address space, the client physical address space, and the real physical address space;
[0008] S2. Randomly allocate address segments to the virtual address space, the client physical address space, and the real physical address space according to the starting position of the address passed from the external parameters and the address segment length;
[0009] S3. Obtain the paging mode configuration of the current computer system, and constrain the virtual address space and the client physical address space according to the paging mode configuration;
[0010] S4. Establish a random mapping relationship between the virtual address space, the client physical address space, and the real physical address space according to the paging mode configuration to obtain the address mapping result.
[0011] Preferably, when the paging mode is configured as raw mode, the constraint on the virtual address space is: the starting virtual address and the ending virtual address of the virtual address space are both limited to the maximum physical address range of the hardware;
[0012] When the paging mode configuration has a mapping from the virtual address space to the client physical address space, the constraint on the virtual address space is: the starting virtual address and the ending virtual address of the virtual address space are limited to the upper limit of the address bits corresponding to the paging mode configuration;
[0013] When the paging mode configuration only involves the mapping from the client's physical address space to the real physical address space, the constraint on the virtual address space is: the starting virtual address and the ending virtual address of the virtual address space are limited to the upper limit of the address bits corresponding to the paging mode configuration.
[0014] Preferably, when the paging mode is configured as raw mode, the address segments of the client physical address space and the address segments of the real physical address space are allocated according to the parameters corresponding to the address segments of the virtual address space, and a mapping relationship is established between the address segments of the virtual address space and the address segments of the client physical address space, as well as between the address segments of the client physical address space and the address segments of the real physical address space.
[0015] Preferably, when the paging mode is configured to only have an address translation relationship from the virtual address space to the client physical address space;
[0016] The address segments of the virtual address space are randomly selected and mapped to the address segments of the client's physical address space in sequence. The address segments of the real physical address space are allocated according to the parameters corresponding to the address segments of the client's physical address space, and the mapping relationship between the address segments of the client's physical address space and the address segments of the real physical address space is established.
[0017] Preferably, when the paging mode is configured to only have an address translation relationship from the client physical address space to the real physical address space;
[0018] The address segments of the client's physical address space are allocated according to the parameters corresponding to the address segments of the virtual address space. A mapping relationship is established one-to-one between the address segments of the virtual address space and the address segments of the client's physical address space. Then, the address segments of the client's physical address space are randomly selected and mapped to the address segments of the real physical address space in turn.
[0019] Preferably, when the pagination mode is configured as a two-level mapping mode;
[0020] Within the upper limit of the address bits corresponding to the paging mode configuration, the address range of the client's physical address space is randomly allocated. The address range of the virtual address space is randomly selected and mapped to the address range of the client's physical address space in turn. The address range of the client's physical address space is randomly selected and mapped to the address range of the real physical address space in turn.
[0021] Preferably, when the pagination mode is configured as a first-level mapping mode in a non-virtualized environment;
[0022] The address segments of the virtual address space are randomly selected and mapped to the address segments of the client's physical address space in turn. The address segments of the client's physical address space are randomly selected and mapped to the address segments of the real physical address space in turn.
[0023] Secondly, the present invention also provides a random address mapping relationship generation system, the random address mapping relationship generation system comprising:
[0024] The address space creation module is used to create the virtual address space, the client physical address space, and the real physical address space;
[0025] The address allocation module is used to randomly allocate address segments to the virtual address space, the client physical address space, and the real physical address space according to the starting position of the address passed by the external parameters and the address segment length.
[0026] The constraint module is used to obtain the paging mode configuration of the current computer system and constrain the virtual address space and the client physical address space according to the paging mode configuration;
[0027] The mapping module is used to establish a random mapping relationship between the virtual address space, the client physical address space, and the real physical address space according to the paging mode configuration, and to obtain the address mapping result.
[0028] Thirdly, the present invention also provides a computer device, comprising: a memory, a processor, and an address mapping relationship random generation program stored in the memory and executable on the processor, wherein when the processor executes the address mapping relationship random generation program, it implements the steps in the address mapping relationship random generation method as described in any of the above embodiments.
[0029] Fourthly, the present invention also provides a computer-readable storage medium storing an address mapping relationship random generation program, wherein when the address mapping relationship random generation program is executed by a processor, it implements the steps of the address mapping relationship random generation method as described in any of the above embodiments.
[0030] Compared with existing technologies, this invention establishes a virtual address space, a client physical address space, and a real physical address space; randomly allocates address segments to these spaces based on the address start position and address segment length of externally passed parameters; obtains the paging mode configuration of the current computer system and constrains the virtual and client physical address spaces according to this configuration; and establishes a random mapping relationship between the virtual, client, and real physical address spaces based on the paging mode configuration to obtain the address mapping result. This invention can quickly and randomly generate one- or two-level address mapping relationships without constructing a complete page table, based on the paging rules defined in the RISC-V specification. It can also randomly generate mapping scenarios with duplicate page names, meaning different virtual addresses can map to the same real physical address, meeting the verification requirements of complex RISC-V address translation modules. Attached Figure Description
[0031] The present invention will now be described in detail with reference to the accompanying drawings. The above and other aspects of the present invention will become clearer and more readily understood through the detailed description following the accompanying drawings. In the drawings:
[0032] Figure 1 This is a flowchart of the address mapping relationship random generation method provided in the embodiments of the present invention;
[0033] Figure 2 This is a schematic diagram of the data structure of the virtual address space, the client physical address space, and the real physical address space in the address mapping relationship random generation method provided in this embodiment of the invention;
[0034] Figure 3 This is a schematic diagram of the address segment of the virtual address space of the address mapping relationship random generation method provided in the embodiments of the present invention;
[0035] Figure 4This is a schematic diagram of the mapping relationship when the paging mode of the address mapping relationship random generation method provided in the embodiment of the present invention is configured as bare mode;
[0036] Figure 5 This is a schematic diagram of the address mapping relationship in the case where the pagination mode of the address mapping relationship random generation method provided in this embodiment of the invention is configured to only have the address translation relationship from the virtual address space to the client physical address space.
[0037] Figure 6 This is a schematic diagram of the paging mode configuration of the address mapping relationship random generation method provided in this embodiment of the invention, where only the address translation relationship from the client physical address space to the real physical address space exists.
[0038] Figure 7 This is a schematic diagram of the mapping relationship when the pagination mode of the address mapping relationship random generation method provided in the embodiment of the present invention is configured as a two-level mapping mode;
[0039] Figure 8 This is a schematic diagram of the mapping relationship when the paging mode of the address mapping relationship random generation method provided in the embodiment of the present invention is configured as a first-level mapping mode in a non-virtualized environment;
[0040] Figure 9 This is a schematic diagram of the address mapping relationship random generation system provided in an embodiment of the present invention;
[0041] Figure 10 This is a schematic diagram of the structure of the computer device provided in an embodiment of the present invention; Detailed Implementation
[0042] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0043] Example 1
[0044] Please refer to Figure 1 This invention provides a method for randomly generating address mapping relationships, the method comprising the following steps:
[0045] S1. Establish the Virtual Address Space (VAS), the Guest Physical Address Space (GPA Space), and the Host Physical Address Space (HPA Space).
[0046] In embodiments of the present invention, reference may be made to Figures 2-3 , Figure 2 This is a schematic diagram of the data structure of the virtual address space, the client physical address space, and the real physical address space in the address mapping relationship random generation method provided in this embodiment of the invention; Figure 3 This is a schematic diagram of the address segment of the virtual address space of the address mapping relationship random generation method provided in the embodiments of the present invention;
[0047] This paper establishes an address mapping class based on a programming language (such as SystemVerilog), which includes data structures for virtual address space, guest physical address space, and real physical address space. All three spaces use dynamic data structures that can be modified at any time. The address segments of each space store information such as start address, end address, address space size, and mapping address. Specifically, the virtual address space refers to the contiguous address space "imagined" by the CPU for each process, not the actual physical memory address space; the guest physical address space refers to the "physical address space" seen from the perspective of the guest machine (virtual machine), that is, the address range of "physical memory" that the operating system (guest OS) inside the virtual machine believes it directly manages; and the real physical address space refers to the address space from the perspective of the physical hardware.
[0048] S2. Randomly allocate address segments to the virtual address space, the client physical address space, and the real physical address space according to the starting position of the address passed from the external parameters and the address segment length.
[0049] In this embodiment of the invention, external parameter passing refers to passing parameters from outside the program to inside, allocating an address segment at a specific location to the virtual address space, the client physical address space, and the real physical address space according to the address start position and address segment length (address segment size) specified by the external parameter passing; or randomly allocating an address segment between the zero address and the upper bound according to the address upper bound and address segment length specified by the external parameter passing, ensuring that the address segment has not been allocated before, and that the boundary is aligned according to the passed address segment size.
[0050] S3. Obtain the paging mode configuration of the current computer system, and constrain the virtual address space and the client physical address space according to the paging mode configuration.
[0051] In this embodiment of the invention, paging mode configuration refers to setting the parameters, rules and operating mode of the memory paging mechanism to determine the translation method from virtual address to physical address, such as SV39, SV48, etc.
[0052] The parameters of the virtual address segments in the virtual address space are constrained, namely the starting virtual address, the number of address segments used, and the ending virtual address, to determine the range of virtual space required for the verification process. To ensure that the constraint on the number of address segments in the virtual address space is within a certain range, the constraints on the starting and ending virtual addresses need to be configured according to the paging mode of the current computer system, taking the following considerations to guarantee compliance with the RISC-V protocol specification:
[0053] When the paging mode is configured as bare metal mode, there is no mapping relationship between the virtual address space, the client physical address space, and the real physical address space. The virtual address and the physical address are equal. Therefore, the constraint on the virtual address space is that the starting virtual address and the ending virtual address of the virtual address space are both limited to the maximum physical address range of the hardware.
[0054] When the paging mode configuration includes a mapping from the virtual address space to the client's physical address space, the virtual address space is constrained to have its starting and ending virtual addresses limited to the upper limit of the address bits corresponding to the paging mode configuration. For example, when the current paging mode configuration is SV39 or SV48, both the starting and ending virtual addresses of the virtual address space should meet the RISC-V address bit requirements. Specifically, for SV39, bits 39 and 38 of the address are identical, and for SV48, bits 47 and 48 of the address are identical.
[0055] When the paging mode configuration only involves a mapping from the client's physical address space to the actual physical address space, both the starting and ending virtual addresses should satisfy the RISC-V requirements for the client's physical address. The constraint on the virtual address space is that its starting and ending virtual addresses are limited to the maximum address bits corresponding to the paging mode configuration. For example, when the paging mode is configured as SV39x4, the client's physical address space can only use a maximum of 41 bits; when the paging mode is configured as SV48x4, the client's physical address space can only use a maximum of 50 bits.
[0056] S4. Establish a random mapping relationship between the virtual address space, the client physical address space, and the real physical address space according to the paging mode configuration to obtain the address mapping result.
[0057] In this embodiment of the invention, based on the paging mode configuration, the allocation of address segments (GPA) in the client physical address space and address segments (PA) in the real physical address space is automatically completed. Furthermore, according to different paging mode configurations, an appropriate address allocation method is selected to ensure that the mapping relationship between the virtual address space, the client physical address space, and the real physical address space maintains randomness while satisfying the RISC-V specification. The specific rules are as follows:
[0058] like Figure 4 As shown, Figure 4 This is a schematic diagram of the paging relationship when the paging mode of the address mapping relationship random generation method provided in this embodiment of the invention is configured in bare mode. When the paging mode is configured in bare mode, the virtual address and the real physical address are equal, there is no address translation, and the number of address segments in the virtual address space, the number of address segments in the client physical address space, and the number of address segments in the real physical address space are all consistent.
[0059] Based on the parameters corresponding to the address segments of the virtual address space (the parameters of the address segment refer to the starting address and length of the address segment), the address segments of the client physical address space and the address segments of the real physical address space are allocated, and a mapping relationship is established between the address segments of the virtual address space and the address segments of the client physical address space, as well as between the address segments of the client physical address space and the address segments of the real physical address space.
[0060] like Figure 5 As shown, Figure 5 This is a schematic diagram of the paging relationship in the address mapping relationship random generation method provided in this embodiment of the invention, where the paging mode is configured to only have the address translation relationship from the virtual address space to the client physical address space; when the paging mode is configured to only have the address translation relationship from the virtual address space to the client physical address space; at this time, the address of the client physical address space is actually the same as the address of the real physical address space;
[0061] The number of address segments in the client's physical address space is less than or equal to the number of address segments in the virtual address space, while the number of address segments in the real physical address space is equal to the number of address segments in the client's physical address space. Since the client's physical address equals the real physical address, the address segments in the client's physical address space need to be randomly allocated within the maximum addressable range of the hardware.
[0062] When establishing the mapping relationship, the address segments of the virtual address space are randomly selected and mapped to the address segments of the client physical address space in sequence. The address segments of the real physical address space are allocated according to the parameters corresponding to the address segments of the client physical address space, and the mapping relationship between the address segments of the client physical address space and the address segments of the real physical address space is established.
[0063] like Figure 6 As shown, Figure 6 This is a schematic diagram of the paging relationship in the address mapping relationship random generation method provided in this embodiment of the invention, where the paging mode is configured to only have the address translation relationship from the client physical address space to the real physical address space; when the paging mode is configured to only have the address translation relationship from the client physical address space to the real physical address space; at this time, the address of the virtual address space is actually the same as the address of the client physical address space;
[0064] The number of address segments in the client's physical address space is equal to the number of address segments in the virtual address space, while the number of address segments in the real physical address space is less than or equal to the number of address segments in the client's physical address space. When establishing mapping relationships, since the client's physical address equals the virtual address, address segments in the client's physical address space are allocated according to the parameters corresponding to the address segments in the virtual address space. A one-to-one mapping relationship is established between the address segments in the virtual address space and the address segments in the client's physical address space. Then, address segments in the client's physical address space are randomly selected and randomly mapped to address segments in the real physical address space.
[0065] like Figure 7 As shown, Figure 7 This is a schematic diagram of the address mapping relationship in the case of a two-level mapping mode configuration of the address mapping relationship random generation method provided in this embodiment of the invention. When the paging mode is configured as a two-level mapping mode, the number of address segments in the client's physical address space can be less than or equal to the number of address segments in the virtual address space, and the number of address segments in the real physical address space can also be less than or equal to the number of address segments in the client's physical address space. If the current computer system's paging mode is configured as SV39x4, the address segments in the client's physical address space can be randomly allocated within the 41-bit address space specified by the RISC-V standard. If the current computer system's paging mode is configured as SV48x4, the address segments in the client's physical address space can be randomly allocated within the 50-bit address space.
[0066] When establishing the mapping relationship, the address range of the client's physical address space is randomly allocated within the upper limit of the address bits corresponding to the paging mode configuration. The address range of the virtual address space is randomly selected and mapped to the address range of the client's physical address space in turn. The address range of the client's physical address space is randomly selected and mapped to the address range of the real physical address space in turn.
[0067] like Figure 8 As shown, Figure 8 This is a schematic diagram of the mapping relationship when the paging mode of the address mapping relationship random generation method provided in the embodiment of the present invention is configured as a first-level mapping mode in a non-virtualized environment;
[0068] When the paging mode is configured as a first-level mapping mode in a non-virtualized environment (i.e., a scenario where the physical machine directly runs the operating system without the intervention of a Virtual Machine Monitor (VMM)); in a non-virtualized environment, if address translation exists, there is actually only a first-level address mapping relationship from virtual address to real physical address. However, to consider the reusability of the entire random method, the entire fundamental mapping process remains consistent with the above-mentioned "two-level mapping mode", that is, the address segments of the virtual address space are randomly selected and mapped to the address segments of the client's physical address space in turn, and the address segments of the client's physical address space are randomly selected and mapped to the address segments of the real physical address space in turn.
[0069] Compared with existing technologies, this invention establishes a virtual address space, a client physical address space, and a real physical address space; randomly allocates address segments to these spaces based on the address start position and address segment length of externally passed parameters; obtains the paging mode configuration of the current computer system and constrains the virtual and client physical address spaces according to this configuration; and establishes a random mapping relationship between the virtual, client, and real physical address spaces based on the paging mode configuration to obtain the address mapping result. This invention can quickly and randomly generate one- or two-level address mapping relationships without constructing a complete page table, based on the paging rules defined in the RISC-V specification. It can also randomly generate mapping scenarios with duplicate page names, meaning different virtual addresses can map to the same real physical address, meeting the verification requirements of complex RISC-V address translation modules.
[0070] Example 2
[0071] This invention also provides a system for randomly generating address mapping relationships. Please refer to [link / reference]. Figure 9 , Figure 9 This is a schematic diagram of the address mapping relationship random generation system 200 provided in an embodiment of the present invention, which includes:
[0072] 201. Space Establishment Module, used to establish the virtual address space, the client physical address space, and the real physical address space;
[0073] 202. Address allocation module, used to randomly allocate address segments to the virtual address space, the client physical address space and the real physical address space according to the starting position of the address and the address segment length of the externally passed parameters;
[0074] 203. Constraint module, used to obtain the paging mode configuration of the current computer system, and constrain the virtual address space and the client physical address space according to the paging mode configuration;
[0075] 204. Mapping module, used to establish a random mapping relationship between the virtual address space, the client physical address space and the real physical address space according to the paging mode configuration, and obtain the address mapping result.
[0076] The address mapping relationship random generation system 200 can implement the steps in the address mapping relationship random generation method in the above embodiments and achieve the same technical effect. Refer to the description in the above embodiments, which will not be repeated here.
[0077] Example 3
[0078] This invention also provides a computer device, please refer to... Figure 10 , Figure 10 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present invention. The computer device 300 includes: a memory 302, a processor 301, and an address mapping relationship random generation program stored in the memory 302 and executable on the processor 301.
[0079] The processor 301 calls the address mapping relationship random generation program stored in the memory 302 and executes the steps in the address mapping relationship random generation method provided in this embodiment of the invention. Please refer to... Figure 1 Specifically, it includes the following steps:
[0080] S1. Establish the virtual address space, the client physical address space, and the real physical address space.
[0081] In this embodiment of the invention, an address mapping class is established based on a programming language (such as SystemVerilog), comprising a data structure of a virtual address space, a guest physical address space, and a real physical address space. All three spaces use dynamic data structures that can be modified at any time. The address segments of each space store information such as the start address, end address, address space size, and mapping address. Specifically, the virtual address space refers to a contiguous address space "imagined" by the CPU for each process, not the actual physical memory address space; the guest physical address space refers to the "physical address space" seen from the perspective of the guest machine (virtual machine), i.e., the address range of "physical memory" that the operating system (guest OS) inside the virtual machine believes it directly manages; and the real physical address space refers to the address space from the perspective of the physical hardware.
[0082] S2. Randomly allocate address segments to the virtual address space, the client physical address space, and the real physical address space according to the starting position of the address passed from the external parameters and the address segment length.
[0083] In this embodiment of the invention, external parameter passing refers to passing parameters from outside the program to inside, allocating an address segment at a specific location to the virtual address space, the client physical address space, and the real physical address space according to the address start position and address segment length (address segment size) specified by the external parameter passing; or randomly allocating an address segment between the zero address and the upper bound according to the address upper bound and address segment length specified by the external parameter passing, ensuring that the address segment has not been allocated before, and that the boundary is aligned according to the passed address segment size.
[0084] S3. Obtain the paging mode configuration of the current computer system, and constrain the virtual address space and the client physical address space according to the paging mode configuration.
[0085] In this embodiment of the invention, paging mode configuration refers to setting the parameters, rules and operating mode of the memory paging mechanism to determine the translation method from virtual address to physical address, such as SV39, SV48, etc.
[0086] The parameters of the virtual address segments in the virtual address space are constrained, namely the starting virtual address, the number of address segments used, and the ending virtual address, to determine the range of virtual space required for the verification process. To ensure that the constraint on the number of address segments in the virtual address space is within a certain range, the constraints on the starting and ending virtual addresses need to be configured according to the paging mode of the current computer system, taking the following considerations to guarantee compliance with the RISC-V protocol specification:
[0087] When the paging mode is configured as bare metal mode, there is no mapping relationship between the virtual address space, the client physical address space, and the real physical address space. The virtual address and the physical address are equal. Therefore, the constraint on the virtual address space is that the starting virtual address and the ending virtual address of the virtual address space are both limited to the maximum physical address range of the hardware.
[0088] When the paging mode configuration includes a mapping from the virtual address space to the client's physical address space, the virtual address space is constrained to have its starting and ending virtual addresses limited to the upper limit of the address bits corresponding to the paging mode configuration. For example, when the current paging mode configuration is SV39 or SV48, both the starting and ending virtual addresses of the virtual address space should meet the RISC-V address bit requirements. Specifically, for SV39, bits 39 and 38 of the address are identical, and for SV48, bits 47 and 48 of the address are identical.
[0089] When the paging mode configuration only involves a mapping from the client's physical address space to the actual physical address space, both the starting and ending virtual addresses should satisfy the RISC-V requirements for the client's physical address. The constraint on the virtual address space is that its starting and ending virtual addresses are limited to the maximum address bits corresponding to the paging mode configuration. For example, when the paging mode is configured as SV39x4, the client's physical address space can only use a maximum of 41 bits; when the paging mode is configured as SV48x4, the client's physical address space can only use a maximum of 50 bits.
[0090] S4. Establish a random mapping relationship between the virtual address space, the client physical address space, and the real physical address space according to the paging mode configuration to obtain the address mapping result.
[0091] In this embodiment of the invention, based on the paging mode configuration, the allocation of address segments (GPA) in the client physical address space and address segments (PA) in the real physical address space is automatically completed. Furthermore, according to different paging mode configurations, an appropriate address allocation method is selected to ensure that the mapping relationship between the virtual address space, the client physical address space, and the real physical address space maintains randomness while satisfying the RISC-V specification. The specific rules are as follows:
[0092] When the paging mode is configured as raw mode, the virtual address and the real physical address are equal, there is no address translation, and the number of address segments in the virtual address space, the number of address segments in the client physical address space, and the number of address segments in the real physical address space are all consistent.
[0093] Based on the parameters corresponding to the address segments of the virtual address space (the parameters of the address segment refer to the starting address and length of the address segment), the address segments of the client physical address space and the address segments of the real physical address space are allocated, and a mapping relationship is established between the address segments of the virtual address space and the address segments of the client physical address space, as well as between the address segments of the client physical address space and the address segments of the real physical address space.
[0094] When the paging mode is configured to only have address translation relationships from the virtual address space to the client physical address space, the number of address segments in the client physical address space is less than or equal to the number of address segments in the virtual address space, and the number of address segments in the real physical address space is equal to the number of address segments in the client physical address space. Since the client physical address is equal to the real physical address, the address segments in the client physical address space need to be randomly allocated within the maximum addressable range of the hardware.
[0095] When establishing the mapping relationship, the address segments of the virtual address space are randomly selected and mapped to the address segments of the client physical address space in sequence. The address segments of the real physical address space are allocated according to the parameters corresponding to the address segments of the client physical address space, and the mapping relationship between the address segments of the client physical address space and the address segments of the real physical address space is established.
[0096] When the paging mode is configured to only have an address translation relationship from the client physical address space to the real physical address space;
[0097] The number of address segments in the client's physical address space is equal to the number of address segments in the virtual address space, while the number of address segments in the real physical address space is less than or equal to the number of address segments in the client's physical address space. When establishing mapping relationships, since the client's physical address equals the virtual address, address segments in the client's physical address space are allocated according to the parameters corresponding to the address segments in the virtual address space. A one-to-one mapping relationship is established between the address segments in the virtual address space and the address segments in the client's physical address space. Then, address segments in the client's physical address space are randomly selected and randomly mapped to address segments in the real physical address space.
[0098] When the paging mode is configured as a two-level mapping mode, the number of address segments in the client's physical address space can be less than or equal to the number of address segments in the virtual address space, and the number of address segments in the real physical address space can also be less than or equal to the number of address segments in the client's physical address space. If the current computer system's paging mode is configured as SV39x4, the address segments in the client's physical address space can be randomly allocated within the 41-bit address space specified by the RISC-V standard. If the current computer system's paging mode is configured as SV48x4, the address segments in the client's physical address space can be randomly allocated within the 50-bit address space.
[0099] When establishing the mapping relationship, the address range of the client's physical address space is randomly allocated within the upper limit of the address bits corresponding to the paging mode configuration. The address range of the virtual address space is randomly selected and mapped to the address range of the client's physical address space in turn. The address range of the client's physical address space is randomly selected and mapped to the address range of the real physical address space in turn.
[0100] When the paging mode is configured as a first-level mapping mode in a non-virtualized environment (i.e., a scenario where the physical machine directly runs the operating system without the intervention of a Virtual Machine Monitor (VMM)); in a non-virtualized environment, if address translation exists, there is actually only a first-level address mapping relationship from virtual address to real physical address. However, to consider the reusability of the entire random method, the entire fundamental mapping process remains consistent with the above-mentioned "two-level mapping mode", that is, the address segments of the virtual address space are randomly selected and mapped to the address segments of the client's physical address space in turn, and the address segments of the client's physical address space are randomly selected and mapped to the address segments of the real physical address space in turn.
[0101] The computer device 300 provided in this embodiment of the invention can implement the steps in the address mapping relationship random generation method as described in the above embodiments, and can achieve the same technical effect. Refer to the description in the above embodiments, which will not be repeated here.
[0102] Example 4
[0103] This invention also provides a computer-readable storage medium storing a random address mapping relationship generation program. When the random address mapping relationship generation program is executed by a processor, it implements the various processes and steps in the random address mapping relationship generation method provided in this invention and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0104] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0105] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0106] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0107] The embodiments of the present invention have been described above with reference to the accompanying drawings. The disclosed embodiments are merely preferred embodiments of the present invention. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many equivalent changes in form without departing from the spirit and scope of the claims of the present invention, and all such changes are within the protection scope of the present invention.
Claims
1. A method for randomly generating address mapping relationship, characterized in that, The address mapping relationship random generation method comprises the following steps: S1, establishing a virtual address space, a client physical address space and a real physical address space; S2, randomly allocating address segments to the virtual address space, the client physical address space and the real physical address space according to an externally transmitted address start position and an address segment length; S3, obtaining a paging mode configuration of a current computer system, and constraining the virtual address space and the client physical address space according to the paging mode configuration; S4, establishing a random mapping relationship between the virtual address space, the client physical address space and the real physical address space according to the paging mode configuration, and obtaining an address mapping result; When the paging mode configuration is a bare mode, the constraint on the virtual address space is that the start virtual address and the end virtual address of the virtual address space are both limited within a hardware maximum physical address range; When the paging mode configuration has a mapping from the virtual address space to the client physical address space, the constraint on the virtual address space is that the start virtual address and the end virtual address of the virtual address space are limited within an address bit upper limit corresponding to the paging mode configuration; When the paging mode configuration only has a mapping from the client physical address space to the real physical address space, the constraint on the virtual address space is that the start virtual address and the end virtual address of the virtual address space are limited within an address bit upper limit corresponding to the paging mode configuration.
2. The address mapping relationship random generation method according to claim 1, wherein, When the paging mode configuration is the bare mode, the address segments of the client physical address space and the real physical address space are allocated according to the parameters corresponding to the address segments of the virtual address space, and a mapping relationship is established between the address segments of the virtual address space and the address segments of the client physical address space, and a mapping relationship is established between the address segments of the client physical address space and the address segments of the real physical address space.
3. The method of claim 1, wherein the address mapping relationship is randomly generated. When the paging mode configuration only has an address conversion relationship from the virtual address space to the client physical address space; The address segments of the real physical address space are allocated according to the parameters corresponding to the address segments of the client physical address space, the address segments of the virtual address space and the address segments of the client physical address space are one-to-one established in a mapping relationship, and the address segments of the client physical address space are sequentially selected to randomly establish a mapping relationship with the address segments of the real physical address space.
4. The method of claim 1, wherein the address mapping relationship is randomly generated. When the paging mode configuration only has an address conversion relationship from the client physical address space to the real physical address space; The address segments of the client physical address space are allocated according to the parameters corresponding to the address segments of the virtual address space, the address segments of the virtual address space and the address segments of the client physical address space are one-to-one established in a mapping relationship, and the address segments of the client physical address space are sequentially selected to randomly establish a mapping relationship with the address segments of the real physical address space.
5. The method of claim 1, wherein the address mapping relationship is randomly generated. When the paging mode configuration is a two-level mapping mode; randomly allocating address segments of the guest physical address space within an upper limit of address bits corresponding to the paging mode configuration, and sequentially selecting address segments of the virtual address space to randomly establish mapping relationships with the address segments of the guest physical address space, and sequentially selecting address segments of the guest physical address space to randomly establish mapping relationships with address segments of the real physical address space.
6. The method of claim 1, wherein the address mapping relationship is randomly generated. When the paging mode configuration is a one-level mapping mode in a non-virtualization environment; sequentially selecting address segments of the virtual address space to randomly establish mapping relationships with the address segments of the guest physical address space, and sequentially selecting address segments of the guest physical address space to randomly establish mapping relationships with address segments of the real physical address space.
7. An address mapping relationship random generation system characterized by comprising: The address mapping relationship random generation system comprises: a space establishment module configured to establish a virtual address space, a guest physical address space, and a real physical address space; an address allocation module configured to randomly allocate address segments to the virtual address space, the guest physical address space, and the real physical address space according to an externally transmitted address start position and an address segment length; a constraint module configured to acquire a paging mode configuration of a current computer system, and constrain the virtual address space and the guest physical address space according to the paging mode configuration; when the paging mode configuration is a bare mode, the constraint on the virtual address space is to limit a start virtual address and an end virtual address of the virtual address space within a hardware maximum physical address range; when the paging mode configuration has mapping from the virtual address space to the guest physical address space, the constraint on the virtual address space is to limit the start virtual address and the end virtual address of the virtual address space within an upper limit of address bits corresponding to the paging mode configuration; when the paging mode configuration only has mapping from the guest physical address space to the real physical address space, the constraint on the virtual address space is to limit the start virtual address and the end virtual address of the virtual address space within the upper limit of address bits corresponding to the paging mode configuration; a mapping module configured to establish random mapping relationships among the virtual address space, the guest physical address space, and the real physical address space according to the paging mode configuration, and obtain an address mapping result.
8. A computer device, comprising: comprise: a memory, a processor, and an address mapping relationship random generation program stored on the memory and executable on the processor, and the processor implements the steps in the address mapping relationship random generation method according to any one of claims 1-6 when executing the address mapping relationship random generation program.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium has an address mapping relationship random generation program stored thereon, and the address mapping relationship random generation program implements the steps in the address mapping relationship random generation method according to any one of claims 1-6 when executed by a processor.
Citation Information
Patent Citations
Method for converting virtual machine user space address into host machine kernel space address
CN110336894A
Address generation method, processor and equipment
CN114237710A