From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380692; b=ry903unODsmhk4Pu6bxaWlSQEJYfFFXNfFRqXKWmxgR6Bxn+x35bEG3JqaIyQE3Rj3Lf 2vhp86uE+t3naH2vKhUQuiJbkzW6m/qmDBJC6A7g6SP/rJt49K0Eqh9zDII5Cn42Gezdi g8q5/IULujKVXbEjbB/YciQRYLFjgFXQcnZC8bPd2vlIzv0DIOlxH0z3Crfp3NlYA5GMY bvMxfzMKdw99yTleLERXvLqGw+U2BN7mAq23XKh/73+1dOgpf8yskdRlMDGlhpYvq6Sq2 hPrgene8iWGFlPlmS17d/E+siX0COnQ+e97M5N+A121sISJxHje/hG53od+mwHW3mXg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380692; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=Sfpk6m8huwL8+umR1n8HPHA00e6D+Ci0OP4cQD0WP74=; b=Xnc3b1U1QVgBLDu0JI3zEMYbgezoxLI4Kq2rw2mWviK7c3konJMxHWu5UvO4VpoGsOE4 0NgZBwrr/boHss2AdWljAaIVV869eWHCdHsWXQELP1/Tpf1mZCGx0urf5taWKybGWd3L/ eTjGBkr8I4gBNw886IeeNK9x24TdY7xzN15l16TYfLpruqND2swaQoNPj+cKm5FCDNk78 Tg7Grqy6MWj5X5/yOHAwm5EdtekWxQv59UQUxcEaueWC9fWfscwiWXS0LuvJBQfegKsBg /RhuiZUYMMn94rHLD8/qE5/Ow/cP/l9XMtA09lZAwQ39D2YNk+yWtlvqLzfB9/1ozUw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UaUB4q4W; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C472606A322; Fri, 4 Dec 2026 10:38:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=UaUB4q4W Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAB631F000C2; Fri, 4 Dec 2026 10:38:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380692; bh=Sfpk6m8huwL8+umR1n8HPHA00e6D+Ci0OP4cQD0WP74=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UaUB4q4Wz9iD/OdTnS/4DQMCJ062mwJyXNW0snBlSjyxAnfpbWIgQyHeDrss9YrDk p8H6RPQaaYD8laARN/hhdSod0RRLhrQgbMuYKqof7kEZGciJzSoeEt6A0YvKluJW5k KpT3csC059aemP8jPKelmhrSUX5AO0TzE0kHZWJI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lijo Lazar , Asad Kamal , Alex Deucher Subject: [PATCH 7.3 382/742] drm/amdgpu: Allow cancelling a requested NPS mode Date: Fri, 4 Dec 2026 19:04:06 +0900 Message-ID: <20261204100645.233582868@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lijo Lazar commit 9284db9e6ebf300b754b406525576d4848ea96f5 upstream. NPS mode change request doesn't allow to request the current mode. This causes an issue where a user stores a request and later wants to cancel the request by writing the current mode back. The pending request stays the same as before. Allow user to change the mode by comparing against the cached request. Writing the current mode back clears the pending request without asking for a reload. Fixes: 012be6f22c01 ("drm/amdgpu: Add sysfs interfaces for NPS mode") Signed-off-by: Lijo Lazar Reviewed-by: Asad Kamal Signed-off-by: Alex Deucher (cherry picked from commit 595b5879f1bf776a8c2d085253d3bff2d19dfb57) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 52 ++++++++++++++++++++++++-------- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 4 ++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 13 ++++++++ 3 files changed, 56 insertions(+), 13 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c @@ -1281,6 +1281,40 @@ static ssize_t available_memory_partitio return size; } +void amdgpu_gmc_set_requested_nps_mode(struct amdgpu_device *adev, + enum amdgpu_memory_partition mode) +{ + struct amdgpu_hive_info *hive; + + /* If device is part of hive, all devices in the hive should request the + * same mode. Hence store the requested mode in hive. + */ + hive = amdgpu_get_xgmi_hive(adev); + if (hive) { + atomic_set(&hive->requested_nps_mode, mode); + amdgpu_put_xgmi_hive(hive); + } else { + adev->gmc.requested_nps_mode = mode; + } +} + +enum amdgpu_memory_partition +amdgpu_gmc_get_requested_nps_mode(struct amdgpu_device *adev) +{ + struct amdgpu_hive_info *hive; + enum amdgpu_memory_partition mode; + + hive = amdgpu_get_xgmi_hive(adev); + if (hive) { + mode = atomic_read(&hive->requested_nps_mode); + amdgpu_put_xgmi_hive(hive); + } else { + mode = adev->gmc.requested_nps_mode; + } + + return mode; +} + static ssize_t current_memory_partition_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -1288,7 +1322,6 @@ static ssize_t current_memory_partition_ struct drm_device *ddev = dev_get_drvdata(dev); struct amdgpu_device *adev = drm_to_adev(ddev); enum amdgpu_memory_partition mode; - struct amdgpu_hive_info *hive; int i; mode = UNKNOWN_MEMORY_PARTITION_MODE; @@ -1302,23 +1335,16 @@ static ssize_t current_memory_partition_ if (mode == UNKNOWN_MEMORY_PARTITION_MODE) return -EINVAL; - if (mode == adev->gmc.gmc_funcs->query_mem_partition_mode(adev)) { + if (mode == amdgpu_gmc_get_requested_nps_mode(adev)) { dev_info( adev->dev, - "requested NPS mode is same as current NPS mode, skipping\n"); + "requested NPS mode is same as current/already requested NPS mode, skipping\n"); return count; } - /* If device is part of hive, all devices in the hive should request the - * same mode. Hence store the requested mode in hive. - */ - hive = amdgpu_get_xgmi_hive(adev); - if (hive) { - atomic_set(&hive->requested_nps_mode, mode); - amdgpu_put_xgmi_hive(hive); - } else { - adev->gmc.requested_nps_mode = mode; - } + amdgpu_gmc_set_requested_nps_mode(adev, mode); + if (mode == amdgpu_gmc_query_memory_partition(adev)) + return count; dev_info( adev->dev, --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h @@ -479,6 +479,10 @@ enum amdgpu_memory_partition amdgpu_gmc_get_memory_partition(struct amdgpu_device *adev, u32 *supp_modes); enum amdgpu_memory_partition amdgpu_gmc_query_memory_partition(struct amdgpu_device *adev); +void amdgpu_gmc_set_requested_nps_mode(struct amdgpu_device *adev, + enum amdgpu_memory_partition mode); +enum amdgpu_memory_partition +amdgpu_gmc_get_requested_nps_mode(struct amdgpu_device *adev); int amdgpu_gmc_init_mem_ranges(struct amdgpu_device *adev); void amdgpu_gmc_init_sw_mem_ranges(struct amdgpu_device *adev, struct amdgpu_mem_partition_info *mem_ranges); --- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c @@ -1616,6 +1616,7 @@ static int gmc_v9_0_early_init(struct am static int gmc_v9_0_late_init(struct amdgpu_ip_block *ip_block) { struct amdgpu_device *adev = ip_block->adev; + bool nps_switch_support; int r; r = amdgpu_gmc_allocate_vm_inv_eng(adev); @@ -1640,6 +1641,18 @@ static int gmc_v9_0_late_init(struct amd amdgpu_ras_reset_error_count(adev, AMDGPU_RAS_BLOCK__HDP); } + nps_switch_support = !adev->gmc.xgmi.connected_to_cpu && + (hweight32(adev->gmc.supported_nps_modes & + AMDGPU_ALL_NPS_MASK) > 1); + /* Initialize requested NPS mode to be the same as current mode */ + if (nps_switch_support) { + enum amdgpu_memory_partition mode = + amdgpu_gmc_get_requested_nps_mode(adev); + if (mode == UNKNOWN_MEMORY_PARTITION_MODE) + amdgpu_gmc_set_requested_nps_mode( + adev, amdgpu_gmc_query_memory_partition(adev)); + } + return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0); }