All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] refactor shmem_get_unmapped_area()
@ 2016-09-09 22:24 ` Toshi Kani
  0 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: linux-nvdimm, mawilcox, hughd, linux-kernel, linux-mm, kirill.shutemov

shmem_get_unmapped_area() provides a functionality similar
to __thp_get_unmapped_area() as both allocate a pmd-aligned
address.  This patchset changes shmem_get_unmapped_area()
to call __thp_get_unmapped_area() to share the code.

Patch 1 fixes a bug in shmem_get_unmapped_area() first.
Patch 2 changes shmem_get_unmapped_area() to call
__thp_get_unmapped_area() for sharing the code.

This patch-set applies on top of my patchset below.
https://lkml.org/lkml/2016/8/29/560

---
Toshi Kani (2):
 1/2 shmem: fix tmpfs to handle the huge= option properly
 2/2 shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr

---
 include/linux/huge_mm.h | 10 +++++++
 mm/shmem.c              | 70 ++++++++++---------------------------------------
 2 files changed, 24 insertions(+), 56 deletions(-)

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 0/2] refactor shmem_get_unmapped_area()
@ 2016-09-09 22:24 ` Toshi Kani
  0 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, toshi.kani,
	linux-nvdimm, linux-mm, linux-kernel

shmem_get_unmapped_area() provides a functionality similar
to __thp_get_unmapped_area() as both allocate a pmd-aligned
address.  This patchset changes shmem_get_unmapped_area()
to call __thp_get_unmapped_area() to share the code.

Patch 1 fixes a bug in shmem_get_unmapped_area() first.
Patch 2 changes shmem_get_unmapped_area() to call
__thp_get_unmapped_area() for sharing the code.

This patch-set applies on top of my patchset below.
https://lkml.org/lkml/2016/8/29/560

---
Toshi Kani (2):
 1/2 shmem: fix tmpfs to handle the huge= option properly
 2/2 shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr

---
 include/linux/huge_mm.h | 10 +++++++
 mm/shmem.c              | 70 ++++++++++---------------------------------------
 2 files changed, 24 insertions(+), 56 deletions(-)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 0/2] refactor shmem_get_unmapped_area()
@ 2016-09-09 22:24 ` Toshi Kani
  0 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, toshi.kani,
	linux-nvdimm, linux-mm, linux-kernel

shmem_get_unmapped_area() provides a functionality similar
to __thp_get_unmapped_area() as both allocate a pmd-aligned
address.  This patchset changes shmem_get_unmapped_area()
to call __thp_get_unmapped_area() to share the code.

Patch 1 fixes a bug in shmem_get_unmapped_area() first.
Patch 2 changes shmem_get_unmapped_area() to call
__thp_get_unmapped_area() for sharing the code.

This patch-set applies on top of my patchset below.
https://lkml.org/lkml/2016/8/29/560

---
Toshi Kani (2):
 1/2 shmem: fix tmpfs to handle the huge= option properly
 2/2 shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr

---
 include/linux/huge_mm.h | 10 +++++++
 mm/shmem.c              | 70 ++++++++++---------------------------------------
 2 files changed, 24 insertions(+), 56 deletions(-)

--
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>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
  2016-09-09 22:24 ` Toshi Kani
  (?)
@ 2016-09-09 22:24   ` Toshi Kani
  -1 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: linux-nvdimm, mawilcox, hughd, linux-kernel, linux-mm, kirill.shutemov

shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
which leads to a reversed effect of "huge=" mount option.

Fix the check in shmem_get_unmapped_area().

Note, the default value of SHMEM_SB(sb)->huge remains as
SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
enable huge page mappings.

Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
---
 mm/shmem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index fd8b2b5..aec5b49 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 				return addr;
 			sb = shm_mnt->mnt_sb;
 		}
-		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
+		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
 			return addr;
 	}
 
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-09 22:24   ` Toshi Kani
  0 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, toshi.kani,
	linux-nvdimm, linux-mm, linux-kernel

shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
which leads to a reversed effect of "huge=" mount option.

Fix the check in shmem_get_unmapped_area().

Note, the default value of SHMEM_SB(sb)->huge remains as
SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
enable huge page mappings.

Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
---
 mm/shmem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index fd8b2b5..aec5b49 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 				return addr;
 			sb = shm_mnt->mnt_sb;
 		}
