From: Prarit Bhargava <prarit@redhat.com>
To: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Cc: Prarit Bhargava <prarit@redhat.com>
Subject: [PATCH]: PCI: GART iommu alignment fixes
Date: Mon, 21 Jul 2008 10:15:27 -0400 [thread overview]
Message-ID: <20080721141506.3720.93023.sendpatchset@prarit.bos.redhat.com> (raw)
In-Reply-To: <20080721141501.3720.4565.sendpatchset@prarit.bos.redhat.com>
pci_alloc_consistent/dma_alloc_coherent is supposed to return size aligned
addresses.
>From Documentation/DMA-mapping.txt:
"pci_alloc_consistent returns two values: the virtual address which you
can use to access it from the CPU and dma_handle which you pass to the
card.
The cpu return address and the DMA bus master address are both
guaranteed to be aligned to the smallest PAGE_SIZE order which
is greater than or equal to the requested size. This invariant
exists (for example) to guarantee that if you allocate a chunk
which is smaller than or equal to 64 kilobytes, the extent of the
buffer you receive will not cross a 64K boundary."
Fix the GART's alloc_iommu code to return a size aligned address. Also fix
an incorrect alignment calculation in the iommu-helper code.
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
index faf3229..329718e 100644
--- a/arch/x86/kernel/pci-gart_64.c
+++ b/arch/x86/kernel/pci-gart_64.c
@@ -96,11 +96,12 @@ static unsigned long alloc_iommu(struct device *dev, int size)
spin_lock_irqsave(&iommu_bitmap_lock, flags);
offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, next_bit,
- size, base_index, boundary_size, 0);
+ size, base_index, boundary_size, size - 1);
if (offset == -1) {
need_flush = 1;
offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, 0,
- size, base_index, boundary_size, 0);
+ size, base_index, boundary_size,
+ size - 1);
}
if (offset != -1) {
set_bit_string(iommu_gart_bitmap, offset, size);
diff --git a/lib/iommu-helper.c b/lib/iommu-helper.c
index a3b8d4c..b970f1b 100644
--- a/lib/iommu-helper.c
+++ b/lib/iommu-helper.c
@@ -16,7 +16,7 @@ again:
index = find_next_zero_bit(map, size, start);
/* Align allocation */
- index = (index + align_mask) & ~align_mask;
+ index = (index + align_mask + 1) & ~align_mask;
end = index + nr;
if (end >= size)
next prev parent reply other threads:[~2008-07-21 14:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-21 14:15 [PATCH]: iommu fix potential overflow in alloc_iommu() Prarit Bhargava
2008-07-21 14:15 ` Prarit Bhargava [this message]
2008-07-21 15:16 ` [PATCH]: PCI: GART iommu alignment fixes FUJITA Tomonori
2008-07-21 15:16 ` [PATCH]: iommu fix potential overflow in alloc_iommu() FUJITA Tomonori
2008-07-21 15:21 ` Prarit Bhargava
2008-07-21 15:46 ` FUJITA Tomonori
2008-07-21 15:47 ` Prarit Bhargava
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=20080721141506.3720.93023.sendpatchset@prarit.bos.redhat.com \
--to=prarit@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@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.