lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <200802142316.44985.m.kozlowski@tuxland.pl>
Date:	Thu, 14 Feb 2008 23:16:44 +0100
From:	Mariusz Kozlowski <m.kozlowski@...land.pl>
To:	Julia Lawall <julia@...u.dk>
Cc:	Pekka Enberg <penberg@...helsinki.fi>,
	Nishanth Aravamudan <nacc@...ibm.com>,
	linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: Re: [PATCH 2/6] fs/direct-io.c: Use DIV_ROUND_UP

Hello,

> > >  Is it just me, or does
> > >
> > >         ((user_addr + iov[seg].iov_len + PAGE_SIZE - 1)/PAGE_SIZE - user_addr/PAGE_SIZE)
> > >
> > >  not simplify to
> > >
> > >         = ((iov[seg].iov_len + PAGE_SIZE - 1)/PAGE_SIZE + user_addr/PAGE_SIZE - user_addr/PAGE_SIZE)
> > >
> > >         = ((iov[seg].iov_len + PAGE_SIZE - 1)/PAGE_SIZE)
> > >
> > >         = DIV_ROUND_UP(iov[seg].iov_len, PAGE_SIZE)
> > >
> > >  CMIIW.
> > 
> > I double-checked this and I believe you're correct. It's simpler to
> > see when you do:
> > 
> >   x = user_addr
> >   y = iov[seg].iov_len
> >   z = PAGE_SIZE
> > 
> > So
> > 
> >   (x + y + z - 1)/z - x/z
> > 
> >   = [x + (y + z - 1)]/z - x/z
> > 
> >   = [xz + z(y + z - 1)]/z^2 - x/z
> > 
> >   = x/z + (y + z - 1)/z - x/z
> > 
> > And the rest follows from your simplifications.
> 
> It doesn't work:
> 
>  ((3+4+5-1)/5) - (3/5) = 2
>  ((4+5-1)/5) = 1

Logic was wrong but conclusion was right :) and so was Nishanth:

(a + b) + c = a + (b + c)

and

k   l   k + l
- + - = -----
m   m     m

thus:

(user_addr + iov[seg].iov_len + PAGE_SIZE - 1) = user_addr + (iov[seg].iov_len + PAGE_SIZE - 1)

and


user_addr + iov[seg].iov_len + PAGE_SIZE - 1   user_addr
-------------------------------------------- - --------- =
                 PAGE_SIZE                     PAGE_SIZE


user_addr   iov[seg].iov_len + PAGE_SIZE - 1   user_addr
--------- + -------------------------------- - --------- = 
PAGE_SIZE               PAGE_SIZE              PAGE_SIZE


iov[seg].iov_len + PAGE_SIZE - 1
--------------------------------
           PAGE_SIZE


or even more:


iov[seg].iov_len - 1
-------------------- + 1
     PAGE_SIZE


Regards,

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