From: Ingo Molnar <mingo@elte.hu>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Joerg Roedel <joerg.roedel@amd.com>
Subject: Re: [GIT PULL] core kernel fixes
Date: Fri, 10 Jul 2009 21:31:10 +0200 [thread overview]
Message-ID: <20090710193110.GA28281@elte.hu> (raw)
In-Reply-To: <alpine.LFD.2.01.0907101206120.3352@localhost.localdomain>
* Linus Torvalds <torvalds@linux-foundation.org> wrote:
>
> On Fri, 10 Jul 2009, Ingo Molnar wrote:
> >
> > Joerg Roedel (1):
> > dma-debug: fix off-by-one error in overlap function
> >
> > diff --git a/lib/dma-debug.c b/lib/dma-debug.c
> > index 3b93129..c9187fe 100644
> > --- a/lib/dma-debug.c
> > +++ b/lib/dma-debug.c
> > @@ -862,7 +862,7 @@ static inline bool overlap(void *addr, u64 size, void *start, void *end)
> >
> > return ((addr >= start && addr < end) ||
> > (addr2 >= start && addr2 < end) ||
> > - ((addr < start) && (addr2 >= end)));
> > + ((addr < start) && (addr2 > end)));
> > }
> >
> > static void check_for_illegal_area(struct device *dev, void *addr, u64 size)
>
> The above seems like total shit.
>
> If (addr < start && addr2 == end) then the two areas very much overlap.
>
> What am I missing (apart from the fact that all those variables are
> horribly badly named)?
>
> Also, the tests make no sense. That's not how you are supposed to check
> for overlap to begin with.
>
> Isn't it easier to test for _not_ overlapping?
>
> /* range1 is fully before range2 */
> (end1 <= start2 ||
> /* range1 is fully after range2 */
> start1 >= end2)
>
> possibly together with checking for overflow in the size addition?
> But I didn't think that through, so maybe I'm doing something
> stupid.
>
> Finally, why is 'size' a u64? It will overflow anyway if it's
> bigger than a pointer, so it should be just 'unsigned long'. Or it
> should all be done in u64 if people care. Or we should care about
> overflow (which cannot be done with pointers).
>
> Also, comparing pointers is unsafe to begin with. It's not clear
> if they are signed or unsigned comparisons, and gcc has
> historically had bugs here (only unsigned comparisons make sense
> for pointers, but _technically_ a crazy compiler person could
> argue that at least in some environments any valid pointers to the
> same object - which is the only thing C defines - must not cross
> the sign barrier, so they use a buggy signed compare).
hm, indeed - and i missed that.
[ Even in the pointer space i think this cast is slightly confused
too:
static inline bool overlap(void *addr, u64 size, void *start, void *end)
{
void *addr2 = (char *)addr + size;
as void * has byte granular arithmetics already so 'addr + size'
would suffice. ]
> IOW, I think this whole function is just total crap, apparently
> put together by randomly assembling characters until it compiles.
> Somebody should put more effort into looking at it, but I think it
> should be something like
>
> static inline int overlap(void *addr, unsigned long len, void *start, void *end)
> {
> unsigned long a1 = (unsigned long) addr;
> unsigned long b1 = a1 + len;
> unsigned long a2 = (unsigned long) start;
> unsigned long b2 = (unsigned long) end;
At least some arguments have unsigned long natural types (they come
out of page_address() for example) so the function parameters could
perhaps be changed to unsigned long too as well.
> #ifdef WE_CARE_DEEPLY
> /* Overflow? */
> if (b1 < a1)
> return 1;
> #ifdef AND_ARE_ANAL
> if (b2 < a2)
> return 1;
> #endif
> #endif
> return !(b1 <= a2 || a1 >= b2);
> }
>
> but I really migth have done soemthing wrong there. It's a simple
> function, but somebody needs to double-check that I haven't made
> it worse.
Looks correct to me.
Ingo
next prev parent reply other threads:[~2009-07-10 19:31 UTC|newest]
Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-10 16:28 [GIT PULL] core kernel fixes Ingo Molnar
2009-07-10 19:06 ` Linus Torvalds
2009-07-10 19:31 ` Ingo Molnar [this message]
2009-07-10 19:51 ` [PATCH] dma-debug: Fix the overlap() function to be correct and readable Ingo Molnar
2009-07-10 20:07 ` Linus Torvalds
2009-07-10 20:34 ` Ingo Molnar
2009-07-14 10:15 ` Jaswinder Singh Rajput
2009-07-14 10:37 ` Jaswinder Singh Rajput
2009-07-14 10:52 ` Jaswinder Singh Rajput
2009-07-10 19:52 ` [GIT PULL] core kernel fixes Linus Torvalds
2009-07-10 20:02 ` Ingo Molnar
2009-07-10 20:36 ` [GIT PULL, v2] " Ingo Molnar
2009-07-13 14:52 ` [GIT PULL] " Joerg Roedel
-- strict thread matches above, loose matches on Subject: below --
2020-01-29 11:53 Ingo Molnar
2020-01-29 19:10 ` pr-tracker-bot
2019-05-18 8:51 Ingo Molnar
2019-05-19 17:45 ` pr-tracker-bot
2019-05-16 15:51 Ingo Molnar
2019-05-16 18:20 ` pr-tracker-bot
2018-07-21 11:58 Ingo Molnar
2017-12-06 22:01 Ingo Molnar
2017-11-05 14:33 Ingo Molnar
2017-11-05 18:09 ` Linus Torvalds
2017-11-05 19:53 ` Josh Poimboeuf
2017-11-05 20:12 ` Linus Torvalds
2017-11-05 21:01 ` Josh Poimboeuf
2017-07-21 10:01 Ingo Molnar
2016-10-18 10:14 Ingo Molnar
2016-07-13 10:55 Ingo Molnar
2016-04-03 10:45 Ingo Molnar
2015-02-06 18:28 Ingo Molnar
2012-10-23 10:57 Ingo Molnar
2012-08-03 16:31 Ingo Molnar
2012-08-03 16:55 ` Darren Hart
2012-08-03 17:01 ` Ingo Molnar
2012-08-03 17:24 ` Darren Hart
2012-06-15 18:45 Ingo Molnar
2012-01-26 18:05 Ingo Molnar
2011-08-04 20:45 Ingo Molnar
2011-04-02 10:21 Ingo Molnar
2011-03-25 12:52 Ingo Molnar
2011-01-21 2:11 Ingo Molnar
2011-01-15 15:15 Ingo Molnar
2010-10-05 19:12 Ingo Molnar
2010-10-05 20:15 ` Linus Torvalds
2010-10-05 21:09 ` Paul E. McKenney
2010-10-05 21:45 ` Linus Torvalds
2010-10-05 22:05 ` Paul E. McKenney
2010-10-06 2:56 ` Eric Dumazet
2010-10-06 4:59 ` Paul E. McKenney
2010-10-06 18:20 ` Ingo Molnar
2010-10-06 21:27 ` Paul E. McKenney
2010-10-07 8:11 ` Ingo Molnar
2010-10-07 17:42 ` Paul E. McKenney
2010-09-08 13:04 Ingo Molnar
2010-03-26 14:53 Ingo Molnar
2010-03-13 16:35 Ingo Molnar
2009-12-18 18:52 Ingo Molnar
2009-11-10 17:53 Ingo Molnar
2009-10-23 14:53 Ingo Molnar
2009-10-13 18:29 Ingo Molnar
2009-10-08 19:06 Ingo Molnar
2009-10-08 19:16 ` Linus Torvalds
2009-10-08 19:20 ` Ingo Molnar
2009-09-21 13:13 Ingo Molnar
2009-08-13 18:54 Ingo Molnar
2009-08-09 16:07 Ingo Molnar
2009-08-09 18:41 ` Darren Hart
2009-06-20 17:30 Ingo Molnar
2009-06-20 18:49 ` Linus Torvalds
2009-06-20 19:01 ` Linus Torvalds
2009-06-20 20:27 ` Ingo Molnar
2009-06-21 17:12 ` Thomas Gleixner
2009-06-21 17:37 ` Linus Torvalds
2009-06-21 17:57 ` Linus Torvalds
2009-06-21 19:26 ` Thomas Gleixner
2009-05-18 14:23 Ingo Molnar
2009-05-18 15:48 ` Linus Torvalds
2009-05-18 19:20 ` Thomas Gleixner
2009-05-19 20:52 ` Linus Torvalds
2009-05-19 21:45 ` Thomas Gleixner
2009-05-19 22:20 ` Darren Hart
2009-05-05 9:33 Ingo Molnar
2009-01-30 23:12 [git pull] " Ingo Molnar
2009-01-26 17:24 Ingo Molnar
2009-01-11 14:36 Ingo Molnar
2008-12-04 19:39 Ingo Molnar
2008-11-29 19:36 Ingo Molnar
2008-11-18 14:14 Ingo Molnar
2008-11-07 16:28 Ingo Molnar
2008-10-30 23:29 Ingo Molnar
2008-10-15 12:50 [git pull] core kernel updates for v2.6.28 Ingo Molnar
2008-10-16 22:32 ` Linus Torvalds
2008-10-17 6:23 ` [git pull] core kernel fixes Ingo Molnar
2008-08-28 11:44 Ingo Molnar
2008-08-18 18:35 Ingo Molnar
2008-07-24 15:13 Ingo Molnar
2008-06-30 15:32 Ingo Molnar
2008-06-30 17:02 ` Vegard Nossum
2008-06-30 18:20 ` Ingo Molnar
2008-06-30 18:43 ` Vegard Nossum
2008-06-30 19:46 ` Thomas Gleixner
2008-06-30 19:51 ` Vegard Nossum
2008-06-30 19:54 ` Thomas Gleixner
2008-06-23 19:45 Ingo Molnar
2008-06-19 15:16 Ingo Molnar
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=20090710193110.GA28281@elte.hu \
--to=mingo@elte.hu \
--cc=a.p.zijlstra@chello.nl \
--cc=joerg.roedel@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--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;
as well as URLs for NNTP newsgroup(s).