All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@linux-m68k.org>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Joerg Roedel <joerg.roedel@amd.com>,
	Anton Blanchard <anton@au1.ibm.com>,
	FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
	linux-kernel@vger.kernel.org
Subject: Re: Is iommu_num_pages() broken ?
Date: Sun, 05 Aug 2012 08:39:39 +0200	[thread overview]
Message-ID: <m24nohsuz8.fsf@linux-m68k.org> (raw)
In-Reply-To: <1344125816.24037.84.camel@pasglop> (Benjamin Herrenschmidt's message of "Sun, 05 Aug 2012 10:16:56 +1000")

Benjamin Herrenschmidt <benh@kernel.crashing.org> writes:

> static inline unsigned long iommu_num_pages(unsigned long addr,
> 					    unsigned long len,
> 					    unsigned long io_page_size)
> {
> 	unsigned long size = (addr & (io_page_size - 1)) + len;
>
> 	return DIV_ROUND_UP(size, io_page_size);
> }
>  
>
> That doesn't look right to me...
>
> The powerpc iommu code at least uses that with an addr which may not be
> page aligned (ie, result of sg_virt() which include the offset).
>
> The above code will align the start before adding the len which is wrong

addr & (io_page_size - 1) computes the offset into the page pointed to
by addr.  Looks right to me.

addr & ~(io_page_size - 1) would round addr down to the start of the
page.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

  reply	other threads:[~2012-08-05  6:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-05  0:16 Is iommu_num_pages() broken ? Benjamin Herrenschmidt
2012-08-05  6:39 ` Andreas Schwab [this message]
2012-08-05  6:49   ` Benjamin Herrenschmidt

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=m24nohsuz8.fsf@linux-m68k.org \
    --to=schwab@linux-m68k.org \
    --cc=anton@au1.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=joerg.roedel@amd.com \
    --cc=linux-kernel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.