]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/gpusvm: Introduce devmem_only flag for allocation
authorHimal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Mon, 12 May 2025 13:54:55 +0000 (06:54 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Wed, 14 May 2025 16:03:29 +0000 (09:03 -0700)
This commit adds a new flag, devmem_only, to the drm_gpusvm structure. The
purpose of this flag is to ensure that the get_pages function allocates
memory exclusively from the device's memory. If the allocation from
device memory fails, the function will return an -EFAULT error.

Required for shared CPU and GPU atomics on certain devices.

v3:
 - s/vram_only/devmem_only/

Fixes: 99624bdff867 ("drm/gpusvm: Add support for GPU Shared Virtual Memory")
Cc: stable@vger.kernel.org
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250512135500.1405019-2-matthew.brost@intel.com
(cherry picked from commit 8a9b978ebd47df9e0694c34748c2d6fa0c31eb4d)
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/drm_gpusvm.c
include/drm/drm_gpusvm.h

index de424e670995cfcdab528e97d6f980ed6f467715..a58d03e6cac277526344b156f7e5c9840cada6d6 100644 (file)
@@ -1454,6 +1454,11 @@ map_pages:
                                goto err_unmap;
                        }
 
+                       if (ctx->devmem_only) {
+                               err = -EFAULT;
+                               goto err_unmap;
+                       }
+
                        addr = dma_map_page(gpusvm->drm->dev,
                                            page, 0,
                                            PAGE_SIZE << order,
index df120b4d1f836c4871f8a54f1c2c1fbe29614a7e..9fd25fc880a4927f8bc1aff47af639d7d98e8a8a 100644 (file)
@@ -286,6 +286,7 @@ struct drm_gpusvm {
  * @in_notifier: entering from a MMU notifier
  * @read_only: operating on read-only memory
  * @devmem_possible: possible to use device memory
+ * @devmem_only: use only device memory
  *
  * Context that is DRM GPUSVM is operating in (i.e. user arguments).
  */
@@ -294,6 +295,7 @@ struct drm_gpusvm_ctx {
        unsigned int in_notifier :1;
        unsigned int read_only :1;
        unsigned int devmem_possible :1;
+       unsigned int devmem_only :1;
 };
 
 int drm_gpusvm_init(struct drm_gpusvm *gpusvm,