Patch "driver core: Add dma_cleanup callback in bus_type" has been added to the 5.15-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

    driver core: Add dma_cleanup callback in bus_type

to the 5.15-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:
     driver-core-add-dma_cleanup-callback-in-bus_type.patch
and it can be found in the queue-5.15 subdirectory.

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



commit e19e821c42d0f37d64153517b29687d3819dc188
Author: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
Date:   Mon Apr 18 08:49:51 2022 +0800

    driver core: Add dma_cleanup callback in bus_type
    
    [ Upstream commit 25f3bcfc54bcf7b0e45d140ec8bfbbf10ba11869 ]
    
    The bus_type structure defines dma_configure() callback for bus drivers
    to configure DMA on the devices. This adds the paired dma_cleanup()
    callback and calls it during driver unbinding so that bus drivers can do
    some cleanup work.
    
    One use case for this paired DMA callbacks is for the bus driver to check
    for DMA ownership conflicts during driver binding, where multiple devices
    belonging to a same IOMMU group (the minimum granularity of isolation and
    protection) may be assigned to kernel drivers or user space respectively.
    
    Without this change, for example, the vfio driver has to listen to a bus
    BOUND_DRIVER event and then BUG_ON() in case of dma ownership conflict.
    This leads to bad user experience since careless driver binding operation
    may crash the system if the admin overlooks the group restriction. Aside
    from bad design, this leads to a security problem as a root user, even with
    lockdown=integrity, can force the kernel to BUG.
    
    With this change, the bus driver could check and set the DMA ownership in
    driver binding process and fail on ownership conflicts. The DMA ownership
    should be released during driver unbinding.
    
    Signed-off-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>
    Reviewed-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Reviewed-by: Jason Gunthorpe <jgg@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20220418005000.897664-3-baolu.lu@xxxxxxxxxxxxxxx
    Signed-off-by: Joerg Roedel <jroedel@xxxxxxx>
    Stable-dep-of: 2e84dc379200 ("driver core: Release all resources during unbind before updating device links")
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 81683c99d6293..394ef41d732a9 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -669,6 +669,8 @@ static int really_probe(struct device *dev, struct device_driver *drv)
 	if (dev->bus)
 		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
 					     BUS_NOTIFY_DRIVER_NOT_BOUND, dev);
+	if (dev->bus && dev->bus->dma_cleanup)
+		dev->bus->dma_cleanup(dev);
 pinctrl_bind_failed:
 	device_links_no_driver(dev);
 	device_unbind_cleanup(dev);
@@ -1225,6 +1227,9 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 		else if (drv->remove)
 			drv->remove(dev);
 
+		if (dev->bus && dev->bus->dma_cleanup)
+			dev->bus->dma_cleanup(dev);
+
 		device_links_driver_cleanup(dev);
 		device_unbind_cleanup(dev);
 
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
index 062777a45a74d..a52a6fe39eec9 100644
--- a/include/linux/device/bus.h
+++ b/include/linux/device/bus.h
@@ -59,6 +59,8 @@ struct fwnode_handle;
  *		bus supports.
  * @dma_configure:	Called to setup DMA configuration on a device on
  *			this bus.
+ * @dma_cleanup:	Called to cleanup DMA configuration on a device on
+ *			this bus.
  * @pm:		Power management operations of this bus, callback the specific
  *		device driver's pm-ops.
  * @iommu_ops:  IOMMU specific operations for this bus, used to attach IOMMU
@@ -103,6 +105,7 @@ struct bus_type {
 	int (*num_vf)(struct device *dev);
 
 	int (*dma_configure)(struct device *dev);
+	void (*dma_cleanup)(struct device *dev);
 
 	const struct dev_pm_ops *pm;
 



[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