From nobody Mon Sep 16 19:49:02 2024 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F6EA1741C3; Fri, 26 Jul 2024 07:24:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978687; cv=none; b=VfzmGuV29VlVzKRz9M1TYgm/ULqlEVQDU2pgj3YV5RNt/wUdVUPXW+0cI2lu7GRKAxk4oWMjFAx7luD05oQWhlS9TNXdqgq3a1qqbtF90nJHtdGxDBS16yLoYhkRyQpPwE16eRa5Ba6Mv9tZKtG3NKX9lLnEYMDBi9x5pQwrPkc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978687; c=relaxed/simple; bh=Tsw5OhV4f4IyQdap6kmuzvQ8xK9TFRXPDuKndjHnCjY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Alt+QWaUToYVAloPZdTzLWKvjx8rvGFt+rP2nHGJLQLbcryiENNrCkm++rBeQ9ZWOYHTIWGIXqsWDmMeP6KQz5VCxjcKC5UhgK8WEmJx63twCY9KjwAJPyYgYDHYeYBHAG69ZeWRD7IwyLWu4h9rgzCtyScIS581F7OH0edb98g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com; spf=pass smtp.mailfrom=hisilicon.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hisilicon.com Received: from mail.maildlp.com (unknown [172.19.163.48]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4WVfPY4vZHzncbr; Fri, 26 Jul 2024 15:23:45 +0800 (CST) Received: from kwepemf100018.china.huawei.com (unknown [7.202.181.17]) by mail.maildlp.com (Postfix) with ESMTPS id 4BB6718009E; Fri, 26 Jul 2024 15:24:37 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemf100018.china.huawei.com (7.202.181.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 26 Jul 2024 15:24:36 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-next 1/3] RDMA/core: Provide rdma_user_mmap_disassociate() to disassociate mmap pages Date: Fri, 26 Jul 2024 15:19:08 +0800 Message-ID: <20240726071910.626802-2-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240726071910.626802-1-huangjunxian6@hisilicon.com> References: <20240726071910.626802-1-huangjunxian6@hisilicon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemf100018.china.huawei.com (7.202.181.17) Content-Type: text/plain; charset="utf-8" From: Chengchang Tang Provide a new api rdma_user_mmap_disassociate() for drivers to disassociate mmap pages for ucontext. This api relies on uverbs_user_mmap_disassociate() in ib_uverbs, causing ib_core relying on ib_uverbs. To avoid this, move uverbs_user_mmap_disassociate() to ib_core_uverbs.c. Signed-off-by: Chengchang Tang Signed-off-by: Junxian Huang --- drivers/infiniband/core/ib_core_uverbs.c | 85 ++++++++++++++++++++++++ drivers/infiniband/core/rdma_core.h | 1 - drivers/infiniband/core/uverbs_main.c | 64 ------------------ include/rdma/ib_verbs.h | 3 + 4 files changed, 88 insertions(+), 65 deletions(-) diff --git a/drivers/infiniband/core/ib_core_uverbs.c b/drivers/infiniband/= core/ib_core_uverbs.c index b51bd7087a88..4e27389a75ad 100644 --- a/drivers/infiniband/core/ib_core_uverbs.c +++ b/drivers/infiniband/core/ib_core_uverbs.c @@ -5,6 +5,7 @@ * Copyright 2019 Marvell. All rights reserved. */ #include +#include #include "uverbs.h" #include "core_priv.h" =20 @@ -365,3 +366,87 @@ int rdma_user_mmap_entry_insert(struct ib_ucontext *uc= ontext, U32_MAX); } EXPORT_SYMBOL(rdma_user_mmap_entry_insert); + +void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile) +{ + struct rdma_umap_priv *priv, *next_priv; + + lockdep_assert_held(&ufile->hw_destroy_rwsem); + + while (1) { + struct mm_struct *mm =3D NULL; + + /* Get an arbitrary mm pointer that hasn't been cleaned yet */ + mutex_lock(&ufile->umap_lock); + while (!list_empty(&ufile->umaps)) { + int ret; + + priv =3D list_first_entry(&ufile->umaps, + struct rdma_umap_priv, list); + mm =3D priv->vma->vm_mm; + ret =3D mmget_not_zero(mm); + if (!ret) { + list_del_init(&priv->list); + if (priv->entry) { + rdma_user_mmap_entry_put(priv->entry); + priv->entry =3D NULL; + } + mm =3D NULL; + continue; + } + break; + } + mutex_unlock(&ufile->umap_lock); + if (!mm) + return; + + /* + * The umap_lock is nested under mmap_lock since it used within + * the vma_ops callbacks, so we have to clean the list one mm + * at a time to get the lock ordering right. Typically there + * will only be one mm, so no big deal. + */ + mmap_read_lock(mm); + mutex_lock(&ufile->umap_lock); + list_for_each_entry_safe(priv, next_priv, &ufile->umaps, list) { + struct vm_area_struct *vma =3D priv->vma; + + if (vma->vm_mm !=3D mm) + continue; + list_del_init(&priv->list); + + zap_vma_ptes(vma, vma->vm_start, + vma->vm_end - vma->vm_start); + + if (priv->entry) { + rdma_user_mmap_entry_put(priv->entry); + priv->entry =3D NULL; + } + } + mutex_unlock(&ufile->umap_lock); + mmap_read_unlock(mm); + mmput(mm); + } +} +EXPORT_SYMBOL(uverbs_user_mmap_disassociate); + +/** + * rdma_user_mmap_disassociate() - disassociate the mmap from the ucontext. + * + * @ucontext: associated user context. + * + * This function should be called by drivers that need to disable mmap for + * some ucontexts. + */ +void rdma_user_mmap_disassociate(struct ib_ucontext *ucontext) +{ + struct ib_uverbs_file *ufile =3D ucontext->ufile; + + /* Racing with uverbs_destroy_ufile_hw */ + if (!down_read_trylock(&ufile->hw_destroy_rwsem)) + return; + + uverbs_user_mmap_disassociate(ufile); + up_read(&ufile->hw_destroy_rwsem); +} +EXPORT_SYMBOL(rdma_user_mmap_disassociate); diff --git a/drivers/infiniband/core/rdma_core.h b/drivers/infiniband/core/= rdma_core.h index 33706dad6c0f..ad01fbd52c48 100644 --- a/drivers/infiniband/core/rdma_core.h +++ b/drivers/infiniband/core/rdma_core.h @@ -149,7 +149,6 @@ void uverbs_disassociate_api(struct uverbs_api *uapi); void uverbs_destroy_api(struct uverbs_api *uapi); void uapi_compute_bundle_size(struct uverbs_api_ioctl_method *method_elm, unsigned int num_attrs); -void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile); =20 extern const struct uapi_definition uverbs_def_obj_async_fd[]; extern const struct uapi_definition uverbs_def_obj_counters[]; diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/cor= e/uverbs_main.c index bc099287de9a..e7cacbc3fe03 100644 --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -45,7 +45,6 @@ #include #include #include -#include =20 #include =20 @@ -817,69 +816,6 @@ static const struct vm_operations_struct rdma_umap_ops= =3D { .fault =3D rdma_umap_fault, }; =20 -void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile) -{ - struct rdma_umap_priv *priv, *next_priv; - - lockdep_assert_held(&ufile->hw_destroy_rwsem); - - while (1) { - struct mm_struct *mm =3D NULL; - - /* Get an arbitrary mm pointer that hasn't been cleaned yet */ - mutex_lock(&ufile->umap_lock); - while (!list_empty(&ufile->umaps)) { - int ret; - - priv =3D list_first_entry(&ufile->umaps, - struct rdma_umap_priv, list); - mm =3D priv->vma->vm_mm; - ret =3D mmget_not_zero(mm); - if (!ret) { - list_del_init(&priv->list); - if (priv->entry) { - rdma_user_mmap_entry_put(priv->entry); - priv->entry =3D NULL; - } - mm =3D NULL; - continue; - } - break; - } - mutex_unlock(&ufile->umap_lock); - if (!mm) - return; - - /* - * The umap_lock is nested under mmap_lock since it used within - * the vma_ops callbacks, so we have to clean the list one mm - * at a time to get the lock ordering right. Typically there - * will only be one mm, so no big deal. - */ - mmap_read_lock(mm); - mutex_lock(&ufile->umap_lock); - list_for_each_entry_safe (priv, next_priv, &ufile->umaps, - list) { - struct vm_area_struct *vma =3D priv->vma; - - if (vma->vm_mm !=3D mm) - continue; - list_del_init(&priv->list); - - zap_vma_ptes(vma, vma->vm_start, - vma->vm_end - vma->vm_start); - - if (priv->entry) { - rdma_user_mmap_entry_put(priv->entry); - priv->entry =3D NULL; - } - } - mutex_unlock(&ufile->umap_lock); - mmap_read_unlock(mm); - mmput(mm); - } -} - /* * ib_uverbs_open() does not need the BKL: * diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 6c5712ae559d..4175e3588b77 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -2947,6 +2947,7 @@ int rdma_user_mmap_entry_insert_range(struct ib_ucont= ext *ucontext, struct rdma_user_mmap_entry *entry, size_t length, u32 min_pgoff, u32 max_pgoff); +void rdma_user_mmap_disassociate(struct ib_ucontext *ucontext); =20 static inline int rdma_user_mmap_entry_insert_exact(struct ib_ucontext *ucontext, @@ -4729,6 +4730,8 @@ struct ib_ucontext *ib_uverbs_get_ucontext_file(struc= t ib_uverbs_file *ufile); =20 int uverbs_destroy_def_handler(struct uverbs_attr_bundle *attrs); =20 +void uverbs_user_mmap_disassociate(struct ib_uverbs_file *ufile); + struct net_device *rdma_alloc_netdev(struct ib_device *device, u32 port_nu= m, enum rdma_netdev_t type, const char *name, unsigned char name_assign_type, --=20 2.33.0 From nobody Mon Sep 16 19:49:02 2024 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2375D3C30; Fri, 26 Jul 2024 07:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721979784; cv=none; b=ASIygHKRe41SRmjNIijQCdbMG3jSDjJ4/c7M8iujVb0ohff5oc2aKDgxjeKsD3qjQnzkIyGoG3iasKclpr70inbEUSzBddj2w/BqvchdqwXIJxO4DlSM+qPGKiPvwxcdGz+oJhkblYfBP33EEE7BFzZAG3OykG/MVXp4Lsa1Nmo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721979784; c=relaxed/simple; bh=JQmFk8P1wPUArmo8G9Bh19XTV93zp5zIYy4AuLYz+4M=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fkJUXM5jYzLZjWpZzVhkVugztan1PZuTGTQuSXHdKPxIFqymbhsY90IENyXfQlfQmIEcmCHDF+CPHK5CCCMlVUVw5aksa91sqsK3DnxaMwFFzUWwtVM58bEDuyRSr/CYdLL3CCY4dbMAj/ueeD3uuE2UYx7IBBX6Cg31OScKa4o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com; spf=pass smtp.mailfrom=hisilicon.com; arc=none smtp.client-ip=45.249.212.35 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hisilicon.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4WVfKP6rdLz1S6pN; Fri, 26 Jul 2024 15:20:09 +0800 (CST) Received: from kwepemf100018.china.huawei.com (unknown [7.202.181.17]) by mail.maildlp.com (Postfix) with ESMTPS id 9A3251400CB; Fri, 26 Jul 2024 15:24:37 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemf100018.china.huawei.com (7.202.181.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 26 Jul 2024 15:24:37 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-next 2/3] RDMA/hns: Link all uctx to uctx_list on a device Date: Fri, 26 Jul 2024 15:19:09 +0800 Message-ID: <20240726071910.626802-3-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240726071910.626802-1-huangjunxian6@hisilicon.com> References: <20240726071910.626802-1-huangjunxian6@hisilicon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemf100018.china.huawei.com (7.202.181.17) Content-Type: text/plain; charset="utf-8" From: Chengchang Tang Link all uctx to uctx_list on a device. Signed-off-by: Chengchang Tang Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_device.h | 4 ++++ drivers/infiniband/hw/hns/hns_roce_main.c | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/drivers/infiniband/hw/hns/hns_roce_device.h b/drivers/infiniba= nd/hw/hns/hns_roce_device.h index 0b1e21cb6d2d..93768660569d 100644 --- a/drivers/infiniband/hw/hns/hns_roce_device.h +++ b/drivers/infiniband/hw/hns/hns_roce_device.h @@ -217,6 +217,7 @@ struct hns_roce_ucontext { struct mutex page_mutex; struct hns_user_mmap_entry *db_mmap_entry; u32 config; + struct list_head list; /* link all uctx to uctx_list on hr_dev */ }; =20 struct hns_roce_pd { @@ -1030,6 +1031,9 @@ struct hns_roce_dev { u64 dwqe_page; struct hns_roce_dev_debugfs dbgfs; atomic64_t *dfx_cnt; + + struct list_head uctx_list; /* list of all uctx on this dev */ + struct mutex uctx_list_mutex; /* protect @uctx_list */ }; =20 static inline struct hns_roce_dev *to_hr_dev(struct ib_device *ib_dev) diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband= /hw/hns/hns_roce_main.c index 4cb0af733587..e19871ebc315 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -426,6 +426,10 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext = *uctx, if (ret) goto error_fail_copy_to_udata; =20 + mutex_lock(&hr_dev->uctx_list_mutex); + list_add(&context->list, &hr_dev->uctx_list); + mutex_unlock(&hr_dev->uctx_list_mutex); + return 0; =20 error_fail_copy_to_udata: @@ -448,6 +452,10 @@ static void hns_roce_dealloc_ucontext(struct ib_uconte= xt *ibcontext) struct hns_roce_ucontext *context =3D to_hr_ucontext(ibcontext); struct hns_roce_dev *hr_dev =3D to_hr_dev(ibcontext->device); =20 + mutex_lock(&hr_dev->uctx_list_mutex); + list_del(&context->list); + mutex_unlock(&hr_dev->uctx_list_mutex); + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB || hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) mutex_destroy(&context->page_mutex); @@ -943,6 +951,7 @@ static int hns_roce_init_hem(struct hns_roce_dev *hr_de= v) static void hns_roce_teardown_hca(struct hns_roce_dev *hr_dev) { hns_roce_cleanup_bitmap(hr_dev); + mutex_destroy(&hr_dev->uctx_list_mutex); =20 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB || hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) @@ -961,6 +970,9 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_d= ev) =20 spin_lock_init(&hr_dev->sm_lock); =20 + INIT_LIST_HEAD(&hr_dev->uctx_list); + mutex_init(&hr_dev->uctx_list_mutex); + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB || hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) { INIT_LIST_HEAD(&hr_dev->pgdir_list); @@ -1000,6 +1012,7 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr= _dev) if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_CQ_RECORD_DB || hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) mutex_destroy(&hr_dev->pgdir_mutex); + mutex_destroy(&hr_dev->uctx_list_mutex); =20 return ret; } --=20 2.33.0 From nobody Mon Sep 16 19:49:02 2024 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB6924C99; Fri, 26 Jul 2024 07:24:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978687; cv=none; b=NyZZLFBAxjO5daq4xY1OxIieLa0pTUDbq/3raP2YAptfPCgsOyx/imPszWG8kEH3x4mrTBg7QoaAnKdly+T+cKOeNxEwUE6uquXwxTi5iD1eHo9wydvf4GkPynKjfivbEUocQpTMOPiXOFQZaHTz4rc4F/YJS1bY1QT3umaqhgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721978687; c=relaxed/simple; bh=PgRiU32PY0W2Dv+x0G52ngm/RaogqAHhWNJI+HQYb4s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Cr/tpkYnKN4LFHz2Kg6SSX5lBJCHuw703oR2OLciQZjKx+3NWKJ9j+3eARnTRQf+jWVn25gO1bOjIGRHMqXL1K9eY3Asb0d9t3Pg/T4g6Jp0pUMsy2ZFljVXzmD6iON0DCZPkFCzxhLDi3F/Hzp6+R9Xtyip4JSUjpMajF5BV6c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com; spf=pass smtp.mailfrom=hisilicon.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=hisilicon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hisilicon.com Received: from mail.maildlp.com (unknown [172.19.163.44]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4WVfMQ4jnmz1HFbQ; Fri, 26 Jul 2024 15:21:54 +0800 (CST) Received: from kwepemf100018.china.huawei.com (unknown [7.202.181.17]) by mail.maildlp.com (Postfix) with ESMTPS id E18431402C6; Fri, 26 Jul 2024 15:24:37 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by kwepemf100018.china.huawei.com (7.202.181.17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 26 Jul 2024 15:24:37 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-next 3/3] RDMA/hns: Disassociate mmap pages for all uctx when HW is being reset Date: Fri, 26 Jul 2024 15:19:10 +0800 Message-ID: <20240726071910.626802-4-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240726071910.626802-1-huangjunxian6@hisilicon.com> References: <20240726071910.626802-1-huangjunxian6@hisilicon.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemf100018.china.huawei.com (7.202.181.17) Content-Type: text/plain; charset="utf-8" From: Chengchang Tang When HW is being reset, userspace should not ring doorbell otherwise it may lead to abnormal consequence such as RAS. Disassociate mmap pages for all uctx to prevent userspace from ringing doorbell to HW. Fixes: 9a4435375cd1 ("IB/hns: Add driver files for hns RoCE driver") Signed-off-by: Chengchang Tang Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniban= d/hw/hns/hns_roce_hw_v2.c index 621b057fb9da..8adf8430212d 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -7012,6 +7012,18 @@ static void hns_roce_hw_v2_uninit_instance(struct hn= ae3_handle *handle, =20 handle->rinfo.instance_state =3D HNS_ROCE_STATE_NON_INIT; } + +static void hns_roce_v2_reset_notify_user(struct hns_roce_dev *hr_dev) +{ + struct hns_roce_ucontext *uctx, *tmp; + + mutex_lock(&hr_dev->uctx_list_mutex); + list_for_each_entry_safe(uctx, tmp, &hr_dev->uctx_list, list) { + rdma_user_mmap_disassociate(&uctx->ibucontext); + } + mutex_unlock(&hr_dev->uctx_list_mutex); +} + static int hns_roce_hw_v2_reset_notify_down(struct hnae3_handle *handle) { struct hns_roce_dev *hr_dev; @@ -7030,6 +7042,9 @@ static int hns_roce_hw_v2_reset_notify_down(struct hn= ae3_handle *handle) =20 hr_dev->active =3D false; hr_dev->dis_db =3D true; + + hns_roce_v2_reset_notify_user(hr_dev); + hr_dev->state =3D HNS_ROCE_DEVICE_STATE_RST_DOWN; =20 return 0; --=20 2.33.0