-		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
+		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
 			return addr;
 	}
 

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-09 22:24   ` Toshi Kani
  0 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, toshi.kani,
	linux-nvdimm, linux-mm, linux-kernel

shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
which leads to a reversed effect of "huge=" mount option.

Fix the check in shmem_get_unmapped_area().

Note, the default value of SHMEM_SB(sb)->huge remains as
SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
enable huge page mappings.

Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
---
 mm/shmem.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index fd8b2b5..aec5b49 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 				return addr;
 			sb = shm_mnt->mnt_sb;
 		}
-		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
+		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
 			return addr;
 	}
 

--
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>

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr
  2016-09-09 22:24 ` Toshi Kani
  (?)
@ 2016-09-09 22:24   ` Toshi Kani
  -1 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: linux-nvdimm, mawilcox, hughd, linux-kernel, linux-mm, kirill.shutemov

shmem_get_unmapped_area() provides a functionality similar
to __thp_get_unmapped_area() as both allocate a pmd-aligned
address.

Change shmem_get_unmapped_area() to do shm-specific checks
and then call __thp_get_unmapped_area() for allocating
a pmd-aligned address.

link: https://lkml.org/lkml/2016/8/29/620
Suggested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Dan Williams <dan.j.williams@intel.com>
---
 include/linux/huge_mm.h |   10 +++++++
 mm/shmem.c              |   68 +++++++++--------------------------------------
 2 files changed, 23 insertions(+), 55 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 4fca526..1b65924 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -90,6 +90,9 @@ extern unsigned long transparent_hugepage_flags;
 extern unsigned long thp_get_unmapped_area(struct file *filp,
 		unsigned long addr, unsigned long len, unsigned long pgoff,
 		unsigned long flags);
+extern unsigned long __thp_get_unmapped_area(struct file *filp,
+		unsigned long len, loff_t off, unsigned long flags,
+		unsigned long size);
 
 extern void prep_transhuge_page(struct page *page);
 extern void free_transhuge_page(struct page *page);
@@ -176,6 +179,13 @@ static inline void prep_transhuge_page(struct page *page) {}
 
 #define thp_get_unmapped_area	NULL
 
+static inline unsigned long __thp_get_unmapped_area(struct file *filp,
+		unsigned long len, loff_t off, unsigned long flags,
+		unsigned long size)
+{
+	return 0;
+}
+
 static inline int
 split_huge_page_to_list(struct page *page, struct list_head *list)
 {
diff --git a/mm/shmem.c b/mm/shmem.c
index aec5b49..ef27455 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1925,45 +1925,23 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 }
 
 unsigned long shmem_get_unmapped_area(struct file *file,
-				      unsigned long uaddr, unsigned long len,
+				      unsigned long addr, unsigned long len,
 				      unsigned long pgoff, unsigned long flags)
 {
-	unsigned long (*get_area)(struct file *,
-		unsigned long, unsigned long, unsigned long, unsigned long);
-	unsigned long addr;
-	unsigned long offset;
-	unsigned long inflated_len;
-	unsigned long inflated_addr;
-	unsigned long inflated_offset;
-
-	if (len > TASK_SIZE)
-		return -ENOMEM;
-
-	get_area = current->mm->get_unmapped_area;
-	addr = get_area(file, uaddr, len, pgoff, flags);
+	loff_t off = (loff_t)pgoff << PAGE_SHIFT;
 
 	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE))
-		return addr;
-	if (IS_ERR_VALUE(addr))
-		return addr;
-	if (addr & ~PAGE_MASK)
-		return addr;
-	if (addr > TASK_SIZE - len)
-		return addr;
-
+		goto out;
 	if (shmem_huge == SHMEM_HUGE_DENY)
-		return addr;
-	if (len < HPAGE_PMD_SIZE)
-		return addr;
-	if (flags & MAP_FIXED)
-		return addr;
+		goto out;
+
 	/*
 	 * Our priority is to support MAP_SHARED mapped hugely;
 	 * and support MAP_PRIVATE mapped hugely too, until it is COWed.
 	 * But if caller specified an address hint, respect that as before.
 	 */
-	if (uaddr)
-		return addr;
+	if (addr)
+		goto out;
 
 	if (shmem_huge != SHMEM_HUGE_FORCE) {
 		struct super_block *sb;
@@ -1977,39 +1955,19 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 			 * for "/dev/zero", to create a shared anonymous object.
 			 */
 			if (IS_ERR(shm_mnt))
-				return addr;
+				goto out;
 			sb = shm_mnt->mnt_sb;
 		}
 		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
-			return addr;
+			goto out;
 	}
 
-	offset = (pgoff << PAGE_SHIFT) & (HPAGE_PMD_SIZE-1);
-	if (offset && offset + len < 2 * HPAGE_PMD_SIZE)
-		return addr;
-	if ((addr & (HPAGE_PMD_SIZE-1)) == offset)
-		return addr;
-
-	inflated_len = len + HPAGE_PMD_SIZE - PAGE_SIZE;
-	if (inflated_len > TASK_SIZE)
-		return addr;
-	if (inflated_len < len)
-		return addr;
-
-	inflated_addr = get_area(NULL, 0, inflated_len, 0, flags);
-	if (IS_ERR_VALUE(inflated_addr))
-		return addr;
-	if (inflated_addr & ~PAGE_MASK)
+	addr = __thp_get_unmapped_area(file, len, off, flags, HPAGE_PMD_SIZE);
+	if (addr)
 		return addr;
 
-	inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1);
-	inflated_addr += offset - inflated_offset;
-	if (inflated_offset > offset)
-		inflated_addr += HPAGE_PMD_SIZE;
-
-	if (inflated_addr > TASK_SIZE - len)
-		return addr;
-	return inflated_addr;
+ out:
+	return current->mm->get_unmapped_area(file, addr, len, pgoff, flags);
 }
 
 #ifdef CONFIG_NUMA
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr
@ 2016-09-09 22:24   ` Toshi Kani
  0 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, toshi.kani,
	linux-nvdimm, linux-mm, linux-kernel

