Commit 99fea682 authored by Francois Dugast's avatar Francois Dugast Committed by Rodrigo Vivi
Browse files

drm/xe: Prefer WARN() over BUG() to avoid crashing the kernel



Replace calls to XE_BUG_ON() with calls XE_WARN_ON() which in turn calls
WARN() instead of BUG(). BUG() crashes the kernel and should only be
used when it is absolutely unavoidable in case of catastrophic and
unrecoverable failures, which is not the case here.

Signed-off-by: default avatarFrancois Dugast <francois.dugast@intel.com>
Reviewed-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
parent 3207a321
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ struct xe_sched_job *xe_bb_create_wa_job(struct xe_engine *wa_eng,
{
	u64 addr = batch_base_ofs + drm_suballoc_soffset(bb->bo);

	XE_BUG_ON(!(wa_eng->vm->flags & XE_VM_FLAG_MIGRATION));
	XE_WARN_ON(!(wa_eng->vm->flags & XE_VM_FLAG_MIGRATION));

	return __xe_bb_create_job(wa_eng, bb, &addr);
}
@@ -94,8 +94,8 @@ struct xe_sched_job *xe_bb_create_migration_job(struct xe_engine *kernel_eng,
		4 * second_idx,
	};

	BUG_ON(second_idx > bb->len);
	BUG_ON(!(kernel_eng->vm->flags & XE_VM_FLAG_MIGRATION));
	XE_WARN_ON(second_idx > bb->len);
	XE_WARN_ON(!(kernel_eng->vm->flags & XE_VM_FLAG_MIGRATION));

	return __xe_bb_create_job(kernel_eng, bb, addr);
}
@@ -105,7 +105,7 @@ struct xe_sched_job *xe_bb_create_job(struct xe_engine *kernel_eng,
{
	u64 addr = xe_sa_bo_gpu_addr(bb->bo);

	BUG_ON(kernel_eng->vm && kernel_eng->vm->flags & XE_VM_FLAG_MIGRATION);
	XE_WARN_ON(kernel_eng->vm && kernel_eng->vm->flags & XE_VM_FLAG_MIGRATION);
	return __xe_bb_create_job(kernel_eng, bb, &addr);
}

+26 −26
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ static bool xe_bo_is_user(struct xe_bo *bo)
static struct xe_tile *
mem_type_to_tile(struct xe_device *xe, u32 mem_type)
{
	XE_BUG_ON(mem_type != XE_PL_STOLEN && !mem_type_is_vram(mem_type));
	XE_WARN_ON(mem_type != XE_PL_STOLEN && !mem_type_is_vram(mem_type));

	return &xe->tiles[mem_type == XE_PL_STOLEN ? 0 : (mem_type - XE_PL_VRAM0)];
}
@@ -142,7 +142,7 @@ static void add_vram(struct xe_device *xe, struct xe_bo *bo,
	struct ttm_place place = { .mem_type = mem_type };
	u64 io_size = tile->mem.vram.io_size;

	XE_BUG_ON(!tile->mem.vram.usable_size);
	XE_WARN_ON(!tile->mem.vram.usable_size);

	/*
	 * For eviction / restore on suspend / resume objects
@@ -285,7 +285,7 @@ static int xe_tt_map_sg(struct ttm_tt *tt)
	unsigned long num_pages = tt->num_pages;
	int ret;

	XE_BUG_ON(tt->page_flags & TTM_TT_FLAG_EXTERNAL);
	XE_WARN_ON(tt->page_flags & TTM_TT_FLAG_EXTERNAL);

	if (xe_tt->sg)
		return 0;
@@ -544,8 +544,8 @@ static int xe_bo_move_dmabuf(struct ttm_buffer_object *ttm_bo,
					       ttm);
	struct sg_table *sg;

	XE_BUG_ON(!attach);
	XE_BUG_ON(!ttm_bo->ttm);
	XE_WARN_ON(!attach);
	XE_WARN_ON(!ttm_bo->ttm);

	if (new_res->mem_type == XE_PL_SYSTEM)
		goto out;
@@ -707,8 +707,8 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
	else if (mem_type_is_vram(old_mem_type))
		tile = mem_type_to_tile(xe, old_mem_type);

	XE_BUG_ON(!tile);
	XE_BUG_ON(!tile->migrate);
	XE_WARN_ON(!tile);
	XE_WARN_ON(!tile->migrate);

	trace_xe_bo_move(bo);
	xe_device_mem_access_get(xe);
@@ -738,7 +738,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
					goto out;
				}

				XE_BUG_ON(new_mem->start !=
				XE_WARN_ON(new_mem->start !=
					  bo->placements->fpfn);

				iosys_map_set_vaddr_iomem(&bo->vmap, new_addr);
@@ -1198,7 +1198,7 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,
	int err;

	/* Only kernel objects should set GT */
	XE_BUG_ON(tile && type != ttm_bo_type_kernel);
	XE_WARN_ON(tile && type != ttm_bo_type_kernel);

	if (XE_WARN_ON(!size))
		return ERR_PTR(-EINVAL);
@@ -1350,7 +1350,7 @@ xe_bo_create_locked_range(struct xe_device *xe,
		if (!tile && flags & XE_BO_CREATE_STOLEN_BIT)
			tile = xe_device_get_root_tile(xe);

		XE_BUG_ON(!tile);
		XE_WARN_ON(!tile);

		if (flags & XE_BO_CREATE_STOLEN_BIT &&
		    flags & XE_BO_FIXED_PLACEMENT_BIT) {
@@ -1481,8 +1481,8 @@ int xe_bo_pin_external(struct xe_bo *bo)
	struct xe_device *xe = xe_bo_device(bo);
	int err;

	XE_BUG_ON(bo->vm);
	XE_BUG_ON(!xe_bo_is_user(bo));
	XE_WARN_ON(bo->vm);
	XE_WARN_ON(!xe_bo_is_user(bo));

	if (!xe_bo_is_pinned(bo)) {
		err = xe_bo_validate(bo, NULL, false);
@@ -1514,20 +1514,20 @@ int xe_bo_pin(struct xe_bo *bo)
	int err;

	/* We currently don't expect user BO to be pinned */
	XE_BUG_ON(xe_bo_is_user(bo));
	XE_WARN_ON(xe_bo_is_user(bo));

	/* Pinned object must be in GGTT or have pinned flag */
	XE_BUG_ON(!(bo->flags & (XE_BO_CREATE_PINNED_BIT |
	XE_WARN_ON(!(bo->flags & (XE_BO_CREATE_PINNED_BIT |
				 XE_BO_CREATE_GGTT_BIT)));

	/*
	 * No reason we can't support pinning imported dma-bufs we just don't
	 * expect to pin an imported dma-buf.
	 */
	XE_BUG_ON(bo->ttm.base.import_attach);
	XE_WARN_ON(bo->ttm.base.import_attach);

	/* We only expect at most 1 pin */
	XE_BUG_ON(xe_bo_is_pinned(bo));
	XE_WARN_ON(xe_bo_is_pinned(bo));

	err = xe_bo_validate(bo, NULL, false);
	if (err)
@@ -1543,7 +1543,7 @@ int xe_bo_pin(struct xe_bo *bo)
		struct ttm_place *place = &(bo->placements[0]);

		if (mem_type_is_vram(place->mem_type)) {
			XE_BUG_ON(!(place->flags & TTM_PL_FLAG_CONTIGUOUS));
			XE_WARN_ON(!(place->flags & TTM_PL_FLAG_CONTIGUOUS));

			place->fpfn = (xe_bo_addr(bo, 0, PAGE_SIZE) -
				       vram_region_gpu_offset(bo->ttm.resource)) >> PAGE_SHIFT;
@@ -1580,9 +1580,9 @@ void xe_bo_unpin_external(struct xe_bo *bo)
{
	struct xe_device *xe = xe_bo_device(bo);

	XE_BUG_ON(bo->vm);
	XE_BUG_ON(!xe_bo_is_pinned(bo));
	XE_BUG_ON(!xe_bo_is_user(bo));
	XE_WARN_ON(bo->vm);
	XE_WARN_ON(!xe_bo_is_pinned(bo));
	XE_WARN_ON(!xe_bo_is_user(bo));

	if (bo->ttm.pin_count == 1 && !list_empty(&bo->pinned_link)) {
		spin_lock(&xe->pinned.lock);
@@ -1603,15 +1603,15 @@ void xe_bo_unpin(struct xe_bo *bo)
{
	struct xe_device *xe = xe_bo_device(bo);

	XE_BUG_ON(bo->ttm.base.import_attach);
	XE_BUG_ON(!xe_bo_is_pinned(bo));
	XE_WARN_ON(bo->ttm.base.import_attach);
	XE_WARN_ON(!xe_bo_is_pinned(bo));

	if (IS_DGFX(xe) && !(IS_ENABLED(CONFIG_DRM_XE_DEBUG) &&
	    bo->flags & XE_BO_INTERNAL_TEST)) {
		struct ttm_place *place = &(bo->placements[0]);

		if (mem_type_is_vram(place->mem_type)) {
			XE_BUG_ON(list_empty(&bo->pinned_link));
			XE_WARN_ON(list_empty(&bo->pinned_link));

			spin_lock(&xe->pinned.lock);
			list_del_init(&bo->pinned_link);
@@ -1675,12 +1675,12 @@ dma_addr_t __xe_bo_addr(struct xe_bo *bo, u64 offset, size_t page_size)
	struct xe_res_cursor cur;
	u64 page;

	XE_BUG_ON(page_size > PAGE_SIZE);
	XE_WARN_ON(page_size > PAGE_SIZE);
	page = offset >> PAGE_SHIFT;
	offset &= (PAGE_SIZE - 1);

	if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) {
		XE_BUG_ON(!bo->ttm.ttm);
		XE_WARN_ON(!bo->ttm.ttm);

		xe_res_first_sg(xe_bo_get_sg(bo), page << PAGE_SHIFT,
				page_size, &cur);
@@ -1874,7 +1874,7 @@ int xe_bo_lock(struct xe_bo *bo, struct ww_acquire_ctx *ww,
	LIST_HEAD(objs);
	LIST_HEAD(dups);

	XE_BUG_ON(!ww);
	XE_WARN_ON(!ww);

	tv_bo.num_shared = num_resv;
	tv_bo.bo = &bo->ttm;
+7 −7
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ void xe_bo_unlock(struct xe_bo *bo, struct ww_acquire_ctx *ww);
static inline void xe_bo_unlock_vm_held(struct xe_bo *bo)
{
	if (bo) {
		XE_BUG_ON(bo->vm && bo->ttm.base.resv != xe_vm_resv(bo->vm));
		XE_WARN_ON(bo->vm && bo->ttm.base.resv != xe_vm_resv(bo->vm));
		if (bo->vm)
			xe_vm_assert_held(bo->vm);
		else
@@ -178,7 +178,7 @@ static inline void xe_bo_lock_no_vm(struct xe_bo *bo,
				    struct ww_acquire_ctx *ctx)
{
	if (bo) {
		XE_BUG_ON(bo->vm || (bo->ttm.type != ttm_bo_type_sg &&
		XE_WARN_ON(bo->vm || (bo->ttm.type != ttm_bo_type_sg &&
				      bo->ttm.base.resv != &bo->ttm.base._resv));
		dma_resv_lock(bo->ttm.base.resv, ctx);
	}
@@ -187,7 +187,7 @@ static inline void xe_bo_lock_no_vm(struct xe_bo *bo,
static inline void xe_bo_unlock_no_vm(struct xe_bo *bo)
{
	if (bo) {
		XE_BUG_ON(bo->vm || (bo->ttm.type != ttm_bo_type_sg &&
		XE_WARN_ON(bo->vm || (bo->ttm.type != ttm_bo_type_sg &&
				      bo->ttm.base.resv != &bo->ttm.base._resv));
		dma_resv_unlock(bo->ttm.base.resv);
	}
@@ -228,8 +228,8 @@ xe_bo_main_addr(struct xe_bo *bo, size_t page_size)
static inline u32
xe_bo_ggtt_addr(struct xe_bo *bo)
{
	XE_BUG_ON(bo->ggtt_node.size > bo->size);
	XE_BUG_ON(bo->ggtt_node.start + bo->ggtt_node.size > (1ull << 32));
	XE_WARN_ON(bo->ggtt_node.size > bo->size);
	XE_WARN_ON(bo->ggtt_node.start + bo->ggtt_node.size > (1ull << 32));
	return bo->ggtt_node.start;
}

+2 −2
Original line number Diff line number Diff line
@@ -160,8 +160,8 @@ int xe_bo_restore_kernel(struct xe_device *xe)
		 * We expect validate to trigger a move VRAM and our move code
		 * should setup the iosys map.
		 */
		XE_BUG_ON(iosys_map_is_null(&bo->vmap));
		XE_BUG_ON(!xe_bo_is_vram(bo));
		XE_WARN_ON(iosys_map_is_null(&bo->vmap));
		XE_WARN_ON(!xe_bo_is_vram(bo));

		xe_bo_put(bo);

+7 −7
Original line number Diff line number Diff line
@@ -50,10 +50,10 @@ static void __start_lrc(struct xe_hw_engine *hwe, struct xe_lrc *lrc,
	lrc_desc = xe_lrc_descriptor(lrc);

	if (GRAPHICS_VERx100(xe) >= 1250) {
		XE_BUG_ON(!FIELD_FIT(XEHP_SW_CTX_ID, ctx_id));
		XE_WARN_ON(!FIELD_FIT(XEHP_SW_CTX_ID, ctx_id));
		lrc_desc |= FIELD_PREP(XEHP_SW_CTX_ID, ctx_id);
	} else {
		XE_BUG_ON(!FIELD_FIT(GEN11_SW_CTX_ID, ctx_id));
		XE_WARN_ON(!FIELD_FIT(GEN11_SW_CTX_ID, ctx_id));
		lrc_desc |= FIELD_PREP(GEN11_SW_CTX_ID, ctx_id);
	}

@@ -213,9 +213,9 @@ static void xe_execlist_make_active(struct xe_execlist_engine *exl)
	struct xe_execlist_port *port = exl->port;
	enum xe_engine_priority priority = exl->active_priority;

	XE_BUG_ON(priority == XE_ENGINE_PRIORITY_UNSET);
	XE_BUG_ON(priority < 0);
	XE_BUG_ON(priority >= ARRAY_SIZE(exl->port->active));
	XE_WARN_ON(priority == XE_ENGINE_PRIORITY_UNSET);
	XE_WARN_ON(priority < 0);
	XE_WARN_ON(priority >= ARRAY_SIZE(exl->port->active));

	spin_lock_irq(&port->lock);

@@ -321,7 +321,7 @@ static int execlist_engine_init(struct xe_engine *e)
	struct xe_device *xe = gt_to_xe(e->gt);
	int err;

	XE_BUG_ON(xe_device_guc_submission_enabled(xe));
	XE_WARN_ON(xe_device_guc_submission_enabled(xe));

	drm_info(&xe->drm, "Enabling execlist submission (GuC submission disabled)\n");

@@ -387,7 +387,7 @@ static void execlist_engine_fini_async(struct work_struct *w)
	struct xe_execlist_engine *exl = e->execlist;
	unsigned long flags;

	XE_BUG_ON(xe_device_guc_submission_enabled(gt_to_xe(e->gt)));
	XE_WARN_ON(xe_device_guc_submission_enabled(gt_to_xe(e->gt)));

	spin_lock_irqsave(&exl->port->lock, flags);
	if (WARN_ON(exl->active_priority != XE_ENGINE_PRIORITY_UNSET))
Loading