Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9203776ybi; Tue, 23 Jul 2019 23:54:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwllSSRfFZVUhimeXJ9VAI4iDbJfOeMrZRw58bjK4y82ui15tAG7QwqmGiLSd/sqC9JzRxE X-Received: by 2002:a17:90a:4806:: with SMTP id a6mr86561058pjh.38.1563951248278; Tue, 23 Jul 2019 23:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563951248; cv=none; d=google.com; s=arc-20160816; b=J6dRp+8xh1u1LVUT6DWLZgxyFWTY4TIen2yy3eE0Ir4/0mjbBeD+zJ4AdiGlwPs1da sSev0gwpKjA59WOvext/6uw1I8AKJdI8CjfbwTPQBogw/uFR/pi65COuDjaOyNoTJCZm 2stYvrrXpKZnCsHXf21wrpyJplPBlsQF7NTvP3E+ChOkvSjkhWLlaJ2MMRhdQSBGn6Y/ ZL074SpwybIDnU2rbD5SPWyfXVCnIPeEBdiLOfQjR9l5UTup84jzq8VekgqHBIOiGBQW zR2B60n+kpWRyYYxp8oT2rAUZIbrf8AU4ptsbcW0NsLRvoG7V/rlA5oGQwOj9jWLDQ6F yXkA== 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=af+9ggTzrooQN+U8Gtergf04cohbJyE/zmcmEx1oVXE=; b=ZCepBhQmE071LMmo9wAZYZxR7bf/xf4u86Jd84X6NrhMh+/FYDch/tY5Y0WCx7C9p1 gqI3oQM2eMju5FQEhaTkzefffP2SgWo4PE+QF0NCpTQY004Bdh2Bz9+aN8XTdXaTTELb BkNmE/vXX6XFPGwXdMJ41/Tm/shcB51/y3EBi0Qy5HvSsyEDvJG0xeZ03/hVWezhM6Dl BRWNSg7OBTYnfvP1q5L52SuToIcsthyMFPTZmz7UheGFeE7Hu4MpGDTx9+S6pBfK3Exq NuRpVGgJ/QTJYZknLrxhvwEm9b2Lwwq9BFo3B/NFrMgsx6V6eYw4dI7IxwtZadiOiOQ+ lzdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=U64OF7RD; 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 v41si15118257pgn.481.2019.07.23.23.53.53; Tue, 23 Jul 2019 23:54:08 -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=U64OF7RD; 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 S1726461AbfGXGxN (ORCPT + 99 others); Wed, 24 Jul 2019 02:53:13 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:39266 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725909AbfGXGxL (ORCPT ); Wed, 24 Jul 2019 02:53:11 -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=af+9ggTzrooQN+U8Gtergf04cohbJyE/zmcmEx1oVXE=; b=U64OF7RDtIK4aPH8u2Yfe/rBOz hVAMPpGIhOwvLO6YSlRDICqyAY7C5IJgR8qZmyRdzrygG4sxifcodjj4gVKlpDoRNbrlF7RbPGDOU oMZbjtjiEIovtu73ZIBM+/nwUvVOK5QMGVdeAz6w4nhu8fetVX4ejYQYQWfedyluBtF1D6JYOENMp l6QRVkOsSz78O1fPMZBUPxNpteExp9DlQHBp9YHkk+OS2Fp6HTFbCTff1LvoMdXdYELaaNGZRR/LA Dt3vndxXBqfKVFdVPR89amKow08m2weDkcEgz3UrRD+ic/YC1nffLvntUV+JIgW7TE96rzOm4ZszC 7DeJxm+A==; 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 1hqB9A-0004IS-3A; Wed, 24 Jul 2019 06:53:08 +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/7] mm: move hmm_vma_range_done and hmm_vma_fault to nouveau Date: Wed, 24 Jul 2019 08:52:53 +0200 Message-Id: <20190724065258.16603-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190724065258.16603-1-hch@lst.de> References: <20190724065258.16603-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 Reviewed-by: Jason Gunthorpe --- drivers/gpu/drm/nouveau/nouveau_svm.c | 46 ++++++++++++++++++++++- include/linux/hmm.h | 54 --------------------------- 2 files changed, 44 insertions(+), 56 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index 8c92374afcf2..6c1b04de0db8 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -475,6 +475,48 @@ 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 +691,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