Message ID | 20190614004450.20252-1-jgg@ziepe.ca (mailing list archive) |
---|---|
Headers | show
Return-Path: <dri-devel-bounces@lists.freedesktop.org> Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1DE5C14C0 for <patchwork-dri-devel@patchwork.kernel.org>; Fri, 14 Jun 2019 07:24:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05E0222ADC for <patchwork-dri-devel@patchwork.kernel.org>; Fri, 14 Jun 2019 07:24:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE9B827DA4; Fri, 14 Jun 2019 07:24:20 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9EF4322ADC for <patchwork-dri-devel@patchwork.kernel.org>; Fri, 14 Jun 2019 07:24:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5D1A689736; Fri, 14 Jun 2019 07:22:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by gabe.freedesktop.org (Postfix) with ESMTPS id 52764892EF for <dri-devel@lists.freedesktop.org>; Fri, 14 Jun 2019 00:44:55 +0000 (UTC) Received: by mail-qt1-x843.google.com with SMTP id 33so588306qtr.8 for <dri-devel@lists.freedesktop.org>; Thu, 13 Jun 2019 17:44:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=R/AhTlxkz9VD/Gth3t6L3luS1MUasGphGhAFUOpm608=; b=c/nBRLBNlbHPWQYfgP/7mwDn6FCSOiPoXi7FJZQQR6L2YFcgBrjEyE/jgxO7EQA+xw ZP3P3Fpz0mRDahWvYmwsYcE83dELI6EK7Z555Td6uIcJT+/cdCrqnli6qF/CtDavGRP0 m9aN9FPzSzPJWOHsnYhF0cx0nBCfT+8NszYRc3L4Yz/5nnULqNMlRjdR3fxqzUHJ9B9s uqze/YRdCOk5ZbkpVhWiQy+3IsyBR6faL9efQzp1dYP1MT+49gkuJv7umJO0JsYMJ1df qSofHuYd2BtBhlI24pYNc+6VJvfvNHruIIAlAeqGCQrujEox731YM3OHPgRdy9Z1/fEa +9Ng== X-Gm-Message-State: APjAAAVvM2dOQWCVeC7WW9PI5LAbpcNcqpizKoKHjpAHR1Euyvu8/4+s C+/XuB84s+YcnGUKrOjnxMhWDA== X-Google-Smtp-Source: APXvYqwwLhCAHZe6HhzxmL/Iw5P6iX8RWN7iT/fwDDndsKBg+CvZVk5Nt+VA+fnelddHK4pmtIZtkw== X-Received: by 2002:aed:3ed5:: with SMTP id o21mr76020282qtf.369.1560473094348; Thu, 13 Jun 2019 17:44:54 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-156-34-55-100.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.55.100]) by smtp.gmail.com with ESMTPSA id c55sm754749qtk.53.2019.06.13.17.44.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Jun 2019 17:44:53 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from <jgg@ziepe.ca>) id 1hbaKr-0005JR-I5; Thu, 13 Jun 2019 21:44:53 -0300 From: Jason Gunthorpe <jgg@ziepe.ca> To: Jerome Glisse <jglisse@redhat.com>, Ralph Campbell <rcampbell@nvidia.com>, John Hubbard <jhubbard@nvidia.com>, Felix.Kuehling@amd.com Subject: [PATCH v3 hmm 00/12] mm/hmm: Various revisions from a locking/code review Date: Thu, 13 Jun 2019 21:44:38 -0300 Message-Id: <20190614004450.20252-1-jgg@ziepe.ca> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 14 Jun 2019 07:21:24 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=R/AhTlxkz9VD/Gth3t6L3luS1MUasGphGhAFUOpm608=; b=lwkJgPljFC3Tn+LXK7qjmyhVvethI42H5ylf1MGRcm6oKxXVhq8Wzl8TRDe9Eqm+YN rJkB0pghRseSkcWlc54ohBbckUGirR4baXgc8115jYObInJrRLwQtP1X+52KdX8JiSYG ZULIP8XcgCXVOf6rHO/PNjB1SdPHt7h/hl6bwATGZ4PjbayxrcZKj0MW25KMUNfW8oby AUpBHYJLOgSKHGgD0ip9zurdr2qqnIm8rtMl4gsk1TRGtmQsYhUxbnXWYhvO49MrsJaQ CyFu2i3cjrPLnh9c7W2+KHMZZ1HkvmrdKx7z9NMxZ/34RA3NYsFe25qalY3RhhfJ8whk 95HQ== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development <dri-devel.lists.freedesktop.org> List-Unsubscribe: <https://lists.freedesktop.org/mailman/options/dri-devel>, <mailto:dri-devel-request@lists.freedesktop.org?subject=unsubscribe> List-Archive: <https://lists.freedesktop.org/archives/dri-devel> List-Post: <mailto:dri-devel@lists.freedesktop.org> List-Help: <mailto:dri-devel-request@lists.freedesktop.org?subject=help> List-Subscribe: <https://lists.freedesktop.org/mailman/listinfo/dri-devel>, <mailto:dri-devel-request@lists.freedesktop.org?subject=subscribe> Cc: Andrea Arcangeli <aarcange@redhat.com>, linux-rdma@vger.kernel.org, amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe <jgg@mellanox.com>, dri-devel@lists.freedesktop.org, Ben Skeggs <bskeggs@redhat.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: base64 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" <dri-devel-bounces@lists.freedesktop.org> X-Virus-Scanned: ClamAV using ClamSMTP |
Series |
mm/hmm: Various revisions from a locking/code review
|
expand
|
From: Jason Gunthorpe <jgg@mellanox.com> This patch series arised out of discussions with Jerome when looking at the ODP changes, particularly informed by use after free races we have already found and fixed in the ODP code (thanks to syzkaller) working with mmu notifiers, and the discussion with Ralph on how to resolve the lifetime model. Overall this brings in a simplified locking scheme and easy to explain lifetime model: If a hmm_range is valid, then the hmm is valid, if a hmm is valid then the mm is allocated memory. If the mm needs to still be alive (ie to lock the mmap_sem, find a vma, etc) then the mmget must be obtained via mmget_not_zero(). The use unlocked reads on 'hmm->dead' are also eliminated in favour of using standard mmget() locking to prevent the mm from being released. Many of the debugging checks of !range->hmm and !hmm->mm are dropped in favour of poison - which is much clearer as to the lifetime intent. The trailing patches are just some random cleanups I noticed when reviewing this code. I would like to run some testing with the ODP patch, but haven't yet. Otherwise I think this is reviewed enough, and if there is nothing more say I hope to apply it next week. I plan to continue to work on the idea with CH to move more of this mirror code into mmu notifiers and other places, but this will take some time and research. Thanks to everyone who took time to look at this! Jason Gunthorpe (12): mm/hmm: fix use after free with struct hmm in the mmu notifiers mm/hmm: Use hmm_mirror not mm as an argument for hmm_range_register mm/hmm: Hold a mmgrab from hmm to mm mm/hmm: Simplify hmm_get_or_create and make it reliable mm/hmm: Remove duplicate condition test before wait_event_timeout mm/hmm: Hold on to the mmget for the lifetime of the range mm/hmm: Use lockdep instead of comments mm/hmm: Remove racy protection against double-unregistration mm/hmm: Poison hmm_range during unregister mm/hmm: Do not use list*_rcu() for hmm->ranges mm/hmm: Remove confusing comment and logic from hmm_release mm/hmm: Fix error flows in hmm_invalidate_range_start drivers/gpu/drm/nouveau/nouveau_svm.c | 2 +- include/linux/hmm.h | 52 +---- kernel/fork.c | 1 - mm/hmm.c | 286 ++++++++++++-------------- 4 files changed, 140 insertions(+), 201 deletions(-)