From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6EB4C43331 for ; Tue, 24 Mar 2020 01:15:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7F5882070A for ; Tue, 24 Mar 2020 01:15:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Nj1g0jZS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7F5882070A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 900DB6B0078; Mon, 23 Mar 2020 21:15:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B17E6B007D; Mon, 23 Mar 2020 21:15:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72CFF6B007E; Mon, 23 Mar 2020 21:15:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id 581426B007D for ; Mon, 23 Mar 2020 21:15:14 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2FEB3BD3D8 for ; Tue, 24 Mar 2020 01:15:14 +0000 (UTC) X-FDA: 76628487348.25.land65_4ac713871115f X-HE-Tag: land65_4ac713871115f X-Filterd-Recvd-Size: 10074 Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by imf38.hostedemail.com (Postfix) with ESMTP for ; Tue, 24 Mar 2020 01:15:13 +0000 (UTC) Received: by mail-qv1-f68.google.com with SMTP id cy12so8409784qvb.7 for ; Mon, 23 Mar 2020 18:15:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FMKo6LdkFYCdsPHJF0fYulYQYBiJ803wxyfJC3f+mbw=; b=Nj1g0jZSQ0AczJrww7hWZY8r8tpap5CLTIvsn2yaRNNdxslEPOg+842Vn6LrtGd1tg HtjjeNAsCQRHtcZtHJpW4DXurPnEed+4T4vGiYe3PnvJn4L94pHllJ37TuOIUV401H5D 94+36Td+rsulGU9kB7n1AAPV9NeNloGJsjC3xcK0nD7e6Y7t/TP6ON81j2BxPu1HyFcn EuaU5WtR5iSqz1oi81pzB0K/Iol09/AusYChyigO43dlEyf9VGWdYvMdcOvoznq37TSm ntW3K0awqVSSmHN4B+Ru6FQks+LZvBmMAGtITUgvEeLCQyOaQD9tzUdnK65nwuY5YgUu Qs3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FMKo6LdkFYCdsPHJF0fYulYQYBiJ803wxyfJC3f+mbw=; b=bZ85j0O03A2XghR+tehWw9lpqhL/Hkbtv5IF4PS0eOJDmOcRJsG/gW8TtaZO01Qenv 18aRnV7uLJLTeGuHuJLAqrQP63eTBiAgUlxANYaSNsV0BTHMQ5/1bC3UvSY9VzPgElJy VpHRDTLtJJcG8P4cZ8PZRhqw1d1F8vFwL0kUgmhf9smZzip1iG7QIHcfAewu5yjUOLuT z3r007AsljNsBGjXHunOC7Wy3rijx77v41Jjf9gY6XoafAtObXar0fS541hr2B9tJYYu yTNFLr0smAMOkkZ1udKhZmhShX05Xwf77qRdrVLGjAKd9AUMl4NkO11GLPvVGpEjCQH5 wKKw== X-Gm-Message-State: ANhLgQ0CONVubfo0LghMe7m9621fq2CvVjSyxWgL/WuZBRm6JrcAz4gs /YhgACkh36RJfDp9c2RlFAa4fw== X-Google-Smtp-Source: ADFU+vs1SPcubDDYu/nEfYMoed2J0S2bdq7cYi/3vm2e/mEXWMX5+97u67uWczDe8pro/1SWHnVy6A== X-Received: by 2002:ad4:4a89:: with SMTP id h9mr23410432qvx.168.1585012513012; Mon, 23 Mar 2020 18:15:13 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id n4sm12902832qti.55.2020.03.23.18.15.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Mar 2020 18:15:10 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jGY9u-0000r6-72; Mon, 23 Mar 2020 22:15:10 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Cc: linux-mm@kvack.org, John Hubbard , dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, Christoph Hellwig , Philip Yang , Jason Gunthorpe Subject: [PATCH v2 hmm 4/9] mm/hmm: remove HMM_FAULT_SNAPSHOT Date: Mon, 23 Mar 2020 22:14:52 -0300 Message-Id: <20200324011457.2817-5-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.2 In-Reply-To: <20200324011457.2817-1-jgg@ziepe.ca> References: <20200324011457.2817-1-jgg@ziepe.ca> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: From: Jason Gunthorpe Now that flags are handled on a fine-grained per-page basis this global flag is redundant and has a confusing overlap with the pfn_flags_mask and default_flags. Normalize the HMM_FAULT_SNAPSHOT behavior into one place. Callers needing the SNAPSHOT behavior should set a pfn_flags_mask and default_flags that always results in a cleared HMM_PFN_VALID. Then no pages will be faulted, and HMM_FAULT_SNAPSHOT is not a special flow that overrides the masking mechanism. As this is the last flag, also remove the flags argument. If future flags are needed they can be part of the struct hmm_range function arguments. Signed-off-by: Jason Gunthorpe --- Documentation/vm/hmm.rst | 12 +++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +- include/linux/hmm.h | 5 +---- mm/hmm.c | 22 ++++++++++++++-------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/Documentation/vm/hmm.rst b/Documentation/vm/hmm.rst index 95fec596836262..4e3e9362afeb10 100644 --- a/Documentation/vm/hmm.rst +++ b/Documentation/vm/hmm.rst @@ -161,13 +161,11 @@ device must complete the update before the driver c= allback returns. When the device driver wants to populate a range of virtual addresses, i= t can use:: =20 - long hmm_range_fault(struct hmm_range *range, unsigned int flags); + long hmm_range_fault(struct hmm_range *range); =20 -With the HMM_RANGE_SNAPSHOT flag, it will only fetch present CPU page ta= ble -entries and will not trigger a page fault on missing or non-present entr= ies. -Without that flag, it does trigger a page fault on missing or read-only = entries -if write access is requested (see below). Page faults use the generic mm= page -fault code path just like a CPU page fault. +It will trigger a page fault on missing or read-only entries if write ac= cess is +requested (see below). Page faults use the generic mm page fault code pa= th just +like a CPU page fault. =20 Both functions copy CPU page table entries into their pfns array argumen= t. Each entry in that array corresponds to an address in the virtual range. HMM @@ -197,7 +195,7 @@ The usage pattern is:: again: range.notifier_seq =3D mmu_interval_read_begin(&interval_sub); down_read(&mm->mmap_sem); - ret =3D hmm_range_fault(&range, HMM_RANGE_SNAPSHOT); + ret =3D hmm_range_fault(&range); if (ret) { up_read(&mm->mmap_sem); if (ret =3D=3D -EBUSY) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/am= d/amdgpu/amdgpu_ttm.c index 90821ce5e6cad0..c520290709371b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -856,7 +856,7 @@ int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo= , struct page **pages) range->notifier_seq =3D mmu_interval_read_begin(&bo->notifier); =20 down_read(&mm->mmap_sem); - r =3D hmm_range_fault(range, 0); + r =3D hmm_range_fault(range); up_read(&mm->mmap_sem); if (unlikely(r <=3D 0)) { /* diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouv= eau/nouveau_svm.c index 39c731a99937c6..e3797b2d4d1759 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -540,7 +540,7 @@ static int nouveau_range_fault(struct nouveau_svmm *s= vmm, range.default_flags =3D 0; range.pfn_flags_mask =3D -1UL; down_read(&mm->mmap_sem); - ret =3D hmm_range_fault(&range, 0); + ret =3D hmm_range_fault(&range); up_read(&mm->mmap_sem); if (ret <=3D 0) { if (ret =3D=3D 0 || ret =3D=3D -EBUSY) diff --git a/include/linux/hmm.h b/include/linux/hmm.h index daee6508a3f609..7475051100c782 100644 --- a/include/linux/hmm.h +++ b/include/linux/hmm.h @@ -117,13 +117,10 @@ static inline struct page *hmm_device_entry_to_page= (const struct hmm_range *rang return pfn_to_page(entry >> range->pfn_shift); } =20 -/* Don't fault in missing PTEs, just snapshot the current state. */ -#define HMM_FAULT_SNAPSHOT (1 << 1) - /* * Please see Documentation/vm/hmm.rst for how to use the range API. */ -long hmm_range_fault(struct hmm_range *range, unsigned int flags); +long hmm_range_fault(struct hmm_range *range); =20 /* * HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a r= ange diff --git a/mm/hmm.c b/mm/hmm.c index c298c936469bbb..43d107a4d9dec6 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -29,7 +29,6 @@ struct hmm_vma_walk { struct hmm_range *range; unsigned long last; - unsigned int flags; }; =20 enum { @@ -112,9 +111,6 @@ static unsigned int hmm_pte_need_fault(const struct h= mm_vma_walk *hmm_vma_walk, { struct hmm_range *range =3D hmm_vma_walk->range; =20 - if (hmm_vma_walk->flags & HMM_FAULT_SNAPSHOT) - return 0; - /* * So we not only consider the individual per page request we also * consider the default flags requested for the range. The API can @@ -142,15 +138,27 @@ static unsigned int hmm_pte_need_fault(const struct= hmm_vma_walk *hmm_vma_walk, return 0; } =20 +/* + * If the valid flag is masked off, and default_flags doesn't set valid,= then + * hmm_pte_need_fault() always returns 0. + */ +static bool hmm_can_fault(struct hmm_range *range) +{ + return ((range->flags[HMM_PFN_VALID] & range->pfn_flags_mask) | + range->default_flags) & + range->flags[HMM_PFN_VALID]; +} + static unsigned int hmm_range_need_fault(const struct hmm_vma_walk *hmm_vma_walk, const uint64_t *pfns, unsigned long npages, uint64_t cpu_flags) { + struct hmm_range *range =3D hmm_vma_walk->range; unsigned int required_fault =3D 0; unsigned long i; =20 - if (hmm_vma_walk->flags & HMM_FAULT_SNAPSHOT) + if (!hmm_can_fault(range)) return 0; =20 for (i =3D 0; i < npages; ++i) { @@ -557,7 +565,6 @@ static const struct mm_walk_ops hmm_walk_ops =3D { /** * hmm_range_fault - try to fault some address in a virtual address rang= e * @range: argument structure - * @flags: HMM_FAULT_* flags * * Return: the number of valid pages in range->pfns[] (from range start * address), which may be zero. On error one of the following status co= des @@ -579,12 +586,11 @@ static const struct mm_walk_ops hmm_walk_ops =3D { * On error, for one virtual address in the range, the function will mar= k the * corresponding HMM pfn entry with an error flag. */ -long hmm_range_fault(struct hmm_range *range, unsigned int flags) +long hmm_range_fault(struct hmm_range *range) { struct hmm_vma_walk hmm_vma_walk =3D { .range =3D range, .last =3D range->start, - .flags =3D flags, }; struct mm_struct *mm =3D range->notifier->mm; int ret; --=20 2.25.2