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] [day] [month] [year] [list]
Date:	Thu, 12 Sep 2013 16:46:58 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
Cc:	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	John Stultz <john.stultz@...aro.org>,
	Thomas Gleixner <tglx@...utronix.de>,
	Richard Cochran <richardcochran@...il.com>,
	Prarit Bhargava <prarit@...hat.com>,
	Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Ingo Molnar <mingo@...e.hu>, linux-kernel@...r.kernel.org,
	lttng-dev@...ts.lttng.org
Subject: Re: [RFC PATCH] timekeeping: introduce timekeeping_is_busy()

On Thu, Sep 12, 2013 at 09:48:16AM -0400, Mathieu Desnoyers wrote:

> struct foo {
> 	...
> };
> 
> spinlock_t foo_lock;
> 
> struct latchfoo {
> 	unsigned int head, tail;
> 	struct foo data[2];
> };
> 
> /**
>  * foo_write_begin - begin foo update.
>  *
>  " @lf: struct latchfoo to update.
>  * @prev: pointer to previous element (output parameter).
>  * @next: pointer to next element (output parameter).
>  *
>  * The area pointed to by "next" should be considered uninitialized.
>  * The caller needs to have exclusive update access to struct latchfoo.
>  */
> static
> void foo_write_begin(struct latchfoo *lf, const struct foo **prev,
> 		struct foo **next)
> {
> 	lf->head++;
> 	smp_wmb();
> 	*prev = &lf->data[lf->tail & 1];
> 	*next = &lf->data[lf->head & 1];
> }
> 
> /**
>  * foo_write_end - end foo update.
>  *
>  " @lf: struct latchfoo.
>  *
>  * The caller needs to have exclusive update access to struct latchfoo.
>  */
> static void
> void foo_write_end(struct latchfoo *lf)
> {
> 	smp_wmb();
> 	lf->tail++;
> }
> 
> /**
>  * foo_read_begin - begin foo read.
>  *
>  " @lf: struct latchfoo to read.
>  * @tail: pointer to unsigned int containing tail position (output).
>  */
> static
> struct foo *foo_read_begin(struct latchfoo *lf, unsigned int *tail)
> {
> 	unsigned int ret;
> 
> 	ret = ACCESS_ONCE(lf->tail);
> 	smp_rmb();
> 	*tail = ret;
> 	return &lf->data[ret & 1];
> }
> 
> /**
>  * foo_read_retry - end foo read, trigger retry if needed.
>  *
>  " @lf: struct latchfoo read.
>  * @tail: tail position returned as output by foo_read_begin().
>  *
>  * If foo_read_retry() returns nonzero, the content of the read should
>  * be considered invalid, and the read should be performed again to
>  * reattempt reading coherent data, starting with foo_read_begin().
>  */
> static
> int foo_read_retry(struct latchfoo *lf, unsigned int tail)
> {
> 	smp_rmb();
> 	return (ACCESS_ONCE(lf->head) - tail >= 2);
> }

Yep, that's good. I suppose if there's multiple use sites we can jump
through another few hoops to get rid of the specific struct foo
assumptions by storing sizeof() whatever we do use and playing pointer
math games.

But for now with the time stuff as only user this looks ok.
--
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