forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mm: move use_mm/unuse_mm from aio.c to mm/
Anyone who wants to do copy to/from user from a kernel thread, needs use_mm (like what fs/aio has). Move that into mm/, to make reusing and exporting easier down the line, and make aio use it. Next intended user, besides aio, will be vhost-net. Acked-by: Andrea Arcangeli <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
- Loading branch information
Showing
4 changed files
with
66 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef _LINUX_MMU_CONTEXT_H | ||
#define _LINUX_MMU_CONTEXT_H | ||
|
||
struct mm_struct; | ||
|
||
void use_mm(struct mm_struct *mm); | ||
void unuse_mm(struct mm_struct *mm); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* Copyright (C) 2009 Red Hat, Inc. | ||
* | ||
* See ../COPYING for licensing terms. | ||
*/ | ||
|
||
#include <linux/mm.h> | ||
#include <linux/mmu_context.h> | ||
#include <linux/sched.h> | ||
|
||
#include <asm/mmu_context.h> | ||
|
||
/* | ||
* use_mm | ||
* Makes the calling kernel thread take on the specified | ||
* mm context. | ||
* Called by the retry thread execute retries within the | ||
* iocb issuer's mm context, so that copy_from/to_user | ||
* operations work seamlessly for aio. | ||
* (Note: this routine is intended to be called only | ||
* from a kernel thread context) | ||
*/ | ||
void use_mm(struct mm_struct *mm) | ||
{ | ||
struct mm_struct *active_mm; | ||
struct task_struct *tsk = current; | ||
|
||
task_lock(tsk); | ||
active_mm = tsk->active_mm; | ||
atomic_inc(&mm->mm_count); | ||
tsk->mm = mm; | ||
tsk->active_mm = mm; | ||
switch_mm(active_mm, mm, tsk); | ||
task_unlock(tsk); | ||
|
||
mmdrop(active_mm); | ||
} | ||
|
||
/* | ||
* unuse_mm | ||
* Reverses the effect of use_mm, i.e. releases the | ||
* specified mm context which was earlier taken on | ||
* by the calling kernel thread | ||
* (Note: this routine is intended to be called only | ||
* from a kernel thread context) | ||
*/ | ||
void unuse_mm(struct mm_struct *mm) | ||
{ | ||
struct task_struct *tsk = current; | ||
|
||
task_lock(tsk); | ||
tsk->mm = NULL; | ||
/* active_mm is still 'mm' */ | ||
enter_lazy_tlb(mm, tsk); | ||
task_unlock(tsk); | ||
} |