From: Keir Fraser <keir@xensource.com>
To: Lukas Hejtmanek <xhejtman@ics.muni.cz>
Cc: xen-devel@lists.xensource.com
Subject: Re: Question regarding SLAB corruption
Date: Mon, 09 Jul 2007 13:47:34 +0100 [thread overview]
Message-ID: <C2B7ECF7.12164%keir@xensource.com> (raw)
In-Reply-To: <20070709120734.GH3885@ics.muni.cz>
[-- Attachment #1: Type: text/plain, Size: 847 bytes --]
On 9/7/07 13:07, "Lukas Hejtmanek" <xhejtman@ics.muni.cz> wrote:
> According to IB developers, it uses alloc_pages and then pci_map_sg which they
> state that is DMA API. So, is it correct approach?
Well, we currently assume that segments of a scatterlist (as passed to
pci_map_sg) do not cross page boundaries. It looks like this assumption is
broken (certainly for the infiniband driver!).
I've just checked in the attached patch to fix this issue. Please give it a
try in your dom0 tree.
> I did debug like this - so it prints physical and virtual addresses and they
> seems to be perfectly contiguous. Are the physical addresses real physical
> addresses or virtualized by Xen hypervisor?
You want to use virt_to_machine(). As you say, the addresses returned by
virt_to_phys() are virtual-physical, which is not what you want.
-- Keir
[-- Attachment #2: map_sg.patch --]
[-- Type: application/octet-stream, Size: 2897 bytes --]
# HG changeset patch
# User kfraser@localhost.localdomain
# Date 1183985110 -3600
# Node ID 08cf42135056cbc07a6d790d4851e0e4b160f847
# Parent f833757672a70ee43afd0bfbfaa22cec3b132445
x86: dma_map_sg() must handle multi-page segments.
Signed-off-by: Keir Fraser <keir@xensource.com>
diff -r f833757672a7 -r 08cf42135056 arch/i386/kernel/pci-dma-xen.c
--- a/arch/i386/kernel/pci-dma-xen.c Sat Jul 07 11:44:16 2007 +0100
+++ b/arch/i386/kernel/pci-dma-xen.c Mon Jul 09 13:45:10 2007 +0100
@@ -97,6 +97,9 @@ dma_map_sg(struct device *hwdev, struct
BUG_ON(!sg[i].page);
IOMMU_BUG_ON(address_needs_mapping(
hwdev, sg[i].dma_address));
+ IOMMU_BUG_ON(range_straddles_page_boundary(
+ page_to_pseudophys(sg[i].page) + sg[i].offset,
+ sg[i].length));
}
rc = nents;
}
@@ -338,7 +341,7 @@ dma_map_single(struct device *dev, void
} else {
dma = gnttab_dma_map_page(virt_to_page(ptr)) +
offset_in_page(ptr);
- IOMMU_BUG_ON(range_straddles_page_boundary(ptr, size));
+ IOMMU_BUG_ON(range_straddles_page_boundary(__pa(ptr), size));
IOMMU_BUG_ON(address_needs_mapping(dev, dma));
}
diff -r f833757672a7 -r 08cf42135056 arch/i386/kernel/swiotlb.c
--- a/arch/i386/kernel/swiotlb.c Sat Jul 07 11:44:16 2007 +0100
+++ b/arch/i386/kernel/swiotlb.c Mon Jul 09 13:45:10 2007 +0100
@@ -480,7 +480,7 @@ swiotlb_map_single(struct device *hwdev,
* we can safely return the device addr and not worry about bounce
* buffering it.
*/
- if (!range_straddles_page_boundary(ptr, size) &&
+ if (!range_straddles_page_boundary(__pa(ptr), size) &&
!address_needs_mapping(hwdev, dev_addr))
return dev_addr;
@@ -577,7 +577,9 @@ swiotlb_map_sg(struct device *hwdev, str
for (i = 0; i < nelems; i++, sg++) {
dev_addr = gnttab_dma_map_page(sg->page) + sg->offset;
- if (address_needs_mapping(hwdev, dev_addr)) {
+ if (range_straddles_page_boundary(page_to_pseudophys(sg->page)
+ + sg->offset, sg->length)
+ || address_needs_mapping(hwdev, dev_addr)) {
gnttab_dma_unmap_page(dev_addr);
buffer.page = sg->page;
buffer.offset = sg->offset;
diff -r f833757672a7 -r 08cf42135056 include/asm-i386/mach-xen/asm/dma-mapping.h
--- a/include/asm-i386/mach-xen/asm/dma-mapping.h Sat Jul 07 11:44:16 2007 +0100
+++ b/include/asm-i386/mach-xen/asm/dma-mapping.h Mon Jul 09 13:45:10 2007 +0100
@@ -23,11 +23,11 @@ address_needs_mapping(struct device *hwd
}
static inline int
-range_straddles_page_boundary(void *p, size_t size)
+range_straddles_page_boundary(paddr_t p, size_t size)
{
extern unsigned long *contiguous_bitmap;
- return (((((unsigned long)p & ~PAGE_MASK) + size) > PAGE_SIZE) &&
- !test_bit(__pa(p) >> PAGE_SHIFT, contiguous_bitmap));
+ return ((((p & ~PAGE_MASK) + size) > PAGE_SIZE) &&
+ !test_bit(p >> PAGE_SHIFT, contiguous_bitmap));
}
#define dma_alloc_noncoherent(d, s, h, f) dma_alloc_coherent(d, s, h, f)
[-- Attachment #3: Type: text/plain, Size: 138 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel
next prev parent reply other threads:[~2007-07-09 12:47 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-08 0:54 Question regarding SLAB corruption Lukas Hejtmanek
2007-07-08 9:59 ` Keir Fraser
2007-07-08 10:05 ` Lukas Hejtmanek
2007-07-08 10:11 ` Keir Fraser
2007-07-09 7:38 ` Lukas Hejtmanek
2007-07-09 8:02 ` Tian, Kevin
2007-07-09 8:31 ` Keir Fraser
2007-07-09 12:07 ` Lukas Hejtmanek
2007-07-09 12:47 ` Keir Fraser [this message]
2007-07-09 13:24 ` Lukas Hejtmanek
2007-07-09 13:42 ` Keir Fraser
2007-07-09 15:39 ` Lukas Hejtmanek
2007-07-09 16:13 ` Keir Fraser
2007-07-09 17:11 ` Lukas Hejtmanek
2007-07-09 17:21 ` Keir Fraser
2007-07-09 17:42 ` Lukas Hejtmanek
2007-07-09 18:29 ` Keir Fraser
2007-07-09 18:37 ` Lukas Hejtmanek
2007-07-09 18:46 ` Keir Fraser
2007-07-09 19:22 ` Keir Fraser
2007-07-09 19:43 ` Lukas Hejtmanek
2007-07-09 21:18 ` Keir Fraser
2007-07-09 21:26 ` Lukas Hejtmanek
2007-07-09 21:50 ` Lukas Hejtmanek
2007-07-09 19:25 ` Roland Dreier
2007-07-09 19:39 ` Keir Fraser
2007-07-09 20:56 ` Lukas Hejtmanek
2007-07-09 21:07 ` Roland Dreier
2007-07-09 21:14 ` Lukas Hejtmanek
2007-07-09 21:18 ` Roland Dreier
2007-07-09 21:42 ` Lukas Hejtmanek
2007-07-09 21:53 ` Roland Dreier
2007-07-09 22:13 ` Lukas Hejtmanek
2007-07-09 22:30 ` Keir Fraser
2007-07-09 22:30 ` Roland Dreier
2007-07-09 22:34 ` Keir Fraser
2007-07-10 18:47 ` Question: Dynamic code in x86_64 Xen Santos, Jose Renato G
2007-07-10 22:01 ` Keir Fraser
2007-07-10 22:06 ` Santos, Jose Renato G
2007-07-09 21:26 ` Question regarding SLAB corruption Roland Dreier
2007-07-09 21:33 ` Keir Fraser
2007-07-11 9:37 ` Question regarding vm creat&boot tgh
2007-07-09 19:21 ` Question regarding SLAB corruption Roland Dreier
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=C2B7ECF7.12164%keir@xensource.com \
--to=keir@xensource.com \
--cc=xen-devel@lists.xensource.com \
--cc=xhejtman@ics.muni.cz \
/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.