]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
swiotlb-xen: Enforce return of DMA_ERROR_CODE in mapping function
authorAlexander Duyck <alexander.h.duyck@intel.com>
Wed, 2 Nov 2016 11:12:47 +0000 (07:12 -0400)
committerKonrad Rzeszutek Wilk <konrad@kernel.org>
Mon, 7 Nov 2016 20:06:32 +0000 (15:06 -0500)
The mapping function should always return DMA_ERROR_CODE when a mapping has
failed as this is what the DMA API expects when a DMA error has occurred.
The current function for mapping a page in Xen was returning either
DMA_ERROR_CODE or 0 depending on where it failed.

On x86 DMA_ERROR_CODE is 0, but on other architectures such as ARM it is
~0. We need to make sure we return the same error value if either the
mapping failed or the device is not capable of accessing the mapping.

If we are returning DMA_ERROR_CODE as our error value we can drop the
function for checking the error code as the default is to compare the
return value against DMA_ERROR_CODE if no function is defined.

Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad@kernel.org>
arch/arm/xen/mm.c
arch/x86/xen/pci-swiotlb-xen.c
drivers/xen/swiotlb-xen.c
include/xen/swiotlb-xen.h

index d062f08f50200f10f54e779e4086ddd6c4bd10ca..bd62d94f8ac5b72cd54e73098ebd3eef89ca6415 100644 (file)
@@ -186,7 +186,6 @@ struct dma_map_ops *xen_dma_ops;
 EXPORT_SYMBOL(xen_dma_ops);
 
 static struct dma_map_ops xen_swiotlb_dma_ops = {
-       .mapping_error = xen_swiotlb_dma_mapping_error,
        .alloc = xen_swiotlb_alloc_coherent,
        .free = xen_swiotlb_free_coherent,
        .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
index 0e98e5d241d04847c7a9a54c242b7a232ebae148..a9fafb5c873897eec1685861180cf4ac5fd826e3 100644 (file)
@@ -19,7 +19,6 @@
 int xen_swiotlb __read_mostly;
 
 static struct dma_map_ops xen_swiotlb_dma_ops = {
-       .mapping_error = xen_swiotlb_dma_mapping_error,
        .alloc = xen_swiotlb_alloc_coherent,
        .free = xen_swiotlb_free_coherent,
        .sync_single_for_cpu = xen_swiotlb_sync_single_for_cpu,
index 87e6035c9e81b24e686e731519df528060dc1a68..b8014bf2b2ed6994f7d39b0d78c5e774230337d5 100644 (file)
@@ -416,11 +416,12 @@ dma_addr_t xen_swiotlb_map_page(struct device *dev, struct page *page,
        /*
         * Ensure that the address returned is DMA'ble
         */
-       if (!dma_capable(dev, dev_addr, size)) {
-               swiotlb_tbl_unmap_single(dev, map, size, dir);
-               dev_addr = 0;
-       }
-       return dev_addr;
+       if (dma_capable(dev, dev_addr, size))
+               return dev_addr;
+
+       swiotlb_tbl_unmap_single(dev, map, size, dir);
+
+       return DMA_ERROR_CODE;
 }
 EXPORT_SYMBOL_GPL(xen_swiotlb_map_page);
 
@@ -648,13 +649,6 @@ xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
 }
 EXPORT_SYMBOL_GPL(xen_swiotlb_sync_sg_for_device);
 
-int
-xen_swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr)
-{
-       return !dma_addr;
-}
-EXPORT_SYMBOL_GPL(xen_swiotlb_dma_mapping_error);
-
 /*
  * Return whether the given device DMA address mask can be supported
  * properly.  For example, if your device can only drive the low 24-bits
index 7c35e279d1e31515bc0060e1ce33006ae76a6a54..a0083be5d5295157bc11b82a343b58f798488bb8 100644 (file)
@@ -50,9 +50,6 @@ extern void
 xen_swiotlb_sync_sg_for_device(struct device *hwdev, struct scatterlist *sg,
                               int nelems, enum dma_data_direction dir);
 
-extern int
-xen_swiotlb_dma_mapping_error(struct device *hwdev, dma_addr_t dma_addr);
-
 extern int
 xen_swiotlb_dma_supported(struct device *hwdev, u64 mask);