shmem_get_unmapped_area() provides a functionality similar
to __thp_get_unmapped_area() as both allocate a pmd-aligned
address.

Change shmem_get_unmapped_area() to do shm-specific checks
and then call __thp_get_unmapped_area() for allocating
a pmd-aligned address.

link: https://lkml.org/lkml/2016/8/29/620
Suggested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Dan Williams <dan.j.williams@intel.com>
---
 include/linux/huge_mm.h |   10 +++++++
 mm/shmem.c              |   68 +++++++++--------------------------------------
 2 files changed, 23 insertions(+), 55 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 4fca526..1b65924 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -90,6 +90,9 @@ extern unsigned long transparent_hugepage_flags;
 extern unsigned long thp_get_unmapped_area(struct file *filp,
 		unsigned long addr, unsigned long len, unsigned long pgoff,
 		unsigned long flags);
+extern unsigned long __thp_get_unmapped_area(struct file *filp,
+		unsigned long len, loff_t off, unsigned long flags,
+		unsigned long size);
 
 extern void prep_transhuge_page(struct page *page);
 extern void free_transhuge_page(struct page *page);
@@ -176,6 +179,13 @@ static inline void prep_transhuge_page(struct page *page) {}
 
 #define thp_get_unmapped_area	NULL
 
+static inline unsigned long __thp_get_unmapped_area(struct file *filp,
+		unsigned long len, loff_t off, unsigned long flags,
+		unsigned long size)
+{
+	return 0;
+}
+
 static inline int
 split_huge_page_to_list(struct page *page, struct list_head *list)
 {
diff --git a/mm/shmem.c b/mm/shmem.c
index aec5b49..ef27455 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1925,45 +1925,23 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 }
 
 unsigned long shmem_get_unmapped_area(struct file *file,
-				      unsigned long uaddr, unsigned long len,
+				      unsigned long addr, unsigned long len,
 				      unsigned long pgoff, unsigned long flags)
 {
-	unsigned long (*get_area)(struct file *,
-		unsigned long, unsigned long, unsigned long, unsigned long);
-	unsigned long addr;
-	unsigned long offset;
-	unsigned long inflated_len;
-	unsigned long inflated_addr;
-	unsigned long inflated_offset;
-
-	if (len > TASK_SIZE)
-		return -ENOMEM;
-
-	get_area = current->mm->get_unmapped_area;
-	addr = get_area(file, uaddr, len, pgoff, flags);
+	loff_t off = (loff_t)pgoff << PAGE_SHIFT;
 
 	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE))
-		return addr;
-	if (IS_ERR_VALUE(addr))
-		return addr;
-	if (addr & ~PAGE_MASK)
-		return addr;
-	if (addr > TASK_SIZE - len)
-		return addr;
-
+		goto out;
 	if (shmem_huge == SHMEM_HUGE_DENY)
-		return addr;
-	if (len < HPAGE_PMD_SIZE)
-		return addr;
-	if (flags & MAP_FIXED)
-		return addr;
+		goto out;
+
 	/*
 	 * Our priority is to support MAP_SHARED mapped hugely;
 	 * and support MAP_PRIVATE mapped hugely too, until it is COWed.
 	 * But if caller specified an address hint, respect that as before.
 	 */
