From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Joerg Roedel <joerg.roedel@amd.com>
Cc: Anton Blanchard <anton@au1.ibm.com>,
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
linux-kernel@vger.kernel.org
Subject: Is iommu_num_pages() broken ?
Date: Sun, 05 Aug 2012 10:16:56 +1000 [thread overview]
Message-ID: <1344125816.24037.84.camel@pasglop> (raw)
Hi folks !
I stumbled upon this today:
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
and will result in potentially missing a page or am I missing
something ?
Shouldn't it be something like
static inline unsigned long iommu_num_pages(unsigned long addr,
unsigned long len,
unsigned long io_page_size)
{
unsigned long start = addr & (io_page_size - 1);
unsigned long end = addr + len;
return DIV_ROUND_UP(end - start, io_page_size);
}
?
Cheers,
Ben.
next reply other threads:[~2012-08-05 0:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-05 0:16 Benjamin Herrenschmidt [this message]
2012-08-05 6:39 ` Is iommu_num_pages() broken ? Andreas Schwab
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=1344125816.24037.84.camel@pasglop \
--to=benh@kernel.crashing.org \
--cc=anton@au1.ibm.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox