Skip to content

Commit 7addf44

Browse files
author
Dominik Brodowski
committed
mm: add kernel_move_pages() helper, move compat syscall to mm/migrate.c
Move compat_sys_move_pages() to mm/migrate.c and make it call a newly introduced helper -- kernel_move_pages() -- instead of the syscall. This patch is part of a series which removes in-kernel calls to syscalls. On this basis, the syscall entry path can be streamlined. For details, see http://lkml.kernel.org/r/20180325162527.GA17492@light.dominikbrodowski.net Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-mm@kvack.org Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
1 parent b6e9b0b commit 7addf44

2 files changed

Lines changed: 35 additions & 26 deletions

File tree

‎kernel/compat.c‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -488,28 +488,6 @@ get_compat_sigset(sigset_t *set, const compat_sigset_t __user *compat)
488488
}
489489
EXPORT_SYMBOL_GPL(get_compat_sigset);
490490

491-
#ifdef CONFIG_NUMA
492-
COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
493-
compat_uptr_t __user *, pages32,
494-
const int __user *, nodes,
495-
int __user *, status,
496-
int, flags)
497-
{
498-
const void __user * __user *pages;
499-
int i;
500-
501-
pages = compat_alloc_user_space(nr_pages * sizeof(void *));
502-
for (i = 0; i < nr_pages; i++) {
503-
compat_uptr_t p;
504-
505-
if (get_user(p, pages32 + i) ||
506-
put_user(compat_ptr(p), pages + i))
507-
return -EFAULT;
508-
}
509-
return sys_move_pages(pid, nr_pages, pages, nodes, status, flags);
510-
}
511-
#endif
512-
513491
/*
514492
* Allocate user-space memory for the duration of a single system call,
515493
* in order to marshall parameters inside a compat thunk.

‎mm/migrate.c‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/backing-dev.h>
3535
#include <linux/compaction.h>
3636
#include <linux/syscalls.h>
37+
#include <linux/compat.h>
3738
#include <linux/hugetlb.h>
3839
#include <linux/hugetlb_cgroup.h>
3940
#include <linux/gfp.h>
@@ -1745,10 +1746,10 @@ static int do_pages_stat(struct mm_struct *mm, unsigned long nr_pages,
17451746
* Move a list of pages in the address space of the currently executing
17461747
* process.
17471748
*/
1748-
SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
1749-
const void __user * __user *, pages,
1750-
const int __user *, nodes,
1751-
int __user *, status, int, flags)
1749+
static int kernel_move_pages(pid_t pid, unsigned long nr_pages,
1750+
const void __user * __user *pages,
1751+
const int __user *nodes,
1752+
int __user *status, int flags)
17521753
{
17531754
struct task_struct *task;
17541755
struct mm_struct *mm;
@@ -1807,6 +1808,36 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
18071808
return err;
18081809
}
18091810

1811+
SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
1812+
const void __user * __user *, pages,
1813+
const int __user *, nodes,
1814+
int __user *, status, int, flags)
1815+
{
1816+
return kernel_move_pages(pid, nr_pages, pages, nodes, status, flags);
1817+
}
1818+
1819+
#ifdef CONFIG_COMPAT
1820+
COMPAT_SYSCALL_DEFINE6(move_pages, pid_t, pid, compat_ulong_t, nr_pages,
1821+
compat_uptr_t __user *, pages32,
1822+
const int __user *, nodes,
1823+
int __user *, status,
1824+
int, flags)
1825+
{
1826+
const void __user * __user *pages;
1827+
int i;
1828+
1829+
pages = compat_alloc_user_space(nr_pages * sizeof(void *));
1830+
for (i = 0; i < nr_pages; i++) {
1831+
compat_uptr_t p;
1832+
1833+
if (get_user(p, pages32 + i) ||
1834+
put_user(compat_ptr(p), pages + i))
1835+
return -EFAULT;
1836+
}
1837+
return kernel_move_pages(pid, nr_pages, pages, nodes, status, flags);
1838+
}
1839+
#endif /* CONFIG_COMPAT */
1840+
18101841
#ifdef CONFIG_NUMA_BALANCING
18111842
/*
18121843
* Returns true if this is a safe migration target node for misplaced NUMA

0 commit comments

Comments
 (0)