-	if (uaddr)
-		return addr;
+	if (addr)
+		goto out;
 
 	if (shmem_huge != SHMEM_HUGE_FORCE) {
 		struct super_block *sb;
@@ -1977,39 +1955,19 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 			 * for "/dev/zero", to create a shared anonymous object.
 			 */
 			if (IS_ERR(shm_mnt))
-				return addr;
+				goto out;
 			sb = shm_mnt->mnt_sb;
 		}
 		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
-			return addr;
+			goto out;
 	}
 
-	offset = (pgoff << PAGE_SHIFT) & (HPAGE_PMD_SIZE-1);
-	if (offset && offset + len < 2 * HPAGE_PMD_SIZE)
-		return addr;
-	if ((addr & (HPAGE_PMD_SIZE-1)) == offset)
-		return addr;
-
-	inflated_len = len + HPAGE_PMD_SIZE - PAGE_SIZE;
-	if (inflated_len > TASK_SIZE)
-		return addr;
-	if (inflated_len < len)
-		return addr;
-
-	inflated_addr = get_area(NULL, 0, inflated_len, 0, flags);
-	if (IS_ERR_VALUE(inflated_addr))
-		return addr;
-	if (inflated_addr & ~PAGE_MASK)
+	addr = __thp_get_unmapped_area(file, len, off, flags, HPAGE_PMD_SIZE);
+	if (addr)
 		return addr;
 
-	inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1);
-	inflated_addr += offset - inflated_offset;
-	if (inflated_offset > offset)
-		inflated_addr += HPAGE_PMD_SIZE;
-
-	if (inflated_addr > TASK_SIZE - len)
-		return addr;
-	return inflated_addr;
+ out:
+	return current->mm->get_unmapped_area(file, addr, len, pgoff, flags);
 }
 
 #ifdef CONFIG_NUMA

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr
@ 2016-09-09 22:24   ` Toshi Kani
  0 siblings, 0 replies; 20+ messages in thread
From: Toshi Kani @ 2016-09-09 22:24 UTC (permalink / raw)
  To: akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, toshi.kani,
	linux-nvdimm, linux-mm, linux-kernel

shmem_get_unmapped_area() provides a functionality similar
to __thp_get_unmapped_area() as both allocate a pmd-aligned
address.

Change shmem_get_unmapped_area() to do shm-specific checks
and then call __thp_get_unmapped_area() for allocating
a pmd-aligned address.

link: https://lkml.org/lkml/2016/8/29/620
Suggested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Dan Williams <dan.j.williams@intel.com>
---
 include/linux/huge_mm.h |   10 +++++++
 mm/shmem.c              |   68 +++++++++--------------------------------------
 2 files changed, 23 insertions(+), 55 deletions(-)

diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h
index 4fca526..1b65924 100644
--- a/include/linux/huge_mm.h
+++ b/include/linux/huge_mm.h
@@ -90,6 +90,9 @@ extern unsigned long transparent_hugepage_flags;
 extern unsigned long thp_get_unmapped_area(struct file *filp,
 		unsigned long addr, unsigned long len, unsigned long pgoff,
 		unsigned long flags);
+extern unsigned long __thp_get_unmapped_area(struct file *filp,
+		unsigned long len, loff_t off, unsigned long flags,
+		unsigned long size);
 
 extern void prep_transhuge_page(struct page *page);
 extern void free_transhuge_page(struct page *page);
@@ -176,6 +179,13 @@ static inline void prep_transhuge_page(struct page *page) {}
 
 #define thp_get_unmapped_area	NULL
 
+static inline unsigned long __thp_get_unmapped_area(struct file *filp,
+		unsigned long len, loff_t off, unsigned long flags,
+		unsigned long size)
+{
+	return 0;
+}
+
 static inline int
 split_huge_page_to_list(struct page *page, struct list_head *list)
 {
diff --git a/mm/shmem.c b/mm/shmem.c
index aec5b49..ef27455 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -1925,45 +1925,23 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 }
 
 unsigned long shmem_get_unmapped_area(struct file *file,
-				      unsigned long uaddr, unsigned long len,
+				      unsigned long addr, unsigned long len,
 				      unsigned long pgoff, unsigned long flags)
 {
-	unsigned long (*get_area)(struct file *,
-		unsigned long, unsigned long, unsigned long, unsigned long);
-	unsigned long addr;
-	unsigned long offset;
-	unsigned long inflated_len;
-	unsigned long inflated_addr;
-	unsigned long inflated_offset;
-
-	if (len > TASK_SIZE)
-		return -ENOMEM;
-
-	get_area = current->mm->get_unmapped_area;
-	addr = get_area(file, uaddr, len, pgoff, flags);
+	loff_t off = (loff_t)pgoff << PAGE_SHIFT;
 
 	if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGE_PAGECACHE))
-		return addr;
-	if (IS_ERR_VALUE(addr))
-		return addr;
-	if (addr & ~PAGE_MASK)
-		return addr;
-	if (addr > TASK_SIZE - len)
-		return addr;
-
+		goto out;
 	if (shmem_huge == SHMEM_HUGE_DENY)
-		return addr;
-	if (len < HPAGE_PMD_SIZE)
-		return addr;
-	if (flags & MAP_FIXED)
-		return addr;
+		goto out;
+
 	/*
 	 * Our priority is to support MAP_SHARED mapped hugely;
 	 * and support MAP_PRIVATE mapped hugely too, until it is COWed.
 	 * But if caller specified an address hint, respect that as before.
 	 */
-	if (uaddr)
-		return addr;
+	if (addr)
+		goto out;
 
 	if (shmem_huge != SHMEM_HUGE_FORCE) {
 		struct super_block *sb;
@@ -1977,39 +1955,19 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 			 * for "/dev/zero", to create a shared anonymous object.
 			 */
 			if (IS_ERR(shm_mnt))
-				return addr;
+				goto out;
 			sb = shm_mnt->mnt_sb;
 		}
 		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
-			return addr;
+			goto out;
 	}
 
-	offset = (pgoff << PAGE_SHIFT) & (HPAGE_PMD_SIZE-1);
-	if (offset && offset + len < 2 * HPAGE_PMD_SIZE)
-		return addr;
-	if ((addr & (HPAGE_PMD_SIZE-1)) == offset)
-		return addr;
-
-	inflated_len = len + HPAGE_PMD_SIZE - PAGE_SIZE;
-	if (inflated_len > TASK_SIZE)
-		return addr;
-	if (inflated_len < len)
-		return addr;
-
-	inflated_addr = get_area(NULL, 0, inflated_len, 0, flags);
-	if (IS_ERR_VALUE(inflated_addr))
-		return addr;
-	if (inflated_addr & ~PAGE_MASK)
+	addr = __thp_get_unmapped_area(file, len, off, flags, HPAGE_PMD_SIZE);
+	if (addr)
 		return addr;
 
-	inflated_offset = inflated_addr & (HPAGE_PMD_SIZE-1);
-	inflated_addr += offset - inflated_offset;
-	if (inflated_offset > offset)
-		inflated_addr += HPAGE_PMD_SIZE;
-
-	if (inflated_addr > TASK_SIZE - len)
-		return addr;
-	return inflated_addr;
+ out:
+	return current->mm->get_unmapped_area(file, addr, len, pgoff, flags);
 }
 
 #ifdef CONFIG_NUMA

--
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>

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
  2016-09-09 22:24   ` Toshi Kani
  (?)
