Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gregory Price <gourry@gourry.net>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Alistair Popple <apopple@nvidia.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Byungchul Park <byungchul@sk.com>,
	David Hildenbrand <david@kernel.org>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Rakie Kim <rakie.kim@sk.com>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Zi Yan <ziy@nvidia.com>, Jann Horn <jannh@google.com>,
	Kees Cook <kees@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] mm/mempolicy: kernel_migrate_pages: simplify the usage of put_task_struct()
Date: Sun, 24 May 2026 22:18:12 -0400	[thread overview]
Message-ID: <ahOxZDJdihsmJpEp@gourry-fedora-PF4VCD3F> (raw)
In-Reply-To: <ahMuF6FC6TIOZ-iZ@redhat.com>

On Sun, May 24, 2026 at 06:57:59PM +0200, Oleg Nesterov wrote:
> kernel_migrate_pages() calls put_task_struct() twice; this complicates the
> code. Move put_task_struct() to the unified exit path. This also allows us
> to move the "out_put" label up and avoid another goto.
> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>

Reviewed-by: Gregory Price <gourry@gourry.net>

> ---
>  mm/mempolicy.c | 11 +++--------
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/mm/mempolicy.c b/mm/mempolicy.c
> index 4e4421b22b59..4326dff16aa6 100644
> --- a/mm/mempolicy.c
> +++ b/mm/mempolicy.c
> @@ -1922,25 +1922,20 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode,
>  		goto out_put;
>  
>  	mm = get_task_mm(task);
> -	put_task_struct(task);
> -
>  	if (!mm) {
>  		err = -EINVAL;
> -		goto out;
> +		goto out_put;
>  	}
>  
>  	err = do_migrate_pages(mm, old, new,
>  		capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
>  
>  	mmput(mm);
> +out_put:
> +	put_task_struct(task);
>  out:
>  	NODEMASK_SCRATCH_FREE(scratch);
> -
>  	return err;
> -
> -out_put:
> -	put_task_struct(task);
> -	goto out;
>  }
>  
>  SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
> -- 
> 2.52.0
> 


  reply	other threads:[~2026-05-25  2:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-24 16:57 [PATCH 0/4] mm/mempolicy: kernel_migrate_pages: fix race between security checks and suid exec Oleg Nesterov
2026-05-24 16:57 ` [PATCH 1/4] mm/mempolicy: kernel_migrate_pages: simplify the usage of put_task_struct() Oleg Nesterov
2026-05-25  2:18   ` Gregory Price [this message]
2026-05-25  2:20   ` Gregory Price
2026-05-25  8:27     ` Oleg Nesterov
2026-05-26 15:22       ` Gregory Price
2026-05-24 16:58 ` [PATCH 2/4] mm/mempolicy: kernel_migrate_pages: use find_get_task_by_vpid() Oleg Nesterov
2026-05-24 16:58 ` [PATCH 3/4] mm/mempolicy: kernel_migrate_pages: check ptrace_may_access() after nodes_and() Oleg Nesterov
2026-05-24 16:58 ` [PATCH 4/4] mm/mempolicy: kernel_migrate_pages: fix race between security checks and suid exec Oleg Nesterov
2026-05-24 19:29 ` [PATCH 0/4] " Oleg Nesterov

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=ahOxZDJdihsmJpEp@gourry-fedora-PF4VCD3F \
    --to=gourry@gourry.net \
    --cc=akpm@linux-foundation.org \
    --cc=apopple@nvidia.com \
    --cc=byungchul@sk.com \
    --cc=david@kernel.org \
    --cc=jannh@google.com \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=matthew.brost@intel.com \
    --cc=oleg@redhat.com \
    --cc=rakie.kim@sk.com \
    --cc=ying.huang@linux.alibaba.com \
    --cc=ziy@nvidia.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