From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 009E9383319 for ; Fri, 10 Jul 2026 19:08:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783710490; cv=none; b=Ezs8q+bVvyxGgx1bJ8a1mOlPH3+5x23/Q28YigYuLv0Mp+eIFUVNM3ipnzxJt0Cft2ofMUVmWV11KlPyAnyqoROKEjLv1QlzMfgvxnsA0b878DmvI+kiRmdu2QLsUxCkpbpx8dWu7uw3TaO20a6CVN+WOi4RMDh2ie7OKJxjWT0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783710490; c=relaxed/simple; bh=1tX+iU+/gK3r+QpIBiHr25SrdipoVWIho6lYX9iVtOc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ooaeJkgONxTykoIDt0MplN5KKRTobO6rvvV7vRqaOGBXhsHDRkuCdOtFzIfb7PDLYfVBfLg6BECLanc4PAAoslMpua27hxpuX1V0uYVOOQ6AD/Jb1QtHYztz/GuNXrRqDCYUbUa83UGDgy7BdqWSQaai6HBzlZhulK8wPECHYVI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mF7F4WAG; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mF7F4WAG" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-493f45e20cdso6624545e9.2 for ; Fri, 10 Jul 2026 12:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783710486; x=1784315286; darn=vger.kernel.org; h=content-transfer-encoding:reply-to:content-type:mime-version :references:in-reply-to:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=IOmjbtLYRqKMFq3vRWGT3hOtZz67iXQHbJfJ46cKOMg=; b=mF7F4WAGcCRnzMdVk4KdltVHL4IdnIIHiftk/hI0qLpmxHZKnrpoP1SqHYTmSnCKn1 cVaCVZuCiIuh3eI6+WU4YXHbAJnUkMSNtPPiVEcS3ZMGb5M1b02rZc+SIk+RCo1Z1iv0 KGCUkRCIAvxbsxOoPSWP0KmKLabBGDyCLLTIJO+egdmH9Oolqt65o06MdaLQROo9w+Z3 BDP161RlLLCn9UIBgCLvT8cyACuE4eyu5+3aUIE8ov4xih2HvfjGcb1tF4MEUXsaCuOz xiZUmyPj/M0sPboiOXpH3QxMy45mtSI3ucFzHQSG3/AxS6f+Dt0BHzfGK1PWUqzt9CaU dgvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783710486; x=1784315286; h=content-transfer-encoding:reply-to:content-type:mime-version :references:in-reply-to:message-id:date:subject:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=IOmjbtLYRqKMFq3vRWGT3hOtZz67iXQHbJfJ46cKOMg=; b=Rhf/5eSkxEinP1kbHVDQGXERbKGO13q7nA72f8qLYuwX5dqIE1bsScQK9tZ44Hkogc WWuGnJp6zcgyuC4DDYoWPC4e6iCXtHS/U3cPAEQdFk6TgSfATLc5UmMRG7BLR5ku6HTn o9sCH2j7b7qHrgICbsp0HX39nAR3xNf3v6Vhd07p1/EGyq9/tvMJ3izlPGTvR+y+SAw2 nCes9h08HZF0McVFlR2gJBIXOSf/Fr/vHMiLAA4as05PRtmdyqBQLh9Wfjy1L7ehtr1k t9utd4RYYXI8edp2q4v9+eBzGukBmda9mSMCQTkKo2uQlH5niPi7S9r1ja+7ArIo7F2L quWw== X-Forwarded-Encrypted: i=1; AHgh+RqC8vXxpHXV3VC19++DUHOSc51pAdAOjFBEL0pqxKdSX53rfME7rzgYFmVAtqYJdyTehxBzuAF+BUAxfa8=@vger.kernel.org X-Gm-Message-State: AOJu0YwueXv02s8W98AjJ9S52XBfF4q+/0ijTgVorokBhZ5nm3ZFMSTH EjRtpS1Ab5nlZswB9zD/PmJC/rFUgc5g40RbarxXJdblx4xSgSxMHjje X-Gm-Gg: AfdE7cmb5wYyRP8tSmGbYLXWLCQ4+Mv2zbnnIXANqRvcurudjzzsFj+KMke/GjVY+Je aNWxi90LJEqzwQrp9wf+rXh5zGOyHDe0ja0ij+4U+IeHYIO1UIFeLhpovROVXjsiU5vgyrbzsa1 xzzRcS68ZjFc0d02wSCNomC6TFRvq9xxaK3Drn6oCxZ3e930n0pOFK1eAr8I0GE4QvwyIdPcMVX N1zWwWiXBAV3mpki1zBhiWl5lvYi4HI3sveR/dbZjVlc6a3Xb2jgCOFADbwshKuunPEQIPybnXV jBy0mPkNkyTtBpGrRpXL/St1OhjFmoLGJQYSjjbzTTZnG+va4cgslY0DSysEUmmdnYaTzhhOz3R ZvJ+XwKr17yDQ9wxbLcgLVkd9592fxkZxc37LNqoC+IE71GI0mLSS+rb+nJ29nLzsJG6IihRGCY nXoRrZ9BijFh6Y2n9wi3Z4txP1gg== X-Received: by 2002:a05:600c:5849:b0:493:b55f:bca2 with SMTP id 5b1f17b1804b1-493f88389cemr678085e9.34.1783710486348; Fri, 10 Jul 2026 12:08:06 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:154f:ec00:aa08:de24:db33:4496]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f567eadfsm55000755e9.6.2026.07.10.12.08.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 12:08:05 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: thomas.hellstrom@linux.intel.com, dakr@kernel.org, ecourtney@nvidia.com, simona@ffwll.ch, matthew.brost@intel.com, nat@pixelcluster.dev, airlied@gmail.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 12/12] drm/amdgpu: use drm_exec during BO validation Date: Fri, 10 Jul 2026 20:52:52 +0200 Message-ID: <20260710190752.2355-13-christian.koenig@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710190752.2355-1-christian.koenig@amd.com> References: <20260710190752.2355-1-christian.koenig@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Reply-To: christian.koenig@amd.com Content-Transfer-Encoding: 8bit This allows to detect deadlocks happening because of resource constraints. Especially submissions which want to use all of GDS doesn't result in sporadic -ENOMEM any more. Signed-off-by: Christian König --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 82 ++++++++++++++------------ 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index c2e6495a28bc5..17223e295ff25 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -793,7 +793,7 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo) struct ttm_operation_ctx ctx = { .interruptible = true, .no_wait_gpu = false, - .resv = bo->tbo.base.resv + .exec = &p->exec, }; uint32_t domain; int r; @@ -845,7 +845,10 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, union drm_amdgpu_cs *cs) { struct amdgpu_fpriv *fpriv = p->filp->driver_priv; - struct ttm_operation_ctx ctx = { true, false }; + struct ttm_operation_ctx ctx = { + .interruptible =true, + .exec = &p->exec + }; struct amdgpu_vm *vm = &fpriv->vm; struct amdgpu_bo_list_entry *e; struct drm_gem_object *obj; @@ -899,6 +902,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, e->user_invalidated = userpage_invalidated; } + amdgpu_cs_get_threshold_for_moves(p->adev, &p->bytes_moved_threshold, + &p->bytes_moved_vis_threshold); + p->bytes_moved = 0; + p->bytes_moved_vis = 0; + drm_exec_until_all_locked(&p->exec) { r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec, 1 + p->gang_size); drm_exec_retry_on_contention(&p->exec); @@ -922,47 +930,48 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, if (unlikely(r)) goto out_free_user_pages; } - } - amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) { - struct mm_struct *usermm; + amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) { + struct mm_struct *usermm; - usermm = amdgpu_ttm_tt_get_usermm(e->bo->tbo.ttm); - if (usermm && usermm != current->mm) { - r = -EPERM; - goto out_free_user_pages; - } - - if (amdgpu_ttm_tt_is_userptr(e->bo->tbo.ttm) && - e->user_invalidated) { - amdgpu_bo_placement_from_domain(e->bo, - AMDGPU_GEM_DOMAIN_CPU); - r = ttm_bo_validate(&e->bo->tbo, &e->bo->placement, - &ctx); - if (r) + usermm = amdgpu_ttm_tt_get_usermm(e->bo->tbo.ttm); + if (usermm && usermm != current->mm) { + r = -EPERM; goto out_free_user_pages; + } - amdgpu_ttm_tt_set_user_pages(e->bo->tbo.ttm, - e->range); + if (amdgpu_ttm_tt_is_userptr(e->bo->tbo.ttm) && + e->user_invalidated) { + amdgpu_bo_placement_from_domain(e->bo, + AMDGPU_GEM_DOMAIN_CPU); + r = ttm_bo_validate(&e->bo->tbo, &e->bo->placement, + &ctx); + drm_exec_retry_on_contention(&p->exec); + if (r) + goto out_free_user_pages; + + amdgpu_ttm_tt_set_user_pages(e->bo->tbo.ttm, + e->range); + } } - } - amdgpu_cs_get_threshold_for_moves(p->adev, &p->bytes_moved_threshold, - &p->bytes_moved_vis_threshold); - p->bytes_moved = 0; - p->bytes_moved_vis = 0; + r = amdgpu_vm_validate(p->adev, &fpriv->vm, NULL, + amdgpu_cs_bo_validate, p); + drm_exec_retry_on_contention(&p->exec); + if (r) { + drm_err(adev_to_drm(p->adev), "amdgpu_vm_validate() failed.\n"); + goto out_free_user_pages; + } - r = amdgpu_vm_validate(p->adev, &fpriv->vm, NULL, - amdgpu_cs_bo_validate, p); - if (r) { - drm_err(adev_to_drm(p->adev), "amdgpu_vm_validate() failed.\n"); - goto out_free_user_pages; - } + drm_exec_for_each_locked_object(&p->exec, obj) { + r = amdgpu_cs_bo_validate(p, gem_to_amdgpu_bo(obj)); + drm_exec_retry_on_contention(&p->exec); + if (unlikely(r)) + goto out_free_user_pages; - drm_exec_for_each_locked_object(&p->exec, obj) { - r = amdgpu_cs_bo_validate(p, gem_to_amdgpu_bo(obj)); - if (unlikely(r)) - goto out_free_user_pages; + amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved, + p->bytes_moved_vis); + } } if (p->uf_bo) { @@ -973,9 +982,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, p->gang_leader->uf_addr += amdgpu_bo_gpu_offset(p->uf_bo); } - amdgpu_cs_report_moved_bytes(p->adev, p->bytes_moved, - p->bytes_moved_vis); - for (i = 0; i < p->gang_size; ++i) amdgpu_job_set_resources(p->jobs[i], p->bo_list->gds_obj, p->bo_list->gws_obj, -- 2.43.0