@ 2016-09-12  9:59     ` Kirill A. Shutemov
  -1 siblings, 0 replies; 20+ messages in thread
From: Kirill A. Shutemov @ 2016-09-12  9:59 UTC (permalink / raw)
  To: Toshi Kani
  Cc: linux-nvdimm, mawilcox, hughd, linux-kernel, linux-mm, akpm,
	kirill.shutemov

On Fri, Sep 09, 2016 at 04:24:22PM -0600, Toshi Kani wrote:
> shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> which leads to a reversed effect of "huge=" mount option.
> 
> Fix the check in shmem_get_unmapped_area().
> 
> Note, the default value of SHMEM_SB(sb)->huge remains as
> SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> enable huge page mappings.
> 
> Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-12  9:59     ` Kirill A. Shutemov
  0 siblings, 0 replies; 20+ messages in thread
From: Kirill A. Shutemov @ 2016-09-12  9:59 UTC (permalink / raw)
  To: Toshi Kani
  Cc: akpm, dan.j.williams, mawilcox, hughd, kirill.shutemov,
	linux-nvdimm, linux-mm, linux-kernel

On Fri, Sep 09, 2016 at 04:24:22PM -0600, Toshi Kani wrote:
> shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> which leads to a reversed effect of "huge=" mount option.
> 
> Fix the check in shmem_get_unmapped_area().
> 
> Note, the default value of SHMEM_SB(sb)->huge remains as
> SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> enable huge page mappings.
> 
> Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-12  9:59     ` Kirill A. Shutemov
  0 siblings, 0 replies; 20+ messages in thread
From: Kirill A. Shutemov @ 2016-09-12  9:59 UTC (permalink / raw)
  To: Toshi Kani
  Cc: akpm, dan.j.williams, mawilcox, hughd, kirill.shutemov,
	linux-nvdimm, linux-mm, linux-kernel

On Fri, Sep 09, 2016 at 04:24:22PM -0600, Toshi Kani wrote:
> shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> which leads to a reversed effect of "huge=" mount option.
> 
> Fix the check in shmem_get_unmapped_area().
> 
> Note, the default value of SHMEM_SB(sb)->huge remains as
> SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> enable huge page mappings.
> 
> Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov

--
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>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr
  2016-09-09 22:24   ` Toshi Kani
