Skip to content

Commit

Permalink
mm: use only pidfd for process_madvise syscall
Browse files Browse the repository at this point in the history
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/[email protected]/

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Minchan Kim <[email protected]>
Reviewed-by: Suren Baghdasaryan <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Arjun Roy <[email protected]>
Cc: Tim Murray <[email protected]>
Cc: Daniel Colascione <[email protected]>
Cc: Sonny Rao <[email protected]>
Cc: Brian Geffon <[email protected]>
Cc: Shakeel Butt <[email protected]>
Cc: John Dias <[email protected]>
Cc: Joel Fernandes <[email protected]>
Cc: SeongJae Park <[email protected]>
Cc: Oleksandr Natalenko <[email protected]>
Cc: Sandeep Patil <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Christian Brauner <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Stephen Rothwell <[email protected]>
  • Loading branch information
minchank authored and sfrothwell committed Jun 5, 2020
1 parent 7c79ea0 commit d8d78ae
Showing 1 changed file with 13 additions and 29 deletions.
42 changes: 13 additions & 29 deletions mm/madvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -1293,9 +1279,8 @@ static ssize_t do_process_madvise(int which, pid_t upid, struct iov_iter *iter,
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];
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit d8d78ae

Please sign in to comment.