Commit 516dffdcd8827a40532798602830dfcfc672294c

Authored by Adam Litke
Committed by Linus Torvalds
1 parent 7b965e0884

[PATCH] Fix get_unmapped_area and fsync for hugetlb shm segments

This patch provides the following hugetlb-related fixes to the recent stacked
shm files changes:
 - Update is_file_hugepages() so it will reconize hugetlb shm segments.
 - get_unmapped_area must be called with the nested file struct to handle
   the sfd->file->f_ops->get_unmapped_area == NULL case.
 - The fsync f_op must be wrapped since it is specified in the hugetlbfs
   f_ops.

This is based on proposed fixes from Eric Biederman that were debugged and
tested by me.  Without it, attempting to use hugetlb shared memory segments
on powerpc (and likely ia64) will kill your box.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Acked-by: William Irwin <bill.irwin@oracle.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Showing 3 changed files with 38 additions and 7 deletions Side-by-side Diff

include/linux/hugetlb.h
... ... @@ -4,6 +4,7 @@
4 4 #ifdef CONFIG_HUGETLB_PAGE
5 5  
6 6 #include <linux/mempolicy.h>
  7 +#include <linux/shm.h>
7 8 #include <asm/tlbflush.h>
8 9  
9 10 struct ctl_table;
... ... @@ -168,7 +169,12 @@
168 169  
169 170 static inline int is_file_hugepages(struct file *file)
170 171 {
171   - return file->f_op == &hugetlbfs_file_operations;
  172 + if (file->f_op == &hugetlbfs_file_operations)
  173 + return 1;
  174 + if (is_file_shm_hugepages(file))
  175 + return 1;
  176 +
  177 + return 0;
172 178 }
173 179  
174 180 static inline void set_file_hugepages(struct file *file)
... ... @@ -96,11 +96,16 @@
96 96  
97 97 #ifdef CONFIG_SYSVIPC
98 98 long do_shmat(int shmid, char __user *shmaddr, int shmflg, unsigned long *addr);
  99 +extern int is_file_shm_hugepages(struct file *file);
99 100 #else
100 101 static inline long do_shmat(int shmid, char __user *shmaddr,
101 102 int shmflg, unsigned long *addr)
102 103 {
103 104 return -ENOSYS;
  105 +}
  106 +static inline int is_file_shm_hugepages(struct file *file)
  107 +{
  108 + return 0;
104 109 }
105 110 #endif
106 111  
... ... @@ -285,21 +285,41 @@
285 285 return 0;
286 286 }
287 287  
288   -#ifndef CONFIG_MMU
  288 +static int shm_fsync(struct file *file, struct dentry *dentry, int datasync)
  289 +{
  290 + int (*fsync) (struct file *, struct dentry *, int datasync);
  291 + struct shm_file_data *sfd = shm_file_data(file);
  292 + int ret = -EINVAL;
  293 +
  294 + fsync = sfd->file->f_op->fsync;
  295 + if (fsync)
  296 + ret = fsync(sfd->file, sfd->file->f_path.dentry, datasync);
  297 + return ret;
  298 +}
  299 +
289 300 static unsigned long shm_get_unmapped_area(struct file *file,
290 301 unsigned long addr, unsigned long len, unsigned long pgoff,
291 302 unsigned long flags)
292 303 {
293 304 struct shm_file_data *sfd = shm_file_data(file);
294   - return sfd->file->f_op->get_unmapped_area(sfd->file, addr, len, pgoff,
295   - flags);
  305 + return get_unmapped_area(sfd->file, addr, len, pgoff, flags);
296 306 }
297   -#else
298   -#define shm_get_unmapped_area NULL
299   -#endif
300 307  
  308 +int is_file_shm_hugepages(struct file *file)
  309 +{
  310 + int ret = 0;
  311 +
  312 + if (file->f_op == &shm_file_operations) {
  313 + struct shm_file_data *sfd;
  314 + sfd = shm_file_data(file);
  315 + ret = is_file_hugepages(sfd->file);
  316 + }
  317 + return ret;
  318 +}
  319 +
301 320 static const struct file_operations shm_file_operations = {
302 321 .mmap = shm_mmap,
  322 + .fsync = shm_fsync,
303 323 .release = shm_release,
304 324 .get_unmapped_area = shm_get_unmapped_area,
305 325 };