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 089B0CA600A for ; Thu, 8 Oct 2026 07:06:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 93D2F10FC96; Thu, 8 Oct 2026 07:06:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="SaAnahPK"; dkim-atps=neutral Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012026.outbound.protection.outlook.com [52.101.53.26]) by gabe.freedesktop.org (Postfix) with ESMTPS id DB07A10E42F for ; Thu, 8 Oct 2026 07:06:38 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TyEDDf/UQeE9wmmOXqV9TBxZd0SkTKbO6jCkzzDrq2Rjc5JIeHTJ8ndHmPuuGepFcaKDukp8jMxAmYmiPr8fOsQi7d2BSaXMWnncF9m7yMc29cwpdzm30rJ3em1Z9nN76or5y12tZ1s4okpB4dU3QSTkl6b2CGVdesPgUittnvfw+IgXYmiURXyNxw4Of/galYro3CetX1KXRzARDIoenHaatXqcvcpO+rVxREm+mvp6KoXpYum3wJ8CGATH11c1sngxEUiQ9uN1oPWGKJFE9fuw4MGhB4KiEZ7ILN4pz8uwdWr6gld9RICsIK1q5Ln9aWJTgQz975gRjoBQYpe0lA== 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=rvUOYW5D1nzzfLI+jlfhg7raNW32lOrqoXH7JNabfh4=; b=oRAEB93qIQ/F2CNGRmfujRD/R4viM7umjRtko9c/5/AAc/43v9lBZIXsLV/DZJfEf+h7MeJwh2lbKEu1WJVuQYhrkl8XKE98TNRK2gxgk2SXUkIA/JJfO9n1brZpfHCv/sLVzHxFTi1LDfzowAMqreN4hd4Ld9aRiQmZJccIHhilMlnPrOv4tYWT08GUVusKC3xhCiuCs04kvpTxWHtRh4GwLOkE/H0nliS6Rdm9NIuGzKW9xHmHSewO89Pk4jKQlPQAZXvaIlNFv26KXCmj74qf2hVUMxLQzNrxdFZXwD5t7N/13/QhjTuYMvo0GotiCaOdgn4q7oNTllaqMpMf/g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org 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=rvUOYW5D1nzzfLI+jlfhg7raNW32lOrqoXH7JNabfh4=; b=SaAnahPKpBs6oCQSYOb6Rm5oD/yVYelS+vj+OKhVNtZBzTfwe7GtpUeVPS7Fsb8cQjfPf+P0DcREIhaXMP1/duPJHQvwC8jgk9TxuvJxDA17MSGjeLEu39NvCDuP2VpeRZPbzDgyRZ0n05xc2UmE3dTWZKr0iNtNNB/URtWyLIY= Received: from DS1PR04CA0025.namprd04.prod.outlook.com (2603:10b6:8:243::13) by CYYPR12MB8989.namprd12.prod.outlook.com (2603:10b6:930:c2::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.15; Thu, 8 Oct 2026 07:06:34 +0000 Received: from CY4PEPF000392D6.namprd03.prod.outlook.com (2603:10b6:8:243:cafe::50) by DS1PR04CA0025.outlook.office365.com (2603:10b6:8:243::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.496.5 via Frontend Transport; Thu, 8 Oct 2026 07:06:34 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; 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 CY4PEPF000392D6.mail.protection.outlook.com (10.167.247.116) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.496.14 via Frontend Transport; Thu, 8 Oct 2026 07:06:34 +0000 Received: from srishanm-Cloudripper.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.49; Thu, 8 Oct 2026 02:06:29 -0500 From: Srinivasan Shanmugam To: =?UTF-8?q?Christian=20K=C3=B6nig?= , "Alex Deucher" CC: , Srinivasan Shanmugam , Felix Kuehling , Lancelot Six , James Zhu , "Lijo Lazar" , Samuel Pitoiset , Natalie Vock , =?UTF-8?q?Timur=20Krist=C3=B3f?= , Pierre-Eric Pelloux-Prayer Subject: [PATCH 7/7] drm/amdgpu/uapi: Add SET/CLEAR L2 TRAP to VM ioctl Date: Thu, 8 Oct 2026 12:35:42 +0530 Message-ID: <20261008070542.1111149-8-srinivasan.shanmugam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261008070542.1111149-1-srinivasan.shanmugam@amd.com> References: <20261008070542.1111149-1-srinivasan.shanmugam@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit 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: CY4PEPF000392D6:EE_|CYYPR12MB8989:EE_ X-MS-Office365-Filtering-Correlation-Id: f166c23c-3b50-4792-1297-08df250ab011 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|23010399003|36860700016|1800799024|10067099003|11063799006|56012099006|260925021911599003|18002099003|22082099003|260925022911599003|260925021311599003; X-Microsoft-Antispam-Message-Info: NX6gmN/eKEkGBBZ1lDp0VdxJcPMT4D7rYCKo87tshKjmM1EYgKQhlUaS/mzxHXFXf0THCBD18TR0+Ob98Dk9ILmF5ZgwM3Xn13alBdbuWUr4rvP3jkaJYr3ZYixTd+qxeYpiDFp4/SMsZf11VpzziBJ3xm5HnKU5gfjE/bf8FZqYIwVl3QwG9jx4ns9a2ZxtueYblLJTnudmyqcI8J7wIvPo5yScqHaTDPWWFQvGmTgF8IQjXafnyDQVL09r6fAquyTDyBlBRHiHiqn2PZJ3BWj3SMm0rRgq7OXHW4nyFcGgP/BsFjOyaiOy2sNcK1f1cMb20r6yDC7MaUHvYdPbceKKtbbjyHR7Lq987sITDwx30J/NFeaPvFyc3U7MPE4z9q4idxirPfziwUYkVv2OkoDACaosg1yklFq5+9X2FAAksjouoKBkP9CB5D5LXfpi8lDWx5XRuUa9cg4qYLuTdC6WiM9hStXb3k8T9cK2mQyVwB/PvxLB0lOmUOhc2i4SPah+HvanG9Q8hyGhHDurOK/s/auIZc3LMkNAn3Mk0oJSz7KgDdCDy398qrgCwQIqz9+Wk4BDHkUfZS6qhd6iFgnGx3oNSZFuRWoPRdIfkE0yhywICg/MbOcN1XppGRaQzthff3tyrHYumZCmHWmPHCb7eFgI4ZX4TEwexYssiS+EhUGWo74umm7dRLtuDiaUW7SCYpONXPsVo3QtCnidYQ== 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)(82310400026)(23010399003)(36860700016)(1800799024)(10067099003)(11063799006)(56012099006)(260925021911599003)(18002099003)(22082099003)(260925022911599003)(260925021311599003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uqIsrH1GjTXLRCczh8yGDFTB/cJjO2Yqq/knM0tURIcCrZcB+26/JQmaCOa7EAtNKpjI/nP/GPEkxhARic6Nwaw89FETOh9hRG5NrSIAzbLoJWwNM7Ca9rsS2fLYYinPdCOrsbNwj9W7+7I+chUqtTx33Nr6JS+yWCrfRuwuGdpCKBh7mXEY6C9pgYOzxN2IM11Vf5jZyWlSS49jsYougwPGEO0L4cRPptAM6CMXY6ooj3eTcBhzb98tCf9O8YgWPyGOPrCzb4dH5aBRkSX8kwtiENsew76uZ97wCRUHMipv+Pa21pIbE5bPPu+rXJS3+xY40zEZ3CN87gqtEhL79QMqiipfZ7Ltt+n+zvZEoP1AG1ulP/wJQJnvvEshRltfg62/dxfKpw9P845Luw/izwziQbugQYa08HGEzpw7Q40aCJkzN2FM/DS6T4EftAhp X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2026 07:06:34.2823 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f166c23c-3b50-4792-1297-08df250ab011 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: CY4PEPF000392D6.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8989 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" Add SET_L2_TRAP and CLEAR_L2_TRAP operations to the VM ioctl. The second-level trap handler is set per GPUVM. All shader waves using the same GPUVM use the same second-level trap handler, regardless of the queue type. SET_L2_TRAP sets the userspace TBA and TMA addresses for the GPUVM. The kernel checks that both address ranges are mapped in the GPUVM before using them. CLEAR_L2_TRAP clears the second-level TBA and TMA addresses from the first-level trap descriptor. Userspace must keep the TBA and TMA mappings valid after SET_L2_TRAP. The mappings can be removed after CLEAR_L2_TRAP completes successfully. Suggested-by: Christian König Suggested-by: Alex Deucher Cc: Felix Kuehling Cc: Lancelot Six Cc: James Zhu Cc: Lijo Lazar Cc: Samuel Pitoiset Cc: Natalie Vock Cc: Timur Kristóf Cc: Pierre-Eric Pelloux-Prayer Signed-off-by: Srinivasan Shanmugam --- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 29 ++++++++++++ include/uapi/drm/amdgpu_drm.h | 64 ++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index de4071db94f5..d82834004bba 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -3008,6 +3008,35 @@ int amdgpu_vm_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) case AMDGPU_VM_OP_UNRESERVE_VMID: amdgpu_vmid_free_reserved(adev, vm, AMDGPU_GFXHUB(0)); break; + case AMDGPU_VM_OP_SET_L2_TRAP: + if (args->in.l2trap._pad || args->in.l2trap._pad2) + return -EINVAL; + + /* + * Install or replace the per-VM second-level trap handler. + * Applies to all shader waves using this GPUVM regardless of + * queue type. + */ + if (!vm->trap_obj) + return -EOPNOTSUPP; + + return amdgpu_trap_vm_set_l2_trap(adev, vm, + vm->trap_obj, + args->in.l2trap.tba_va, + args->in.l2trap.tba_sz, + args->in.l2trap.tma_va, + args->in.l2trap.tma_sz); + case AMDGPU_VM_OP_CLEAR_L2_TRAP: + if (memchr_inv(&args->in.l2trap, 0, + sizeof(args->in.l2trap))) + return -EINVAL; + + /* Disable the per-VM second-level trap handler. */ + if (!vm->trap_obj) + return -EOPNOTSUPP; + + return amdgpu_trap_vm_clear_l2_trap(adev, vm, + vm->trap_obj); default: return -EINVAL; } diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h index 9317018330ec..6c86d5731ca5 100644 --- a/include/uapi/drm/amdgpu_drm.h +++ b/include/uapi/drm/amdgpu_drm.h @@ -614,10 +614,74 @@ struct drm_amdgpu_userq_wait { #define AMDGPU_VM_OP_RESERVE_VMID 1 #define AMDGPU_VM_OP_UNRESERVE_VMID 2 +/** + * AMDGPU_VM_OP_SET_L2_TRAP - install or replace the second-level trap + * handler for this GPUVM. + * + * The second-level trap handler is a per-GPUVM setting. All shader waves + * using this GPUVM use the same handler regardless of queue type. + * + * TBA is the GPU virtual address of the second-level trap handler code. + * TMA is the GPU virtual address of the second-level trap handler scratch + * memory. Each range must be non-empty and contained within a single mapping + * in this GPUVM. + * + * This operation may block until outstanding GPUVM work completes. + * + * Userspace must keep the TBA and TMA mappings valid while the second-level + * trap handler is installed. + * + * Returns: + * 0 on success; + * -EOPNOTSUPP if the first-level CWSR handler is unavailable; + * -EINVAL if TBA/TMA is invalid or not mapped in this GPUVM; + * negative errno if waiting for GPUVM work or reserving the GPUVM fails. + */ +#define AMDGPU_VM_OP_SET_L2_TRAP 3 + +/** + * AMDGPU_VM_OP_CLEAR_L2_TRAP - disable the second-level trap handler. + * + * This operation may block until outstanding GPUVM work completes. + * + * The l2trap input members must be zero for this operation. + * + * After this operation succeeds, userspace may remove the second-level + * TBA and TMA mappings. + * + * Returns: + * 0 on success; + * -EOPNOTSUPP if the first-level CWSR handler is unavailable; + * -EINVAL if the GPUVM trap state is invalid; + * negative errno if waiting for GPUVM work or reserving the GPUVM fails. + */ +#define AMDGPU_VM_OP_CLEAR_L2_TRAP 4 + struct drm_amdgpu_vm_in { /** AMDGPU_VM_OP_* */ __u32 op; __u32 flags; + union { + struct { + /** GPU VA of second-level trap handler code buffer */ + __u64 tba_va; + /** TBA buffer size in bytes */ + __u32 tba_sz; + /** Explicit padding; tma_va starts at offset 24 */ + __u32 _pad; + /** GPU VA of second-level trap handler scratch buffer */ + __u64 tma_va; + /** TMA buffer size in bytes */ + __u32 tma_sz; + /** Padding to fix total union size at 32 bytes */ + __u32 _pad2; + } l2trap; + /** + * Reserved; keeps the union at a fixed 32-byte size for + * future operations. + */ + __u64 reserved[4]; + }; }; struct drm_amdgpu_vm_out { -- 2.34.1