lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200820134348.tmoydr2aawghyfkt@wittgenstein>
Date:   Thu, 20 Aug 2020 15:43:48 +0200
From:   Christian Brauner <christian.brauner@...ntu.com>
To:     Michal Hocko <mhocko@...e.com>
Cc:     Oleg Nesterov <oleg@...hat.com>,
        Suren Baghdasaryan <surenb@...gle.com>, mingo@...nel.org,
        peterz@...radead.org, tglx@...utronix.de, esyr@...hat.com,
        christian@...lner.me, areber@...hat.com, shakeelb@...gle.com,
        cyphar@...har.com, adobriyan@...il.com, akpm@...ux-foundation.org,
        ebiederm@...ssion.com, gladkov.alexey@...il.com, walken@...gle.com,
        daniel.m.jordan@...cle.com, avagin@...il.com,
        bernd.edlinger@...mail.de, john.johansen@...onical.com,
        laoar.shao@...il.com, timmurray@...gle.com, minchan@...nel.org,
        kernel-team@...roid.com, linux-kernel@...r.kernel.org,
        linux-fsdevel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH 1/1] mm, oom_adj: don't loop through tasks in
 __set_oom_adj when not necessary

On Thu, Aug 20, 2020 at 02:41:09PM +0200, Michal Hocko wrote:
> On Thu 20-08-20 13:42:56, Michal Hocko wrote:
> > On Thu 20-08-20 13:30:23, Christian Brauner wrote:
> [...]
> > > trying to rely on set_bit() and test_bit() in copy_mm() being atomic and
> > > then calling it where Oleg said after the point of no return.
> > 
> > No objections.
> 
> Would something like the following work for you?
> 
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 9177a76bf840..25b83f0912a6 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -1403,15 +1403,6 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
>  	if (clone_flags & CLONE_VM) {
>  		mmget(oldmm);
>  		mm = oldmm;
> -		if (!(clone_flags & CLONE_SIGHAND)) {
> -			/* We need to synchronize with __set_oom_adj */
> -			mutex_lock(&oom_adj_lock);
> -			set_bit(MMF_PROC_SHARED, &mm->flags);
> -			/* Update the values in case they were changed after copy_signal */
> -			tsk->signal->oom_score_adj = current->signal->oom_score_adj;
> -			tsk->signal->oom_score_adj_min = current->signal->oom_score_adj_min;
> -			mutex_unlock(&oom_adj_lock);
> -		}
>  		goto good_mm;
>  	}
>  
> @@ -1818,6 +1809,19 @@ static __always_inline void delayed_free_task(struct task_struct *tsk)
>  		free_task(tsk);
>  }
>  
> +static void copy_oom_score_adj(u64 clone_flags, struct task_struct *tsk)
> +{
> +	if ((clone_flags & (CLONE_VM | CLONE_THREAD | CLONE_VFORK)) == CLONE_VM) {
> +		/* We need to synchronize with __set_oom_adj */
> +		mutex_lock(&oom_adj_lock);
> +		set_bit(MMF_PROC_SHARED, &mm->flags);
> +		/* Update the values in case they were changed after copy_signal */
> +		tsk->signal->oom_score_adj = current->signal->oom_score_adj;
> +		tsk->signal->oom_score_adj_min = current->signal->oom_score_adj_min;
> +		mutex_unlock(&oom_adj_lock);
> +	}
> +}
> +
>  /*
>   * This creates a new process as a copy of the old one,
>   * but does not actually start it yet.
> @@ -2290,6 +2294,8 @@ static __latent_entropy struct task_struct *copy_process(
>  	trace_task_newtask(p, clone_flags);
>  	uprobe_copy_process(p, clone_flags);
>  
> +	copy_oom_score_adj(clone_flags, p);
> +
>  	return p;
>  
>  bad_fork_cancel_cgroup:

This should work, yes.
And keeps the patch reasonably small.

Christian

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