Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1255580ybi; Wed, 3 Jul 2019 12:16:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqygAWcKRbmgqOYiQQ/kAMb12i5iwCcDIYoyaFJ/KVfLVy2PFbSje0kyYub69+di0KGXTCkw X-Received: by 2002:a63:480a:: with SMTP id v10mr38884264pga.60.1562181385858; Wed, 03 Jul 2019 12:16:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562181385; cv=none; d=google.com; s=arc-20160816; b=qsf9CUzw7Am4oKq3y4Y/HK4wiCSe3KoVcUoZydlWpj5vrtRavMGF8Od4YT+cW52DJX rrwvaqAVQH8rfqy5ZUqg+tHdu3hcUF3Ce93ajf5pc3Go7Ts+wdc+lgvgy11v9r3wSYSX c6cQ2SIT1LTdbKbuOuojt9AhC79fkDFGWna54hQvlLwSWZtfsO+xILYBxockVWnV0WCC bzHWSc83vR3Hv15oM7lSyhrYyF+Ly0/6NCxcDLn46/RApgTocNtWdw7P9xQuJEEfqMHK gxb8pyGW6OdKoatI97uJq3wRmCRIHXrdddmY64GlUIX5DPxFYRF3AfVWgSEMz7157lsr RDgA== 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=pfzb7DKQGxSim4j5P5NViAehCYDnD7twhlehxZF4/mk=; b=FHE2lUVV68V+YhMIcOWsxzBh7HT+ofI1NpT9Q3rk2yWeO1DqLm4UjhYhLmodesH8Z+ kVeTyqjS0yYzl6puykZXlKjekBduswDIEMdLJJ4f0+ky1Mvr4OZw1xmncyXd9dXhtRoC wD+9UVY14Yp7d1osjOkJDRaYPDsVzM12YO20kHBZ8Gw27gRToSg6osmsVqn26ikiPH5J 32zdgbz0b8qRWGpN/Ytdhqq3wDh+Wa8AgxdbGaoH7+VCFYEgeIGjmly9FSCG3d5qdWIA 2/EjIq0DLa++HTcGxd0bs1ZHQcpCyX5w9qWcskaGdrdyg4CeWqjWIn9D5+V49BRzU6q2 jFaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=RuEQvC5S; 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 w10si3233521pfq.115.2019.07.03.12.16.09; Wed, 03 Jul 2019 12:16:25 -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=RuEQvC5S; 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 S1727184AbfGCSpM (ORCPT + 99 others); Wed, 3 Jul 2019 14:45:12 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:57560 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727095AbfGCSpK (ORCPT ); Wed, 3 Jul 2019 14:45:10 -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=pfzb7DKQGxSim4j5P5NViAehCYDnD7twhlehxZF4/mk=; b=RuEQvC5Szk3Lm7vVbLr+MfSSqa XBkXs0IYy8wwiP8zUJ+sptGQCbIJgaonwPKADc6EYKfe8cyLXuX6OJAXDLaSAqo00fEJgivMA8G9r Jp3rCAEIlz5o5MUoRMlgjCGuRlKGShwoKhkln491IBgIkVFD2jgvlsNTOIVjVI9KsBedL8bGACTAc Y6LiYyZQM8WHHYqbip9c8930hWAY1B3O4CF9CFWJhVXPoSCnctq2177N1Vc5lVbLit4yJeQh82Csg Uw0Xc8TeK5lNphU2JBlRLkMw4VS923+E5sYbHWFj/v3i0IpK3DbzoSl+Hs3Td3pWdzq4YCGK8hnn6 B82DJdiA==; 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 1hikFb-0007Gl-TU; Wed, 03 Jul 2019 18:45:03 +0000 From: Christoph Hellwig To: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Jason Gunthorpe , Ben Skeggs Cc: linux-mm@kvack.org, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] nouveau: unlock mmap_sem on all errors from nouveau_range_fault Date: Wed, 3 Jul 2019 11:45:01 -0700 Message-Id: <20190703184502.16234-5-hch@lst.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703184502.16234-1-hch@lst.de> References: <20190703184502.16234-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 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_svm.c b/drivers/gpu/drm/nouveau/nouveau_svm.c index e831f4184a17..c0cf7aeaefb3 100644 --- a/drivers/gpu/drm/nouveau/nouveau_svm.c +++ b/drivers/gpu/drm/nouveau/nouveau_svm.c @@ -500,8 +500,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, NOUVEAU_RANGE_FAULT_TIMEOUT)) { /* @@ -515,15 +517,14 @@ nouveau_range_fault(struct hmm_mirror *mirror, struct hmm_range *range, 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) + if (ret == 0) ret = -EBUSY; + if (ret != -EAGAIN) + up_read(&range->vma->vm_mm->mmap_sem); hmm_range_unregister(range); return ret; } + return 0; } @@ -718,8 +719,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