All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jianguo Wu <wujianguo@huawei.com>
To: Joern Engel <joern@logfs.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 2/2] mmap: allow MAP_HUGETLB for hugetlbfs files
Date: Wed, 19 Jun 2013 09:22:49 +0800	[thread overview]
Message-ID: <51C107E9.9050900@huawei.com> (raw)
In-Reply-To: <1371581225-27535-3-git-send-email-joern@logfs.org>

Hi Joerni 1/4 ?

On 2013/6/19 2:47, Joern Engel wrote:

> It is counterintuitive at best that mmap'ing a hugetlbfs file with
> MAP_HUGETLB fails, while mmap'ing it without will a) succeed and b)
> return huge pages.
> 
> Signed-off-by: Joern Engel <joern@logfs.org>
> ---
>  mm/mmap.c |   12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2a594246..76eb6df 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -33,6 +33,7 @@
>  #include <linux/uprobes.h>
>  #include <linux/rbtree_augmented.h>
>  #include <linux/sched/sysctl.h>
> +#include <linux/magic.h>
>  
>  #include <asm/uaccess.h>
>  #include <asm/cacheflush.h>
> @@ -1313,6 +1314,11 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>  	return addr;
>  }
>  
> +static inline int is_hugetlb_file(struct file *file)
> +{
> +	return file->f_inode->i_sb->s_magic == HUGETLBFS_MAGIC;
> +}
> +
>  SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
>  		unsigned long, prot, unsigned long, flags,
>  		unsigned long, fd, unsigned long, pgoff)
> @@ -1322,11 +1328,12 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
>  
>  	if (!(flags & MAP_ANONYMOUS)) {
>  		audit_mmap_fd(fd, flags);
> -		if (unlikely(flags & MAP_HUGETLB))
> -			return -EINVAL;
>  		file = fget(fd);
>  		if (!file)
>  			goto out;
> +		retval = -EINVAL;
> +		if (unlikely(flags & MAP_HUGETLB && !is_hugetlb_file(file)))

We already have is_file_hugepages().

Thanks,
Jianguo Wu

> +			goto out_fput;
>  	} else if (flags & MAP_HUGETLB) {
>  		struct user_struct *user = NULL;
>  		/*
> @@ -1346,6 +1353,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
>  	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
>  
>  	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
> +out_fput:
>  	if (file)
>  		fput(file);
>  out:



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Jianguo Wu <wujianguo@huawei.com>
To: Joern Engel <joern@logfs.org>
Cc: <linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH 2/2] mmap: allow MAP_HUGETLB for hugetlbfs files
Date: Wed, 19 Jun 2013 09:22:49 +0800	[thread overview]
Message-ID: <51C107E9.9050900@huawei.com> (raw)
In-Reply-To: <1371581225-27535-3-git-send-email-joern@logfs.org>

Hi Joern,

On 2013/6/19 2:47, Joern Engel wrote:

> It is counterintuitive at best that mmap'ing a hugetlbfs file with
> MAP_HUGETLB fails, while mmap'ing it without will a) succeed and b)
> return huge pages.
> 
> Signed-off-by: Joern Engel <joern@logfs.org>
> ---
>  mm/mmap.c |   12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/mmap.c b/mm/mmap.c
> index 2a594246..76eb6df 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -33,6 +33,7 @@
>  #include <linux/uprobes.h>
>  #include <linux/rbtree_augmented.h>
>  #include <linux/sched/sysctl.h>
> +#include <linux/magic.h>
>  
>  #include <asm/uaccess.h>
>  #include <asm/cacheflush.h>
> @@ -1313,6 +1314,11 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
>  	return addr;
>  }
>  
> +static inline int is_hugetlb_file(struct file *file)
> +{
> +	return file->f_inode->i_sb->s_magic == HUGETLBFS_MAGIC;
> +}
> +
>  SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
>  		unsigned long, prot, unsigned long, flags,
>  		unsigned long, fd, unsigned long, pgoff)
> @@ -1322,11 +1328,12 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
>  
>  	if (!(flags & MAP_ANONYMOUS)) {
>  		audit_mmap_fd(fd, flags);
> -		if (unlikely(flags & MAP_HUGETLB))
> -			return -EINVAL;
>  		file = fget(fd);
>  		if (!file)
>  			goto out;
> +		retval = -EINVAL;
> +		if (unlikely(flags & MAP_HUGETLB && !is_hugetlb_file(file)))

We already have is_file_hugepages().

Thanks,
Jianguo Wu

> +			goto out_fput;
>  	} else if (flags & MAP_HUGETLB) {
>  		struct user_struct *user = NULL;
>  		/*
> @@ -1346,6 +1353,7 @@ SYSCALL_DEFINE6(mmap_pgoff, unsigned long, addr, unsigned long, len,
>  	flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE);
>  
>  	retval = vm_mmap_pgoff(file, addr, len, prot, flags, pgoff);
> +out_fput:
>  	if (file)
>  		fput(file);
>  out:




  reply	other threads:[~2013-06-19  1:23 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-18 18:47 [PATCH 0/2] hugetlb fixes Joern Engel
2013-06-18 18:47 ` Joern Engel
2013-06-18 18:47 ` [PATCH 1/2] hugetlb: properly account rss Joern Engel
2013-06-18 18:47   ` Joern Engel
2013-06-28 22:03   ` Andrew Morton
2013-06-28 22:03     ` Andrew Morton
2013-07-03 13:41   ` Steve Capper
2013-07-03 13:41     ` Steve Capper
2013-07-03 14:55     ` Steve Capper
2013-07-03 14:55       ` Steve Capper
2013-06-18 18:47 ` [PATCH 2/2] mmap: allow MAP_HUGETLB for hugetlbfs files Joern Engel
2013-06-18 18:47   ` Joern Engel
2013-06-19  1:22   ` Jianguo Wu [this message]
2013-06-19  1:22     ` Jianguo Wu
2013-06-19 16:25     ` [PATCH] mmap: allow MAP_HUGETLB for hugetlbfs files v2 Jörn Engel
2013-06-19 16:25       ` Jörn Engel
2013-06-20  1:31       ` Jianguo Wu
2013-06-20  1:31         ` Jianguo Wu
2013-06-19 16:25     ` [PATCH 2/2] mmap: allow MAP_HUGETLB for hugetlbfs files Jörn Engel
2013-06-19 16:25       ` Jörn Engel
2013-06-18 18:50 ` [PATCH 0/2] hugetlb fixes Jörn Engel
2013-06-18 18:50   ` Jörn Engel
2013-06-18 20:27   ` Andrew Morton
2013-06-18 20:27     ` Andrew Morton
2013-06-18 20:04     ` Jörn Engel
2013-06-18 20:04       ` Jörn Engel

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=51C107E9.9050900@huawei.com \
    --to=wujianguo@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=joern@logfs.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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.