@ 2016-09-12 10:02     ` Kirill A. Shutemov
  -1 siblings, 0 replies; 20+ messages in thread
From: Kirill A. Shutemov @ 2016-09-12 10:02 UTC (permalink / raw)
  To: Toshi Kani
  Cc: akpm, dan.j.williams, mawilcox, hughd, kirill.shutemov,
	linux-nvdimm, linux-mm, linux-kernel

On Fri, Sep 09, 2016 at 04:24:23PM -0600, Toshi Kani wrote:
> shmem_get_unmapped_area() provides a functionality similar
> to __thp_get_unmapped_area() as both allocate a pmd-aligned
> address.
> 
> Change shmem_get_unmapped_area() to do shm-specific checks
> and then call __thp_get_unmapped_area() for allocating
> a pmd-aligned address.
> 
> link: https://lkml.org/lkml/2016/8/29/620
> Suggested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Matthew Wilcox <mawilcox@microsoft.com>
> Cc: Dan Williams <dan.j.williams@intel.com>

Looks good to me. Thanks.

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov

--
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>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr
@ 2016-09-12 10:02     ` Kirill A. Shutemov
  0 siblings, 0 replies; 20+ messages in thread
From: Kirill A. Shutemov @ 2016-09-12 10:02 UTC (permalink / raw)
  To: Toshi Kani
  Cc: akpm, dan.j.williams, mawilcox, hughd, kirill.shutemov,
	linux-nvdimm, linux-mm, linux-kernel

On Fri, Sep 09, 2016 at 04:24:23PM -0600, Toshi Kani wrote:
> shmem_get_unmapped_area() provides a functionality similar
> to __thp_get_unmapped_area() as both allocate a pmd-aligned
> address.
> 
> Change shmem_get_unmapped_area() to do shm-specific checks
> and then call __thp_get_unmapped_area() for allocating
> a pmd-aligned address.
> 
> link: https://lkml.org/lkml/2016/8/29/620
> Suggested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: Matthew Wilcox <mawilcox@microsoft.com>
> Cc: Dan Williams <dan.j.williams@intel.com>

Looks good to me. Thanks.

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

-- 
 Kirill A. Shutemov

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
  2016-09-09 22:24   ` Toshi Kani
  (?)
@ 2016-09-22 10:58     ` Aneesh Kumar K.V
  -1 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2016-09-22 10:58 UTC (permalink / raw)
  To: Toshi Kani, akpm
  Cc: linux-nvdimm, mawilcox, hughd, linux-kernel, linux-mm, kirill.shutemov

Toshi Kani <toshi.kani@hpe.com> writes:

> shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> which leads to a reversed effect of "huge=" mount option.
>
> Fix the check in shmem_get_unmapped_area().
>
> Note, the default value of SHMEM_SB(sb)->huge remains as
> SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> enable huge page mappings.
>

Any update on getting this merged ?

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

> Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>
> ---
>  mm/shmem.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index fd8b2b5..aec5b49 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
>  				return addr;
>  			sb = shm_mnt->mnt_sb;
>  		}
> -		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
> +		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
>  			return addr;
>  	}
>  
>
> --
> 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>

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-22 10:58     ` Aneesh Kumar K.V
  0 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2016-09-22 10:58 UTC (permalink / raw)
  To: Toshi Kani, akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, toshi.kani,
	linux-nvdimm, linux-mm, linux-kernel

Toshi Kani <toshi.kani@hpe.com> writes:

> shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> which leads to a reversed effect of "huge=" mount option.
>
> Fix the check in shmem_get_unmapped_area().
>
> Note, the default value of SHMEM_SB(sb)->huge remains as
> SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> enable huge page mappings.
>

Any update on getting this merged ?

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

> Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>
> ---
>  mm/shmem.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index fd8b2b5..aec5b49 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
>  				return addr;
>  			sb = shm_mnt->mnt_sb;
>  		}
> -		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
> +		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
>  			return addr;
>  	}
>  
>
> --
> 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>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-22 10:58     ` Aneesh Kumar K.V
  0 siblings, 0 replies; 20+ messages in thread
