From patchwork Thu Sep 5 15:31:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nanyong Sun X-Patchwork-Id: 13792622 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F811CD5BCB for ; Thu, 5 Sep 2024 15:32:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D5A496B008A; Thu, 5 Sep 2024 11:32:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0A1C6B008C; Thu, 5 Sep 2024 11:32:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAC7D6B0095; Thu, 5 Sep 2024 11:32:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 9876E6B008A for ; Thu, 5 Sep 2024 11:32:36 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 23DC81204F8 for ; Thu, 5 Sep 2024 15:32:36 +0000 (UTC) X-FDA: 82531076712.07.FF2E221 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf03.hostedemail.com (Postfix) with ESMTP id D4BBC20022 for ; Thu, 5 Sep 2024 15:32:33 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of sunnanyong@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=sunnanyong@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725550246; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=jwKiukE/IQU2ZlySdfgtg0HxyaOEclmphuCoxCpw+OI=; b=5PQwaFzXw26pmDsaatP6sHRY3a09g3qVUMbxWkJ1czoSxp1p7imMxM3T0g9f5++gBaLalw iUIpYzWquq356+wx6n5qTKm07j063pRPKnmt1B1yHMlW2fpE50PIf9f6lGqFGicBbLHrif +aP6r/RYV5xb80lrwBAG4N6TVdlO3EE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725550246; a=rsa-sha256; cv=none; b=IwszyhkdnlwL/lj5Qv9VcmOaxLmmgvO8tWJTqd/5jrh0zVwyKl+dcwRGwkU0zYUyvvg831 BVjOiupaniN0vuy/tj3TNq3D+su2n5tHXgnEHG58lCOpeBEB0qPa2GtHbaQ6eA3pedAHnm NpzXRPG6tQJV2313c1TrLPXMHMmOhGA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of sunnanyong@huawei.com designates 45.249.212.190 as permitted sender) smtp.mailfrom=sunnanyong@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4X03Bq4Pcpz20nWD; Thu, 5 Sep 2024 23:27:31 +0800 (CST) Received: from kwepemm600003.china.huawei.com (unknown [7.193.23.202]) by mail.maildlp.com (Postfix) with ESMTPS id 00BAC1400FD; Thu, 5 Sep 2024 23:32:30 +0800 (CST) Received: from huawei.com (10.175.124.71) by kwepemm600003.china.huawei.com (7.193.23.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Thu, 5 Sep 2024 23:32:29 +0800 From: Nanyong Sun To: CC: , , , Subject: [PATCH] mm: migrate: simplify find_mm_struct() Date: Thu, 5 Sep 2024 23:31:18 +0800 Message-ID: <20240905153118.1205173-1-sunnanyong@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.175.124.71] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600003.china.huawei.com (7.193.23.202) X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D4BBC20022 X-Stat-Signature: 17hsxkb9zgswefmqktcawfniedotd8iq X-Rspam-User: X-HE-Tag: 1725550353-683053 X-HE-Meta: U2FsdGVkX18JdsZVHI3KgHsiHdOp8OAqHYF2vg6a8U9BpmsTkV0dclFKihVAQovnIMw4AyEmtu+a5afz2b37EZ2FutB81BbA3WGlMpW6pXtSpCtX566NoYiegMw5jxZSja0Gjhun2o1kxyQv5epOfKOraKqB8JP0xQN8jLhteb+ynYJ+GzkFk21j+PYXBxU1JWnz8ySgmgmbZVhL0ynpTtWqdF9UbDFVpOcCP4JlJaibP0PAGBKODzZucgnCfIsAemUF+DoQW3Ie+l7ikEQnOeFUBNgSCWTioDU6gZwNXGRvOxYdRjxC3DDm7YDJZXzVHPljlcJ4UE0o533zkwhq6HyovXjP1hZG11lSz0wItGPKYYoJWOoAwiczPsKHwdasDVH0GLGo72h0BwZsg8aLo8/peJBA4OJTB4WOiy/sIqlnUeyVSdzLc1/KR5BOF48k/q4g3zrkfHm+zcIor4KDK/7ZUJzH8rEKPeDGLe4fFpBfXR4isW7XgUP3tCi6OmuG/ph7xOxVkOCyeVPExKh1KQKY862Zz9GR4eVKWmqONgMZFqA6h51cdUv1gjcr5VmCmSkpui+re8JMrNrIWMkwOnxN9/bjzrwWTHYNjQ+PETSLp9HNuZPUE4VZRqdFwrfoYAFnOt8f7NWnP9bMNl0KMo9hEIuh+lVWBsGtuBnqy2ApHK7QEgqio9VMv/9Ntr7ow15ZvaMIOtEjQ1M90W/xFyCDZe4NCUy6JWNVoBPw1egGK4Rxe/W9MH+M6PYdtL426sv1u0LbmlWIAsYGpqMigVD55IVTQbYHauOH2FjbJuW8rxHyedR6STL69zs/ptD9dGgVyfNzq7LIILne84mxoxzd2EhzzZX2XNOpyzvHF+sLziq2OcxWrMSB/oODsUnYjlHFQaDYovthuVwtcxQydXxMkrLw/pNhuMFifFUDRcrGZFBGOM5U8rr3+Ov8w5x10w2dA044iXVKRsEUlKu B3y5Oj93 cZc0RY6sAuVOhcWBw1KAmz9Yxm0W4QyJH5HZKaSejrH0D8FawbwJZuDSw3Yl5NBt1QsZrLX4Ie2DQtSuyl4rdft1a5BPT3i6Pcmz7VXwtHTdOsaoS1aUo0ZGiJB05nmz0HkEF/oGNco2Y1XCvAFew+kHaJbVBqypXSB/mo8/BAauHFG/1BmpZrMxsO0n45BLbqHOq 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: List-Subscribe: List-Unsubscribe: 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 --- 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))