Merge tag 'drm-xe-fixes-2025-04-18' of https://gitlab.freedesktop.org/drm/xe/kernel into drm-fixes

Driver Changes:
- Fix LRC address being written too late for GuC
- Fix notifier vs folio deadlock
- Fix race betwen dma_buf unmap and vram eviction
- Fix debugfs handling PXP terminations unconditionally

Signed-off-by: Dave Airlie <airlied@redhat.com>

From: Lucas De Marchi <lucas.demarchi@intel.com>
Link: https://lore.kernel.org/r/ndinq644zenywaaycxyfqqivsb2xer4z7err3dlpalbz33jfkm@ttabzsg6wnet

+57 -60
+1 -4
drivers/gpu/drm/xe/xe_dma_buf.c
··· 145 struct sg_table *sgt, 146 enum dma_data_direction dir) 147 { 148 - struct dma_buf *dma_buf = attach->dmabuf; 149 - struct xe_bo *bo = gem_to_xe_bo(dma_buf->priv); 150 - 151 - if (!xe_bo_is_vram(bo)) { 152 dma_unmap_sgtable(attach->dev, sgt, dir, 0); 153 sg_free_table(sgt); 154 kfree(sgt);
··· 145 struct sg_table *sgt, 146 enum dma_data_direction dir) 147 { 148 + if (sg_page(sgt->sgl)) { 149 dma_unmap_sgtable(attach->dev, sgt, dir, 0); 150 sg_free_table(sgt); 151 kfree(sgt);
+45 -30
drivers/gpu/drm/xe/xe_guc_ads.c
··· 490 engine_enable_mask(gt, XE_ENGINE_CLASS_OTHER)); 491 } 492 493 - static void guc_prep_golden_lrc_null(struct xe_guc_ads *ads) 494 { 495 struct xe_device *xe = ads_to_xe(ads); 496 struct iosys_map info_map = IOSYS_MAP_INIT_OFFSET(ads_to_map(ads), 497 offsetof(struct __guc_ads_blob, system_info)); 498 - u8 guc_class; 499 500 - for (guc_class = 0; guc_class <= GUC_MAX_ENGINE_CLASSES; ++guc_class) { 501 if (!info_map_read(xe, &info_map, 502 engine_enabled_masks[guc_class])) 503 continue; 504 505 ads_blob_write(ads, ads.eng_state_size[guc_class], 506 - guc_ads_golden_lrc_size(ads) - 507 - xe_lrc_skip_size(xe)); 508 ads_blob_write(ads, ads.golden_context_lrca[guc_class], 509 - xe_bo_ggtt_addr(ads->bo) + 510 - guc_ads_golden_lrc_offset(ads)); 511 } 512 } 513 ··· 885 886 xe_map_memset(ads_to_xe(ads), ads_to_map(ads), 0, 0, ads->bo->size); 887 guc_policies_init(ads); 888 - guc_prep_golden_lrc_null(ads); 889 guc_mapping_table_init_invalid(gt, &info_map); 890 guc_doorbell_init(ads); 891 ··· 911 guc_policies_init(ads); 912 fill_engine_enable_masks(gt, &info_map); 913 guc_mmio_reg_state_init(ads); 914 - guc_prep_golden_lrc_null(ads); 915 guc_mapping_table_init(gt, &info_map); 916 guc_capture_prep_lists(ads); 917 guc_doorbell_init(ads); ··· 931 guc_ads_private_data_offset(ads)); 932 } 933 934 - static void guc_populate_golden_lrc(struct xe_guc_ads *ads) 935 { 936 struct xe_device *xe = ads_to_xe(ads); 937 struct xe_gt *gt = ads_to_gt(ads); 938 struct iosys_map info_map = IOSYS_MAP_INIT_OFFSET(ads_to_map(ads), 939 offsetof(struct __guc_ads_blob, system_info)); 940 size_t total_size = 0, alloc_size, real_size; 941 - u32 addr_ggtt, offset; 942 int class; 943 944 offset = guc_ads_golden_lrc_offset(ads); 945 - addr_ggtt = xe_bo_ggtt_addr(ads->bo) + offset; 946 947 for (class = 0; class < XE_ENGINE_CLASS_MAX; ++class) { 948 u8 guc_class; ··· 963 alloc_size = PAGE_ALIGN(real_size); 964 total_size += alloc_size; 965 966 - /* 967 - * This interface is slightly confusing. We need to pass the 968 - * base address of the full golden context and the size of just 969 - * the engine state, which is the section of the context image 970 - * that starts after the execlists LRC registers. This is 971 - * required to allow the GuC to restore just the engine state 972 - * when a watchdog reset occurs. 973 - * We calculate the engine state size by removing the size of 974 - * what comes before it in the context image (which is identical 975 - * on all engines). 976 - */ 977 - ads_blob_write(ads, ads.eng_state_size[guc_class], 978 - real_size - xe_lrc_skip_size(xe)); 979 - ads_blob_write(ads, ads.golden_context_lrca[guc_class], 980 - addr_ggtt); 981 - 982 xe_map_memcpy_to(xe, ads_to_map(ads), offset, 983 gt->default_lrc[class], real_size); 984 985 - addr_ggtt += alloc_size; 986 offset += alloc_size; 987 } 988 ··· 974 975 void xe_guc_ads_populate_post_load(struct xe_guc_ads *ads) 976 { 977 - guc_populate_golden_lrc(ads); 978 } 979 980 static int guc_ads_action_update_policies(struct xe_guc_ads *ads, u32 policy_offset)
··· 490 engine_enable_mask(gt, XE_ENGINE_CLASS_OTHER)); 491 } 492 493 + /* 494 + * Write the offsets corresponding to the golden LRCs. The actual data is 495 + * populated later by guc_golden_lrc_populate() 496 + */ 497 + static void guc_golden_lrc_init(struct xe_guc_ads *ads) 498 { 499 struct xe_device *xe = ads_to_xe(ads); 500 + struct xe_gt *gt = ads_to_gt(ads); 501 struct iosys_map info_map = IOSYS_MAP_INIT_OFFSET(ads_to_map(ads), 502 offsetof(struct __guc_ads_blob, system_info)); 503 + size_t alloc_size, real_size; 504 + u32 addr_ggtt, offset; 505 + int class; 506 507 + offset = guc_ads_golden_lrc_offset(ads); 508 + addr_ggtt = xe_bo_ggtt_addr(ads->bo) + offset; 509 + 510 + for (class = 0; class < XE_ENGINE_CLASS_MAX; ++class) { 511 + u8 guc_class; 512 + 513 + guc_class = xe_engine_class_to_guc_class(class); 514 + 515 if (!info_map_read(xe, &info_map, 516 engine_enabled_masks[guc_class])) 517 continue; 518 519 + real_size = xe_gt_lrc_size(gt, class); 520 + alloc_size = PAGE_ALIGN(real_size); 521 + 522 + /* 523 + * This interface is slightly confusing. We need to pass the 524 + * base address of the full golden context and the size of just 525 + * the engine state, which is the section of the context image 526 + * that starts after the execlists LRC registers. This is 527 + * required to allow the GuC to restore just the engine state 528 + * when a watchdog reset occurs. 529 + * We calculate the engine state size by removing the size of 530 + * what comes before it in the context image (which is identical 531 + * on all engines). 532 + */ 533 ads_blob_write(ads, ads.eng_state_size[guc_class], 534 + real_size - xe_lrc_skip_size(xe)); 535 ads_blob_write(ads, ads.golden_context_lrca[guc_class], 536 + addr_ggtt); 537 + 538 + addr_ggtt += alloc_size; 539 } 540 } 541 ··· 857 858 xe_map_memset(ads_to_xe(ads), ads_to_map(ads), 0, 0, ads->bo->size); 859 guc_policies_init(ads); 860 + guc_golden_lrc_init(ads); 861 guc_mapping_table_init_invalid(gt, &info_map); 862 guc_doorbell_init(ads); 863 ··· 883 guc_policies_init(ads); 884 fill_engine_enable_masks(gt, &info_map); 885 guc_mmio_reg_state_init(ads); 886 + guc_golden_lrc_init(ads); 887 guc_mapping_table_init(gt, &info_map); 888 guc_capture_prep_lists(ads); 889 guc_doorbell_init(ads); ··· 903 guc_ads_private_data_offset(ads)); 904 } 905 906 + /* 907 + * After the golden LRC's are recorded for each engine class by the first 908 + * submission, copy them to the ADS, as initialized earlier by 909 + * guc_golden_lrc_init(). 910 + */ 911 + static void guc_golden_lrc_populate(struct xe_guc_ads *ads) 912 { 913 struct xe_device *xe = ads_to_xe(ads); 914 struct xe_gt *gt = ads_to_gt(ads); 915 struct iosys_map info_map = IOSYS_MAP_INIT_OFFSET(ads_to_map(ads), 916 offsetof(struct __guc_ads_blob, system_info)); 917 size_t total_size = 0, alloc_size, real_size; 918 + u32 offset; 919 int class; 920 921 offset = guc_ads_golden_lrc_offset(ads); 922 923 for (class = 0; class < XE_ENGINE_CLASS_MAX; ++class) { 924 u8 guc_class; ··· 931 alloc_size = PAGE_ALIGN(real_size); 932 total_size += alloc_size; 933 934 xe_map_memcpy_to(xe, ads_to_map(ads), offset, 935 gt->default_lrc[class], real_size); 936 937 offset += alloc_size; 938 } 939 ··· 959 960 void xe_guc_ads_populate_post_load(struct xe_guc_ads *ads) 961 { 962 + guc_golden_lrc_populate(ads); 963 } 964 965 static int guc_ads_action_update_policies(struct xe_guc_ads *ads, u32 policy_offset)
-24
drivers/gpu/drm/xe/xe_hmm.c
··· 19 return (end - start) >> PAGE_SHIFT; 20 } 21 22 - /** 23 - * xe_mark_range_accessed() - mark a range is accessed, so core mm 24 - * have such information for memory eviction or write back to 25 - * hard disk 26 - * @range: the range to mark 27 - * @write: if write to this range, we mark pages in this range 28 - * as dirty 29 - */ 30 - static void xe_mark_range_accessed(struct hmm_range *range, bool write) 31 - { 32 - struct page *page; 33 - u64 i, npages; 34 - 35 - npages = xe_npages_in_range(range->start, range->end); 36 - for (i = 0; i < npages; i++) { 37 - page = hmm_pfn_to_page(range->hmm_pfns[i]); 38 - if (write) 39 - set_page_dirty_lock(page); 40 - 41 - mark_page_accessed(page); 42 - } 43 - } 44 - 45 static int xe_alloc_sg(struct xe_device *xe, struct sg_table *st, 46 struct hmm_range *range, struct rw_semaphore *notifier_sem) 47 { ··· 308 if (ret) 309 goto out_unlock; 310 311 - xe_mark_range_accessed(&hmm_range, write); 312 userptr->sg = &userptr->sgt; 313 xe_hmm_userptr_set_mapped(uvma); 314 userptr->notifier_seq = hmm_range.notifier_seq;
··· 19 return (end - start) >> PAGE_SHIFT; 20 } 21 22 static int xe_alloc_sg(struct xe_device *xe, struct sg_table *st, 23 struct hmm_range *range, struct rw_semaphore *notifier_sem) 24 { ··· 331 if (ret) 332 goto out_unlock; 333 334 userptr->sg = &userptr->sgt; 335 xe_hmm_userptr_set_mapped(uvma); 336 userptr->notifier_seq = hmm_range.notifier_seq;
+11 -2
drivers/gpu/drm/xe/xe_pxp_debugfs.c
··· 66 { 67 struct xe_pxp *pxp = node_to_pxp(m->private); 68 struct drm_printer p = drm_seq_file_printer(m); 69 70 - if (!xe_pxp_is_enabled(pxp)) 71 - return -ENODEV; 72 73 /* simulate a termination interrupt */ 74 spin_lock_irq(&pxp->xe->irq.lock);
··· 66 { 67 struct xe_pxp *pxp = node_to_pxp(m->private); 68 struct drm_printer p = drm_seq_file_printer(m); 69 + int ready = xe_pxp_get_readiness_status(pxp); 70 71 + if (ready < 0) 72 + return ready; /* disabled or error occurred */ 73 + else if (!ready) 74 + return -EBUSY; /* init still in progress */ 75 + 76 + /* no need for a termination if PXP is not active */ 77 + if (pxp->status != XE_PXP_ACTIVE) { 78 + drm_printf(&p, "PXP not active\n"); 79 + return 0; 80 + } 81 82 /* simulate a termination interrupt */ 83 spin_lock_irq(&pxp->xe->irq.lock);