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 145 struct sg_table *sgt, 146 146 enum dma_data_direction dir) 147 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)) { 148 + if (sg_page(sgt->sgl)) { 152 149 dma_unmap_sgtable(attach->dev, sgt, dir, 0); 153 150 sg_free_table(sgt); 154 151 kfree(sgt);
+45 -30
drivers/gpu/drm/xe/xe_guc_ads.c
··· 490 490 engine_enable_mask(gt, XE_ENGINE_CLASS_OTHER)); 491 491 } 492 492 493 - static void guc_prep_golden_lrc_null(struct xe_guc_ads *ads) 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) 494 498 { 495 499 struct xe_device *xe = ads_to_xe(ads); 500 + struct xe_gt *gt = ads_to_gt(ads); 496 501 struct iosys_map info_map = IOSYS_MAP_INIT_OFFSET(ads_to_map(ads), 497 502 offsetof(struct __guc_ads_blob, system_info)); 498 - u8 guc_class; 503 + size_t alloc_size, real_size; 504 + u32 addr_ggtt, offset; 505 + int class; 499 506 500 - for (guc_class = 0; guc_class <= GUC_MAX_ENGINE_CLASSES; ++guc_class) { 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 + 501 515 if (!info_map_read(xe, &info_map, 502 516 engine_enabled_masks[guc_class])) 503 517 continue; 504 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 + */ 505 533 ads_blob_write(ads, ads.eng_state_size[guc_class], 506 - guc_ads_golden_lrc_size(ads) - 507 - xe_lrc_skip_size(xe)); 534 + real_size - xe_lrc_skip_size(xe)); 508 535 ads_blob_write(ads, ads.golden_context_lrca[guc_class], 509 - xe_bo_ggtt_addr(ads->bo) + 510 - guc_ads_golden_lrc_offset(ads)); 536 + addr_ggtt); 537 + 538 + addr_ggtt += alloc_size; 511 539 } 512 540 } 513 541 ··· 885 857 886 858 xe_map_memset(ads_to_xe(ads), ads_to_map(ads), 0, 0, ads->bo->size); 887 859 guc_policies_init(ads); 888 - guc_prep_golden_lrc_null(ads); 860 + guc_golden_lrc_init(ads); 889 861 guc_mapping_table_init_invalid(gt, &info_map); 890 862 guc_doorbell_init(ads); 891 863 ··· 911 883 guc_policies_init(ads); 912 884 fill_engine_enable_masks(gt, &info_map); 913 885 guc_mmio_reg_state_init(ads); 914 - guc_prep_golden_lrc_null(ads); 886 + guc_golden_lrc_init(ads); 915 887 guc_mapping_table_init(gt, &info_map); 916 888 guc_capture_prep_lists(ads); 917 889 guc_doorbell_init(ads); ··· 931 903 guc_ads_private_data_offset(ads)); 932 904 } 933 905 934 - static void guc_populate_golden_lrc(struct xe_guc_ads *ads) 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) 935 912 { 936 913 struct xe_device *xe = ads_to_xe(ads); 937 914 struct xe_gt *gt = ads_to_gt(ads); 938 915 struct iosys_map info_map = IOSYS_MAP_INIT_OFFSET(ads_to_map(ads), 939 916 offsetof(struct __guc_ads_blob, system_info)); 940 917 size_t total_size = 0, alloc_size, real_size; 941 - u32 addr_ggtt, offset; 918 + u32 offset; 942 919 int class; 943 920 944 921 offset = guc_ads_golden_lrc_offset(ads); 945 - addr_ggtt = xe_bo_ggtt_addr(ads->bo) + offset; 946 922 947 923 for (class = 0; class < XE_ENGINE_CLASS_MAX; ++class) { 948 924 u8 guc_class; ··· 963 931 alloc_size = PAGE_ALIGN(real_size); 964 932 total_size += alloc_size; 965 933 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 934 xe_map_memcpy_to(xe, ads_to_map(ads), offset, 983 935 gt->default_lrc[class], real_size); 984 936 985 - addr_ggtt += alloc_size; 986 937 offset += alloc_size; 987 938 } 988 939 ··· 974 959 975 960 void xe_guc_ads_populate_post_load(struct xe_guc_ads *ads) 976 961 { 977 - guc_populate_golden_lrc(ads); 962 + guc_golden_lrc_populate(ads); 978 963 } 979 964 980 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 19 return (end - start) >> PAGE_SHIFT; 20 20 } 21 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 22 static int xe_alloc_sg(struct xe_device *xe, struct sg_table *st, 46 23 struct hmm_range *range, struct rw_semaphore *notifier_sem) 47 24 { ··· 308 331 if (ret) 309 332 goto out_unlock; 310 333 311 - xe_mark_range_accessed(&hmm_range, write); 312 334 userptr->sg = &userptr->sgt; 313 335 xe_hmm_userptr_set_mapped(uvma); 314 336 userptr->notifier_seq = hmm_range.notifier_seq;
+11 -2
drivers/gpu/drm/xe/xe_pxp_debugfs.c
··· 66 66 { 67 67 struct xe_pxp *pxp = node_to_pxp(m->private); 68 68 struct drm_printer p = drm_seq_file_printer(m); 69 + int ready = xe_pxp_get_readiness_status(pxp); 69 70 70 - if (!xe_pxp_is_enabled(pxp)) 71 - return -ENODEV; 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 + } 72 81 73 82 /* simulate a termination interrupt */ 74 83 spin_lock_irq(&pxp->xe->irq.lock);