Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1393851ybi; Wed, 3 Jul 2019 15:04:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqykNuOQFDs2h8XOtIMX88EjPzqyPthLy1IqL7rNm36OsiNO1Mu+ygIz9nm2AnnG8O33eNFQ X-Received: by 2002:a17:90a:ad89:: with SMTP id s9mr15481515pjq.41.1562191485357; Wed, 03 Jul 2019 15:04:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562191485; cv=none; d=google.com; s=arc-20160816; b=YmuYdTbb+bR4qgJVpbPtvXIalyg72SinFAaVSx8OXyZNewqfrP9V3Xh9I3fgFi1Qko 0ML4T3AUjOdKnnTHIvC02xdLre+McL/QfgFJNL9p0NacNca+d8N3d7r+9DvJMJS0b5+F u25ednlJH4p/TIx/uSLLa/cm8yJ6JBcWiUxT7DQALCMkE+zv371ydfGV6tR16QlsskQw 4qYwE7drVEV2ihxkwEQjJViB+He6dtsukd24K1Qn8cqjcfbWKuCTt2uyU3MzqDpou3t7 MUyhObXuIKyYz5FszFys9nMgAO7sE0PmpnA2QOOZF2zUSoq6h3w2ovpBPRu09XrJXtUv p4aA== 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=/hemVxgPEOdbiVtqmrJ7Pu3HACPpqgUeF/rrQJ8zMho=; b=FaeGhPITcQz5wpkABQqKLLAky93VtK5OmosndRXQCALVdPlmNoeRIwX9GOrKKU7Oc4 PZCmnLwRE7a/S35YEBB2m5Ez5+GdQtBKim1b2q9Bc2Mxx60PMneotnJohLOS7q27rp5G SMx9uT2KucCxTDrGa1feTbyx/7sAGDRT+drK1GC/lYVPUk3nmRGnhSoMRkYPUclQpETH r5aTDrV4Lws1XewC4EyrC1ZR/np/eDeSqosS95szdowmdu4ma4prPFVHgmW+t6HpFBJe C9iBL09A7JE34fspvi9M7Iz9nun8c0ziWkUEO4vqGFJU1Jb5DDnkHp9Pk2jM3fY9PyDz /Org== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Kkz67VFi; 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 a15si3129123pgw.246.2019.07.03.15.04.30; Wed, 03 Jul 2019 15:04:45 -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=Kkz67VFi; 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 S1727376AbfGCWCU (ORCPT + 99 others); Wed, 3 Jul 2019 18:02:20 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:33844 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727087AbfGCWCU (ORCPT ); Wed, 3 Jul 2019 18:02:20 -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=/hemVxgPEOdbiVtqmrJ7Pu3HACPpqgUeF/rrQJ8zMho=; b=Kkz67VFiEYQBRKNbXzQ6Ojm7Ri OcwpoDV/CsFrwaqGuhBbSPNg3mkKTGK3IBm4+RL/EUwlT0NR3dRRgi/wPRUKHT9sxRXcnmpRyRMwf m6MHJce1FU7Shn767N08Sk0B9F/mSAOHWhU6/7GIcuZm/DWc1kgge97CFqvxLueX1nexjJfh2RFvu Gs6UiDeiyfwXE/5jyQ+mVDkX0Cgeidpr53Uwx7wASNMlwTwo61RQBiZYib9OefWnsuFa4yw4ZR+dS jGCf81A/6pWNFN7na5WjJOH3ajeY3WvYZLe26FCPeDdEc0pyG2G39NSjTPRsO5OI7H1G9xOMn0fIR 3b9pwbVA==; Received: from rap-us.hgst.com ([199.255.44.250] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1hinKS-0004EV-0U; Wed, 03 Jul 2019 22:02:16 +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: Wed, 3 Jul 2019 15:02:10 -0700 Message-Id: <20190703220214.28319-3-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703220214.28319-1-hch@lst.de> References: <20190703220214.28319-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 | 52 +++++++++++++++++++++- include/linux/hmm.h | 63 --------------------------- 2 files changed, 50 insertions(+), 65 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index 8c92374afcf2..033a9241a14a 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -36,6 +36,13 @@ #include #include +/* + * When waiting for mmu notifiers we need some kind of time out otherwise we + * could potentialy wait for ever, 1000ms ie 1s sounds like a long time to + * wait already. + */ +#define NOUVEAU_RANGE_FAULT_TIMEOUT 1000 + struct nouveau_svm { struct nouveau_drm *drm; struct mutex mutex; @@ -475,6 +482,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, NOUVEAU_RANGE_FAULT_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 +697,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..fa43a9f53833 100644 --- a/include/linux/hmm.h +++ b/include/linux/hmm.h @@ -475,69 +475,6 @@ long hmm_range_dma_unmap(struct hmm_range *range, dma_addr_t *daddrs, bool dirty); -/* - * HMM_RANGE_DEFAULT_TIMEOUT - default timeout (ms) when waiting for a range - * - * When waiting for mmu notifiers we need some kind of time out otherwise we - * could potentialy wait for ever, 1000ms ie 1s sounds like a long time to - * wait already. - */ -#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