Received: by 10.223.176.46 with SMTP id f43csp2550941wra; Thu, 25 Jan 2018 11:36:10 -0800 (PST) X-Google-Smtp-Source: AH8x227tqYpE65FqeyGUVVd8hctZCoK2cYWEMEQWyrIMy8089zDKa4ikzwOeqnoueZeCxI5KFrjf X-Received: by 2002:a17:902:b20b:: with SMTP id t11-v6mr12772563plr.172.1516908970210; Thu, 25 Jan 2018 11:36:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516908970; cv=none; d=google.com; s=arc-20160816; b=t64oWlvFZM5uckIECIKXniwlLsCQyAk7FYDkoXBHBLVSMv3ORQ30COZiE5We1tNUWr Cy7yA52BMty4XcvUmPGjRBBksTf5L/P9H94xqhnefWZYBjB3kYLgQRC/DAtEfi9AklEP mIhZ0Hiiy+nKU2MShk6h+Zf23zo0mx1XsqA629ByvhzCKw8o/H3RWDRQYeO8IVi+7j+3 ZD2PEg9Dhk4Bage6oO8O6rj3oeeijBhUg94LjeNbGZTe6PW9vyTPG6uSTGU1fA0i0VPK MSJGzayT/I512g8db+gFCoaeH2Jr2aWW1W0sO0nvZxw6lWhoIhQTizTm7o1STRKvivJH tyXg== 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:arc-authentication-results; bh=IL2TiWAZXbi4LHOQt8CJ5ZA2OPUZcphXBKyGytX3/xs=; b=Nb3ZtG68cXaNAjjtxuRYGchXQ7qwWy6O6sGL2TMJOwYB6FvTIjTq6r2UO6y5q/sxoz lVGTxoZdoprnK+ESWw9Okjb+HuxGIHieYNfbmpKSd9JBE1qWHKaLeuPbEDpLhfwOTRCU 47VISQUKMwtqt7xyS/3aKBcYfucwMn6lIVkAhhXoeYLHYGv4GtWmVXVw0o3iBk90D0Um wt6pkXAXrw61LRf26ygaUL9AHPMsxRvmI9y0s23WbfBFcOkKNzw8JfYN0e2xaZBUBSkZ RcQ+JUh8wVWBS7CHrnEYWQeJCOXt40oegEo5sNS7WHdNNtrNbSiqXlSoZcIxAxVVdjCP 6TsQ== 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 a3-v6si2404739plc.552.2018.01.25.11.35.55; Thu, 25 Jan 2018 11:36:10 -0800 (PST) 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 S1751367AbeAYTfH (ORCPT + 99 others); Thu, 25 Jan 2018 14:35:07 -0500 Received: from mx2.suse.de ([195.135.220.15]:47627 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751174AbeAYTfG (ORCPT ); Thu, 25 Jan 2018 14:35:06 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 80811AEFC; Thu, 25 Jan 2018 19:35:04 +0000 (UTC) Date: Thu, 25 Jan 2018 11:27:27 -0800 From: Davidlohr Bueso To: Jason Gunthorpe Cc: Doug Ledford , roland@purestorage.com, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH] IB/mthca: Fix how mthca_map_user_db() calls gup Message-ID: <20180125192727.dkwuqel3xfut66wj@linux-n805> References: <20180123205459.432-1-dave@stgolabs.net> <1516898063.27592.136.camel@redhat.com> <20180125175048.GG10706@ziepe.ca> <1516903584.27592.183.camel@redhat.com> <20180125185330.GH10706@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20180125185330.GH10706@ziepe.ca> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 25 Jan 2018, Jason Gunthorpe wrote: >> >> Since the original post was referred to an ABBA deadlock, wouldn't we >> have to drop db_tab->mutex, then grab both in the proper order? > >I had understood that was only a concern because Davidlohr was having >trouble proving the callchain didn't include mmap_sem already.. > >I can see the call chain all ends on verbs ops, and I know verbs ops >with ucontext's are never called under mmap_sem by the core code.. Right. Ok so this simplifies things and we can just use gup_fast(). Thanks, Davidlohr ---8<--------------------------------------------------- [PATCH v2] IB/mthca: Fix gup usage in mthca_map_user_db() get_user_pages() must be called with mmap_sem held, currently it is not. In fact it is called under the user db_table->mutex. To fix this we can convert gup to use the fast alternative, and safely avoid taking mmap_sem, if possible. Furthermore this is safe wrt to the mutex as other callers that take the lock (unmap and alloc_db) are not called under mmap_sem (hence possible deadlock). Signed-off-by: Davidlohr Bueso --- drivers/infiniband/hw/mthca/mthca_memfree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c index c6fe89d79248..9a412738d5c3 100644 --- a/drivers/infiniband/hw/mthca/mthca_memfree.c +++ b/drivers/infiniband/hw/mthca/mthca_memfree.c @@ -472,7 +472,7 @@ int mthca_map_user_db(struct mthca_dev *dev, struct mthca_uar *uar, goto out; } - ret = get_user_pages(uaddr & PAGE_MASK, 1, FOLL_WRITE, pages, NULL); + ret = get_user_pages_fast(uaddr & PAGE_MASK, 1, FOLL_WRITE, pages); if (ret < 0) goto out; -- 2.13.6