All of lore.kernel.org
 help / color / mirror / Atom feed
From: Donet Tom <donettom@linux.ibm.com>
To: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Muchun Song <muchun.song@linux.dev>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Ritesh Harjani <ritesh.list@gmail.com>,
	Mike Rapoport <rppt@kernel.org>,
	David Hildenbrand <david@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	Tony Battersby <tonyb@cybernetics.com>,
	"Aneesh Kumar K . V" <aneesh.kumar@kernel.org>,
	Nicholas Piggin <npiggin@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Andy Lutomirski <luto@kernel.org>
Subject: Re: [PATCH v2] fs/hugetlbfs/inode.c: Ensure generic_hugetlb_get_unmapped_area() returns higher address than mmap_min_addr
Date: Tue, 9 Jul 2024 19:08:35 +0530	[thread overview]
Message-ID: <2ab9d7e3-3edc-4366-9c3e-100da41c4ffc@linux.ibm.com> (raw)
In-Reply-To: <kbypmoemiq43kuok7c3f3rxhzigpva6ov7ua2wfblkjmaccyes@6k4b37lj7msd>


On 7/9/24 16:04, Kirill A . Shutemov 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.
> checks are included to maintain stack gap.
Thank you. I will update and send  V3.

-Donet
>> How to reproduce
>> ================
>>
>>   #include <stdio.h>
>>   #include <stdlib.h>
>>   #include <sys/mman.h>
>>   #include <unistd.h>
>>
>>   #define HUGEPAGE_SIZE (16 * 1024 * 1024)
>>
>>   int main() {
>>
>>      void *addr = mmap((void *)-1, HUGEPAGE_SIZE,
>>                   PROT_READ | PROT_WRITE,
>>                   MAP_SHARED | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
>>      if (addr == MAP_FAILED) {
>>          perror("mmap");
>>          exit(EXIT_FAILURE);
>>      }
>>
>>      snprintf((char *)addr, HUGEPAGE_SIZE, "Hello, Huge Pages!");
>>
>>      printf("%s\n", (char *)addr);
>>
>>      if (munmap(addr, HUGEPAGE_SIZE) == -1) {
>>          perror("munmap");
>>          exit(EXIT_FAILURE);
>>      }
>>
>>      return 0;
>>   }
>>
>> Result without fix
>> ==================
>>   # cat /proc/meminfo |grep -i HugePages_Free
>>   HugePages_Free:       20
>>   # ./test
>>   mmap: Permission denied
>>   #
>>
>> Result with fix
>> ===============
>>   # cat /proc/meminfo |grep -i HugePages_Free
>>   HugePages_Free:       20
>>   # ./test
>>   Hello, Huge Pages!
>>   #
>>
>> V2:
>> Added vm_end_gap() check.
>>
>> V1:
>> https://lore.kernel.org/all/20240705071150.84972-1-donettom@linux.ibm.com/
>>
>> Reported-by Pavithra Prakash <pavrampu@linux.vnet.ibm.com>
>> Signed-off-by: Donet Tom <donettom@linux.ibm.com>
> Please use "hugetlbfs:" as subject prefix. No need to spell out full path.
>
> Otherwise,
>
> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
>

      reply	other threads:[~2024-07-09 13:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-09  9:21 [PATCH v2] fs/hugetlbfs/inode.c: Ensure generic_hugetlb_get_unmapped_area() returns higher address than mmap_min_addr Donet Tom
2024-07-09  9:56 ` Oscar Salvador
2024-07-09 13:44   ` Donet Tom
2024-07-09 14:02     ` Oscar Salvador
2024-07-09 14:26       ` Donet Tom
2024-07-09 10:34 ` Kirill A . Shutemov
2024-07-09 13:38   ` Donet Tom [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2ab9d7e3-3edc-4366-9c3e-100da41c4ffc@linux.ibm.com \
    --to=donettom@linux.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=ast@kernel.org \
    --cc=david@redhat.com \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=rppt@kernel.org \
    --cc=tonyb@cybernetics.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.