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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20121010175032.GA22642@redhat.com>
Date:	Wed, 10 Oct 2012 19:50:32 +0200
From:	Oleg Nesterov <oleg@...hat.com>
To:	Lai Jiangshan <laijs@...fujitsu.com>
Cc:	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	LKML <linux-kernel@...r.kernel.org>,
	Al Viro <viro@...iv.linux.org.uk>,
	Ingo Molnar <mingo@...nel.org>,
	Eric Dumazet <edumazet@...gle.com>
Subject: Re: [PATCH V2] task_work: avoid unneeded cmpxchg() in
	task_work_run()

On 10/10, Lai Jiangshan wrote:
>
> --- a/kernel/task_work.c
> +++ b/kernel/task_work.c
> @@ -52,16 +52,7 @@ void task_work_run(void)
>  	struct callback_head *work, *head, *next;
>
>  	for (;;) {
> -		/*
> -		 * work->func() can do task_work_add(), do not set
> -		 * work_exited unless the list is empty.
> -		 */
> -		do {
> -			work = ACCESS_ONCE(task->task_works);
> -			head = !work && (task->flags & PF_EXITING) ?
> -				&work_exited : NULL;
> -		} while (cmpxchg(&task->task_works, work, head) != work);
> -
> +		work = xchg(&task->task_works, NULL);
>  		if (!work)
>  			break;
>  		/*
> @@ -90,3 +81,17 @@ void task_work_run(void)
>  		} while (work);
>  	}
>  }
> +
> +void exit_task_work(struct task_struct *task)
> +{
> +	for (;;) {
> +		/*
> +		 * work->func() can do task_work_add(), do not set
> +		 * work_exited unless the list is empty.
> +		 */
> +		if (unlikely(task->task_works))
> +			task_work_run();
> +		if (cmpxchg(&task->task_works, NULL, &work_exited) == NULL)
> +			break;
> +	}
> +}

I agree, this looks fine.

But if you add "unlikely" before task_work_run(), then probably
it should do

	while (cmpxchg(&task->task_works, NULL, work_exited))
		task_work_run();

? it looks more simple/clean.

(OTOH I am not sure "unlikely" is true, note that exit_files() will
 offload ____fput() to task_work_run()).

But you did not answer, and I am curious. What was your original
motivation? Is xchg really faster than cmpxchg?

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