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: <1979415164.29724.1428944899771.JavaMail.zimbra@efficios.com>
Date:	Mon, 13 Apr 2015 17:08:19 +0000 (UTC)
From:	Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
To:	Ingo Molnar <mingo@...nel.org>
Cc:	Peter Zijlstra <peterz@...radead.org>, rusty@...tcorp.com.au,
	oleg@...hat.com, paulmck@...ux.vnet.ibm.com,
	torvalds@...ux-foundation.org, linux-kernel@...r.kernel.org,
	andi@...stfloor.org, rostedt@...dmis.org, tglx@...utronix.de,
	laijs@...fujitsu.com, linux@...izon.com,
	Andrea Arcangeli <aarcange@...hat.com>,
	David Woodhouse <David.Woodhouse@...el.com>,
	Rik van Riel <riel@...hat.com>,
	Michel Lespinasse <walken@...gle.com>
Subject: Re: [PATCH v5 05/10] seqlock: Better document
 raw_write_seqcount_latch()

----- Original Message -----
> 
> * Peter Zijlstra <peterz@...radead.org> wrote:
> 
[...]
> > + * The query will have a form like:
> > + *
> > + * struct entry *latch_query(struct latch_struct *latch, ...)
> > + * {
> > + *	struct entry *entry;
> > + *	unsigned seq, idx;
> > + *
> > + *	do {
> > + *		seq = latch->seq;
> > + *		smp_rmb();
> > + *
> > + *		idx = seq & 0x01;
> > + *		entry = data_query(latch->data[idx], ...);
> > + *
> > + *		smp_rmb();
> > + *	} while (seq != latch->seq);
> 
> Btw., I realize this is just a sample, but couldn't this be written
> more optimally as:
> 
> 	do {
> 		seq = READ_ONCE(latch->seq);
> 		smp_read_barrier_depends();
> 
> 		idx = seq & 0x01;
> 		entry = data_query(latch->data[idx], ...);
> 
> 		smp_rmb();
> 	} while (seq != latch->seq);
> 
> Note that there's just a single smp_rmb() barrier: the READ_ONCE() is
> there to make sure GCC doesn't calculate 'idx' from two separate
> reads, but otherwise there's a direct data dependency on latch->seq so
> no smp_rmb() is needed, only a data dependency barrier when doing the
> first lookup AFAICS?
> 
> (This doesn't matter on x86 where smp_rmb() is barrier().)

The latch evolved from seqlock.h, where there was no
data dependency between the sequence counter and the
data read, hence the smp_rmb(). Indeed, there is a
data dependency in the case of the latch, so I think
your approach of READ_ONCE + smp_read_barrier_depends()
is appropriate.

Thanks!

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
--
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