From: Brian Behlendorf on

> On Mon, 2 Aug 2010 18:09:51 +0200
>
> Oleg Nesterov <oleg(a)redhat.com> wrote:
> > We have a bugreport which blames div64_u64() on 32bit platforms.
> >
> > However, the code obviously doesn't even try to pretend it can do
> > the 64bit division precisely. If there is something in the high
> > word of divisor, div64_u64() just shifts both arguments and throws
> > out the low bits.
>
> Well that was a bit lazy of us - I wonder how hard it is to fix.
>
> At present people will test their code on 64-bit only to find out later
> that it doesn't work correctly on 32-bit. Bad. Perhaps we should
> similarly break the 64-bit version :)

Here's an even crazier idea, let's just fix the 32-bit version. :)

The attached patch fully implements div64_u64() such that it will return
precisely the right quotient even when the divisor exceeds 32-bits. The
patch also adds a div64_s64() function to fully support signed 64-bit
division.

Because this fix is non-obvious I have also included a unsigned and signed
regression test to verify the correctness of the patch. Using a vanilla
2.6.35 kernel the unsigned regression tests fails on 32-bit platforms. With
the proposed patch applied both the unsigned and signed tests pass.

--
Thanks,
Brian