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 99D07606A31A for ; Tue, 1 Dec 2026 09:01:11 +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=xgHJ7M7w Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 365D610E2DC; Tue, 1 Dec 2026 09:01:06 +0000 (UTC) Received: from SN4PR0501CU005.outbound.protection.outlook.com (mail-southcentralusazon11011054.outbound.protection.outlook.com [40.93.194.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id 795CB10E2DC for ; Tue, 1 Dec 2026 09:01:00 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D0WyEtsPD/w26CYR/MTIu9TXf8iiZXxH4Blna0STLgw9Jz6NBzPhRbfQBdFky84EC/Y0IeRgL2+zCbW+8InR2ea2e0hRuCHfJ2E/oAcEuiIGGlKIv8bboIkKdRJP3LY3HdjWmcBC8/PKC8LPVItZigRBx/CjWDpGD6Al6Yv5YkGnTzJ5gdEKbz8ZEJ3x8Isxug1fNJaC9Y66mKh40Q7YYJN6Y9q5vYF14JDEbOOz3qfMfz2p4uR011Ggb6wmewT1pJyrzFCquTJz3R1GV2lvh8G/rm30xVQEcCzi6D7XUEnxhzRpjShABEIWPYmyWeLLd3wXFqzQRD5wYIGd4wxfoA== 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=zElhaCmF5hLanxcI9nTPFQIDEUCnkp458yl+rPWtMfY=; b=ykOU4r49yzpvUGy4zqeYDHNppqAvnEQjCTOiQZ6IOFbUvqrmLZeOati8QZz98XXYc93yb0kHe5y5q+vjIF7uhxkDwPCgPGUbe6iLB8ivLnIz0f/k4piN7QYifuphb8obrQ6WqOmz1dFuoaJko1B/YlczVlbzFrb7m5xH5riWzZaZlMdVvHmn43qpzx3PYBD+7MTq24bheGbRutuJgZflGEq4V/Hze6ZvBoJmoGgRPQx2+l05oGpSXen+0Bt8VWJlU9IKSOl9rCvNpC5Y043Kh96gBTgmU94Uk+8u2ps+83I7nt8kLrgkwxnIQ4D0hd/iAPKTcF7lmen2ThXW+5zjig== 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=zElhaCmF5hLanxcI9nTPFQIDEUCnkp458yl+rPWtMfY=; b=xgHJ7M7w8Nn+sMzYsLZ2Xbp35ERcyFOooUA2WQ89ZjSDUVHrVPsXGFqMgm1bDLcrcLySBuVGDO7ASwRGA7s1Stkl9cQ9aXuDUBDtcCR1NcnUcPK3nWKADK3r1TETng8m0z33FU39bVkiiU1e1gueoMPjGSw4v+PCJ8O45ftVtzo= Received: from BY5PR03CA0015.namprd03.prod.outlook.com (2603:10b6:a03:1e0::25) by SA3PR12MB7924.namprd12.prod.outlook.com (2603:10b6:806:313::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.7; Tue, 1 Dec 2026 09:00:54 +0000 Received: from SJ1PEPF000037A4.namprd04.prod.outlook.com (2603:10b6:a03:1e0:cafe::8c) by BY5PR03CA0015.outlook.office365.com (2603:10b6:a03:1e0::25) 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 09:00:53 +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 SJ1PEPF000037A4.mail.protection.outlook.com (10.167.244.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 09:00:53 +0000 Received: from pyuan-Chachani-VN.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; Tue, 1 Dec 2026 03:00:48 -0600 From: Perry Yuan To: CC: , , , Subject: [PATCH 2/3] drm/amdkfd: Fix leaked PTL disable request on process exit Date: Tue, 1 Dec 2026 17:00:27 +0800 Message-ID: <20261201090028.86494-2-perry.yuan@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261201090028.86494-1-perry.yuan@amd.com> References: <20261201090028.86494-1-perry.yuan@amd.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PEPF000037A4:EE_|SA3PR12MB7924:EE_ X-MS-Office365-Filtering-Correlation-Id: 68c12d97-e772-4b36-eba6-08df4f899ae9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700016|23010399003|376014|82310400026|1800799024|261021121427099003|56012099006|10067099003|261022105027099003|261028144727099003|261026140227099003|261026121527099003|261102123227099003|261021123027099003|261009223027099003|11063799006|18002099003|22082099003; X-Microsoft-Antispam-Message-Info: Kqk1L48k7lz+MbK1s/2NPf5ZznLF7oYW8WvaIHSeKxpS4c1C6YXqA2WhMGQnUeEeET/RlAEEGGGtSoiozOCjklOEPlKWcNeIrG4F/mGOs0hNi6gfTC/v/4vJzBqfe8DGQBz9nE4AM/+GbEG1lPzBpMDvXy5Zb7Dd3L5jRcQdhEXmgmsoTAn138a+scuUZ32yHgFvFN8sA/cLj2KOwkc5bzpk2IJvSnsOwlYSAAMMR34VhmuoJt23rwPdokIl+GLiAE5k9rniIi9KWKQOnH/AkAN7XyMRjGb6p/K/GeCCPGodla1ZX1w7K2V6klXj8KtJUnX158L+9w8I9tYzimtUo16iPv/cjMvUzRHk5NdYxSdaaPO6e8huqJ6qhfVSfYjzfN9vq5eNAzOpVlMvOEqlpVdfd7ms/3/UbbYYEzciNVr3NcaNmeMoUaDaFqeVzDerWyTtcAANPXsM1Jkwr9H/iCkw+WdcZSP/SXPOOxIGaS0YzMLnUZ4LSn3PBhBsd7CVAmQTmjD/WLrQKO+h2OJFRn8Pfh9dRU/QbyuGo5xI1WOJDEAAB4QvG2IbQwMBjEwZ51GfOvG/mO2JaZC4pXQBXl0zH82uoGc8qYBZWqJPVP+6IEv63fMidEg7JMlNNG1FzamXrIB32dIHbbnA6abOAc31Un3i1LgDZhg2bBdNkrQPlK95EnaF1rWEOZT7aBedYlzCL2xweiZgVAKaq12Rrw== 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)(36860700016)(23010399003)(376014)(82310400026)(1800799024)(261021121427099003)(56012099006)(10067099003)(261022105027099003)(261028144727099003)(261026140227099003)(261026121527099003)(261102123227099003)(261021123027099003)(261009223027099003)(11063799006)(18002099003)(22082099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9pzZNQ+WVPsgWJttJp/HWcC1LJ64VO0sqMMbv3h9iNbnzVaOoNo2697GMDmadcX2PbLnVF6NgkvmM7i7oRnby/Y6m1HclNxC2XVfU3X47ZboYjE41oyxQDnUGsrN6Qr1S3Lvid+2qzZH//cRXDjRM7X82uBOW/09eIoy60MulSfmgQg6/YmbnBVvuQYdwGTdD/I89Zh8FH0HpKRENF0zAmlWaVPm9RKS+aXQqG5CCTmUELPsljnrYgtCR9FSVuKtNyCM8LiL7Ge/fP3ttMGULt+Ya/VCJCu0txZvMaOnkxWUpjOaaUlO6W85LRG0UAdmgPbosVFoaPjqfUXXk5mhA9ATfJDs60d+2c1dMe1+l89NS+nfHiQT/zKEL10qMOmvmhwLIM/Y4cRgSrxcyPBaweo+kaWJ+ZNCIRYAKiuVaO2JwKc5s18vyxGgctbnirGM X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 09:00:53.6998 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 68c12d97-e772-4b36-eba6-08df4f899ae9 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: SJ1PEPF000037A4.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7924 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 When the last profiler releases its PTL disable request, KFD tries to enable PTL. If that fails, KFD restores the request so the owner can retry. At process teardown, however, kfd_process_destroy_pdds() frees the owner immediately after the release. The restored request then has no owner. Subsequent profiler sessions never drop the reference count to zero, and the profiler bit blocks attempts to enable PTL via sysfs. On the final release, report the enable error but do not restore the request. The next profiler release or sysfs enable can then retry the hardware operation. Keep the existing rollback for explicit releases. Fixes: dd61e27535a6 ("drm/amdkfd: Add PTL control IOCTL Option and unify refcount logic") Signed-off-by: Perry Yuan --- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 16 +++++++++------- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +-- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c index ae5b430a0031..43cb0af5e527 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -1882,8 +1882,7 @@ int kfd_ptl_disable_request(struct kfd_process_device *pdd, return ret; } -int kfd_ptl_disable_release(struct kfd_process_device *pdd, - struct kfd_process *p) +int kfd_ptl_disable_release(struct kfd_process_device *pdd, bool final) { struct amdgpu_device *adev = pdd->dev->adev; struct amdgpu_ptl *ptl = &adev->psp.ptl; @@ -1901,10 +1900,13 @@ int kfd_ptl_disable_release(struct kfd_process_device *pdd, clear_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap); ret = kfd_ptl_control(pdd, true); if (ret) { - atomic_inc(&ptl->disable_ref); - set_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap); dev_warn(adev->dev, "Failed to enable PTL on release: %d\n", ret); - goto out; + /* Only a live pdd can retry the release. */ + if (!final) { + atomic_inc(&ptl->disable_ref); + set_bit(AMDGPU_PTL_DISABLE_PROFILER, ptl->disable_bitmap); + goto out; + } } } pdd->ptl_disable_req = false; @@ -1930,7 +1932,7 @@ static int kfd_profiler_ptl_control(struct kfd_process *p, if (args->enable == 0) ret = kfd_ptl_disable_request(pdd, p); else - ret = kfd_ptl_disable_release(pdd, p); + ret = kfd_ptl_disable_release(pdd, false); return ret; } @@ -3444,7 +3446,7 @@ static inline int profile_lock_device(struct kfd_process *p, up_read(&kfd->adev->reset_domain->sem); if (ptl->hw_supported_state == AMDGPU_PTL_HW_SUPPORTED) { - status = kfd_ptl_disable_release(pdd, p); + status = kfd_ptl_disable_release(pdd, false); if (status) dev_err(kfd_device, "Failed to unlock device %d for profiling, error %d\n", diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 8eac086aa108..4950a8b9d162 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -1661,8 +1661,7 @@ static inline bool kfd_is_first_node(struct kfd_node *node) /* PTL support */ int kfd_ptl_disable_request(struct kfd_process_device *pdd, struct kfd_process *p); -int kfd_ptl_disable_release(struct kfd_process_device *pdd, - struct kfd_process *p); +int kfd_ptl_disable_release(struct kfd_process_device *pdd, bool final); /* Debugfs */ #if defined(CONFIG_DEBUG_FS) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 5dc657f32d38..a5ec822077b6 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -1258,7 +1258,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) kfd_process_profiler_release(p, pdd); if (pdd->ptl_disable_req) - kfd_ptl_disable_release(pdd, p); + kfd_ptl_disable_release(pdd, true); kfd_process_device_destroy_cwsr_dgpu(pdd); kfd_process_device_destroy_ib_mem(pdd); -- 2.34.1