From: Eric Dumazet <eric.dumazet@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ben Hutchings <bhutchings@solarflare.com>,
Andi Kleen <andi@firstfloor.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: >Re: [RFC] should VM_BUG_ON(cond) really evaluate cond
Date: Fri, 28 Oct 2011 16:47:32 +0200 [thread overview]
Message-ID: <1319813252.23112.122.camel@edumazet-laptop> (raw)
In-Reply-To: <CA+55aFxy6VSBbikFrfXwUPOafihR+MOdi+yKSp_6qz7_Vax_YA@mail.gmail.com>
Le vendredi 28 octobre 2011 à 05:40 -0700, Linus Torvalds a écrit :
> On Fri, Oct 28, 2011 at 5:19 AM, Linus Torvalds
> <torvalds@linux-foundation.org> wrote:
> >
> > "Sane interfaces" are important. Insane interfaces lead to bugs.
>
> Qutie frankly, if I do "atomic_read()", I do expect to get a single
> value. If I don't get a single value, but some mixture of two values,
> I'd personally go
>
> wtf, what does that "atomic" mean in "atomic_read()"?
>
> and I think that's a reasonable wtf to ask.
>
> That said, as mentioned, I don't know of any way to tell gcc "at most once".
>
> Hmm.
>
> Except perhaps using inline asm. Something like this might work:
>
> static inline int atomic_read(const atomic_t *v)
> {
> int val;
> asm("":"=r" (val):"0" (v->value));
> return val;
> }
>
> (totally untested, but you get the idea: use a non-volatile asm to
> make sure that gcc doesn't think it can re-load the value).
>
> That's the trick we use in asmlinkage_protect() and a couple of other
> places. It *should* make gcc able to optimize the value away entirely
> if it isn't used, but will stop gcc from doing the reload magic.
>
> Does that work for the test-case with VM_BUG_ON()?
On x86 it seems to work :
c050f80f: 0f 84 ea 00 00 00 je c050f8ff <tcp_sendmsg+0xa1f>
c050f815: 8b 55 bc mov -0x44(%ebp),%edx
c050f818: f0 ff 42 10 lock incl 0x10(%edx) atomic_inc(&page->count)
c050f81c: 8b 02 mov (%edx),%eax page->flags
c050f81e: 25 00 40 02 00 and $0x24000,%eax
c050f823: 3d 00 40 02 00 cmp $0x24000,%eax
c050f828: 0f 84 9f 01 00 00 je c050f9cd <tcp_sendmsg+0xaed>
On x86_64 (gcc-4.6.1 Debian-4.6.1-4) we still have a page->flags useless load,
but the atomic_read() itself is removed.
This looks like a CONFIG_PAGEFLAGS_EXTENDED difference.
In this case, PageTail() is :
#define TESTPAGEFLAG(uname, lname) \
static inline int Page##uname(const struct page *page) \
{ return test_bit(PG_##lname, &page->flags); }
So we need a similar idea to remove the volatile from :
static __always_inline int constant_test_bit(unsigned int nr, const volatile unsigned long *addr)
{
return ((1UL << (nr % BITS_PER_LONG)) &
(addr[nr / BITS_PER_LONG])) != 0;
}
next prev parent reply other threads:[~2011-10-28 14:47 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-28 1:19 [RFC] should VM_BUG_ON(cond) really evaluate cond Eric Dumazet
2011-10-28 1:25 ` Andi Kleen
2011-10-28 1:34 ` Linus Torvalds
2011-10-28 1:44 ` Ben Hutchings
2011-10-28 2:52 ` Eric Dumazet
2011-10-28 3:29 ` Ben Hutchings
2011-10-28 4:43 ` >Re: " Eric Dumazet
2011-10-28 11:37 ` Linus Torvalds
2011-10-28 12:09 ` Eric Dumazet
2011-10-28 12:19 ` Linus Torvalds
2011-10-28 12:40 ` Linus Torvalds
2011-10-28 14:47 ` Eric Dumazet [this message]
2011-10-28 14:55 ` Linus Torvalds
2011-10-29 15:43 ` Eric Dumazet
2011-10-29 17:34 ` Linus Torvalds
2011-10-30 8:52 ` Eric Dumazet
2011-10-30 9:59 ` Andi Kleen
2011-10-30 15:16 ` Eric Dumazet
2011-10-30 17:07 ` Linus Torvalds
2011-10-30 17:41 ` Eric Dumazet
2011-10-30 17:48 ` Linus Torvalds
2011-10-30 17:59 ` Eric Dumazet
2011-10-30 18:09 ` Linus Torvalds
2011-11-02 0:14 ` Eric Dumazet
2011-11-01 4:06 ` Stephen Rothwell
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=1319813252.23112.122.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=bhutchings@solarflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox