Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Mon, 17 Nov 2014 21:35:53 -0500
From: Rich Felker <dalias@...c.org>
To: Russell King - ARM Linux <linux@....linux.org.uk>
Cc: musl@...ts.openwall.com
Subject: Return value of kuser helper cas function

As far as I can tell, the kuser helper compare-and-swap function
always returns testval-oldval. Is this a behavior that is or could be
made into a guarantee of the API? In musl we want a cas that returns
the old value, and the failure of kuser helper to provide this
currently has us using a second loop around the call to kuser, of the
form:

	for (;;) {
		if (!kuser_cas(testval, setval, ptr))
			return testval;
		if ((oldval = *ptr) != testval)
			return oldval;
	}

It's not safe to just read and return *ptr when the cas fails, because
another thread could race to change *ptr and thereby make it equal to
testval (so that the caller would wrongly infer the cas succeeded).

It would be much nicer if we could just do:

	return testval - kuser_cas(testval, setval, ptr);

and this appears to work, but it's not documented as working at
present.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.