From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: David Laight <david.laight.linux@gmail.com>
Cc: Johannes Berg <johannes@sipsolutions.net>,
linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-wireless@vger.kernel.org, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Subject: Re: [PATCH v1 1/2] overflow: Allow to sum a few arguments at once
Date: Thu, 18 Jun 2026 09:39:37 +0300 [thread overview]
Message-ID: <ajOSqWpYUhFTVqP-@ashevche-desk.local> (raw)
In-Reply-To: <20260617223056.754bfcb8@pumpkin>
On Wed, Jun 17, 2026 at 10:30:56PM +0100, David Laight wrote:
> On Wed, 17 Jun 2026 14:56:09 +0200
> Johannes Berg <johannes@sipsolutions.net> wrote:
> > On Wed, 2026-06-17 at 13:12 +0200, Andy Shevchenko wrote:
> > > Convert size_add() to take variadic argument, so we can simplify users
> > > with using a macro only once.
> >
> > > +#define __size_add3(addend1, addend2, addend3, addend4, ...) \
> > > + __size_add(__size_add2(addend1, addend2, addend3), addend4)
> > > +#define __size_add4(addend1, addend2, addend3, addend4, addend5, ...) \
> > > + __size_add(__size_add3(addend1, addend2, addend3, addend4), addend5)
> >
> > I guess it's not going to really matter, but it would generate fewer
> > calls to have something more like
> >
> > #define __size_add3(a1, a2, a3, a4) \
> > size_add(size_add(a1, a2), size_add(a3, a4))
> > #define __size_add4(a1, a2, a3, a4, a5) \
> > size_add(size_add(a1, a2), size_add(a3, a4, a5))
> >
> > as a binary tree, rather than only cutting one off every time. Not sure
> > that results in hugely different code though - maybe fewer overflow
> > checks?
Good question. I'm also thinking that one-by-one may expand in too much of
preprocessor code (haven't checked myself).
> The binary tree stands a chance of executing less slowly because the leaf
> adds can be executed in parallel.
> Excluding the saturation checks (wtf is it called size_add() not
> saturating_add() ?) (a + b) + (c + d) will usually execute faster than
> ((a + b) + c) + d because the (a + b) and (c + d) can execute at the
> same time; unfortunately gcc will always generate the latter.
I'm confused. "unfortunately... the latter"? You meant "the former"?
> > Although your version make it really completely equivalent to the
> > nl80211.c code, clearly it doesn't matter if all the values are "good",
> > and I believe the overflow behaviour means it doesn't matter for the
> > overflow case either?
Indeed. Whenever the value is saturated, the rest is just matter of sequential
unlikely branches taken.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2026-06-18 6:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 11:12 [rfc, PATCH v1 0/2] overflow: Convert size_add() to take variadic arguments Andy Shevchenko
2026-06-17 11:12 ` [PATCH v1 1/2] overflow: Allow to sum a few arguments at once Andy Shevchenko
2026-06-17 12:56 ` Johannes Berg
2026-06-17 21:30 ` David Laight
2026-06-18 6:39 ` Andy Shevchenko [this message]
2026-06-18 18:53 ` Johannes Berg
2026-06-18 21:36 ` David Laight
2026-06-17 11:12 ` [PATCH v1 2/2] wifi: nl80211: Call size_add() only once Andy Shevchenko
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=ajOSqWpYUhFTVqP-@ashevche-desk.local \
--to=andriy.shevchenko@linux.intel.com \
--cc=david.laight.linux@gmail.com \
--cc=gustavoars@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox