Langsdorf, Mark
2007-Feb-26 20:37 UTC
[Xen-devel] [PATCH] Retry 3: Use i386 swiotlb code in lib/swiotlb-xen.c [2/2]
Move the arch/i386/kernel/swiotlb.c code to lib/swiotlb-xen.c code in order to simplify maintenance of Xen in the future. The first patch simply moves the code to lib/swiotlb-xen.c; the second patch adds the necessary changes to the Xen code base to allow x86_64 systems to boot with SWIOTLB and the dma_ops framework. The first patch also copies the standard arch/x86_64/kernel/pci-dma.c to arch/x86_64/kernel/pci-dma-xen.c, which should make reviewing the second patch a little easier. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Jan Beulich
2007-Feb-27 08:34 UTC
Re: [Xen-devel] [PATCH] Retry 3: Use i386 swiotlb code in lib/swiotlb-xen.c [2/2]
>>> "Langsdorf, Mark" <mark.langsdorf@amd.com> 26.02.07 21:37 >>> >Move the arch/i386/kernel/swiotlb.c code to lib/swiotlb-xen.c >code in order to simplify maintenance of Xen in the future. > >The first patch simply moves the code to lib/swiotlb-xen.c;Without the lib/Makefile adjustment the first patch can''t work without the second one.>the second patch adds the necessary changes to the Xen code >base to allow x86_64 systems to boot with SWIOTLB and the >dma_ops framework.>--- a/linux-2.6-xen-sparse/arch/x86_64/kernel/pci-dma-xen.c Mon Feb 26 15:52:16 2007 -0600 >+++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/pci-dma-xen.c Mon Feb 26 15:58:43 2007 -0600 >... >+#include <xen/balloon.h> >+#include <asm/tlbflush.h>Why xen/balloon.h? asm/hypervisor.h is what declares xen_{create,destroy}_contiguous_region().>... >+ /* Hardcode 31 address bits for now: aacraid limitation. */ >+ if (xen_create_contiguous_region((unsigned long)memory, get_order(size), fls64(dma_mask)) != 0) { >+ free_pages((unsigned long)memory, get_order(size)); >+ return NULL; >+ } >+Could we also get rid of the (now wrong) comment?>--- a/linux-2.6-xen-sparse/lib/swiotlb-xen.c Mon Feb 26 15:52:16 2007 -0600 >+++ b/linux-2.6-xen-sparse/lib/swiotlb-xen.c Mon Feb 26 15:58:43 2007 -0600 >... >+void >+swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr, >+ dma_addr_t dma_handle) >+{ >+ if (in_swiotlb_aperture((dma_addr_t) vaddr)) >+ free_pages((unsigned long) vaddr, get_order(size)); >+ else >+ /* DMA_TO_DEVICE to avoid memcpy in unmap_single */ >+ swiotlb_unmap_single (hwdev, dma_handle, size, DMA_TO_DEVICE); >+}I''m pretty certain this is wrong: dma_handle is what should be passed to in_swiotlb_aperture().>The first patch also copies the standard >arch/x86_64/kernel/pci-dma.c to arch/x86_64/kernel/pci-dma-xen.c, >which should make reviewing the second patch a little easier.While the second patch assumes the first patch does what you describe, the first patch really just moves swiotlb.c. Jan _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Langsdorf, Mark
2007-Feb-27 20:30 UTC
RE: [Xen-devel] [PATCH] Retry 3: Use i386 swiotlb code in lib/swiotlb-xen.c [2/2]
> >>> "Langsdorf, Mark" <mark.langsdorf@amd.com> 26.02.07 21:37 >>> > >Move the arch/i386/kernel/swiotlb.c code to lib/swiotlb-xen.c > >code in order to simplify maintenance of Xen in the future. > > > >The first patch simply moves the code to lib/swiotlb-xen.c; > > Without the lib/Makefile adjustment the first patch can''t work without > the second one.Okay.> >--- a/linux-2.6-xen-sparse/lib/swiotlb-xen.c Mon Feb 26 > 15:52:16 2007 -0600 > >+++ b/linux-2.6-xen-sparse/lib/swiotlb-xen.c Mon Feb 26 > 15:58:43 2007 -0600 > >... > >+void > >+swiotlb_free_coherent(struct device *hwdev, size_t size, > void *vaddr, > >+ dma_addr_t dma_handle) > >+{ > >+ if (in_swiotlb_aperture((dma_addr_t) vaddr)) > >+ free_pages((unsigned long) vaddr, get_order(size)); > >+ else > >+ /* DMA_TO_DEVICE to avoid memcpy in unmap_single */ > >+ swiotlb_unmap_single (hwdev, dma_handle, size, > DMA_TO_DEVICE); > >+} > > I''m pretty certain this is wrong: dma_handle is what should be passed > to in_swiotlb_aperture().The original code is if (!(vaddr >= (void *)io_tlb_start) && vaddr < (void *) io_tlb_end)) free_pages((unsigned long) vaddr, get_order(size)); I can''t see why I wouldn''t check the vaddr address in Xen, also. -Mark Langsdorf AMD, Inc. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2007-Feb-27 20:49 UTC
Re: [Xen-devel] [PATCH] Retry 3: Use i386 swiotlb code in lib/swiotlb-xen.c [2/2]
On 27/2/07 20:30, "Langsdorf, Mark" <mark.langsdorf@amd.com> wrote:>> I''m pretty certain this is wrong: dma_handle is what should be passed >> to in_swiotlb_aperture(). > > The original code is > if (!(vaddr >= (void *)io_tlb_start) && vaddr < (void *) > io_tlb_end)) > free_pages((unsigned long) vaddr, get_order(size)); > > I can''t see why I wouldn''t check the vaddr address in Xen, also.You can either use the vaddr check from original lib/swiotlb.c *or* you can pass the dma_handle to in_swiotlb_aperture(). You cannot pass a vaddr to in_swiotlb_aperture(): it makes no sense! Actually I think the dma_alloc_coherent() you''ve hauled in from native x86/64 code won''t even work on Xen as it is. The dma_alloc_pages() function it uses first won''t guarantee to return contiguous memory on Xen, but that is implicitly assumed by the caller. I''m afraid various rather serious niggles like these make me wary of applying these patches until they''ve been very thoroughly audited. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Keir Fraser
2007-Feb-27 21:21 UTC
Re: [Xen-devel] [PATCH] Retry 3: Use i386 swiotlb code in lib/swiotlb-xen.c [2/2]
On 27/2/07 20:49, "Keir Fraser" <Keir.Fraser@cl.cam.ac.uk> wrote:> You can either use the vaddr check from original lib/swiotlb.c *or* you can > pass the dma_handle to in_swiotlb_aperture(). You cannot pass a vaddr to > in_swiotlb_aperture(): it makes no sense! > > Actually I think the dma_alloc_coherent() you''ve hauled in from native > x86/64 code won''t even work on Xen as it is. The dma_alloc_pages() function > it uses first won''t guarantee to return contiguous memory on Xen, but that > is implicitly assumed by the caller.Perhaps it would be best to focus on just the changes required to meet your main objective, which (I think?) is to move Xen x86/64 over to dma_ops so that you can conveniently slide the AMD GART implementation in place of the swiotlb. If this is the case, relocating swiotlb.c to lib/swiotlb-xen.c and doing a halfway merge with lib/swiotlb.c is not really on the critical path. Moreover, Jan has some patches pending for mainline Linux which will change things around in that area anyway if they get accepted. Now is probably not the time to churn the swiotlb.c code. Instead can you not just define a swiotlb-based dma_mapping_ops structure in a suitable arch/x86_64 file (e.g., pci-swiotlb-xen.c would be an obvious place) and then work on moving us towards using dma_ops hooks for all the dma-mapping operations. You could do this latter step piecemeal across a number of patches if you like (i.e., so that intermediate steps some dma operations are using the dma_ops hooks while others are still statically falling back to calling into swiotlb code directly). Probably you''d start off taking a copy of i386/kernel/pci-dma-xen.c into x86_64, and then progressively pull in dma_ops logic from x86_64/kernel/pci_dma.c. At the same time you''d be progressively reintroducing dma_ops usage into mach-xen/asm/dma-mapping.h as well. -- Keir _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel