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=1796382216; b=NC1PCkT0BsOh76WIzdUT+NpZ0Ye82NFBpNJydjE3pMsiRPL/nmJh2qlM3zWo5i+plWIv Qtz3/whE4FcFgG+kgpo78L0SjhzGES+L+K9tSRa799xKu0uI6m5iJZwd7dHpv2I++qdrV FBO2KwUR4W+WVYm+SmPKK6ZLne+y3NhG37d6mB/pBaWL/66kGOv3IGsU9681SvqpgfCmN Qvl1CqQvgipIl1ILY8Xo+L+BkdWjKr5zsZ7oYolI2tAxllNRD4eB+lnsbNm1GYS0M2Tsm ckTobDLvIQNb5OkoKLTJLSpt0t953FMRLllq1/7VTXZWWx/l3H0LC+Jr5pT4doy++aQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382216; 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=rAO/XkZqLV8UjH+DsQl74C0yuRijIXveoSDO6sSUfaE=; b=dqvGgh/qGWeK8GWNPBFwF5GtfwPYX4JriU4kaf9FS2uxqQVjRyQ0MSQDGj2gx2AAzs1h rzsZIemfrhvRxIz5FMOdwE9kElXIaZh+azR6k9NQjPEjfSDOGXfgfJdtfvsybRezu/CSA RNyAULze8ZGWpTTQufQUoHI+bXi9ilwofzxtdiofwxkMGQJIR+mWdCvmjo+9C1JEphDYn SGBnpKywhoFd2uUVi9e9q5EvXQjE8SjTvIg8DkVjHQXxiiaFZ5pb1Be644BUOXO3aoWXv lyOBrZlAHArSdtl5nfBu5iA2Ebjt/TZwCGuziBRvYmZHlNAiCjI071bRYFS2XkNO/Yg== 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=i2kvJmdP; 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 A49FE606A322; Fri, 4 Dec 2026 11:03:36 +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=i2kvJmdP Received: by smtp.kernel.org (Postfix) with ESMTPSA id 214701F000C2; Fri, 4 Dec 2026 11:03:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382216; bh=rAO/XkZqLV8UjH+DsQl74C0yuRijIXveoSDO6sSUfaE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i2kvJmdPuKh/XD0l1Kkve41a6H1JnuFijq9aMc99X3wdanza4LvtUesbw1wnUeb9H CmuE3v2TndW32jHmSCey+k28CnehNhN/ZaFmZj+/FtE7OO35xioLvHmrBf1Pu3PmxN 8wvbvqpN3F6odNPDC1Ug47FW8T/FPk+q4GUXSNN0= 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 6.18 356/703] drm/amdgpu: Allow cancelling a requested NPS mode Date: Fri, 4 Dec 2026 19:04:15 +0900 Message-ID: <20261204100637.281599183@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-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 @@ -1220,6 +1220,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) @@ -1227,7 +1261,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; @@ -1241,23 +1274,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 @@ -465,6 +465,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 @@ -1636,6 +1636,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); @@ -1664,6 +1665,18 @@ static int gmc_v9_0_late_init(struct amd if (r) return r; + 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); }