Where do we stand with the Xen patches?
Subsystems (8)
Hi Ingo,
Over the last week or so, I've set out pull requests for the following branches in git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git :
for-ingo/xen/dom0/core
You made two comments about the first post of this set:
1. The // comments in the mtrr code. Now fixed.
2. A query about when Xen can support PAT. In progress; when its done, we can remove the unconditional PAT disable.
for-ingo/xen/dom0/pci
for-ingo/xen/dom0/swiotlb
Updated with Joerg Roedel, FUJITA Tomonori and Matthew Wilcox's comments, Acked-by and Reviewed-bys as appropriate.
for-ingo/xen/dom0/apic-ops
After discussion between yourself and HPA, we resolved that using io_apic_ops was the right way to go forward with this. I replaced for-ingo/xen/dom0/apic with the new branch for-ingo/xen/dom0/apic-ops, which is identical aside from implementing and using io_apic_ops.
for-ingo/xen/dom0/mtrr
You queried the value of "extending" this interface, given that its considered to be deprecated. These changes in no way extend the interface, but just make the existing interface functional under Xen. And while we don't have PAT support, there's no other way of setting cachability attributes on memory, so not supporting it has a fairly severe performance impact on things like X.
Aside from some whitespace issues around some Impact: lines, I don't know of any outstanding problems. (I just pushed an updates to these branches to fix those, and fold a change to address Jesse's comment.)
Please tell me if you have any further issues which prevents you from pulling these changes. Otherwise I'd appreciate it if you pulled them soon, as we're already on -rc5, and I have more changes I'd like to prep for the next merge window.
Thanks,
J
Quoted 14 lines · Jeremy Fitzhardinge
Hi Ingo,
Over the last week or so, I've set out pull requests for the following branches in
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git
:for-ingo/xen/dom0/core
You made two comments about the first post of this set:
1. The // comments in the mtrr code. Now fixed.
2. A query about when Xen can support PAT. In progress; when its done, we can remove the unconditional PAT disable.
Quoted 5 lines
for-ingo/xen/dom0/pci
for-ingo/xen/dom0/swiotlbUpdated with Joerg Roedel, FUJITA Tomonori and Matthew Wilcox's comments, Acked-by and Reviewed-bys as appropriate.
These look fine but i still need to go over them one last time before pulling them.
Quoted 7 lines
for-ingo/xen/dom0/apic-ops
After discussion between yourself and HPA, we resolved that using
io_apic_opswas the right way to go forward with this. I replaced for-ingo/xen/dom0/apic with the new branch for-ingo/xen/dom0/apic-ops, which is identical aside from implementing and usingio_apic_ops.
Yes. Here too i still need to go over them once more before pulling them.
Quoted 8 lines
for-ingo/xen/dom0/mtrr
You queried the value of "extending" this interface, given that its considered to be deprecated. These changes in no way extend the interface, but just make the existing interface functional under Xen. And while we don't have PAT support, there's no other way of setting cachability attributes on memory, so not supporting it has a fairly severe performance impact on things like X.
Latest Xorg doesnt need /proc/mtrr. By the time this kernel (.31 or later) hits any distribution, /proc/mtrr using Xorg will be a distant memory. So i see no reason why to apply those bits at all, and i see a lot of reasons to not apply them.
Quoted 9 lines
Aside from some whitespace issues around some Impact: lines, I don't know of any outstanding problems. (I just pushed an updates to these branches to fix those, and fold a change to address Jesse's comment.)
Please tell me if you have any further issues which prevents you from pulling these changes. Otherwise I'd appreciate it if you pulled them soon, as we're already on -rc5, and I have more changes I'd like to prep for the next merge window.
As in the past, my main worry is performance overhead of paravirt in general.
The patches that dont affect any native kernel fast path are probably OK (but still pending final review).
Regarding patches that do change the fastpath i'll do a round of measurements of CONFIG_PARAVIRT against !CONFIG_PARAVIRT kernels, and make up my mind based on that.
You could accelerate this by sending some "perf stat" hard numbers to give us an idea about where we stand today.
Ingo
Quoted 5 lines · Ingo Molnar
These look fine but i still need to go over them one last time before pulling them.
Yes. Here too i still need to go over them once more before pulling them.
I've been posting these patches in fundamentally the same form for about 6 months now. I don't think you'll find anything surprising.
Quoted 10 lines
Quoted 9 lines
for-ingo/xen/dom0/mtrr
You queried the value of "extending" this interface, given that its considered to be deprecated. These changes in no way extend the interface, but just make the existing interface functional under Xen. And while we don't have PAT support, there's no other way of setting cachability attributes on memory, so not supporting it has a fairly severe performance impact on things like X.
Quoted 2 lines
Latest Xorg doesnt need
/proc/mtrr. By the time this kernel (.31 or later) hits any distribution,/proc/mtrrusing Xorg will be a distant memory. So i see no reason why to apply those bits at all, and i see a lot of reasons to not apply them.
In general we don't break usermode ABIs, even when using new kernels with old distros, so I don't see why this case is any different.
Besides, these changes are not only for /proc/mtrr, but also to implement the internal mtrr_add() APIs that DRM uses to set the MTRR inside the kernel, so failing to implement them will cause performance regressions on new X servers.
Given that we're talking about 120 lines of code with no runtime impact and tiny kernel size impact (when configured), I'm at a loss for what your "lot of reasons" might be. Perhaps you could be more specific.
Quoted 4 lines
As in the past, my main worry is performance overhead of paravirt in general.
The patches that dont affect any native kernel fast path are probably OK (but still pending final review).
These changes don't have anything much to do with paravirt_ops, per se, and are all specifically about Xen dom0 support. Aside from that, none of the changes are on performance-critical paths.
Quoted 3 lines
Regarding patches that do change the fastpath i'll do a round of measurements of
CONFIG_PARAVIRTagainst !CONFIG_PARAVIRT kernels, and make up my mind based on that.You could accelerate this by sending some "perf stat" hard numbers to give us an idea about where we stand today.
I posted them the other day; those perf stat measurements pointing out the pv-spinlock problem also showed that paravirt_ops in general has a sub-1% performance hit (and possible performance benefit) when running mmap-perf. You added them into the commit log for the patch, so I presume you read it.
J
Quoted 13 lines · On Thu, 14 May 2009 12:54:54 -0700 Jeremy Fitzhardinge <[email protected]> wrote:
Hi Ingo,
Over the last week or so, I've set out pull requests for the following branches in
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git:for-ingo/xen/dom0/core
You made two comments about the first post of this set:
1. The // comments in the mtrr code. Now fixed.
2. A query about when Xen can support PAT. In progress; when its done, we can remove the unconditional PAT disable.
Quoted 5 lines
for-ingo/xen/dom0/pci
for-ingo/xen/dom0/swiotlbUpdated with Joerg Roedel, FUJITA Tomonori and Matthew Wilcox's comments, Acked-by and Reviewed-bys as appropriate.
The original code added dom0-specific dma mapping stuff in the generic place, which is completely wrong. I asked you to move the hacky stuff to Xen-specific code and ack'ed the patchset.
But as I said again and again, the dom0 changes to the generic dma mapipng code is really ugly and I don't like them at all. I didn't ack'ed such changes.
Quoted 7 lines · FUJITA Tomonori
Quoted 6 lines
for-ingo/xen/dom0/pci
for-ingo/xen/dom0/swiotlbUpdated with Joerg Roedel, FUJITA Tomonori and Matthew Wilcox's comments, Acked-by and Reviewed-bys as appropriate.
Quoted 8 lines
The original code added dom0-specific dma mapping stuff in the generic place, which is completely wrong. I asked you to move the hacky stuff to Xen-specific code and ack'ed the patchset.
But as I said again and again, the dom0 changes to the generic dma mapipng code is really ugly and I don't like them at all. I didn't ack'ed such changes.
I didn't mean to imply that you all acked all the patches. I tried to be careful to add Acked tags to the actual patches you each respectively acked.
J
Quoted 22 lines · FUJITA Tomonori
Quoted 13 lines · On Thu, 14 May 2009 12:54:54 -0700 Jeremy Fitzhardinge <[email protected]> wrote:
Hi Ingo,
Over the last week or so, I've set out pull requests for the following branches in
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git:for-ingo/xen/dom0/core
You made two comments about the first post of this set:
1. The // comments in the mtrr code. Now fixed.
2. A query about when Xen can support PAT. In progress; when its done, we can remove the unconditional PAT disable.Quoted 5 lines
for-ingo/xen/dom0/pci
for-ingo/xen/dom0/swiotlbUpdated with Joerg Roedel, FUJITA Tomonori and Matthew Wilcox's comments, Acked-by and Reviewed-bys as appropriate.
Quoted 7 lines
The original code added dom0-specific dma mapping stuff in the generic place, which is completely wrong. I asked you to move the hacky stuff to Xen-specific code and ack'ed the patchset.
But as I said again and again, the dom0 changes to the generic dma mapipng code is really ugly and I don't like them at all. I didn't ack'ed such changes.
How should it be solved instead? Can you see a clean way to achieve it? (maybe you already explained it in past threads - if yes then have you got subject lines or URIs to that?)
Thanks,
Ingo
Quoted 29 lines · On Mon, 18 May 2009 10:40:52 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 26 lines · FUJITA Tomonori
Quoted 13 lines · On Thu, 14 May 2009 12:54:54 -0700 Jeremy Fitzhardinge <[email protected]> wrote:
Hi Ingo,
Over the last week or so, I've set out pull requests for the following branches in
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git:for-ingo/xen/dom0/core
You made two comments about the first post of this set:
1. The // comments in the mtrr code. Now fixed.
2. A query about when Xen can support PAT. In progress; when its done, we can remove the unconditional PAT disable.Quoted 5 lines
for-ingo/xen/dom0/pci
for-ingo/xen/dom0/swiotlbUpdated with Joerg Roedel, FUJITA Tomonori and Matthew Wilcox's comments, Acked-by and Reviewed-bys as appropriate.
The original code added dom0-specific dma mapping stuff in the generic place, which is completely wrong. I asked you to move the hacky stuff to Xen-specific code and ack'ed the patchset.
Quoted 7 lines
Quoted 3 lines
But as I said again and again, the dom0 changes to the generic dma mapipng code is really ugly and I don't like them at all. I didn't ack'ed such changes.
How should it be solved instead? Can you see a clean way to achieve it? (maybe you already explained it in past threads - if yes then have you got subject lines or URIs to that?)
If we really need to merge dom0 support, then dom0 should have the own IOMMU implementation instead of adding any hacks to swiotlb (as I said long time ago). Yeah, there might be some duplication between swiotlb and the Xen IOMMU but IMO it's better to have clean code with some duplication rather than ugly unified code; unification makes sense only if we do cleanly.
Quoted 40 lines · FUJITA Tomonori
Quoted 29 lines · On Mon, 18 May 2009 10:40:52 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 26 lines · FUJITA Tomonori
Quoted 13 lines · On Thu, 14 May 2009 12:54:54 -0700 Jeremy Fitzhardinge <[email protected]> wrote:
Hi Ingo,
Over the last week or so, I've set out pull requests for the following branches in
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git:for-ingo/xen/dom0/core
You made two comments about the first post of this set:
1. The // comments in the mtrr code. Now fixed.
2. A query about when Xen can support PAT. In progress; when its done, we can remove the unconditional PAT disable.Quoted 5 lines
for-ingo/xen/dom0/pci
for-ingo/xen/dom0/swiotlbUpdated with Joerg Roedel, FUJITA Tomonori and Matthew Wilcox's comments, Acked-by and Reviewed-bys as appropriate.
The original code added dom0-specific dma mapping stuff in the generic place, which is completely wrong. I asked you to move the hacky stuff to Xen-specific code and ack'ed the patchset.
Quoted 7 lines
Quoted 3 lines
But as I said again and again, the dom0 changes to the generic dma mapipng code is really ugly and I don't like them at all. I didn't ack'ed such changes.
How should it be solved instead? Can you see a clean way to achieve it? (maybe you already explained it in past threads - if yes then have you got subject lines or URIs to that?)
Quoted 6 lines
If we really need to merge dom0 support, then dom0 should have the own IOMMU implementation instead of adding any hacks to swiotlb (as I said long time ago). Yeah, there might be some duplication between swiotlb and the Xen IOMMU but IMO it's better to have clean code with some duplication rather than ugly unified code; unification makes sense only if we do cleanly.
Well, but since we merged PowerPC highmem support ... the precedent is there already that the swiotlb code can be librarized and generalized some more, right?
What is the fundamental difference between a DMA32 device on native hardware using lib/swiotlb.c to bounce IO directed to/from a high address over buffers in a low, DMA-capable address, and between a Xen Dom0 instance using the same functionality to DMA buffers?
The payback is significant: Linux drivers can be used basically as-is (as far as their DMA functionality goes) in a Xen dom0 guest.
There's really just two non-standard Xen features compared to the PowerPC-highmem use:
- special allocation
- non-standard virtual/physical/bus memory translations
The latter is understandable - Xen cannot do the (mostly-) linear transformations that (most) platforms can do in their address transformation primitives. But other than the non-linearity, it's a "mapping" just as much.
The special allocator is arguably a bit of a hack - Xen should _probably_ recognize GFP_DMA32 allocations at the page allocator level and rearrange buffers there.
So realizing that dom0 _has_ to have guest OS help here, the best possible design seems to be to minimalize the Xen cross section to Linux, while still keeping it fast enough. And that seems to be these two straightforward hooks: 'ready buffers for DMA' and 'map addresses'. As long as we'll want to have swiotlb code in the kernel, we'll deal with such primitives anyway - so there doesnt seem to be a significant mainteinance drag here.
Hm?
Ingo
Quoted 10 lines · On Tue, 19 May 2009 15:03:00 +0200 Ingo Molnar <[email protected]> wrote:
Quoted 6 lines
If we really need to merge dom0 support, then dom0 should have the own IOMMU implementation instead of adding any hacks to swiotlb (as I said long time ago). Yeah, there might be some duplication between swiotlb and the Xen IOMMU but IMO it's better to have clean code with some duplication rather than ugly unified code; unification makes sense only if we do cleanly.
Well, but since we merged PowerPC highmem support ... the precedent is there already that the swiotlb code can be librarized and generalized some more, right?
No,
The highmem support is ok for me (I was against the initial highmem patchset but Becky's highmem patchset was much cleaner and we merged it).
Due to dom0 support, we can't use architecture abstraction (such as arch/include/asm/):
http://marc.info/?l=linux-kernel&m=124271086910299&w=2
We also need hacks for memory allocation due to dom0 support.
Quoted 24 lines
What is the fundamental difference between a DMA32 device on native hardware using
lib/swiotlb.cto bounce IO directed to/from a high address over buffers in a low, DMA-capable address, and between a Xen Dom0 instance using the same functionality to DMA buffers?The payback is significant: Linux drivers can be used basically as-is (as far as their DMA functionality goes) in a Xen dom0 guest.
There's really just two non-standard Xen features compared to the PowerPC-highmem use:
- special allocation
- non-standard virtual/physical/bus memory translations
The latter is understandable - Xen cannot do the (mostly-) linear transformations that (most) platforms can do in their address transformation primitives. But other than the non-linearity, it's a "mapping" just as much.
The special allocator is arguably a bit of a hack - Xen should _probably_ recognize
GFP_DMA32allocations at the page allocator level and rearrange buffers there.
Quoted 7 lines
So realizing that dom0 _has_ to have guest OS help here, the best possible design seems to be to minimalize the Xen cross section to Linux, while still keeping it fast enough. And that seems to be these two straightforward hooks: 'ready buffers for DMA' and 'map addresses'. As long as we'll want to have swiotlb code in the kernel, we'll deal with such primitives anyway - so there doesnt seem to be a significant mainteinance drag here.
We need these hooks but as I wrote above, they are architecture-specific and we should handle them with the architecture abstraction (as we handle similar problems) however we can't due to dom0 support.
Quoted 5 lines · FUJITA Tomonori
We need these hooks but as I wrote above, they are architecture-specific and we should handle them with the architecture abstraction (as we handle similar problems) however we can't due to dom0 support.
I don't understand this. What exactly about the dom0 support patch prevents future abstraction here?
The dom0 hooks would simply move into the per-arch abstractions as appropriate, wouldn't they?
Ian.
Signature · 5 lines
Ian Campbell Current Noise: Mondo Generator - Simple Exploding Man "We are on the verge: Today our program proved Fermat's next-to-last theorem." -- Epigrams in Programming, ACM SIGPLAN Sept. 1982
Quoted 8 lines · Ian Campbell
Quoted 5 lines · FUJITA Tomonori
We need these hooks but as I wrote above, they are architecture-specific and we should handle them with the architecture abstraction (as we handle similar problems) however we can't due to dom0 support.
Quoted 5 lines
I don't understand this. What exactly about the dom0 support patch prevents future abstraction here?
The dom0 hooks would simply move into the per-arch abstractions as appropriate, wouldn't they?
Fujita-san's suggestion to me was that swiotlb could just use the normal (albeit deprecated) phys_to_bus()/bus_to_phys() interfaces rather than defining its own. That would be perfectly OK for Xen; we have a single global translation which is unaffected by the target device, etc.
But I'm not sure it would work for powerpc; Becky's patches which added swiotlb_bus_to_phys/phys_bus made them take a device argument, because (apparently) the bus/phys offset can differ on a per-device or per-bus basis. The powerpc side of swiotlb doesn't seem to be in mainline yet, so I'm not sure what the details are here (maybe it can be handled with a single big runtime switch, if the offset is always constant on a given machine).
(Hm, now that I look I see that they're defined as virt_to_bus/bus_to_virt, which doesn't work for highmem at all; it would need to be phys.)
But I may have misinterpreted what he meant.
J
Quoted 28 lines · On Wed, 20 May 2009 10:06:13 -0700 Jeremy Fitzhardinge <[email protected]> wrote:
Quoted 8 lines · Ian Campbell
Quoted 5 lines · FUJITA Tomonori
We need these hooks but as I wrote above, they are architecture-specific and we should handle them with the architecture abstraction (as we handle similar problems) however we can't due to dom0 support.
Quoted 5 lines
I don't understand this. What exactly about the dom0 support patch prevents future abstraction here?
The dom0 hooks would simply move into the per-arch abstractions as appropriate, wouldn't they?
Fujita-san's suggestion to me was that swiotlb could just use the normal (albeit deprecated) phys_to_bus()/bus_to_phys() interfaces rather than defining its own. That would be perfectly OK for Xen; we have a single global translation which is unaffected by the target device, etc.
But I'm not sure it would work for powerpc; Becky's patches which added swiotlb_bus_to_phys/phys_bus made them take a device argument, because (apparently) the bus/phys offset can differ on a per-device or per-bus basis. The powerpc side of swiotlb doesn't seem to be in mainline yet, so I'm not sure what the details are here (maybe it can be handled with a single big runtime switch, if the offset is always constant on a given machine).
Quoted 5 lines
(Hm, now that I look I see that they're defined as virt_to_bus/bus_to_virt, which doesn't work for highmem at all; it would need to be phys.)
But I may have misinterpreted what he meant.
What I want to remove all the __weak hacks and use the architecture abstraction. For example, the following patch is killing swiotlb_arch_address_needs_mapping() and swiotlb_arch_range_needs_mapping().
As you said, POWERPC needs a pair of conversion functions between phys and bus. I want to use arch/*/include/ for it in the same way.
=
From: FUJITA Tomonori <[email protected]>
Subject: [PATCH] make is_buffer_dma_capable architecture-specific
This moves is_buffer_dma_capable() from include/linux/dma-mapping.h to arch/*/include/asm/dma-mapping.h because it's architecture-specific; we shouldn't have added it in the generic place.
This function is used only in swiotlb (supported by x86 and IA64, and POWERPC shortly).
POWERPC needs struct device to see if an address is DMA-capable or not. How POWERPC implements is_buffer_dma_capable() is still under discussion. So this patch doesn't add POWERPC's one.
--- arch/ia64/include/asm/dma-mapping.h | 6 +++++ arch/x86/include/asm/dma-mapping.h | 6 +++++ arch/x86/kernel/pci-dma.c | 2 +- arch/x86/kernel/pci-gart_64.c | 4 +- arch/x86/kernel/pci-nommu.c | 2 +- include/linux/dma-mapping.h | 5 ---- lib/swiotlb.c | 39 +++++++--------------------------- 7 files changed, 24 insertions(+), 40 deletions(-)
arch/ia64/include/asm/dma-mapping.h +6 -0
@@ -174,4 +174,10 @@ dma_cache_sync (struct device *dev, void *vaddr, size_t size,#define dma_is_consistent (d, h) (1)/* all we do is coherent memory... */ +static inline int is_buffer_dma_capable (struct device *dev,u64 mask, +dma_addr_t addr,size_t size) +{ +return addr + size <= mask; +} +#endif /* _ASM_IA64_DMA_MAPPING_H */
arch/x86/include/asm/dma-mapping.h +6 -0
@@ -309,4 +309,10 @@ static inline void dma_free_coherent(struct device *dev, size_t size, ops->free_coherent(dev, size, vaddr, bus); } +static inline int is_buffer_dma_capable (struct device *dev,u64 mask, +dma_addr_t addr,size_t size) +{ +return addr + size <= mask; +} +#endif
arch/x86/kernel/pci-dma.c +1 -1
@@ -145,7 +145,7 @@ again:return NULL ; addr =page_to_phys (page); -if (!is_buffer_dma_capable (dma_mask, addr, size)) { +if (!is_buffer_dma_capable (dev, dma_mask, addr, size)) {__free_pages (page,get_order (size));if (dma_mask <DMA_BIT_MASK (32 ) && !(flag &GFP_DMA )) {
arch/x86/kernel/pci-gart_64.c +2 -2
@@ -191,13 +191,13 @@ static inline int need_iommu(struct device *dev, unsigned long addr, size_t size) { return force_iommu || - !is_buffer_dma_capable(*dev->dma_mask, addr, size); + !is_buffer_dma_capable(dev, *dev->dma_mask, addr, size); }static inline int nonforced_iommu (struct device *dev,unsigned long addr,size_t size) { -return !is_buffer_dma_capable (*dev->dma_mask, addr, size); +return !is_buffer_dma_capable (dev, *dev->dma_mask, addr, size); }/* Map a single continuous physical area into the IOMMU.
arch/x86/kernel/pci-nommu.c +1 -1
@@ -14,7 +14,7 @@static int check_addr (char *name,struct device *hwdev,dma_addr_t bus,size_t size) { -if (hwdev && !is_buffer_dma_capable (*hwdev->dma_mask, bus, size)) { +if (hwdev && !is_buffer_dma_capable (hwdev, *hwdev->dma_mask, bus, size)) {if (*hwdev->dma_mask >=DMA_BIT_MASK (32 )) printk(KERN_ERR "nommu_%s: overflow %Lx+%zu of device mask %Lx\n",
include/linux/dma-mapping.h +0 -5
@@ -96,11 +96,6 @@ static inline int is_device_dma_capable(struct device *dev)return dev->dma_mask !=NULL && *dev->dma_mask !=DMA_MASK_NONE ; } -static inline int is_buffer_dma_capable (u64 mask,dma_addr_t addr,size_t size) -{ -return addr + size <= mask; -} -#ifdef CONFIG_HAS_DMA #include <asm/dma-mapping.h> #else
lib/swiotlb.c +8 -31
@@ -145,17 +145,6 @@ void * __weak swiotlb_bus_to_virt(struct device *hwdev, dma_addr_t address)return phys_to_virt (swiotlb_bus_to_phys (hwdev, address)); } -int __weak swiotlb_arch_address_needs_mapping (struct device *hwdev, -dma_addr_t addr,size_t size) -{ -return !is_buffer_dma_capable (dma_get_mask (hwdev), addr, size); -} - -int __weak swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size) -{ -return 0 ; -} -static void swiotlb_print_info (unsigned long bytes) {phys_addr_t pstart, pend;
@@ -315,17 +304,6 @@ cleanup1:return -ENOMEM ; } -static inline int -address_needs_mapping (struct device *hwdev,dma_addr_t addr,size_t size) -{ -return swiotlb_arch_address_needs_mapping (hwdev, addr, size); -} - -static inline int range_needs_mapping (phys_addr_t paddr,size_t size) -{ -return swiotlb_force ||swiotlb_arch_range_needs_mapping (paddr, size); -} -static int is_swiotlb_buffer (char *addr) {return addr >= io_tlb_start && addr < io_tlb_end;
@@ -561,9 +539,8 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, dma_mask = hwdev->coherent_dma_mask; ret = (void *)__get_free_pages (flags, order); -if (ret && - !is_buffer_dma_capable (dma_mask,swiotlb_virt_to_bus (hwdev, ret), - size)) { +if (ret && !is_buffer_dma_capable (hwdev, dma_mask, +swiotlb_virt_to_bus (hwdev, ret), size)) {/* * The allocated memory isn't reachable by the device. */
@@ -585,7 +562,7 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, dev_addr =swiotlb_virt_to_bus (hwdev, ret);/* Confirm address can be DMA'd by device */ -if (!is_buffer_dma_capable (dma_mask, dev_addr, size)) { +if (!is_buffer_dma_capable (hwdev, dma_mask, dev_addr, size)) {printk ("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , (unsigned long long )dma_mask, (unsigned long long )dev_addr);
@@ -655,8 +632,8 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,* we can safely return the device addr and not worry about bounce * buffering it. */ -if (!address_needs_mapping (dev, dev_addr, size) && - !range_needs_mapping (phys, size)) +if (is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size) && + !swiotlb_force)return dev_addr;/*
@@ -673,7 +650,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,/* * Ensure that the address returned is DMA'ble */ -if (address_needs_mapping (dev, dev_addr, size)) +if (!is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size))panic ("map_single: bounce buffer is not DMA'ble" );return dev_addr;
@@ -819,8 +796,8 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,phys_addr_t paddr =sg_phys (sg);dma_addr_t dev_addr =swiotlb_phys_to_bus (hwdev, paddr); -if (range_needs_mapping (paddr, sg->length) || -address_needs_mapping (hwdev, dev_addr, sg->length)) { +if (!is_buffer_dma_capable (hwdev,dma_get_mask (hwdev), paddr, sg->length) || + swiotlb_force) {void *map =map_single (hwdev,sg_phys (sg), sg->length, dir);if (!map) {
Signature · 1 line
1.6.0.6
Quoted 5 lines · FUJITA Tomonori
What I want to remove all the
__weakhacks and use the architecture abstraction. For example, the following patch is killingswiotlb_arch_address_needs_mapping()andswiotlb_arch_range_needs_mapping().
I think the swiotlb_arch_address_needs_mapping()/is_buffer_dma_capable() aspects of this are fine from the Xen POV but a hook along the lines of swiotlb_arch_range_needs_mapping() is unfortunately still required to handle potential discontigousness in multipage buffers. There's no reason this can't be handled in a similar way though. e.g. the following updated patch is based on yours but also moves the swiotlb_range_needs mapping hook to dma-mapping.h. The corresponding the Xen updates will.
Subject: swiotlb: is_buffer_dma_capable and swiotlb_range_needs_mapping are arch-specific
This moves is_buffer_dma_capable() from include/linux/dma-mapping.h to arch/*/include/asm/dma-mapping.h because it's architecture-specific; we shouldn't have added it in the generic place.
This function is used only in swiotlb (supported by x86 and IA64, and POWERPC shortly).
POWERPC needs struct device to see if an address is DMA-capable or not. How POWERPC implements is_buffer_dma_capable() is still under discussion. So this patch doesn't add POWERPC's one.
The range_needs_mapping hook is needed by Xen PCI to support multipage buffers which are potentially discontiguous in the DMA address space.
Based on original patch by FUJITA Tomonori.
arch/ia64/include/asm/dma-mapping.h +11 -0
@@ -174,4 +174,15 @@ dma_cache_sync (struct device *dev, void *vaddr, size_t size,#define dma_is_consistent (d, h) (1)/* all we do is coherent memory... */ +static inline int is_buffer_dma_capable (struct device *dev,u64 mask, +dma_addr_t addr,size_t size) +{ +return addr + size <= mask; +} + +static int inline swiotlb_range_needs_mapping (phys_addr_t paddr,size_t size) +{ +return 0 ; +} +#endif /* _ASM_IA64_DMA_MAPPING_H */
arch/x86/include/asm/dma-mapping.h +11 -0
@@ -309,4 +309,15 @@ static inline void dma_free_coherent(struct device *dev, size_t size, ops->free_coherent(dev, size, vaddr, bus); } +static inline int is_buffer_dma_capable (struct device *dev,u64 mask, +dma_addr_t addr,size_t size) +{ +return addr + size <= mask; +} + +static int inline swiotlb_range_needs_mapping (phys_addr_t paddr,size_t size) +{ +return 0 ; +} +#endif
arch/x86/kernel/pci-dma.c +1 -1
@@ -146,7 +146,7 @@ again:return NULL ; addr =page_to_phys (page); -if (!is_buffer_dma_capable (dma_mask, addr, size)) { +if (!is_buffer_dma_capable (dev, dma_mask, addr, size)) {__free_pages (page,get_order (size));if (dma_mask <DMA_BIT_MASK (32 ) && !(flag &GFP_DMA )) {
arch/x86/kernel/pci-gart_64.c +2 -2
@@ -191,13 +191,13 @@ static inline int need_iommu(struct device *dev, unsigned long addr, size_t size) { return force_iommu || - !is_buffer_dma_capable(*dev->dma_mask, addr, size); + !is_buffer_dma_capable(dev, *dev->dma_mask, addr, size); }static inline int nonforced_iommu (struct device *dev,unsigned long addr,size_t size) { -return !is_buffer_dma_capable (*dev->dma_mask, addr, size); +return !is_buffer_dma_capable (dev, *dev->dma_mask, addr, size); }/* Map a single continuous physical area into the IOMMU.
arch/x86/kernel/pci-nommu.c +1 -1
@@ -14,7 +14,7 @@static int check_addr (char *name,struct device *hwdev,dma_addr_t bus,size_t size) { -if (hwdev && !is_buffer_dma_capable (*hwdev->dma_mask, bus, size)) { +if (hwdev && !is_buffer_dma_capable (hwdev, *hwdev->dma_mask, bus, size)) {if (*hwdev->dma_mask >=DMA_BIT_MASK (32 )) printk(KERN_ERR "nommu_%s: overflow %Lx+%zu of device mask %Lx\n",
include/linux/dma-mapping.h +0 -5
@@ -96,11 +96,6 @@ static inline int is_device_dma_capable(struct device *dev)return dev->dma_mask !=NULL && *dev->dma_mask !=DMA_MASK_NONE ; } -static inline int is_buffer_dma_capable (u64 mask,dma_addr_t addr,size_t size) -{ -return addr + size <= mask; -} -#ifdef CONFIG_HAS_DMA #include <asm/dma-mapping.h> #else
include/linux/swiotlb.h +0 -2
@@ -32,8 +32,6 @@ extern dma_addr_t swiotlb_phys_to_bus(struct device *hwdev,extern phys_addr_t swiotlb_bus_to_phys (struct device *hwdev,dma_addr_t address); -extern int swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size); -extern void *swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags);
lib/swiotlb.c +7 -25
@@ -147,17 +147,6 @@ void * __weak swiotlb_bus_to_virt(struct device *hwdev, dma_addr_t address)return phys_to_virt (swiotlb_bus_to_phys (hwdev, address)); } -int __weak swiotlb_arch_address_needs_mapping (struct device *hwdev, -dma_addr_t addr,size_t size) -{ -return !is_buffer_dma_capable (dma_get_mask (hwdev), addr, size); -} - -int __weak swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size) -{ -return 0 ; -} -static void swiotlb_print_info (unsigned long bytes) {phys_addr_t pstart, pend;
@@ -318,15 +307,9 @@ cleanup1:return -ENOMEM ; } -static inline int -address_needs_mapping (struct device *hwdev,dma_addr_t addr,size_t size) -{ -return swiotlb_arch_address_needs_mapping (hwdev, addr, size); -} -static inline int range_needs_mapping (phys_addr_t paddr,size_t size) { -return swiotlb_force ||swiotlb_arch_range_needs_mapping (paddr, size); +return swiotlb_force ||swiotlb_range_needs_mapping (paddr, size); }static int is_swiotlb_buffer (char *addr)
@@ -564,9 +547,8 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, dma_mask = hwdev->coherent_dma_mask; ret = (void *)__get_free_pages (flags, order); -if (ret && - !is_buffer_dma_capable (dma_mask,swiotlb_virt_to_bus (hwdev, ret), - size)) { +if (ret && !is_buffer_dma_capable (hwdev, dma_mask, +swiotlb_virt_to_bus (hwdev, ret), size)) {/* * The allocated memory isn't reachable by the device. */
@@ -588,7 +570,7 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, dev_addr =swiotlb_virt_to_bus (hwdev, ret);/* Confirm address can be DMA'd by device */ -if (!is_buffer_dma_capable (dma_mask, dev_addr, size)) { +if (!is_buffer_dma_capable (hwdev, dma_mask, dev_addr, size)) {printk ("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , (unsigned long long )dma_mask, (unsigned long long )dev_addr);
@@ -658,7 +640,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,* we can safely return the device addr and not worry about bounce * buffering it. */ -if (!address_needs_mapping (dev, dev_addr, size) && +if (is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size) && !range_needs_mapping (phys, size))return dev_addr;
@@ -676,7 +658,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,/* * Ensure that the address returned is DMA'ble */ -if (address_needs_mapping (dev, dev_addr, size)) +if (!is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size))panic ("map_single: bounce buffer is not DMA'ble" );return dev_addr;
@@ -823,7 +805,7 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,dma_addr_t dev_addr =swiotlb_phys_to_bus (hwdev, paddr);if (range_needs_mapping (paddr, sg->length) || -address_needs_mapping (hwdev, dev_addr, sg->length)) { + !is_buffer_dma_capable (hwdev,dma_get_mask (hwdev), dev_addr, sg->length)) {void *map =map_single (hwdev,sg_phys (sg), sg->length, dir);if (!map) {
Signature · 4 lines
Ian Campbell Current Noise: Dark Fortress - Edge Of Night Yow! Is this sexual intercourse yet?? Is it, huh, is it??
Quoted 1 line · Ian Campbell
The corresponding the Xen updates will...
...follow.
Subject:swiotlb/xen: add implementation of swiotlb_range_needs_mapping hook
This function is now implemented via asm/dma-mapping.h rather than as a weak hook in swiotlb.c
arch/x86/include/asm/dma-mapping.h +7 -1
@@ -315,9 +315,15 @@ static inline int is_buffer_dma_capable(struct device *dev, u64 mask, return addr + size <= mask; } +#ifdef CONFIG_PCI_XEN +extern int xen_range_needs_mapping (phys_addr_t paddr,size_t size); +#else +static inline int xen_range_needs_mapping (phys_addr_t paddr,size_t size) {return 0 ; } +#endif +static int inline swiotlb_range_needs_mapping (phys_addr_t paddr,size_t size) { -return 0 ; +return xen_range_needs_mapping (paddr, size); }#endif
arch/x86/xen/pci-swiotlb.c +0 -8
@@ -43,11 +43,3 @@ phys_addr_t swiotlb_bus_to_phys(struct device *hwdev, dma_addr_t baddr)return baddr; } - -int swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size) -{ -if (xen_pv_domain ()) -return xen_range_needs_mapping (paddr, size); - -return 0 ; -}
drivers/pci/xen-iommu.c +2 -0
@@ -132,6 +132,8 @@ static int range_straddles_page_boundary(phys_addr_t p, size_t size)int xen_range_needs_mapping (phys_addr_t paddr,size_t size) { +if (!xen_pv_domain ()) +return 0 ;return range_straddles_page_boundary (paddr, size); }
Signature · 6 lines
Ian Campbell Current Noise: Isis - Wills Dissolve "Hey Ivan, check your six." -- Sidewinder missile jacket patch, showing a Sidewinder driving up the tail of a Russian Su-27
Quoted 16 lines · On Thu, 21 May 2009 11:28:53 +0100 Ian Campbell <[email protected]> wrote:
Quoted 1 line · Ian Campbell
The corresponding the Xen updates will...
...follow.
Subject:swiotlb/xen: add implementation of
swiotlb_range_needs_mappinghookThis function is now implemented via
asm/dma-mapping.hrather than as a weak hook inswiotlb.cSigned-off-by Ian Campbell <[email protected]>arch/x86/include/asm/dma-mapping.h +0
-0
arch/x86/include/asm/dma-mapping.h static inline int is_buffer_dma_capable(struct device *dev, u64 mask, · line 322
Quoted 8 lines
arch/x86/include/asm/dma-mapping.h +5
-0@@ -315,9 +315,15 @@ static inline int is_buffer_dma_capable(struct device *dev, u64 mask,return addr + size <= mask; } +#ifdef CONFIG_PCI_XEN +extern int xen_range_needs_mapping (phys_addr_t paddr,size_t size); +#else +static inline int xen_range_needs_mapping (phys_addr_t paddr,size_t size) {return 0 ; } +#endif
I know Xen can do something like this but you think that this is clean?
In addition, you also the similar hack in arch/ia64/include/asm/dma-mapping.h for ia64's dom0 support, I think.
IMO, your patch just moves the ugly hacks from lib/swiotlb.c to arch/{x86|ia64}/include/asm/dma-mapping.h.
lib/swiotlb.c swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems, · line 803
Quoted 11 lines · FUJITA Tomonori
lib/swiotlb.c +2
-2@@ -819,8 +796,8 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,phys_addr_t paddr =sg_phys (sg);dma_addr_t dev_addr =swiotlb_phys_to_bus (hwdev, paddr); -if (range_needs_mapping (paddr, sg->length) || -address_needs_mapping (hwdev, dev_addr, sg->length)) { +if (!is_buffer_dma_capable (hwdev,dma_get_mask (hwdev), paddr, sg->length) || + swiotlb_force) {void *map =map_single (hwdev,sg_phys (sg), sg->length, dir);if (!map) {
BTW I think there was a typo here, dev_addr becomes paddr. I fixed that in my updated version.
Ian.
Signature · 7 lines
Ian Campbell Current Noise: Isis - In Fiction Poorochrondria: Hypochrondria derived from not having medical insurance. -- Douglas Coupland, "Generation X: Tales for an Accelerated Culture"
Quoted 11 lines · FUJITA Tomonori
arch/x86/include/asm/dma-mapping.h static inline int is_buffer_dma_capable(struct device *dev, u64 mask, · line 322
Quoted 5 lines · On Thu, 21 May 2009 11:28:53 +0100 Ian Campbell <[email protected]> wrote:
arch/x86/include/asm/dma-mapping.h +5
-0+#ifdef CONFIG_PCI_XEN +extern int xen_range_needs_mapping (phys_addr_t paddr,size_t size); +#else +static inline int xen_range_needs_mapping (phys_addr_t paddr,size_t size) {return 0 ; } +#endif I know Xen can do something like this but you think that this is clean?
Well, defining a static inline function when a CONFIG option is disabled is fairly idiomatic in the kernel and in general hiding these sorts of things in the headers in this way is preferred to having them in .c files. See e.g. the handling of CONFIG_PRINTK in include/linux/kernel.h or CONFIG_HIGHMEM in include/linux/highmem.h for just two examples out of many.
Quoted 5 lines
In addition, you also the similar hack in
arch/ia64/include/asm/dma-mapping.hfor ia64's dom0 support, I think.IMO, your patch just moves the ugly hacks from
lib/swiotlb.cto arch/{x86|ia64}/include/asm/dma-mapping.h.
I nearly suggested that for this hook it might actually be preferable to put the one line Xen hook directly into swiotlb.c. I didn't think this suggestion would go down very well though.
In any case something along these lines needs to go somewhere. I think you are slightly mischaracterising this as an "ugly hack" -- it is a necessary interface to enable a particular use-case, and it actually has a very small cross section (it's basically five or six lines of code).
If there was a cleaner way to achieve the same result we would of course go with that. I don't think duplicating swiotlb.c, as has been suggested as the alternative, just for that one hook point makes sense.
Ian.
Signature · 6 lines
Ian Campbell Current Noise: Isis - Altered Course "For a male and female to live continuously together is... biologically speaking, an extremely unnatural condition." -- Robert Briffault
Quoted 12 lines · Ian Campbell
Quoted 5 lines · FUJITA Tomonori
Review
Quoted 2 lines · On Thu, 21 May 2009 11:28:53 +0100 Ian Campbell <[email protected]> wrote:
(quoted diff) +2
-0+#ifdef CONFIG_PCI_XEN +extern int xen_range_needs_mapping(phys_addr_t paddr, size_tsize);
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#else +static inline int xen_range_needs_mapping(phys_addr_t paddr,
size_tsize) { return 0; }Quoted 2 lines
Quoted 1 line
+#endif
Quoted 7 lines
Quoted 2 lines
I know Xen can do something like this but you think that this is clean?
Well, defining a static inline function when a CONFIG option is disabled is fairly idiomatic in the kernel and in general hiding these sorts of things in the headers in this way is preferred to having them in .c files.
Although I do concede that the function definition would probably be better placed in a xen specific header.
Ian.
Quoted 13 lines · On Thu, 21 May 2009 12:03:05 +0100 Ian Campbell <[email protected]> wrote:
Quoted 11 lines · FUJITA Tomonori
arch/x86/include/asm/dma-mapping.h static inline int is_buffer_dma_capable(struct device *dev, u64 mask, · line 322
Quoted 5 lines · On Thu, 21 May 2009 11:28:53 +0100 Ian Campbell <[email protected]> wrote:
arch/x86/include/asm/dma-mapping.h +5
-0+#ifdef CONFIG_PCI_XEN +extern int xen_range_needs_mapping (phys_addr_t paddr,size_t size); +#else +static inline int xen_range_needs_mapping (phys_addr_t paddr,size_t size) {return 0 ; } +#endif I know Xen can do something like this but you think that this is clean?
Quoted 6 lines
Well, defining a static inline function when a CONFIG option is disabled is fairly idiomatic in the kernel and in general hiding these sorts of things in the headers in this way is preferred to having them in .c files. See e.g. the handling of
CONFIG_PRINTKininclude/linux/kernel.horCONFIG_HIGHMEMininclude/linux/highmem.hfor just two examples out of many.
Well, I know that it's idiomatic, but placing CONFIG_PCI_XEN in arch/{x86|ia64}/include/asm/ is a wrong abstraction to me.
Quoted 9 lines
Quoted 5 lines
In addition, you also the similar hack in
arch/ia64/include/asm/dma-mapping.hfor ia64's dom0 support, I think.IMO, your patch just moves the ugly hacks from
lib/swiotlb.cto arch/{x86|ia64}/include/asm/dma-mapping.h.I nearly suggested that for this hook it might actually be preferable to put the one line Xen hook directly into
swiotlb.c. I didn't think this suggestion would go down very well though.
Any arch or Xen specific code should not live in swiotlb.c
Quoted 4 lines
In any case something along these lines needs to go somewhere. I think you are slightly mischaracterising this as an "ugly hack" -- it is a necessary interface to enable a particular use-case, and it actually has a very small cross section (it's basically five or six lines of code).
A necessary interface? Sorry, I don't buy it. It's necessary for only Xen. And it's not fit well for swiotlb and the architecture abstraction.
Quoted 3 lines
If there was a cleaner way to achieve the same result we would of course go with that. I don't think duplicating
swiotlb.c, as has been suggested as the alternative, just for that one hook point makes sense.
One hook? You need to reread swiotlb.c. There are more. All should go.
Quoted 23 lines · FUJITA Tomonori
Quoted 13 lines · On Thu, 21 May 2009 12:03:05 +0100 Ian Campbell <[email protected]> wrote:
Quoted 11 lines · FUJITA Tomonori
arch/x86/include/asm/dma-mapping.h static inline int is_buffer_dma_capable(struct device *dev, u64 mask, · line 322
Quoted 5 lines · On Thu, 21 May 2009 11:28:53 +0100 Ian Campbell <[email protected]> wrote:
arch/x86/include/asm/dma-mapping.h +5
-0+#ifdef CONFIG_PCI_XEN +extern int xen_range_needs_mapping (phys_addr_t paddr,size_t size); +#else +static inline int xen_range_needs_mapping (phys_addr_t paddr,size_t size) {return 0 ; } +#endif I know Xen can do something like this but you think that this is clean?
Quoted 6 lines
Well, defining a static inline function when a CONFIG option is disabled is fairly idiomatic in the kernel and in general hiding these sorts of things in the headers in this way is preferred to having them in .c files. See e.g. the handling of
CONFIG_PRINTKininclude/linux/kernel.horCONFIG_HIGHMEMininclude/linux/highmem.hfor just two examples out of many.
Quoted 2 lines
Well, I know that it's idiomatic, but placing
CONFIG_PCI_XENin arch/{x86|ia64}/include/asm/ is a wrong abstraction to me.
Agreed, include/xen/swiotlb.h is the right place for it.
Quoted 11 lines
Quoted 9 lines
Quoted 5 lines
In addition, you also the similar hack in
arch/ia64/include/asm/dma-mapping.hfor ia64's dom0 support, I think.IMO, your patch just moves the ugly hacks from
lib/swiotlb.cto arch/{x86|ia64}/include/asm/dma-mapping.h.I nearly suggested that for this hook it might actually be preferable to put the one line Xen hook directly into
swiotlb.c. I didn't think this suggestion would go down very well though.Any arch or Xen specific code should not live in
swiotlb.c
Again agreed, which is why I didn't suggest it ;-)
Quoted 10 lines
Quoted 4 lines
In any case something along these lines needs to go somewhere. I think you are slightly mischaracterising this as an "ugly hack" -- it is a necessary interface to enable a particular use-case, and it actually has a very small cross section (it's basically five or six lines of code).
A necessary interface? Sorry, I don't buy it. It's necessary for only Xen. And it's not fit well for swiotlb and the architecture abstraction.
I said "necessary interface to enable a particular use-case". Xen is a valid use case -- I appreciate that you personally may have no interest in it but plenty of people do and plenty of people would like to see it working in the mainline kernels.
In terms of clean abstraction this is a architecture hook to allow mappings to be forced through the swiotlb. It is essentially a more flexible extension to the existing swiotlb_force flag, in fact swiotlb_force_mapping() might even be a better name for it.
IMHO, the benefits here (working Xen domain 0 plus PCI passthrough to guest domains) are well worth the costs.
Quoted 5 lines
Quoted 3 lines
If there was a cleaner way to achieve the same result we would of course go with that. I don't think duplicating
swiotlb.c, as has been suggested as the alternative, just for that one hook point makes sense.One hook? You need to reread
swiotlb.c. There are more. All should go.
I meant that swiotlb_range_needs_mapping is the single contentious hook as far as I can tell. It is the only one which you appear to be disputing the very existence of (irrespective of whether it uses __weak or is moved into asm/dma-mapping.h). The other existing __weak hooks are useful to other users too and all can, AFAICT, be moved into asm/dma-mapping.h.
You have already dealt with moving swiotlb_address_needs_mapping and I am currently looking into the the phys_to_bus and bus_to_phys ones. That just leaves the alloc functions, which are next on my list after phys_to_bus and bus_to_phys. Will finishing up those patches resolve most of your objections are do you have others?
Ian.
Signature · 3 lines
Ian Campbell This supersedes all previous notices.
swiotlb: remove __weak hooks in favour of architecture-specific functions
At the end of this series there are no more __weak functions in lib/swiotlb.c
The series adds several hook functions to the x86 architecture. Would they be preferred as a struct x86_swiotlb_ops or as individual hooks?
I was unsure what to do about powerpc in most places since the existing support seems to in-progress so it wasn't always clear where to put the implementation. If there is a tree somewhere with more complete support I'll be happy to provide additional patches.
Boot tested on x86 under xen but not even compiled for ia64 or powerpc. If someone can point me to a decent source of cross compilers I can sort that out. (http://www.kernel.org/pub/tools/crosstool/ seems to be out-of-date and only has ia64 in any case)
---
arch/ia64/include/asm/dma-mapping.h | 29 ++++++++++++++ arch/ia64/kernel/pci-swiotlb.c | 11 +++++ arch/powerpc/include/asm/dma-mapping.h | 5 ++ arch/x86/include/asm/agp.h | 4 +- arch/x86/include/asm/dma-mapping.h | 34 +++++++++++++++++ arch/x86/include/asm/xen/iommu.h | 4 ++ arch/x86/kernel/pci-dma.c | 6 ++- arch/x86/kernel/pci-gart_64.c | 4 +- arch/x86/kernel/pci-nommu.c | 3 +- arch/x86/kernel/pci-swiotlb.c | 32 ++++++++++++++++ arch/x86/xen/Makefile | 3 +- arch/x86/xen/pci-swiotlb.c | 53 -------------------------- drivers/pci/xen-iommu.c | 20 ++++++++-- include/linux/dma-mapping.h | 5 -- include/linux/swiotlb.h | 10 ----- include/xen/swiotlb.h | 5 -- lib/swiotlb.c | 64 +++++++------------------------- 17 files changed, 156 insertions(+), 136 deletions(-)
PATCH 1/1 swiotlb: make is_buffer_dma_capable architecture-specific
In reply to Ian CampbellThis moves is_buffer_dma_capable() from include/linux/dma-mapping.h to arch/*/include/asm/dma-mapping.h because it's architecture-specific; we shouldn't have added it in the generic place.
This function is used only in swiotlb (supported by x86 and IA64, and POWERPC shortly).
POWERPC needs struct device to see if an address is DMA-capable or not. How POWERPC implements is_buffer_dma_capable() is still under discussion. So this patch doesn't add POWERPC's one.
Based on original patch by FUJITA Tomonori.
--- arch/ia64/include/asm/dma-mapping.h | 6 ++++++ arch/x86/include/asm/dma-mapping.h | 6 ++++++ arch/x86/kernel/pci-dma.c | 2 +- arch/x86/kernel/pci-gart_64.c | 4 ++-- arch/x86/kernel/pci-nommu.c | 3 ++- include/linux/dma-mapping.h | 5 ----- lib/swiotlb.c | 25 +++++++------------------ 7 files changed, 24 insertions(+), 27 deletions(-)
arch/ia64/include/asm/dma-mapping.h +6 -0
@@ -174,4 +174,10 @@ dma_cache_sync (struct device *dev, void *vaddr, size_t size,#define dma_is_consistent (d, h) (1)/* all we do is coherent memory... */ +static inline int is_buffer_dma_capable (struct device *dev,u64 mask, +dma_addr_t addr,size_t size) +{ +return addr + size <= mask; +} +#endif /* _ASM_IA64_DMA_MAPPING_H */
arch/x86/include/asm/dma-mapping.h +6 -0
@@ -309,4 +309,10 @@ static inline void dma_free_coherent(struct device *dev, size_t size, ops->free_coherent(dev, size, vaddr, bus); } +static inline int is_buffer_dma_capable (struct device *dev,u64 mask, +dma_addr_t addr,size_t size) +{ +return addr + size <= mask; +} +#endif
arch/x86/kernel/pci-dma.c +1 -1
@@ -146,7 +146,7 @@ again:return NULL ; addr =page_to_phys (page); -if (!is_buffer_dma_capable (dma_mask, addr, size)) { +if (!is_buffer_dma_capable (dev, dma_mask, addr, size)) {__free_pages (page,get_order (size));if (dma_mask <DMA_BIT_MASK (32 ) && !(flag &GFP_DMA )) {
arch/x86/kernel/pci-gart_64.c +2 -2
@@ -191,13 +191,13 @@ static inline int need_iommu(struct device *dev, unsigned long addr, size_t size) { return force_iommu || - !is_buffer_dma_capable(*dev->dma_mask, addr, size); + !is_buffer_dma_capable(dev, *dev->dma_mask, addr, size); }static inline int nonforced_iommu (struct device *dev,unsigned long addr,size_t size) { -return !is_buffer_dma_capable (*dev->dma_mask, addr, size); +return !is_buffer_dma_capable (dev, *dev->dma_mask, addr, size); }/* Map a single continuous physical area into the IOMMU.
arch/x86/kernel/pci-nommu.c +2 -1
@@ -14,7 +14,8 @@static int check_addr (char *name,struct device *hwdev,dma_addr_t bus,size_t size) { -if (hwdev && !is_buffer_dma_capable (*hwdev->dma_mask, bus, size)) { +if (hwdev && + !is_buffer_dma_capable (hwdev, *hwdev->dma_mask, bus, size)) {if (*hwdev->dma_mask >=DMA_BIT_MASK (32 )) printk(KERN_ERR "nommu_%s: overflow %Lx+%zu of device mask %Lx\n",
include/linux/dma-mapping.h +0 -5
@@ -96,11 +96,6 @@ static inline int is_device_dma_capable(struct device *dev)return dev->dma_mask !=NULL && *dev->dma_mask !=DMA_MASK_NONE ; } -static inline int is_buffer_dma_capable (u64 mask,dma_addr_t addr,size_t size) -{ -return addr + size <= mask; -} -#ifdef CONFIG_HAS_DMA #include <asm/dma-mapping.h> #else
lib/swiotlb.c +7 -18
@@ -147,12 +147,6 @@ void * __weak swiotlb_bus_to_virt(struct device *hwdev, dma_addr_t address)return phys_to_virt (swiotlb_bus_to_phys (hwdev, address)); } -int __weak swiotlb_arch_address_needs_mapping (struct device *hwdev, -dma_addr_t addr,size_t size) -{ -return !is_buffer_dma_capable (dma_get_mask (hwdev), addr, size); -} -int __weak swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size) {return 0 ;
@@ -318,12 +312,6 @@ cleanup1:return -ENOMEM ; } -static inline int -address_needs_mapping (struct device *hwdev,dma_addr_t addr,size_t size) -{ -return swiotlb_arch_address_needs_mapping (hwdev, addr, size); -} -static inline int range_needs_mapping (phys_addr_t paddr,size_t size) {return swiotlb_force ||swiotlb_arch_range_needs_mapping (paddr, size);
@@ -565,8 +553,8 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, ret = (void *)__get_free_pages (flags, order);if (ret && - !is_buffer_dma_capable (dma_mask,swiotlb_virt_to_bus (hwdev, ret), - size)) { + !is_buffer_dma_capable (hwdev, dma_mask, +swiotlb_virt_to_bus (hwdev, ret), size)) {/* * The allocated memory isn't reachable by the device. */
@@ -588,7 +576,7 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size, dev_addr =swiotlb_virt_to_bus (hwdev, ret);/* Confirm address can be DMA'd by device */ -if (!is_buffer_dma_capable (dma_mask, dev_addr, size)) { +if (!is_buffer_dma_capable (hwdev, dma_mask, dev_addr, size)) {printk ("hwdev DMA mask = 0x%016Lx, dev_addr = 0x%016Lx\n" , (unsigned long long )dma_mask, (unsigned long long )dev_addr);
@@ -658,7 +646,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,* we can safely return the device addr and not worry about bounce * buffering it. */ -if (!address_needs_mapping (dev, dev_addr, size) && +if (is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size) && !range_needs_mapping (phys, size))return dev_addr;
@@ -676,7 +664,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,/* * Ensure that the address returned is DMA'ble */ -if (address_needs_mapping (dev, dev_addr, size)) +if (!is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size))panic ("map_single: bounce buffer is not DMA'ble" );return dev_addr;
@@ -823,7 +811,8 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,dma_addr_t dev_addr =swiotlb_phys_to_bus (hwdev, paddr);if (range_needs_mapping (paddr, sg->length) || -address_needs_mapping (hwdev, dev_addr, sg->length)) { + !is_buffer_dma_capable (hwdev,dma_get_mask (hwdev), + dev_addr, sg->length)) {void *map =map_single (hwdev,sg_phys (sg), sg->length, dir);if (!map) {
Signature · 1 line
1.5.6.5
PATCH 1/1 swiotlb: make range_needs_mapping architecture-specific
In reply to Ian CampbellThis moves range_needs_mapping() from lib/swiotlb.c to arch/*/include/asm/dma-mapping.h and renames it swiotlb_arch_force_mapping() to more acurately reflect its usage.
--- arch/ia64/include/asm/dma-mapping.h | 5 +++++ arch/powerpc/include/asm/dma-mapping.h | 5 +++++ arch/x86/include/asm/dma-mapping.h | 9 +++++++++ arch/x86/kernel/pci-swiotlb.c | 2 ++ include/linux/swiotlb.h | 2 -- lib/swiotlb.c | 13 ++++--------- 6 files changed, 25 insertions(+), 11 deletions(-)
arch/ia64/include/asm/dma-mapping.h +5 -0
@@ -180,4 +180,9 @@ static inline int is_buffer_dma_capable(struct device *dev, u64 mask, return addr + size <= mask; } +static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +return 0 ; +} +#endif /* _ASM_IA64_DMA_MAPPING_H */
arch/powerpc/include/asm/dma-mapping.h +5 -0
@@ -429,5 +429,10 @@ static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,__dma_sync (vaddr, size, (int )direction); } +static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +return 0 ; +} +#endif /* __KERNEL__ */ #endif /* _ASM_DMA_MAPPING_H */
arch/x86/include/asm/dma-mapping.h +9 -0
@@ -315,4 +315,13 @@ static inline int is_buffer_dma_capable(struct device *dev, u64 mask, return addr + size <= mask; } +extern int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); + +static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +if (x86_swiotlb_force_mapping) +return x86_swiotlb_force_mapping (paddr, size); +return 0 ; +} +#endif
arch/x86/kernel/pci-swiotlb.c +2 -0
@@ -15,6 +15,8 @@int swiotlb__read_mostly ; +int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); +static void *x86_swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags) {
include/linux/swiotlb.h +0 -2
@@ -32,8 +32,6 @@ extern dma_addr_t swiotlb_phys_to_bus(struct device *hwdev,extern phys_addr_t swiotlb_bus_to_phys (struct device *hwdev,dma_addr_t address); -extern int swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size); -extern void *swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags);
lib/swiotlb.c +4 -9
@@ -147,11 +147,6 @@ void * __weak swiotlb_bus_to_virt(struct device *hwdev, dma_addr_t address)return phys_to_virt (swiotlb_bus_to_phys (hwdev, address)); } -int __weak swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size) -{ -return 0 ; -} -static void swiotlb_print_info (unsigned long bytes) {phys_addr_t pstart, pend;
@@ -312,9 +307,9 @@ cleanup1:return -ENOMEM ; } -static inline int range_needs_mapping (phys_addr_t paddr,size_t size) +static inline int force_mapping (phys_addr_t paddr,size_t size) { -return swiotlb_force ||swiotlb_arch_range_needs_mapping (paddr, size); +return swiotlb_force ||swiotlb_force_mapping (paddr, size); }static int is_swiotlb_buffer (char *addr)
@@ -647,7 +642,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,* buffering it. */ if (is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size) && - !range_needs_mapping (phys, size)) + !force_mapping (phys, size))return dev_addr;/*
@@ -810,7 +805,7 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,phys_addr_t paddr =sg_phys (sg);dma_addr_t dev_addr =swiotlb_phys_to_bus (hwdev, paddr); -if (range_needs_mapping (paddr, sg->length) || +if (force_mapping (paddr, sg->length) || !is_buffer_dma_capable (hwdev,dma_get_mask (hwdev), dev_addr, sg->length)) { void *map = map_single(hwdev, sg_phys(sg),
Signature · 1 line
1.5.6.5
PATCH 1/1 swiotlb/xen: update xen for swiotlb_arch_force_mapping changes
In reply to Ian CampbellThis function is now implemented via a hook in arch/x86/include/asm/dma-mapping.h rather than as a weak hook in swiotlb.c
--- arch/x86/xen/pci-swiotlb.c | 8 -------- drivers/pci/xen-iommu.c | 4 +++- include/xen/swiotlb.h | 1 - 3 files changed, 3 insertions(+), 10 deletions(-)
arch/x86/xen/pci-swiotlb.c +0 -8
@@ -43,11 +43,3 @@ phys_addr_t swiotlb_bus_to_phys(struct device *hwdev, dma_addr_t baddr)return baddr; } - -int swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size) -{ -if (xen_pv_domain ()) -return xen_range_needs_mapping (paddr, size); - -return 0 ; -}
drivers/pci/xen-iommu.c +3 -1
@@ -130,7 +130,7 @@ static int range_straddles_page_boundary(phys_addr_t p, size_t size)return 1 ; } -int xen_range_needs_mapping (phys_addr_t paddr,size_t size) +static int xen_swiotlb_force_mapping (phys_addr_t paddr,size_t size) {return range_straddles_page_boundary (paddr, size); }
@@ -324,6 +324,8 @@ void __init xen_iommu_init(void) force_iommu =0 ; dma_ops = &xen_dma_ops; + x86_swiotlb_force_mapping = &xen_swiotlb_force_mapping; +if (swiotlb) {printk (KERN_INFO "Xen: Enabling DMA fallback to swiotlb\n" ); dma_ops = &xen_swiotlb_dma_ops;
include/xen/swiotlb.h +0 -1
@@ -4,7 +4,6 @@extern void xen_swiotlb_fixup (void *buf,size_t size,unsigned long nslabs);extern phys_addr_t xen_bus_to_phys (dma_addr_t daddr);extern dma_addr_t xen_phys_to_bus (phys_addr_t paddr); -extern int xen_range_needs_mapping (phys_addr_t phys,size_t size);#ifdef CONFIG_PCI_XEN extern int xen_wants_swiotlb (void );
Signature · 1 line
1.5.6.5
PATCH 1/1 swiotlb: make swiotlb allocation functions architecture-specific
In reply to Ian CampbellSome architectures need to allocate memory to be used as a swiotlb in a special manner.
Also make the swiotlb_late_init_with_default_size() function only available on architectures which require it.
--- arch/ia64/include/asm/dma-mapping.h | 5 +++++ arch/ia64/kernel/pci-swiotlb.c | 11 +++++++++++ arch/x86/include/asm/dma-mapping.h | 4 ++++ arch/x86/kernel/pci-swiotlb.c | 12 ++++++++++++ arch/x86/xen/pci-swiotlb.c | 17 ----------------- include/linux/swiotlb.h | 3 --- lib/swiotlb.c | 12 ++---------- 7 files changed, 34 insertions(+), 30 deletions(-)
arch/ia64/include/asm/dma-mapping.h +5 -0
@@ -185,4 +185,9 @@ static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size) return 0; } +#define SWIOTLB_WANT_LATE_INIT 1 + +extern void *swiotlb_alloc_boot (size_t size,unsigned long nslabs); +extern void *swiotlb_alloc (unsigned order,unsigned long nslabs); +#endif /* _ASM_IA64_DMA_MAPPING_H */
arch/ia64/kernel/pci-swiotlb.c +11 -0
@@ -4,6 +4,7 @@#include <linux/cache.h> #include <linux/module.h> #include <linux/dma-mapping.h> +#include <linux/bootmem.h> #include <asm/swiotlb.h> #include <asm/dma.h>
@@ -13,6 +14,16 @@int swiotlb__read_mostly ;EXPORT_SYMBOL (swiotlb); +void *__init swiotlb_alloc_boot (size_t size,unsigned long nslabs) +{ +return alloc_bootmem_low_pages (size); +} + +void *swiotlb_alloc (unsigned order,unsigned long nslabs) +{ +return (void *)__get_free_pages (GFP_DMA | __GFP_NOWARN, order); +} +static void *ia64_swiotlb_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp) {
arch/x86/include/asm/dma-mapping.h +4 -0
@@ -324,4 +324,8 @@ static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size) return 0; } +extern void (*x86_swiotlb_alloc_fixup)(void *buf,size_t size, +unsigned long nslabs); +extern void *swiotlb_alloc_boot (size_t size,unsigned long nslabs); +#endif
arch/x86/kernel/pci-swiotlb.c +12 -0
@@ -6,6 +6,7 @@#include <linux/swiotlb.h> #include <linux/bootmem.h> #include <linux/dma-mapping.h> +#include <linux/bootmem.h> #include <asm/iommu.h> #include <asm/swiotlb.h>
@@ -16,6 +17,17 @@int swiotlb__read_mostly ;int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); +void __initdata (*x86_swiotlb_alloc_fixup)(void *buf,size_t size,unsigned long nslabs); + +void *__init swiotlb_alloc_boot (size_t size,unsigned long nslabs) +{ +void *ret =alloc_bootmem_low_pages (size); + +if (ret && x86_swiotlb_alloc_fixup) +x86_swiotlb_alloc_fixup (ret, size, nslabs); + +return ret; +}static void *x86_swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags)
arch/x86/xen/pci-swiotlb.c +0 -17
@@ -11,23 +11,6 @@* implementations in lib/swiotlb.c. */ -void *__init swiotlb_alloc_boot (size_t size,unsigned long nslabs) -{ -void *ret =alloc_bootmem_low_pages (size); - -if (ret &&xen_pv_domain ()) -xen_swiotlb_fixup (ret, size, nslabs); - -return ret; -} - -void *swiotlb_alloc (unsigned order,unsigned long nslabs) -{ -/* Never called on x86. Warn, just in case. */ -WARN_ON (1 ); -return NULL ; -} -dma_addr_t swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t paddr) {if (xen_pv_domain ())
include/linux/swiotlb.h +0 -3
@@ -24,9 +24,6 @@ struct scatterlist;extern void swiotlb_init (void ); -extern void *swiotlb_alloc_boot (size_t bytes,unsigned long nslabs); -extern void *swiotlb_alloc (unsigned order,unsigned long nslabs); -extern dma_addr_t swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t address); extern phys_addr_t swiotlb_bus_to_phys(struct device *hwdev,
lib/swiotlb.c +2 -10
@@ -114,16 +114,6 @@ setup_io_tlb_npages(char *str)__setup ("swiotlb=" , setup_io_tlb_npages);/* make io_tlb_overflow tunable too? */ -void *__weak __init swiotlb_alloc_boot (size_t size,unsigned long nslabs) -{ -return alloc_bootmem_low_pages (size); -} - -void *__weak swiotlb_alloc (unsigned order,unsigned long nslabs) -{ -return (void *)__get_free_pages (GFP_DMA | __GFP_NOWARN, order); -} -dma_addr_t __weak swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t paddr) {return paddr;
@@ -213,6 +203,7 @@ swiotlb_init(void)swiotlb_init_with_default_size (64 * (1 <<20 ));/* default to 64MB */ } +#ifdef SWIOTLB_WANT_LATE_INIT /* * Systems with larger DMA zones (those that don't support ISA) can * initialize the swiotlb later using the slab allocator if needed.
@@ -306,6 +297,7 @@ cleanup1: io_tlb_nslabs = req_nslabs; return -ENOMEM; } +#endif static inline int force_mapping (phys_addr_t paddr,size_t size) {
Signature · 1 line
1.5.6.5
PATCH 1/1 swiotlb/xen: update xen for changes to swiotlb allocation interface
In reply to Ian CampbellThis function is now implemented via an explicit hook in arch/x86/kernel/pci-swiotlb.c rather than as a weak hook in swiotlb.c
Initialsation of the hook needs to happen before xen_iommu_init() is called so add detect_xen_iommu() (mirroring other IOMMU implementations) which is called early enough.
--- arch/x86/include/asm/xen/iommu.h | 4 ++++ arch/x86/kernel/pci-dma.c | 4 +++- drivers/pci/xen-iommu.c | 14 +++++++++++--- include/xen/swiotlb.h | 1 - 4 files changed, 18 insertions(+), 5 deletions(-)
arch/x86/include/asm/xen/iommu.h +4 -0
@@ -1,8 +1,12 @@#ifndef ASM_X86__XEN_IOMMU_H #ifdef CONFIG_PCI_XEN +extern void detect_xen_iommu (void );extern void xen_iommu_init (void );#else +static inline void detect_xen_iommu (void ) +{ +}static inline void xen_iommu_init (void ) { }
arch/x86/kernel/pci-dma.c +3 -1
@@ -121,6 +121,8 @@ void __init pci_iommu_alloc(void)*/ gart_iommu_hole_init (); +detect_xen_iommu (); +detect_calgary ();detect_intel_iommu ();
@@ -277,7 +279,7 @@ static int __init pci_iommu_init(void)#endif xen_iommu_init (); - +calgary_iommu_init ();intel_iommu_init ();
drivers/pci/xen-iommu.c +11 -3
@@ -39,7 +39,8 @@ do { \static int max_dma_bits =32 ; -void xen_swiotlb_fixup (void *buf,size_t size,unsigned long nslabs) +static void __init xen_swiotlb_alloc_fixup (void *buf,size_t size, +unsigned long nslabs) {int i, rc;int dma_bits;
@@ -314,6 +315,15 @@ static struct dma_map_ops xen_swiotlb_dma_ops = { .is_phys = 0, }; +void __init detect_xen_iommu (void ) +{ +if (!xen_pv_domain ()) +return ; + + x86_swiotlb_force_mapping = &xen_swiotlb_force_mapping; + x86_swiotlb_alloc_fixup = &xen_swiotlb_alloc_fixup; +} +void __init xen_iommu_init (void ) {if (!xen_pv_domain ())
@@ -324,8 +334,6 @@ void __init xen_iommu_init(void) force_iommu =0 ; dma_ops = &xen_dma_ops; - x86_swiotlb_force_mapping = &xen_swiotlb_force_mapping; -if (swiotlb) {printk (KERN_INFO "Xen: Enabling DMA fallback to swiotlb\n" ); dma_ops = &xen_swiotlb_dma_ops;
include/xen/swiotlb.h +0 -1
@@ -1,7 +1,6 @@#ifndef _XEN_SWIOTLB_H#define _XEN_SWIOTLB_H -extern void xen_swiotlb_fixup (void *buf,size_t size,unsigned long nslabs);extern phys_addr_t xen_bus_to_phys (dma_addr_t daddr);extern dma_addr_t xen_phys_to_bus (phys_addr_t paddr);
Signature · 1 line
1.5.6.5
PATCH 1/1 swiotlb: make swiotlb phys<->bus translations architecture-specific
In reply to Ian CampbellThis moves swiotlb_bus_to_phys() and swiotlb_phys_to_bus() from lib/swiotlb.c to arch/*/include/asm/dma-mapping.h. On x86 gart_to_phys and phys_to_gart translations need an exported function for use from drivers so introduce common x86_ variants to implement the interface required by both.
The __weak swiotlb_bus_to_virt is not currently overriden by any architecture therefore it can be made static again. I imagine the ability to override phys<->bus translations will be sufficient for any potential users anyhow, otherwise we can revisit this aspect.
--- arch/ia64/include/asm/dma-mapping.h | 13 +++++++++++++ arch/x86/include/asm/agp.h | 4 ++-- arch/x86/include/asm/dma-mapping.h | 15 +++++++++++++++ arch/x86/kernel/pci-swiotlb.c | 18 ++++++++++++++++++ arch/x86/xen/pci-swiotlb.c | 15 --------------- include/linux/swiotlb.h | 5 ----- lib/swiotlb.c | 14 +------------- 7 files changed, 49 insertions(+), 35 deletions(-)
arch/ia64/include/asm/dma-mapping.h +13 -0
@@ -190,4 +190,17 @@ static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size)extern void *swiotlb_alloc_boot (size_t size,unsigned long nslabs);extern void *swiotlb_alloc (unsigned order,unsigned long nslabs); +static inline dma_addr_t swiotlb_phys_to_bus (struct device *hwdev, +phys_addr_t paddr) +{ +return paddr; +} + +static inline phys_addr_t swiotlb_bus_to_phys (struct device *hwdev, +dma_addr_t baddr) +{ +return baddr; +} + +#endif /* _ASM_IA64_DMA_MAPPING_H */
arch/x86/include/asm/agp.h +2 -2
@@ -26,8 +26,8 @@#define flush_agp_cache () wbinvd()/* Convert a physical address to an address suitable for the GART. */ -#define phys_to_gart (x) swiotlb_phys_to_bus(NULL, (x)) -#define gart_to_phys (x) swiotlb_bus_to_phys(NULL, (x)) +#define phys_to_gart (x) x86_phys_to_bus(NULL, (x)) +#define gart_to_phys (x) x86_bus_to_phys(NULL, (x))/* GATT allocation. Returns/accepts GATT kernel virtual address. */ #define alloc_gatt_pages (order) ({ \
arch/x86/include/asm/dma-mapping.h +15 -0
@@ -328,4 +328,19 @@ extern void (*x86_swiotlb_alloc_fixup)(void *buf, size_t size, unsigned long nslabs);extern void *swiotlb_alloc_boot (size_t size,unsigned long nslabs); +extern dma_addr_t (*x86_phys_to_bus)(struct device *hwdev,phys_addr_t paddr); +extern phys_addr_t (*x86_bus_to_phys)(struct device *hwdev,dma_addr_t baddr); + +static inline dma_addr_t swiotlb_phys_to_bus (struct device *hwdev, +phys_addr_t paddr) +{ +return x86_phys_to_bus (hwdev, paddr); +} + +static inline phys_addr_t swiotlb_bus_to_phys (struct device *hwdev, +dma_addr_t baddr) +{ +return x86_bus_to_phys (hwdev, baddr); +} +#endif
arch/x86/kernel/pci-swiotlb.c +18 -0
@@ -29,6 +29,24 @@ void * __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)return ret; } +static dma_addr_t __x86_phys_to_bus (struct device *hwdev,phys_addr_t paddr) +{ +return paddr; +} + +static phys_addr_t __x86_bus_to_phys (struct device *hwdev,dma_addr_t baddr) +{ +return baddr; +} + +dma_addr_t (*x86_phys_to_bus)(struct device *hwdev, +phys_addr_t paddr) = __x86_phys_to_bus; +EXPORT_SYMBOL_GPL (x86_phys_to_bus); + +phys_addr_t (*x86_bus_to_phys)(struct device *hwdev, +dma_addr_t baddr) = __x86_bus_to_phys; +EXPORT_SYMBOL_GPL (x86_bus_to_phys); +static void *x86_swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags) {
arch/x86/xen/pci-swiotlb.c +0 -15
@@ -11,18 +11,3 @@* implementations in lib/swiotlb.c. */ -dma_addr_t swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t paddr) -{ -if (xen_pv_domain ()) -return xen_phys_to_bus (paddr); - -return paddr; -} - -phys_addr_t swiotlb_bus_to_phys (struct device *hwdev,dma_addr_t baddr) -{ -if (xen_pv_domain ()) -return xen_bus_to_phys (baddr); - -return baddr; -}
include/linux/swiotlb.h +0 -5
@@ -24,11 +24,6 @@ struct scatterlist;extern void swiotlb_init (void ); -extern dma_addr_t swiotlb_phys_to_bus (struct device *hwdev, -phys_addr_t address); -extern phys_addr_t swiotlb_bus_to_phys (struct device *hwdev, -dma_addr_t address); -extern void *swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags);
lib/swiotlb.c +1 -13
@@ -114,25 +114,13 @@ setup_io_tlb_npages(char *str)__setup ("swiotlb=" , setup_io_tlb_npages);/* make io_tlb_overflow tunable too? */ -dma_addr_t __weak swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t paddr) -{ -return paddr; -} -EXPORT_SYMBOL_GPL (swiotlb_phys_to_bus); - -phys_addr_t __weak swiotlb_bus_to_phys (struct device *hwdev,dma_addr_t baddr) -{ -return baddr; -} -EXPORT_SYMBOL_GPL (swiotlb_bus_to_phys); -static dma_addr_t swiotlb_virt_to_bus (struct device *hwdev,volatile void *address) {return swiotlb_phys_to_bus (hwdev,virt_to_phys (address)); } -void *__weak swiotlb_bus_to_virt (struct device *hwdev,dma_addr_t address) +static void *swiotlb_bus_to_virt (struct device *hwdev,dma_addr_t address) {return phys_to_virt (swiotlb_bus_to_phys (hwdev, address)); }
Signature · 1 line
1.5.6.5
PATCH 1/1 swiotlb/xen: update xen swiotlb for phys<->bus API changes
In reply to Ian CampbellThese functions are now implemented via explicit hooks in arch/x86/kernel/pci-swiotlb.c rather than as weak hooks in swiotlb.c
--- drivers/pci/xen-iommu.c | 6 ++++-- include/xen/swiotlb.h | 3 --- 2 files changed, 4 insertions(+), 5 deletions(-)
drivers/pci/xen-iommu.c +4 -2
@@ -72,12 +72,12 @@ int xen_wants_swiotlb(void)return xen_initial_domain (); } -dma_addr_t xen_phys_to_bus (phys_addr_t paddr) +static dma_addr_t xen_phys_to_bus (struct device *hwdev,phys_addr_t paddr) {return phys_to_machine (XPADDR (paddr)).maddr; } -phys_addr_t xen_bus_to_phys (dma_addr_t daddr) +static phys_addr_t xen_bus_to_phys (struct device *hwdev,dma_addr_t daddr) {return machine_to_phys (XMADDR (daddr)).paddr; }
@@ -322,6 +322,8 @@ void __init detect_xen_iommu(void) x86_swiotlb_force_mapping = &xen_swiotlb_force_mapping; x86_swiotlb_alloc_fixup = &xen_swiotlb_alloc_fixup; + x86_bus_to_phys = &xen_bus_to_phys; + x86_phys_to_bus = &xen_phys_to_bus; }void __init xen_iommu_init (void )
include/xen/swiotlb.h +0 -3
@@ -1,9 +1,6 @@#ifndef _XEN_SWIOTLB_H#define _XEN_SWIOTLB_H -extern phys_addr_t xen_bus_to_phys (dma_addr_t daddr); -extern dma_addr_t xen_phys_to_bus (phys_addr_t paddr); -#ifdef CONFIG_PCI_XEN extern int xen_wants_swiotlb (void );#else
Signature · 1 line
1.5.6.5
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
In reply to Ian CampbellQuoted 2 lines · Ian Campbell
At the end of this series there are no more
__weakfunctions inlib/swiotlb.c
Hmm, I was expecting the patches to be numbered in the subject by default. The correct order is:
swiotlb: make is_buffer_dma_capable architecture-specific
swiotlb: make range_needs_mapping architecture-specific swiotlb/xen: update xen for swiotlb_arch_force_mapping changes
swiotlb: make swiotlb allocation functions architecture-specific swiotlb/xen: update xen for changes to swiotlb allocation interface
swiotlb: make swiotlb phys<->bus translations architecture-specific swiotlb/xen: update xen swiotlb for phys<->bus API changes
xen: remove arch/x86/xen/pci-swiotlb.c
Also xen-devel missed out due to a typo, sorry. See the LKML archives if you are interested.
Ian.
Quoted 44 lines
The series adds several hook functions to the x86 architecture. Would they be preferred as a struct
x86_swiotlb_opsor as individual hooks?I was unsure what to do about powerpc in most places since the existing support seems to in-progress so it wasn't always clear where to put the implementation. If there is a tree somewhere with more complete support I'll be happy to provide additional patches.
Boot tested on x86 under xen but not even compiled for ia64 or powerpc. If someone can point me to a decent source of cross compilers I can sort that out. (http://www.kernel.org/pub/tools/crosstool/ seems to be out-of-date and only has ia64 in any case)
Signed-off-by Ian Campbell <[email protected]>Cc FUJITA Tomonori <[email protected]>Cc Jeremy Fitzhardinge <[email protected]>Cc Becky Bruce <[email protected]>Cc Olaf Kirch <[email protected]>Cc Ingo Molnar <[email protected]>Cc Greg KH <[email protected]>Cc xen-devel <[email protected]>Cc x86 maintainers <[email protected]>Cc lkml <[email protected]>---
arch/ia64/include/asm/dma-mapping.h | 29 ++++++++++++++ arch/ia64/kernel/pci-swiotlb.c | 11 +++++ arch/powerpc/include/asm/dma-mapping.h | 5 ++ arch/x86/include/asm/agp.h | 4 +- arch/x86/include/asm/dma-mapping.h | 34 +++++++++++++++++ arch/x86/include/asm/xen/iommu.h | 4 ++ arch/x86/kernel/pci-dma.c | 6 ++- arch/x86/kernel/pci-gart_64.c | 4 +- arch/x86/kernel/pci-nommu.c | 3 +- arch/x86/kernel/pci-swiotlb.c | 32 ++++++++++++++++ arch/x86/xen/Makefile | 3 +- arch/x86/xen/pci-swiotlb.c | 53 -------------------------- drivers/pci/xen-iommu.c | 20 ++++++++-- include/linux/dma-mapping.h | 5 -- include/linux/swiotlb.h | 10 ----- include/xen/swiotlb.h | 5 -- lib/swiotlb.c | 64 +++++++------------------------- 17 files changed, 156 insertions(+), 136 deletions(-)
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
In reply to Ian CampbellQuoted 11 lines · Ian Campbell
At the end of this series there are no more
__weakfunctions inlib/swiotlb.cThe series adds several hook functions to the x86 architecture. Would they be preferred as a struct
x86_swiotlb_opsor as individual hooks?I was unsure what to do about powerpc in most places since the existing support seems to in-progress so it wasn't always clear where to put the implementation. If there is a tree somewhere with more complete support I'll be happy to provide additional patches.
Quoted 4 lines
Boot tested on x86 under xen but not even compiled for ia64 or powerpc. If someone can point me to a decent source of cross compilers I can sort that out. (http://www.kernel.org/pub/tools/crosstool/ seems to be out-of-date and only has ia64 in any case)
Try these. They are fairly current. I have used several of them.
http://bakeyournoodle.com/cross/
Signature · 3 lines
~Randy LPC 2009, Sept. 23-25, Portland, Oregon http://linuxplumbersconf.org/2009/
Quoted 9 lines · On Thu, 21 May 2009 12:45:35 +0100 Ian Campbell <[email protected]> wrote:
Quoted 3 lines
A necessary interface? Sorry, I don't buy it. It's necessary for only Xen. And it's not fit well for swiotlb and the architecture abstraction.
I said "necessary interface to enable a particular use-case". Xen is a valid use case -- I appreciate that you personally may have no interest in it but plenty of people do and plenty of people would like to see it working in the mainline kernels.
Quoted 7 lines
In terms of clean abstraction this is a architecture hook to allow mappings to be forced through the swiotlb. It is essentially a more flexible extension to the existing
swiotlb_forceflag, in factswiotlb_force_mapping()might even be a better name for it.IMHO, the benefits here (working Xen domain 0 plus PCI passthrough to guest domains) are well worth the costs.
All I care about is a clean design; an wrong design will hurt us.
Quoted 13 lines
Quoted 5 lines
Quoted 3 lines
If there was a cleaner way to achieve the same result we would of course go with that. I don't think duplicating
swiotlb.c, as has been suggested as the alternative, just for that one hook point makes sense.One hook? You need to reread
swiotlb.c. There are more. All should go.I meant that
swiotlb_range_needs_mappingis the single contentious hook as far as I can tell. It is the only one which you appear to be disputing the very existence of (irrespective of whether it uses__weakor is moved intoasm/dma-mapping.h). The other existing__weakhooks are useful to other users too and all can, AFAICT, be moved intoasm/dma-mapping.h.
Quoted 5 lines
You have already dealt with moving
swiotlb_address_needs_mappingand I am currently looking into the thephys_to_busandbus_to_physones. That just leaves the alloc functions, which are next on my list afterphys_to_busandbus_to_phys. Will finishing up those patches resolve most of your objections are do you have others?
The latest your patch is more hacky than the current code. You just move the ugly hacks for dom0 from lib/swiotlb.c to somewhere else.
I guess that the only way to keep the Xen-specific stuff in Xen's land is something like this. Then xen/pci-swiotlb.c implements its own map/unmap functions without messing up the generic code.
I guess that do_map_single's io_tlb_daddr argument is pointless for Xen since swiotlb doesn't work if iotlb buffer is not physically continuous (you will see data corruption with some device drivers).
include/linux/swiotlb.h +11 -2
@@ -21,8 +21,17 @@ struct scatterlist;*/ #define IO_TLB_SHIFT 11 -extern void -swiotlb_init (void ); +extern void swiotlb_init (void ); +extern void swiotlb_register_io_tlb (void *); + +extern void *do_map_single (struct device *hwdev,dma_addr_t io_tlb_daddr, +phys_addr_t phys,size_t size, +enum dma_data_direction dir); +extern void do_unmap_single (struct device *hwdev,char *dma_addr,size_t size, +enum dma_data_direction dir); + +extern void sync_single (struct device *hwdev,char *dma_addr,size_t size, +int dir,int target);extern void *swiotlb_alloc_boot (size_t bytes,unsigned long nslabs);extern void *swiotlb_alloc (unsigned order,unsigned long nslabs);
lib/swiotlb.c +34 -25
112 lines not on this page · raw message
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
In reply to Randy DunlapQuoted 3 lines · Randy Dunlap
Try these. They are fairly current. I have used several of them.
Thanks for the pointer, these look ideal.
Ian.
Re: [PATCH] swiotlb: make swiotlb phys<->bus translations architecture-specific
In reply to Ian CampbellQuoted 42 lines · On Thu, 21 May 2009 17:15:27 +0100 Ian Campbell <[email protected]> wrote:
This moves
swiotlb_bus_to_phys()andswiotlb_phys_to_bus()fromlib/swiotlb.ctoarch/*/include/asm/dma-mapping.h. On x86gart_to_physandphys_to_garttranslations need an exported function for use from drivers so introduce commonx86_variants to implement the interface required by both.The
__weakswiotlb_bus_to_virtis not currently overriden by any architecture therefore it can be made static again. I imagine the ability to override phys<->bus translations will be sufficient for any potential users anyhow, otherwise we can revisit this aspect.Signed-off-by Ian Campbell <[email protected]>Cc FUJITA Tomonori <[email protected]>Cc Jeremy Fitzhardinge <[email protected]>Cc Becky Bruce <[email protected]>Cc Olaf Kirch <[email protected]>Cc Ingo Molnar <[email protected]>Cc Greg KH <[email protected]>Cc xen-devel <[email protected]>Cc x86 maintainers <[email protected]>Cc lkml <[email protected]>--- arch/ia64/include/asm/dma-mapping.h | 13 +++++++++++++ arch/x86/include/asm/agp.h | 4 ++-- arch/x86/include/asm/dma-mapping.h | 15 +++++++++++++++ arch/x86/kernel/pci-swiotlb.c | 18 ++++++++++++++++++ arch/x86/xen/pci-swiotlb.c | 15 --------------- include/linux/swiotlb.h | 5 ----- lib/swiotlb.c | 14 +------------- 7 files changed, 49 insertions(+), 35 deletions(-)arch/ia64/include/asm/dma-mapping.h +3
-0@@ -190,4 +190,17 @@ static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size)extern void *swiotlb_alloc_boot (size_t size,unsigned long nslabs);extern void *swiotlb_alloc (unsigned order,unsigned long nslabs); +static inline dma_addr_t swiotlb_phys_to_bus (struct device *hwdev, +phys_addr_t paddr) +{
arch/ia64/include/asm/dma-mapping.h static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size) · line 205
Quoted 10 lines
arch/ia64/include/asm/dma-mapping.h +10
-0+return paddr; +} + +static inline phys_addr_t swiotlb_bus_to_phys (struct device *hwdev, +dma_addr_t baddr) +{ +return baddr; +} + +
As I wrote in another mail, adding swiotlb specific code in dma-mapping.h is wrong.
Re: [PATCH] swiotlb: make swiotlb allocation functions architecture-specific
In reply to Ian CampbellQuoted 2 lines · On Thu, 21 May 2009 17:15:25 +0100 Ian Campbell <[email protected]> wrote:
Some architectures need to allocate memory to be used as a swiotlb in a special manner.
Hmm, what architectures need a special manner? I guess only Xen.
Quoted 196 lines
Also make the
swiotlb_late_init_with_default_size()function only available on architectures which require it.Signed-off-by Ian Campbell <[email protected]>Cc FUJITA Tomonori <[email protected]>Cc Jeremy Fitzhardinge <[email protected]>Cc Becky Bruce <[email protected]>Cc Olaf Kirch <[email protected]>Cc Ingo Molnar <[email protected]>Cc Greg KH <[email protected]>Cc xen-devel <[email protected]>Cc x86 maintainers <[email protected]>Cc lkml <[email protected]>--- arch/ia64/include/asm/dma-mapping.h | 5 +++++ arch/ia64/kernel/pci-swiotlb.c | 11 +++++++++++ arch/x86/include/asm/dma-mapping.h | 4 ++++ arch/x86/kernel/pci-swiotlb.c | 12 ++++++++++++ arch/x86/xen/pci-swiotlb.c | 17 ----------------- include/linux/swiotlb.h | 3 --- lib/swiotlb.c | 12 ++---------- 7 files changed, 34 insertions(+), 30 deletions(-)arch/ia64/include/asm/dma-mapping.h +5
-0@@ -185,4 +185,9 @@ static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size) return 0; } +#define SWIOTLB_WANT_LATE_INIT 1 + +extern void *swiotlb_alloc_boot (size_t size,unsigned long nslabs); +extern void *swiotlb_alloc (unsigned order,unsigned long nslabs); +#endif /* _ASM_IA64_DMA_MAPPING_H */ arch/ia64/kernel/pci-swiotlb.c +11
-0@@ -4,6 +4,7 @@#include <linux/cache.h> #include <linux/module.h> #include <linux/dma-mapping.h> +#include <linux/bootmem.h> #include <asm/swiotlb.h> #include <asm/dma.h> @@ -13,6 +14,16 @@int swiotlb__read_mostly ;EXPORT_SYMBOL (swiotlb); +void *__init swiotlb_alloc_boot (size_t size,unsigned long nslabs) +{ +return alloc_bootmem_low_pages (size); +} + +void *swiotlb_alloc (unsigned order,unsigned long nslabs) +{ +return (void *)__get_free_pages (GFP_DMA | __GFP_NOWARN, order); +} +static void *ia64_swiotlb_alloc_coherent (struct device *dev,size_t size,dma_addr_t *dma_handle,gfp_t gfp) {arch/x86/include/asm/dma-mapping.h +4
-0@@ -324,4 +324,8 @@ static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size) return 0; } +extern void (*x86_swiotlb_alloc_fixup)(void *buf,size_t size, +unsigned long nslabs); +extern void *swiotlb_alloc_boot (size_t size,unsigned long nslabs); +#endif arch/x86/kernel/pci-swiotlb.c +12
-0@@ -6,6 +6,7 @@#include <linux/swiotlb.h> #include <linux/bootmem.h> #include <linux/dma-mapping.h> +#include <linux/bootmem.h> #include <asm/iommu.h> #include <asm/swiotlb.h> @@ -16,6 +17,17 @@int swiotlb__read_mostly ;int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); +void __initdata (*x86_swiotlb_alloc_fixup)(void *buf,size_t size,unsigned long nslabs); + +void *__init swiotlb_alloc_boot (size_t size,unsigned long nslabs) +{ +void *ret =alloc_bootmem_low_pages (size); + +if (ret && x86_swiotlb_alloc_fixup) +x86_swiotlb_alloc_fixup (ret, size, nslabs); + +return ret; +}static void *x86_swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags)arch/x86/xen/pci-swiotlb.c +0
-17@@ -11,23 +11,6 @@* implementations in lib/swiotlb.c. */ -void *__init swiotlb_alloc_boot (size_t size,unsigned long nslabs) -{ -void *ret =alloc_bootmem_low_pages (size); - -if (ret &&xen_pv_domain ()) -xen_swiotlb_fixup (ret, size, nslabs); - -return ret; -} - -void *swiotlb_alloc (unsigned order,unsigned long nslabs) -{ -/* Never called on x86. Warn, just in case. */ -WARN_ON (1 ); -return NULL ; -} -dma_addr_t swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t paddr) {if (xen_pv_domain ())include/linux/swiotlb.h +0
-3@@ -24,9 +24,6 @@ struct scatterlist;extern void swiotlb_init (void ); -extern void *swiotlb_alloc_boot (size_t bytes,unsigned long nslabs); -extern void *swiotlb_alloc (unsigned order,unsigned long nslabs); -extern dma_addr_t swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t address); extern phys_addr_t swiotlb_bus_to_phys(struct device *hwdev,lib/swiotlb.c +2
-10@@ -114,16 +114,6 @@ setup_io_tlb_npages(char *str)__setup ("swiotlb=" , setup_io_tlb_npages);/* make io_tlb_overflow tunable too? */ -void *__weak __init swiotlb_alloc_boot (size_t size,unsigned long nslabs) -{ -return alloc_bootmem_low_pages (size); -} - -void *__weak swiotlb_alloc (unsigned order,unsigned long nslabs) -{ -return (void *)__get_free_pages (GFP_DMA | __GFP_NOWARN, order); -} -dma_addr_t __weak swiotlb_phys_to_bus (struct device *hwdev,phys_addr_t paddr) {return paddr;@@ -213,6 +203,7 @@ swiotlb_init(void)swiotlb_init_with_default_size (64 * (1 <<20 ));/* default to 64MB */ } +#ifdef SWIOTLB_WANT_LATE_INIT /* * Systems with larger DMA zones (those that don't support ISA) can * initialize the swiotlb later using the slab allocator if needed. @@ -306,6 +297,7 @@ cleanup1: io_tlb_nslabs = req_nslabs; return -ENOMEM; } +#endif static inline int force_mapping (phys_addr_t paddr,size_t size) {Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
In reply to Ian CampbellQuoted 16 lines · On Thu, 21 May 2009 17:15:21 +0100 Ian Campbell <[email protected]> wrote:
At the end of this series there are no more
__weakfunctions inlib/swiotlb.cThe series adds several hook functions to the x86 architecture. Would they be preferred as a struct
x86_swiotlb_opsor as individual hooks?I was unsure what to do about powerpc in most places since the existing support seems to in-progress so it wasn't always clear where to put the implementation. If there is a tree somewhere with more complete support I'll be happy to provide additional patches.
Boot tested on x86 under xen but not even compiled for ia64 or powerpc. If someone can point me to a decent source of cross compilers I can sort that out. (http://www.kernel.org/pub/tools/crosstool/ seems to be out-of-date and only has ia64 in any case)
Quoted 10 lines
Signed-off-by Ian Campbell <[email protected]>Cc FUJITA Tomonori <[email protected]>Cc Jeremy Fitzhardinge <[email protected]>Cc Becky Bruce <[email protected]>Cc Olaf Kirch <[email protected]>Cc Ingo Molnar <[email protected]>Cc Greg KH <[email protected]>Cc xen-devel <[email protected]>Cc x86 maintainers <[email protected]>Cc lkml <[email protected]>
Sorry, Nack.
As I wrote in another mail, this patch makes the code more difficult to understand; it just moves the hacks in lib/swiotlb.c somewhere else in a strange way instead of killing them.
Please go with the following way (that I posted yesterday):
http://marc.info/?l=xen-devel&m=124292666214380&w=2
Export the core feature of swiotlb, managing iotlb buffer and implement the Xen mapping functions. With that approach, there is not much code duplication and there is no need for ugly hooks for dom0; the phys/bus address conversion and address checking.
Re: [PATCH] swiotlb: make range_needs_mapping architecture-specific
In reply to Ian CampbellQuoted 42 lines · On Thu, 21 May 2009 17:15:23 +0100 Ian Campbell <[email protected]> wrote:
This moves
range_needs_mapping()fromlib/swiotlb.ctoarch/*/include/asm/dma-mapping.hand renames itswiotlb_arch_force_mapping()to more acurately reflect its usage.Signed-off-by Ian Campbell <[email protected]>Cc FUJITA Tomonori <[email protected]>Cc Jeremy Fitzhardinge <[email protected]>Cc Becky Bruce <[email protected]>Cc Olaf Kirch <[email protected]>Cc Ingo Molnar <[email protected]>Cc Greg KH <[email protected]>Cc xen-devel <[email protected]>Cc x86 maintainers <[email protected]>Cc lkml <[email protected]>--- arch/ia64/include/asm/dma-mapping.h | 5 +++++ arch/powerpc/include/asm/dma-mapping.h | 5 +++++ arch/x86/include/asm/dma-mapping.h | 9 +++++++++ arch/x86/kernel/pci-swiotlb.c | 2 ++ include/linux/swiotlb.h | 2 -- lib/swiotlb.c | 13 ++++--------- 6 files changed, 25 insertions(+), 11 deletions(-)arch/ia64/include/asm/dma-mapping.h +5
-0@@ -180,4 +180,9 @@ static inline int is_buffer_dma_capable(struct device *dev, u64 mask, return addr + size <= mask; } +static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +return 0 ; +} +#endif /* _ASM_IA64_DMA_MAPPING_H */ arch/powerpc/include/asm/dma-mapping.h +0
-0
arch/powerpc/include/asm/dma-mapping.h static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, · line 436
Quoted 8 lines
arch/powerpc/include/asm/dma-mapping.h +5
-0@@ -429,5 +429,10 @@ static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size,__dma_sync (vaddr, size, (int )direction); } +static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +return 0 ; +} +
Adding a swiotlb specific function to asm/dma-mapping.h is wrong.
Quoted 38 lines
arch/powerpc/include/asm/dma-mapping.h +0
-0#endif /* __KERNEL__ */ #endif /* _ASM_DMA_MAPPING_H */ arch/x86/include/asm/dma-mapping.h +9
-0@@ -315,4 +315,13 @@ static inline int is_buffer_dma_capable(struct device *dev, u64 mask, return addr + size <= mask; } +extern int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); + +static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +if (x86_swiotlb_force_mapping) +return x86_swiotlb_force_mapping (paddr, size); +return 0 ; +} +#endif arch/x86/kernel/pci-swiotlb.c +2
-0@@ -15,6 +15,8 @@int swiotlb__read_mostly ; +int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); +static void *x86_swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags) {include/linux/swiotlb.h +0
-0
include/linux/swiotlb.h extern dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, · line 33
Quoted 2 lines
include/linux/swiotlb.h +0
-0@@ -32,8 +32,6 @@ extern dma_addr_t swiotlb_phys_to_bus(struct device *hwdev,extern phys_addr_t swiotlb_bus_to_phys (struct device *hwdev,dma_addr_t address);
Ditto.
And using a function pointer for the architecture abstraction is worse than __weak.
Quoted 59 lines
include/linux/swiotlb.h +0
-2-extern int swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size); -extern void *swiotlb_alloc_coherent (struct device *hwdev,size_t size,dma_addr_t *dma_handle,gfp_t flags);lib/swiotlb.c +4
-9@@ -147,11 +147,6 @@ void * __weak swiotlb_bus_to_virt(struct device *hwdev, dma_addr_t address)return phys_to_virt (swiotlb_bus_to_phys (hwdev, address)); } -int __weak swiotlb_arch_range_needs_mapping (phys_addr_t paddr,size_t size) -{ -return 0 ; -} -static void swiotlb_print_info (unsigned long bytes) {phys_addr_t pstart, pend;@@ -312,9 +307,9 @@ cleanup1:return -ENOMEM ; } -static inline int range_needs_mapping (phys_addr_t paddr,size_t size) +static inline int force_mapping (phys_addr_t paddr,size_t size) { -return swiotlb_force ||swiotlb_arch_range_needs_mapping (paddr, size); +return swiotlb_force ||swiotlb_force_mapping (paddr, size); }static int is_swiotlb_buffer (char *addr)@@ -647,7 +642,7 @@ dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,* buffering it. */ if (is_buffer_dma_capable (dev,dma_get_mask (dev), dev_addr, size) && - !range_needs_mapping (phys, size)) + !force_mapping (phys, size))return dev_addr;/* @@ -810,7 +805,7 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,phys_addr_t paddr =sg_phys (sg);dma_addr_t dev_addr =swiotlb_phys_to_bus (hwdev, paddr); -if (range_needs_mapping (paddr, sg->length) || +if (force_mapping (paddr, sg->length) || !is_buffer_dma_capable (hwdev,dma_get_mask (hwdev), dev_addr, sg->length)) { void *map = map_single(hwdev, sg_phys(sg),Signature · 7 lines
1.5.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
In reply to FUJITA TomonoriQuoted 9 lines · FUJITA Tomonori
On Thu, 21 May 2009 17:15:21 +0100
Ian Campbell <[email protected]> wrote:
Please go with the following way (that I posted yesterday):http://marc.info/?l=xen-devel&m=124292666214380&w=2
Export the core feature of swiotlb, managing iotlb buffer and implement the Xen mapping functions.
I feel that should be a last resort, before we go down that path we should try and find a way for us to use the generic code in a clean way which makes everyone happy.
We have had several attempts at this and admittedly have not yet come up with something that satisfies everyone but I don't really think we have gotten to the point of admitting defeat and just duplicating the code.
I think the proposal to use a dma_map_range-like function which I sent a few minutes ago I think gets us closer to something which satisfies everyone's requirements, including yours for a clean abstraction.
Quoted 3 lines
With that approach, there is not
much code duplication and there is no need for ugly hooks for dom0; the phys/bus address conversion and address checking.
The phys/bus address conversion is also needed for powerpc.
I think the two address checking functions can be collapsed into a single one which satisfies the needs of both Xen and powerpc.
What dom0 specific "ugly" hooks does that leave? The alloc one? I've discussed that in another mail.
Ian.
Re: [PATCH] swiotlb: make range_needs_mapping architecture-specific
In reply to FUJITA TomonoriQuoted 9 lines · FUJITA Tomonori
arch/ia64/include/asm/dma-mapping.h static inline int is_buffer_dma_capable(struct device *dev, u64 mask, · line 187
Quoted 5 lines · On Thu, 21 May 2009 17:15:23 +0100 Ian Campbell <[email protected]> wrote:
arch/ia64/include/asm/dma-mapping.h +5
-0+static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +return 0 ; +} +Adding a swiotlb specific function to
asm/dma-mapping.his wrong.
This one is unnecessary with the dma_map_range proposal.
Quoted 2 lines
Quoted 2 lines
arch/x86/kernel/pci-swiotlb.c +2
-0+int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); +
[...]
Quoted 2 lines
And using a function pointer for the architecture abstraction is worse than
__weak.
This specific hook is unnecessary with the dma_map_range proposal but in general we use function pointers quite extensively for abstraction in the kernel.
This case is internal to the x86 arch code and I'd really like to hear the x86 maintainer's opinion of the general approach.
Ian.
Re: [PATCH] swiotlb: make swiotlb allocation functions architecture-specific
In reply to FUJITA TomonoriQuoted 7 lines · FUJITA Tomonori
Quoted 2 lines · On Thu, 21 May 2009 17:15:25 +0100 Ian Campbell <[email protected]> wrote:
Some architectures need to allocate memory to be used as a swiotlb in a special manner.
Hmm, what architectures need a special manner? I guess only Xen.
The x86 architecture, when running as a paravirtualised guest under Xen, needs it. I guess ia64 might need it for similar reasons, I'm not sure.
How does the fact that x86-Xen is (currently) the only user invalidate the requirement? You seem to have a knee-jerk reaction to anything which might be useful to Xen and I really don't understand why that should be the case.
We are talking about an initialisation path and we are not talking about changes which completely obscure all meaning or anything. The semantics of the API are pretty clear, I think.
Ian.
Re: [PATCH] swiotlb: make swiotlb phys<->bus translations architecture-specific
In reply to FUJITA TomonoriQuoted 10 lines · FUJITA Tomonori
arch/ia64/include/asm/dma-mapping.h static inline int swiotlb_force_mapping(phys_addr_t paddr, size_t size) · line 205
Quoted 7 lines
arch/ia64/include/asm/dma-mapping.h +7
-0+static inline phys_addr_t swiotlb_bus_to_phys (struct device *hwdev, +dma_addr_t baddr) +{ +return baddr; +} + +As I wrote in another mail, adding swiotlb specific code in
dma-mapping.his wrong.
They aren't really swiotlb specific, I just foolishly carried over the old name, really I think they should be called just bus_to_phys and phys_to_bus or something.
Ian.
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
In reply to Ian CampbellQuoted 11 lines · On Fri, 22 May 2009 12:43:16 +0100 Ian Campbell <[email protected]>…
Quoted 9 lines · FUJITA Tomonori
On Thu, 21 May 2009 17:15:21 +0100
Ian Campbell <[email protected]> wrote:
Please go with the following way (that I posted yesterday):http://marc.info/?l=xen-devel&m=124292666214380&w=2
Export the core feature of swiotlb, managing iotlb buffer and implement the Xen mapping functions.
Quoted 7 lines
I feel that should be a last resort, before we go down that path we should try and find a way for us to use the generic code in a clean way which makes everyone happy.
We have had several attempts at this and admittedly have not yet come up with something that satisfies everyone but I don't really think we have gotten to the point of admitting defeat and just duplicating the code.
There should not be much duplication.
Quoted 3 lines
I think the proposal to use a dma_map_range-like function which I sent a few minutes ago I think gets us closer to something which satisfies everyone's requirements, including yours for a clean abstraction.
Seems you don't understand the point; with dom0, we can't cleanly use arch/*/include/asm/.
You need to insert Xen's hook like this:
+++ b/arch/x86/include/asm/dma-mapping.h
@@ -309,4 +309,20 @@ static inline void dma_free_coherent(struct device *dev, size_t size,
ops->free_coherent(dev, size, vaddr, bus);
}
+static inline dma_addr_t dma_map_range(struct device *dev, u64 mask,
+ phys_addr_t addr, size_t size)
+{
+ dma_addr_t dma_addr;
+#ifdef CONFIG_XEN
+ extern int xen_range_needs_mapping(phys_addr_t paddr, size_t size);
+ if (xen_pv_domain() && xen_range_needs_mapping(addr, size))
+ return 0;
+#endif
+
+ dma_addr = swiotlb_phys_to_bus(dev, addr);
+ if (dma_addr + size <= mask)
+ return 0;
+ return dma_addr;
+}
Or you need to use a function pointer in a strange way.
arch/x86/include/asm/dma-mapping.h +9 -0
@@ -315,4 +315,13 @@ static inline int is_buffer_dma_capable(struct device *dev, u64 mask,return addr + size <= mask; } +extern int (*x86_swiotlb_force_mapping)(phys_addr_t paddr,size_t size); + +static inline int swiotlb_force_mapping (phys_addr_t paddr,size_t size) +{ +if (x86_swiotlb_force_mapping) +return x86_swiotlb_force_mapping (paddr, size); +return 0 ; +} +
Or you could invent something more.
As you said in another mail, it's up to the x86 maintainer :
Quoted 2 lines
This case is internal to the x86 arch code and I'd really like to hear the x86 maintainer's opinion of the general approach.
But the above code looks really ugly to me.
Quoted 11 lines
Quoted 3 lines
With that approach, there is not
much code duplication and there is no need for ugly hooks for dom0; the phys/bus address conversion and address checking.The phys/bus address conversion is also needed for powerpc.
I think the two address checking functions can be collapsed into a single one which satisfies the needs of both Xen and powerpc.
What dom0 specific "ugly" hooks does that leave? The alloc one? I've discussed that in another mail.
See above. POWERPC can use arch/*/include/asm/ cleanly for the phys/bus address conversion while dom0 can't. That's what I said again and again.
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
Quoted 25 lines · FUJITA Tomonori
Quoted 11 lines · On Fri, 22 May 2009 12:43:16 +0100 Ian Campbell <[email protected]>…
Quoted 9 lines · FUJITA Tomonori
On Thu, 21 May 2009 17:15:21 +0100
Ian Campbell <[email protected]> wrote:
Please go with the following way (that I posted yesterday):http://marc.info/?l=xen-devel&m=124292666214380&w=2
Export the core feature of swiotlb, managing iotlb buffer and implement the Xen mapping functions.
Quoted 7 lines
I feel that should be a last resort, before we go down that path we should try and find a way for us to use the generic code in a clean way which makes everyone happy.
We have had several attempts at this and admittedly have not yet come up with something that satisfies everyone but I don't really think we have gotten to the point of admitting defeat and just duplicating the code.
There should not be much duplication.
Quoted 6 lines
Quoted 3 lines
I think the proposal to use a dma_map_range-like function which I sent a few minutes ago I think gets us closer to something which satisfies everyone's requirements, including yours for a clean abstraction.
Seems you don't understand the point; with dom0, we can't cleanly use
arch/*/include/asm/.
I understand precisely what you are saying, I just fundamentally disagree with you. It is perfectly possible for an arch/*/include/asm interface for this stuff to be defined which is completely abstracted from the POV of the swiotlb code (and any other arch-external code).
Quoted 1 line
You need to insert Xen's hook like this:
As I said in the email this snippet was contained in:
Quoted 3 lines
* The Xen specific stuff in
arch/x86/include/asm/dma-mapping.hclearly needs to be properly abstracted away (I just stuck it there for testing).
So obviously I am well aware that it is unacceptable as it stands.
I think we can find a way to implement this functionality which is contained entirely within the arch/x86 code and is also acceptable to the x86 maintainers. There are plenty of cases where we define similar interfaces where arch code implements an API with different backends for different configurations, hardware configurations etc etc.
Quoted 3 lines
See above. POWERPC can use
arch/*/include/asm/cleanly for the phys/bus address conversion while dom0 can't. That's what I said again and again.
And I dispute this claim, again and again.
Ian.
Re: swiotlb: remove __weak hooks in favour of architecture-specific functions
Quoted 38 lines · On Fri, 22 May 2009 15:02:04 +0100 Ian Campbell <[email protected]>…
Quoted 25 lines · FUJITA Tomonori
Quoted 11 lines · On Fri, 22 May 2009 12:43:16 +0100 Ian Campbell <[email protected]>…
Quoted 9 lines · FUJITA Tomonori
On Thu, 21 May 2009 17:15:21 +0100
Ian Campbell <[email protected]> wrote:
Please go with the following way (that I posted yesterday):http://marc.info/?l=xen-devel&m=124292666214380&w=2
Export the core feature of swiotlb, managing iotlb buffer and implement the Xen mapping functions.
Quoted 7 lines
I feel that should be a last resort, before we go down that path we should try and find a way for us to use the generic code in a clean way which makes everyone happy.
We have had several attempts at this and admittedly have not yet come up with something that satisfies everyone but I don't really think we have gotten to the point of admitting defeat and just duplicating the code.
There should not be much duplication.
Quoted 6 lines
Quoted 3 lines
I think the proposal to use a dma_map_range-like function which I sent a few minutes ago I think gets us closer to something which satisfies everyone's requirements, including yours for a clean abstraction.
Seems you don't understand the point; with dom0, we can't cleanly use
arch/*/include/asm/.I understand precisely what you are saying, I just fundamentally disagree with you. It is perfectly possible for an
arch/*/include/asminterface for this stuff to be defined which is completely abstracted from the POV of the swiotlb code (and any other arch-external code).
Quoted 8 lines
Quoted 1 line
You need to insert Xen's hook like this:
As I said in the email this snippet was contained in:
Quoted 3 lines
* The Xen specific stuff in
arch/x86/include/asm/dma-mapping.hclearly needs to be properly abstracted away (I just stuck it there for testing).So obviously I am well aware that it is unacceptable as it stands.
I don't think that you can't clean up the above much.
After all, you need a hook for Xen in arch/x86/include/asm/dma-mapping.h and define it in Xen's land.
That will not be much different from:
http://marc.info/?l=linux-kernel&m=124299344606890&w=2
And adding 'if xen' hook in common header files in arch/x86/include/ is a wrong design to me. Do you add a similar 'if xen' hook in other x86's common headers files?
Quoted 1 line
I think we can find a way to implement this functionality which is
k> contained entirely within the arch/x86 code and is also acceptable to
Quoted 1 line
the x86 maintainers. There are plenty of cases where we define similar
I'm not sure about it (hopefully, not). But if the x86 maintainers ACK the above code, I have no complaint.
Quoted 2 lines
interfaces where arch code implements an API with different backends for different configurations, hardware configurations etc etc.