The patch titled Subject: mm: reduce the rcu lock duration has been added to the -mm mm-unstable branch. Its filename is mm-reduce-the-rcu-lock-duration.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-reduce-the-rcu-lock-duration.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Miaohe Lin <linmiaohe@xxxxxxxxxx> Subject: mm: reduce the rcu lock duration Date: Mon, 30 May 2022 19:30:13 +0800 Patch series "A few cleanup and fixup patches for migration", v4. This series contains a few patches to remove unneeded lock page and PageMovable check, reduce the rcu lock duration. Also we fix potential pte_unmap on an not mapped pte. More details can be found in the respective changelogs. This patch (of 4): Commit 3268c63eded4 ("mm: fix move/migrate_pages() race on task struct") extends the period of the rcu_read_lock until after the permissions checks are done to prevent the task pointed to from changing from under us. But the task_struct refcount is also taken at that time, the reference to task is guaranteed to be stable. So it's unnecessary to extend the period of the rcu_read_lock. Release the rcu lock after task refcount is successfully grabbed to reduce the rcu holding time. Link: https://lkml.kernel.org/r/20220530113016.16663-1-linmiaohe@xxxxxxxxxx Link: https://lkml.kernel.org/r/20220530113016.16663-2-linmiaohe@xxxxxxxxxx Signed-off-by: Miaohe Lin <linmiaohe@xxxxxxxxxx> Reviewed-by: Muchun Song <songmuchun@xxxxxxxxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> Reviewed-by: Oscar Salvador <osalvador@xxxxxxx> Cc: Huang Ying <ying.huang@xxxxxxxxx> Cc: David Howells <dhowells@xxxxxxxxxx> Cc: Christoph Lameter <cl@xxxxxxxxx> Cc: Peter Xu <peterx@xxxxxxxxxx> Cc: Alistair Popple <apopple@xxxxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: David Howells <dhowells@xxxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: kernel test robot <lkp@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/mempolicy.c | 3 +-- mm/migrate.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) --- a/mm/mempolicy.c~mm-reduce-the-rcu-lock-duration +++ a/mm/mempolicy.c @@ -1609,6 +1609,7 @@ static int kernel_migrate_pages(pid_t pi goto out; } get_task_struct(task); + rcu_read_unlock(); err = -EINVAL; @@ -1617,11 +1618,9 @@ static int kernel_migrate_pages(pid_t pi * Use the regular "ptrace_may_access()" checks. */ if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) { - rcu_read_unlock(); err = -EPERM; goto out_put; } - rcu_read_unlock(); task_nodes = cpuset_mems_allowed(task); /* Is the user allowed to access the target nodes? */ --- a/mm/migrate.c~mm-reduce-the-rcu-lock-duration +++ a/mm/migrate.c @@ -1902,17 +1902,16 @@ static struct mm_struct *find_mm_struct( return ERR_PTR(-ESRCH); } get_task_struct(task); + rcu_read_unlock(); /* * 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)) _ Patches currently in -mm which might be from linmiaohe@xxxxxxxxxx are maintainers-add-maintainer-information-for-z3fold.patch mm-shmemc-clean-up-comment-of-shmem_swapin_folio.patch mm-reduce-the-rcu-lock-duration.patch mm-migration-remove-unneeded-lock-page-and-pagemovable-check.patch mm-migration-return-errno-when-isolate_huge_page-failed.patch mm-migration-fix-potential-pte_unmap-on-an-not-mapped-pte.patch