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] [day] [month] [year] [list]
Message-ID: <20160829134857.GA28568@redhat.com>
Date:   Mon, 29 Aug 2016 15:48:58 +0200
From:   Oleg Nesterov <oleg@...hat.com>
To:     Hillf Danton <hillf.zj@...baba-inc.com>
Cc:     linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 2/2] sched/wait: avoid abort_exclusive_wait() in
        __wait_on_bit_lock()

On 08/29, Hillf Danton wrote:
>
> > > On 08/26, Oleg Nesterov wrote:
> > __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q,
> > 			wait_bit_action_f *action, unsigned mode)
> > {
> > 	int ret = 0;
> >
> > 	for (;;) {
> > 		prepare_to_wait_exclusive(wq, &q->wait, mode);
> > 		if (test_bit(q->key.bit_nr, q->key.flags)) {
> > 			ret = action(&q->key, mode);
> > 			/*
> > 			 * Ensure that clear_bit() + wake_up() right after
> > 			 * test_and_set_bit() below can't see us; it should
> > 			 * wake up another exclusive waiter if we fail.
> > 			 */
> > 			if (ret)
> > 				finish_wait(wq, &q->wait);
> > 		}
> > 		if (!test_and_set_bit(q->key.bit_nr, q->key.flags)) {
> > 			if (!ret)
> > 				finish_wait(wq, &q->wait);
> > 			return 0;
> > 		} else if (ret) {
> > 			return ret;
> > 		}
> > 	}
> > }
> >
> Can we fold two bit operations into one?

Yes, we can, but I am not sure we want. I guess the first test_bit()
is optimization to avoid the locked test_and_set_bit() which should
likely fail.

>  __wait_on_bit_lock(wait_queue_head_t *wq, struct wait_bit_queue *q,
>  			wait_bit_action_f *action, unsigned mode)
>  {
> -	do {
> -		int ret;
> +	int ret = 0;
>  
> -		prepare_to_wait_exclusive(wq, &q->wait, mode);
> -		if (!test_bit(q->key.bit_nr, q->key.flags))
> -			continue;
> +	prepare_to_wait_exclusive(wq, &q->wait, mode);
> +	do {
> +		if (!test_and_set_bit(q->key.bit_nr, q->key.flags))
> +			break;
>  		ret = action(&q->key, mode);
> -		if (!ret)
> -			continue;
> -		abort_exclusive_wait(wq, &q->wait, mode, &q->key);
> -		return ret;
> -	} while (test_and_set_bit(q->key.bit_nr, q->key.flags));
> +	} while (!ret);
> +

No, no, this is wrong.

We can't simply remove abort_exclusive_wait(), please read the comment
above this function and the comment added by this patch.

And we can't move prepare_to_wait_exclusive() outside of the main loop.

Oleg.

>  	finish_wait(wq, &q->wait);
> -	return 0;
> +	return ret;
>  }
>  EXPORT_SYMBOL(__wait_on_bit_lock);
>  
> --
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