Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp8942772ybi; Tue, 23 Jul 2019 18:33:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqySS12jcDFM2G5LnTaAb50VzXJPWaO2H10dZYtFyAmu3pHXq47Z5ovlkfyUH2QJQLfSr3o5 X-Received: by 2002:a17:90a:db08:: with SMTP id g8mr82199318pjv.39.1563932038947; Tue, 23 Jul 2019 18:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563932038; cv=none; d=google.com; s=arc-20160816; b=JL9pg6gP7+ACQ1kX2+WS/biiziOHgFM65k4XpdbXeBxxPYl2pYd5+bDELm7Q7wU4J7 RBDz+TZ86KW96CT2qzW198doz0/lW/YQ/5Kp5Lp/CYYp7DjgylJfDUyJKpcjKBcL8y9S +GqBoJc/L6Bp+gyBBPmEJZtBbgug6TbKQnY9hYbbmbYKurKtccaWrPxfu1MIFgQZTqHC z5aox8/jR0fHvZUYEH2PA4Lf7HD97wiT2excetrgMBDg1JL3bsnt8cePNFewEMDQRtcs 7YV89tuWt6NrkL8rRf0goyU2vpzaZnwyjaIR9g+5EK1ppkqHmKFlj4Gn0btoO2sBHrEI JB2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=BuplSnnL3WMx/Jb7sI7R9wCtdKIxvBlt+7K+m5n19w8=; b=A7RDViuvq/phE2wtOBB8RHpMfz6wbDdjs3GqB31o18fEXJlQLRBmIslQD4mVIc9Xpd BykqpnqFhUOgwtVyFp1NN450WKla/VSIANnfkXXGl5XJPnqTcTeqktmBSimZcxnViPlG wXVY+ZqqRs5AxzPVcr/dgxChqjwV7fA6e+tvdrdRdOLfCYwYpH7pkO9yv9ZmSxZWk48F Jbu84NBFfND9zHOPaquCiA60myv48DHzajmengKbOS+o0bgMy3t8Df9Ux0DnSWR8GCFg z9In6niukXSjieQ88DyurD2/PBJ9omq54fePssDgzaeIqrbUTWh4Y+pAH4KVpdag8tC1 1SCQ== ARC-Authentication-Results: i=1; mx.google.com; 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 s94si11613051pjb.83.2019.07.23.18.33.42; Tue, 23 Jul 2019 18:33: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; 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 S2388762AbfGWQaw (ORCPT + 99 others); Tue, 23 Jul 2019 12:30:52 -0400 Received: from verein.lst.de ([213.95.11.211]:43190 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727671AbfGWQav (ORCPT ); Tue, 23 Jul 2019 12:30:51 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 9C53F68B02; Tue, 23 Jul 2019 18:30:48 +0200 (CEST) Date: Tue, 23 Jul 2019 18:30:48 +0200 From: Christoph Hellwig To: Jason Gunthorpe Cc: Christoph Hellwig , =?iso-8859-1?B?Suly9G1l?= Glisse , Ben Skeggs , Ralph Campbell , "linux-mm@kvack.org" , "nouveau@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 4/6] nouveau: unlock mmap_sem on all errors from nouveau_range_fault Message-ID: <20190723163048.GD1655@lst.de> References: <20190722094426.18563-1-hch@lst.de> <20190722094426.18563-5-hch@lst.de> <20190723151824.GL15331@mellanox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190723151824.GL15331@mellanox.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 23, 2019 at 03:18:28PM +0000, Jason Gunthorpe wrote: > Hum.. > > The caller does this: > > again: > ret = nouveau_range_fault(&svmm->mirror, &range); > if (ret == 0) { > mutex_lock(&svmm->mutex); > if (!nouveau_range_done(&range)) { > mutex_unlock(&svmm->mutex); > goto again; > > And we can't call nouveau_range_fault() -> hmm_range_fault() without > holding the mmap_sem, so we can't allow nouveau_range_fault to unlock > it. Goto again can only happen if nouveau_range_fault was successful, in which case we did not drop mmap_sem. Also: > ret = hmm_range_fault(range, true); > if (ret <= 0) { > if (ret == 0) > ret = -EBUSY; > - up_read(&range->vma->vm_mm->mmap_sem); > hmm_range_unregister(range); This would hold mmap_sem over hmm_range_unregister, which can lead to deadlock if we call exit_mmap and then acquire mmap_sem again.