From patchwork Thu Jan 25 19:27:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Davidlohr Bueso X-Patchwork-Id: 10184733 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7102D60388 for ; Thu, 25 Jan 2018 19:35:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5DE2128AAA for ; Thu, 25 Jan 2018 19:35:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F1EE28AAD; Thu, 25 Jan 2018 19:35:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2EF728AAA for ; Thu, 25 Jan 2018 19:35:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751254AbeAYTfG (ORCPT ); Thu, 25 Jan 2018 14:35:06 -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-Disposition: inline In-Reply-To: <20180125185330.GH10706@ziepe.ca> User-Agent: NeoMutt/20170421 (1.8.2) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;