]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
driver core: Replace dev->dma_skip_sync with dev_dma_skip_sync()
authorDouglas Anderson <dianders@chromium.org>
Mon, 6 Apr 2026 23:22:57 +0000 (16:22 -0700)
committerDanilo Krummrich <dakr@kernel.org>
Sun, 26 Apr 2026 21:38:57 +0000 (23:38 +0200)
In C, bitfields are not necessarily safe to modify from multiple
threads without locking. Switch "dma_skip_sync" over to the "flags"
field so modifications are safe.

Cc: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Christoph Hellwig <hch@lst.de>
Reviewed-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://patch.msgid.link/20260406162231.v5.4.Icf072aa4184dd86a88fa8ca195b09d1651984000@changeid
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
include/linux/device.h
include/linux/dma-map-ops.h
include/linux/dma-mapping.h
kernel/dma/mapping.c
mm/hmm.c

index bb02afb00f05ef4d8fd65f43e7ff052fba885ef4..cc93a5e1e5d23332c8ececd18627d245d318e611 100644 (file)
@@ -517,12 +517,15 @@ struct device_physical_location {
  *             until other devices probe successfully.
  * @DEV_FLAG_DMA_IOMMU: Device is using default IOMMU implementation for DMA and
  *             doesn't rely on dma_ops structure.
+ * @DEV_FLAG_DMA_SKIP_SYNC: DMA sync operations can be skipped for coherent
+ *             buffers.
  * @DEV_FLAG_COUNT: Number of defined struct_device_flags.
  */
 enum struct_device_flags {
        DEV_FLAG_READY_TO_PROBE = 0,
        DEV_FLAG_CAN_MATCH = 1,
        DEV_FLAG_DMA_IOMMU = 2,
+       DEV_FLAG_DMA_SKIP_SYNC = 3,
 
        DEV_FLAG_COUNT
 };
@@ -616,7 +619,6 @@ enum struct_device_flags {
  *             and optionall (if the coherent mask is large enough) also
  *             for dma allocations.  This flag is managed by the dma ops
  *             instance from ->dma_supported.
- * @dma_skip_sync: DMA sync operations can be skipped for coherent buffers.
  * @flags:     DEV_FLAG_XXX flags. Use atomic bitfield operations to modify.
  *
  * At the lowest level, every device in a Linux system is represented by an
@@ -733,9 +735,6 @@ struct device {
 #ifdef CONFIG_DMA_OPS_BYPASS
        bool                    dma_ops_bypass : 1;
 #endif
-#ifdef CONFIG_DMA_NEED_SYNC
-       bool                    dma_skip_sync:1;
-#endif
 
        DECLARE_BITMAP(flags, DEV_FLAG_COUNT);
 };
@@ -765,6 +764,7 @@ static inline bool dev_test_and_set_##accessor_name(struct device *dev) \
 __create_dev_flag_accessors(ready_to_probe, DEV_FLAG_READY_TO_PROBE);
 __create_dev_flag_accessors(can_match, DEV_FLAG_CAN_MATCH);
 __create_dev_flag_accessors(dma_iommu, DEV_FLAG_DMA_IOMMU);
+__create_dev_flag_accessors(dma_skip_sync, DEV_FLAG_DMA_SKIP_SYNC);
 
 #undef __create_dev_flag_accessors
 
index 6a1832a73cad8da449a4e2349f22341152305105..9e677a79f3a8f18d529a32c3ebbb0ff017700314 100644 (file)
@@ -240,8 +240,8 @@ static inline void dma_reset_need_sync(struct device *dev)
 {
 #ifdef CONFIG_DMA_NEED_SYNC
        /* Reset it only once so that the function can be called on hotpath */
-       if (unlikely(dev->dma_skip_sync))
-               dev->dma_skip_sync = false;
+       if (unlikely(dev_dma_skip_sync(dev)))
+               dev_clear_dma_skip_sync(dev);
 #endif
 }
 
index db8ab24a54f4a375cdb597683e925312f5b422a9..cc0823a99cfdb5c6917a551df7f68c1587e1781c 100644 (file)
@@ -429,7 +429,7 @@ bool __dma_need_sync(struct device *dev, dma_addr_t dma_addr);
 static inline bool dma_dev_need_sync(const struct device *dev)
 {
        /* Always call DMA sync operations when debugging is enabled */
-       return !dev->dma_skip_sync || IS_ENABLED(CONFIG_DMA_API_DEBUG);
+       return !dev_dma_skip_sync(dev) || IS_ENABLED(CONFIG_DMA_API_DEBUG);
 }
 
 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t addr,
index 23ed8eb9233e552fe520cec14caba4508babc072..a81a316971ff4a278796a921d4a5984b03a62a6e 100644 (file)
@@ -476,7 +476,7 @@ bool dma_need_unmap(struct device *dev)
 {
        if (!dma_map_direct(dev, get_dma_ops(dev)))
                return true;
-       if (!dev->dma_skip_sync)
+       if (!dev_dma_skip_sync(dev))
                return true;
        return IS_ENABLED(CONFIG_DMA_API_DEBUG);
 }
@@ -492,16 +492,16 @@ static void dma_setup_need_sync(struct device *dev)
                 * mapping, if any. During the device initialization, it's
                 * enough to check only for the DMA coherence.
                 */
-               dev->dma_skip_sync = dev_is_dma_coherent(dev);
+               dev_assign_dma_skip_sync(dev, dev_is_dma_coherent(dev));
        else if (!ops->sync_single_for_device && !ops->sync_single_for_cpu &&
                 !ops->sync_sg_for_device && !ops->sync_sg_for_cpu)
                /*
                 * Synchronization is not possible when none of DMA sync ops
                 * is set.
                 */
-               dev->dma_skip_sync = true;
+               dev_set_dma_skip_sync(dev);
        else
-               dev->dma_skip_sync = false;
+               dev_clear_dma_skip_sync(dev);
 }
 #else /* !CONFIG_DMA_NEED_SYNC */
 static inline void dma_setup_need_sync(struct device *dev) { }
index 5955f2f0c83db180cd9ae781214ccde2a8eeaed6..c72c9ddfdb2f62712134503cab50282045a9837c 100644 (file)
--- a/mm/hmm.c
+++ b/mm/hmm.c
@@ -709,7 +709,7 @@ int hmm_dma_map_alloc(struct device *dev, struct hmm_dma_map *map,
         * best approximation to ensure no swiotlb buffering happens.
         */
 #ifdef CONFIG_DMA_NEED_SYNC
-       dma_need_sync = !dev->dma_skip_sync;
+       dma_need_sync = !dev_dma_skip_sync(dev);
 #endif /* CONFIG_DMA_NEED_SYNC */
        if (dma_need_sync || dma_addressing_limited(dev))
                return -EOPNOTSUPP;