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 587C5606A31A for ; Tue, 1 Dec 2026 01:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=kWmoDnEU Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EFCD510E33C; Tue, 1 Dec 2026 01:19:54 +0000 (UTC) Received: from CH1PR05CU001.outbound.protection.outlook.com (mail-northcentralusazon11010050.outbound.protection.outlook.com [52.101.193.50]) by gabe.freedesktop.org (Postfix) with ESMTPS id 97D4510E1EC for ; Tue, 1 Dec 2026 01:19:48 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XQaTNXzHaqH+fsyW+cUOeh0c6GqAl4lSirZANQbOdTV5fqbfmfBww3SGV9F8+bKBxbMltWzlmXB5zAS78O9BA83No8yLSAkhESY6wodyfNNhYQ18BP8XlECvHG3ibTkt4bG9u2S/oYNtHtEP0OXCv5wVt6dgSDIYZopRM4FyzjmIIfvdxfvOo8LaBNtAxAnRYvbvcRvm6HJCLWv00CamvVzIWQH0cOsyKgl8T3aMv18y/My1moUmM+LAve5f6WQQYHuW7jMBjVKpDRGRNejHZCjr7cBNtiyRFFLxLDHpGNVqLFof66ipzvlKE9L5WPXIuaJ1cfBaNW93ptjpPftshA== 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=/HN9VFc9vlXgO5qfzpQfmw8eGrPeNc3ZeqLDFugpOBY=; b=JfBQ/QB06NTrUU2E/MRiGkkFjS08GcBBPmfeEQMawG7dE9eZtK2Wz/08ieyT1TecO4D2PlDP5OcsVvZVu2a6TvvyeUfcPw45ptJy1FI5wkUSmNRPoDnMZgJksvHFDcZ2RkYpdpMyOeuVlqB+s7e02s/VHGNMy806rssUGyhDNt7NZ5kioiWVpu7AlIOwlZt1hhtQCwauDvw2Jyqv7BUzhgQOymEs4qQ+vpOm4ef/yllzLfjUuHK7ALbAlFSYfzqLlJcgFcfcuFmzpeoc++TbTaT00BOlF8sShu699vkRns8PWpmTN1O4nveJ2eArB7ycy8YNQhowOmzVM4AypN2pVw== 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=/HN9VFc9vlXgO5qfzpQfmw8eGrPeNc3ZeqLDFugpOBY=; b=kWmoDnEUolQQA0nCXAsxh0WAmpHpH/5vaed5HEJ14ysR2nmfLypSIP4LCnZbqe2w43cyyD2ezhyiyo/N4zwBlkEH3mcqReoP6vdPCP+T/OLRynrLa7kObQBGprhFM+dlc/BOvtEpXUnkeOmyKeGknJYGM7nVqZLtZg3nUtqFQH4= Received: from PH5P220CA0007.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:34a::12) by MN0PR12MB5716.namprd12.prod.outlook.com (2603:10b6:208:373::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 01:19:45 +0000 Received: from PH7PEPF00000013.namprd21.prod.outlook.com (2603:10b6:510:34a:cafe::a8) by PH5P220CA0007.outlook.office365.com (2603:10b6:510:34a::12) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 01:19:45 +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 PH7PEPF00000013.mail.protection.outlook.com (10.167.243.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.2 via Frontend Transport; Tue, 1 Dec 2026 01:19:44 +0000 Received: from 0yonsun-linux-dev.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.57; Mon, 30 Nov 2026 19:19:43 -0600 From: Yongqiang Sun To: CC: Yongqiang Sun Subject: [PATCH] drm/amdgpu: reject CS on a VM that KFD has acquired Date: Mon, 30 Nov 2026 20:19:26 -0500 Message-ID: <20261201011926.2451774-1-Yongqiang.Sun@amd.com> X-Mailer: git-send-email 2.43.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: PH7PEPF00000013:EE_|MN0PR12MB5716:EE_ X-MS-Office365-Filtering-Correlation-Id: 28251013-278d-4cac-7f4b-08df4f492edb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|1800799024|23010399003|36860700016|82310400026|376014|56012099006|10067099003|261026140227099003|261026121527099003|261028144727099003|261102123227099003|261021121427099003|261022105027099003|261009223027099003|18002099003|11063799006; X-Microsoft-Antispam-Message-Info: RbZbG6USouKFCc5L92VGDQ4zaz1ZUjvmD7m+NGFb7x6tk76uAGVittgM60hVfV7JZu/MEWZ9MaccDAPzFR0mokbgrQUZj9b3IMwYPT3XJhFiGnWeZTZdkojkSlIlXkQphRrmfWoxfuoqYEd4sZAi6WlsxjgiL9t2cChxzSkWA/e8U1xYxhDu8PGlnTHljWkoo5Ob+prsEfxS+yH/NIT6i8uuWVBarGFuJ1azYi9u3cBKKk5G4lRE7N/qyrTb4pGVMBktImmK52POOhppkyNivxFEcBPM0oG0Rph/P9yQFHljU2GodBf1+q9lqopEyE1wLjChrsxYfCyDO66i53/ct5o/7/Q1nCTHk18SRx4ZPicCfq3+h2VjIf+q7l8iPumIhcjFf20ZsuA6sg9bX5ahdERUqly5RNJKFs9oLz45wQSqbNWwzTt4CHsfurP8T3I58MpCJohjIJlPvwcRrxXf1RMrai59a4vIqnDgE165n+IFxKiQOqFD0kZDL7NWw6gXO7fR0UJ8wgfuM4s1o2orqUn9p4mXQ/Aqqs6O6d1v7NKBAheIE/+T2w+Noz9sM5FYYk77IAmGG+lGF6w34/lv8hYeHue3VjToMesAyh+WNK/1apAYa+PQnWHkYJTf5CcpzZqVkVB7TCCq7so3RQ+xTwPK56WcFaEg/S47XDCWPKCcw0y6aQpY/wKb0U2tqSspzYlhZAz23DJqsrOEX0/WjA== 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)(23010399003)(36860700016)(82310400026)(376014)(56012099006)(10067099003)(261026140227099003)(261026121527099003)(261028144727099003)(261102123227099003)(261021121427099003)(261022105027099003)(261009223027099003)(18002099003)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cyAgHLcvMGeomaTZAgtuAG1UshhUjUTVYHySaqJNVheMCQ0dqnCU+pFEDUmQYYI6IY219dnJMipiMfoMzE6GWFUVmocIhpUI8TC8XceuMxXYeSJW3OmmBvDspQY8S6DaCRFLzVSUnfL5wLnCJs6LZuots2Mr4DVrespPqHW2j1OcMc7L72XbjX09sSJZlwWMwUz0qUaWr+FC5Rv3m6LmACSxmZ/2IniWocVBwrVxGyoMgCk1fIW+c+brWPiUifyVUAu5Zkf8MoeIc+v5MW1stOj/mt7pyboxJlrjXR7vI/wbJJI1bm+7+2QgQJeOjioZ/x1WncWE1HPZZTXBeGXD/Gf0N1lNmNqw1zti3Uu7BEAgtrVnOT30T8HjYgORL39rO4LAZCZoeynJ1tpj1NmLYPRf+itt1FNhxmhREB11IdRvQyA14VGEx+3/7d4f40rG X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 01:19:44.6542 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 28251013-278d-4cac-7f4b-08df4f492edb 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: PH7PEPF00000013.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5716 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: , Sender: "amd-gfx" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT 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 KFD's userptr and SVM notifiers stop KFD queues only. On the eviction path they leave the GPU page tables valid, so a DRM_IOCTL_AMDGPU_CS job on the acquired VM can keep writing through a translation after the memory is gone. Jobs submitted before ACQUIRE_VM are already waited for in init_kfd_vm(). Refuse later submissions with -EPERM before validating buffers, so the rejection does not move backing store or leave the KFD VM with stale page tables. Signed-off-by: Yongqiang Sun --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 71e2b83faa12b..0360ed53659a5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -964,6 +964,20 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, } } + /* + * 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(). Reject before vm_validate or ttm_bo_validate moves + * anything: a later failure would leave the KFD VM with new backing + * store and stale page tables. + */ + if (vm->is_compute_context) { + r = -EPERM; + goto out_free_user_pages; + } + amdgpu_bo_list_for_each_userptr_entry(e, list) { struct mm_struct *usermm; -- 2.43.0