fork.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  1. /*
  2. * linux/kernel/fork.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. */
  6. /*
  7. * 'fork.c' contains the help-routines for the 'fork' system call
  8. * (see also entry.S and others).
  9. * Fork is rather simple, once you get the hang of it, but the memory
  10. * management can be a bitch. See 'mm/memory.c': 'copy_page_range()'
  11. */
  12. #include <linux/config.h>
  13. #include <linux/slab.h>
  14. #include <linux/init.h>
  15. #include <linux/unistd.h>
  16. #include <linux/smp_lock.h>
  17. #include <linux/module.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/completion.h>
  20. #include <linux/namespace.h>
  21. #include <linux/personality.h>
  22. #include <linux/mempolicy.h>
  23. #include <linux/sem.h>
  24. #include <linux/file.h>
  25. #include <linux/key.h>
  26. #include <linux/binfmts.h>
  27. #include <linux/mman.h>
  28. #include <linux/fs.h>
  29. #include <linux/cpu.h>
  30. #include <linux/cpuset.h>
  31. #include <linux/security.h>
  32. #include <linux/swap.h>
  33. #include <linux/syscalls.h>
  34. #include <linux/jiffies.h>
  35. #include <linux/futex.h>
  36. #include <linux/ptrace.h>
  37. #include <linux/mount.h>
  38. #include <linux/audit.h>
  39. #include <linux/profile.h>
  40. #include <linux/rmap.h>
  41. #include <linux/acct.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/pgalloc.h>
  44. #include <asm/uaccess.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/cacheflush.h>
  47. #include <asm/tlbflush.h>
  48. /*
  49. * Protected counters by write_lock_irq(&tasklist_lock)
  50. */
  51. unsigned long total_forks; /* Handle normal Linux uptimes. */
  52. int nr_threads; /* The idle threads do not count.. */
  53. int max_threads; /* tunable limit on nr_threads */
  54. DEFINE_PER_CPU(unsigned long, process_counts) = 0;
  55. __cacheline_aligned DEFINE_RWLOCK(tasklist_lock); /* outer */
  56. EXPORT_SYMBOL(tasklist_lock);
  57. int nr_processes(void)
  58. {
  59. int cpu;
  60. int total = 0;
  61. for_each_online_cpu(cpu)
  62. total += per_cpu(process_counts, cpu);
  63. return total;
  64. }
  65. #ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
  66. # define alloc_task_struct() kmem_cache_alloc(task_struct_cachep, GFP_KERNEL)
  67. # define free_task_struct(tsk) kmem_cache_free(task_struct_cachep, (tsk))
  68. static kmem_cache_t *task_struct_cachep;
  69. #endif
  70. /* SLAB cache for signal_struct structures (tsk->signal) */
  71. kmem_cache_t *signal_cachep;
  72. /* SLAB cache for sighand_struct structures (tsk->sighand) */
  73. kmem_cache_t *sighand_cachep;
  74. /* SLAB cache for files_struct structures (tsk->files) */
  75. kmem_cache_t *files_cachep;
  76. /* SLAB cache for fs_struct structures (tsk->fs) */
  77. kmem_cache_t *fs_cachep;
  78. /* SLAB cache for vm_area_struct structures */
  79. kmem_cache_t *vm_area_cachep;
  80. /* SLAB cache for mm_struct structures (tsk->mm) */
  81. static kmem_cache_t *mm_cachep;
  82. void free_task(struct task_struct *tsk)
  83. {
  84. free_thread_info(tsk->thread_info);
  85. free_task_struct(tsk);
  86. }
  87. EXPORT_SYMBOL(free_task);
  88. void __put_task_struct(struct task_struct *tsk)
  89. {
  90. WARN_ON(!(tsk->exit_state & (EXIT_DEAD | EXIT_ZOMBIE)));
  91. WARN_ON(atomic_read(&tsk->usage));
  92. WARN_ON(tsk == current);
  93. if (unlikely(tsk->audit_context))
  94. audit_free(tsk);
  95. security_task_free(tsk);
  96. free_uid(tsk->user);
  97. put_group_info(tsk->group_info);
  98. if (!profile_handoff_task(tsk))
  99. free_task(tsk);
  100. }
  101. void __init fork_init(unsigned long mempages)
  102. {
  103. #ifndef __HAVE_ARCH_TASK_STRUCT_ALLOCATOR
  104. #ifndef ARCH_MIN_TASKALIGN
  105. #define ARCH_MIN_TASKALIGN L1_CACHE_BYTES
  106. #endif
  107. /* create a slab on which task_structs can be allocated */
  108. task_struct_cachep =
  109. kmem_cache_create("task_struct", sizeof(struct task_struct),
  110. ARCH_MIN_TASKALIGN, SLAB_PANIC, NULL, NULL);
  111. #endif
  112. /*
  113. * The default maximum number of threads is set to a safe
  114. * value: the thread structures can take up at most half
  115. * of memory.
  116. */
  117. max_threads = mempages / (8 * THREAD_SIZE / PAGE_SIZE);
  118. /*
  119. * we need to allow at least 20 threads to boot a system
  120. */
  121. if(max_threads < 20)
  122. max_threads = 20;
  123. init_task.signal->rlim[RLIMIT_NPROC].rlim_cur = max_threads/2;
  124. init_task.signal->rlim[RLIMIT_NPROC].rlim_max = max_threads/2;
  125. init_task.signal->rlim[RLIMIT_SIGPENDING] =
  126. init_task.signal->rlim[RLIMIT_NPROC];
  127. }
  128. static struct task_struct *dup_task_struct(struct task_struct *orig)
  129. {
  130. struct task_struct *tsk;
  131. struct thread_info *ti;
  132. prepare_to_copy(orig);
  133. tsk = alloc_task_struct();
  134. if (!tsk)
  135. return NULL;
  136. ti = alloc_thread_info(tsk);
  137. if (!ti) {
  138. free_task_struct(tsk);
  139. return NULL;
  140. }
  141. *ti = *orig->thread_info;
  142. *tsk = *orig;
  143. tsk->thread_info = ti;
  144. ti->task = tsk;
  145. /* One for us, one for whoever does the "release_task()" (usually parent) */
  146. atomic_set(&tsk->usage,2);
  147. return tsk;
  148. }
  149. #ifdef CONFIG_MMU
  150. static inline int dup_mmap(struct mm_struct * mm, struct mm_struct * oldmm)
  151. {
  152. struct vm_area_struct * mpnt, *tmp, **pprev;
  153. struct rb_node **rb_link, *rb_parent;
  154. int retval;
  155. unsigned long charge;
  156. struct mempolicy *pol;
  157. down_write(&oldmm->mmap_sem);
  158. flush_cache_mm(current->mm);
  159. mm->locked_vm = 0;
  160. mm->mmap = NULL;
  161. mm->mmap_cache = NULL;
  162. mm->free_area_cache = oldmm->mmap_base;
  163. mm->map_count = 0;
  164. set_mm_counter(mm, rss, 0);
  165. set_mm_counter(mm, anon_rss, 0);
  166. cpus_clear(mm->cpu_vm_mask);
  167. mm->mm_rb = RB_ROOT;
  168. rb_link = &mm->mm_rb.rb_node;
  169. rb_parent = NULL;
  170. pprev = &mm->mmap;
  171. for (mpnt = current->mm->mmap ; mpnt ; mpnt = mpnt->vm_next) {
  172. struct file *file;
  173. if (mpnt->vm_flags & VM_DONTCOPY) {
  174. __vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
  175. -vma_pages(mpnt));
  176. continue;
  177. }
  178. charge = 0;
  179. if (mpnt->vm_flags & VM_ACCOUNT) {
  180. unsigned int len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
  181. if (security_vm_enough_memory(len))
  182. goto fail_nomem;
  183. charge = len;
  184. }
  185. tmp = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
  186. if (!tmp)
  187. goto fail_nomem;
  188. *tmp = *mpnt;
  189. pol = mpol_copy(vma_policy(mpnt));
  190. retval = PTR_ERR(pol);
  191. if (IS_ERR(pol))
  192. goto fail_nomem_policy;
  193. vma_set_policy(tmp, pol);
  194. tmp->vm_flags &= ~VM_LOCKED;
  195. tmp->vm_mm = mm;
  196. tmp->vm_next = NULL;
  197. anon_vma_link(tmp);
  198. file = tmp->vm_file;
  199. if (file) {
  200. struct inode *inode = file->f_dentry->d_inode;
  201. get_file(file);
  202. if (tmp->vm_flags & VM_DENYWRITE)
  203. atomic_dec(&inode->i_writecount);
  204. /* insert tmp into the share list, just after mpnt */
  205. spin_lock(&file->f_mapping->i_mmap_lock);
  206. tmp->vm_truncate_count = mpnt->vm_truncate_count;
  207. flush_dcache_mmap_lock(file->f_mapping);
  208. vma_prio_tree_add(tmp, mpnt);
  209. flush_dcache_mmap_unlock(file->f_mapping);
  210. spin_unlock(&file->f_mapping->i_mmap_lock);
  211. }
  212. /*
  213. * Link in the new vma and copy the page table entries:
  214. * link in first so that swapoff can see swap entries,
  215. * and try_to_unmap_one's find_vma find the new vma.
  216. */
  217. spin_lock(&mm->page_table_lock);
  218. *pprev = tmp;
  219. pprev = &tmp->vm_next;
  220. __vma_link_rb(mm, tmp, rb_link, rb_parent);
  221. rb_link = &tmp->vm_rb.rb_right;
  222. rb_parent = &tmp->vm_rb;
  223. mm->map_count++;
  224. retval = copy_page_range(mm, current->mm, tmp);
  225. spin_unlock(&mm->page_table_lock);
  226. if (tmp->vm_ops && tmp->vm_ops->open)
  227. tmp->vm_ops->open(tmp);
  228. if (retval)
  229. goto out;
  230. }
  231. retval = 0;
  232. out:
  233. flush_tlb_mm(current->mm);
  234. up_write(&oldmm->mmap_sem);
  235. return retval;
  236. fail_nomem_policy:
  237. kmem_cache_free(vm_area_cachep, tmp);
  238. fail_nomem:
  239. retval = -ENOMEM;
  240. vm_unacct_memory(charge);
  241. goto out;
  242. }
  243. static inline int mm_alloc_pgd(struct mm_struct * mm)
  244. {
  245. mm->pgd = pgd_alloc(mm);
  246. if (unlikely(!mm->pgd))
  247. return -ENOMEM;
  248. return 0;
  249. }
  250. static inline void mm_free_pgd(struct mm_struct * mm)
  251. {
  252. pgd_free(mm->pgd);
  253. }
  254. #else
  255. #define dup_mmap(mm, oldmm) (0)
  256. #define mm_alloc_pgd(mm) (0)
  257. #define mm_free_pgd(mm)
  258. #endif /* CONFIG_MMU */
  259. __cacheline_aligned_in_smp DEFINE_SPINLOCK(mmlist_lock);
  260. #define allocate_mm() (kmem_cache_alloc(mm_cachep, SLAB_KERNEL))
  261. #define free_mm(mm) (kmem_cache_free(mm_cachep, (mm)))
  262. #include <linux/init_task.h>
  263. static struct mm_struct * mm_init(struct mm_struct * mm)
  264. {
  265. atomic_set(&mm->mm_users, 1);
  266. atomic_set(&mm->mm_count, 1);
  267. init_rwsem(&mm->mmap_sem);
  268. INIT_LIST_HEAD(&mm->mmlist);
  269. mm->core_waiters = 0;
  270. mm->nr_ptes = 0;
  271. spin_lock_init(&mm->page_table_lock);
  272. rwlock_init(&mm->ioctx_list_lock);
  273. mm->ioctx_list = NULL;
  274. mm->default_kioctx = (struct kioctx)INIT_KIOCTX(mm->default_kioctx, *mm);
  275. mm->free_area_cache = TASK_UNMAPPED_BASE;
  276. if (likely(!mm_alloc_pgd(mm))) {
  277. mm->def_flags = 0;
  278. return mm;
  279. }
  280. free_mm(mm);
  281. return NULL;
  282. }
  283. /*
  284. * Allocate and initialize an mm_struct.
  285. */
  286. struct mm_struct * mm_alloc(void)
  287. {
  288. struct mm_struct * mm;
  289. mm = allocate_mm();
  290. if (mm) {
  291. memset(mm, 0, sizeof(*mm));
  292. mm = mm_init(mm);
  293. }
  294. return mm;
  295. }
  296. /*
  297. * Called when the last reference to the mm
  298. * is dropped: either by a lazy thread or by
  299. * mmput. Free the page directory and the mm.
  300. */
  301. void fastcall __mmdrop(struct mm_struct *mm)
  302. {
  303. BUG_ON(mm == &init_mm);
  304. mm_free_pgd(mm);
  305. destroy_context(mm);
  306. free_mm(mm);
  307. }
  308. /*
  309. * Decrement the use count and release all resources for an mm.
  310. */
  311. void mmput(struct mm_struct *mm)
  312. {
  313. if (atomic_dec_and_test(&mm->mm_users)) {
  314. exit_aio(mm);
  315. exit_mmap(mm);
  316. if (!list_empty(&mm->mmlist)) {
  317. spin_lock(&mmlist_lock);
  318. list_del(&mm->mmlist);
  319. spin_unlock(&mmlist_lock);
  320. }
  321. put_swap_token(mm);
  322. mmdrop(mm);
  323. }
  324. }
  325. EXPORT_SYMBOL_GPL(mmput);
  326. /**
  327. * get_task_mm - acquire a reference to the task's mm
  328. *
  329. * Returns %NULL if the task has no mm. Checks PF_BORROWED_MM (meaning
  330. * this kernel workthread has transiently adopted a user mm with use_mm,
  331. * to do its AIO) is not set and if so returns a reference to it, after
  332. * bumping up the use count. User must release the mm via mmput()
  333. * after use. Typically used by /proc and ptrace.
  334. */
  335. struct mm_struct *get_task_mm(struct task_struct *task)
  336. {
  337. struct mm_struct *mm;
  338. task_lock(task);
  339. mm = task->mm;
  340. if (mm) {
  341. if (task->flags & PF_BORROWED_MM)
  342. mm = NULL;
  343. else
  344. atomic_inc(&mm->mm_users);
  345. }
  346. task_unlock(task);
  347. return mm;
  348. }
  349. EXPORT_SYMBOL_GPL(get_task_mm);
  350. /* Please note the differences between mmput and mm_release.
  351. * mmput is called whenever we stop holding onto a mm_struct,
  352. * error success whatever.
  353. *
  354. * mm_release is called after a mm_struct has been removed
  355. * from the current process.
  356. *
  357. * This difference is important for error handling, when we
  358. * only half set up a mm_struct for a new process and need to restore
  359. * the old one. Because we mmput the new mm_struct before
  360. * restoring the old one. . .
  361. * Eric Biederman 10 January 1998
  362. */
  363. void mm_release(struct task_struct *tsk, struct mm_struct *mm)
  364. {
  365. struct completion *vfork_done = tsk->vfork_done;
  366. /* Get rid of any cached register state */
  367. deactivate_mm(tsk, mm);
  368. /* notify parent sleeping on vfork() */
  369. if (vfork_done) {
  370. tsk->vfork_done = NULL;
  371. complete(vfork_done);
  372. }
  373. if (tsk->clear_child_tid && atomic_read(&mm->mm_users) > 1) {
  374. u32 __user * tidptr = tsk->clear_child_tid;
  375. tsk->clear_child_tid = NULL;
  376. /*
  377. * We don't check the error code - if userspace has
  378. * not set up a proper pointer then tough luck.
  379. */
  380. put_user(0, tidptr);
  381. sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
  382. }
  383. }
  384. static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
  385. {
  386. struct mm_struct * mm, *oldmm;
  387. int retval;
  388. tsk->min_flt = tsk->maj_flt = 0;
  389. tsk->nvcsw = tsk->nivcsw = 0;
  390. tsk->mm = NULL;
  391. tsk->active_mm = NULL;
  392. /*
  393. * Are we cloning a kernel thread?
  394. *
  395. * We need to steal a active VM for that..
  396. */
  397. oldmm = current->mm;
  398. if (!oldmm)
  399. return 0;
  400. if (clone_flags & CLONE_VM) {
  401. atomic_inc(&oldmm->mm_users);
  402. mm = oldmm;
  403. /*
  404. * There are cases where the PTL is held to ensure no
  405. * new threads start up in user mode using an mm, which
  406. * allows optimizing out ipis; the tlb_gather_mmu code
  407. * is an example.
  408. */
  409. spin_unlock_wait(&oldmm->page_table_lock);
  410. goto good_mm;
  411. }
  412. retval = -ENOMEM;
  413. mm = allocate_mm();
  414. if (!mm)
  415. goto fail_nomem;
  416. /* Copy the current MM stuff.. */
  417. memcpy(mm, oldmm, sizeof(*mm));
  418. if (!mm_init(mm))
  419. goto fail_nomem;
  420. if (init_new_context(tsk,mm))
  421. goto fail_nocontext;
  422. retval = dup_mmap(mm, oldmm);
  423. if (retval)
  424. goto free_pt;
  425. mm->hiwater_rss = get_mm_counter(mm,rss);
  426. mm->hiwater_vm = mm->total_vm;
  427. good_mm:
  428. tsk->mm = mm;
  429. tsk->active_mm = mm;
  430. return 0;
  431. free_pt:
  432. mmput(mm);
  433. fail_nomem:
  434. return retval;
  435. fail_nocontext:
  436. /*
  437. * If init_new_context() failed, we cannot use mmput() to free the mm
  438. * because it calls destroy_context()
  439. */
  440. mm_free_pgd(mm);
  441. free_mm(mm);
  442. return retval;
  443. }
  444. static inline struct fs_struct *__copy_fs_struct(struct fs_struct *old)
  445. {
  446. struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
  447. /* We don't need to lock fs - think why ;-) */
  448. if (fs) {
  449. atomic_set(&fs->count, 1);
  450. rwlock_init(&fs->lock);
  451. fs->umask = old->umask;
  452. read_lock(&old->lock);
  453. fs->rootmnt = mntget(old->rootmnt);
  454. fs->root = dget(old->root);
  455. fs->pwdmnt = mntget(old->pwdmnt);
  456. fs->pwd = dget(old->pwd);
  457. if (old->altroot) {
  458. fs->altrootmnt = mntget(old->altrootmnt);
  459. fs->altroot = dget(old->altroot);
  460. } else {
  461. fs->altrootmnt = NULL;
  462. fs->altroot = NULL;
  463. }
  464. read_unlock(&old->lock);
  465. }
  466. return fs;
  467. }
  468. struct fs_struct *copy_fs_struct(struct fs_struct *old)
  469. {
  470. return __copy_fs_struct(old);
  471. }
  472. EXPORT_SYMBOL_GPL(copy_fs_struct);
  473. static inline int copy_fs(unsigned long clone_flags, struct task_struct * tsk)
  474. {
  475. if (clone_flags & CLONE_FS) {
  476. atomic_inc(&current->fs->count);
  477. return 0;
  478. }
  479. tsk->fs = __copy_fs_struct(current->fs);
  480. if (!tsk->fs)
  481. return -ENOMEM;
  482. return 0;
  483. }
  484. static int count_open_files(struct files_struct *files, int size)
  485. {
  486. int i;
  487. /* Find the last open fd */
  488. for (i = size/(8*sizeof(long)); i > 0; ) {
  489. if (files->open_fds->fds_bits[--i])
  490. break;
  491. }
  492. i = (i+1) * 8 * sizeof(long);
  493. return i;
  494. }
  495. static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
  496. {
  497. struct files_struct *oldf, *newf;
  498. struct file **old_fds, **new_fds;
  499. int open_files, size, i, error = 0, expand;
  500. /*
  501. * A background process may not have any files ...
  502. */
  503. oldf = current->files;
  504. if (!oldf)
  505. goto out;
  506. if (clone_flags & CLONE_FILES) {
  507. atomic_inc(&oldf->count);
  508. goto out;
  509. }
  510. /*
  511. * Note: we may be using current for both targets (See exec.c)
  512. * This works because we cache current->files (old) as oldf. Don't
  513. * break this.
  514. */
  515. tsk->files = NULL;
  516. error = -ENOMEM;
  517. newf = kmem_cache_alloc(files_cachep, SLAB_KERNEL);
  518. if (!newf)
  519. goto out;
  520. atomic_set(&newf->count, 1);
  521. spin_lock_init(&newf->file_lock);
  522. newf->next_fd = 0;
  523. newf->max_fds = NR_OPEN_DEFAULT;
  524. newf->max_fdset = __FD_SETSIZE;
  525. newf->close_on_exec = &newf->close_on_exec_init;
  526. newf->open_fds = &newf->open_fds_init;
  527. newf->fd = &newf->fd_array[0];
  528. spin_lock(&oldf->file_lock);
  529. open_files = count_open_files(oldf, oldf->max_fdset);
  530. expand = 0;
  531. /*
  532. * Check whether we need to allocate a larger fd array or fd set.
  533. * Note: we're not a clone task, so the open count won't change.
  534. */
  535. if (open_files > newf->max_fdset) {
  536. newf->max_fdset = 0;
  537. expand = 1;
  538. }
  539. if (open_files > newf->max_fds) {
  540. newf->max_fds = 0;
  541. expand = 1;
  542. }
  543. /* if the old fdset gets grown now, we'll only copy up to "size" fds */
  544. if (expand) {
  545. spin_unlock(&oldf->file_lock);
  546. spin_lock(&newf->file_lock);
  547. error = expand_files(newf, open_files-1);
  548. spin_unlock(&newf->file_lock);
  549. if (error < 0)
  550. goto out_release;
  551. spin_lock(&oldf->file_lock);
  552. }
  553. old_fds = oldf->fd;
  554. new_fds = newf->fd;
  555. memcpy(newf->open_fds->fds_bits, oldf->open_fds->fds_bits, open_files/8);
  556. memcpy(newf->close_on_exec->fds_bits, oldf->close_on_exec->fds_bits, open_files/8);
  557. for (i = open_files; i != 0; i--) {
  558. struct file *f = *old_fds++;
  559. if (f) {
  560. get_file(f);
  561. } else {
  562. /*
  563. * The fd may be claimed in the fd bitmap but not yet
  564. * instantiated in the files array if a sibling thread
  565. * is partway through open(). So make sure that this
  566. * fd is available to the new process.
  567. */
  568. FD_CLR(open_files - i, newf->open_fds);
  569. }
  570. *new_fds++ = f;
  571. }
  572. spin_unlock(&oldf->file_lock);
  573. /* compute the remainder to be cleared */
  574. size = (newf->max_fds - open_files) * sizeof(struct file *);
  575. /* This is long word aligned thus could use a optimized version */
  576. memset(new_fds, 0, size);
  577. if (newf->max_fdset > open_files) {
  578. int left = (newf->max_fdset-open_files)/8;
  579. int start = open_files / (8 * sizeof(unsigned long));
  580. memset(&newf->open_fds->fds_bits[start], 0, left);
  581. memset(&newf->close_on_exec->fds_bits[start], 0, left);
  582. }
  583. tsk->files = newf;
  584. error = 0;
  585. out:
  586. return error;
  587. out_release:
  588. free_fdset (newf->close_on_exec, newf->max_fdset);
  589. free_fdset (newf->open_fds, newf->max_fdset);
  590. free_fd_array(newf->fd, newf->max_fds);
  591. kmem_cache_free(files_cachep, newf);
  592. goto out;
  593. }
  594. /*
  595. * Helper to unshare the files of the current task.
  596. * We don't want to expose copy_files internals to
  597. * the exec layer of the kernel.
  598. */
  599. int unshare_files(void)
  600. {
  601. struct files_struct *files = current->files;
  602. int rc;
  603. if(!files)
  604. BUG();
  605. /* This can race but the race causes us to copy when we don't
  606. need to and drop the copy */
  607. if(atomic_read(&files->count) == 1)
  608. {
  609. atomic_inc(&files->count);
  610. return 0;
  611. }
  612. rc = copy_files(0, current);
  613. if(rc)
  614. current->files = files;
  615. return rc;
  616. }
  617. EXPORT_SYMBOL(unshare_files);
  618. static inline int copy_sighand(unsigned long clone_flags, struct task_struct * tsk)
  619. {
  620. struct sighand_struct *sig;
  621. if (clone_flags & (CLONE_SIGHAND | CLONE_THREAD)) {
  622. atomic_inc(&current->sighand->count);
  623. return 0;
  624. }
  625. sig = kmem_cache_alloc(sighand_cachep, GFP_KERNEL);
  626. tsk->sighand = sig;
  627. if (!sig)
  628. return -ENOMEM;
  629. spin_lock_init(&sig->siglock);
  630. atomic_set(&sig->count, 1);
  631. memcpy(sig->action, current->sighand->action, sizeof(sig->action));
  632. return 0;
  633. }
  634. static inline int copy_signal(unsigned long clone_flags, struct task_struct * tsk)
  635. {
  636. struct signal_struct *sig;
  637. int ret;
  638. if (clone_flags & CLONE_THREAD) {
  639. atomic_inc(&current->signal->count);
  640. atomic_inc(&current->signal->live);
  641. return 0;
  642. }
  643. sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
  644. tsk->signal = sig;
  645. if (!sig)
  646. return -ENOMEM;
  647. ret = copy_thread_group_keys(tsk);
  648. if (ret < 0) {
  649. kmem_cache_free(signal_cachep, sig);
  650. return ret;
  651. }
  652. atomic_set(&sig->count, 1);
  653. atomic_set(&sig->live, 1);
  654. init_waitqueue_head(&sig->wait_chldexit);
  655. sig->flags = 0;
  656. sig->group_exit_code = 0;
  657. sig->group_exit_task = NULL;
  658. sig->group_stop_count = 0;
  659. sig->curr_target = NULL;
  660. init_sigpending(&sig->shared_pending);
  661. INIT_LIST_HEAD(&sig->posix_timers);
  662. sig->it_real_value = sig->it_real_incr = 0;
  663. sig->real_timer.function = it_real_fn;
  664. sig->real_timer.data = (unsigned long) tsk;
  665. init_timer(&sig->real_timer);
  666. sig->it_virt_expires = cputime_zero;
  667. sig->it_virt_incr = cputime_zero;
  668. sig->it_prof_expires = cputime_zero;
  669. sig->it_prof_incr = cputime_zero;
  670. sig->tty = current->signal->tty;
  671. sig->pgrp = process_group(current);
  672. sig->session = current->signal->session;
  673. sig->leader = 0; /* session leadership doesn't inherit */
  674. sig->tty_old_pgrp = 0;
  675. sig->utime = sig->stime = sig->cutime = sig->cstime = cputime_zero;
  676. sig->nvcsw = sig->nivcsw = sig->cnvcsw = sig->cnivcsw = 0;
  677. sig->min_flt = sig->maj_flt = sig->cmin_flt = sig->cmaj_flt = 0;
  678. sig->sched_time = 0;
  679. INIT_LIST_HEAD(&sig->cpu_timers[0]);
  680. INIT_LIST_HEAD(&sig->cpu_timers[1]);
  681. INIT_LIST_HEAD(&sig->cpu_timers[2]);
  682. task_lock(current->group_leader);
  683. memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
  684. task_unlock(current->group_leader);
  685. if (sig->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY) {
  686. /*
  687. * New sole thread in the process gets an expiry time
  688. * of the whole CPU time limit.
  689. */
  690. tsk->it_prof_expires =
  691. secs_to_cputime(sig->rlim[RLIMIT_CPU].rlim_cur);
  692. }
  693. return 0;
  694. }
  695. static inline void copy_flags(unsigned long clone_flags, struct task_struct *p)
  696. {
  697. unsigned long new_flags = p->flags;
  698. new_flags &= ~PF_SUPERPRIV;
  699. new_flags |= PF_FORKNOEXEC;
  700. if (!(clone_flags & CLONE_PTRACE))
  701. p->ptrace = 0;
  702. p->flags = new_flags;
  703. }
  704. asmlinkage long sys_set_tid_address(int __user *tidptr)
  705. {
  706. current->clear_child_tid = tidptr;
  707. return current->pid;
  708. }
  709. /*
  710. * This creates a new process as a copy of the old one,
  711. * but does not actually start it yet.
  712. *
  713. * It copies the registers, and all the appropriate
  714. * parts of the process environment (as per the clone
  715. * flags). The actual kick-off is left to the caller.
  716. */
  717. static task_t *copy_process(unsigned long clone_flags,
  718. unsigned long stack_start,
  719. struct pt_regs *regs,
  720. unsigned long stack_size,
  721. int __user *parent_tidptr,
  722. int __user *child_tidptr,
  723. int pid)
  724. {
  725. int retval;
  726. struct task_struct *p = NULL;
  727. if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
  728. return ERR_PTR(-EINVAL);
  729. /*
  730. * Thread groups must share signals as well, and detached threads
  731. * can only be started up within the thread group.
  732. */
  733. if ((clone_flags & CLONE_THREAD) && !(clone_flags & CLONE_SIGHAND))
  734. return ERR_PTR(-EINVAL);
  735. /*
  736. * Shared signal handlers imply shared VM. By way of the above,
  737. * thread groups also imply shared VM. Blocking this case allows
  738. * for various simplifications in other code.
  739. */
  740. if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM))
  741. return ERR_PTR(-EINVAL);
  742. retval = security_task_create(clone_flags);
  743. if (retval)
  744. goto fork_out;
  745. retval = -ENOMEM;
  746. p = dup_task_struct(current);
  747. if (!p)
  748. goto fork_out;
  749. retval = -EAGAIN;
  750. if (atomic_read(&p->user->processes) >=
  751. p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
  752. if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
  753. p->user != &root_user)
  754. goto bad_fork_free;
  755. }
  756. atomic_inc(&p->user->__count);
  757. atomic_inc(&p->user->processes);
  758. get_group_info(p->group_info);
  759. /*
  760. * If multiple threads are within copy_process(), then this check
  761. * triggers too late. This doesn't hurt, the check is only there
  762. * to stop root fork bombs.
  763. */
  764. if (nr_threads >= max_threads)
  765. goto bad_fork_cleanup_count;
  766. if (!try_module_get(p->thread_info->exec_domain->module))
  767. goto bad_fork_cleanup_count;
  768. if (p->binfmt && !try_module_get(p->binfmt->module))
  769. goto bad_fork_cleanup_put_domain;
  770. p->did_exec = 0;
  771. copy_flags(clone_flags, p);
  772. p->pid = pid;
  773. retval = -EFAULT;
  774. if (clone_flags & CLONE_PARENT_SETTID)
  775. if (put_user(p->pid, parent_tidptr))
  776. goto bad_fork_cleanup;
  777. p->proc_dentry = NULL;
  778. INIT_LIST_HEAD(&p->children);
  779. INIT_LIST_HEAD(&p->sibling);
  780. p->vfork_done = NULL;
  781. spin_lock_init(&p->alloc_lock);
  782. spin_lock_init(&p->proc_lock);
  783. clear_tsk_thread_flag(p, TIF_SIGPENDING);
  784. init_sigpending(&p->pending);
  785. p->utime = cputime_zero;
  786. p->stime = cputime_zero;
  787. p->sched_time = 0;
  788. p->rchar = 0; /* I/O counter: bytes read */
  789. p->wchar = 0; /* I/O counter: bytes written */
  790. p->syscr = 0; /* I/O counter: read syscalls */
  791. p->syscw = 0; /* I/O counter: write syscalls */
  792. acct_clear_integrals(p);
  793. p->it_virt_expires = cputime_zero;
  794. p->it_prof_expires = cputime_zero;
  795. p->it_sched_expires = 0;
  796. INIT_LIST_HEAD(&p->cpu_timers[0]);
  797. INIT_LIST_HEAD(&p->cpu_timers[1]);
  798. INIT_LIST_HEAD(&p->cpu_timers[2]);
  799. p->lock_depth = -1; /* -1 = no lock */
  800. do_posix_clock_monotonic_gettime(&p->start_time);
  801. p->security = NULL;
  802. p->io_context = NULL;
  803. p->io_wait = NULL;
  804. p->audit_context = NULL;
  805. #ifdef CONFIG_NUMA
  806. p->mempolicy = mpol_copy(p->mempolicy);
  807. if (IS_ERR(p->mempolicy)) {
  808. retval = PTR_ERR(p->mempolicy);
  809. p->mempolicy = NULL;
  810. goto bad_fork_cleanup;
  811. }
  812. #endif
  813. p->tgid = p->pid;
  814. if (clone_flags & CLONE_THREAD)
  815. p->tgid = current->tgid;
  816. if ((retval = security_task_alloc(p)))
  817. goto bad_fork_cleanup_policy;
  818. if ((retval = audit_alloc(p)))
  819. goto bad_fork_cleanup_security;
  820. /* copy all the process information */
  821. if ((retval = copy_semundo(clone_flags, p)))
  822. goto bad_fork_cleanup_audit;
  823. if ((retval = copy_files(clone_flags, p)))
  824. goto bad_fork_cleanup_semundo;
  825. if ((retval = copy_fs(clone_flags, p)))
  826. goto bad_fork_cleanup_files;
  827. if ((retval = copy_sighand(clone_flags, p)))
  828. goto bad_fork_cleanup_fs;
  829. if ((retval = copy_signal(clone_flags, p)))
  830. goto bad_fork_cleanup_sighand;
  831. if ((retval = copy_mm(clone_flags, p)))
  832. goto bad_fork_cleanup_signal;
  833. if ((retval = copy_keys(clone_flags, p)))
  834. goto bad_fork_cleanup_mm;
  835. if ((retval = copy_namespace(clone_flags, p)))
  836. goto bad_fork_cleanup_keys;
  837. retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
  838. if (retval)
  839. goto bad_fork_cleanup_namespace;
  840. p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
  841. /*
  842. * Clear TID on mm_release()?
  843. */
  844. p->clear_child_tid = (clone_flags & CLONE_CHILD_CLEARTID) ? child_tidptr: NULL;
  845. /*
  846. * Syscall tracing should be turned off in the child regardless
  847. * of CLONE_PTRACE.
  848. */
  849. clear_tsk_thread_flag(p, TIF_SYSCALL_TRACE);
  850. /* Our parent execution domain becomes current domain
  851. These must match for thread signalling to apply */
  852. p->parent_exec_id = p->self_exec_id;
  853. /* ok, now we should be set up.. */
  854. p->exit_signal = (clone_flags & CLONE_THREAD) ? -1 : (clone_flags & CSIGNAL);
  855. p->pdeath_signal = 0;
  856. p->exit_state = 0;
  857. /* Perform scheduler related setup */
  858. sched_fork(p);
  859. /*
  860. * Ok, make it visible to the rest of the system.
  861. * We dont wake it up yet.
  862. */
  863. p->group_leader = p;
  864. INIT_LIST_HEAD(&p->ptrace_children);
  865. INIT_LIST_HEAD(&p->ptrace_list);
  866. /* Need tasklist lock for parent etc handling! */
  867. write_lock_irq(&tasklist_lock);
  868. /*
  869. * The task hasn't been attached yet, so cpus_allowed mask cannot
  870. * have changed. The cpus_allowed mask of the parent may have
  871. * changed after it was copied first time, and it may then move to
  872. * another CPU - so we re-copy it here and set the child's CPU to
  873. * the parent's CPU. This avoids alot of nasty races.
  874. */
  875. p->cpus_allowed = current->cpus_allowed;
  876. set_task_cpu(p, smp_processor_id());
  877. /*
  878. * Check for pending SIGKILL! The new thread should not be allowed
  879. * to slip out of an OOM kill. (or normal SIGKILL.)
  880. */
  881. if (sigismember(&current->pending.signal, SIGKILL)) {
  882. write_unlock_irq(&tasklist_lock);
  883. retval = -EINTR;
  884. goto bad_fork_cleanup_namespace;
  885. }
  886. /* CLONE_PARENT re-uses the old parent */
  887. if (clone_flags & (CLONE_PARENT|CLONE_THREAD))
  888. p->real_parent = current->real_parent;
  889. else
  890. p->real_parent = current;
  891. p->parent = p->real_parent;
  892. if (clone_flags & CLONE_THREAD) {
  893. spin_lock(&current->sighand->siglock);
  894. /*
  895. * Important: if an exit-all has been started then
  896. * do not create this new thread - the whole thread
  897. * group is supposed to exit anyway.
  898. */
  899. if (current->signal->flags & SIGNAL_GROUP_EXIT) {
  900. spin_unlock(&current->sighand->siglock);
  901. write_unlock_irq(&tasklist_lock);
  902. retval = -EAGAIN;
  903. goto bad_fork_cleanup_namespace;
  904. }
  905. p->group_leader = current->group_leader;
  906. if (current->signal->group_stop_count > 0) {
  907. /*
  908. * There is an all-stop in progress for the group.
  909. * We ourselves will stop as soon as we check signals.
  910. * Make the new thread part of that group stop too.
  911. */
  912. current->signal->group_stop_count++;
  913. set_tsk_thread_flag(p, TIF_SIGPENDING);
  914. }
  915. if (!cputime_eq(current->signal->it_virt_expires,
  916. cputime_zero) ||
  917. !cputime_eq(current->signal->it_prof_expires,
  918. cputime_zero) ||
  919. current->signal->rlim[RLIMIT_CPU].rlim_cur != RLIM_INFINITY ||
  920. !list_empty(&current->signal->cpu_timers[0]) ||
  921. !list_empty(&current->signal->cpu_timers[1]) ||
  922. !list_empty(&current->signal->cpu_timers[2])) {
  923. /*
  924. * Have child wake up on its first tick to check
  925. * for process CPU timers.
  926. */
  927. p->it_prof_expires = jiffies_to_cputime(1);
  928. }
  929. spin_unlock(&current->sighand->siglock);
  930. }
  931. SET_LINKS(p);
  932. if (unlikely(p->ptrace & PT_PTRACED))
  933. __ptrace_link(p, current->parent);
  934. cpuset_fork(p);
  935. attach_pid(p, PIDTYPE_PID, p->pid);
  936. attach_pid(p, PIDTYPE_TGID, p->tgid);
  937. if (thread_group_leader(p)) {
  938. attach_pid(p, PIDTYPE_PGID, process_group(p));
  939. attach_pid(p, PIDTYPE_SID, p->signal->session);
  940. if (p->pid)
  941. __get_cpu_var(process_counts)++;
  942. }
  943. nr_threads++;
  944. total_forks++;
  945. write_unlock_irq(&tasklist_lock);
  946. retval = 0;
  947. fork_out:
  948. if (retval)
  949. return ERR_PTR(retval);
  950. return p;
  951. bad_fork_cleanup_namespace:
  952. exit_namespace(p);
  953. bad_fork_cleanup_keys:
  954. exit_keys(p);
  955. bad_fork_cleanup_mm:
  956. if (p->mm)
  957. mmput(p->mm);
  958. bad_fork_cleanup_signal:
  959. exit_signal(p);
  960. bad_fork_cleanup_sighand:
  961. exit_sighand(p);
  962. bad_fork_cleanup_fs:
  963. exit_fs(p); /* blocking */
  964. bad_fork_cleanup_files:
  965. exit_files(p); /* blocking */
  966. bad_fork_cleanup_semundo:
  967. exit_sem(p);
  968. bad_fork_cleanup_audit:
  969. audit_free(p);
  970. bad_fork_cleanup_security:
  971. security_task_free(p);
  972. bad_fork_cleanup_policy:
  973. #ifdef CONFIG_NUMA
  974. mpol_free(p->mempolicy);
  975. #endif
  976. bad_fork_cleanup:
  977. if (p->binfmt)
  978. module_put(p->binfmt->module);
  979. bad_fork_cleanup_put_domain:
  980. module_put(p->thread_info->exec_domain->module);
  981. bad_fork_cleanup_count:
  982. put_group_info(p->group_info);
  983. atomic_dec(&p->user->processes);
  984. free_uid(p->user);
  985. bad_fork_free:
  986. free_task(p);
  987. goto fork_out;
  988. }
  989. struct pt_regs * __devinit __attribute__((weak)) idle_regs(struct pt_regs *regs)
  990. {
  991. memset(regs, 0, sizeof(struct pt_regs));
  992. return regs;
  993. }
  994. task_t * __devinit fork_idle(int cpu)
  995. {
  996. task_t *task;
  997. struct pt_regs regs;
  998. task = copy_process(CLONE_VM, 0, idle_regs(&regs), 0, NULL, NULL, 0);
  999. if (!task)
  1000. return ERR_PTR(-ENOMEM);
  1001. init_idle(task, cpu);
  1002. unhash_process(task);
  1003. return task;
  1004. }
  1005. static inline int fork_traceflag (unsigned clone_flags)
  1006. {
  1007. if (clone_flags & CLONE_UNTRACED)
  1008. return 0;
  1009. else if (clone_flags & CLONE_VFORK) {
  1010. if (current->ptrace & PT_TRACE_VFORK)
  1011. return PTRACE_EVENT_VFORK;
  1012. } else if ((clone_flags & CSIGNAL) != SIGCHLD) {
  1013. if (current->ptrace & PT_TRACE_CLONE)
  1014. return PTRACE_EVENT_CLONE;
  1015. } else if (current->ptrace & PT_TRACE_FORK)
  1016. return PTRACE_EVENT_FORK;
  1017. return 0;
  1018. }
  1019. /*
  1020. * Ok, this is the main fork-routine.
  1021. *
  1022. * It copies the process, and if successful kick-starts
  1023. * it and waits for it to finish using the VM if required.
  1024. */
  1025. long do_fork(unsigned long clone_flags,
  1026. unsigned long stack_start,
  1027. struct pt_regs *regs,
  1028. unsigned long stack_size,
  1029. int __user *parent_tidptr,
  1030. int __user *child_tidptr)
  1031. {
  1032. struct task_struct *p;
  1033. int trace = 0;
  1034. long pid = alloc_pidmap();
  1035. if (pid < 0)
  1036. return -EAGAIN;
  1037. if (unlikely(current->ptrace)) {
  1038. trace = fork_traceflag (clone_flags);
  1039. if (trace)
  1040. clone_flags |= CLONE_PTRACE;
  1041. }
  1042. p = copy_process(clone_flags, stack_start, regs, stack_size, parent_tidptr, child_tidptr, pid);
  1043. /*
  1044. * Do this prior waking up the new thread - the thread pointer
  1045. * might get invalid after that point, if the thread exits quickly.
  1046. */
  1047. if (!IS_ERR(p)) {
  1048. struct completion vfork;
  1049. if (clone_flags & CLONE_VFORK) {
  1050. p->vfork_done = &vfork;
  1051. init_completion(&vfork);
  1052. }
  1053. if ((p->ptrace & PT_PTRACED) || (clone_flags & CLONE_STOPPED)) {
  1054. /*
  1055. * We'll start up with an immediate SIGSTOP.
  1056. */
  1057. sigaddset(&p->pending.signal, SIGSTOP);
  1058. set_tsk_thread_flag(p, TIF_SIGPENDING);
  1059. }
  1060. if (!(clone_flags & CLONE_STOPPED))
  1061. wake_up_new_task(p, clone_flags);
  1062. else
  1063. p->state = TASK_STOPPED;
  1064. if (unlikely (trace)) {
  1065. current->ptrace_message = pid;
  1066. ptrace_notify ((trace << 8) | SIGTRAP);
  1067. }
  1068. if (clone_flags & CLONE_VFORK) {
  1069. wait_for_completion(&vfork);
  1070. if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE))
  1071. ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP);
  1072. }
  1073. } else {
  1074. free_pidmap(pid);
  1075. pid = PTR_ERR(p);
  1076. }
  1077. return pid;
  1078. }
  1079. void __init proc_caches_init(void)
  1080. {
  1081. sighand_cachep = kmem_cache_create("sighand_cache",
  1082. sizeof(struct sighand_struct), 0,
  1083. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1084. signal_cachep = kmem_cache_create("signal_cache",
  1085. sizeof(struct signal_struct), 0,
  1086. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1087. files_cachep = kmem_cache_create("files_cache",
  1088. sizeof(struct files_struct), 0,
  1089. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1090. fs_cachep = kmem_cache_create("fs_cache",
  1091. sizeof(struct fs_struct), 0,
  1092. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1093. vm_area_cachep = kmem_cache_create("vm_area_struct",
  1094. sizeof(struct vm_area_struct), 0,
  1095. SLAB_PANIC, NULL, NULL);
  1096. mm_cachep = kmem_cache_create("mm_struct",
  1097. sizeof(struct mm_struct), 0,
  1098. SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
  1099. }