Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2265091imm; Mon, 28 May 2018 05:03:52 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLSL3B2togA8XvXuEI5FGdpvTpPCAW6ZfUErGoGb8UjX/gz2t7PzLTYJW90wvZbDyWiq9TO X-Received: by 2002:a62:6710:: with SMTP id b16-v6mr1408476pfc.37.1527509031958; Mon, 28 May 2018 05:03:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527509031; cv=none; d=google.com; s=arc-20160816; b=cdEB2G5QlSlXEDZGepZaCb34FDxcWW27iYV3RorOiyxx5IGYV7CVzZvIbEEUgmlfYG igfS/rABBKrw64sCwTINnfKNXpsQHpffgpGaVwsgG/w42IT+WCXbKWM7P9ojyq7ZjkVl xBWryNKyoNK/kr9h6JBo51X2GOwemoGeQbX5M5jYhMjuPB9S1U3l2npAZZDBIFZkTWgw QFvKrj4CtD4bM0VrC3N0+Tg0x7kH/Cmdku7qqlSmGFQROILA5oo7Ki/t9q8Ve36wPgak 6rySyyxYRe25MvoMAzvzl88afZ1NEFC5l3slCa1Ujy6SmaUdnqBqGhLwh/7BhEPJCg5u mFpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=UIWmwS4hsxoRoXj0QXC6LngeCV1ACTXWD2Idu2iKh+E=; b=coYJ4xWgjXDWQm6AYIv9oa18o0CizBbCvA1VX5kx+lEHIiaP0gyMSja7e/ftGiVVse v4arevS0pxWqFQ6Spj6HBWg9Y4aFkOwANSMOTG2hmeAN6AWxc/Wa4ZNR5hO0fY6QhsMk 2a1KXmDNmUmlDLADYUuOyQCoE74Gu+E8Licij2z7C2ZQ53TIbWETfw5K64Yp73p8+0m+ mZ4NI8fchy7ZZblzrViISRtwLr2xmIN+GOPTPPJ97orU7NK1HKnrfff+bp0VBT+2mFiw PcQ+okPTi0w5semYgc0ghtYqYDtms525V2k/B1ldV8XFYHsDW9S6tOjQxwi2bd2aPIv8 LEng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k134-v6si1943623pga.149.2018.05.28.05.03.36; Mon, 28 May 2018 05:03:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938545AbeE1MCj (ORCPT + 99 others); Mon, 28 May 2018 08:02:39 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:33486 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1423002AbeE1LGo (ORCPT ); Mon, 28 May 2018 07:06:44 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 8DA7F9923444E; Mon, 28 May 2018 19:06:39 +0800 (CST) Received: from [127.0.0.1] (10.57.115.182) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.382.0; Mon, 28 May 2018 19:06:35 +0800 Subject: Re: [PATCH V3 rdma-next 3/4] RDMA/uverbs: Hoist the common process of disassociate_ucontext into ib core To: Leon Romanovsky References: <1527324107-56593-1-git-send-email-xavier.huwei@huawei.com> <1527324107-56593-4-git-send-email-xavier.huwei@huawei.com> <20180527150500.GA3085@mtr-leonro.mtl.com> CC: , , , , , , From: "Wei Hu (Xavier)" Message-ID: <5B0BE2BB.8000101@huawei.com> Date: Mon, 28 May 2018 19:06:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <20180527150500.GA3085@mtr-leonro.mtl.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.57.115.182] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/5/27 23:05, Leon Romanovsky wrote: > On Sat, May 26, 2018 at 04:41:46PM +0800, Wei Hu (Xavier) wrote: >> This patch hoisted the common process of disassociate_ucontext >> callback function into ib core code, and these code are common >> to ervery ib_device driver. >> >> Signed-off-by: Wei Hu (Xavier) >> --- >> drivers/infiniband/core/uverbs_main.c | 45 ++++++++++++++++++++++++++++++++++- >> drivers/infiniband/hw/mlx4/main.c | 34 -------------------------- >> drivers/infiniband/hw/mlx5/main.c | 34 -------------------------- >> 3 files changed, 44 insertions(+), 69 deletions(-) >> >> diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c >> index 4445d8e..a0a1c70 100644 >> --- a/drivers/infiniband/core/uverbs_main.c >> +++ b/drivers/infiniband/core/uverbs_main.c >> @@ -41,6 +41,8 @@ >> #include >> #include >> #include >> +#include >> +#include >> #include >> #include >> #include >> @@ -1090,6 +1092,47 @@ static void ib_uverbs_add_one(struct ib_device *device) >> return; >> } >> >> +static void ib_uverbs_disassociate_ucontext(struct ib_ucontext *ibcontext) >> +{ >> + struct ib_device *ib_dev = ibcontext->device; >> + struct task_struct *owning_process = NULL; >> + struct mm_struct *owning_mm = NULL; >> + >> + owning_process = get_pid_task(ibcontext->tgid, PIDTYPE_PID); >> + if (!owning_process) >> + return; >> + >> + owning_mm = get_task_mm(owning_process); >> + if (!owning_mm) { >> + pr_info("no mm, disassociate ucontext is pending task termination\n"); >> + while (1) { >> + put_task_struct(owning_process); >> + usleep_range(1000, 2000); >> + owning_process = get_pid_task(ibcontext->tgid, >> + PIDTYPE_PID); >> + if (!owning_process || >> + owning_process->state == TASK_DEAD) { >> + pr_info("disassociate ucontext done, task was terminated\n"); >> + /* in case task was dead need to release the >> + * task struct. >> + */ >> + if (owning_process) >> + put_task_struct(owning_process); >> + return; >> + } >> + } >> + } >> + >> + /* need to protect from a race on closing the vma as part of >> + * mlx5_ib_vma_close. > Except this "mlx5_ib_vma_close" > > Acked-by: Leon Romanovsky Hi, Leon Thanks, We will fix it in V4. Regards Wei Hu >> + */ >> + down_write(&owning_mm->mmap_sem); >> + ib_dev->disassociate_ucontext(ibcontext); >> + up_write(&owning_mm->mmap_sem); >> + mmput(owning_mm); >> + put_task_struct(owning_process); >> +} >> + >> static void ib_uverbs_free_hw_resources(struct ib_uverbs_device *uverbs_dev, >> struct ib_device *ib_dev) >> { >> @@ -1130,7 +1173,7 @@ static void ib_uverbs_free_hw_resources(struct ib_uverbs_device *uverbs_dev, >> * (e.g mmput). >> */ >> ib_uverbs_event_handler(&file->event_handler, &event); >> - ib_dev->disassociate_ucontext(ucontext); >> + ib_uverbs_disassociate_ucontext(ucontext); >> mutex_lock(&file->cleanup_mutex); >> ib_uverbs_cleanup_ucontext(file, ucontext, true); >> mutex_unlock(&file->cleanup_mutex); >> diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c >> index bf12394..59aed45 100644 >> --- a/drivers/infiniband/hw/mlx4/main.c >> +++ b/drivers/infiniband/hw/mlx4/main.c >> @@ -1189,40 +1189,10 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) >> int ret = 0; >> struct vm_area_struct *vma; >> struct mlx4_ib_ucontext *context = to_mucontext(ibcontext); >> - struct task_struct *owning_process = NULL; >> - struct mm_struct *owning_mm = NULL; >> - >> - owning_process = get_pid_task(ibcontext->tgid, PIDTYPE_PID); >> - if (!owning_process) >> - return; >> - >> - owning_mm = get_task_mm(owning_process); >> - if (!owning_mm) { >> - pr_info("no mm, disassociate ucontext is pending task termination\n"); >> - while (1) { >> - /* make sure that task is dead before returning, it may >> - * prevent a rare case of module down in parallel to a >> - * call to mlx4_ib_vma_close. >> - */ >> - put_task_struct(owning_process); >> - usleep_range(1000, 2000); >> - owning_process = get_pid_task(ibcontext->tgid, >> - PIDTYPE_PID); >> - if (!owning_process || >> - owning_process->state == TASK_DEAD) { >> - pr_info("disassociate ucontext done, task was terminated\n"); >> - /* in case task was dead need to release the task struct */ >> - if (owning_process) >> - put_task_struct(owning_process); >> - return; >> - } >> - } >> - } >> >> /* need to protect from a race on closing the vma as part of >> * mlx4_ib_vma_close(). >> */ >> - down_write(&owning_mm->mmap_sem); >> for (i = 0; i < HW_BAR_COUNT; i++) { >> vma = context->hw_bar_info[i].vma; >> if (!vma) >> @@ -1241,10 +1211,6 @@ static void mlx4_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) >> /* context going to be destroyed, should not access ops any more */ >> context->hw_bar_info[i].vma->vm_ops = NULL; >> } >> - >> - up_write(&owning_mm->mmap_sem); >> - mmput(owning_mm); >> - put_task_struct(owning_process); >> } >> >> static void mlx4_ib_set_vma_data(struct vm_area_struct *vma, >> diff --git a/drivers/infiniband/hw/mlx5/main.c b/drivers/infiniband/hw/mlx5/main.c >> index f3e7d7c..136d64f 100644 >> --- a/drivers/infiniband/hw/mlx5/main.c >> +++ b/drivers/infiniband/hw/mlx5/main.c >> @@ -1965,38 +1965,7 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) >> struct vm_area_struct *vma; >> struct mlx5_ib_vma_private_data *vma_private, *n; >> struct mlx5_ib_ucontext *context = to_mucontext(ibcontext); >> - struct task_struct *owning_process = NULL; >> - struct mm_struct *owning_mm = NULL; >> >> - owning_process = get_pid_task(ibcontext->tgid, PIDTYPE_PID); >> - if (!owning_process) >> - return; >> - >> - owning_mm = get_task_mm(owning_process); >> - if (!owning_mm) { >> - pr_info("no mm, disassociate ucontext is pending task termination\n"); >> - while (1) { >> - put_task_struct(owning_process); >> - usleep_range(1000, 2000); >> - owning_process = get_pid_task(ibcontext->tgid, >> - PIDTYPE_PID); >> - if (!owning_process || >> - owning_process->state == TASK_DEAD) { >> - pr_info("disassociate ucontext done, task was terminated\n"); >> - /* in case task was dead need to release the >> - * task struct. >> - */ >> - if (owning_process) >> - put_task_struct(owning_process); >> - return; >> - } >> - } >> - } >> - >> - /* need to protect from a race on closing the vma as part of >> - * mlx5_ib_vma_close. >> - */ >> - down_write(&owning_mm->mmap_sem); >> mutex_lock(&context->vma_private_list_mutex); >> list_for_each_entry_safe(vma_private, n, &context->vma_private_list, >> list) { >> @@ -2013,9 +1982,6 @@ static void mlx5_ib_disassociate_ucontext(struct ib_ucontext *ibcontext) >> kfree(vma_private); >> } >> mutex_unlock(&context->vma_private_list_mutex); >> - up_write(&owning_mm->mmap_sem); >> - mmput(owning_mm); >> - put_task_struct(owning_process); >> } >> >> static inline char *mmap_cmd2str(enum mlx5_ib_mmap_cmd cmd) >> -- >> 1.9.1 >>