From: Boaz Harrosh <bharrosh@panasas.com>
To: adobriyan@gmail.com
Cc: Ingo Molnar <mingo@elte.hu>,
Rusty Russell <rusty@rustcorp.com.au>,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Sam Ravnborg <sam@ravnborg.org>
Subject: Re: [PATCH] debug: fix BUILD_BUG_ON() for non-constant expressions
Date: Wed, 20 Aug 2008 16:07:22 +0300 [thread overview]
Message-ID: <48AC170A.2070702@panasas.com> (raw)
In-Reply-To: <20080820123929.GA29972@x200.localdomain>
adobriyan@gmail.com wrote:
> On Wed, Aug 20, 2008 at 03:31:53PM +0300, Boaz Harrosh wrote:
>> Ingo Molnar wrote:
>>> * Boaz Harrosh <bharrosh@panasas.com> wrote:
>>>
>>>> If the user of virtio_has_feature() must pass a compile-time constant
>>>> then it must be converted to a MACRO, and then the BUILD_BUG_ON will
>>>> work. Or it should be changed to a BUG_ON() if fbit is a runtime
>>>> variable.
>> The use of __builtin_constant_p in inline functions is broken. This
>> is because it will give different results depending on the -O level
>> used. So I think that using it in the Kernel with inlines is plain
>> broken. And should be discouraged.
>
> See how kmalloc() works.
>
Right:
static inline void *kmalloc(size_t size, gfp_t flags)
{
if (__builtin_constant_p(size)) {
... do some stuff
else
return __kmalloc_xxx(..)
}
So if optimization is on we might gain some cycles
but we must make sure we have the proper else clause.
In any way virtio_has_feature() is broken and no amount
of optimization may ever fix it. Please look at it:
static inline bool virtio_has_feature(const struct virtio_device *vdev,
unsigned int fbit)
{
/* Did you forget to fix assumptions on max features? */
if (__builtin_constant_p(fbit))
BUILD_BUG_ON(sizeof(fbit) >= 32);
the __builtin_constant_p(fbit) will never help.
sizeof(fbit) is always sizeof(unsigned int) in any case. Only
a macro can help here. Sorry
Boaz
next prev parent reply other threads:[~2008-08-20 13:08 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-16 10:09 [PATCH] BUILD_BUG_ON sucks Alexey Dobriyan
2008-08-16 10:55 ` Rusty Russell
2008-08-16 20:07 ` Linus Torvalds
2008-08-17 10:32 ` [PATCH] debug: fix BUILD_BUG_ON() for non-constant expressions Ingo Molnar
2008-08-17 16:56 ` Linus Torvalds
2008-08-17 17:33 ` Ingo Molnar
2008-08-17 17:53 ` Ingo Molnar
2008-08-17 18:39 ` Linus Torvalds
2008-08-17 18:45 ` Ingo Molnar
2008-08-18 1:09 ` Rusty Russell
2008-08-18 7:54 ` Ingo Molnar
2008-08-18 9:55 ` Boaz Harrosh
2008-08-18 12:32 ` Boaz Harrosh
2008-08-19 13:34 ` Ingo Molnar
2008-08-19 16:33 ` Boaz Harrosh
2008-08-20 10:59 ` Ingo Molnar
2008-08-20 12:31 ` Boaz Harrosh
2008-08-20 12:39 ` adobriyan
2008-08-20 13:07 ` Boaz Harrosh [this message]
2008-08-21 12:17 ` Ingo Molnar
2008-08-25 1:19 ` Rusty Russell
2008-08-20 13:21 ` Boaz Harrosh
2008-08-16 17:46 ` [PATCH] BUILD_BUG_ON sucks Andrew Morton
2008-08-17 12:19 ` Theodore Tso
2008-08-17 16:33 ` Andrew Morton
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=48AC170A.2070702@panasas.com \
--to=bharrosh@panasas.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=rusty@rustcorp.com.au \
--cc=sam@ravnborg.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 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.