From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CC0E173 for ; Thu, 12 Dec 2024 00:12:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733962374; cv=none; b=l46S5FEgARwieirSLTm1pXn/gSUMfR68gp7mswo0L6ziS8TzFMry/8DTZCesmRUfs+jRyqf+9gBXeV4xqyxMeyZZwn8JmUReUpFIO2+djbJUnQI/gYkXoT8iScxTik7PayBj3VF9tIebB6jCqhcWVmz0L0JXwbcvT3MF2HstZU0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733962374; c=relaxed/simple; bh=ijFY7WSB6aFHf7XybGQvZeWCwBp6v+VI6lHFll7X9oU=; h=Date:To:From:Subject:Message-Id; b=IcByKtvsBqBejyO7OcylJeoyk7N25jc1FziG/OmpxBUQwI3npczA93filcMx2Zyx8o6WcyDMgl86U60kga/aD/ixLjHeNi0pbrT0RCd6d2MoNAn9xJWwVfXmuyteUgo3SPMVYv+qYhFllLE5HlKyOgP+7GJyDAxb02N8DCknGMU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=03lkrKO3; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="03lkrKO3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 920D3C4CED2; Thu, 12 Dec 2024 00:12:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1733962373; bh=ijFY7WSB6aFHf7XybGQvZeWCwBp6v+VI6lHFll7X9oU=; h=Date:To:From:Subject:From; b=03lkrKO3pyckOortCWqiCVgLjf4Vye5kimhZLWUtsY+4LmLgc5Q40rG6rDnlzcy3N 5AQxw4bGuTepGA0aOVNMsgA/Y9tz8eqRGeOKoQqMHxPfV61eJ/p7d7YwbU3EsUMv8g 6+IsRBEI6W95UKbIM+UcfHJgCduSYA3LUTZnblc4= Date: Wed, 11 Dec 2024 16:12:52 -0800 To: mm-commits@vger.kernel.org,ysato@users.sourceforge.jp,yang@os.amperecomputing.com,vbabka@suse.cz,tsbogend@alpha.franken.de,tglx@linutronix.de,riel@surriel.com,minchan@kernel.org,linux@armlinux.org.uk,leitao@debian.org,jcmvbkbc@gmail.com,jason.andryuk@amd.com,James.Bottomley@HansenPartnership.com,glaubitz@physik.fu-berlin.de,david@redhat.com,davem@davemloft.net,dave.hansen@linux.intel.com,dalias@libc.org,chris@zankel.net,bp@alien8.de,bhelgaas@google.com,andreas@gaisler.com,kaleshsingh@google.com,akpm@linux-foundation.org From: Andrew Morton Subject: + mm-introduce-generic_mmap_hint.patch added to mm-unstable branch Message-Id: <20241212001253.920D3C4CED2@smtp.kernel.org> Precedence: bulk X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: The patch titled Subject: mm: introduce generic_mmap_hint() has been added to the -mm mm-unstable branch. Its filename is mm-introduce-generic_mmap_hint.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-introduce-generic_mmap_hint.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Kalesh Singh Subject: mm: introduce generic_mmap_hint() Date: Wed, 11 Dec 2024 15:27:39 -0800 Patch series "mm: Introduce arch_mmap_hint()", v2. This series introduces arch_mmap_hint() to handle allocating VA space for the hint address. Patches 1-16 introduce this new helper and Patch 17 uses it to fix the issue of mmap hint being ignored in some cases due to THP alignment [1] [1] https://lore.kernel.org/r/20241118214650.3667577-1-kaleshsingh@google.com/ This patch (of 16): Consolidate the hint searches from both directions (topdown and bottomup) into generic_mmap_hint(). No functional change is introduced. Link: https://lkml.kernel.org/r/20241211232754.1583023-1-kaleshsingh@google.com Link: https://lkml.kernel.org/r/20241211232754.1583023-2-kaleshsingh@google.com Signed-off-by: Kalesh Singh Cc: Andreas Larsson Cc: Bjorn Helgaas Cc: Borislav Petkov (AMD) Cc: Breno Leitao Cc: Chris Zankel Cc: Dave Hansen Cc: David Hildenbrand Cc: David S. Miller Cc: James Bottomley Cc: Jason Andryuk Cc: John Paul Adrian Glaubitz Cc: Max Filippov Cc: Minchan Kim Cc: Rich Felker Cc: Rik van Riel Cc: Russell King Cc: Thomas Bogendoerfer Cc: Thomas Gleixner Cc: Vlastimil Babka Cc: Yang Shi Cc: Yoshinori Sato Signed-off-by: Andrew Morton --- include/linux/sched/mm.h | 4 + mm/mmap.c | 76 ++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 30 deletions(-) --- a/include/linux/sched/mm.h~mm-introduce-generic_mmap_hint +++ a/include/linux/sched/mm.h @@ -201,6 +201,10 @@ unsigned long mm_get_unmapped_area_vmfla unsigned long flags, vm_flags_t vm_flags); +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags); + unsigned long generic_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, --- a/mm/mmap.c~mm-introduce-generic_mmap_hint +++ a/mm/mmap.c @@ -620,6 +620,47 @@ unsigned long vm_unmapped_area(struct vm return addr; } +/* + * Look up unmapped area at the requested hint addr + * + * NOTE: MAP_FIXED is also handled here since it's a special case of + * enforcing the hint address. + * + * Returns: + * ERR_VALUE: If the requested mapping is not valid + * 0: If there isn't a sufficiently large hole at the hint addr. + * addr: If sufficient VA space is available at the hint address; + * or MAP_FIXED was specified. + */ +unsigned long generic_mmap_hint(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma, *prev; + const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); + + /* requested length too big for entire address space */ + if (len > mmap_end - mmap_min_addr) + return -ENOMEM; + + if (flags & MAP_FIXED) + return addr; + + if (!addr) + return 0; + + addr = PAGE_ALIGN(addr); + vma = find_vma_prev(mm, addr, &prev); + if (mmap_end - len >= addr && addr >= mmap_min_addr && + (!vma || addr + len <= vm_start_gap(vma)) && + (!prev || addr >= vm_end_gap(prev))) + return addr; + + /* Fallback to VA space search */ + return 0; +} + /* Get an address range which is currently unmapped. * For shmat() with addr=0. * @@ -637,25 +678,13 @@ generic_get_unmapped_area(struct file *f unsigned long flags, vm_flags_t vm_flags) { struct mm_struct *mm = current->mm; - struct vm_area_struct *vma, *prev; struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); - if (len > mmap_end - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) + addr = generic_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) return addr; - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma_prev(mm, addr, &prev); - if (mmap_end - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - return addr; - } - info.length = len; info.low_limit = mm->mmap_base; info.high_limit = mmap_end; @@ -685,27 +714,14 @@ generic_get_unmapped_area_topdown(struct unsigned long len, unsigned long pgoff, unsigned long flags, vm_flags_t vm_flags) { - struct vm_area_struct *vma, *prev; struct mm_struct *mm = current->mm; struct vm_unmapped_area_info info = {}; const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags); - /* requested length too big for entire address space */ - if (len > mmap_end - mmap_min_addr) - return -ENOMEM; - - if (flags & MAP_FIXED) - return addr; - /* requesting a specific address */ - if (addr) { - addr = PAGE_ALIGN(addr); - vma = find_vma_prev(mm, addr, &prev); - if (mmap_end - len >= addr && addr >= mmap_min_addr && - (!vma || addr + len <= vm_start_gap(vma)) && - (!prev || addr >= vm_end_gap(prev))) - return addr; - } + addr = generic_mmap_hint(filp, addr, len, pgoff, flags); + if (addr) + return addr; info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; _ Patches currently in -mm which might be from kaleshsingh@google.com are mm-introduce-generic_mmap_hint.patch mm-x86-introduce-arch_mmap_hint.patch mm-arm-introduce-arch_mmap_hint.patch mm-alpha-introduce-arch_mmap_hint.patch mm-arc-use-generic_mmap_hint.patch mm-csky-introduce-arch_mmap_hint.patch mm-loongarch-introduce-arch_mmap_hint.patch mm-mips-introduce-arch_align_mmap_hint.patch mm-parisc-introduce-arch_align_mmap_hint.patch mm-s390-use-generic_mmap_hint.patch mm-sh-introduce-arch_mmap_hint.patch mm-sparc32-introduce-arch_mmap_hint.patch mm-sparc64-introduce-arch_mmap_hint.patch mm-xtensa-introduce-arch_mmap_hint.patch mm-powerpc-introduce-arch_mmap_hint.patch mm-respect-mmap-hint-before-thp-alignment-if-allocation-is-possible.patch