From patchwork Thu May 17 08:02:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wei Hu (Xavier)" X-Patchwork-Id: 10405729 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 54143602C2 for ; Thu, 17 May 2018 07:31:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DE5B28877 for ; Thu, 17 May 2018 07:31:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 273802887E; Thu, 17 May 2018 07:31:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8E9328877 for ; Thu, 17 May 2018 07:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751543AbeEQHaA (ORCPT ); Thu, 17 May 2018 03:30:00 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:55094 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750924AbeEQH37 (ORCPT ); Thu, 17 May 2018 03:29:59 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 32E8A3DE03B6D; Thu, 17 May 2018 15:29:54 +0800 (CST) Received: from linux-ioko.site (10.71.200.31) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.382.0; Thu, 17 May 2018 15:29:50 +0800 From: "Wei Hu (Xavier)" To: , CC: , , , Subject: [PATCH rdma-next 1/5] RDMA/hns: Implement the disassociate_ucontext API Date: Thu, 17 May 2018 16:02:49 +0800 Message-ID: <1526544173-106587-2-git-send-email-xavier.huwei@huawei.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1526544173-106587-1-git-send-email-xavier.huwei@huawei.com> References: <1526544173-106587-1-git-send-email-xavier.huwei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.71.200.31] X-CFilter-Loop: Reflected Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch Implements the IB core disassociate_ucontext API. Signed-off-by: Wei Hu (Xavier) --- drivers/infiniband/hw/hns/hns_roce_main.c | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/drivers/infiniband/hw/hns/hns_roce_main.c b/drivers/infiniband/hw/hns/hns_roce_main.c index 96fb6a9..7fafe9d 100644 --- a/drivers/infiniband/hw/hns/hns_roce_main.c +++ b/drivers/infiniband/hw/hns/hns_roce_main.c @@ -33,6 +33,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -422,6 +425,38 @@ static int hns_roce_port_immutable(struct ib_device *ib_dev, u8 port_num, return 0; } +static void hns_roce_disassociate_ucontext(struct ib_ucontext *ibcontext) +{ + struct task_struct *process; + struct mm_struct *mm; + + process = get_pid_task(ibcontext->tgid, PIDTYPE_PID); + if (!process) + return; + + mm = get_task_mm(process); + if (!mm) { + pr_info("no mm, disassociate ucontext is pending task termination\n"); + while (1) { + put_task_struct(process); + usleep_range(1000, 2000); + process = get_pid_task(ibcontext->tgid, PIDTYPE_PID); + if (!process || process->state == TASK_DEAD) { + pr_info("disassociate ucontext done, task was terminated\n"); + /* if task was dead, need to release the task + * struct. + */ + if (process) + put_task_struct(process); + return; + } + } + } + + mmput(mm); + put_task_struct(process); +} + static void hns_roce_unregister_device(struct hns_roce_dev *hr_dev) { struct hns_roce_ib_iboe *iboe = &hr_dev->iboe; @@ -516,6 +551,7 @@ static int hns_roce_register_device(struct hns_roce_dev *hr_dev) /* OTHERS */ ib_dev->get_port_immutable = hns_roce_port_immutable; + ib_dev->disassociate_ucontext = hns_roce_disassociate_ucontext; ib_dev->driver_id = RDMA_DRIVER_HNS; ret = ib_register_device(ib_dev, NULL);