linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yury Norov <yury.norov@gmail.com>
To: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: Kees Cook <kees@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
	linux-kernel@vger.kernel.org, linux-sparse@vger.kernel.org,
	Masahiro Yamada <masahiroy@kernel.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Nick Desaulniers <nick.desaulniers+lkml@gmail.com>
Subject: Re: [PATCH v2] build_bug.h: more user friendly error messages in BUILD_BUG_ON_ZERO()
Date: Wed, 9 Apr 2025 10:17:49 -0400	[thread overview]
Message-ID: <Z_aBjSP4WB062Ii9@yury> (raw)
In-Reply-To: <4c01c2a6-5271-41e4-8013-836e59aeae6d@wanadoo.fr>

On Wed, Apr 09, 2025 at 09:26:41PM +0900, Vincent Mailhol wrote:
> +To: Yury Norov
> 
> On 09/04/2025 at 04:03, Kees Cook wrote:
> > On Tue, Apr 08, 2025 at 10:23:53PM +0900, Vincent Mailhol wrote:
> >> On 08/04/2025 at 01:46, Kees Cook wrote:
> >>> On Sat, Mar 29, 2025 at 01:48:50AM +0900, Vincent Mailhol wrote:
> >>>> __BUILD_BUG_ON_ZERO_MSG(), as introduced in [1], makes it possible to
> >>>> do a static assertions in expressions. The direct benefit is to
> >>>> provide a meaningful error message instead of the cryptic negative
> >>>> bitfield size error message currently returned by BUILD_BUG_ON_ZERO():
> >>>>
> >>>>   ./include/linux/build_bug.h:16:51: error: negative width in bit-field '<anonymous>'
> >>>>      16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
> >>>>         |                                                   ^
> >>>>
> >>>> Get rid of BUILD_BUG_ON_ZERO()'s bitfield size hack. Instead rely on
> >>>> __BUILD_BUG_ON_ZERO_MSG() which in turn relies on C11's
> >>>> _Static_assert().
> >>>>
> >>>> Use some macro magic, similarly to static_assert(), to either use an
> >>>> optional error message provided by the user or, when omitted, to
> >>>> produce a default error message by stringifying the tested
> >>>> expression. With this, for example:
> >>>>
> >>>>   BUILD_BUG_ON_ZERO(1 > 0)
> >>>>
> >>>> would now throw:
> >>>>
> >>>>   ./include/linux/compiler.h:197:62: error: static assertion failed: "1 > 0 is true"
> >>>
> >>> This is so much easier to read! Thanks for this. :)
> >>>
> >>> If no one else snags it, I can take this via the hardening tree for
> >>> -next once -rc2 is released.
> >>
> >> I discussed about this with Andrew by DM.
> >>
> >> Andrew can pick it up but for the next-next release. That is to say,
> >> wait for [1] to be merged in v6.16 and then take it to target the v6.17
> >> merge windows.
> >>
> >> If you can take it in your hardening-next tree and have it merged in
> >> v6.16, then this is convenient for me.
> >>
> >> Just make sure that you send it to Linus after Yury's bitmap-for-next
> >> get merged: https://github.com/norov/linux/commits/bitmap-for-next/
> > 
> > Could this land via Yury's tree?
> 
> Hi Yury,
> 
> I have this patch:
> 
> https://lore.kernel.org/all/20250329-build_bug-v2-1-1c831e5ddf89@wanadoo.fr/
> 
> which depends on commit b88937277df ("drm/i915: Convert REG_GENMASK*()
> to fixed-width GENMASK_U*()") in your bitmap-for-next tree.
> 
> I discussed this with Andrew (by DM) and Kees. Because of the
> dependency, it would be convenient if this patch went through your tree.
> 
> What do you think?

Sure, I can merge it. Please everyone send your tags before the end of
week.

Thanks,
Yury

  reply	other threads:[~2025-04-09 14:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-28 16:48 [PATCH v2] build_bug.h: more user friendly error messages in BUILD_BUG_ON_ZERO() Vincent Mailhol
2025-04-07 16:46 ` Kees Cook
2025-04-08 13:23   ` Vincent Mailhol
2025-04-08 19:03     ` Kees Cook
2025-04-09 12:26       ` Vincent Mailhol
2025-04-09 14:17         ` Yury Norov [this message]
2025-04-09 16:14           ` Kees Cook
2025-04-14 21:55             ` Yury Norov

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=Z_aBjSP4WB062Ii9@yury \
    --to=yury.norov@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=masahiroy@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=pbonzini@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).