diff options
author | Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> | 2013-05-07 19:18:13 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-05-07 21:38:27 -0400 |
commit | af73e4d9506d3b797509f3c030e7dcd554f7d9c4 (patch) | |
tree | f9f1bf7483495b66b6cf2cfb3c676791133733b1 /include/linux/hugetlb.h | |
parent | 1ab4ce762370b82870834899e49c08129d7ae271 (diff) |
hugetlbfs: fix mmap failure in unaligned size request
The current kernel returns -EINVAL unless a given mmap length is
"almost" hugepage aligned. This is because in sys_mmap_pgoff() the
given length is passed to vm_mmap_pgoff() as it is without being aligned
with hugepage boundary.
This is a regression introduced in commit 40716e29243d ("hugetlbfs: fix
alignment of huge page requests"), where alignment code is pushed into
hugetlb_file_setup() and the variable len in caller side is not changed.
To fix this, this patch partially reverts that commit, and adds
alignment code in caller side. And it also introduces hstate_sizelog()
in order to get proper hstate to specified hugepage size.
Addresses https://bugzilla.kernel.org/show_bug.cgi?id=56881
[akpm@linux-foundation.org: fix warning when CONFIG_HUGETLB_PAGE=n]
Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
Reported-by: <iceman_dvd@yahoo.com>
Cc: Steven Truelove <steven.truelove@utoronto.ca>
Cc: Jianguo Wu <wujianguo@huawei.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include/linux/hugetlb.h')
-rw-r--r-- | include/linux/hugetlb.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 3a62df310f2e..6b4890fa57e7 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h | |||
@@ -189,8 +189,7 @@ static inline struct hugetlbfs_sb_info *HUGETLBFS_SB(struct super_block *sb) | |||
189 | 189 | ||
190 | extern const struct file_operations hugetlbfs_file_operations; | 190 | extern const struct file_operations hugetlbfs_file_operations; |
191 | extern const struct vm_operations_struct hugetlb_vm_ops; | 191 | extern const struct vm_operations_struct hugetlb_vm_ops; |
192 | struct file *hugetlb_file_setup(const char *name, unsigned long addr, | 192 | struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct, |
193 | size_t size, vm_flags_t acct, | ||
194 | struct user_struct **user, int creat_flags, | 193 | struct user_struct **user, int creat_flags, |
195 | int page_size_log); | 194 | int page_size_log); |
196 | 195 | ||
@@ -209,8 +208,8 @@ static inline int is_file_hugepages(struct file *file) | |||
209 | 208 | ||
210 | #define is_file_hugepages(file) 0 | 209 | #define is_file_hugepages(file) 0 |
211 | static inline struct file * | 210 | static inline struct file * |
212 | hugetlb_file_setup(const char *name, unsigned long addr, size_t size, | 211 | hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag, |
213 | vm_flags_t acctflag, struct user_struct **user, int creat_flags, | 212 | struct user_struct **user, int creat_flags, |
214 | int page_size_log) | 213 | int page_size_log) |
215 | { | 214 | { |
216 | return ERR_PTR(-ENOSYS); | 215 | return ERR_PTR(-ENOSYS); |
@@ -288,6 +287,13 @@ static inline struct hstate *hstate_file(struct file *f) | |||
288 | return hstate_inode(file_inode(f)); | 287 | return hstate_inode(file_inode(f)); |
289 | } | 288 | } |
290 | 289 | ||
290 | static inline struct hstate *hstate_sizelog(int page_size_log) | ||
291 | { | ||
292 | if (!page_size_log) | ||
293 | return &default_hstate; | ||
294 | return size_to_hstate(1 << page_size_log); | ||
295 | } | ||
296 | |||
291 | static inline struct hstate *hstate_vma(struct vm_area_struct *vma) | 297 | static inline struct hstate *hstate_vma(struct vm_area_struct *vma) |
292 | { | 298 | { |
293 | return hstate_file(vma->vm_file); | 299 | return hstate_file(vma->vm_file); |
@@ -352,11 +358,12 @@ static inline int hstate_index(struct hstate *h) | |||
352 | return h - hstates; | 358 | return h - hstates; |
353 | } | 359 | } |
354 | 360 | ||
355 | #else | 361 | #else /* CONFIG_HUGETLB_PAGE */ |
356 | struct hstate {}; | 362 | struct hstate {}; |
357 | #define alloc_huge_page_node(h, nid) NULL | 363 | #define alloc_huge_page_node(h, nid) NULL |
358 | #define alloc_bootmem_huge_page(h) NULL | 364 | #define alloc_bootmem_huge_page(h) NULL |
359 | #define hstate_file(f) NULL | 365 | #define hstate_file(f) NULL |
366 | #define hstate_sizelog(s) NULL | ||
360 | #define hstate_vma(v) NULL | 367 | #define hstate_vma(v) NULL |
361 | #define hstate_inode(i) NULL | 368 | #define hstate_inode(i) NULL |
362 | #define huge_page_size(h) PAGE_SIZE | 369 | #define huge_page_size(h) PAGE_SIZE |
@@ -371,6 +378,6 @@ static inline unsigned int pages_per_huge_page(struct hstate *h) | |||
371 | } | 378 | } |
372 | #define hstate_index_to_shift(index) 0 | 379 | #define hstate_index_to_shift(index) 0 |
373 | #define hstate_index(h) 0 | 380 | #define hstate_index(h) 0 |
374 | #endif | 381 | #endif /* CONFIG_HUGETLB_PAGE */ |
375 | 382 | ||
376 | #endif /* _LINUX_HUGETLB_H */ | 383 | #endif /* _LINUX_HUGETLB_H */ |