Patch "cdx: fix driver managed dma support" has been added to the 6.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    cdx: fix driver managed dma support

to the 6.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     cdx-fix-driver-managed-dma-support.patch
and it can be found in the queue-6.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 083cad331436fbcc7cf7df19e1725eea1db6e2c3
Author: Nipun Gupta <nipun.gupta@xxxxxxx>
Date:   Mon Jun 5 18:40:09 2023 +0530

    cdx: fix driver managed dma support
    
    [ Upstream commit b8c5ff76059ded3758de3db83e04189a072ac01f ]
    
    The devices on cdx could be bound to drivers with the device
    DMA managed by kernel drivers or user-space applications.
    As multiple devices can be placed in the same IOMMU group, the
    DMA on these devices must either be entirely under kernel control
    or userspace control. Fix the CDX bus driver to acknowlege the
    driver_managed_dma flag and call the appropriate iommu APIs.
    
    Fixes: 2959ab247061 ("cdx: add the cdx bus driver")
    Signed-off-by: Nipun Gupta <nipun.gupta@xxxxxxx>
    Reported-by: Alex Williamson <alex.williamson@xxxxxxxxxx>
    Closes: https://lore.kernel.org/lkml/20230524134831.28dc97e2.alex.williamson@xxxxxxxxxx/
    Reviewed-by: Nikhil Agarwal <nikhil.agarwal@xxxxxxx>
    Message-ID: <20230605131009.6869-1-nipun.gupta@xxxxxxx>
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/cdx/cdx.c b/drivers/cdx/cdx.c
index 38511fd363257..d2cad4c670a07 100644
--- a/drivers/cdx/cdx.c
+++ b/drivers/cdx/cdx.c
@@ -62,6 +62,8 @@
 #include <linux/mm.h>
 #include <linux/xarray.h>
 #include <linux/cdx/cdx_bus.h>
+#include <linux/iommu.h>
+#include <linux/dma-map-ops.h>
 #include "cdx.h"
 
 /* Default DMA mask for devices on a CDX bus */
@@ -257,6 +259,7 @@ static void cdx_shutdown(struct device *dev)
 
 static int cdx_dma_configure(struct device *dev)
 {
+	struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver);
 	struct cdx_device *cdx_dev = to_cdx_device(dev);
 	u32 input_id = cdx_dev->req_id;
 	int ret;
@@ -267,9 +270,23 @@ static int cdx_dma_configure(struct device *dev)
 		return ret;
 	}
 
+	if (!ret && !cdx_drv->driver_managed_dma) {
+		ret = iommu_device_use_default_domain(dev);
+		if (ret)
+			arch_teardown_dma_ops(dev);
+	}
+
 	return 0;
 }
 
+static void cdx_dma_cleanup(struct device *dev)
+{
+	struct cdx_driver *cdx_drv = to_cdx_driver(dev->driver);
+
+	if (!cdx_drv->driver_managed_dma)
+		iommu_device_unuse_default_domain(dev);
+}
+
 /* show configuration fields */
 #define cdx_config_attr(field, format_string)	\
 static ssize_t	\
@@ -405,6 +422,7 @@ struct bus_type cdx_bus_type = {
 	.remove		= cdx_remove,
 	.shutdown	= cdx_shutdown,
 	.dma_configure	= cdx_dma_configure,
+	.dma_cleanup	= cdx_dma_cleanup,
 	.bus_groups	= cdx_bus_groups,
 	.dev_groups	= cdx_dev_groups,
 };



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux