cregit-Linux how code gets into the kernel

Release 4.13 ipc/shm.c

Directory: ipc
/*
 * linux/ipc/shm.c
 * Copyright (C) 1992, 1993 Krishna Balasubramanian
 *       Many improvements/fixes by Bruno Haible.
 * Replaced `struct shm_desc' by `struct vm_area_struct', July 1994.
 * Fixed the shm swap deallocation (shm_unuse()), August 1998 Andrea Arcangeli.
 *
 * /proc/sysvipc/shm support (c) 1999 Dragos Acostachioaie <dragos@iname.com>
 * BIGMEM support, Andrea Arcangeli <andrea@suse.de>
 * SMP thread shm, Jean-Luc Boyard <jean-luc.boyard@siemens.fr>
 * HIGHMEM support, Ingo Molnar <mingo@redhat.com>
 * Make shmmax, shmall, shmmni sysctl'able, Christoph Rohland <cr@sap.com>
 * Shared /dev/zero support, Kanoj Sarcar <kanoj@sgi.com>
 * Move the mm functionality over to mm/shmem.c, Christoph Rohland <cr@sap.com>
 *
 * support for audit of ipc object properties and permission changes
 * Dustin Kirkland <dustin.kirkland@us.ibm.com>
 *
 * namespaces support
 * OpenVZ, SWsoft Inc.
 * Pavel Emelianov <xemul@openvz.org>
 *
 * Better ipc lock (kern_ipc_perm.lock) handling
 * Davidlohr Bueso <davidlohr.bueso@hp.com>, June 2013.
 */

#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/hugetlb.h>
#include <linux/shm.h>
#include <linux/init.h>
#include <linux/file.h>
#include <linux/mman.h>
#include <linux/shmem_fs.h>
#include <linux/security.h>
#include <linux/syscalls.h>
#include <linux/audit.h>
#include <linux/capability.h>
#include <linux/ptrace.h>
#include <linux/seq_file.h>
#include <linux/rwsem.h>
#include <linux/nsproxy.h>
#include <linux/mount.h>
#include <linux/ipc_namespace.h>

#include <linux/uaccess.h>

#include "util.h"


struct shm_file_data {
	
int id;
	
struct ipc_namespace *ns;
	
struct file *file;
	
const struct vm_operations_struct *vm_ops;
};


#define shm_file_data(file) (*((struct shm_file_data **)&(file)->private_data))


static const struct file_operations shm_file_operations;

static const struct vm_operations_struct shm_vm_ops;


#define shm_ids(ns)	((ns)->ids[IPC_SHM_IDS])


#define shm_unlock(shp)			\
	ipc_unlock(&(shp)->shm_perm)

static int newseg(struct ipc_namespace *, struct ipc_params *);
static void shm_open(struct vm_area_struct *vma);
static void shm_close(struct vm_area_struct *vma);
static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
#ifdef CONFIG_PROC_FS
static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
#endif


