diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2014-01-20 06:30:41 -0500 |
---|---|---|
committer | Stefano Stabellini <stefano.stabellini@eu.citrix.com> | 2014-01-30 07:54:20 -0500 |
commit | e17b2f114cba5420fb28fa4bfead57d406a16533 (patch) | |
tree | 0a30053f6a3cc7bcf835b4acb61aa7a0a2d3c19b /drivers/xen/swiotlb-xen.c | |
parent | 8b271d57b57585a3e3e8cd7abc5f4d7710a0e62d (diff) |
xen: swiotlb: handle sizeof(dma_addr_t) != sizeof(phys_addr_t)
The use of phys_to_machine and machine_to_phys in the phys<=>bus conversions
causes us to lose the top bits of the DMA address if the size of a DMA address is not the same as the size of the phyiscal address.
This can happen in practice on ARM where foreign pages can be above 4GB even
though the local kernel does not have LPAE page tables enabled (which is
totally reasonable if the guest does not itself have >4GB of RAM). In this
case the kernel still maps the foreign pages at a phys addr below 4G (as it
must) but the resulting DMA address (returned by the grant map operation) is
much higher.
This is analogous to a hardware device which has its view of RAM mapped up
high for some reason.
This patch makes I/O to foreign pages (specifically blkif) work on 32-bit ARM
systems with more than 4GB of RAM.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Diffstat (limited to 'drivers/xen/swiotlb-xen.c')
-rw-r--r-- | drivers/xen/swiotlb-xen.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c index 1eac0731c349..ebd8f218a788 100644 --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c | |||
@@ -75,14 +75,32 @@ static unsigned long xen_io_tlb_nslabs; | |||
75 | 75 | ||
76 | static u64 start_dma_addr; | 76 | static u64 start_dma_addr; |
77 | 77 | ||
78 | /* | ||
79 | * Both of these functions should avoid PFN_PHYS because phys_addr_t | ||
80 | * can be 32bit when dma_addr_t is 64bit leading to a loss in | ||
81 | * information if the shift is done before casting to 64bit. | ||
82 | */ | ||
78 | static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr) | 83 | static inline dma_addr_t xen_phys_to_bus(phys_addr_t paddr) |
79 | { | 84 | { |
80 | return phys_to_machine(XPADDR(paddr)).maddr; | 85 | unsigned long mfn = pfn_to_mfn(PFN_DOWN(paddr)); |
86 | dma_addr_t dma = (dma_addr_t)mfn << PAGE_SHIFT; | ||
87 | |||
88 | dma |= paddr & ~PAGE_MASK; | ||
89 | |||
90 | return dma; | ||
81 | } | 91 | } |
82 | 92 | ||
83 | static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr) | 93 | static inline phys_addr_t xen_bus_to_phys(dma_addr_t baddr) |
84 | { | 94 | { |
85 | return machine_to_phys(XMADDR(baddr)).paddr; | 95 | unsigned long pfn = mfn_to_pfn(PFN_DOWN(baddr)); |
96 | dma_addr_t dma = (dma_addr_t)pfn << PAGE_SHIFT; | ||
97 | phys_addr_t paddr = dma; | ||
98 | |||
99 | BUG_ON(paddr != dma); /* truncation has occurred, should never happen */ | ||
100 | |||
101 | paddr |= baddr & ~PAGE_MASK; | ||
102 | |||
103 | return paddr; | ||
86 | } | 104 | } |
87 | 105 | ||
88 | static inline dma_addr_t xen_virt_to_bus(void *address) | 106 | static inline dma_addr_t xen_virt_to_bus(void *address) |