From: Nanyong Sun <sunnanyong@huawei.com>
To: <akpm@linux-foundation.org>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
<wangkefeng.wang@huawei.com>, <sunnanyong@huawei.com>
Subject: [PATCH] mm: migrate: simplify find_mm_struct()
Date: Thu, 5 Sep 2024 23:31:18 +0800 [thread overview]
Message-ID: <20240905153118.1205173-1-sunnanyong@huawei.com> (raw)
Use find_get_task_by_vpid() to replace the task_struct find logic in
find_mm_struct(), note that this patch move the ptrace_may_access()
call out from rcu_read_lock() scope, this is ok because it actually
does not need it, find_get_task_by_vpid() already get the pid and task
safely, ptrace_may_access() can use the task safely, like what
sched_core_share_pid() similarly do.
Signed-off-by: Nanyong Sun <sunnanyong@huawei.com>
---
mm/migrate.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/mm/migrate.c b/mm/migrate.c
index 923ea80ba744..e9477c64c267 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -2432,25 +2432,19 @@ static struct mm_struct *find_mm_struct(pid_t pid, nodemask_t *mem_nodes)
return current->mm;
}
- /* Find the mm_struct */
- rcu_read_lock();
- task = find_task_by_vpid(pid);
+ task = find_get_task_by_vpid(pid);
if (!task) {
- rcu_read_unlock();
return ERR_PTR(-ESRCH);
}
- get_task_struct(task);
/*
* Check if this process has the right to modify the specified
* process. Use the regular "ptrace_may_access()" checks.
*/
if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) {
- rcu_read_unlock();
mm = ERR_PTR(-EPERM);
goto out;
}
- rcu_read_unlock();
mm = ERR_PTR(security_task_movememory(task));
if (IS_ERR(mm))
--
2.33.0
reply other threads:[~2024-09-05 15:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240905153118.1205173-1-sunnanyong@huawei.com \
--to=sunnanyong@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=wangkefeng.wang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox