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 9CA60CD4F52 for ; Tue, 19 May 2026 08:32:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 09B4310EB3E; Tue, 19 May 2026 08:32:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="th6v+vGa"; dkim-atps=neutral Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011011.outbound.protection.outlook.com [40.93.194.11]) by gabe.freedesktop.org (Postfix) with ESMTPS id 985EB10EB3E; Tue, 19 May 2026 08:31:58 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VegriXHXbvGDMqqQeGI5qjW6fYKWTcDju7JNVRjhsCgZ1cnDo2ZaKBbe9Xv8qcgYONYa4SBVUhdCytwpHJvoBh2jBrJZvKhccNMN+lHI/yTaeM9mPoBPraj9N0qtICiRlh+mnyNLFaBW5OSwiFvshX3TU0OJFVrV09cBU50TkK1dL1eaMJJlBj+lYMM9oc+PGOCeTK6zmpfJ0sGjHW1St2moEqTIeya6F2ECJ/Q1EfA0J1KLUw4gJU9kWkO1bLLQq7huOZie2LN7IXfJW1j3tPWefxAfhHglSSFNr1ebxThSCI9Gf55kppA06QD7PJJKm1rQ2V51rz0Bq4mMkUiaLw== 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=zQvNJraocaKSDMA/Ppu/MTTgJKyFFNHqxxOVnt1zSz4=; b=fn0hv1xYKh1O2Nxidymh8TNLQbn6O8/huFM67HNxjKTjWbQAdnSfZgVceCMGVbQnRytSizXisJ84xQZISbLzM2yFIScGkMTAdkomd/GSr6gzJTzvLWfraEPYmd+cC4hpUkjLRXJzUsQHEQeCYbSxwMdnLibrLlW3rG4Gz9lZkcS2hLYaNUgwFziMlZWKAAkeBuba6zFs5sONSH1CviG9Xkb7bGqVoVE0+Msc9yh40aQhSpTzByc9Uhhd15b/EfUuKqx7yxkyqX7cPlsVGQOrFpczcnnacZVBtHrkm5D5ggf5fHp3iVUWW6qAIrhDK0pU2VUivxoKFFhjD5ksgH5p3w== 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=zQvNJraocaKSDMA/Ppu/MTTgJKyFFNHqxxOVnt1zSz4=; b=th6v+vGazLqhE5yEs5uMYQW/gmNXPh/d2y+oM0AZcBrBFPAERL9wbPuYQLtu3Er1D8/z0nBJInJlqNkk84+zam9Ah1X26vXPCDoO+Z3j+ZCWpvDexC8yt66obXsPmLrhu5fw/+mu1TrBa9n35R86fVgMfMLDSpLaQDLy2G0QX00= Received: from BY3PR05CA0020.namprd05.prod.outlook.com (2603:10b6:a03:254::25) by BL3PR12MB6402.namprd12.prod.outlook.com (2603:10b6:208:3b2::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.25.24; Tue, 19 May 2026 08:31:53 +0000 Received: from SJ5PEPF000001F1.namprd05.prod.outlook.com (2603:10b6:a03:254:cafe::19) by BY3PR05CA0020.outlook.office365.com (2603:10b6:a03:254::25) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.48.14 via Frontend Transport; Tue, 19 May 2026 08:31:52 +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 SJ5PEPF000001F1.mail.protection.outlook.com (10.167.242.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.11 via Frontend Transport; Tue, 19 May 2026 08:31:52 +0000 Received: from honglei-remote.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; Tue, 19 May 2026 03:31:48 -0500 From: Honglei Huang To: , , , , , , , , , , , , , , , , CC: , , Subject: [RFC V6 02/12] drm/amdgpu: add SVM core header and VM integration Date: Tue, 19 May 2026 16:30:47 +0800 Message-ID: <20260519083057.3108087-3-honglei1.huang@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260519083057.3108087-1-honglei1.huang@amd.com> References: <20260519083057.3108087-1-honglei1.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: SJ5PEPF000001F1:EE_|BL3PR12MB6402:EE_ X-MS-Office365-Filtering-Correlation-Id: 68866d17-5e4d-4644-95a7-08deb581143f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|36860700016|82310400026|1800799024|921020|11063799005|18002099003|22082099003|56012099003|3023799003; X-Microsoft-Antispam-Message-Info: 5CPaJAMlym00f2Unjjzt00+uWke50tnNAAyZVGRXkGSjlaRiKuyQ6h2q9fR/q0R1m3beCnOzdVSzYN9JrlGLvY8+ALWBy0vJiLbru8xeicZ0HDsWcqoTqQkjd9KY+Pjl/uQh//7fwS+uAjGsLQhr27lH62gEbkTnpHp93XI/Xd8NNwn9lsqk3yLI5nMjDVcqVkaZqqSPOtOpWdeKDEQ3bwNlmHEdd1Pwe1WZ0c9yzFNSWuwNviHmXAHPbbo44pkRxMfIKJ7JLTXFbU179ullqevDzYODY195xd9r04nk3ZeCwFE3SHJFv6Iofyo5deoqtuFNbNgdidpi6ClmuCXgK+yy38pNyk6hq9hmCV4p2Pg/lKGAjeRHPdG7EqsJr/MoRwdc/rOgWKftBrzTObYyVwJL+FIDu3LrrQeACW5Xy0zCfSTdjFVb18ssfad0vVS+T7bg63bjnHHIiD8J8EjWQAtxvkuGVRUxAaMuHTpyZiRWTFg1uDiVZFWRdkbgIn1vHFu9J/iEs+eTWTFZKLJQdNqVOHw/wx2WSwrFKIDSlV3ZDz57KDk5KMmLJBSx59y/7AL739X1JVwjDgUNg9KQxUyROGJyYwrN5WePPUhLkKntXYWQ96qmdceD7OAD02v7gIGqRkpbFzD7UWtzPDYJxIbgXngJmEJPDRH5tV28t6R5rm/JyC6Zkxxr8UXAemD8srzrqpULXMAuxRhBcnhys1OVMa//JpCnmNeDaJBG3O1qpWqmYQLhah8EBOdBT+QCxQy3ixtanPgi4wHmqIG7cA== 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)(376014)(36860700016)(82310400026)(1800799024)(921020)(11063799005)(18002099003)(22082099003)(56012099003)(3023799003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LXS+zhmbr4XH2MsOasJpx7cL6gYQXGOHFKGHRpAvz9kbGjF1aUtMowDpb6W+SQ3sfdu0ClL42AZKNQiLTXWzgLCCqo8lZXvxjZZOoJNaLBAuhJdrv0ITtT3/pkr535dmLDIeD2Z8iJXDA7BLzvdaKwqlPds32GCLUD4yWkEVOUj0VinGJGcYs2xSLxLbXuiHh3tEORwsEdPRa27rn5nlGk3Mc51xLrSbzcdkxTol9+lM0IIKspU9K9hsRT2HP8Nrk8pwvtWo9dzAYPGMeO83wOZYNh/bxzhiwxoG56Rds9hOUMyWwS+MfUr2HrLLAhfhiIzKE7byVgcanovCxvb695EuAw2BmvAStD0iPpUZIi1s1HTvcgLPN5gdFt22gcMC9x/pAKY7eQ6O75rop+UtRzWvHUGOP2XUkpEqAonTlVXmkbLQidd3GbqgIMhFEiTZ X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2026 08:31:52.7618 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68866d17-5e4d-4644-95a7-08deb581143f 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: SJ5PEPF000001F1.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR12MB6402 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Honglei Huang Add amdgpu_svm.h with SVM data structures and public API: - enum amdgpu_svm_xnack_mode: OFF, ON, DEFAULT mode selection - struct amdgpu_svm: core context with drm_gpusvm, kref lifecycle, attribute tree, rw_semaphore, GC workqueue, xnack state, flush_tlb and invalidate_ranges function pointers - struct amdgpu_svm_gc: garbage collector with workqueue and work_struct - Debug/trace macros: AMDGPU_SVM_TRACE, AMDGPU_SVM_WARN, AMDGPU_SVM_ERR - Kmem cache helpers: AMDGPU_SVM_KMEM_CACHE_CREATE/DESTROY - Locking helpers: amdgpu_svm_lock/unlock/assert_locked - Public API declarations (including clean_queue, sync_work) with static inline stubs when CONFIG_DRM_AMDGPU_SVM is disabled Add struct amdgpu_svm forward declaration and svm pointer to amdgpu_vm. Signed-off-by: Honglei Huang --- drivers/gpu/drm/amd/amdgpu/amdgpu_svm.h | 195 ++++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 4 + 2 files changed, 199 insertions(+) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_svm.h diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_svm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_svm.h new file mode 100644 index 000000000..49f8b8f06 --- /dev/null +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_svm.h @@ -0,0 +1,195 @@ +/* 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_H__ +#define __AMDGPU_SVM_H__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct amdgpu_device; +struct amdgpu_vm; +struct amdgpu_svm_attr_tree; +struct amdgpu_svm_attrs; +struct drm_device; +struct drm_file; + +enum amdgpu_svm_xnack_mode { + AMDGPU_SVM_XNACK_OFF, + AMDGPU_SVM_XNACK_ON, + AMDGPU_SVM_XNACK_DEFAULT, +}; + +#define AMDGPU_SVM_TRACE(fmt, ...) \ + pr_debug("%s: " fmt, __func__, ##__VA_ARGS__) + +#define AMDGPU_SVM_WARN(fmt, ...) \ + pr_warn("%s: " fmt, __func__, ##__VA_ARGS__) + +#define AMDGPU_SVM_ERR(fmt, ...) \ + pr_err("%s: " fmt, __func__, ##__VA_ARGS__) + +#define AMDGPU_SVM_KMEM_CACHE_CREATE(name, type) \ + kmem_cache_create((name), sizeof(type), 0, 0, NULL) + +#define AMDGPU_SVM_KMEM_CACHE_DESTROY(cache) \ + do { \ + if ((cache) != NULL) { \ + kmem_cache_destroy((cache)); \ + (cache) = NULL; \ + } \ + } while (0) + +#define amdgpu_svm_assert_in_notifier(svm__) \ + lockdep_assert_held_write(&(svm__)->gpusvm.notifier_lock) + +struct amdgpu_svm_gc { + struct workqueue_struct *wq; + struct list_head list; + struct work_struct work; +}; + +struct amdgpu_svm { + struct drm_gpusvm gpusvm; + struct kref refcount; + struct amdgpu_device *adev; + struct amdgpu_vm *vm; + struct amdgpu_svm_attr_tree *attr_tree; + struct rw_semaphore svm_lock; + spinlock_t work_lock; + struct amdgpu_svm_gc gc; + atomic_t exiting; + uint64_t checkpoint_ts; + u8 default_granularity; + bool xnack_enabled; + void (*flush_tlb)(struct amdgpu_svm *svm); + void (*invalidate_ranges)(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); +}; + +static inline struct amdgpu_svm *to_amdgpu_svm(struct drm_gpusvm *gpusvm) +{ + return container_of(gpusvm, struct amdgpu_svm, gpusvm); +} + +static inline void amdgpu_svm_lock(struct amdgpu_svm *svm) +{ + down_write(&svm->svm_lock); +} + +static inline void amdgpu_svm_unlock(struct amdgpu_svm *svm) +{ + up_write(&svm->svm_lock); +} + +static inline void amdgpu_svm_assert_locked(struct amdgpu_svm *svm) +{ + lockdep_assert_held_write(&svm->svm_lock); +} + +#if IS_ENABLED(CONFIG_DRM_AMDGPU_SVM) +int amdgpu_svm_cache_init(void); +void amdgpu_svm_cache_fini(void); + +int amdgpu_svm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm); +void amdgpu_svm_close(struct amdgpu_vm *vm); +void amdgpu_svm_fini(struct amdgpu_vm *vm); + +void amdgpu_svm_put(struct amdgpu_svm *svm); +struct amdgpu_svm *amdgpu_svm_lookup_by_pasid(struct amdgpu_device *adev, + uint32_t pasid); +int amdgpu_svm_handle_fault(struct amdgpu_device *adev, uint32_t pasid, + uint64_t fault_page, uint64_t ts, + bool write_fault); +bool amdgpu_svm_is_enabled(struct amdgpu_vm *vm); + +int amdgpu_gem_svm_ioctl(struct drm_device *dev, void *data, + struct drm_file *filp); +void amdgpu_svm_clean_queue(struct amdgpu_svm *svm, + struct list_head *work_list); +void amdgpu_svm_sync_work(struct amdgpu_svm *svm); +int amdgpu_svm_garbage_collector(struct amdgpu_svm *svm); +int amdgpu_svm_apply_attr_change(struct amdgpu_svm *svm, + const struct amdgpu_svm_attrs *old_attrs, + const struct amdgpu_svm_attrs *new_attrs, + unsigned long start_page, + unsigned long last_page); +#else +static inline int amdgpu_svm_init(struct amdgpu_device *adev, + struct amdgpu_vm *vm) +{ + return 0; +} + +static inline int amdgpu_svm_cache_init(void) +{ + return 0; +} + +static inline void amdgpu_svm_cache_fini(void) +{ +} + +static inline void amdgpu_svm_close(struct amdgpu_vm *vm) +{ +} + +static inline void amdgpu_svm_fini(struct amdgpu_vm *vm) +{ +} + +static inline int amdgpu_svm_handle_fault(struct amdgpu_device *adev, + uint32_t pasid, + uint64_t fault_page, + uint64_t ts, + bool write_fault) +{ + return -EOPNOTSUPP; +} + +static inline bool amdgpu_svm_is_enabled(struct amdgpu_vm *vm) +{ + return false; +} + +static inline int amdgpu_gem_svm_ioctl(struct drm_device *dev, void *data, + struct drm_file *filp) +{ + return -EOPNOTSUPP; +} +#endif /* CONFIG_DRM_AMDGPU_SVM */ + +#endif /* __AMDGPU_SVM_H__ */ diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h index 602deb8a7..9931cc0bb 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h @@ -43,6 +43,7 @@ struct amdgpu_bo_va; struct amdgpu_job; struct amdgpu_bo_list_entry; struct amdgpu_bo_vm; +struct amdgpu_svm; /* * GPUVM handling @@ -449,6 +450,9 @@ struct amdgpu_vm { /* cached fault info */ struct amdgpu_vm_fault_info fault_info; + + /* SVM experimental implementation */ + struct amdgpu_svm *svm; }; struct amdgpu_vm_manager { -- 2.34.1