Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36741606A685 for ; Fri, 4 Dec 2026 13:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=simple-co.de header.i=@simple-co.de header.a=rsa-sha256 header.s=201801 header.b=wnr8KGBc; dkim=pass (2048-bit key) header.d=simple-co.de header.i=@simple-co.de header.a=rsa-sha256 header.s=201801 header.b=DgZnX79v Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 75630112F8A; Fri, 4 Dec 2026 13:56:24 +0000 (UTC) Received: from mail.bin-co.de (mail.bin-co.de [37.120.183.211]) by gabe.freedesktop.org (Postfix) with ESMTPS id EC75110EAE2 for ; Fri, 4 Dec 2026 12:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simple-co.de; s=201801; t=1796388784; bh=+9DS4xFk36ZmMV+MIDSn4vzmvx6vcgstqexsOcaDw3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wnr8KGBcpdj+Bs/bpsF6qXU7d0CZ8ppizTOfK2cyndRNpTQY0aENh5eSlckurM8WY DBe6av8d9CYkTl7qRwlbvZXHYVmxjk6txori4bEJ9ePL2dn0sWBHvtLNYJlNmnnN/6 p2xDIdp6K2ru5JuNAhwdo+xYqrX0YjMWqgm89lVX0V5yLdmYogsoZuI6UNVBqnU40Z js73zoWK1dBrkHGiBsUsT226tfUPk0zGwW7ba1QxSEiH9IeqOLoTOuu92X1dYCojS7 lpgnrListUsyTyQoiNSZ6f/tckwLqU0QcTk9MGXh7G9Q7wQwVxwjrp/Xtjs1O/dKq5 RmlNA2V4ZbJGA== Received: from localhost (localhost [127.0.0.1]) by mail.bin-co.de (Postfix) with ESMTP id 1D1DC17F36C; Fri, 04 Dec 2026 13:53:04 +0100 (CET) X-Virus-Scanned: Debian amavis at v2202603343726440230.luckysrv.de Received: from mail.bin-co.de ([127.0.0.1]) by localhost (mail.bin-co.de [127.0.0.1]) (amavis, port 10024) with ESMTP id VymO4OhMoKs1; Fri, 4 Dec 2026 13:53:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simple-co.de; s=201801; t=1796388782; bh=+9DS4xFk36ZmMV+MIDSn4vzmvx6vcgstqexsOcaDw3A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DgZnX79vX5BWfDHaUk0qrhuW1iZDoyudQJnYVAyQQww+MuCgXLKuIW/pvevHYYMJE Qsv3ExzSVYpTBeyXTm1A5aYam71ugo5diSXw2kuwMBZPVTkoy0FRFiMUNNHqeSXT89 esCplN8ZYJ7Kdxo2ctn1RwMfdnzxrIrVBWJKjMJ6vsLLmpXMNe4lpxVlGFVXpGX9Cu M6wSjDUkitSegmozIz5HsS0KrMT8lgwpVt3a9RZMXeKN7Jl5yOrl9aotj0AH9oGD0e Z+/bR5D5JdXExuckrXuBt033be9xfe50Tj1FYsIBMjw2wmbtnw5+ZLtu5c8I12kJy6 /aZV3gP3YYg8A== Received: from deepblue.zlan.intra (wan.zappel.net [IPv6:2a02:8106:4:c300::1]) (Authenticated sender: zappel@simple-co.de) by mail.bin-co.de (Postfix) with ESMTPSA id B4B9017F36A; Fri, 04 Dec 2026 13:53:02 +0100 (CET) From: Armas Spann To: amd-gfx@lists.freedesktop.org Cc: alexander.deucher@amd.com, christian.koenig@amd.com, Felix.Kuehling@amd.com, Armas Spann Subject: [PATCH 7/8] drm/amdkfd: apply queue property updates only after unmap Date: Fri, 4 Dec 2026 13:52:49 +0100 Message-ID: <20261204125251.10703-8-zappel@simple-co.de> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204125251.10703-1-zappel@simple-co.de> References: <20261204125251.10703-1-zappel@simple-co.de> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Fri, 04 Dec 2026 13:56:23 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 pqm_update_queue_properties() drops the references on the old ring buffer and overwrites the queue properties before update_queue() takes the queue off the hardware. If the unmap fails, the scheduler keeps running the old ring, which is no longer protected against being unmapped, while the driver describes the new one. Hand the new properties to update_queue() in the mqd_update_info of the call and let it apply them at the point where the queue is unmapped, under the dqm lock. Swap the ring buffer reference afterwards, and only if the properties were applied. The properties travel with the call and not in the queue, because set_perfcount() updates every queue of every process under the dqm lock alone, and must not apply the properties of an update that is in flight for one of them. The update used to pass no mqd_update_info. It passes one now, and the gfx9 MQD manager derives a compute resource limit bit from its GWS flag on GC 9.4.2 and later, so the flag is set from the GWS state of the queue to leave that bit as pqm_set_gws() programmed it. A queue that is updated while the scheduler is stopped, in the no-HWS debug mode, now gets -EBUSY. The update is not applied in that state; it returned success before. Signed-off-by: Armas Spann Co-Authored-By: Claude Fable 5.2 --- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 21 +++++- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 6 ++ .../amd/amdkfd/kfd_process_queue_manager.c | 69 +++++++++++-------- 3 files changed, 68 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c index 468e22d18..c31844cf5 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1466,6 +1466,24 @@ static void update_queue_mqd(struct device_queue_manager *dqm, struct queue *q, dqm->mqd_mgrs[get_mqd_type_from_queue_type(q->properties.type)]; bool prev_active = q->properties.is_active; + /* + * The queue is off the hardware now. Only from here on may its + * properties change, otherwise a failed unmap would leave the + * scheduler running the old ring under the new description. The + * new properties travel with the update that carries them, so an + * update of another kind (perfcount, debug) cannot apply them. + */ + if (minfo && minfo->new_props) { + const struct queue_properties *np = minfo->new_props; + + q->properties.queue_address = np->queue_address; + q->properties.queue_size = np->queue_size; + q->properties.queue_percent = np->queue_percent; + q->properties.priority = np->priority; + q->properties.pm4_target_xcc = np->pm4_target_xcc; + minfo->new_props = NULL; + } + mqd_mgr->update_mqd(mqd_mgr, q->mqd, &q->properties, minfo); /* @@ -1544,7 +1562,8 @@ static int update_queue_locked(struct device_queue_manager *dqm, struct queue *q if (!dqm->sched_running) { WARN_ONCE(1, "Update non-HWS queue while stopped\n"); - return retval; + /* Nothing was applied, say so */ + return -EBUSY; } retval = mqd_mgr->destroy_mqd(mqd_mgr, q->mqd, diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index f8ab1bde8..40d3d481c 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -581,6 +581,12 @@ struct mqd_update_info { } cu_mask; }; enum mqd_update_flag update_flag; + /* + * New properties from pqm_update_queue_properties(). Applied by + * update_queue() under the dqm lock once the queue is unmapped, and + * cleared to report that it did. + */ + const struct queue_properties *new_props; }; /* What MES knows about a queue, see kfd_mes_queue_retired() */ diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c index b43b9f0eb..07ed59b88 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -640,60 +640,75 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid) int pqm_update_queue_properties(struct process_queue_manager *pqm, unsigned int qid, struct queue_properties *p) { - int retval; + struct amdgpu_bo *new_ring_bo = NULL, *old_ring_bo; struct process_queue_node *pqn; + struct mqd_update_info minfo = {0}; + struct amdgpu_vm *vm = NULL; + struct queue *q; + int retval; pqn = get_queue_by_qid(pqm, qid); if (!pqn || !pqn->q) { pr_debug("No queue %d exists for update operation\n", qid); return -EFAULT; } + q = pqn->q; /* * Update with NULL ring address is used to disable the queue */ if (p->queue_address && p->queue_size) { + u64 size = p->queue_size + q->properties.metadata_queue_size; struct kfd_process_device *pdd; - struct amdgpu_vm *vm; - struct queue *q = pqn->q; - int err; pdd = kfd_get_process_device_data(q->device, q->process); if (!pdd) return -ENODEV; vm = drm_priv_to_vm(pdd->drm_priv); - err = amdgpu_bo_reserve(vm->root.bo, false); - if (err) - return err; + retval = amdgpu_bo_reserve(vm->root.bo, false); + if (retval) + return retval; - if (kfd_queue_buffer_get(vm, (void *)p->queue_address, &p->ring_bo, - p->queue_size + - pqn->q->properties.metadata_queue_size)) { + retval = kfd_queue_buffer_get(vm, (void *)p->queue_address, + &new_ring_bo, size); + amdgpu_bo_unreserve(vm->root.bo); + if (retval) { pr_debug("ring buf 0x%llx size 0x%llx not mapped on GPU\n", p->queue_address, p->queue_size); - amdgpu_bo_unreserve(vm->root.bo); return -EFAULT; } - - kfd_queue_unref_bo_va(vm, &pqn->q->properties.ring_bo); - kfd_queue_buffer_put(&pqn->q->properties.ring_bo); - amdgpu_bo_unreserve(vm->root.bo); - - pqn->q->properties.ring_bo = p->ring_bo; } - pqn->q->properties.queue_address = p->queue_address; - pqn->q->properties.queue_size = p->queue_size; - pqn->q->properties.queue_percent = p->queue_percent; - pqn->q->properties.priority = p->priority; - pqn->q->properties.pm4_target_xcc = p->pm4_target_xcc; + /* + * The dqm applies the new properties once the queue is unmapped. If + * it fails before that, the queue still runs on the old ring and + * keeps its old properties. The flag keeps the GWS state of the MQD + * as it is, see pqm_set_gws(). + */ + minfo.new_props = p; + minfo.update_flag = q->gws ? UPDATE_FLAG_IS_GWS : 0; + retval = q->device->dqm->ops.update_queue(q->device->dqm, q, &minfo); + + if (minfo.new_props) { + /* Not applied. Drop the reference on the new ring. */ + old_ring_bo = new_ring_bo; + } else if (new_ring_bo) { + old_ring_bo = q->properties.ring_bo; + q->properties.ring_bo = new_ring_bo; + } else { + old_ring_bo = NULL; + } - retval = pqn->q->device->dqm->ops.update_queue(pqn->q->device->dqm, - pqn->q, NULL); - if (retval != 0) - return retval; + /* There is an old ring to drop only if a new one was looked up */ + if (old_ring_bo) { + if (!amdgpu_bo_reserve(vm->root.bo, true)) { + kfd_queue_unref_bo_va(vm, &old_ring_bo); + amdgpu_bo_unreserve(vm->root.bo); + } + kfd_queue_buffer_put(&old_ring_bo); + } - return 0; + return retval; } int pqm_update_mqd(struct process_queue_manager *pqm, -- 2.47.3