Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E2EDCCD98D9 for ; Fri, 12 Jun 2026 09:10:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 75E5910F38D; Fri, 12 Jun 2026 09:10:37 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="t50wv/p3"; dkim-atps=neutral Received: from BN8PR05CU002.outbound.protection.outlook.com (mail-eastus2azon11011043.outbound.protection.outlook.com [52.101.57.43]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8376610F38D; Fri, 12 Jun 2026 09:10:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=qQzBYWwMqvKzzJFFjRVX05Agd4j+WX8mhxDF3KmXxuxP4tTJFq3KVwBFafXGGWwQJaxS9QzULg+qfFeRpu90+6Iu1yiiKmeLOwUzV4dbpDXB1vzHR1qRKb7RnoIGkLWjvtWX4ABVmaNV3xDDX0NAbMTFsiiaYnhyCkuI0kapK+4EOueV+jIfxn+Yx5J5n8zsufd5oqbRfq1+BC8pOTTWDHHNggPJsHd5GbPjJ6CE9+zJKmJVulP6zYJ0q1PHxlxE/WdlUooTSwLPmjZoEQw/7RFwro4LgVclDV9IOiZ+VgW2ndr45punQQnJ/1LdqGddVFP2UDG98N+bLYx6XCWZNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4iU8CeFWuyEpEHvBmNLYctswr2elEpA2ZuMBlAGzKnQ=; b=NZDF3CFlnYowUWMbpVa/QHhKbX//KyNvZiDx6hoHrVpwX2v8dHpY+BBfTkWcVR7NkCucTtxcRbLrYdI7pbadALxG4cx2U6DvbHD1natI9DucWhgyU16tal0xJ9pngq8jKQw9yow40ktUUrVrC2D+uKp/GhauehRwDY7CJEByLrm6aAVdce3QuY2H7gK9S3H8gD0l8ZzBUd/IBl4l3/FU+GvCJzOSMmaq7p3XYK5YMzqUm9xDwPcyiFPI8cGT/VYzXgmN1ZcJwv3mnZWOt1UZtTzVK1U+2+pEYgWSyxMbTpZfaSP3cg8aP3yJpk+2z67VQKM3CK69C08SiiZaaMsDxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=ffwll.ch smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4iU8CeFWuyEpEHvBmNLYctswr2elEpA2ZuMBlAGzKnQ=; b=t50wv/p3nqPLN+VNOaOJ9YaEdRCxFfiyLUfRwhs4S9R101dRlMesrag9CFdGsq4DM3NH5/KOWQWll370phAf0RAkpArjTajkOj8yhtPQ5VKGD3kk2ak+UvbuGxZu0t3oqqWudo3OAy+wJZR/hj86Dhjel28HZ6qSlNIn1hl3V6E= Received: from CH0PR03CA0211.namprd03.prod.outlook.com (2603:10b6:610:e7::6) by CH3PR12MB8936.namprd12.prod.outlook.com (2603:10b6:610:179::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.14; Fri, 12 Jun 2026 09:10:30 +0000 Received: from CH1PEPF0000AD7D.namprd04.prod.outlook.com (2603:10b6:610:e7:cafe::16) by CH0PR03CA0211.outlook.office365.com (2603:10b6:610:e7::6) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.92.12 via Frontend Transport; Fri, 12 Jun 2026 09:10:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by CH1PEPF0000AD7D.mail.protection.outlook.com (10.167.244.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.113.7 via Frontend Transport; Fri, 12 Jun 2026 09:10:30 +0000 Received: from hr-amd.amd.com (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.41; Fri, 12 Jun 2026 04:10:25 -0500 From: Huang Rui To: =?UTF-8?q?Christian=20K=C3=B6nig?= , Philip Yang , Alex Deucher , "Felix Kuehling" , Simona Vetter , "Matthew Brost" , Rodrigo Vivi , =?UTF-8?q?Thomas=20Hellstr=C3=B6m?= , Danilo Krummrich , Alice Ryhl , , CC: Xiaogang Chen , Oak Zeng , "Jenny Liu" , Zhu Lingshan , "Honglei Huang" , Junhua Shen , Yiru Ma , Honglei Huang Subject: [PATCH v8 06/18] drm/amdgpu: add SVM range types and work queue interface Date: Fri, 12 Jun 2026 17:09:08 +0800 Message-ID: <20260612090928.29682-7-ray.huang@amd.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260612090928.29682-1-ray.huang@amd.com> References: <20260612090928.29682-1-ray.huang@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD7D:EE_|CH3PR12MB8936:EE_ X-MS-Office365-Filtering-Correlation-Id: eee562d0-5b0b-496b-5206-08dec862739d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|376014|23010399003|36860700016|82310400026|921020|56012099006|11063799006|3023799007|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: 4J+jOz1Q1rLY6F9L49Dwjm0/uK5HWh5M1aivn7Ya2b2w7g0LxgsCWaS5XxVk7Jy9DEBClaGBsAlkKDVRMY80BrouPFCr+XmWUZUS4f8hkIX98cFLARf6YUlnz2JFtfuFzjTbBrJO/1Kp28pywK16TKJmhGPCBRrsXPEggFhUzfWROAxKjbmZWUvCbDBrU3MzGiUh8FGV8FA7BIIpn61o6YqBq/GeLmN9WJ0fi1ZQq7Hg/0ifpPfFAFCCJKu7Vg612gSJDQ443/rqCZT3Ntc9BsQNZ90yIqCtrX8FhEKXIrnxlcu+/yn21/UgpKQ9A4rPFALMQmKC4xw4sCkxuNbZaQzwF61hFrSgig6Tlp/SsCRnAKAxQJ3lRZFkDfOT2qZ5onzAxyfY1RlYlldOd+SM9yiKK0Y+DXct8feKLuVP9m24Hajd14S1PujTK4LghKjKotkxjZKyi0zYZ5m6FztdVBjq6cgOjLYAjTLyyj2BSm35RZxka1gk00SMza2Ep6PIlaqfuUOPl2WBs4WUPG6jXZkc0q0u3SNdYSYQiZEwToa3wj1NwB980Q2ekO4yUHiz2zZfXn73KERkB/i3XLh0RdsfX/q3lCGMMDpiF9dKxRO+zBkDkJbCu99t+kounTZqKLPMzT7ABppyWM9BktvKk4VLGBi2oU1smFvRxh6tPeBuuGYJAE+GKC3vrCV33+kWK/MoquDxHDsOnGfFqOw1yW3HaXb5kcGrddXKZtL5kSNHXulqyzkF3ix5sqT/6gQiCfUBKhnwIBmAaCteVcezWQ== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(1800799024)(376014)(23010399003)(36860700016)(82310400026)(921020)(56012099006)(11063799006)(3023799007)(22082099003)(18002099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3N469zc1Oqn0y1PcZSD/TG02yHEqtroBSyExvRJ+FqrBcwEjnBpojF1BhofE1HAF2UzTZo9MC7tax008VhfZRd5+/SraZE760qAvGWG3NbA+X+E8KD9sjAggdqFBuORJF4C8cLvFx+huvldu3RDz7HzBTIwQD414aUGDmUv9P+7H+NTjEpVNKst+0BG2sgtu4Kaeww1OPdtVqWSecJQboR1c3GzWqKjh0S2VkZP7BYbYxdjcm9+1KER48yNQqGwVkTSiMNfC5qzfD7gPqCCyJP/MrfUsYX0wy6TiNrvLw8b31eF21AqBW2qBueF4xwxYI0PLs6a1zvHu+NzwKGOQtatH7yGi6VG4+dOFLYsqEiAx1dfkxGpuUE+mv+3+zxT3Z0wFQ8AMTpOuOIKoALpgsh4pYRriDl+0T98MalNmQu2Vz2LQxxZDA/nXd1ijUxji X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jun 2026 09:10:30.4949 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eee562d0-5b0b-496b-5206-08dec862739d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000AD7D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8936 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" From: Honglei Huang Add amdgpu_svm_range.h with GPU mapped range types and interfaces: - enum amdgpu_svm_range_queue_state: NOT_QUEUED, IN_GC, PROCESSING states for queue work - struct amdgpu_svm_range: extends drm_gpusvm_range with gpu_mapped state, queue_state, attribute flags, work queue node, pending ops/pages, and validation timestamp - enum amdgpu_svm_range_op: NONE, UNMAP operation types - struct amdgpu_svm_range_op_ctx: dequeue context for GC processing - Inline helper: amdgpu_svm_range_invalidate_gpu_mapping - Range operations API declarations: find_or_insert, get_pages, update_mapping, update_gpu_range, invalidate Signed-off-by: Honglei Huang --- drivers/gpu/drm/amd/amdgpu/amdgpu_svm_range.h | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_svm_range.h diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_svm_range.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_svm_range.h new file mode 100644 index 0000000000000..a079eff86020e --- /dev/null +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_svm_range.h @@ -0,0 +1,165 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* + * Copyright 2026 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + */ + +#ifndef __AMDGPU_SVM_RANGE_H__ +#define __AMDGPU_SVM_RANGE_H__ + +#include +#include + +#include "amdgpu_svm.h" +#include "amdgpu_vm.h" + +#include +#include +#include + +struct amdgpu_svm; +struct amdgpu_svm_attr_range; +struct amdgpu_svm_attrs; +struct dma_fence; +struct drm_exec; +struct drm_gpusvm_notifier; +struct drm_gpusvm_range; +struct mmu_notifier_range; + +enum amdgpu_svm_range_queue_state { + AMDGPU_SVM_RANGE_NOT_QUEUED = 0, + AMDGPU_SVM_RANGE_IN_GC, + AMDGPU_SVM_RANGE_PROCESSING, +}; + +struct amdgpu_svm_range { + struct drm_gpusvm_range base; + struct list_head work_node; + bool gpu_mapped; + u8 queue_state; + u8 pending_ops; + unsigned long pending_start_page; + unsigned long pending_last_page; + uint32_t attr_flags; + ktime_t validate_timestamp; +}; + +static inline struct amdgpu_svm_range * +to_amdgpu_svm_range(struct drm_gpusvm_range *range) +{ + return container_of(range, struct amdgpu_svm_range, base); +} + +static inline void +amdgpu_svm_range_invalidate_gpu_mapping(struct amdgpu_svm_range *range) +{ + WRITE_ONCE(range->gpu_mapped, false); +} + +#define AMDGPU_SVM_RANGE_DEBUG(r__, op__) \ + AMDGPU_SVM_TRACE("%s: pasid=%u, gpusvm=%p, mapped=%d, " \ + "seqno=%lu, range: [0x%lx-0x%lx]-" \ + "0x%lx\n", \ + (op__), to_amdgpu_svm((r__)->base.gpusvm)->vm->pasid, \ + (r__)->base.gpusvm, READ_ONCE((r__)->gpu_mapped), \ + (r__)->base.pages.notifier_seq, \ + drm_gpusvm_range_start(&(r__)->base) >> PAGE_SHIFT, \ + drm_gpusvm_range_end(&(r__)->base) >> PAGE_SHIFT, \ + (drm_gpusvm_range_end(&(r__)->base) - \ + drm_gpusvm_range_start(&(r__)->base)) >> PAGE_SHIFT) + +enum amdgpu_svm_range_op { + AMDGPU_SVM_RANGE_OP_NONE = 0, + AMDGPU_SVM_RANGE_OP_UNMAP = BIT(0), +}; + +struct amdgpu_svm_range_op_ctx { + struct amdgpu_svm_range *range; + unsigned long start_page; + unsigned long last_page; + uint8_t pending_ops; +}; + +#define UNMAP_WORK(ops) ((ops) & AMDGPU_SVM_RANGE_OP_UNMAP) + +void amdgpu_svm_capture_checkpoint_ts(struct amdgpu_svm *svm); + +uint64_t amdgpu_svm_range_attr_pte_flags(struct amdgpu_svm *svm, + const struct amdgpu_svm_attrs *attrs, + bool read_only, + enum drm_interconnect_protocol proto); +int amdgpu_svm_range_lock_vm_pd(struct amdgpu_svm *svm, + struct drm_exec *exec, + bool intr); +bool amdgpu_svm_range_pages_valid(struct amdgpu_svm *svm, + struct amdgpu_svm_range *range); +bool amdgpu_svm_range_is_valid(struct amdgpu_svm *svm, + struct amdgpu_svm_range *range, + const struct amdgpu_svm_attrs *attrs); +int amdgpu_svm_range_update_gpu_range(struct amdgpu_svm *svm, + struct amdgpu_svm_range *range, + const struct amdgpu_svm_attrs *attrs, + bool read_only, + bool flush_tlb, bool wait, + struct dma_fence **fence); +int amdgpu_svm_range_update_mapping(struct amdgpu_svm *svm, + struct amdgpu_svm_range *range, + const struct amdgpu_svm_attrs *attrs, + bool read_only, + bool intr, bool wait, + bool flush_tlb); +bool amdgpu_svm_range_dequeue_locked(struct amdgpu_svm *svm, + struct list_head *work_list, + struct amdgpu_svm_range_op_ctx *op_ctx); +void amdgpu_svm_range_put_if_dequeued(struct amdgpu_svm *svm, + struct amdgpu_svm_range *range); +void amdgpu_svm_range_remove(struct amdgpu_svm *svm, + struct amdgpu_svm_range *range, + struct drm_gpusvm_ctx *ctx); +int amdgpu_svm_range_map_attrs(struct amdgpu_svm *svm, + const struct amdgpu_svm_attrs *attrs, + unsigned long start, unsigned long end); +int amdgpu_svm_range_invalidate_interval(struct amdgpu_svm *svm, + unsigned long start_page, + unsigned long last_page); +int amdgpu_svm_range_zap_ptes(struct amdgpu_svm *svm, + struct amdgpu_svm_range *range, + unsigned long start_page, + unsigned long last_page); +void amdgpu_svm_range_evict(struct amdgpu_svm *svm, + struct drm_gpusvm_range *range); +void amdgpu_svm_range_invalidate(struct amdgpu_svm *svm, + struct drm_gpusvm_notifier *notifier, + const struct mmu_notifier_range *mmu_range, + struct drm_gpusvm_range *first, + uint64_t adj_start, uint64_t adj_end); +bool amdgpu_svm_range_notifier_event_begin(struct amdgpu_svm *svm, + struct drm_gpusvm_range *range, + const struct mmu_notifier_range *mmu_range); +struct amdgpu_svm_range * +amdgpu_svm_range_find_or_insert(struct amdgpu_svm *svm, unsigned long addr, + unsigned long gpuva_start, unsigned long gpuva_end, + struct drm_gpusvm_ctx *ctx); +int amdgpu_svm_range_get_pages(struct amdgpu_svm *svm, + struct drm_gpusvm_range *range, + struct drm_gpusvm_ctx *ctx); + +#endif /* __AMDGPU_SVM_RANGE_H__ */ -- 2.53.0