Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6968618ybi; Mon, 22 Jul 2019 04:55:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxw1qt4uAY7EohWFzPsqUkkZ/4cFhXj/ppjv93ysM9Tv/zF7ymxtkr99/x2zeXOWExor8NC X-Received: by 2002:a17:90a:ac11:: with SMTP id o17mr77812140pjq.134.1563796542175; Mon, 22 Jul 2019 04:55:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563796542; cv=none; d=google.com; s=arc-20160816; b=xS/FfJR4N4AbYfADsZzjU7aA1YxuENI7EwgUmmHzcvq1Zi8Gz4UjXA/VnEVZZCFqhN 9S/Y8Axc3RGf8w/JvCYZzBPUKxO8rTLK56pxNK1kjLIb9uHBKiBn2Tkqvh8j2P/OroSP UrEfhOekZa1lQaC1Ct7gZPhuJ/WoSBtZ29S+ZhCHpFmPZjucmgNQ5+8JciyHgv14yAKL Ui0mfSKtRDlwGK/VT4Cn/fxjvs0yMNV7UOF3lp8ko5aWpCjwoUdZxy13qBFqdqTKBwg6 do2vVpmjkea0uugfwXEhvKRHQCFgYWLBAeAXPlyE9YZBGhlD3dYsc82KBTUvPiZSmPsv b95A== 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=7FsIrxY02SwL66nSI+mJn6yPhyHFx4vF4xrsx6w9rHE=; b=zRkA3vpCoGQt57qowLAx9lNu87s1/nVF0+GukLa5Qa17UiF1xbDfq21fbj4fbneQBO LXhbXFtXXHxtwoW712NNU4+kD9OO4+9dzQXtowWBIxO5fK9fL5KXQx49t2zeYpv7BBp+ /vKI9IIG3STqq0Asy4tsS6eHTJOfirB5OqsOlRSt+5AgDgudFCYXwoKK8VYPDRTM7NrA J9mytScDf5w2KfvGTWzzj5tisFdlfx7HjS7i693COfT+qg11JeFwhikz6BpcylsiQPOn yDsvUSX6QWmg8GeviYL5baQivDy54yMuJe8ZC6kdg62s2SKx1Nk3TC6ZtGUZvA8FhSy9 9rJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=KBrWujtJ; 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 14si9320328pgy.255.2019.07.22.04.55.26; Mon, 22 Jul 2019 04:55:42 -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=KBrWujtJ; 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 S1729169AbfGVJon (ORCPT + 99 others); Mon, 22 Jul 2019 05:44:43 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35320 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729160AbfGVJol (ORCPT ); Mon, 22 Jul 2019 05:44:41 -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=7FsIrxY02SwL66nSI+mJn6yPhyHFx4vF4xrsx6w9rHE=; b=KBrWujtJOcYc9XfEbicugrh0Ld WNtLBZQsXjaV9zG4rza6opsoXkHSVU7X6uZkzlxFHi6MsHHy0+PcuHhana1BszUNp8Vz6cBez9Ue4 lR4CHnIFsGeZ/Y9okLdcFzmr7AM8zdJeoz88kBt4imZWSN9mspryETy3V896mi/j7diZq7x5xf6Xl 9wcVv5WzOBsbGHk8ZDhV5+bt1qqSHyVvaTrKA4lFLINhGHFemEvdx228VplD4T33YKY3JBy4Ybui8 rV5r1H5tG+d8FVqHsVlNuFyYCzShgyzz/le6tL8pmGTUPrA72N4i8B1la8aDBZTfhXBNtMdEklZ69 BqQvr05Q==; 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 1hpUs2-0001ss-AE; Mon, 22 Jul 2019 09:44:38 +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 4/6] nouveau: unlock mmap_sem on all errors from nouveau_range_fault Date: Mon, 22 Jul 2019 11:44:24 +0200 Message-Id: <20190722094426.18563-5-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 Currently nouveau_svm_fault expects nouveau_range_fault to never unlock mmap_sem, but the latter unlocks it for a random selection of error codes. Fix this up by always unlocking mmap_sem for non-zero return values in nouveau_range_fault, and only unlocking it in the caller for successful returns. Signed-off-by: Christoph Hellwig --- drivers/gpu/drm/nouveau/nouveau_svm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index 5dd83a46578f..5de2d54b9782 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -494,8 +494,10 @@ nouveau_range_fault(struct hmm_mirror *mirror, struct hmm_range *range) ret = hmm_range_register(range, mirror, range->start, range->end, PAGE_SHIFT); - if (ret) + if (ret) { + up_read(&range->vma->vm_mm->mmap_sem); return (int)ret; + } if (!hmm_range_wait_until_valid(range, HMM_RANGE_DEFAULT_TIMEOUT)) { up_read(&range->vma->vm_mm->mmap_sem); @@ -504,11 +506,9 @@ nouveau_range_fault(struct hmm_mirror *mirror, struct hmm_range *range) ret = hmm_range_fault(range, true); if (ret <= 0) { - if (ret == -EBUSY || !ret) { - up_read(&range->vma->vm_mm->mmap_sem); - ret = -EBUSY; - } else if (ret == -EAGAIN) + if (ret == 0) ret = -EBUSY; + up_read(&range->vma->vm_mm->mmap_sem); hmm_range_unregister(range); return ret; } @@ -706,8 +706,8 @@ nouveau_svm_fault(struct nvif_notify *notify) NULL); svmm->vmm->vmm.object.client->super = false; mutex_unlock(&svmm->mutex); + up_read(&svmm->mm->mmap_sem); } - up_read(&svmm->mm->mmap_sem); /* Cancel any faults in the window whose pages didn't manage * to keep their valid bit, or stay writeable when required. -- 2.20.1