Re: [PATCH v2] fs/hugetlbfs/inode.c: Ensure generic_hugetlb_get_unmapped_area() returns higher address than mmap_min_addr

From: Donet Tom
Date: Tue Jul 09 2024 - 09:45:24 EST



On 7/9/24 15:26, Oscar Salvador wrote:
On Tue, Jul 09, 2024 at 04:21:22AM -0500, Donet Tom wrote:
generic_hugetlb_get_unmapped_area() was returning an address less
than mmap_min_addr if the mmap argument addr, after alignment, was
less than mmap_min_addr, causing mmap to fail.

This is because current generic_hugetlb_get_unmapped_area() code does
not take into account mmap_min_addr.

This patch ensures that generic_hugetlb_get_unmapped_area() always returns
an address that is greater than mmap_min_addr. Additionally, similar to
generic_get_unmapped_area(), vm_end_gap() checks are included to ensure
that the address is within the limit.
Hi Donet,

jfyi: I am already working on other parts of the kernel to avoid hugetlb code
duplication vs mm core.
I am also working on getting rid of hugetlb-unmapped_area specific code
[1].
I still need to perform some more tests but looks promising
code-deletion-wise:

arch/parisc/mm/hugetlbpage.c | 23 -------
arch/powerpc/mm/book3s64/slice.c | 49 ++++++++------
arch/s390/mm/hugetlbpage.c | 84 ------------------------
arch/s390/mm/mmap.c | 14 +++-
arch/sparc/kernel/sys_sparc_32.c | 16 +++--
arch/sparc/kernel/sys_sparc_64.c | 36 ++++++++---
arch/sparc/mm/hugetlbpage.c | 108 -------------------------------
arch/x86/kernel/sys_x86_64.c | 27 +++++---
arch/x86/mm/hugetlbpage.c | 100 ----------------------------
fs/hugetlbfs/inode.c | 97 ++-------------------------
include/linux/hugetlb.h | 10 +++
mm/mmap.c | 25 ++++++-
12 files changed, 139 insertions(+), 450 deletions(-)

I plan to post it in a day or two.

[1] https://github.com/leberus/linux/tree/hugetlb-unmapped-area
Thank you Oscar.

The issue I am trying to fix will also get fixed by this new changes right.
So should we drop my patch or should we continue it?

-Donet