drm/xe: SVM squash for CI
Subsystems (9)
Matthew Brost
maintainerPATCH v6 1/1 drm/xe: SVM squash for CI
Fixing Kconfig issues, kernel doc, sending for CI. Do not review.
--- Documentation/gpu/rfc/gpusvm.rst | 84 + Documentation/gpu/rfc/index.rst | 4 + drivers/gpu/drm/Kconfig | 9 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_gpusvm.c | 2236 +++++++++++++++++++ drivers/gpu/drm/xe/Kconfig | 10 + drivers/gpu/drm/xe/Makefile | 1 + drivers/gpu/drm/xe/xe_bo.c | 54 + drivers/gpu/drm/xe/xe_bo.h | 20 + drivers/gpu/drm/xe/xe_bo_types.h | 4 + drivers/gpu/drm/xe/xe_device.c | 3 + drivers/gpu/drm/xe/xe_device_types.h | 22 + drivers/gpu/drm/xe/xe_gt_pagefault.c | 18 +- drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c | 22 + drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h | 2 + drivers/gpu/drm/xe/xe_migrate.c | 175 ++ drivers/gpu/drm/xe/xe_migrate.h | 10 + drivers/gpu/drm/xe/xe_module.c | 7 + drivers/gpu/drm/xe/xe_module.h | 2 + drivers/gpu/drm/xe/xe_pt.c | 393 +++- drivers/gpu/drm/xe/xe_pt.h | 5 + drivers/gpu/drm/xe/xe_pt_types.h | 2 + drivers/gpu/drm/xe/xe_query.c | 5 +- drivers/gpu/drm/xe/xe_res_cursor.h | 123 +- drivers/gpu/drm/xe/xe_svm.c | 946 ++++++++ drivers/gpu/drm/xe/xe_svm.h | 150 ++ drivers/gpu/drm/xe/xe_tile.c | 5 + drivers/gpu/drm/xe/xe_vm.c | 386 +++- drivers/gpu/drm/xe/xe_vm.h | 15 +- drivers/gpu/drm/xe/xe_vm_types.h | 57 + include/drm/drm_gpusvm.h | 509 +++++ include/drm/drm_gpuvm.h | 5 + include/drm/drm_pagemap.h | 109 + include/linux/migrate.h | 1 + include/uapi/drm/xe_drm.h | 22 +- mm/memory.c | 13 +- mm/migrate_device.c | 116 +- 37 files changed, 5393 insertions(+), 153 deletions(-) create mode 100644 Documentation/gpu/rfc/gpusvm.rst create mode 100644 drivers/gpu/drm/drm_gpusvm.c create mode 100644 drivers/gpu/drm/xe/xe_svm.c create mode 100644 drivers/gpu/drm/xe/xe_svm.h create mode 100644 include/drm/drm_gpusvm.h create mode 100644 include/drm/drm_pagemap.h
Documentation/gpu/rfc/gpusvm.rst new file +84 -0
@@ -0,0 +1,84 @@ +=============== +GPU SVM Section +=============== + +Agreed upon design principles +============================= + +* migrate_to_ram path + * Rely only on core MM concepts (migration PTEs, page references, and + page locking). + * No driver specific locks other than locks for hardware interaction in + this path. These are not required and generally a bad idea to + invent driver defined locks to seal core MM races. + * Partial migration is supported (i.e., a subset of pages attempting to + migrate can actually migrate, with only the faulting page guaranteed + to migrate). + * Driver handles mixed migrations via retry loops rather than locking. +* Eviction + * Only looking at physical memory data structures and locks as opposed to + looking at virtual memory data structures and locks. + * No looking at mm/vma structs or relying on those being locked. +* GPU fault side + * mmap_read only used around core MM functions which require this lock + and should strive to take mmap_read lock only in GPU SVM layer. + * Big retry loop to handle all races with the mmu notifier under the gpu + pagetable locks/mmu notifier range lock/whatever we end up calling + those. + * Races (especially against concurrent eviction or migrate_to_ram) + should not be handled on the fault side by trying to hold locks; + rather, they should be handled using retry loops. One possible + exception is holding a BO's dma-resv lock during the initial migration + to VRAM, as this is a well-defined lock that can be taken underneath + the mmap_read lock. +* Physical memory to virtual backpointer + * Does not work, no pointers from physical memory to virtual should + exist. + * Physical memory backpointer (page->zone_device_data) should be stable + from allocation to page free. +* GPU pagetable locking + * Notifier lock only protects range tree, pages valid state for a range + (rather than seqno due to wider notifiers), pagetable entries, and + mmu notifier seqno tracking, it is not a global lock to protect + against races. + * All races handled with big retry as mentioned above. + +Overview of current design +========================== + +Baseline design is simple as possible to get a working basline in which can be +built upon. + +.. kernel-doc:: drivers/gpu/drm/xe/drm_gpusvm.c + :doc: Overview + :doc: Locking + :doc: Migrataion + :doc: Partial Unmapping of Ranges + :doc: Examples + +Possible future design features +=============================== + +* Concurrent GPU faults + * CPU faults are concurrent so makes sense to have concurrent GPU + faults. + * Should be possible with fined grained locking in the driver GPU + fault handler. + * No expected GPU SVM changes required. +* Ranges with mixed system and device pages + * Can be added if required to drm_gpusvm_get_pages fairly easily. +* Multi-GPU support + * Work in progress and patches expected after initially landing on GPU + SVM. + * Ideally can be done with little to no changes to GPU SVM. +* Drop ranges in favor of radix tree + * May be desirable for faster notifiers. +* Compound device pages + * Nvidia, AMD, and Intel all have agreed expensive core MM functions in + migrate device layer are a performance bottleneck, having compound + device pages should help increase performance by reducing the number + of these expensive calls. +* Higher order dma mapping for migration + * 4k dma mapping adversely affects migration performance on Intel + hardware, higher order (2M) dma mapping should help here. +* Build common userptr implementation on top of GPU SVM
Documentation/gpu/rfc/index.rst +4 -0
@@ -16,6 +16,10 @@ host such documentation: * Once the code has landed move all the documentation to the right places in the main core, helper or driver sections. +.. toctree:: + + gpusvm.rst + .. toctree:: i915_gem_lmem.rst
drivers/gpu/drm/Kconfig +9 -0
@@ -278,6 +278,15 @@ config DRM_GPUVM GPU-VM representation providing helpers to manage a GPUs virtual address space +config DRM_GPUSVM + tristate + depends on DRM && DEVICE_PRIVATE + select HMM_MIRROR + select MMU_NOTIFIER + help + GPU-SVM representation providing helpers to manage a GPUs shared + virtual memory + config DRM_BUDDY tristate depends on DRM
drivers/gpu/drm/Makefile +1 -0
@@ -104,6 +104,7 @@ obj-$(CONFIG_DRM_PANEL_BACKLIGHT_QUIRKS) += drm_panel_backlight_quirks.o # obj-$(CONFIG_DRM_EXEC) += drm_exec.o obj-$(CONFIG_DRM_GPUVM) += drm_gpuvm.o +obj-$(CONFIG_DRM_GPUSVM) += drm_gpusvm.o obj-$(CONFIG_DRM_BUDDY) += drm_buddy.o
drivers/gpu/drm/drm_gpusvm.c new file +2236 -0
2,236 lines not on this page · raw message
drivers/gpu/drm/xe/Kconfig +10 -0
@@ -39,6 +39,7 @@ config DRM_XE select DRM_TTM_HELPER select DRM_EXEC select DRM_GPUVM + select DRM_GPUSVM if !UML && DEVICE_PRIVATE select DRM_SCHED select MMU_NOTIFIER select WANT_DEV_COREDUMP
@@ -73,6 +74,15 @@ config DRM_XE_DP_TUNNEL If in doubt say "Y". +config DRM_XE_DEVMEM_MIRROR + bool "Enable device memory mirror" + depends on DRM_XE + select GET_FREE_REGION + default y + help + Disable this option only if you want to compile out without device + memory mirror. Will reduce KMD memory footprint when disabled. + config DRM_XE_FORCE_PROBE string "Force probe xe for selected Intel hardware IDs" depends on DRM_XE
drivers/gpu/drm/xe/Makefile +1 -0
@@ -123,6 +123,7 @@ xe-y += xe_bb.o \ xe_wopcm.o xe-$(CONFIG_HMM_MIRROR) += xe_hmm.o +xe-$(CONFIG_DRM_GPUSVM) += xe_svm.o # graphics hardware monitoring (HWMON) support xe-$(CONFIG_HWMON) += xe_hwmon.o
drivers/gpu/drm/xe/xe_bo.c +54 -0
96 lines not on this page · raw message
drivers/gpu/drm/xe/xe_bo.h +20 -0
@@ -47,6 +47,7 @@ XE_BO_FLAG_GGTT1 | \ XE_BO_FLAG_GGTT2 | \ XE_BO_FLAG_GGTT3) +#define XE_BO_FLAG_CPU_ADDR_MIRROR BIT(22)/* this one is trigger internally only */ #define XE_BO_FLAG_INTERNAL_TEST BIT(30)
@@ -323,6 +324,25 @@ xe_bo_put_deferred(struct xe_bo *bo, struct llist_head *deferred)void xe_bo_put_commit (struct llist_head *deferred); +/** +* xe_bo_put_async() - Put BO async +* @bo: The bo to put. +* +* Put BO async, the final put is deferred to a worker to exit an IRQ context. +*/ +static inline void +xe_bo_put_async (struct xe_bo *bo) +{ +struct xe_bo_dev *bo_device = &xe_bo_device (bo)->bo_device; + +if (xe_bo_put_deferred (bo, &bo_device->async_list)) +schedule_work (&bo_device->async_free); +} + +void xe_bo_dev_init (struct xe_bo_dev *bo_device); + +void xe_bo_dev_fini (struct xe_bo_dev *bo_device); +struct sg_table *xe_bo_sg (struct xe_bo *bo);/*
drivers/gpu/drm/xe/xe_bo_types.h +4 -0
@@ -8,6 +8,7 @@#include <linux/iosys-map.h> +#include <drm/drm_gpusvm.h> #include <drm/ttm/ttm_bo.h> #include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_placement.h>
@@ -80,6 +81,9 @@ struct xe_bo {*/ u16 cpu_caching; +/** @devmem_allocation: SVM device memory allocation */ +struct drm_gpusvm_devmem devmem_allocation; +/** @vram_userfault_link: Link into @mem_access.vram_userfault.list */ struct list_head vram_userfault_link;
drivers/gpu/drm/xe/xe_device.c +3 -0
@@ -394,6 +394,8 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy) {struct xe_device *xe =to_xe_device (dev); +xe_bo_dev_fini (&xe->bo_device); +if (xe->preempt_fence_wq)destroy_workqueue (xe->preempt_fence_wq);
@@ -431,6 +433,7 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,if (WARN_ON (err)) goto err; +xe_bo_dev_init (&xe->bo_device); err =drmm_add_action_or_reset (&xe->drm, xe_device_destroy,NULL );if (err) goto err;
drivers/gpu/drm/xe/xe_device_types.h +22 -0
@@ -10,6 +10,7 @@#include <drm/drm_device.h> #include <drm/drm_file.h> +#include <drm/drm_pagemap.h> #include <drm/ttm/ttm_device.h> #include "xe_devcoredump_types.h"
@@ -106,6 +107,19 @@ struct xe_vram_region {resource_size_t actual_physical_size;/** @mapping: pointer to VRAM mappable space */ void __iomem *mapping; +/** @pagemap: Used to remap device memory as ZONE_DEVICE */ +struct dev_pagemap pagemap; +/** +* @dpagemap: The struct drm_pagemap of the ZONE_DEVICE memory +* pages of this tile. +*/ +struct drm_pagemap dpagemap; +/** +* @hpa_base: base host physical address +* +* This is generated when remap device memory as ZONE_DEVICE +*/ +resource_size_t hpa_base;/** @ttm: VRAM TTM manager */ struct xe_ttm_vram_mgr ttm; };
@@ -539,6 +553,14 @@ struct xe_device {int mode; } wedged; +/** @bo_device: Struct to control async free of BOs */ +struct xe_bo_dev { +/** @bo_device.async_free: Free worker */ +struct work_struct async_free; +/** @bo_device.async_list: List of BOs to be freed */ +struct llist_head async_list; + } bo_device; +/** @pmu: performance monitoring unit */ struct xe_pmu pmu;
drivers/gpu/drm/xe/xe_gt_pagefault.c +13 -5
@@ -19,6 +19,7 @@#include "xe_guc.h" #include "xe_guc_ct.h" #include "xe_migrate.h" +#include "xe_svm.h" #include "xe_trace_bo.h" #include "xe_vm.h"
@@ -125,8 +126,8 @@ static int xe_pf_begin(struct drm_exec *exec, struct xe_vma *vma,return 0 ; } -static int handle_vma_pagefault (struct xe_gt *gt,struct pagefault *pf, -struct xe_vma *vma) +static int handle_vma_pagefault (struct xe_gt *gt,struct xe_vma *vma, +bool atomic) {struct xe_vm *vm =xe_vma_vm (vma);struct xe_tile *tile =gt_to_tile (gt);
@@ -134,13 +135,13 @@ static int handle_vma_pagefault(struct xe_gt *gt, struct pagefault *pf,struct dma_fence *fence;ktime_t end =0 ;int err; -bool atomic; + +lockdep_assert_held_write (&vm->lock);xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_COUNT ,1 );xe_gt_stats_incr (gt,XE_GT_STATS_ID_VMA_PAGEFAULT_BYTES ,xe_vma_size (vma));trace_xe_vma_pagefault (vma); - atomic =access_is_atomic (pf->access_type);/* Check if VMA is valid */ if (vma_is_valid (tile, vma) && !atomic)
@@ -210,6 +211,7 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf)struct xe_vm *vm;struct xe_vma *vma =NULL ;int err; +bool atomic;/* SW isn't expected to handle TRTT faults */ if (pf->trva_fault)
@@ -235,7 +237,13 @@ static int handle_pagefault(struct xe_gt *gt, struct pagefault *pf) goto unlock_vm; } - err =handle_vma_pagefault (gt, pf, vma); + atomic =access_is_atomic (pf->access_type); + +if (xe_vma_is_cpu_addr_mirror (vma)) + err =xe_svm_handle_pagefault (vm, vma,gt_to_tile (gt), + pf->page_addr, atomic); +else + err =handle_vma_pagefault (gt, vma, atomic); unlock_vm:if (!err)
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.c +22 -0
@@ -410,6 +410,28 @@ int xe_gt_tlb_invalidation_range(struct xe_gt *gt,return send_tlb_invalidation (>->uc.guc, fence, action, len); } +/** +* xe_gt_tlb_invalidation_vm - Issue a TLB invalidation on this GT for a VM +* @gt: graphics tile +* @vm: VM to invalidate +* +* Invalidate entire VM's address space +*/ +void xe_gt_tlb_invalidation_vm (struct xe_gt *gt,struct xe_vm *vm) +{ +struct xe_gt_tlb_invalidation_fence fence; +u64 range =1ull << vm->xe->info.va_bits; +int ret; + +xe_gt_tlb_invalidation_fence_init (gt, &fence, true); + + ret =xe_gt_tlb_invalidation_range (gt, &fence,0 , range, vm->usm.asid); +if (ret <0 ) +return ; + +xe_gt_tlb_invalidation_fence_wait (&fence); +} +/** * xe_gt_tlb_invalidation_vma - Issue a TLB invalidation on this GT for a VMA * @gt: GT structure
drivers/gpu/drm/xe/xe_gt_tlb_invalidation.h +2 -0
@@ -12,6 +12,7 @@struct xe_gt ;struct xe_guc ; +struct xe_vm ;struct xe_vma ;int xe_gt_tlb_invalidation_init_early (struct xe_gt *gt);
@@ -21,6 +22,7 @@ int xe_gt_tlb_invalidation_ggtt(struct xe_gt *gt);int xe_gt_tlb_invalidation_vma (struct xe_gt *gt,struct xe_gt_tlb_invalidation_fence *fence,struct xe_vma *vma); +void xe_gt_tlb_invalidation_vm (struct xe_gt *gt,struct xe_vm *vm);int xe_gt_tlb_invalidation_range (struct xe_gt *gt,struct xe_gt_tlb_invalidation_fence *fence,u64 start,u64 end,u32 asid);
drivers/gpu/drm/xe/xe_migrate.c +175 -0
181 lines not on this page · raw message
drivers/gpu/drm/xe/xe_migrate.h +10 -0
@@ -95,6 +95,16 @@ struct xe_migrate_pt_update {struct xe_migrate *xe_migrate_init (struct xe_tile *tile); +struct dma_fence *xe_migrate_to_vram (struct xe_migrate *m, +unsigned long npages, +dma_addr_t *src_addr, +u64 dst_addr); + +struct dma_fence *xe_migrate_from_vram (struct xe_migrate *m, +unsigned long npages, +u64 src_addr, +dma_addr_t *dst_addr); + struct dma_fence *xe_migrate_copy(struct xe_migrate *m, struct xe_bo *src_bo, struct xe_bo *dst_bo,
drivers/gpu/drm/xe/xe_module.c +7 -0
@@ -25,9 +25,16 @@ struct xe_modparam xe_modparam = { .max_vfs = IS_ENABLED(CONFIG_DRM_XE_DEBUG) ? ~0 : 0, #endif .wedged_mode = 1, + .svm_notifier_size =512 ,/* the rest are 0 by default */ }; +module_param_named (svm_notifier_size, xe_modparam.svm_notifier_size, uint,0600 ); +MODULE_PARM_DESC (svm_notifier_size,"Set the svm notifier size(in MiB), must be power of 2" ); + +module_param_named (always_migrate_to_vram, xe_modparam.always_migrate_to_vram, bool,0444 ); +MODULE_PARM_DESC (always_migrate_to_vram,"Always migrate to VRAM on GPU fault" ); +module_param_named_unsafe (force_execlist, xe_modparam.force_execlist, bool,0444 );MODULE_PARM_DESC (force_execlist,"Force Execlist submission" );
drivers/gpu/drm/xe/xe_module.h +2 -0
@@ -12,6 +12,7 @@struct xe_modparam {bool force_execlist;bool probe_display; +bool always_migrate_to_vram;u32 force_vram_bar_size;int guc_log_level;char *guc_firmware_path;
@@ -22,6 +23,7 @@ struct xe_modparam {unsigned int max_vfs;#endif int wedged_mode; +u32 svm_notifier_size; };extern struct xe_modparam xe_modparam;
drivers/gpu/drm/xe/xe_pt.c +343 -50
98 lines not on this page · raw message
drivers/gpu/drm/xe/xe_res_cursor.h +121 -2
123 lines not on this page · raw message
drivers/gpu/drm/xe/xe_svm.c new file +946 -0
946 lines not on this page · raw message
drivers/gpu/drm/xe/xe_svm.h new file +150 -0
150 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm.c +330 -56
386 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vm_types.h +57 -0
57 lines not on this page · raw message
include/drm/drm_gpusvm.h new file +509 -0
509 lines not on this page · raw message
include/drm/drm_pagemap.h new file +109 -0
109 lines not on this page · raw message
mm/migrate_device.c +83 -33
116 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Patchwork
CI✗ CI.Patch_applied: failure for drm/xe: SVM squash for CI
== Series Details ==
== Series Details ==
Series: drm/xe: SVM squash for CI
URL : https://patchwork.freedesktop.org/series/145551/
State : failure
== Summary ==
=== Applying kernel patches on branch 'drm-tip' with base: ===
Base commit: 8541a64154cd drm-tip: 2025y-02m-26d-23h-59m-28s UTC integration manifest === git am output follows ===
error: patch failed: drivers/gpu/drm/xe/xe_gt_pagefault.c:134
error: drivers/gpu/drm/xe/xe_gt_pagefault.c: patch does not apply
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Applying: drm/xe: SVM squash for CI
Patch failed at 0001 drm/xe: SVM squash for CI
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".