hugetlbfs: fix alignment of huge page requests
When calling shmget() with SHM_HUGETLB, shmget aligns the request size to PAGE_SIZE, but this is not sufficient. Modify hugetlb_file_setup() to align requests to the huge page size, and to accept an address argument so that all alignment checks can be performed in hugetlb_file_setup(), rather than in its callers. Change newseg() and mmap_pgoff() to match the new prototype and eliminate a now redundant alignment check. [akpm@linux-foundation.org: fix build] Signed-off-by: Steven Truelove <steven.truelove@utoronto.ca> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:

committed by
Linus Torvalds

parent
21a3c273f8
commit
40716e2924
@@ -935,8 +935,8 @@ static int can_do_hugetlb_shm(void)
|
||||
return capable(CAP_IPC_LOCK) || in_group_p(sysctl_hugetlb_shm_group);
|
||||
}
|
||||
|
||||
struct file *hugetlb_file_setup(const char *name, size_t size,
|
||||
vm_flags_t acctflag,
|
||||
struct file *hugetlb_file_setup(const char *name, unsigned long addr,
|
||||
size_t size, vm_flags_t acctflag,
|
||||
struct user_struct **user, int creat_flags)
|
||||
{
|
||||
int error = -ENOMEM;
|
||||
@@ -945,6 +945,8 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
|
||||
struct path path;
|
||||
struct dentry *root;
|
||||
struct qstr quick_string;
|
||||
struct hstate *hstate;
|
||||
unsigned long num_pages;
|
||||
|
||||
*user = NULL;
|
||||
if (!hugetlbfs_vfsmount)
|
||||
@@ -978,10 +980,12 @@ struct file *hugetlb_file_setup(const char *name, size_t size,
|
||||
if (!inode)
|
||||
goto out_dentry;
|
||||
|
||||
hstate = hstate_inode(inode);
|
||||
size += addr & ~huge_page_mask(hstate);
|
||||
num_pages = ALIGN(size, huge_page_size(hstate)) >>
|
||||
huge_page_shift(hstate);
|
||||
error = -ENOMEM;
|
||||
if (hugetlb_reserve_pages(inode, 0,
|
||||
size >> huge_page_shift(hstate_inode(inode)), NULL,
|
||||
acctflag))
|
||||
if (hugetlb_reserve_pages(inode, 0, num_pages, NULL, acctflag))
|
||||
goto out_inode;
|
||||
|
||||
d_instantiate(path.dentry, inode);
|
||||
|
Reference in New Issue
Block a user