From patchwork Mon Oct 11 13:32:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 12549989 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12586C433EF for ; Mon, 11 Oct 2021 13:33:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BAB3C60F6E for ; Mon, 11 Oct 2021 13:33:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org BAB3C60F6E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 5743C6B0072; Mon, 11 Oct 2021 09:33:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 524466B0073; Mon, 11 Oct 2021 09:33:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3ECD66B0074; Mon, 11 Oct 2021 09:33:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0018.hostedemail.com [216.40.44.18]) by kanga.kvack.org (Postfix) with ESMTP id 311946B0072 for ; Mon, 11 Oct 2021 09:33:25 -0400 (EDT) Received: from smtpin37.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id D8A65181AF5C1 for ; Mon, 11 Oct 2021 13:33:24 +0000 (UTC) X-FDA: 78684248328.37.1546078 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf12.hostedemail.com (Postfix) with ESMTP id 811931001127 for ; Mon, 11 Oct 2021 13:33:24 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 7FF7460F38; Mon, 11 Oct 2021 13:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633959202; bh=DXIzCSpi0RMG4dxsT+13/zfQG6b0wwvFu8K9jUKsz4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=boN89nL87b+2RXpe4mOrWkPGADimTy3zB2vYJVOVXzZe9mJTtGw1E5nYKI3FU8g77 lWdg437+a7T1oKsakmN7/slXtLUMHypqF3acPLY9bXdB1ULVngI66/kHaGzrXMBOC+ xcnHkg1DnHJs8g49J9jGjt9Fr9cE/8Lh7cRWZ15UXEzGPWb0gtHZ0XUQ4O1JdqlpIP tCCSw3ga+K5OzvQB8jUGZkIdjBMdUUIscvGxe3U4pPvfLvKPO0Dy0Y8P7ErQNJNwn8 ttOK4+d9xZ/+HRSf0IpdxKW9AEIfbe9E8ogHcZ16Lh6puUH0q7ZaVJscFAMVBOwFLm qksEaMJ0KeyPw== From: Christian Brauner To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Vlastimil Babka , Suren Baghdasaryan , Matthew Bobrowski , Alexander Duyck , David Hildenbrand , Jan Kara , Christian Brauner , Minchan Kim Subject: [PATCH v2 2/2] mm: use pidfd_get_task() Date: Mon, 11 Oct 2021 15:32:45 +0200 Message-Id: <20211011133245.1703103-3-brauner@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211011133245.1703103-1-brauner@kernel.org> References: <20211011133245.1703103-1-brauner@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2998; h=from:subject; bh=hPRC+QAhxeSGyr5q6D0CanWJl4f/7BbqBOnGLZetuAE=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMSSm2PxMcnkzIST7bdw6hkkrbZqTuN5e7t6/sOWp07cFZnGX bXTVO0pZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACbyajkjw4KFN67P+/nA+6990t3uc0 lfd5/65RHpzheW8SP+jUWb6iqG/6Xp8+cuaYv/Yd+yxWPCBMWrZQIZH5a9/tys1G4smTV/DwMA X-Developer-Key: i=christian.brauner@ubuntu.com; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 811931001127 X-Stat-Signature: i8tabfz879w4h3x7ybrzp3t8dfjdw3to Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=boN89nL8; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of brauner@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=brauner@kernel.org X-HE-Tag: 1633959204-635630 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Christian Brauner Instead of duplicating the same code in two places use the newly added pidfd_get_task() helper. This fixes an (unimportant for now) bug where PIDTYPE_PID is used whereas PIDTYPE_TGID should have been used. Link: https://lore.kernel.org/r/20211004125050.1153693-3-christian.brauner@ubuntu.com Cc: Vlastimil Babka Cc: Suren Baghdasaryan Cc: Matthew Bobrowski Cc: Alexander Duyck Cc: David Hildenbrand Cc: Jan Kara Cc: Minchan Kim Reviewed-by: Matthew Bobrowski Signed-off-by: Christian Brauner Acked-by: David Hildenbrand --- /* v2 */ unchanged --- mm/madvise.c | 15 +++------------ mm/oom_kill.c | 15 +++------------ 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 0734db8d53a7..8c927202bbe6 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1235,7 +1235,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, struct iovec iovstack[UIO_FASTIOV], iovec; struct iovec *iov = iovstack; struct iov_iter iter; - struct pid *pid; struct task_struct *task; struct mm_struct *mm; size_t total_len; @@ -1250,18 +1249,12 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, if (ret < 0) goto out; - pid = pidfd_get_pid(pidfd, &f_flags); - if (IS_ERR(pid)) { - ret = PTR_ERR(pid); + task = pidfd_get_task(pidfd, &f_flags); + if (IS_ERR(task)) { + ret = PTR_ERR(task); goto free_iov; } - task = get_pid_task(pid, PIDTYPE_PID); - if (!task) { - ret = -ESRCH; - goto put_pid; - } - if (!process_madvise_behavior_valid(behavior)) { ret = -EINVAL; goto release_task; @@ -1301,8 +1294,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, mmput(mm); release_task: put_task_struct(task); -put_pid: - put_pid(pid); free_iov: kfree(iov); out: diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 831340e7ad8b..70d399d5817e 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -1151,21 +1151,14 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags) struct task_struct *p; unsigned int f_flags; bool reap = true; - struct pid *pid; long ret = 0; if (flags) return -EINVAL; - pid = pidfd_get_pid(pidfd, &f_flags); - if (IS_ERR(pid)) - return PTR_ERR(pid); - - task = get_pid_task(pid, PIDTYPE_TGID); - if (!task) { - ret = -ESRCH; - goto put_pid; - } + task = pidfd_get_task(pidfd, &f_flags); + if (IS_ERR(task)) + return PTR_ERR(task); /* * Make sure to choose a thread which still has a reference to mm @@ -1204,8 +1197,6 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags) mmdrop(mm); put_task: put_task_struct(task); -put_pid: - put_pid(pid); return ret; #else return -ENOSYS;