Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1261137

Re: [GIT] Networking

From Andy Lutomirski <luto@amacapital.net>
Newsgroups linux.kernel
Subject Re: [GIT] Networking
Date 2015-11-03 03:00 +0100
Message-ID <qqz3d-4xe-31@gated-at.bofh.it> (permalink)
References (3 earlier) <qquGe-1YL-11@gated-at.bofh.it> <qquGj-1YL-115@gated-at.bofh.it> <qquZB-250-39@gated-at.bofh.it> <qqy77-3Xq-9@gated-at.bofh.it> <qqz3d-4xe-33@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Mon, Nov 2, 2015 at 5:54 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> The biggest problem - and where the compiler could actually help us -
> tends to be multiplication overflows. We have several (not *many*, but
> certainly more than just a couple) cases where we simply check by
> dividing MAX_INT or something.
>
> See for example kmalloc_array(), which does
>
>         if (size != 0 && n > SIZE_MAX / size)
>                 return NULL;
>
> exactly to avoid the overflow when it does the "n*size" allocation.
>
> So for multiplication, we really *could* use overflow logic. It's not
> horribly common, but it definitely happens.
>

Based in part on an old patch by Sasha, what if we relied on CSE:

if (mul_would_overflow(size, n))
  return NULL;
do_something_with(size * n);

I haven't checked, but it would be sad if gcc couldn't optimize this
correctly if we use the builtins.

The downside is that I don't see off the top of my head how this could
be implemented using inline asm if we want a fast fallback when the
builtins aren't available.

--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [GIT] Networking Andy Lutomirski <luto@kernel.org> - 2015-11-02 21:40 +0100
  Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-02 22:20 +0100
    Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-02 22:20 +0100
      Re: [GIT] Networking Andy Lutomirski <luto@amacapital.net> - 2015-11-02 22:40 +0100
        Re: [GIT] Networking Hannes Frederic Sowa <hannes@stressinduktion.org> - 2015-11-02 23:20 +0100
          Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-03 00:30 +0100
        Re: [GIT] Networking Benjamin Herrenschmidt <benh@kernel.crashing.org> - 2015-11-03 02:00 +0100
          Re: [GIT] Networking Andy Lutomirski <luto@amacapital.net> - 2015-11-03 03:00 +0100
            Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-03 03:40 +0100
              Re: [GIT] Networking Hannes Frederic Sowa <hannes@stressinduktion.org> - 2015-11-03 14:00 +0100
                Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-03 21:10 +0100
                Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-03 21:50 +0100
                RE: [GIT] Networking David Laight <David.Laight@ACULAB.COM> - 2015-11-06 16:30 +0100
                Re: [GIT] Networking Andy Lutomirski <luto@amacapital.net> - 2015-11-07 01:50 +0100
                Re: [GIT] Networking Ingo Molnar <mingo@kernel.org> - 2015-11-09 09:20 +0100
                Re: [GIT] Networking Hannes Frederic Sowa <hannes@stressinduktion.org> - 2015-11-09 11:40 +0100
                Re: [GIT] Networking Hannes Frederic Sowa <hannes@stressinduktion.org> - 2015-11-09 11:40 +0100
          Re: [GIT] Networking Linus Torvalds <torvalds@linux-foundation.org> - 2015-11-03 03:00 +0100

csiph-web