From: ebiederm@xmission.com (Eric W. Biederman)
To: Andy Isaacson <adi@hexapodia.org>
Cc: Andrew Morton <akpm@osdl.org>,
linux-kernel@vger.kernel.org, fastboot@osdl.org,
Andi Kleen <ak@suse.de>
Subject: Re: i386 nmi_watchdog: Merge check_nmi_watchdog fixes from x86_64
Date: Sat, 15 Oct 2005 06:49:56 -0600 [thread overview]
Message-ID: <m13bn3ndvv.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <20051014185311.GH14194@hexapodia.org> (Andy Isaacson's message of "Fri, 14 Oct 2005 11:53:11 -0700")
Andy Isaacson <adi@hexapodia.org> writes:
> On Thu, Oct 13, 2005 at 10:13:12PM -0600, Eric W. Biederman wrote:
>> Andrew Morton <akpm@osdl.org> writes:
>> > ebiederm@xmission.com (Eric W. Biederman) wrote:
>> >> static int __init check_nmi_watchdog(void)
>> >> {
>> >> + volatile int endflag = 0;
>> >
>> > I don't think this needs to be declared volatile?
>>
>> If the variable was static the volatile would clearly be unnecessary
>> as we have taken the address earlier so at some point the compiler
>> would be obligated to but with the variable being auto the rules are a
>> little murky.
>
> I don't think it's murky at all; since you took the address and passed
> it to another function, the compiler has to assume that you saved the
> pointer away and will be referring to it later. (Unless the compiler
> can prove that you *won't* be referring to it later, such as if there
> are no more function calls between the store and the variable going out
> of scope, or if the compiler does whole-program optimization and can see
> the entire data flow of that pointer and prove that it's not
> dereferenced.)
>
> Now, I think the following could hypothetically be a problem:
>
> An optimizing compiler could look at foo() and decide that since blah is
> not volatile, and there are no function calls after it is incremented,
> the increment can be discarded. But alas, baz() does check the value on
> another thread.
>
> I believe (but have not verified) that GCC simply inhibits
> dead-store-elimination when the address of the variable has been taken,
> so this theoretical possibility is not a real danger under gcc. And in
> any case, it doesn't apply to your check_nmi_watchdog, because you've
> got function calls after the assignment.
It comes very close to applying to check_nmi_watchdog as both
of the functions called after endflag is set: printk and kfree
both have nothing to do with the setting of endflag. If they
were simpler functions an optimizing compiler could look at
them realizing that. Since those two functions have nothing
to do with endflag someone else looking at the code remove or
reorder them with a trivial patch and the code could stop working.
GCC keeps getting more powerful optimizations so I am not comfortable
with depending on it simply eliminating dead-store-elimination when the
address of a variable has been taken.
If there is a better idiom to synchronize the cpus which does
not mark the variable volatile I could see switching to that.
There is a theoretical race there as some cpu might not see endflag
get set and the next function on the stack could set it that same
stack slot to 0. I can see value in fixing that, if there is a simple
and clear solution. Currently I am having a failure of imagination.
Eric
next prev parent reply other threads:[~2005-10-15 12:50 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-04 15:02 i386 nmi_watchdog: Merge check_nmi_watchdog fixes from x86_64 Eric W. Biederman
2005-10-05 19:50 ` Bill Davidsen
2005-10-05 20:00 ` Eric W. Biederman
2005-10-12 1:26 ` Andrew Morton
2005-10-14 4:13 ` Eric W. Biederman
2005-10-14 18:53 ` Andy Isaacson
2005-10-15 12:49 ` Eric W. Biederman [this message]
2005-10-18 7:05 ` Andy Isaacson
2005-10-18 12:44 ` Eric W. Biederman
2005-10-19 7:10 ` Zwane Mwaikambo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m13bn3ndvv.fsf@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=adi@hexapodia.org \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=fastboot@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.