Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1314941imu; Wed, 23 Jan 2019 14:47:12 -0800 (PST) X-Google-Smtp-Source: ALg8bN7gFHNQd9snh6JajaL/MqzvnGkULRouq6iE0AzKefm4PgD5WpJ8QbFqcErcSHXCHJGW6CkJ X-Received: by 2002:a17:902:714c:: with SMTP id u12mr4094462plm.234.1548283632034; Wed, 23 Jan 2019 14:47:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548283632; cv=none; d=google.com; s=arc-20160816; b=wPWUemURhMy9MC1aAy/93hg1h6yoxX2jekgjsOhWJQo+JjRWYz7PtjXPL92O3lw/vg iGGFovcD9jdtudmYtzRQu1PeR+9jVI+1Z/qpsjB6X0Oqtc0b5T0AHy9DT7+Wsz5hC+jC 4BD8hls56IB+zMspZVhtRnxavludky6+Wg8Gb/1/RkNAszmNlvahqBt0c5MNtovPC1zj BrlJvqWhsBcpqZZJf+0mjRasSR8cNWXi1I7JeefvOVu+3ar8SxpTGuqeodk87Pbz4HuC oEnJRQ2MiiakTvGItYCtRqAJDH18Wh+C0HtbkVsAUCBt+NaXEV32fzqb+7yRBHufrRoc tqbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=NnoSMwQKdzvQpDWCpDivUoKT6WdjzMB1BJiTpthNpKM=; b=uXldPybVMZJ/1XHY/h7L37eEtjv8IEzAWvOIIpOvNVzu90khdxS8yr1AmpdD2QbQuZ mcqJidY+5+3co2cJAVyL3CUXREKxFzmn4pU5cd2gcTAWmSv7ZbbHVvkFmQFUk4yN+RTh kQBiL5b1rE9nMmPjd7jG/StuHjNa3zrhP1Jh/BQVJcgIBnha2SmaaW1AVR5QOxmJTbi+ lkqnC9U+ZHfs2s/5EbE6YAkxhlxUwOYaPe0staD9bLZjjYIHoO0WXgN52KiRC2L/3LcB 0DTKAXCV/jo4oWvAnBuPekCnFwgV82E20X93vI+v+2cmMa6dBpc0b5BmYLg1uaEqDoPz It0w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cd2si21457106plb.39.2019.01.23.14.46.56; Wed, 23 Jan 2019 14:47:12 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727009AbfAWWqr (ORCPT + 99 others); Wed, 23 Jan 2019 17:46:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:40332 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726109AbfAWWqr (ORCPT ); Wed, 23 Jan 2019 17:46:47 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB823C0C6C15; Wed, 23 Jan 2019 22:46:45 +0000 (UTC) Received: from redhat.com (ovpn-120-127.rdu2.redhat.com [10.10.120.127]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AFD076B8FC; Wed, 23 Jan 2019 22:46:42 +0000 (UTC) Date: Wed, 23 Jan 2019 17:46:40 -0500 From: Jerome Glisse To: Jason Gunthorpe Cc: "linux-mm@kvack.org" , Andrew Morton , "linux-kernel@vger.kernel.org" , Christian =?iso-8859-1?Q?K=F6nig?= , Jan Kara , Felix Kuehling , Matthew Wilcox , Ross Zwisler , Dan Williams , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , 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: Re: [PATCH v4 9/9] RDMA/umem_odp: optimize out the case when a range is updated to read only Message-ID: <20190123224640.GA1257@redhat.com> References: <20190123222315.1122-1-jglisse@redhat.com> <20190123222315.1122-10-jglisse@redhat.com> <20190123223153.GP8986@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190123223153.GP8986@mellanox.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 23 Jan 2019 22:46:46 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 23, 2019 at 10:32:00PM +0000, Jason Gunthorpe wrote: > On Wed, Jan 23, 2019 at 05:23:15PM -0500, jglisse@redhat.com wrote: > > 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 > > +++ 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; > > No locking? The mmu notitfier exclusion will ensure that it is not missed ie it will be false before any mmu notifier might be call on page GUPed with write flag which is what matter here. So lock are useless here. > > > 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 > > +++ 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; > > }; > > The ib_umem already has a writeable flag. This reflects if the user > asked for write permission to be granted.. The tracking here is if any > remote fault thus far has requested write, is this an important > difference to justify the new flag? I did that patch couple week ago and now i do not remember why i did not use that, i remember thinking about it ... damm i need to keep better notes. I will review the code again. Cheers, Jérôme