From patchwork Wed Apr 22 00:21:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11502571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B45A313B2 for ; Wed, 22 Apr 2020 00:21:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 558C120706 for ; Wed, 22 Apr 2020 00:21:50 +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="QqRL1zP8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 558C120706 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 55E9B8E0005; Tue, 21 Apr 2020 20:21:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 50FCA8E0003; Tue, 21 Apr 2020 20:21:49 -0400 (EDT) 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 3FFCB8E0005; Tue, 21 Apr 2020 20:21:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0139.hostedemail.com [216.40.44.139]) by kanga.kvack.org (Postfix) with ESMTP id 266278E0003 for ; Tue, 21 Apr 2020 20:21:49 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id DB73B180AD820 for ; Wed, 22 Apr 2020 00:21:48 +0000 (UTC) X-FDA: 76733587896.11.grape82_8435b2855513a X-Spam-Summary: 10,1,0,9f9992cba2e9cf5e,d41d8cd98f00b204,jgg@ziepe.ca,,RULES_HIT:1:2:41:69:355:379:800:960:968:973:988:989:1260:1311:1314:1321:1345:1437:1515:1605:1730:1747:1777:1792:1801:2393:2559:2562:2898:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:4051:4250:4321:4605:5007:6117:6119:6120:6261:6653:6742:7576:7875:7901:7903:8603:9036:9040:9592:10004:11026:11232:11473:11657:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13161:13229:13894:13972:14096:14394:21080:21325:21444:21451:21627:21990:30003:30012:30034:30051:30054:30056:30070:30080,0,RBL:209.85.160.196:@ziepe.ca:.lbl8.mailshell.net-66.201.201.201 62.14.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: grape82_8435b2855513a X-Filterd-Recvd-Size: 11605 Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Wed, 22 Apr 2020 00:21:48 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id o10so328851qtr.6 for ; Tue, 21 Apr 2020 17:21:48 -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:mime-version :content-transfer-encoding; bh=DOrXrBA8QTub/2t4P8iuXJjEm4ygMvU/FqA4XiW8uMI=; b=QqRL1zP89wuwpYO4tjdu5tQyhiJKZz+123CtN7/lSOHBgi0BEsWgVLQtWqFkF0Hxyv i3YnSB79YQLqZfUqs5VQ7ORnBAyiLhFYAln1p5Tnm/66Ok8O2embqN8L6iR1Sj0Ort0y NiL7//AOzryih+UFlmGnfx6bobjRIrul/aI3C+e5/SiAT+H7LGnV5wHUTpPuLEv055M1 uMHLaK7/BuqPaleUtPgV4/1Ef1uoO3rlJPwt0B/OnMxSwsCx6SyQqweIoXubAzBYVdiU hAM6PcjZ4PVCa1LC7dZTxqVcSv+QUxA3OnGMRz1ddHlWleWeR0SrIXcEJ0Gh53ILWxgL YmMQ== 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:mime-version :content-transfer-encoding; bh=DOrXrBA8QTub/2t4P8iuXJjEm4ygMvU/FqA4XiW8uMI=; b=oV/KMqwCYifM4jYUtj4HKbGARYESH+QGw9lhXgzPmArRcGqFJkez3BPJFvC9I1bIp1 mswrW1iAUS1UaPta/IyZjvVxEjjXV1sPYSep3wA14uARSEG/E7OH8mKLiXndkoFN6okM PBSK6CeGQdTbQItY1AooQyHcfLbyBEOJr7Hfr5Y6uiPcfJUc6M/zcFsYpTt5Je1JHoWk rohymEsuxWONa55KbXWlPbCnRp3yd+LbPanLN36SNJBzXC0T5ArL78mjo+HWMJPHxl65 i0h7PIE8sMY3cU0QzovI8fKQG40tnnO9KiWjAr70kKRIbmiVV4XolmoDapIJ4vkquMO4 fqIQ== X-Gm-Message-State: AGi0Pua0MyAAhBT+kgZ7n2gwB8wQiljCZ5GBbG9fuJX/NtgDLOkp0S4j GxuxL8nWUF6EHOiWnOl7wlscWPzThyi9+Q== X-Google-Smtp-Source: APiQypI+VXdJnBmgFU/RD6dwwKcyUmh89IKsfPkwPYI8eruL612VHTCsM8nTWqECUcuFa61w7n1eEg== X-Received: by 2002:ac8:31e1:: with SMTP id i30mr23775526qte.74.1587514907550; Tue, 21 Apr 2020 17:21:47 -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 u190sm2815110qkb.102.2020.04.21.17.21.46 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Apr 2020 17:21:46 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jR398-0000As-9O; Tue, 21 Apr 2020 21:21:46 -0300 From: Jason Gunthorpe To: linux-mm@kvack.org, Ralph Campbell Cc: Alex Deucher , amd-gfx@lists.freedesktop.org, Ben Skeggs , =?utf-8?q?Christian_K=C3=B6nig?= , "David (ChunMing) Zhou" , dri-devel@lists.freedesktop.org, "Kuehling, Felix" , Christoph Hellwig , intel-gfx@lists.freedesktop.org, =?utf-8?b?SsOpcsO0bWUgR2xpc3Nl?= , John Hubbard , linux-kernel@vger.kernel.org, Niranjana Vishwanathapura , nouveau@lists.freedesktop.org Subject: [PATCH hmm 0/5] Adjust hmm_range_fault() API Date: Tue, 21 Apr 2020 21:21:41 -0300 Message-Id: <0-v1-4eb72686de3c+5062-hmm_no_flags_jgg@mellanox.com> MIME-Version: 1.0 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 The API is a bit complicated for the uses we actually have, and disucssions for simplifying have come up a number of times. This small series removes the customizable pfn format and simplifies the return code of hmm_range_fault() All the drivers are adjusted to process in the simplified format. I would appreciated tested-by's for the two drivers, thanks! This passes the hmm tester with the following diff: Jason Gunthorpe (5): mm/hmm: make CONFIG_DEVICE_PRIVATE into a select mm/hmm: make hmm_range_fault return 0 or -1 drm/amdgpu: remove dead code after hmm_range_fault() mm/hmm: remove HMM_PFN_SPECIAL mm/hmm: remove the customizable pfn format from hmm_range_fault Documentation/vm/hmm.rst | 28 ++-- arch/powerpc/Kconfig | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 56 +++---- drivers/gpu/drm/nouveau/Kconfig | 2 +- drivers/gpu/drm/nouveau/nouveau_dmem.c | 60 ++++++-- drivers/gpu/drm/nouveau/nouveau_dmem.h | 4 +- drivers/gpu/drm/nouveau/nouveau_svm.c | 59 ++++---- include/linux/hmm.h | 109 +++++--------- mm/Kconfig | 7 +- mm/hmm.c | 185 +++++++++++------------- 10 files changed, 229 insertions(+), 283 deletions(-) Tested-by: Ralph Campbell diff --git a/lib/test_hmm.c b/lib/test_hmm.c index d75e18f2ffd245..a2442efa038c41 100644 --- a/lib/test_hmm.c +++ b/lib/test_hmm.c @@ -47,23 +47,8 @@ struct dmirror_bounce { unsigned long cpages; }; -#define DPT_SHIFT PAGE_SHIFT -#define DPT_VALID (1UL << 0) -#define DPT_WRITE (1UL << 1) - #define DPT_XA_TAG_WRITE 3UL -static const uint64_t dmirror_hmm_flags[HMM_PFN_FLAG_MAX] = { - [HMM_PFN_VALID] = DPT_VALID, - [HMM_PFN_WRITE] = DPT_WRITE, -}; - -static const uint64_t dmirror_hmm_values[HMM_PFN_VALUE_MAX] = { - [HMM_PFN_NONE] = 0, - [HMM_PFN_ERROR] = 0x10, - [HMM_PFN_SPECIAL] = 0x10, -}; - /* * Data structure to track address ranges and register for mmu interval * notifier updates. @@ -175,7 +160,7 @@ static inline struct dmirror_device *dmirror_page_to_device(struct page *page) static int dmirror_do_fault(struct dmirror *dmirror, struct hmm_range *range) { - uint64_t *pfns = range->pfns; + unsigned long *pfns = range->hmm_pfns; unsigned long pfn; for (pfn = (range->start >> PAGE_SHIFT); @@ -188,15 +173,16 @@ static int dmirror_do_fault(struct dmirror *dmirror, struct hmm_range *range) * Since we asked for hmm_range_fault() to populate pages, * it shouldn't return an error entry on success. */ - WARN_ON(*pfns == range->values[HMM_PFN_ERROR]); + WARN_ON(*pfns & HMM_PFN_ERROR); + WARN_ON(!(*pfns & HMM_PFN_VALID)); - page = hmm_device_entry_to_page(range, *pfns); + page = hmm_pfn_to_page(*pfns); WARN_ON(!page); entry = page; - if (*pfns & range->flags[HMM_PFN_WRITE]) + if (*pfns & HMM_PFN_WRITE) entry = xa_tag_pointer(entry, DPT_XA_TAG_WRITE); - else if (range->default_flags & range->flags[HMM_PFN_WRITE]) + else if (WARN_ON(range->default_flags & HMM_PFN_WRITE)) return -EFAULT; entry = xa_store(&dmirror->pt, pfn, entry, GFP_ATOMIC); if (xa_is_err(entry)) @@ -260,8 +246,6 @@ static int dmirror_range_fault(struct dmirror *dmirror, int ret; while (true) { - long count; - if (time_after(jiffies, timeout)) { ret = -EBUSY; goto out; @@ -269,12 +253,11 @@ static int dmirror_range_fault(struct dmirror *dmirror, range->notifier_seq = mmu_interval_read_begin(range->notifier); down_read(&mm->mmap_sem); - count = hmm_range_fault(range); + ret = hmm_range_fault(range); up_read(&mm->mmap_sem); - if (count <= 0) { - if (count == 0 || count == -EBUSY) + if (ret) { + if (ret == -EBUSY) continue; - ret = count; goto out; } @@ -299,16 +282,13 @@ static int dmirror_fault(struct dmirror *dmirror, unsigned long start, { struct mm_struct *mm = dmirror->notifier.mm; unsigned long addr; - uint64_t pfns[64]; + unsigned long pfns[64]; struct hmm_range range = { .notifier = &dmirror->notifier, - .pfns = pfns, - .flags = dmirror_hmm_flags, - .values = dmirror_hmm_values, - .pfn_shift = DPT_SHIFT, + .hmm_pfns = pfns, .pfn_flags_mask = 0, - .default_flags = dmirror_hmm_flags[HMM_PFN_VALID] | - (write ? dmirror_hmm_flags[HMM_PFN_WRITE] : 0), + .default_flags = + HMM_PFN_REQ_FAULT | (write ? HMM_PFN_REQ_WRITE : 0), .dev_private_owner = dmirror->mdevice, }; int ret = 0; @@ -754,19 +734,20 @@ static int dmirror_migrate(struct dmirror *dmirror, } static void dmirror_mkentry(struct dmirror *dmirror, struct hmm_range *range, - unsigned char *perm, uint64_t entry) + unsigned char *perm, unsigned long entry) { struct page *page; - if (entry == range->values[HMM_PFN_ERROR]) { + if (entry & HMM_PFN_ERROR) { *perm = HMM_DMIRROR_PROT_ERROR; return; } - page = hmm_device_entry_to_page(range, entry); - if (!page) { + if (!(entry & HMM_PFN_VALID)) { *perm = HMM_DMIRROR_PROT_NONE; return; } + + page = hmm_pfn_to_page(entry); if (is_device_private_page(page)) { /* Is the page migrated to this device or some other? */ if (dmirror->mdevice == dmirror_page_to_device(page)) @@ -777,7 +758,7 @@ static void dmirror_mkentry(struct dmirror *dmirror, struct hmm_range *range, *perm = HMM_DMIRROR_PROT_ZERO; else *perm = HMM_DMIRROR_PROT_NONE; - if (entry & range->flags[HMM_PFN_WRITE]) + if (entry & HMM_PFN_WRITE) *perm |= HMM_DMIRROR_PROT_WRITE; else *perm |= HMM_DMIRROR_PROT_READ; @@ -832,8 +813,6 @@ static int dmirror_range_snapshot(struct dmirror *dmirror, return ret; while (true) { - long count; - if (time_after(jiffies, timeout)) { ret = -EBUSY; goto out; @@ -842,12 +821,11 @@ static int dmirror_range_snapshot(struct dmirror *dmirror, range->notifier_seq = mmu_interval_read_begin(range->notifier); down_read(&mm->mmap_sem); - count = hmm_range_fault(range); + ret = hmm_range_fault(range); up_read(&mm->mmap_sem); - if (count <= 0) { - if (count == 0 || count == -EBUSY) + if (ret) { + if (ret == -EBUSY) continue; - ret = count; goto out; } @@ -862,7 +840,7 @@ static int dmirror_range_snapshot(struct dmirror *dmirror, n = (range->end - range->start) >> PAGE_SHIFT; for (i = 0; i < n; i++) - dmirror_mkentry(dmirror, range, perm + i, range->pfns[i]); + dmirror_mkentry(dmirror, range, perm + i, range->hmm_pfns[i]); mutex_unlock(&dmirror->mutex); out: @@ -878,15 +856,11 @@ static int dmirror_snapshot(struct dmirror *dmirror, unsigned long size = cmd->npages << PAGE_SHIFT; unsigned long addr; unsigned long next; - uint64_t pfns[64]; + unsigned long pfns[64]; unsigned char perm[64]; char __user *uptr; struct hmm_range range = { - .pfns = pfns, - .flags = dmirror_hmm_flags, - .values = dmirror_hmm_values, - .pfn_shift = DPT_SHIFT, - .pfn_flags_mask = 0, + .hmm_pfns = pfns, .dev_private_owner = dmirror->mdevice, }; int ret = 0; @@ -1097,6 +1071,7 @@ static int dmirror_device_init(struct dmirror_device *mdevice, int id) spin_lock_init(&mdevice->lock); cdev_init(&mdevice->cdevice, &dmirror_fops); + mdevice->cdevice.owner = THIS_MODULE; ret = cdev_add(&mdevice->cdevice, dev, 1); if (ret) return ret; diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 033a12c7ab5b6d..da15471a2bbf9a 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -1274,7 +1274,7 @@ TEST_F(hmm2, snapshot) /* Check what the device saw. */ m = buffer->mirror; ASSERT_EQ(m[0], HMM_DMIRROR_PROT_ERROR); - ASSERT_EQ(m[1], HMM_DMIRROR_PROT_NONE); + ASSERT_EQ(m[1], HMM_DMIRROR_PROT_ERROR); ASSERT_EQ(m[2], HMM_DMIRROR_PROT_ZERO | HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[3], HMM_DMIRROR_PROT_READ); ASSERT_EQ(m[4], HMM_DMIRROR_PROT_WRITE);