void shm_init_ns(struct ipc_namespace *ns) { ns->shm_ctlmax = SHMMAX; ns->shm_ctlall = SHMALL; ns->shm_ctlmni = SHMMNI; ns->shm_rmid_forced = 0; ns->shm_tot = 0; ipc_init_ids(&shm_ids(ns)); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill Korotaev3163.27%120.00%
Vasiliy Kulikov612.24%120.00%
Linus Torvalds (pre-git)612.24%120.00%
Pierre Peiffer36.12%120.00%
WANG Cong36.12%120.00%
Total49100.00%5100.00%

/* * Called with shm_ids.rwsem (writer) and the shp structure locked. * Only shm_ids.rwsem remains locked on exit. */
static void do_shm_rmid(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp) { struct shmid_kernel *shp; shp = container_of(ipcp, struct shmid_kernel, shm_perm); if (shp->shm_nattch) { shp->shm_perm.mode |= SHM_DEST; /* Do not find it any more */ shp->shm_perm.key = IPC_PRIVATE; shm_unlock(shp); } else shm_destroy(ns, shp); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill Korotaev5171.83%133.33%
Pierre Peiffer1926.76%133.33%
Linus Torvalds (pre-git)11.41%133.33%
Total71100.00%3100.00%

#ifdef CONFIG_IPC_NS
void shm_exit_ns(struct ipc_namespace *ns) { free_ipcs(ns, &shm_ids(ns), do_shm_rmid); idr_destroy(&ns->ids[IPC_SHM_IDS].ipcs_idr); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill Korotaev1747.22%120.00%
Serge E. Hallyn1336.11%120.00%
Pierre Peiffer38.33%240.00%
Nadia Derbey38.33%120.00%
Total36100.00%5100.00%

#endif
static int __init ipc_ns_init(void) { shm_init_ns(&init_ipc_ns); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)950.00%240.00%
Linus Torvalds738.89%120.00%
Kirill Korotaev15.56%120.00%
Pierre Peiffer15.56%120.00%
Total18100.00%5100.00%

pure_initcall(ipc_ns_init);
void __init shm_init(void) { ipc_init_proc_interface("sysvipc/shm", #if BITS_PER_LONG <= 32 " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n", #else " key shmid perms size cpid lpid nattch uid gid cuid cgid atime dtime ctime rss swap\n", #endif IPC_SHM_IDS, sysvipc_shm_proc_show); }

Contributors

PersonTokensPropCommitsCommitProp
Helge Deller1240.00%120.00%
Linus Torvalds (pre-git)826.67%120.00%
Linus Torvalds723.33%120.00%
Mike Waychison26.67%120.00%
Kirill Korotaev13.33%120.00%
Total30100.00%5100.00%


static inline struct shmid_kernel *shm_obtain_object(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp = ipc_obtain_object_idr(&shm_ids(ns), id); if (IS_ERR(ipcp)) return ERR_CAST(ipcp); return container_of(ipcp, struct shmid_kernel, shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Davidlohr Bueso A57100.00%2100.00%
Total57100.00%2100.00%


static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp = ipc_obtain_object_check(&shm_ids(ns), id); if (IS_ERR(ipcp)) return ERR_CAST(ipcp); return container_of(ipcp, struct shmid_kernel, shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Davidlohr Bueso A57100.00%1100.00%
Total57100.00%1100.00%

/* * shm_lock_(check_) routines are called in the paths where the rwsem * is not necessarily held. */
static inline struct shmid_kernel *shm_lock(struct ipc_namespace *ns, int id) { struct kern_ipc_perm *ipcp = ipc_lock(&shm_ids(ns), id); /* * Callers of shm_lock() must validate the status of the returned ipc * object pointer (as returned by ipc_lock()), and error out as * appropriate. */ if (IS_ERR(ipcp)) return (void *)ipcp; return container_of(ipcp, struct shmid_kernel, shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Nadia Derbey3661.02%228.57%
Kirill A. Shutemov1118.64%114.29%
Pierre Peiffer46.78%114.29%
Kirill Korotaev46.78%114.29%
Linus Torvalds (pre-git)46.78%228.57%
Total59100.00%7100.00%


static inline void shm_lock_by_ptr(struct shmid_kernel *ipcp) { rcu_read_lock(); ipc_lock_object(&ipcp->shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov2295.65%150.00%
Davidlohr Bueso A14.35%150.00%
Total23100.00%2100.00%


static void shm_rcu_free(struct rcu_head *head) { struct kern_ipc_perm *ptr = container_of(head, struct kern_ipc_perm, rcu); struct shmid_kernel *shp = container_of(ptr, struct shmid_kernel, shm_perm); security_shm_free(shp); kvfree(shp); }

Contributors

PersonTokensPropCommitsCommitProp
Davidlohr Bueso A3976.47%125.00%
Manfred Spraul1019.61%125.00%
Kees Cook23.92%250.00%
Total51100.00%4100.00%


static inline void shm_rmid(struct ipc_namespace *ns, struct shmid_kernel *s) { list_del(&s->shm_clist); ipc_rmid(&shm_ids(ns), &s->shm_perm); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)1333.33%350.00%
Nadia Derbey1025.64%116.67%
Jack Miller820.51%116.67%
Kirill Korotaev820.51%116.67%
Total39100.00%6100.00%


static int __shm_open(struct vm_area_struct *vma) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); struct shmid_kernel *shp; shp = shm_lock(sfd->ns, sfd->id); if (IS_ERR(shp)) return PTR_ERR(shp); shp->shm_atim = get_seconds(); shp->shm_lprid = task_tgid_vnr(current); shp->shm_nattch++; shm_unlock(shp); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3538.89%541.67%
Eric W. Biedermann2527.78%18.33%
Kirill A. Shutemov1921.11%18.33%
Kirill Korotaev44.44%18.33%
Pavel Emelyanov33.33%18.33%
Andi Kleen22.22%18.33%
Andrew Morton11.11%18.33%
Eric Sesterhenn / Snakebyte11.11%18.33%
Total90100.00%12100.00%

/* This is called by fork, once for every shm attach. */
static void shm_open(struct vm_area_struct *vma) { int err = __shm_open(vma); /* * We raced in the idr lookup or with shm_destroy(). * Either way, the ID is busted. */ WARN_ON_ONCE(err); }

Contributors

PersonTokensPropCommitsCommitProp
Kirill A. Shutemov2496.00%150.00%
Linus Torvalds (pre-git)14.00%150.00%
Total25100.00%2100.00%

/* * shm_destroy - free the struct shmid_kernel * * @ns: namespace * @shp: struct to free * * It has to be called with shp and shm_ids.rwsem (writer) locked, * but returns with shp unlocked and freed. */
static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) { struct file *shm_file; shm_file = shp->shm_file; shp->shm_file = NULL; ns->shm_tot -= (shp->shm_segsz + PAGE_SIZE - 1) >> PAGE_SHIFT; shm_rmid(ns, shp); shm_unlock(shp); if (!is_file_hugepages(shm_file)) shmem_lock(shm_file, 0, shp->mlock_user); else if (shp->mlock_user) user_shm_unlock(i_size_read(file_inode(shm_file)), shp->mlock_user); fput(shm_file); ipc_rcu_putref(&shp->shm_perm, shm_rcu_free); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)3933.33%529.41%
Greg Thelen1714.53%15.88%
Rik Van Riel1311.11%15.88%
Hugh Dickins1210.26%211.76%
Kirill Korotaev97.69%15.88%
Andrew Morton86.84%15.88%
Linus Torvalds75.98%15.88%
Manfred Spraul43.42%211.76%
Al Viro32.56%15.88%
Dave Hansen32.56%15.88%
Davidlohr Bueso A21.71%15.88%
Total117100.00%17100.00%

/* * shm_may_destroy - identifies whether shm segment should be destroyed now * * Returns true if and only if there are no active users of the segment and * one of the following is true: * * 1) shmctl(id, IPC_RMID, NULL) was called for this shp * * 2) sysctl kernel.shm_rmid_forced is set to 1. */
static bool shm_may_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp) { return (shp->shm_nattch == 0) && (ns->shm_rmid_forced || (shp->shm_perm.mode & SHM_DEST)); }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov41100.00%1100.00%
Total41100.00%1100.00%

/* * remove the attach descriptor vma. * free memory for segment if it is marked destroyed. * The descriptor has already been removed from the current->mm->mmap list * and will later be kfree()d. */
static void shm_close(struct vm_area_struct *vma) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); struct shmid_kernel *shp; struct ipc_namespace *ns = sfd->ns; down_write(&shm_ids(ns).rwsem); /* remove from the list of attaches of the shm segment */ shp = shm_lock(ns, sfd->id); /* * We raced in the idr lookup or with shm_destroy(). * Either way, the ID is busted. */ if (WARN_ON_ONCE(IS_ERR(shp))) goto done; /* no-op */ shp->shm_lprid = task_tgid_vnr(current); shp->shm_dtim = get_seconds(); shp->shm_nattch--; if (shm_may_destroy(ns, shp)) shm_destroy(ns, shp); else shm_unlock(shp); done: up_write(&shm_ids(ns).rwsem); }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)5539.86%533.33%
Vasiliy Kulikov3122.46%16.67%
Kirill A. Shutemov1712.32%16.67%
Eric W. Biedermann1510.87%16.67%
Kirill Korotaev107.25%16.67%
Pavel Emelyanov32.17%16.67%
Davidlohr Bueso A21.45%16.67%
Nadia Derbey21.45%213.33%
Andi Kleen21.45%16.67%
Eric Sesterhenn / Snakebyte10.72%16.67%
Total138100.00%15100.00%

/* Called with ns->shm_ids(ns).rwsem locked */
static int shm_try_destroy_orphaned(int id, void *p, void *data) { struct ipc_namespace *ns = data; struct kern_ipc_perm *ipcp = p; struct shmid_kernel *shp = container_of(ipcp, struct shmid_kernel, shm_perm); /* * We want to destroy segments without users and with already * exit'ed originating process. * * As shp->* are changed under rwsem, it's safe to skip shp locking. */ if (shp->shm_creator != NULL) return 0; if (shm_may_destroy(ns, shp)) { shm_lock_by_ptr(shp); shm_destroy(ns, shp); } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov7488.10%337.50%
Linus Torvalds (pre-git)89.52%337.50%
Davidlohr Bueso A11.19%112.50%
Andrew Morton11.19%112.50%
Total84100.00%8100.00%


void shm_destroy_orphaned(struct ipc_namespace *ns) { down_write(&shm_ids(ns).rwsem); if (shm_ids(ns).in_use) idr_for_each(&shm_ids(ns).ipcs_idr, &shm_try_destroy_orphaned, ns); up_write(&shm_ids(ns).rwsem); }

Contributors

PersonTokensPropCommitsCommitProp
Vasiliy Kulikov5596.49%266.67%
Davidlohr Bueso A23.51%133.33%
Total57100.00%3100.00%

/* Locking assumes this will only be called with task == current */
void exit_shm(struct task_struct *task) { struct ipc_namespace *ns = task->nsproxy->ipc_ns; struct shmid_kernel *shp, *n; if (list_empty(&task->sysvshm.shm_clist)) return; /* * If kernel.shm_rmid_forced is not set then only keep track of * which shmids are orphaned, so that a later set of the sysctl * can clean them up. */ if (!ns->shm_rmid_forced) { down_read(&shm_ids(ns).rwsem); list_for_each_entry(shp, &task->sysvshm.shm_clist, shm_clist) shp->shm_creator = NULL; /* * Only under read lock but we are only called on current * so no entry on the list will be shared. */ list_del(&task->sysvshm.shm_clist); up_read(&shm_ids(ns).rwsem); return; } /* * Destroy all already created segments, that were not yet mapped, * and mark any mapped as orphan to cover the sysctl toggling. * Destroy is skipped if shm_may_destroy() returns false. */ down_write(&shm_ids(ns).rwsem); list_for_each_entry_safe(shp, n, &task->sysvshm.shm_clist, shm_clist) { shp->shm_creator = NULL; if (shm_may_destroy(ns, shp)) { shm_lock_by_ptr(shp); shm_destroy(ns, shp); } } /* Remove the list head from any segments still attached. */ list_del(&task->sysvshm.shm_clist); up_write(&shm_ids(ns).rwsem); }

Contributors

PersonTokensPropCommitsCommitProp
Jack Miller11766.86%218.18%
Vasiliy Kulikov4525.71%327.27%
Linus Torvalds (pre-git)74.00%327.27%
Kirill Korotaev31.71%19.09%
Davidlohr Bueso A21.14%19.09%
Nadia Derbey10.57%19.09%
Total175100.00%11100.00%


static int shm_fault(struct vm_fault *vmf) { struct file *file = vmf->vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); return sfd->vm_ops->fault(vmf); }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann1945.24%18.33%
Linus Torvalds (pre-git)1126.19%433.33%
Nicholas Piggin614.29%216.67%
Dave Jiang24.76%18.33%
Hugh Dickins12.38%18.33%
Adrian Bunk12.38%18.33%
David Howells12.38%18.33%
Kirill Korotaev12.38%18.33%
Total42100.00%12100.00%

#ifdef CONFIG_NUMA
static int shm_set_policy(struct vm_area_struct *vma, struct mempolicy *new) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); int err = 0; if (sfd->vm_ops->set_policy) err = sfd->vm_ops->set_policy(vma, new); return err; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann4773.44%133.33%
Kirill Korotaev1625.00%133.33%
Adrian Bunk11.56%133.33%
Total64100.00%3100.00%


static struct mempolicy *shm_get_policy(struct vm_area_struct *vma, unsigned long addr) { struct file *file = vma->vm_file; struct shm_file_data *sfd = shm_file_data(file); struct mempolicy *pol = NULL; if (sfd->vm_ops->get_policy) pol = sfd->vm_ops->get_policy(vma, addr); else if (vma->vm_policy) pol = vma->vm_policy; return pol; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann6986.25%125.00%
Adam Litke78.75%125.00%
Kirill Korotaev33.75%125.00%
Adrian Bunk11.25%125.00%
Total80100.00%4100.00%

#endif
static int shm_mmap(struct file *file, struct vm_area_struct *vma) { struct shm_file_data *sfd = shm_file_data(file); int ret; /* * In case of remap_file_pages() emulation, the file can represent * removed IPC ID: propogate shm_lock() error to caller. */ ret = __shm_open(vma); if (ret) return ret; ret = call_mmap(sfd->file, vma); if (ret) { shm_close(vma); return ret; } sfd->vm_ops = vma->vm_ops; #ifdef CONFIG_MMU WARN_ON(!sfd->vm_ops->fault); #endif vma->vm_ops = &shm_vm_ops; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann6159.80%114.29%
Kirill A. Shutemov2322.55%114.29%
Nicholas Piggin98.82%114.29%
David Howells54.90%114.29%
Kirill Korotaev21.96%114.29%
Davidlohr Bueso A10.98%114.29%
Miklos Szeredi10.98%114.29%
Total102100.00%7100.00%


static int shm_release(struct inode *ino, struct file *file) { struct shm_file_data *sfd = shm_file_data(file); put_ipc_ns(sfd->ns); shm_file_data(file) = NULL; kfree(sfd); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann48100.00%1100.00%
Total48100.00%1100.00%


static int shm_fsync(struct file *file, loff_t start, loff_t end, int datasync) { struct shm_file_data *sfd = shm_file_data(file); if (!sfd->file->f_op->fsync) return -EINVAL; return sfd->file->f_op->fsync(sfd->file, start, end, datasync); }

Contributors

PersonTokensPropCommitsCommitProp
Adam Litke3960.00%125.00%
Josef Bacik1015.38%125.00%
Christoph Hellwig913.85%125.00%
Jeff Layton710.77%125.00%
Total65100.00%4100.00%


static long shm_fallocate(struct file *file, int mode, loff_t offset, loff_t len) { struct shm_file_data *sfd = shm_file_data(file); if (!sfd->file->f_op->fallocate) return -EOPNOTSUPP; return sfd->file->f_op->fallocate(file, mode, offset, len); }

Contributors

PersonTokensPropCommitsCommitProp
Will Deacon63100.00%1100.00%
Total63100.00%1100.00%


static unsigned long shm_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { struct shm_file_data *sfd = shm_file_data(file); return sfd->file->f_op->get_unmapped_area(sfd->file, addr, len, pgoff, flags); }

Contributors

PersonTokensPropCommitsCommitProp
Eric W. Biedermann5490.00%150.00%
Al Viro610.00%150.00%
Total60100.00%2100.00%

static const struct file_operations shm_file_operations = { .mmap = shm_mmap, .fsync = shm_fsync, .release = shm_release, .get_unmapped_area = shm_get_unmapped_area, .llseek = noop_llseek, .fallocate = shm_fallocate, }; /* * shm_file_operations_huge is now identical to shm_file_operations, * but we keep it distinct for the sake of is_file_shm_hugepages(). */ static const struct file_operations shm_file_operations_huge = { .mmap = shm_mmap, .fsync = shm_fsync, .release = shm_release, .get_unmapped_area = shm_get_unmapped_area, .llseek = noop_llseek, .fallocate = shm_fallocate, };
bool is_file_shm_hugepages(struct file *file) { return file->f_op == &shm_file_operations_huge; }

Contributors

PersonTokensPropCommitsCommitProp
Al Viro1794.44%150.00%
Yaowei Bai15.56%150.00%
Total18100.00%2100.00%

static const struct vm_operations_struct shm_vm_ops = { .open = shm_open, /* callback for a new vm-area open */ .close = shm_close, /* callback for when the vm-area is released */ .fault = shm_fault, #if defined(CONFIG_NUMA) .set_policy = shm_set_policy, .get_policy = shm_get_policy, #endif }; /** * newseg - Create a new shared memory segment * @ns: namespace * @params: ptr to the structure that contains key, size and shmflg * * Called with shm_ids.rwsem held as a writer. */
static int newseg(struct ipc_namespace *ns, struct ipc_params *params) { key_t key = params->key; int shmflg = params->flg; size_t size = params->u.size; int error; struct shmid_kernel *shp; size_t numpages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; struct file *file; char name[13]; vm_flags_t acctflag = 0; if (size < SHMMIN || size > ns->shm_ctlmax) return -EINVAL; if (numpages << PAGE_SHIFT < size) return -ENOSPC; if (ns->shm_tot + numpages < ns->shm_tot || ns->shm_tot + numpages > ns->shm_ctlall) return -ENOSPC; shp = kvmalloc(sizeof(*shp), GFP_KERNEL); if (unlikely(!shp)) return -ENOMEM; shp->shm_perm.key = key; shp->shm_perm.mode = (shmflg & S_IRWXUGO); shp->mlock_user = NULL; shp->shm_perm.security = NULL; error = security_shm_alloc(shp); if (error) { kvfree(shp); return error; } sprintf(name, "SYSV%08x", key); if (shmflg & SHM_HUGETLB) { struct hstate *hs; size_t hugesize; hs = hstate_sizelog((shmflg >> SHM_HUGE_SHIFT) & SHM_HUGE_MASK); if (!hs) { error = -EINVAL; goto no_file; } hugesize = ALIGN(size, huge_page_size(hs)); /* hugetlb_file_setup applies strict accounting */ if (shmflg & SHM_NORESERVE) acctflag = VM_NORESERVE; file = hugetlb_file_setup(name, hugesize, acctflag, &shp->mlock_user, HUGETLB_SHMFS_INODE, (shmflg >> SHM_HUGE_SHIFT) & SHM_HUGE_MASK); } else { /* * Do not allow no accounting for OVERCOMMIT_NEVER, even * if it's asked for. */ if ((shmflg & SHM_NORESERVE) && sysctl_overcommit_memory != OVERCOMMIT_NEVER) acctflag = VM_NORESERVE; file = shmem_kernel_file_setup(name, size, acctflag); } error = PTR_ERR(file); if (IS_ERR(file)) goto no_file; shp->shm_cprid = task_tgid_vnr(current); shp->shm_lprid = 0; shp->shm_atim = shp->shm_dtim = 0; shp->shm_ctim = get_seconds(); shp->shm_segsz = size; shp->shm_nattch = 0; shp->shm_file = file; shp->shm_creator = current; error = ipc_addid(&shm_ids(ns), &shp->shm_perm, ns->shm_ctlmni); if (error < 0) goto no_id; list_add(&shp->shm_clist, &current->sysvshm.shm_clist); /* * shmid gets reported as "inode#" in /proc/pid/maps. * proc-ps tools use this. Changing this will break them. */ file_inode(file)->i_ino = shp->shm_perm.id; ns->shm_tot += numpages; error = shp->shm_perm.id; ipc_unlock_object(&shp->shm_perm); rcu_read_unlock(); return error; no_id: if (is_file_hugepages(file) && shp->mlock_user) user_shm_unlock(size, shp->mlock_user); fput(file); no_file: call_rcu(&shp->shm_perm.rcu, shm_rcu_free); return error; }

Contributors

PersonTokensPropCommitsCommitProp
Linus Torvalds (pre-git)17431.87%917.31%
Nadia Derbey346.23%23.85%
Manfred Spraul315.68%59.62%
Linus Torvalds285.13%23.85%
Badari Pulavarty254.58%23.85%
Hugh Dickins244.40%35.77%
Stephen D. Smalley244.40%23.85%
Naoya Horiguchi244.40%11.92%
Andrew Morton234.21%47.69%
Greg Kroah-Hartman224.03%35.77%
Li Zefan183.30%11.92%
Mel Gorman173.11%11.92%
Jack Miller152.75%11.92%
Kees Cook142.56%11.92%
Kirill Korotaev132.38%11.92%
Eric W. Biedermann122.20%11.92%
Rik Van Riel122.20%11.92%
Andi Kleen101.83%23.85%
Davidlohr Bueso A91.65%35.77%
Vasiliy Kulikov61.10%11.92%
Al Viro30.55%11.92%
Pavel Emelyanov30.55%11.92%
Eric B Munson20.37%11.92%
Robin Holt10.18%11.92%
Motohiro Kosaki10.18%11.92%
Guy Streeter10.18%11.92%
Total546100.00%52100.00%

/* * Called with shm_ids.rwsem and ipcp locked. */
static inline int