From patchwork Wed Jan 23 22:23:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10778015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE1301399 for ; Wed, 23 Jan 2019 22:23:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE43F2C4F8 for ; Wed, 23 Jan 2019 22:23:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A26532C4FF; Wed, 23 Jan 2019 22:23:59 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 090B92C4F8 for ; Wed, 23 Jan 2019 22:23:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D94638E0057; Wed, 23 Jan 2019 17:23:56 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C54758E0047; Wed, 23 Jan 2019 17:23:56 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B1BC38E0057; Wed, 23 Jan 2019 17:23:56 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 792758E0047 for ; Wed, 23 Jan 2019 17:23:56 -0500 (EST) Received: by mail-qt1-f199.google.com with SMTP id p24so4368941qtl.2 for ; Wed, 23 Jan 2019 14:23:56 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5ej6STBe/ObX0owf3bf30yvaziyxsISS35lOCKy3kXM=; b=KapB+W64wGTaaHgpdVgZtDJdTHZ/9asO3SME5kr869t1qt7PbYXqy6rWm373EgP0m7 kt3KckJ8lB5QNhMrraZIu1GBjs81e/tlgr21rCTPxkfVYMyrmRtZ6k2y6IJEyhUNoTQ+ YX8JQEaWLCCjCpRf9+GY21NXA4IIoOeAnjrUkm7Du8ckwSeZ39ta/qCKQ/nga/m1P8Ds bON7HvHFppjUwTF+FKDcvJDwg12/q+zNF9DX9Y4Yb00qDfkc2NqB6qDYXNEjwOq+jIKN DrYtkxTiCrgK4TVGIBb9s/Z5gIuRB0/5x6aZ/xT1bTkkiIirm7yuKdkOsSzuLNy92bqj UuWw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: AJcUukfe6RCDH/MypI69wjVKDsiN2uhzsEQxnX0DFfa+sgb2T5Vc8ymn PLC5jwuSrJYFa7RYPAxEndry1H4LgBELCLt3gH+y/k+9acIFMpYBFZLINujmP03yO7jG/KrKtaN wfvUSC6c67tLDvWa98inWSb/Hq/kfHNUV1Iq4/V3a7g/1D25KyPfsezh3Ukb7quHAVw== X-Received: by 2002:ac8:2211:: with SMTP id o17mr4446899qto.170.1548282236279; Wed, 23 Jan 2019 14:23:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN7SXfjG09j3PKcYYIGQy80cLksEH1ryt/Ce07wCvHKHepleMhsr8q+9mZBfnI/qDY1g1KvG X-Received: by 2002:ac8:2211:: with SMTP id o17mr4446878qto.170.1548282235824; Wed, 23 Jan 2019 14:23:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548282235; cv=none; d=google.com; s=arc-20160816; b=nSbG97p060HAw6cUmQuxbA4gI39/+E21W9BdfDrrlPc722GD+KNKnnsqgcEC4YgOS6 W6Q/2hVwQ380FOX8UbY3RXKCJc5gx3ljxOYY+e0yeiCYuv8Z4ZG7wApeXP3maj/3kWmT ErbcZjHHFvWSyE2sxGnifQ8ZudizP3lXJ349tzf/yhGmXNIxgWcL36GkLyWC9nrJ7gMq 5UqfrcE7vAEECaLdQkAC1JYfQi3MTXLKv/pTK5A0u+iBLAi6ciuBLbgC4shKUzzJJMnP zdJx3IhgfTBSvd8sGCCJSd5NQ6194lj09UXoINOiBKQrtLIFYWyohu5MiYshJPjYUbSn ja/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=5ej6STBe/ObX0owf3bf30yvaziyxsISS35lOCKy3kXM=; b=VCSclwf+J7IXrt+tJJQ1fPRBGbSDuk4zq7C7uynDR5s5FGrtIPxlMKhMxO4K4SVYFm BflYcfzA60Vr3SKXcKQaIR6YG9zZL0hXflk8kVkf4DommmT0N3vMfXiFETsgASAMupcu h9bdCvkVdj1GCGI/1u0W/eT3sJMKgDLbqG5htYlVYVimoaEubUbq639fU+iVmNVyNohF Rr5Roobmtx0+9mCzMIbvxpkpkqnOZYaWxm8Vesq70/gKPy1A3IG3EsD5S9CsUgd5uesM ytX1YutDO0Y5LZAjNUs2TlaJiaq5qu4u+AqodTEb46aAnbD4Sq8bfGNaaSaPdyqHGHrE UyDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id c4si3776096qtj.64.2019.01.23.14.23.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Jan 2019 14:23:55 -0800 (PST) Received-SPF: pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jglisse@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jglisse@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D387F432A0; Wed, 23 Jan 2019 22:23:54 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-127.rdu2.redhat.com [10.10.120.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3606D6A685; Wed, 23 Jan 2019 22:23:52 +0000 (UTC) From: jglisse@redhat.com To: linux-mm@kvack.org Cc: Andrew Morton , linux-kernel@vger.kernel.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , =?utf-8?q?Christian_?= =?utf-8?q?K=C3=B6nig?= , Jan Kara , Felix Kuehling , Jason Gunthorpe , Matthew Wilcox , Ross Zwisler , Dan Williams , Paolo Bonzini , =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= , Michal Hocko , Ralph Campbell , John Hubbard , kvm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-rdma@vger.kernel.org, linux-fsdevel@vger.kernel.org, Arnd Bergmann Subject: [PATCH v4 9/9] RDMA/umem_odp: optimize out the case when a range is updated to read only Date: Wed, 23 Jan 2019 17:23:15 -0500 Message-Id: <20190123222315.1122-10-jglisse@redhat.com> In-Reply-To: <20190123222315.1122-1-jglisse@redhat.com> References: <20190123222315.1122-1-jglisse@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 23 Jan 2019 22:23:55 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Jérôme Glisse When range of virtual address is updated read only and corresponding user ptr object are already read only it is pointless to do anything. Optimize this case out. Signed-off-by: Jérôme Glisse Cc: Christian König Cc: Jan Kara Cc: Felix Kuehling Cc: Jason Gunthorpe Cc: Andrew Morton Cc: Matthew Wilcox Cc: Ross Zwisler Cc: Dan Williams Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Michal Hocko Cc: Ralph Campbell Cc: John Hubbard Cc: kvm@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: linux-rdma@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: Arnd Bergmann --- drivers/infiniband/core/umem_odp.c | 22 +++++++++++++++++++--- include/rdma/ib_umem_odp.h | 1 + 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/core/umem_odp.c b/drivers/infiniband/core/umem_odp.c index a4ec43093cb3..fa4e7fdcabfc 100644 --- a/drivers/infiniband/core/umem_odp.c +++ b/drivers/infiniband/core/umem_odp.c @@ -140,8 +140,15 @@ static void ib_umem_notifier_release(struct mmu_notifier *mn, static int invalidate_range_start_trampoline(struct ib_umem_odp *item, u64 start, u64 end, void *cookie) { + bool update_to_read_only = *((bool *)cookie); + ib_umem_notifier_start_account(item); - item->umem.context->invalidate_range(item, start, end); + /* + * If it is already read only and we are updating to read only then we + * do not need to change anything. So save time and skip this one. + */ + if (!update_to_read_only || !item->read_only) + item->umem.context->invalidate_range(item, start, end); return 0; } @@ -150,6 +157,7 @@ static int ib_umem_notifier_invalidate_range_start(struct mmu_notifier *mn, { struct ib_ucontext_per_mm *per_mm = container_of(mn, struct ib_ucontext_per_mm, mn); + bool update_to_read_only; if (range->blockable) down_read(&per_mm->umem_rwsem); @@ -166,10 +174,13 @@ static int ib_umem_notifier_invalidate_range_start(struct mmu_notifier *mn, return 0; } + update_to_read_only = mmu_notifier_range_update_to_read_only(range); + return rbt_ib_umem_for_each_in_range(&per_mm->umem_tree, range->start, range->end, invalidate_range_start_trampoline, - range->blockable, NULL); + range->blockable, + &update_to_read_only); } static int invalidate_range_end_trampoline(struct ib_umem_odp *item, u64 start, @@ -363,6 +374,9 @@ struct ib_umem_odp *ib_alloc_odp_umem(struct ib_ucontext_per_mm *per_mm, goto out_odp_data; } + /* Assume read only at first, each time GUP is call this is updated. */ + odp_data->read_only = true; + odp_data->dma_list = vzalloc(array_size(pages, sizeof(*odp_data->dma_list))); if (!odp_data->dma_list) { @@ -619,8 +633,10 @@ int ib_umem_odp_map_dma_pages(struct ib_umem_odp *umem_odp, u64 user_virt, goto out_put_task; } - if (access_mask & ODP_WRITE_ALLOWED_BIT) + if (access_mask & ODP_WRITE_ALLOWED_BIT) { + umem_odp->read_only = false; flags |= FOLL_WRITE; + } start_idx = (user_virt - ib_umem_start(umem)) >> page_shift; k = start_idx; diff --git a/include/rdma/ib_umem_odp.h b/include/rdma/ib_umem_odp.h index 0b1446fe2fab..8256668c6170 100644 --- a/include/rdma/ib_umem_odp.h +++ b/include/rdma/ib_umem_odp.h @@ -76,6 +76,7 @@ struct ib_umem_odp { struct completion notifier_completion; int dying; struct work_struct work; + bool read_only; }; static inline struct ib_umem_odp *to_ib_umem_odp(struct ib_umem *umem)