From: Aneesh Kumar K.V @ 2016-09-22 10:58 UTC (permalink / raw)
  To: Toshi Kani, akpm
  Cc: dan.j.williams, mawilcox, hughd, kirill.shutemov, linux-nvdimm,
	linux-mm, linux-kernel

Toshi Kani <toshi.kani@hpe.com> writes:

> shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> which leads to a reversed effect of "huge=" mount option.
>
> Fix the check in shmem_get_unmapped_area().
>
> Note, the default value of SHMEM_SB(sb)->huge remains as
> SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> enable huge page mappings.
>

Any update on getting this merged ?

Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

> Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Hugh Dickins <hughd@google.com>
> ---
>  mm/shmem.c |    2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/shmem.c b/mm/shmem.c
> index fd8b2b5..aec5b49 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
>  				return addr;
>  			sb = shm_mnt->mnt_sb;
>  		}
> -		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
> +		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
>  			return addr;
>  	}
>  
>
> --
> 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>

--
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>

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
  2016-09-22 10:58     ` Aneesh Kumar K.V
  (?)
@ 2016-09-23  2:33       ` Hugh Dickins
  -1 siblings, 0 replies; 20+ messages in thread
From: Hugh Dickins @ 2016-09-23  2:33 UTC (permalink / raw)
  To: Andrew Morton
  Cc: mawilcox, Hillf Danton, hughd, linux-kernel, linux-mm,
	linux-nvdimm, Aneesh Kumar K.V, kirill.shutemov

On Thu, 22 Sep 2016, Aneesh Kumar K.V wrote:
> Toshi Kani <toshi.kani@hpe.com> writes:
> 
> > shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> > which leads to a reversed effect of "huge=" mount option.
> >
> > Fix the check in shmem_get_unmapped_area().
> >
> > Note, the default value of SHMEM_SB(sb)->huge remains as
> > SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> > enable huge page mappings.
> >
> 
> Any update on getting this merged ?
> 
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

Yikes, how did we ever not notice this?  Very embarrassing.

Huge thank you to Hillf for spotting it (only now do I rediscover
your June mail: I'm sorry, my attention has been fully elsewhere).

Big thank you to Toshi for sending the patch,
and to Aneesh for now sounding the alarm.

The only reassurance is that at least all the rest of it has
been under test for the last few months, via the SHMEM_HUGE_FORCE
override.  So it's not as if none of the code has been tested,
but I am still mystified why it hasn't been obvious without.

To the patch,
Acked-by: Hugh Dickins <hughd@google.com>
but I wish I could dream up a more emphatic tag.

Andrew, please please grab this and send it in!

Thank you,
Hugh

> 
> > Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> > Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Cc: Hugh Dickins <hughd@google.com>
> > ---
> >  mm/shmem.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index fd8b2b5..aec5b49 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
> >  				return addr;
> >  			sb = shm_mnt->mnt_sb;
> >  		}
> > -		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
> > +		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
> >  			return addr;
> >  	}
> >  
> >
> > --
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-23  2:33       ` Hugh Dickins
  0 siblings, 0 replies; 20+ messages in thread
From: Hugh Dickins @ 2016-09-23  2:33 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Aneesh Kumar K.V, Toshi Kani, Hillf Danton, dan.j.williams,
	mawilcox, hughd, kirill.shutemov, linux-nvdimm, linux-mm,
	linux-kernel

On Thu, 22 Sep 2016, Aneesh Kumar K.V wrote:
> Toshi Kani <toshi.kani@hpe.com> writes:
> 
> > shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> > which leads to a reversed effect of "huge=" mount option.
> >
> > Fix the check in shmem_get_unmapped_area().
> >
> > Note, the default value of SHMEM_SB(sb)->huge remains as
> > SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> > enable huge page mappings.
> >
> 
> Any update on getting this merged ?
> 
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

Yikes, how did we ever not notice this?  Very embarrassing.

Huge thank you to Hillf for spotting it (only now do I rediscover
your June mail: I'm sorry, my attention has been fully elsewhere).

Big thank you to Toshi for sending the patch,
and to Aneesh for now sounding the alarm.

The only reassurance is that at least all the rest of it has
been under test for the last few months, via the SHMEM_HUGE_FORCE
override.  So it's not as if none of the code has been tested,
but I am still mystified why it hasn't been obvious without.

To the patch,
Acked-by: Hugh Dickins <hughd@google.com>
but I wish I could dream up a more emphatic tag.

Andrew, please please grab this and send it in!

Thank you,
Hugh

> 
> > Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> > Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Cc: Hugh Dickins <hughd@google.com>
> > ---
> >  mm/shmem.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index fd8b2b5..aec5b49 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
> >  				return addr;
> >  			sb = shm_mnt->mnt_sb;
> >  		}
> > -		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
> > +		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
> >  			return addr;
> >  	}
> >  
> >
> > --

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly
@ 2016-09-23  2:33       ` Hugh Dickins
  0 siblings, 0 replies; 20+ messages in thread
