mm: Remove PMD alignment constraint in execmem_vmalloc()
Subsystems (2)
PATCH 1/1 mm: Remove PMD alignment constraint in execmem_vmalloc()
When using vmalloc with VM_ALLOW_HUGE_VMAP flag, it will set the alignment to PMD_SIZE internally, if it deems huge mappings to be eligible. Therefore, setting the alignment in execmem_vmalloc is redundant. Apart from this, it also reduces the probability of allocation in case vmalloc fails to allocate hugepages - in the fallback case, vmalloc tries to use the original alignment and allocate basepages, which unfortunately will again be PMD_SIZE passed over from execmem_vmalloc, thus constraining the search for a free space in vmalloc region.
Therefore, remove this constraint.
---
mm-selftests pass, but I am not sure if they touch execmem code, and I have no experience with this code.
mm/execmem.c | 3 --- 1 file changed, 3 deletions(-)
mm/execmem.c +0 -3
@@ -38,9 +38,6 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,if (kasan) vm_flags |=VM_DEFER_KMEMLEAK ; -if (vm_flags &VM_ALLOW_HUGE_VMAP ) - align =PMD_SIZE ; - p =__vmalloc_node_range (size, align, start, end, gfp_flags, pgprot, vm_flags,NUMA_NO_NODE ,__builtin_return_address (0 ));
Signature · 1 line
2.30.2
Quoted 9 lines · Dev Jain
When using vmalloc with
VM_ALLOW_HUGE_VMAPflag, it will set the alignment toPMD_SIZEinternally, if it deems huge mappings to be eligible. Therefore, setting the alignment inexecmem_vmallocis redundant. Apart from this, it also reduces the probability of allocation in case vmalloc fails to allocate hugepages - in the fallback case, vmalloc tries to use the original alignment and allocate basepages, which unfortunately will again bePMD_SIZEpassed over fromexecmem_vmalloc, thus constraining the search for a free space in vmalloc region.
Quoted 3 lines
Therefore, remove this constraint.
Signed-off-by Dev Jain <[email protected]>
Quoted 24 lines
---
mm-selftests pass, but I am not sure if they touch execmem code, and I have no experience with this code.mm/execmem.c | 3 --- 1 file changed, 3 deletions(-)mm/execmem.c +0
-3@@ -38,9 +38,6 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,if (kasan) vm_flags |=VM_DEFER_KMEMLEAK ; -if (vm_flags &VM_ALLOW_HUGE_VMAP ) - align =PMD_SIZE ; - p =__vmalloc_node_range (size, align, start, end, gfp_flags, pgprot, vm_flags,NUMA_NO_NODE ,__builtin_return_address (0 ));Signature · 1 line
2.30.2
Signature · 2 lines
Sincerely yours, Mike.
Quoted 10 lines · Mike Rapoport
Quoted 9 lines · Dev Jain
When using vmalloc with
VM_ALLOW_HUGE_VMAPflag, it will set the alignment toPMD_SIZEinternally, if it deems huge mappings to be eligible. Therefore, setting the alignment inexecmem_vmallocis redundant. Apart from this, it also reduces the probability of allocation in case vmalloc fails to allocate hugepages - in the fallback case, vmalloc tries to use the original alignment and allocate basepages, which unfortunately will again bePMD_SIZEpassed over fromexecmem_vmalloc, thus constraining the search for a free space in vmalloc region.
Quoted 5 lines
Quoted 3 lines
Therefore, remove this constraint.
Signed-off-by Dev Jain <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>
Hijacking this thread to ask Mike a related question, which I noticed during code review...
execmem_alloc() determines the pgprot from the descriptor set by the architecture, and for !CONFIG_ARCH_HAS_EXECMEM_ROX (a la arm64), passes the value into __vmalloc_node_range() (via execmem_vmalloc()). vmalloc then uses the pgprot to set the permissions of the vmap. But the linear map is left as is (i.e. RW).
arm64 requests PAGE_KERNEL_ROX for the EXECMEM_KPROBES type. So by my reckoning, the memory ends up ROX in vmap and RW in linear map. Naively that sounds like something we should be avoiding? Is this intentional?
For arches using the ROX cache, execmem_cache_populate() calls set_memory_rox() which sets both vmap and linear map to ROX.
Thanks,
Ryan
Quoted 26 lines
Quoted 25 lines
---
mm-selftests pass, but I am not sure if they touch execmem code, and I have no experience with this code.mm/execmem.c | 3 --- 1 file changed, 3 deletions(-)mm/execmem.c +0
-3@@ -38,9 +38,6 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,if (kasan) vm_flags |=VM_DEFER_KMEMLEAK ; -if (vm_flags &VM_ALLOW_HUGE_VMAP ) - align =PMD_SIZE ; - p =__vmalloc_node_range (size, align, start, end, gfp_flags, pgprot, vm_flags,NUMA_NO_NODE ,__builtin_return_address (0 ));Signature · 1 line
2.30.2
Mike Rapoport
maintainerHi Ryan,
Quoted 11 lines · Ryan Roberts
Quoted 10 lines · Mike Rapoport
Quoted 9 lines · Dev Jain
When using vmalloc with
VM_ALLOW_HUGE_VMAPflag, it will set the alignment toPMD_SIZEinternally, if it deems huge mappings to be eligible. Therefore, setting the alignment inexecmem_vmallocis redundant. Apart from this, it also reduces the probability of allocation in case vmalloc fails to allocate hugepages - in the fallback case, vmalloc tries to use the original alignment and allocate basepages, which unfortunately will again bePMD_SIZEpassed over fromexecmem_vmalloc, thus constraining the search for a free space in vmalloc region.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Therefore, remove this constraint.
Signed-off-by Dev Jain <[email protected]>Reviewed-by Mike Rapoport (Microsoft) <[email protected]>Hijacking this thread to ask Mike a related question, which I noticed during code review...
Replied on the related thread :)
https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Sincerely yours, Mike.
Quoted 24 lines · Dev Jain
When using vmalloc with
VM_ALLOW_HUGE_VMAPflag, it will set the alignment toPMD_SIZEinternally, if it deems huge mappings to be eligible. Therefore, setting the alignment inexecmem_vmallocis redundant. Apart from this, it also reduces the probability of allocation in case vmalloc fails to allocate hugepages - in the fallback case, vmalloc tries to use the original alignment and allocate basepages, which unfortunately will again bePMD_SIZEpassed over fromexecmem_vmalloc, thus constraining the search for a free space in vmalloc region.Therefore, remove this constraint.
Signed-off-by Dev Jain <[email protected]>---
mm-selftests pass, but I am not sure if they touch execmem code, and I have no experience with this code.mm/execmem.c | 3 --- 1 file changed, 3 deletions(-)mm/execmem.c +0
-0
mm/execmem.c static void *execmem_vmalloc(struct execmem_range *range, size_t size, · line 43
Quoted 6 lines
mm/execmem.c +0
-3@@ -38,9 +38,6 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,if (kasan) vm_flags |=VM_DEFER_KMEMLEAK ; -if (vm_flags &VM_ALLOW_HUGE_VMAP ) - align =PMD_SIZE ; -
So if the above assignment is getting dropped here, probably the local variable 'align' could be dropped as well and range->alignment be used directly instead ?
Quoted 3 lines
mm/execmem.c +0
-0p =__vmalloc_node_range (size, align, start, end, gfp_flags, pgprot, vm_flags,NUMA_NO_NODE ,__builtin_return_address (0 ));
Quoted 29 lines · Anshuman Khandual
Quoted 27 lines · Dev Jain
When using vmalloc with
VM_ALLOW_HUGE_VMAPflag, it will set the alignment toPMD_SIZEinternally, if it deems huge mappings to be eligible. Therefore, setting the alignment inexecmem_vmallocis redundant. Apart from this, it also reduces the probability of allocation in case vmalloc fails to allocate hugepages - in the fallback case, vmalloc tries to use the original alignment and allocate basepages, which unfortunately will again bePMD_SIZEpassed over fromexecmem_vmalloc, thus constraining the search for a free space in vmalloc region.Therefore, remove this constraint.
Signed-off-by Dev Jain <[email protected]>---
mm-selftests pass, but I am not sure if they touch execmem code, and I have no experience with this code.mm/execmem.c | 3 --- 1 file changed, 3 deletions(-)mm/execmem.c +0
-0@@ -38,9 +38,6 @@ static void *execmem_vmalloc(struct execmem_range *range, size_t size,if (kasan) vm_flags |=VM_DEFER_KMEMLEAK ;
Quoted 6 lines
mm/execmem.c static void *execmem_vmalloc(struct execmem_range *range, size_t size, · line 43
Quoted 3 lines
mm/execmem.c +0
-3-if (vm_flags &VM_ALLOW_HUGE_VMAP ) - align =PMD_SIZE ; -So if the above assignment is getting dropped here, probably the local variable 'align' could be dropped as well and
range->alignmentbe used directly instead ?
Sure, but that isn't a big deal. Replacing with range->aligment will push the arguments declaration into an extra line in __vmalloc_node_range. So will prefer not respinning for this triviality, this has already been pulled into mm-new :)
Quoted 3 lines
Quoted 3 lines
mm/execmem.c +0
-0p =__vmalloc_node_range (size, align, start, end, gfp_flags, pgprot, vm_flags,NUMA_NO_NODE ,__builtin_return_address (0 ));