Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6968018ybi; Mon, 22 Jul 2019 04:54:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqypWBnXTaLWo3F3Ug40uB46J9NKfhDtzZJyVd5CKc2Y3wc4MaLTLkA+Jszy5uzYT5bw6VBQ X-Received: by 2002:a63:6d8d:: with SMTP id i135mr70640231pgc.303.1563796498081; Mon, 22 Jul 2019 04:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563796498; cv=none; d=google.com; s=arc-20160816; b=yztnIdhXphNtFpBoA48mjIJlAw6lIr2V9qtVm8bOstWeAkgokcsRGKnKJdM7XnKVsx qiOu8p+ILOOrYKu+MVd5gsmvOV4GUZOfAMfLxd5D71BulsVXsmDRXOMITo4FhMpILzbg pF0Hh6kJzf7hGl6pwdKVf5reELcRaRSfxlwetxo8R65AVZsbrC7KOvgsdYcfv5QemaSO tbZ6u+hti4D1Rgbey9VgxNfhB/pJWYAXS8fX6b2UOye5ds0w3Uo6MdjuG3Rbb59jdhls KNANnSn0Et6gTQ+J988ZNtKE5S1hOUHrStP2PjraiC6cCwslgBVzduAuZX+WPWqoIHZz azFQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3uvTtAB60j2sX58BYKBbOjuVpS09AJwPFJhgG33SN6g=; b=O7CT3vx6tRKHFRrXuOqGbJro8ZO6apz3OVIR8i45aEN6DaLhNrv+V/GFWi8ACG2RT5 LbPq04atTm91vLfL51CYLeHskuSLtwxztNuwvYficnhOxA2hsvkzDE7G39+VVLk8J0wp Nr+URKO9SIkM4Ec1n8O1l+cIFsEmeyFLKbFOs/tnhNyVJSZI+o/rHVWK6O6NQ3oiOfji LGzJus+RHEJWMWTElsHyb6bStPejf7UHMpyovl4dQG0wNDFdhJf0pTC8T/jzGERy+P2k 4jhGhAYL8XzC30fliTCPN3T63dPogKn8ocWWfqXrN3nSa7As2Xa2bTf5PFU8Vxq6lcrr ugsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dis5qQNz; 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 m2si10394652pll.374.2019.07.22.04.54.41; Mon, 22 Jul 2019 04:54:58 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=dis5qQNz; 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 S1729139AbfGVJoh (ORCPT + 99 others); Mon, 22 Jul 2019 05:44:37 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35282 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729122AbfGVJog (ORCPT ); Mon, 22 Jul 2019 05:44:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=3uvTtAB60j2sX58BYKBbOjuVpS09AJwPFJhgG33SN6g=; b=dis5qQNzsIQBdOBibWkzOcJ4gK wStPEqafXe7BljX8GR9Ovc0C8MOXMPORFunkej4Z2wtu/1OAGwdDhQil4cSP3APO0tdpl5KEEkciz 9ZHJB9c2O+QWlBVXDRJs4F0usZmTE9XcH/83CA8fIyRrAI9bwxm9bx6+iyh8mVs3DLPWVq6Mxhosk 6h/WbrwjMpFCEqgg6v+Rg4UR5WAk++SEIdLwxzAQi1T3cXDvo12hZrZxN7hKlFcvOh6ZGBjTWt2Ck V04FZyL5dp0fidDGE36KR/hilcR9x4PmNpoWu28WqJRzfaJE+lyH6dPVXuAXRiQ8yH78kBeHbWB5C R8GIBJhQ==; Received: from 089144207240.atnat0016.highway.bob.at ([89.144.207.240] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hpUrx-0001s1-9G; Mon, 22 Jul 2019 09:44:33 +0000 From: Christoph Hellwig To: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Jason Gunthorpe , Ben Skeggs Cc: Ralph Campbell , linux-mm@kvack.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] mm: move hmm_vma_range_done and hmm_vma_fault to nouveau Date: Mon, 22 Jul 2019 11:44:22 +0200 Message-Id: <20190722094426.18563-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190722094426.18563-1-hch@lst.de> References: <20190722094426.18563-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org These two functions are marked as a legacy APIs to get rid of, but seem to suit the current nouveau flow. Move it to the only user in preparation for fixing a locking bug involving caller and callee. All comments referring to the old API have been removed as this now is a driver private helper. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/nouveau/nouveau_svm.c | 45 +++++++++++++++++++++- include/linux/hmm.h | 54 --------------------------- 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index 8c92374afcf2..cde09003c06b 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -475,6 +475,47 @@ nouveau_svm_fault_cache(struct nouveau_svm *svm, fault->inst, fault->addr, fault->access); } +static inline bool nouveau_range_done(struct hmm_range *range) +{ + bool ret = hmm_range_valid(range); + + hmm_range_unregister(range); + return ret; +} + +static int +nouveau_range_fault(struct hmm_mirror *mirror, struct hmm_range *range, + bool block) +{ + long ret; + + range->default_flags = 0; + range->pfn_flags_mask = -1UL; + + ret = hmm_range_register(range, mirror, + range->start, range->end, + PAGE_SHIFT); + if (ret) + return (int)ret; + + if (!hmm_range_wait_until_valid(range, HMM_RANGE_DEFAULT_TIMEOUT)) { + up_read(&range->vma->vm_mm->mmap_sem); + return -EAGAIN; + } + + ret = hmm_range_fault(range, block); + if (ret <= 0) { + if (ret == -EBUSY || !ret) { + up_read(&range->vma->vm_mm->mmap_sem); + ret = -EBUSY; + } else if (ret == -EAGAIN) + ret = -EBUSY; + hmm_range_unregister(range); + return ret; + } + return 0; +} + static int nouveau_svm_fault(struct nvif_notify *notify) { @@ -649,10 +690,10 @@ nouveau_svm_fault(struct nvif_notify *notify) range.values = nouveau_svm_pfn_values; range.pfn_shift = NVIF_VMM_PFNMAP_V0_ADDR_SHIFT; again: - ret = hmm_vma_fault(&svmm->mirror, &range, true); + ret = nouveau_range_fault(&svmm->mirror, &range, true); if (ret == 0) { mutex_lock(&svmm->mutex); - if (!hmm_vma_range_done(&range)) { + if (!nouveau_range_done(&range)) { mutex_unlock(&svmm->mutex); goto again; } diff --git a/include/linux/hmm.h b/include/linux/hmm.h index b8a08b2a10ca..7ef56dc18050 100644 --- a/include/linux/hmm.h +++ b/include/linux/hmm.h @@ -484,60 +484,6 @@ long hmm_range_dma_unmap(struct hmm_range *range, */ #define HMM_RANGE_DEFAULT_TIMEOUT 1000 -/* This is a temporary helper to avoid merge conflict between trees. */ -static inline bool hmm_vma_range_done(struct hmm_range *range) -{ - bool ret = hmm_range_valid(range); - - hmm_range_unregister(range); - return ret; -} - -/* This is a temporary helper to avoid merge conflict between trees. */ -static inline int hmm_vma_fault(struct hmm_mirror *mirror, - struct hmm_range *range, bool block) -{ - long ret; - - /* - * With the old API the driver must set each individual entries with - * the requested flags (valid, write, ...). So here we set the mask to - * keep intact the entries provided by the driver and zero out the - * default_flags. - */ - range->default_flags = 0; - range->pfn_flags_mask = -1UL; - - ret = hmm_range_register(range, mirror, - range->start, range->end, - PAGE_SHIFT); - if (ret) - return (int)ret; - - if (!hmm_range_wait_until_valid(range, HMM_RANGE_DEFAULT_TIMEOUT)) { - /* - * The mmap_sem was taken by driver we release it here and - * returns -EAGAIN which correspond to mmap_sem have been - * drop in the old API. - */ - up_read(&range->vma->vm_mm->mmap_sem); - return -EAGAIN; - } - - ret = hmm_range_fault(range, block); - if (ret <= 0) { - if (ret == -EBUSY || !ret) { - /* Same as above, drop mmap_sem to match old API. */ - up_read(&range->vma->vm_mm->mmap_sem); - ret = -EBUSY; - } else if (ret == -EAGAIN) - ret = -EBUSY; - hmm_range_unregister(range); - return ret; - } - return 0; -} - /* Below are for HMM internal use only! Not to be used by device driver! */ static inline void hmm_mm_init(struct mm_struct *mm) { -- 2.20.1