From mboxrd@z Thu Jan 1 00:00:00 1970 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 1400E606A31A for ; Mon, 30 Nov 2026 21:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=m+klGiqv Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A680D10E0C7; Mon, 30 Nov 2026 21:41:42 +0000 (UTC) Received: from tor.source.kernel.org (tor.source.kernel.org [172.105.4.254]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5B92710E0C7 for ; Mon, 30 Nov 2026 21:41:36 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 504AB61D41; Mon, 30 Nov 2026 21:41:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B36801F000C1; Mon, 30 Nov 2026 21:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796074894; bh=1oUum86w8kKMrnC3+P/RSNAQjSYqnDFSumk7IdyYtqU=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=m+klGiqvb0iDRgsHyX+z/RsOEp/Uw/otaPI0BHKlb4cw/6TWmpUv/UnMaduxmqxZO zaCUo4z8HHBeGKadevaG1b6c0EG3cwgwCoYnEZqL06QfK4eJYOJMy8TrVSMw2husXJ DeJDkZZr7FOCXs37MtwmJvQebYCf9+vP3XbRT8/IRkwsQB/8goqPLIUk03+aHjOQnD dGqFl719+j1Z7m7OvFppiRX4QjobO6iSOg3j08TTaNgNAs3BnpylGViKOMoYjWF+NN eRXye4za1FP+klDWQTstR4XlU50XAusQqW//HuMZZ6SVic6SJV8LRPYsMu080du7Vv Ekq6biThLYctw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] drm/amdgpu: reject CS on a VM that KFD has acquired To: "Yongqiang Sun" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261130212328.2369114-1-Yongqiang.Sun@amd.com> References: <20261130212328.2369114-1-Yongqiang.Sun@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 21:41:34 +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: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 X-Archived-By: Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] drm/amdgpu: late vm->is_compute_context check in amdgpu_cs_vm_handling() -- commit 217554c6af3d7136df0f66880e6fb5b7119d400b Author: Yongqiang Sun drm/amdgpu: reject CS on a VM that KFD has acquired This commit rejects DRM_IOCTL_AMDGPU_CS command submissions with -EPERM in amdgpu_cs_vm_handling() when the VM has been acquired by KFD. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd= /amdgpu/amdgpu_cs.c > index 71e2b83faa12b..a0f4a0e779c38 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c > @@ -1147,6 +1147,16 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_= parser *p) > if (!amdgpu_vm_ready(vm)) > return -EINVAL; > =20 > + /* > + * KFD acquired this VM. Its notifiers stop KFD queues only, and for > + * an eviction they leave the page tables valid, so a kernel-queue job > + * submitted here can keep using translations after the memory is gone. > + * Jobs submitted before the acquire are already waited for in > + * init_kfd_vm(). > + */ > + if (vm->is_compute_context) > + return -EPERM; > + > r =3D amdgpu_vm_clear_freed(adev, vm, NULL); > if (r) > return r; [Severity: High] Does checking vm->is_compute_context in amdgpu_cs_vm_handling() happen too late, after amdgpu_cs_parser_bos() has already migrated BOs and mutated the KFD VM state without updating its page tables? Before amdgpu_cs_ioctl() reaches amdgpu_cs_vm_handling(), amdgpu_cs_parser_bos() locks the VM and runs: drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c:amdgpu_cs_parser_bos() { ... r =3D 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 =3D amdgpu_cs_bo_validate(p, gem_to_amdgpu_bo(obj)); if (unlikely(r)) goto out_free_user_pages; } ... } amdgpu_vm_validate() moves evicted page table BOs to needs_update and clears vm->evicting =3D false, and amdgpu_cs_bo_validate() validates every locked BO (including vm->root.bo and mapped BOs in p->bo_list) into bo->preferred_domains. When a BO or page table in a fallback domain such as GTT is migrated to VRAM and amdgpu_cs_vm_handling() then returns -EPERM before amdgpu_vm_bo_update(), amdgpu_vm_handle_moved() and amdgpu_vm_update_pdes() run, the old TTM resource is freed while the live KFD compute VM is left with unupdated PDEs/PTEs (and a stale vm->pd_phys_addr if vm->root.bo moved) and vm->evicting cleared. Checking fpriv->vm.is_compute_context in amdgpu_cs_parser_bos() right after drm_exec_until_all_locked(&p->exec) locks the VM PD would reject the submission before any VM or BO state is modified. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130212328.2369= 114-1-Yongqiang.Sun@amd.com?part=3D1