Date: Tue, 18 Sep 2012 17:01:07 +0100 From: Attilio Rao <attilio@freebsd.org> To: Poul-Henning Kamp <phk@phk.freebsd.dk> Cc: arch@freebsd.org Subject: Re: Aliasing issue with TAILQ on ppc64 ? Message-ID: <CAJ-FndAwUDJsJZNqihzdfz60UEhS75oOYijjb7LAzT%2Bwx1V6DA@mail.gmail.com> In-Reply-To: <22286.1347983589@critter.freebsd.dk> References: <CAJ-FndCsf2Xsn=1ioHyr_tn3-yAFOE7E9-wrjp4rcQJajhZvpg@mail.gmail.com> <22286.1347983589@critter.freebsd.dk>
next in thread | previous in thread | raw e-mail | index | archive | help
On 9/18/12, Poul-Henning Kamp <phk@phk.freebsd.dk> wrote: > In message > <CAJ-FndCsf2Xsn=1ioHyr_tn3-yAFOE7E9-wrjp4rcQJajhZvpg@mail.gmail.com> > , Attilio Rao writes: > >>The only way I can see this >>code is safe is, infact, to lock it with proper locks around the >>operations. > > This is not about locking: at the time where this croaks there is > only one thread. > > The problem is that: > > // Empty, freshly initialized ban_head > > b = valid_ban_object(); > TAILQ_INSERT_HEAD(&ban_head, b, list); > > be = TAILQ_LAST(&ban_head, banhead_s); > > Causes a sig#11 in TAILQ_LAST(). > > I belive it is a NULL dereference, and I belive it happens > because the compiler overoptimizes TAILQ_{LAST|PREV}() Yep, it likely means you need to use compiler memory barriers then. I didn't look into details the implementation of TAILQ (but I can if you want) to point you precisely where, but it seems you already know that code well enough to tell where. Compiler memory barriers will avoid the compiler to reorder loads/stores before/after it and currently we use the gcc idiom for it __asm __volatile (" " : : : "memory") which forces a registers reflush. This also avoids the compiler to optimize some variables in the registers when traversing a barrier, saving the usage of "volatile" more often. TAILQ is certainly subjective to aliasing because it is inlined code, so, differently from hard functions which are safe with gcc compiling flags. However, please note that this type of issue is not only related to ppc64, but to all gcc/clang supported platforms. Attilio -- Peace can only be achieved by understanding - A. Einstein
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAJ-FndAwUDJsJZNqihzdfz60UEhS75oOYijjb7LAzT%2Bwx1V6DA>