From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50AAF350297; Fri, 21 Nov 2025 13:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732516; cv=none; b=f7DXAMmTzBYQilhlnZcvVAmo4vicRL2SGi4LwBifC7vL4qD2Pc/9Oj935j4PuvW+0WpqqwOnArfijtSP1jzgEpVaLg3+wqPbdQJ9I8gtW9LjmPyt+Rgn3hc91mdiJECVCMowVzITZHPjy5tEov7+FdBUP2MI15WbjYTgiip3lMM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763732516; c=relaxed/simple; bh=701+A1XGZsTlL2lIKV1gVsG3TpHe4UgpUr0rJP6+FJk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QVX6cvn+MhhB5pn0/sW4OReoQK35nraJm5SZQZsQzx76AYP1ui/5ROfi0pRJySgmelcRICR6BZjJHwD7Wlc5/+7Vt+VD+jCX+uATxUAIr1fBkX9F0D0E9GmjJpxbJWLt2Nw4ZnnLUwqzEm0qzzUVzdKsx9Cv6cVUKE8rpr204O4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Lx3vecEt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Lx3vecEt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB2B4C116C6; Fri, 21 Nov 2025 13:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1763732516; bh=701+A1XGZsTlL2lIKV1gVsG3TpHe4UgpUr0rJP6+FJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lx3vecEtTFypGawDrCyCBYGRVMTLFtgi0diEKngxDqEVgf2ifamQLeNmypgU5iwwb qdejgraM51myvQX48oKrDjfYzlos6qcI8Ut1RRA+2hGmqWYZLNlOX74TDq+pwT1SNc S40i6seTYwsF/6ezb4Nnhvl6d/ER7AOr9l1tP01o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Kent Russell , Felix Kuehling , Alex Deucher , Sasha Levin Subject: [PATCH 6.6 149/529] drm/amdkfd: Handle lack of READ permissions in SVM mapping Date: Fri, 21 Nov 2025 14:07:28 +0100 Message-ID: <20251121130236.322481588@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251121130230.985163914@linuxfoundation.org> References: <20251121130230.985163914@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kent Russell [ Upstream commit 0ed704d058cec7643a716a21888d58c7d03f2c3e ] HMM assumes that pages have READ permissions by default. Inside svm_range_validate_and_map, we add READ permissions then add WRITE permissions if the VMA isn't read-only. This will conflict with regions that only have PROT_WRITE or have PROT_NONE. When that happens, svm_range_restore_work will continue to retry, silently, giving the impression of a hang if pr_debug isn't enabled to show the retries.. If pages don't have READ permissions, simply unmap them and continue. If they weren't mapped in the first place, this would be a no-op. Since x86 doesn't support write-only, and PROT_NONE doesn't allow reads or writes anyways, this will allow the svm range validation to continue without getting stuck in a loop forever on mappings we can't use with HMM. Signed-off-by: Kent Russell Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c index 3168d6fb11e76..9ba9732f0172a 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c @@ -1709,6 +1709,29 @@ static int svm_range_validate_and_map(struct mm_struct *mm, next = min(vma->vm_end, end); npages = (next - addr) >> PAGE_SHIFT; + /* HMM requires at least READ permissions. If provided with PROT_NONE, + * unmap the memory. If it's not already mapped, this is a no-op + * If PROT_WRITE is provided without READ, warn first then unmap + */ + if (!(vma->vm_flags & VM_READ)) { + unsigned long e, s; + + svm_range_lock(prange); + if (vma->vm_flags & VM_WRITE) + pr_debug("VM_WRITE without VM_READ is not supported"); + s = max(start, prange->start); + e = min(end, prange->last); + if (e >= s) + r = svm_range_unmap_from_gpus(prange, s, e, + KFD_SVM_UNMAP_TRIGGER_UNMAP_FROM_CPU); + svm_range_unlock(prange); + /* If unmap returns non-zero, we'll bail on the next for loop + * iteration, so just leave r and continue + */ + addr = next; + continue; + } + WRITE_ONCE(p->svms.faulting_task, current); r = amdgpu_hmm_range_get_pages(&prange->notifier, addr, npages, readonly, owner, NULL, -- 2.51.0