Commit 21a3c273f88c ("mm, hugetlb: add thread name and pid to SHM_HUGETLB mlock rlimit warning") marked this as deprecated in 2012, but it is not deleted yet. Mike says he still sees that message in log files on occasion, so maybe we should preserve this warning. Also remove hugetlbfs related user_shm_unlock in ipc/shm.c and remove the user_shm_unlock after out.
Unified · Split
| @@ -1446,8 +1446,8 @@ static int get_hstate_idx(int page_size_log) · 1445 unmodified lines | |||
| 1446 | * otherwise hugetlb_reserve_pages reserves one less hugepages than intended. | 1446 | * otherwise hugetlb_reserve_pages reserves one less hugepages than intended. |
| 1447 | */ | 1447 | */ |
| 1448 | struct file *hugetlb_file_setup(const char *name, size_t size, | 1448 | struct file *hugetlb_file_setup(const char *name, size_t size, |
| 1449 | vm_flags_t acctflag, struct ucounts **ucounts, | 1449 | vm_flags_t acctflag, int creat_flags, |
| 1450 | int creat_flags, int page_size_log) | 1450 | int page_size_log) |
| 1451 | { | 1451 | { |
| 1452 | struct inode *inode; | 1452 | struct inode *inode; |
| 1453 | struct vfsmount *mnt; | 1453 | struct vfsmount *mnt; |
| @@ -1458,22 +1458,19 @@ struct file *hugetlb_file_setup(const char *name, size_t size, · 4 unmodified lines | |||
| 1458 | if (hstate_idx < 0) | 1458 | if (hstate_idx < 0) |
| 1459 | return ERR_PTR(-ENODEV); | 1459 | return ERR_PTR(-ENODEV); |
| 1460 | 1460 | ||
| 1461 | *ucounts = NULL; | ||
| 1462 | mnt = hugetlbfs_vfsmount[hstate_idx]; | 1461 | mnt = hugetlbfs_vfsmount[hstate_idx]; |
| 1463 | if (!mnt) | 1462 | if (!mnt) |
| 1464 | return ERR_PTR(-ENOENT); | 1463 | return ERR_PTR(-ENOENT); |
| 1465 | 1464 | ||
| 1466 | if (creat_flags == HUGETLB_SHMFS_INODE && !can_do_hugetlb_shm()) { | 1465 | if (creat_flags == HUGETLB_SHMFS_INODE && !can_do_hugetlb_shm()) { |
| 1467 | *ucounts = current_ucounts(); | 1466 | struct ucounts *ucounts = current_ucounts(); |
| 1468 | if (user_shm_lock(size, *ucounts)) { | 1467 | |
| 1469 | task_lock(current); | 1468 | if (user_shm_lock(size, ucounts)) { |
| 1470 | pr_warn_once("%s (%d): Using mlock ulimits for SHM_HUGETLB is deprecated\n", | 1469 | pr_warn_once("%s (%d): Using mlock ulimits for SHM_HUGETLB is obsolete\n", |
| 1471 | current->comm, current->pid); | 1470 | current->comm, current->pid); |
| 1472 | task_unlock(current); | 1471 | user_shm_unlock(size, ucounts); |
| 1473 | } else { | ||
| 1474 | *ucounts = NULL; | ||
| 1475 | return ERR_PTR(-EPERM); | ||
| 1476 | } | 1472 | } |
| 1473 | return ERR_PTR(-EPERM); | ||
| 1477 | } | 1474 | } |
| 1478 | 1475 | ||
| 1479 | file = ERR_PTR(-ENOSPC); | 1476 | file = ERR_PTR(-ENOSPC); |
| @@ -1498,10 +1495,6 @@ struct file *hugetlb_file_setup(const char *name, size_t size, · 18 unmodified lines | |||
| 1498 | 1495 | ||
| 1499 | iput(inode); | 1496 | iput(inode); |
| 1500 | out: | 1497 | out: |
| 1501 | if (*ucounts) { | ||
| 1502 | user_shm_unlock(size, *ucounts); | ||
| 1503 | *ucounts = NULL; | ||
| 1504 | } | ||
| 1505 | return file; | 1498 | return file; |
| 1506 | } | 1499 | } |
| 1507 | 1500 | ||
| @@ -477,8 +477,7 @@ static inline struct hugetlbfs_inode_info *HUGETLBFS_I(struct inode *inode) · 476 unmodified lines | |||
| 477 | extern const struct file_operations hugetlbfs_file_operations; | 477 | extern const struct file_operations hugetlbfs_file_operations; |
| 478 | extern const struct vm_operations_struct hugetlb_vm_ops; | 478 | extern const struct vm_operations_struct hugetlb_vm_ops; |
| 479 | struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct, | 479 | struct file *hugetlb_file_setup(const char *name, size_t size, vm_flags_t acct, |
| 480 | struct ucounts **ucounts, int creat_flags, | 480 | int creat_flags, int page_size_log); |
| 481 | int page_size_log); | ||
| 482 | 481 | ||
| 483 | static inline bool is_file_hugepages(struct file *file) | 482 | static inline bool is_file_hugepages(struct file *file) |
| 484 | { | 483 | { |
| @@ -497,8 +496,7 @@ static inline struct hstate *hstate_inode(struct inode *i) · 12 unmodified lines | |||
| 497 | #define is_file_hugepages(file) false | 496 | #define is_file_hugepages(file) false |
| 498 | static inline struct file * | 497 | static inline struct file * |
| 499 | hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag, | 498 | hugetlb_file_setup(const char *name, size_t size, vm_flags_t acctflag, |
| 500 | struct ucounts **ucounts, int creat_flags, | 499 | int creat_flags, int page_size_log) |
| 501 | int page_size_log) | ||
| 502 | { | 500 | { |
| 503 | return ERR_PTR(-ENOSYS); | 501 | return ERR_PTR(-ENOSYS); |
| 504 | } | 502 | } |
| @@ -287,9 +287,6 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) · 286 unmodified lines | |||
| 287 | shm_unlock(shp); | 287 | shm_unlock(shp); |
| 288 | if (!is_file_hugepages(shm_file)) | 288 | if (!is_file_hugepages(shm_file)) |
| 289 | shmem_lock(shm_file, 0, shp->mlock_ucounts); | 289 | shmem_lock(shm_file, 0, shp->mlock_ucounts); |
| 290 | else if (shp->mlock_ucounts) | ||
| 291 | user_shm_unlock(i_size_read(file_inode(shm_file)), | ||
| 292 | shp->mlock_ucounts); | ||
| 293 | fput(shm_file); | 290 | fput(shm_file); |
| 294 | ipc_update_pid(&shp->shm_cprid, NULL); | 291 | ipc_update_pid(&shp->shm_cprid, NULL); |
| 295 | ipc_update_pid(&shp->shm_lprid, NULL); | 292 | ipc_update_pid(&shp->shm_lprid, NULL); |
| @@ -650,8 +647,7 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) · 354 unmodified lines | |||
| 650 | if (shmflg & SHM_NORESERVE) | 647 | if (shmflg & SHM_NORESERVE) |
| 651 | acctflag = VM_NORESERVE; | 648 | acctflag = VM_NORESERVE; |
| 652 | file = hugetlb_file_setup(name, hugesize, acctflag, | 649 | file = hugetlb_file_setup(name, hugesize, acctflag, |
| 653 | &shp->mlock_ucounts, HUGETLB_SHMFS_INODE, | 650 | HUGETLB_SHMFS_INODE, (shmflg >> SHM_HUGE_SHIFT) & SHM_HUGE_MASK); |
| 654 | (shmflg >> SHM_HUGE_SHIFT) & SHM_HUGE_MASK); | ||
| 655 | } else { | 651 | } else { |
| 656 | /* | 652 | /* |
| 657 | * Do not allow no accounting for OVERCOMMIT_NEVER, even | 653 | * Do not allow no accounting for OVERCOMMIT_NEVER, even |
| @@ -698,8 +694,6 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params) · 40 unmodified lines | |||
| 698 | no_id: | 694 | no_id: |
| 699 | ipc_update_pid(&shp->shm_cprid, NULL); | 695 | ipc_update_pid(&shp->shm_cprid, NULL); |
| 700 | ipc_update_pid(&shp->shm_lprid, NULL); | 696 | ipc_update_pid(&shp->shm_lprid, NULL); |
| 701 | if (is_file_hugepages(file) && shp->mlock_ucounts) | ||
| 702 | user_shm_unlock(size, shp->mlock_ucounts); | ||
| 703 | fput(file); | 697 | fput(file); |
| 704 | ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); | 698 | ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); |
| 705 | return error; | 699 | return error; |
| @@ -297,9 +297,7 @@ SYSCALL_DEFINE2(memfd_create, · 296 unmodified lines | |||
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | if (flags & MFD_HUGETLB) { | 299 | if (flags & MFD_HUGETLB) { |
| 300 | struct ucounts *ucounts = NULL; | 300 | file = hugetlb_file_setup(name, 0, VM_NORESERVE, |
| 301 | |||
| 302 | file = hugetlb_file_setup(name, 0, VM_NORESERVE, &ucounts, | ||
| 303 | HUGETLB_ANONHUGE_INODE, | 301 | HUGETLB_ANONHUGE_INODE, |
| 304 | (flags >> MFD_HUGE_SHIFT) & | 302 | (flags >> MFD_HUGE_SHIFT) & |
| 305 | MFD_HUGE_MASK); | 303 | MFD_HUGE_MASK); |
| @@ -1599,7 +1599,6 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len, · 1598 unmodified lines | |||
| 1599 | goto out_fput; | 1599 | goto out_fput; |
| 1600 | } | 1600 | } |
| 1601 | } else if (flags & MAP_HUGETLB) { | 1601 | } else if (flags & MAP_HUGETLB) { |
| 1602 | struct ucounts *ucounts = NULL; | ||
| 1603 | struct hstate *hs; | 1602 | struct hstate *hs; |
| 1604 | 1603 | ||
| 1605 | hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); | 1604 | hs = hstate_sizelog((flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); |
| @@ -1615,7 +1614,7 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len, · 9 unmodified lines | |||
| 1615 | */ | 1614 | */ |
| 1616 | file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, | 1615 | file = hugetlb_file_setup(HUGETLB_ANON_FILE, len, |
| 1617 | VM_NORESERVE, | 1616 | VM_NORESERVE, |
| 1618 | &ucounts, HUGETLB_ANONHUGE_INODE, | 1617 | HUGETLB_ANONHUGE_INODE, |
| 1619 | (flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); | 1618 | (flags >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK); |
| 1620 | if (IS_ERR(file)) | 1619 | if (IS_ERR(file)) |
| 1621 | return PTR_ERR(file); | 1620 | return PTR_ERR(file); |