Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Aug 2014 19:42:36 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Mateusz Guzik <mjguzik@gmail.com>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: atomic_load_acq_int in sequential_heuristic
Message-ID:  <20140824164236.GX2737@kib.kiev.ua>
In-Reply-To: <20140824162331.GW2737@kib.kiev.ua>
References:  <20140824115729.GC2045@dft-labs.eu> <20140824162331.GW2737@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help

--oNcod2irK9ys8Qxe
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sun, Aug 24, 2014 at 07:23:31PM +0300, Konstantin Belousov wrote:
> On Sun, Aug 24, 2014 at 01:57:29PM +0200, Mateusz Guzik wrote:
> > Writer side is:
> > fp->f_seqcount =3D (arg + bsize - 1) / bsize;
> > do {
> > 	new =3D old =3D fp->f_flag;
> > 	new |=3D FRDAHEAD;
> > } while (!atomic_cmpset_rel_int(&fp->f_flag, old, new));
> >=20
> > Reader side is:
> > if (atomic_load_acq_int(&(fp->f_flag)) & FRDAHEAD)
> > 	return (fp->f_seqcount << IO_SEQSHIFT);
> >=20
> > We can easily get the following despite load_acq:
> > CPU0				CPU1
> > 				load_acq fp->f_flag
> > fp->f_seqcount =3D ...
> > store_rel fp->f_flag
> > 				read fp->f_seqcount
> > 			=09
> > So the barrier does not seem to serve any purpose.
> It does.
>=20
> Consider initial situation, when the flag is not set yet. There, we
> do not want to allow the reader to interpret automatically calculated
> f_seqcount as the user-supplied constant.  Without barriers, we might
> read the flag as set, while user-provided value for f_seqcount is still
> not visible to processor doing read.
That said, I think now that there is a real bug.

If we did not read the FRDAHEAD in sequential_heuristic(), we may
override user-supplied value for f_seqcount.  I do not see other
solution than start to use locking.

--oNcod2irK9ys8Qxe
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJT+hX8AAoJEJDCuSvBvK1BgmAQAJNQ0m8/urD0kssB0dO81XiS
GKYSvzkAX2Ca+kQ6uHZm7JEBsSL8rBgUU/pLa4lUymnQoSjutz54YcuBIvxBnRV2
MZVUy+HqoW4Ze2XP3YQVLAyJjXhH9bVme9dye+btyXOf/qR8WXemGId5vTeZa61T
gtAm4jcTPA0tkFFsAUoCBX/+//0ixVZb/YUQGdEPbd1YpModt06Lrgwm9K5mBGNm
RZVZ8j0HsjDH6cHxvw4Z1ENwka/1gYA1bIBA1soXUU1RgKZf9kFArds5Y5jo7QTP
iDQCquHmPenA1EJ1DUAj6/3EiIErL+Velsyv2xkA00yQgYCUiMk9wOV5lW3c0kCq
QKSg2OMnE8SwODDX9QgFNtS2X91Qjj2UayUS4M5Hy1WDHcgzDDhlWipO95bwji9u
hl0e2eheENST2DWZ4R6bqE9nmFpcGs8zsG79+2qc5geYpqv5RljgDUp8+STDfhG3
9ddZhv0mnsmRX14gE1AqB9o25XwRQpr4up99S1ilo/3B8Id7TQv0iNvEl3OD7G3U
IOB+U0uQ+CxoM70DOGK90fcMzsnflGF0wySUuDEZyaTTqCJL4KnYJYS3ai9plVzM
cGtLtdHv08FjsZpA1fy/8p4ePiBui2G3e1mf6s4p98KZSrdJeItop0Dkc4Ykj4X9
jQevNfkEGrydNmFDicfD
=7/yO
-----END PGP SIGNATURE-----

--oNcod2irK9ys8Qxe--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20140824164236.GX2737>