On Mon 16-11-15 21:52:10, Michal Hocko wrote: > [CCing Cyril] > > On Mon 16-11-15 18:36:19, Piotr Kwapulinski wrote: > > When a new virtual memory area is added to the process's virtual address > > space and this vma causes the process's virtual address space limit > > (RLIMIT_AS) to be exceeded then kernel behaves incorrectly. Incorrect > > behavior is a result of a kernel bug. The kernel in most cases > > unnecessarily scans the entire process's virtual address space trying to > > find the overlapping vma with the virtual memory region being added. > > The kernel incorrectly compares the MAP_FIXED flag with vm_flags variable > > in mmap_region function. The vm_flags variable should not be compared > > with MAP_FIXED flag. The MAP_FIXED flag has got the same numerical value > > as VM_MAYREAD flag (0x10). As a result the following test > > from mmap_region: > > > > if (!(vm_flags & MAP_FIXED)) > > is in fact: > > if (!(vm_flags & VM_MAYREAD)) > > It seems this has been broken since it was introduced e8420a8ece80 > ("mm/mmap: check for RLIMIT_AS before unmapping"). The patch has fixed > the case where unmap happened before the we tested may_expand_vm and > failed which was sufficient for the LTP test case but it apparently > never tried to consider the overlapping ranges to eventually allow to > create the mapping. > > > The VM_MAYREAD flag is almost always set in vm_flags while MAP_FIXED > > flag is not so common. The result of the above condition is somewhat > > reverted. > > This patch fixes this bug. It causes that the kernel tries to find the > > overlapping vma only when the requested virtual memory region has got > > the fixed starting virtual address (MAP_FIXED flag set). > > For tile architecture Calling mmap_region with the MAP_FIXED flag only is > > sufficient. However the MAP_ANONYMOUS and MAP_PRIVATE flags are passed for > > the completeness of the solution. > > I found the changelog rather hard to grasp. But the fix is correct. The > user visible effect is that RLIMIT_AS might hit for a MAP_FIXED > mapping even though it wouldn't enlarge the used address space. And I was obviously blind and read the condition incorrectly. Sigh... There is no real issue in fact. We do call count_vma_pages_range even for !MAP_FIXED case but that is merely a pointless find_vma call but nothing really earth shattering. So nothing for the stable tree and also quite exaggerated to be called a bug. I am sorry about the confusion. -- Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to majordomo@xxxxxxxxx. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"dont@xxxxxxxxx"> email@xxxxxxxxx </a>