-------- Forwarded Message -------- Subject: Kernel Updates: HNS3 ROH Fixes, Hisilicon Memory Repair Support, and PCIe Hot-Remove Stability Date: Wed, 18 Nov 2026 23:33:25 +1400 From: xiehaibing (C) <xiehaibing7@h-partners.com> To: kongxinwei (A) <kong.kongxinwei@hisilicon.com> From f0a4e6f187375a4cc31850877a4bdb268c9683b9 Mon Sep 17 00:00:00 2001 From: Haibing Xie <xiehaibing7@h-partners.com> Date: Wed, 18 Nov 2026 15:54:56 +0800 Subject: [PATCH 0/6] Kernel Updates: HNS3 ROH Fixes, Hisilicon Memory Repair Support, and PCIe Hot-Remove Stability The kernel faced multiple issues across Hisilicon and subsystem drivers: the HNS3 ROH driver suffered from heap OOB writes, incorrect error handling, and lack of NULL checks; the OS lacked visibility into Kunpeng SoC online memory repairs; acls_repair_store had incorrect printing and potential NULL pointer dereferences via ACPI_COMPANION; and PCIe hot-remove logic could incorrectly trigger link speed reductions due to stale LBMS flags. Additionally, SVE Direct WQE support was missing in libhns. Fixed the HNS3 driver by correcting buffer allocation logic, ensuring proper error code propagation, and adding defensive NULL checks. Enabled OS-triggered online memory repairs (ACLS and sPPR) for Kunpeng SoCs by adding page solation mechanisms. Corrected printing semantics and added NULL safety for ACPI companions. Implemented a minimal fix to clear LBMS during PCIe hot-remove to prevent erroneous link retrains, and added the SVE DWQE flag to support libhns functionality. Junhao He (1): soc: hisilicon: Add checks against NULL pointer reference Xiaofei Tan (2): soc: hisilicon: Support memory repair driver on Kunpeng SoC soc: hisilicon: Fix one printing issue and simplify some printing Yixing Liu (1): RDMA/hns: Add SVE DIRECT WQE flag to support libhns kangfenglong (2): Fix AI-reviewed issues in roh driver pciehp: Clear LBMS on hot-remove to prevent link speed reduction MAINTAINERS | 6 + drivers/infiniband/hw/hns/hns_roce_device.h | 1 + drivers/infiniband/hw/hns/hns_roce_qp.c | 3 + drivers/pci/hotplug/pciehp_ctrl.c | 3 + drivers/roh/core/sysfs.c | 12 +- drivers/roh/hw/hns3/hns3_main.c | 4 +- drivers/roh/hw/hns3/hns3_verbs.c | 4 +- drivers/soc/hisilicon/Kconfig | 13 + drivers/soc/hisilicon/Makefile | 1 + drivers/soc/hisilicon/hisi_mem_ras.c | 586 ++++++++++++++++++++ drivers/soc/hisilicon/hisi_mem_ras.h | 112 ++++ include/uapi/rdma/hns-abi.h | 1 + 12 files changed, 739 insertions(+), 7 deletions(-) create mode 100644 drivers/soc/hisilicon/hisi_mem_ras.c create mode 100644 drivers/soc/hisilicon/hisi_mem_ras.h -- 2.33.0 From 9ec549d84867654fe5de0d31fa6a55947dfb3950 Mon Sep 17 00:00:00 2001 From: kangfenglong <kangfenglong@huawei.com> Date: Wed, 29 Jul 2026 16:33:54 +0800 Subject: [PATCH OLK-6.6 1/6] Fix AI-reviewed issues in roh driver driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10353 ---------------------------------------------------------------------- Fix three issues found by AI code review in the roh driver, aligning the fixes with olk-5.10. Applies to drivers/roh/ in kernel_v5r9_polestar and polestar_v5r9c10. 1. Fix heap OOB write in hns3_roh_alloc_hw_stats for private MIB (polestar_v5r9c10 only; kernel_v5r9_polestar already fixed) hns3_roh_get_hw_stats() fills stats->value[] per descriptor for ROH_MIB_PRIVATE, writing HNS3_ROH_RD_OTHER_STATS_NUM (=4) u64 per desc, i.e. total written = ceil(num_counters/4) * 4. But hns3_roh_alloc_hw_stats() only allocated num_counters u64. When num_counters is not a multiple of 4, get_hw_stats writes past the kzalloc'd buffer, causing a heap out-of-bounds write. before: stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64), GFP_KERNEL); after: num_mib_private_value = DIV_ROUND_UP(num_counters, HNS3_ROH_RD_OTHER_STATS_NUM) * HNS3_ROH_RD_OTHER_STATS_NUM; stats = kzalloc(sizeof(*stats) + num_mib_private_value * sizeof(u64), GFP_KERNEL); stats->num_counters stays as num_counters, so sysfs visible counter count is unchanged; the extra slots are a safe write margin matching the per-descriptor fill in get_hw_stats. 2. Fix wrong return value in hns3_roh_dfx_cmd_write (both targets) hns3_roh_dfx_cmd_write() returned the wrong value in two error paths: - kzalloc failure returned `count` instead of -ENOMEM, masking the allocation failure from userspace. - Function end returned `count` unconditionally, dropping the error code from hns3_roh_dfx_check_cmd(), so invalid dfx commands were reported as success. before: if (!cmd_buf) return count; ... return count; after: if (!cmd_buf) return -ENOMEM; ... return ret ? ret : count; 3. Add NULL check before kfree in free_hw_stats (both targets) free_hw_stats() unconditionally called kfree() on hw_private_stats and hw_public_stats. Add NULL guards to avoid redundant free / keep pointers sane on repeat calls. kfree(NULL) is itself safe, so this is defensive hardening, not a fix for an active crash. before: kfree(device->hw_private_stats); device->hw_private_stats = NULL; kfree(device->hw_public_stats); device->hw_public_stats = NULL; after: if (device->hw_private_stats) { kfree(device->hw_private_stats); device->hw_private_stats = NULL; } if (device->hw_public_stats) { kfree(device->hw_public_stats); device->hw_public_stats = NULL; } Files changed: drivers/roh/core/sysfs.c (both targets) drivers/roh/hw/hns3/hns3_main.c (both targets) drivers/roh/hw/hns3/hns3_verbs.c (polestar_v5r9c10 only) Kconfig, Makefile and core/core.c are intentionally left unchanged: Kconfig keeps ARM64/NET_VENDOR_HISILICON deps; core.c keeps const qualifier on roh_device_uevent (required by target class.dev_uevent signature) and strscpy (modern API, available in both targets). Fixes: d7e48f100166 ("net: hns3: add dcbnl_setbuffer and dcbnl_getbuffer support for pf") Signed-off-by: kangfenglong <kangfenglong@huawei.com> Signed-off-by: Haibing Xie <xiehaibing7@h-partners.com> --- drivers/roh/core/sysfs.c | 12 ++++++++---- drivers/roh/hw/hns3/hns3_main.c | 4 ++-- drivers/roh/hw/hns3/hns3_verbs.c | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/drivers/roh/core/sysfs.c b/drivers/roh/core/sysfs.c index edb9f7ef3f6f..e78cacc51fa4 100644 --- a/drivers/roh/core/sysfs.c +++ b/drivers/roh/core/sysfs.c @@ -158,10 +158,14 @@ static struct attribute *alloc_hsa(const char *name, static void free_hw_stats(struct roh_device *device) { - kfree(device->hw_private_stats); - device->hw_private_stats = NULL; - kfree(device->hw_public_stats); - device->hw_public_stats = NULL; + if (device->hw_private_stats) { + kfree(device->hw_private_stats); + device->hw_private_stats = NULL; + } + if (device->hw_public_stats) { + kfree(device->hw_public_stats); + device->hw_public_stats = NULL; + } } static int alloc_and_get_hw_stats(struct roh_device *device) diff --git a/drivers/roh/hw/hns3/hns3_main.c b/drivers/roh/hw/hns3/hns3_main.c index def17c8134e8..ec3c6e390e83 100644 --- a/drivers/roh/hw/hns3/hns3_main.c +++ b/drivers/roh/hw/hns3/hns3_main.c @@ -465,7 +465,7 @@ static ssize_t hns3_roh_dfx_cmd_write(struct file *filp, const char __user *buff cmd_buf = kzalloc(count + 1, GFP_KERNEL); if (!cmd_buf) - return count; + return -ENOMEM; uncopied_bytes = copy_from_user(cmd_buf, buffer, count); if (uncopied_bytes) { @@ -488,7 +488,7 @@ static ssize_t hns3_roh_dfx_cmd_write(struct file *filp, const char __user *buff kfree(cmd_buf); cmd_buf = NULL; - return count; + return ret ? ret : count; } static const struct file_operations hns3_roh_dfx_cmd_fops = { diff --git a/drivers/roh/hw/hns3/hns3_verbs.c b/drivers/roh/hw/hns3/hns3_verbs.c index 9356b31786d6..2a50d7f82377 100644 --- a/drivers/roh/hw/hns3/hns3_verbs.c +++ b/drivers/roh/hw/hns3/hns3_verbs.c @@ -162,6 +162,7 @@ static const char * const hns3_roh_hw_stats_name_private[] = { struct roh_mib_stats *hns3_roh_alloc_hw_stats(struct roh_device *rohdev, enum roh_mib_type mib_type) { struct roh_mib_stats *stats = NULL; + u32 num_mib_private_value; u32 num_counters; switch (mib_type) { @@ -175,7 +176,8 @@ struct roh_mib_stats *hns3_roh_alloc_hw_stats(struct roh_device *rohdev, enum ro break; case ROH_MIB_PRIVATE: num_counters = ARRAY_SIZE(hns3_roh_hw_stats_name_private); - stats = kzalloc(sizeof(*stats) + num_counters * sizeof(u64), GFP_KERNEL); + num_mib_private_value = DIV_ROUND_UP(num_counters, HNS3_ROH_RD_OTHER_STATS_NUM) * HNS3_ROH_RD_OTHER_STATS_NUM; + stats = kzalloc(sizeof(*stats) + num_mib_private_value * sizeof(u64), GFP_KERNEL); if (!stats) return NULL; stats->names = hns3_roh_hw_stats_name_private; -- 2.33.0 From 082f873d14de0a6ccb8038dfb92796bd6da3d5c0 Mon Sep 17 00:00:00 2001 From: Xiaofei Tan <tanxiaofei@huawei.com> Date: Mon, 5 Aug 2024 18:09:54 +0800 Subject: [PATCH OLK-6.6 2/6] soc: hisilicon: Support memory repair driver on Kunpeng SoC driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10353 ---------------------------------------------------------------------- Kunpeng SoC support several memory repair capability. Normally, such repairs are done in firmware startup stage or triggered by BMC(Baseboard Management Controller) and done in firmware in runtime stage. OS can't perceive such capability. Some support online repair, while others can't. One reason of not supporting online repair is that the memory is in use and the hardware does not support backpressure on the primary access channel. In order to support more online memory repair, we seek solutions from OS. That is try to isolate the memory page first, and do repair, and de-isloate after repair done. This patch support online ACLS(Adapter Cache Line Sparing) repair, and sPPR(Soft Post Package Repair). All need firmware support first. Fixes: d7e48f100166 ("net: hns3: add dcbnl_setbuffer and dcbnl_getbuffer support for pf") Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com> Signed-off-by: Junhao He <hejunhao3@h-partners.com> (cherry picked from commit a774c7f3fd01514087bf740eca38e6090d1f9f28) Signed-off-by: Haibing Xie <xiehaibing7@h-partners.com> --- MAINTAINERS | 6 + drivers/soc/hisilicon/Kconfig | 13 + drivers/soc/hisilicon/Makefile | 1 + drivers/soc/hisilicon/hisi_mem_ras.c | 582 +++++++++++++++++++++++++++ drivers/soc/hisilicon/hisi_mem_ras.h | 112 ++++++ 5 files changed, 714 insertions(+) create mode 100644 drivers/soc/hisilicon/hisi_mem_ras.c create mode 100644 drivers/soc/hisilicon/hisi_mem_ras.h diff --git a/MAINTAINERS b/MAINTAINERS index 5e44ed384a38..3df57e164255 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -9490,6 +9490,12 @@ F: Documentation/ABI/testing/sysfs-devices-platform-kunpeng_hccs F: drivers/soc/hisilicon/kunpeng_hccs.c F: drivers/soc/hisilicon/kunpeng_hccs.h +HISILICON KUNPENG SOC MEMORY RAS DRIVER +M: Xiaofei Tan <tanxiaofei@huawei.com> +S: Maintained +F: drivers/soc/hisilicon/hisi_mem_ras.c +F: drivers/soc/hisilicon/hisi_mem_ras.h + HISILICON LPC BUS DRIVER M: Jay Fang <f.fangjian@huawei.com> S: Maintained diff --git a/drivers/soc/hisilicon/Kconfig b/drivers/soc/hisilicon/Kconfig index 93be217a50da..d2925cb9f9a4 100644 --- a/drivers/soc/hisilicon/Kconfig +++ b/drivers/soc/hisilicon/Kconfig @@ -77,4 +77,17 @@ config HISI_SOC_HHA This driver can be built as a module. If so, the module will be called hisi_soc_hha. +config HISI_MEM_RAS + tristate "Add RAS support for Hisilicon memory device" + depends on ACPI + depends on PCC + depends on ARM64 || COMPILE_TEST + help + Add RAS driver for Hisilicon memory device to repair hardware error of + memory devices in OS side. The driver interacts with firmware through PCC + and provides sysfs files as user-mode interfaces.It could support both + HBM and DDR memory. + + If not sure say no. + endmenu diff --git a/drivers/soc/hisilicon/Makefile b/drivers/soc/hisilicon/Makefile index c2f01fa4862a..37d1ca8b118e 100644 --- a/drivers/soc/hisilicon/Makefile +++ b/drivers/soc/hisilicon/Makefile @@ -8,3 +8,4 @@ obj-$(CONFIG_ARM64_PBHA) += pbha.o obj-$(CONFIG_HISI_SOC_CACHE) += hisi_soc_cache_framework.o obj-$(CONFIG_HISI_SOC_HHA) += hisi_soc_hha.o obj-$(CONFIG_HISI_SOC_L3C) += hisi_soc_l3c.o +obj-$(CONFIG_HISI_MEM_RAS) += hisi_mem_ras.o diff --git a/drivers/soc/hisilicon/hisi_mem_ras.c b/drivers/soc/hisilicon/hisi_mem_ras.c new file mode 100644 index 000000000000..765132cf1c04 --- /dev/null +++ b/drivers/soc/hisilicon/hisi_mem_ras.c @@ -0,0 +1,582 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. + */ + +#include <linux/acpi.h> +#include <linux/module.h> +#include <linux/mm.h> +#include <linux/platform_device.h> +#include <acpi/pcc.h> +#include "hisi_mem_ras.h" + +#define DRV_NAME "hisi_mem_ras" +#define MAX_PCC_CMD_RETRIES 500ULL + +struct hisi_mem_register_ctx { + struct device *dev; + u8 chan_id; + int err; +}; + +static acpi_status hisi_mem_get_chan_id_cb(struct acpi_resource *ares, void *context) +{ + struct acpi_resource_generic_register *reg; + struct hisi_mem_register_ctx *ctx = context; + + if (ares->type != ACPI_RESOURCE_TYPE_GENERIC_REGISTER) + return AE_OK; + + reg = &ares->data.generic_reg; + if (reg->space_id != ACPI_ADR_SPACE_PLATFORM_COMM) { + dev_err(ctx->dev, "Bad register resource.\n"); + ctx->err = -EINVAL; + return AE_ERROR; + } + ctx->chan_id = reg->access_size; + + return AE_OK; +} + +static int hisi_mem_get_pcc_chan_id(struct hisi_mem_dev *hdev) +{ + struct platform_device *pdev = hdev->pdev; + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); + struct hisi_mem_register_ctx ctx = {0}; + acpi_handle handle = adev->handle; + acpi_status status; + + if (!acpi_has_method(handle, METHOD_NAME__CRS)) { + dev_err(&pdev->dev, "No _CRS method.\n"); + return -ENODEV; + } + + ctx.dev = &pdev->dev; + status = acpi_walk_resources(handle, METHOD_NAME__CRS, + hisi_mem_get_chan_id_cb, &ctx); + if (ACPI_FAILURE(status)) + return ctx.err; + + hdev->chan_id = ctx.chan_id; + return 0; +} + +static void hisi_mem_chan_tx_done(struct mbox_client *cl, void *mssg, int ret) +{ + if (ret < 0) + pr_debug("TX did not complete: CMD sent:0x%x, ret:%d\n", + *(u8 *)mssg, ret); + else + pr_debug("TX completed. CMD sent:0x%x, ret:%d\n", + *(u8 *)mssg, ret); +} + +static void hisi_mem_pcc_rx_callback(struct mbox_client *cl, void *mssg) +{ + struct hisi_mem_mbox_client_info *cl_info = + container_of(cl, struct hisi_mem_mbox_client_info, client); + + complete(&cl_info->done); +} + +static void hisi_mem_unregister_pcc_channel(struct hisi_mem_dev *hdev) +{ + struct hisi_mem_mbox_client_info *cl_info = &hdev->cl_info; + + pcc_mbox_free_channel(cl_info->pcc_chan); +} + +static int hisi_mem_register_pcc_channel(struct hisi_mem_dev *hdev) +{ + struct hisi_mem_mbox_client_info *cl_info = &hdev->cl_info; + struct mbox_client *cl = &cl_info->client; + struct platform_device *pdev = hdev->pdev; + struct pcc_mbox_chan *pcc_chan; + int rc; + + cl->dev = &pdev->dev; + cl->tx_block = false; + cl->knows_txdone = true; + cl->tx_done = hisi_mem_chan_tx_done; + cl->rx_callback = hisi_mem_pcc_rx_callback; + pcc_chan = pcc_mbox_request_channel(cl, hdev->chan_id); + if (IS_ERR(pcc_chan)) + return dev_err_probe(&pdev->dev, -ENODEV, "PCC channel request failed.\n"); + + if (pcc_chan->shmem_size > HISI_MEM_PCC_SHARE_MEM_BYTES_MAX || + pcc_chan->shmem_size < HISI_MEM_PCC_SHARE_MEM_BYTES_MIN) { + rc = dev_err_probe(&pdev->dev, -EINVAL, "Unsupported PCC shmem size 0x%llx.\n", + pcc_chan->shmem_size); + goto err_mbx_channel_free; + } + + /* + * pcc_chan->latency is just a nominal value. In reality the remote + * processor could be much slower to reply. So add an arbitrary amount + * of wait on top of nominal. + */ + cl_info->deadline_us = MAX_PCC_CMD_RETRIES * pcc_chan->latency; + cl_info->pcc_chan = pcc_chan; + init_completion(&cl_info->done); + if (!pcc_chan->mchan->mbox->txdone_irq) { + rc = dev_err_probe(&pdev->dev, -EINVAL, "PCC IRQ in PCCT isn't supported.\n"); + goto err_mbx_channel_free; + } + + cl_info->pcc_comm_addr = devm_ioremap(&pdev->dev, pcc_chan->shmem_base_addr, + pcc_chan->shmem_size); + if (!cl_info->pcc_comm_addr) { + rc = dev_err_probe(&pdev->dev, -ENOMEM, + "Failed to ioremap PCC communication region for channel-%u.\n", + hdev->chan_id); + goto err_mbx_channel_free; + } + + return 0; + +err_mbx_channel_free: + pcc_mbox_free_channel(cl_info->pcc_chan); + return rc; +} + +static int hisi_mem_wait_cmd_complete_by_irq(struct hisi_mem_dev *hdev) +{ + struct hisi_mem_mbox_client_info *cl_info = &hdev->cl_info; + struct platform_device *pdev = hdev->pdev; + + if (!wait_for_completion_timeout(&cl_info->done, usecs_to_jiffies(cl_info->deadline_us))) { + dev_err(&pdev->dev, "PCC command executed timeout!\n"); + return -ETIMEDOUT; + } + + return 0; +} + +static inline void hisi_mem_fill_ext_pcc_shared_mem_region(struct hisi_mem_dev *hdev, u8 cmd, + struct hisi_mem_desc *desc, + void __iomem *comm_space, + u32 space_size) +{ + struct hisi_mem_mbox_client_info *cl_info = &hdev->cl_info; + struct acpi_pcct_ext_pcc_shared_memory tmp = { + .signature = PCC_SIGNATURE | hdev->chan_id, + .flags = PCC_CMD_COMPLETION_NOTIFY, + .length = cl_info->pcc_chan->shmem_size, + .command = cmd, + }; + + memcpy_toio(hdev->cl_info.pcc_comm_addr, &tmp, sizeof(tmp)); + + /* Copy the message to the PCC comm space */ + memcpy_toio(comm_space, desc, space_size); +} + +static int hisi_mem_pcc_cmd_send(struct hisi_mem_dev *hdev, u8 cmd, + struct hisi_mem_desc *desc) +{ + struct hisi_mem_mbox_client_info *cl_info = &hdev->cl_info; + struct platform_device *pdev = hdev->pdev; + void __iomem *comm_space; + u32 space_size; + int ret; + + mutex_lock(&hdev->lock); + comm_space = cl_info->pcc_comm_addr + sizeof(struct acpi_pcct_ext_pcc_shared_memory); + space_size = cl_info->pcc_chan->shmem_size - sizeof(struct acpi_pcct_ext_pcc_shared_memory); + hisi_mem_fill_ext_pcc_shared_mem_region(hdev, cmd, desc, comm_space, space_size); + reinit_completion(&cl_info->done); + + /* Ring doorbell */ + ret = mbox_send_message(cl_info->pcc_chan->mchan, &cmd); + if (ret < 0) { + dev_err(&pdev->dev, "Send PCC mbox message failed, ret = %d.\n", ret); + goto end; + } + + ret = hisi_mem_wait_cmd_complete_by_irq(hdev); + if (ret) + goto end; + + /* Copy response data */ + memcpy_fromio(desc, comm_space, space_size); + +end: + mbox_chan_txdone(cl_info->pcc_chan->mchan, ret); + mutex_unlock(&hdev->lock); + return ret; +} + +static int check_fw_ret_status(struct device *dev, u8 status, char *cmd_desc) +{ + if (status == HISI_MEM_RAS_NO_RES) { + dev_info(dev, "%s failed due to no resource.\n", cmd_desc); + return -ENOSPC; + } else if (status != HISI_MEM_RAS_OK) { + dev_info(dev, "%s failed due to error code %u.\n", cmd_desc, status); + return -ENXIO; + } + + return 0; +} + +static struct page *trans_and_check_paddr(struct device *dev, const char *buf, u64 *paddr) +{ + struct page *page; + u64 paddr_tmp; + + if (kstrtoull(buf, 16, &paddr_tmp)) + return NULL; + + page = pfn_to_online_page(__phys_to_pfn(paddr_tmp)); + if (!page) { + dev_info(dev, "The page of paddr 0x%llx is not online page.\n", paddr_tmp); + return NULL; + } + + *paddr = paddr_tmp; + return page; +} + +static ssize_t acls_query_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct hisi_mem_dev *hdev = platform_get_drvdata(pdev); + struct hisi_mem_desc desc = {0}; + struct page *page; + u64 paddr; + int ret; + + page = trans_and_check_paddr(dev, buf, &paddr); + if (!page) + return -EINVAL; + + desc.req.req_head.subcmd = HISI_MEM_RAS_QUERY; + desc.req.data[0] = lower_32_bits(paddr); + desc.req.data[1] = upper_32_bits(paddr); + ret = hisi_mem_pcc_cmd_send(hdev, HISI_MEM_RAS_ACLS, &desc); + if (ret) { + dev_err(dev, "ACLS query failed, ret = %d.\n", ret); + return -EIO; + } + + ret = check_fw_ret_status(dev, desc.rsp.rsp_head.ret_status, "ACLS query"); + if (ret) + return ret; + + return count; +} +static DEVICE_ATTR_WO(acls_query); + +static ssize_t acls_repair_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct hisi_mem_dev *hdev = platform_get_drvdata(pdev); + struct hisi_mem_desc desc = {0}; + struct page *page; + u64 paddr; + int ret; + + page = trans_and_check_paddr(dev, buf, &paddr); + if (!page) + return -EINVAL; + + if (hdev->mem_type == MEMORY_TYPE_HBM && !PageHWPoison(page)) { + dev_info(dev, "The page of paddr 0x%llx is not unpoisoned.\n", paddr); + return -EIO; + } + + desc.req.req_head.subcmd = HISI_MEM_RAS_DO_REPAIR; + desc.req.data[0] = lower_32_bits(paddr); + desc.req.data[1] = upper_32_bits(paddr); + ret = hisi_mem_pcc_cmd_send(hdev, HISI_MEM_RAS_ACLS, &desc); + if (ret) { + dev_err(dev, "ACLS repair failed, ret = %d.\n", ret); + return -EIO; + } + + ret = check_fw_ret_status(dev, desc.rsp.rsp_head.ret_status, "ACLS repair"); + if (ret) + return ret; + + return count; +} +static DEVICE_ATTR_WO(acls_repair); + +static ssize_t sppr_query_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct hisi_mem_dev *hdev = platform_get_drvdata(pdev); + struct hisi_mem_desc desc = {0}; + struct page *page; + u64 paddr; + int ret; + + page = trans_and_check_paddr(dev, buf, &paddr); + if (!page) + return -EINVAL; + + desc.req.req_head.subcmd = HISI_MEM_RAS_QUERY; + desc.req.data[0] = lower_32_bits(paddr); + desc.req.data[1] = upper_32_bits(paddr); + ret = hisi_mem_pcc_cmd_send(hdev, HISI_MEM_RAS_SPPR, &desc); + if (ret) { + dev_err(dev, "SPPR query failed, ret = %d.\n", ret); + return -EIO; + } + + ret = check_fw_ret_status(dev, desc.rsp.rsp_head.ret_status, "SPPR query"); + if (ret) + return ret; + + return count; +} +static DEVICE_ATTR_WO(sppr_query); + +static ssize_t sppr_repair_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct hisi_mem_dev *hdev = platform_get_drvdata(pdev); + struct hisi_mem_desc desc = {0}; + struct page *page; + u64 paddr; + int ret; + + page = trans_and_check_paddr(dev, buf, &paddr); + if (!page) + return -EINVAL; + + if (hdev->mem_type == MEMORY_TYPE_HBM && !PageHWPoison(page)) { + dev_info(dev, "The page of paddr 0x%llx is not poisoned.\n", paddr); + return -EIO; + } + + desc.req.req_head.subcmd = HISI_MEM_RAS_DO_REPAIR; + desc.req.data[0] = lower_32_bits(paddr); + desc.req.data[1] = upper_32_bits(paddr); + ret = hisi_mem_pcc_cmd_send(hdev, HISI_MEM_RAS_SPPR, &desc); + if (ret) { + dev_err(dev, "SPPR repair failed, ret = %d.\n", ret); + return -EIO; + } + + ret = check_fw_ret_status(dev, desc.rsp.rsp_head.ret_status, "SPPR repair"); + if (ret) + return ret; + + return count; +} +static DEVICE_ATTR_WO(sppr_repair); + +static const char * const memory_type_name[MEMORY_TYPE_MAX] = { + "HBM", + "DDR", +}; + +static ssize_t memory_type_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + struct hisi_mem_dev *hdev = platform_get_drvdata(pdev); + int ret; + + if (hdev->mem_type < MEMORY_TYPE_MAX) + ret = sysfs_emit(buf, "%s\n", memory_type_name[hdev->mem_type]); + else + ret = sysfs_emit(buf, "Unknown\n"); + + return ret; +} +static DEVICE_ATTR_RO(memory_type); + +static ssize_t memory_type_supported_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + int ret = 0; + int i; + + ret += sysfs_emit_at(buf, ret, "%s", memory_type_name[0]); + for (i = 1; i < MEMORY_TYPE_MAX; i++) + ret += sysfs_emit_at(buf, ret, " %s", memory_type_name[i]); + + ret += sysfs_emit_at(buf, ret, "\n"); + + return ret; +} +static DEVICE_ATTR_RO(memory_type_supported); + +static int hisi_mem_ras_get_attribute(struct hisi_mem_dev *hdev) +{ + struct platform_device *pdev = hdev->pdev; + struct hisi_mem_desc desc = {0}; + int ret; + + ret = hisi_mem_pcc_cmd_send(hdev, HISI_MEM_RAS_CAP, &desc); + if (ret) + return dev_err_probe(&pdev->dev, -EIO, "Get attribute failed, ret = %d.\n", ret); + + if (desc.rsp.rsp_head.ret_status) + return dev_err_probe(&pdev->dev, -EIO, "Device in bad status %u.\n", + desc.rsp.rsp_head.ret_status); + + if (desc.rsp.rsp_head.mem_type >= MEMORY_TYPE_MAX) + return dev_err_probe(&pdev->dev, -EIO, "Unsupported memory type %u.\n", + desc.rsp.rsp_head.mem_type); + + hdev->mem_type = desc.rsp.rsp_head.mem_type; + hdev->ras_cap = desc.rsp.rsp_head.ras_cap; + + return 0; +} + +static struct attribute *memory_type_attrs[] = { + &dev_attr_memory_type.attr, + &dev_attr_memory_type_supported.attr, + NULL, +}; + +static struct attribute_group memory_type_attr_group = { + .attrs = memory_type_attrs, +}; + +static struct attribute *acls_attrs[] = { + &dev_attr_acls_query.attr, + &dev_attr_acls_repair.attr, + NULL, +}; + +static struct attribute_group acls_attr_group = { + .attrs = acls_attrs, +}; + +static struct attribute *sppr_attrs[] = { + &dev_attr_sppr_query.attr, + &dev_attr_sppr_repair.attr, + NULL, +}; + +static struct attribute_group sppr_attr_group = { + .attrs = sppr_attrs, +}; + +static int hisi_mem_create_sysfs_files(struct hisi_mem_dev *hdev) +{ + struct platform_device *pdev = hdev->pdev; + int ret; + + if (hdev->ras_cap & HISI_MEM_CAP_ACLS_EN) { + ret = sysfs_create_group(&pdev->dev.kobj, &acls_attr_group); + if (ret) { + dev_err(&pdev->dev, "Create ACLS sysfs group failed, ret = %d.\n", ret); + return ret; + } + } + + if (hdev->ras_cap & HISI_MEM_CAP_SPPR_EN) { + ret = sysfs_create_group(&pdev->dev.kobj, &sppr_attr_group); + if (ret) { + dev_err(&pdev->dev, "Create SPPR sysfs group failed, ret = %d.\n", ret); + goto acls_files; + } + } + + ret = sysfs_create_group(&pdev->dev.kobj, &memory_type_attr_group); + if (ret) { + dev_err(&pdev->dev, "Create memory type file failed, ret =%d.\n", ret); + goto sppr_files; + } + + return 0; + +sppr_files: + if (hdev->ras_cap & HISI_MEM_CAP_SPPR_EN) + sysfs_remove_group(&pdev->dev.kobj, &sppr_attr_group); + +acls_files: + if (hdev->ras_cap & HISI_MEM_CAP_ACLS_EN) + sysfs_remove_group(&pdev->dev.kobj, &acls_attr_group); + + return ret; +} + +static void hisi_mem_remove_sysfs_files(struct hisi_mem_dev *hdev) +{ + struct platform_device *pdev = hdev->pdev; + + sysfs_remove_group(&pdev->dev.kobj, &memory_type_attr_group); + if (hdev->ras_cap & HISI_MEM_CAP_SPPR_EN) + sysfs_remove_group(&pdev->dev.kobj, &sppr_attr_group); + + if (hdev->ras_cap & HISI_MEM_CAP_ACLS_EN) + sysfs_remove_group(&pdev->dev.kobj, &acls_attr_group); +} + +static int hisi_mem_ras_probe(struct platform_device *pdev) +{ + struct hisi_mem_dev *hdev; + int ret; + + hdev = devm_kzalloc(&pdev->dev, sizeof(struct hisi_mem_dev), GFP_KERNEL); + if (!hdev) + return -ENOMEM; + + hdev->pdev = pdev; + mutex_init(&hdev->lock); + platform_set_drvdata(pdev, hdev); + ret = hisi_mem_get_pcc_chan_id(hdev); + if (ret) + return ret; + + ret = hisi_mem_register_pcc_channel(hdev); + if (ret) + return ret; + + ret = hisi_mem_ras_get_attribute(hdev); + if (ret) + goto unregister_pcc_chan; + + ret = hisi_mem_create_sysfs_files(hdev); + if (ret) + goto unregister_pcc_chan; + + return 0; + +unregister_pcc_chan: + hisi_mem_unregister_pcc_channel(hdev); + + return ret; +} + +static int hisi_mem_ras_remove(struct platform_device *pdev) +{ + struct hisi_mem_dev *hdev = platform_get_drvdata(pdev); + + hisi_mem_remove_sysfs_files(hdev); + hisi_mem_unregister_pcc_channel(hdev); + + return 0; +} + +static const struct acpi_device_id hisi_mem_acpi_match[] = { + { "HISI0521", 0 }, + { } +}; +MODULE_DEVICE_TABLE(acpi, hisi_mem_acpi_match); + +static struct platform_driver hisi_mem_ras_driver = { + .probe = hisi_mem_ras_probe, + .remove = hisi_mem_ras_remove, + .driver = { + .name = "hisi_mem_ras", + .acpi_match_table = hisi_mem_acpi_match, + }, +}; +module_platform_driver(hisi_mem_ras_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Xiaofei Tan <tanxiaofei@huawei.com>"); +MODULE_DESCRIPTION("HISILICON Memory RAS driver"); +MODULE_ALIAS("platform:" DRV_NAME); diff --git a/drivers/soc/hisilicon/hisi_mem_ras.h b/drivers/soc/hisilicon/hisi_mem_ras.h new file mode 100644 index 000000000000..985d86d40b1d --- /dev/null +++ b/drivers/soc/hisilicon/hisi_mem_ras.h @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) Huawei Technologies Co., Ltd. 2024. All rights reserved. + */ + +#ifndef _HISI_MEM_RAS_H +#define _HISI_MEM_RAS_H + +struct hisi_mem_mbox_client_info { + struct mbox_client client; + struct pcc_mbox_chan *pcc_chan; + u64 deadline_us; + void __iomem *pcc_comm_addr; + struct completion done; +}; + +#define HISI_MEM_CAP_ACLS_EN BIT(0) +#define HISI_MEM_CAP_SPPR_EN BIT(1) +struct hisi_mem_dev { + struct platform_device *pdev; + struct hisi_mem_mbox_client_info cl_info; + struct mutex lock; + u8 chan_id; + u8 mem_type; + u8 ras_cap; +}; + +enum hisi_mem_ras_cmd_type { + HISI_MEM_RAS_CAP = 1, + HISI_MEM_RAS_ACLS = 2, + HISI_MEM_RAS_SPPR = 3, +}; + +enum hisi_mem_ras_subcmd_type { + HISI_MEM_RAS_QUERY = 0, + HISI_MEM_RAS_DO_REPAIR = 1, +}; + +enum hisi_mem_type { + MEMORY_TYPE_HBM = 0, + MEMORY_TYPE_DDR = 1, + MEMORY_TYPE_MAX = 2, +}; + +#define HISI_MEM_PCC_SHARE_MEM_BYTES_MAX 128 +#define HISI_MEM_PCC_SHARE_MEM_BYTES_MIN 64 +#define HISI_MEM_FW_INNER_HEAD_BYTES 4 +#define HISI_MEM_REQ_HEAD_BYTES 4 +#define HISI_MEM_MAX_REQ_DATA_BYTES (HISI_MEM_PCC_SHARE_MEM_BYTES_MAX - \ + HISI_MEM_FW_INNER_HEAD_BYTES - \ + HISI_MEM_REQ_HEAD_BYTES) +#define HISI_MEM_MAX_REQ_DATA_SIZE_MAX (HISI_MEM_MAX_REQ_DATA_BYTES / 4) + +#define HISI_MEM_RSP_HEAD_BYTES 4 +#define HISI_MEM_MAX_RSP_DATA_BYTES (HISI_MEM_PCC_SHARE_MEM_BYTES_MAX - \ + HISI_MEM_FW_INNER_HEAD_BYTES - \ + HISI_MEM_RSP_HEAD_BYTES) +#define HISI_MEM_MAX_RSP_DATA_SIZE_MAX (HISI_MEM_MAX_RSP_DATA_BYTES / 4) + +struct hisi_mem_req_head { + u8 subcmd; + u8 rsv[3]; +}; + +/* + * Note: Actual available size of data field also depends on the PCC header + * bytes of the specific type. Driver needs to copy the request data to the + * communication space based on the real length. + */ +struct hisi_mem_req_desc { + struct hisi_mem_req_head req_head; + u32 data[HISI_MEM_MAX_REQ_DATA_SIZE_MAX]; +}; + +#define HISI_MEM_RAS_OK 0 +#define HISI_MEM_RAS_NO_RES 1 +#define HISI_MEM_RAS_REPAIR_FAIL 2 +#define HISI_MEM_RAS_EINVAL 3 +#define HISI_MEM_RAS_ENXIO 4 +struct hisi_mem_rsp_head { + u8 ret_status; /* 0: success, other: failure */ + u8 mem_type; /* 0: HBM, 1: DDR, other: reserved */ + u8 ras_cap; /* bit0: ACLS, bit1: SPPR, other: reserved */ + u8 rsv; +}; + +/* + * Note: Actual available size of data field also depends on the PCC header + * bytes of the specific type. Driver needs to copy the response data in the + * communication space based on the real length. + */ +struct hisi_mem_rsp_desc { + struct hisi_mem_rsp_head rsp_head; + u32 data[HISI_MEM_MAX_RSP_DATA_SIZE_MAX]; +}; + +struct hisi_mem_fw_inner_head { + u8 cmd_type; + u8 msg_len; + u8 status; + u8 need_resp; +}; + +struct hisi_mem_desc { + struct hisi_mem_fw_inner_head fw_inner_head; /* 4 Bytes */ + union { + struct hisi_mem_req_desc req; + struct hisi_mem_rsp_desc rsp; + }; +}; + +#endif -- 2.33.0 From 6b0611651c352985cd72f1ce87bd421ac9b6503e Mon Sep 17 00:00:00 2001 From: Xiaofei Tan <tanxiaofei@huawei.com> Date: Fri, 25 Oct 2024 15:35:59 +0800 Subject: [PATCH OLK-6.6 3/6] soc: hisilicon: Fix one printing issue and simplify some printing driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10353 ---------------------------------------------------------------------- It's the opposite of what acls_repair_store printing really means. Fix it and add some printing simplification. Fixes: d7e48f100166 ("net: hns3: add dcbnl_setbuffer and dcbnl_getbuffer support for pf") Signed-off-by: Xiaofei Tan <tanxiaofei@huawei.com> (cherry picked from commit fc84bb8655f8ec3d34aa3e4ab9219b13952f4948) Signed-off-by: Haibing Xie <xiehaibing7@h-partners.com> --- drivers/soc/hisilicon/hisi_mem_ras.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/soc/hisilicon/hisi_mem_ras.c b/drivers/soc/hisilicon/hisi_mem_ras.c index 765132cf1c04..991b76e3075d 100644 --- a/drivers/soc/hisilicon/hisi_mem_ras.c +++ b/drivers/soc/hisilicon/hisi_mem_ras.c @@ -229,7 +229,7 @@ static struct page *trans_and_check_paddr(struct device *dev, const char *buf, u page = pfn_to_online_page(__phys_to_pfn(paddr_tmp)); if (!page) { - dev_info(dev, "The page of paddr 0x%llx is not online page.\n", paddr_tmp); + dev_info(dev, "The page of paddr 0x%llx not online.\n", paddr_tmp); return NULL; } @@ -283,7 +283,7 @@ static ssize_t acls_repair_store(struct device *dev, struct device_attribute *at return -EINVAL; if (hdev->mem_type == MEMORY_TYPE_HBM && !PageHWPoison(page)) { - dev_info(dev, "The page of paddr 0x%llx is not unpoisoned.\n", paddr); + dev_info(dev, "The page of paddr 0x%llx not poisoned.\n", paddr); return -EIO; } @@ -350,7 +350,7 @@ static ssize_t sppr_repair_store(struct device *dev, struct device_attribute *at return -EINVAL; if (hdev->mem_type == MEMORY_TYPE_HBM && !PageHWPoison(page)) { - dev_info(dev, "The page of paddr 0x%llx is not poisoned.\n", paddr); + dev_info(dev, "The page of paddr 0x%llx not poisoned.\n", paddr); return -EIO; } -- 2.33.0 From 25029d0bf88192c4020d6d9faaab70cebea0b462 Mon Sep 17 00:00:00 2001 From: Junhao He <hejunhao3@huawei.com> Date: Fri, 7 Mar 2025 11:07:52 +0800 Subject: [PATCH OLK-6.6 4/6] soc: hisilicon: Add checks against NULL pointer reference driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10353 ---------------------------------------------------------------------- The function of ACPI_COMPANION returns a NULL pointer when the device without an fwnode, so add checks for this to fix NULL pointer reference at ACPI_COMPANION. Fixes: d7e48f100166 ("net: hns3: add dcbnl_setbuffer and dcbnl_getbuffer support for pf") Signed-off-by: Junhao He <hejunhao3@huawei.com> (cherry picked from commit a0444df3c65bfeca69293e7f4dcb17535b7318c2) Signed-off-by: Haibing Xie <xiehaibing7@h-partners.com> --- drivers/soc/hisilicon/hisi_mem_ras.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/soc/hisilicon/hisi_mem_ras.c b/drivers/soc/hisilicon/hisi_mem_ras.c index 991b76e3075d..556a6be8afda 100644 --- a/drivers/soc/hisilicon/hisi_mem_ras.c +++ b/drivers/soc/hisilicon/hisi_mem_ras.c @@ -43,16 +43,20 @@ static int hisi_mem_get_pcc_chan_id(struct hisi_mem_dev *hdev) struct platform_device *pdev = hdev->pdev; struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); struct hisi_mem_register_ctx ctx = {0}; - acpi_handle handle = adev->handle; acpi_status status; - if (!acpi_has_method(handle, METHOD_NAME__CRS)) { + if (!adev) { + dev_err(&pdev->dev, "ACPI companion missing\n"); + return -ENODEV; + } + + if (!acpi_has_method(adev->handle, METHOD_NAME__CRS)) { dev_err(&pdev->dev, "No _CRS method.\n"); return -ENODEV; } ctx.dev = &pdev->dev; - status = acpi_walk_resources(handle, METHOD_NAME__CRS, + status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS, hisi_mem_get_chan_id_cb, &ctx); if (ACPI_FAILURE(status)) return ctx.err; -- 2.33.0 From e8bc34da6f754a067e65640cc4a5f20baa1c1c5a Mon Sep 17 00:00:00 2001 From: Yixing Liu <liuyixing1@huawei.com> Date: Mon, 17 Apr 2023 09:48:08 +0800 Subject: [PATCH OLK-6.6 5/6] RDMA/hns: Add SVE DIRECT WQE flag to support libhns driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10353 --------------------------------------------------------------- Added SVE DWQE flag to control libhns SVE DWQE function. Fixes: 9a4435375cd1 ("IB/hns: Add driver files for hns RoCE driver") Signed-off-by: Yixing Liu <liuyixing1@huawei.com> Reviewed-by: Yangyang Li <liyangyang20@huawei.com> Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com> (cherry picked from commit 7c36903d6425c10f31797840ce9142728955f270) Signed-off-by: Haibing Xie <xiehaibing7@h-partners.com> --- drivers/infiniband/hw/hns/hns_roce_device.h | 1 + drivers/infiniband/hw/hns/hns_roce_qp.c | 3 +++ include/uapi/rdma/hns-abi.h | 1 + 3 files changed, 5 insertions(+) diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniband/hw/hns/hns_roce_device.h index 3fb91b1c026e..5131a3fe1f1f 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -169,6 +169,7 @@ enum { HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL = BIT(9), HNS_ROCE_CAP_FLAG_ATOMIC = BIT(10), HNS_ROCE_CAP_FLAG_DIRECT_WQE = BIT(12), + HNS_ROCE_CAP_FLAG_SVE_DIRECT_WQE = BIT(13), HNS_ROCE_CAP_FLAG_SDI_MODE = BIT(14), HNS_ROCE_CAP_FLAG_DCA_MODE = BIT(15), HNS_ROCE_CAP_FLAG_STASH = BIT(17), diff --git a/drivers/infiniband/hw/hns/hns_roce_qp.c b/drivers/infiniband/hw/hns/hns_roce_qp.c index 5dc90da214f0..bd6c7f77f268 100644 --- a/drivers/infiniband/hw/hns/hns_roce_qp.c +++ b/drivers/infiniband/hw/hns/hns_roce_qp.c @@ -854,6 +854,9 @@ static int alloc_wqe_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp, */ if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_DIRECT_WQE) hr_qp->en_flags |= HNS_ROCE_QP_CAP_DIRECT_WQE; + + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SVE_DIRECT_WQE) + hr_qp->en_flags |= HNS_ROCE_QP_CAP_SVE_DIRECT_WQE; } hr_qp->mtr = hns_roce_mtr_create(hr_dev, buf_attr, diff --git a/include/uapi/rdma/hns-abi.h b/include/uapi/rdma/hns-abi.h index 8a8f2e4f1bea..ac87ccc01c44 100644 --- a/include/uapi/rdma/hns-abi.h +++ b/include/uapi/rdma/hns-abi.h @@ -102,6 +102,7 @@ enum hns_roce_qp_cap_flags { HNS_ROCE_QP_CAP_RQ_RECORD_DB = 1 << 0, HNS_ROCE_QP_CAP_SQ_RECORD_DB = 1 << 1, HNS_ROCE_QP_CAP_OWNER_DB = 1 << 2, + HNS_ROCE_QP_CAP_SVE_DIRECT_WQE = 1 << 3, HNS_ROCE_QP_CAP_DYNAMIC_CTX_ATTACH = 1 << 4, HNS_ROCE_QP_CAP_DIRECT_WQE = 1 << 5, HNS_ROCE_QP_CAP_DYNAMIC_CTX_DETACH = 1 << 6, -- 2.33.0 From f0a4e6f187375a4cc31850877a4bdb268c9683b9 Mon Sep 17 00:00:00 2001 From: kangfenglong <kangfenglong@huawei.com> Date: Thu, 16 Apr 2026 20:30:37 +0800 Subject: [PATCH OLK-6.6 6/6] pciehp: Clear LBMS on hot-remove to prevent link speed reduction driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/10353 ---------------------------------------------------------------------- During hot-remove, PDSC may arrive after DLLSC, causing a delayed presence detect to be misinterpreted as a slot-on event. If LBMS is set from before the removal, the kernel attempts link retrain at 2.5GT/s, reducing link speed even though no device is present. Note: Newer kernel versions contain more extensive rework for this issue. Use a minimal fix here to clear LBMS on hot-remove, keeping changes conservative and suitable for stable backports without large-scale code modification. Fixes: d7e48f100166 ("net: hns3: add dcbnl_setbuffer and dcbnl_getbuffer support for pf") Signed-off-by: kangfenglong <kangfenglong@huawei.com> (cherry picked from commit b4bb8cbc97240023fcf1cdbde9dc93560b726db1) Signed-off-by: Haibing Xie <xiehaibing7@h-partners.com> --- drivers/pci/hotplug/pciehp_ctrl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c index 702b64395510..7276960a985d 100644 --- a/drivers/pci/hotplug/pciehp_ctrl.c +++ b/drivers/pci/hotplug/pciehp_ctrl.c @@ -130,6 +130,9 @@ static void remove_board(struct controller *ctrl, bool safe_removal) pciehp_set_indicators(ctrl, PCI_EXP_SLTCTL_PWR_IND_OFF, INDICATOR_NOOP); + + /* Don't carry LBMS indications across */ + pcie_capability_write_word(ctrl->pcie->port, PCI_EXP_LNKSTA, PCI_EXP_LNKSTA_LBMS); } static int pciehp_enable_slot(struct controller *ctrl); -- 2.33.0 .