summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinchan Kim <minchan@kernel.org>2020-05-30 14:51:09 +1000
committerStephen Rothwell <sfr@canb.auug.org.au>2020-06-02 19:15:36 +1000
commitb4e6875644ed112a492f1bcd8ba21febb5df31f8 (patch)
treeab955900a602492e1d65901b69aca0800367ac46
parent457adc9bc0869a912b42af7303ba4407bc5d3155 (diff)
downloadlinux-b4e6875644ed112a492f1bcd8ba21febb5df31f8.tar.gz
mm: use only pidfd for process_madvise syscall
Based on discussion[1], people didn't feel we need to support both pid and pidfd for every new coming API[2] so this patch keeps only pidfd. This patch also changes flags's type with "unsigned int". [1] https://lore.kernel.org/linux-mm/20200509124817.xmrvsrq3mla6b76k@wittgenstein/ [2] https://lore.kernel.org/linux-mm/9d849087-3359-c4ab-fbec-859e8186c509@virtuozzo.com/ Link: http://lkml.kernel.org/r/20200518211350.GA50295@google.com Signed-off-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Suren Baghdasaryan <surenb@google.com> Cc: David Rientjes <rientjes@google.com> Cc: Arjun Roy <arjunroy@google.com> Cc: Tim Murray <timmurray@google.com> Cc: Daniel Colascione <dancol@google.com> Cc: Sonny Rao <sonnyrao@google.com> Cc: Brian Geffon <bgeffon@google.com> Cc: Shakeel Butt <shakeelb@google.com> Cc: John Dias <joaodias@google.com> Cc: Joel Fernandes <joel@joelfernandes.org> Cc: SeongJae Park <sj38.park@gmail.com> Cc: Oleksandr Natalenko <oleksandr@redhat.com> Cc: Sandeep Patil <sspatil@google.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
-rw-r--r--mm/madvise.c42
1 files changed, 13 insertions, 29 deletions
diff --git a/mm/madvise.c b/mm/madvise.c
index 89a620f8b793..f2a9619d8d46 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -1230,8 +1230,8 @@ static int process_madvise_vec(struct task_struct *target_task,
return ret;
}
-static ssize_t do_process_madvise(int which, pid_t upid, struct iov_iter *iter,
- int behavior, unsigned long flags)
+static ssize_t do_process_madvise(int pidfd, struct iov_iter *iter,
+ int behavior, unsigned int flags)
{
ssize_t ret;
struct pid *pid;
@@ -1242,26 +1242,12 @@ static ssize_t do_process_madvise(int which, pid_t upid, struct iov_iter *iter,
if (flags != 0)
return -EINVAL;
- switch (which) {
- case P_PID:
- if (upid <= 0)
- return -EINVAL;
-
- pid = find_get_pid(upid);
- if (!pid)
- return -ESRCH;
- break;
- case P_PIDFD:
- if (upid < 0)
- return -EINVAL;
-
- pid = pidfd_get_pid(upid);
- if (IS_ERR(pid))
- return PTR_ERR(pid);
- break;
- default:
+ if (pidfd < 0)
return -EINVAL;
- }
+
+ pid = pidfd_get_pid(pidfd);
+ if (IS_ERR(pid))
+ return PTR_ERR(pid);
task = get_pid_task(pid, PIDTYPE_PID);
if (!task) {
@@ -1293,9 +1279,8 @@ put_pid:
return ret;
}
-SYSCALL_DEFINE6(process_madvise, int, which, pid_t, upid,
- const struct iovec __user *, vec, unsigned long, vlen,
- int, behavior, unsigned long, flags)
+SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
+ unsigned long, vlen, int, behavior, unsigned int, flags)
{
ssize_t ret;
struct iovec iovstack[UIO_FASTIOV];
@@ -1304,19 +1289,18 @@ SYSCALL_DEFINE6(process_madvise, int, which, pid_t, upid,
ret = import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter);
if (ret >= 0) {
- ret = do_process_madvise(which, upid, &iter, behavior, flags);
+ ret = do_process_madvise(pidfd, &iter, behavior, flags);
kfree(iov);
}
return ret;
}
#ifdef CONFIG_COMPAT
-COMPAT_SYSCALL_DEFINE6(process_madvise, compat_int_t, which,
- compat_pid_t, upid,
+COMPAT_SYSCALL_DEFINE5(process_madvise, compat_int_t, pidfd,
const struct compat_iovec __user *, vec,
compat_ulong_t, vlen,
compat_int_t, behavior,
- compat_ulong_t, flags)
+ compat_int_t, flags)
{
ssize_t ret;
@@ -1327,7 +1311,7 @@ COMPAT_SYSCALL_DEFINE6(process_madvise, compat_int_t, which,
ret = compat_import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack),
&iov, &iter);
if (ret >= 0) {
- ret = do_process_madvise(which, upid, &iter, behavior, flags);
+ ret = do_process_madvise(pidfd, &iter, behavior, flags);
kfree(iov);
}
return ret;