From: Hugh Dickins @ 2016-09-23  2:33 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Aneesh Kumar K.V, Toshi Kani, Hillf Danton, dan.j.williams,
	mawilcox, hughd, kirill.shutemov, linux-nvdimm, linux-mm,
	linux-kernel

On Thu, 22 Sep 2016, Aneesh Kumar K.V wrote:
> Toshi Kani <toshi.kani@hpe.com> writes:
> 
> > shmem_get_unmapped_area() checks SHMEM_SB(sb)->huge incorrectly,
> > which leads to a reversed effect of "huge=" mount option.
> >
> > Fix the check in shmem_get_unmapped_area().
> >
> > Note, the default value of SHMEM_SB(sb)->huge remains as
> > SHMEM_HUGE_NEVER.  User will need to specify "huge=" option to
> > enable huge page mappings.
> >
> 
> Any update on getting this merged ?
> 
> Reviewed-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>

Yikes, how did we ever not notice this?  Very embarrassing.

Huge thank you to Hillf for spotting it (only now do I rediscover
your June mail: I'm sorry, my attention has been fully elsewhere).

Big thank you to Toshi for sending the patch,
and to Aneesh for now sounding the alarm.

The only reassurance is that at least all the rest of it has
been under test for the last few months, via the SHMEM_HUGE_FORCE
override.  So it's not as if none of the code has been tested,
but I am still mystified why it hasn't been obvious without.

To the patch,
Acked-by: Hugh Dickins <hughd@google.com>
but I wish I could dream up a more emphatic tag.

Andrew, please please grab this and send it in!

Thank you,
Hugh

> 
> > Reported-by: Hillf Danton <hillf.zj@alibaba-inc.com>
> > Signed-off-by: Toshi Kani <toshi.kani@hpe.com>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> > Cc: Hugh Dickins <hughd@google.com>
> > ---
> >  mm/shmem.c |    2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index fd8b2b5..aec5b49 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -1980,7 +1980,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
> >  				return addr;
> >  			sb = shm_mnt->mnt_sb;
> >  		}
> > -		if (SHMEM_SB(sb)->huge != SHMEM_HUGE_NEVER)
> > +		if (SHMEM_SB(sb)->huge == SHMEM_HUGE_NEVER)
> >  			return addr;
> >  	}
> >  
> >
> > --

--
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>

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2016-09-23  2:33 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-09 22:24 [PATCH 0/2] refactor shmem_get_unmapped_area() Toshi Kani
2016-09-09 22:24 ` Toshi Kani
2016-09-09 22:24 ` Toshi Kani
2016-09-09 22:24 ` [PATCH 1/2] shmem: fix tmpfs to handle the huge= option properly Toshi Kani
2016-09-09 22:24   ` Toshi Kani
2016-09-09 22:24   ` Toshi Kani
2016-09-12  9:59   ` Kirill A. Shutemov
2016-09-12  9:59     ` Kirill A. Shutemov
2016-09-12  9:59     ` Kirill A. Shutemov
2016-09-22 10:58   ` Aneesh Kumar K.V
2016-09-22 10:58     ` Aneesh Kumar K.V
2016-09-22 10:58     ` Aneesh Kumar K.V
2016-09-23  2:33     ` Hugh Dickins
2016-09-23  2:33       ` Hugh Dickins
2016-09-23  2:33       ` Hugh Dickins
2016-09-09 22:24 ` [PATCH 2/2] shmem: call __thp_get_unmapped_area to alloc a pmd-aligned addr Toshi Kani
2016-09-09 22:24   ` Toshi Kani
2016-09-09 22:24   ` Toshi Kani
2016-09-12 10:02   ` Kirill A. Shutemov
2016-09-12 10:02     ` Kirill A. Shutemov

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.