Skip to content

Commit 67553d0

Browse files
jchu314atgithubjfvogel
authored andcommitted
ipc/shm.c add ->pagesize function to shm_vm_ops
Commit 05ea886 ("mm, hugetlbfs: introduce ->pagesize() to vm_operations_struct") adds a new ->pagesize() function to hugetlb_vm_ops, intended to cover all hugetlbfs backed files. With System V shared memory model, if "huge page" is specified, the "shared memory" is backed by hugetlbfs files, but the mappings initiated via shmget/shmat have their original vm_ops overwritten with shm_vm_ops, so we need to add a ->pagesize function to shm_vm_ops. Otherwise, vma_kernel_pagesize() returns PAGE_SIZE given a hugetlbfs backed vma, result in below BUG: fs/hugetlbfs/inode.c 443 if (unlikely(page_mapped(page))) { 444 BUG_ON(truncate_op); resulting in hugetlbfs: oracle (4592): Using mlock ulimits for SHM_HUGETLB is deprecated ------------[ cut here ]------------ kernel BUG at fs/hugetlbfs/inode.c:444! Modules linked in: nfsv3 rpcsec_gss_krb5 nfsv4 ... CPU: 35 PID: 5583 Comm: oracle_5583_sbt Not tainted 4.14.35-1829.el7uek.x86_64 #2 RIP: 0010:remove_inode_hugepages+0x3db/0x3e2 .... Call Trace: hugetlbfs_evict_inode+0x1e/0x3e evict+0xdb/0x1af iput+0x1a2/0x1f7 dentry_unlink_inode+0xc6/0xf0 __dentry_kill+0xd8/0x18d dput+0x1b5/0x1ed __fput+0x18b/0x216 ____fput+0xe/0x10 task_work_run+0x90/0xa7 exit_to_usermode_loop+0xdd/0x116 do_syscall_64+0x187/0x1ae entry_SYSCALL_64_after_hwframe+0x150/0x0 [[email protected]: relocate comment] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Fixes: 05ea886 ("mm, hugetlbfs: introduce ->pagesize() to vm_operations_struct") Signed-off-by: Jane Chu <[email protected]> Suggested-by: Mike Kravetz <[email protected]> Reviewed-by: Mike Kravetz <[email protected]> Acked-by: Davidlohr Bueso <[email protected]> Acked-by: Michal Hocko <[email protected]> Cc: Dan Williams <[email protected]> Cc: Jan Kara <[email protected]> Cc: Jérôme Glisse <[email protected]> Cc: Manfred Spraul <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> (cherry picked from commit eec3636) Orabug: 28069826 Signed-off-by: Jane Chu <[email protected]> Reviewed-by: Mike Kravetz <[email protected]>
1 parent 696b340 commit 67553d0

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

ipc/shm.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,17 @@ static int shm_split(struct vm_area_struct *vma, unsigned long addr)
403403
return 0;
404404
}
405405

406+
static unsigned long shm_pagesize(struct vm_area_struct *vma)
407+
{
408+
struct file *file = vma->vm_file;
409+
struct shm_file_data *sfd = shm_file_data(file);
410+
411+
if (sfd->vm_ops->pagesize)
412+
return sfd->vm_ops->pagesize(vma);
413+
414+
return PAGE_SIZE;
415+
}
416+
406417
#ifdef CONFIG_NUMA
407418
static int shm_set_policy(struct vm_area_struct *vma, struct mempolicy *new)
408419
{
@@ -530,6 +541,7 @@ static const struct vm_operations_struct shm_vm_ops = {
530541
.close = shm_close, /* callback for when the vm-area is released */
531542
.fault = shm_fault,
532543
.split = shm_split,
544+
.pagesize = shm_pagesize,
533545
#if defined(CONFIG_NUMA)
534546
.set_policy = shm_set_policy,
535547
.get_policy = shm_get_policy,

mm/hugetlb.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,6 +3146,13 @@ static int hugetlb_vm_op_fault(struct vm_fault *vmf)
31463146
return 0;
31473147
}
31483148

3149+
/*
3150+
* When a new function is introduced to vm_operations_struct and added
3151+
* to hugetlb_vm_ops, please consider adding the function to shm_vm_ops.
3152+
* This is because under System V memory model, mappings created via
3153+
* shmget/shmat with "huge page" specified are backed by hugetlbfs files,
3154+
* their original vm_ops are overwritten with shm_vm_ops.
3155+
*/
31493156
const struct vm_operations_struct hugetlb_vm_ops = {
31503157
.fault = hugetlb_vm_op_fault,
31513158
.open = hugetlb_vm_op_open,

0 commit comments

Comments
 (0)