From patchwork Tue May 7 23:55:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10933889 Return-Path: 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 72573912 for ; Wed, 8 May 2019 00:09:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F77B28643 for ; Wed, 8 May 2019 00:09:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E29D286A0; Wed, 8 May 2019 00:09:50 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (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 E1BC228643 for ; Wed, 8 May 2019 00:09:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 98ABE21243BC7; Tue, 7 May 2019 17:09:49 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=dan.j.williams@intel.com; receiver=linux-nvdimm@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E57DC211F9D7B for ; Tue, 7 May 2019 17:09:47 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 May 2019 17:09:45 -0700 X-ExtLoop1: 1 Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga004.fm.intel.com with ESMTP; 07 May 2019 17:09:46 -0700 Subject: [PATCH v2 0/6] mm/devm_memremap_pages: Fix page release race From: Dan Williams To: akpm@linux-foundation.org Date: Tue, 07 May 2019 16:55:59 -0700 Message-ID: <155727335978.292046.12068191395005445711.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Rafael J. Wysocki" , linux-nvdimm@lists.01.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?utf-8?b?SsOpcsO0bWU=?= Glisse , Greg Kroah-Hartman , Bjorn Helgaas , Christoph Hellwig Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP Changes since v1 [1]: - Fix a NULL-pointer deref crash in pci_p2pdma_release() (Logan) - Refresh the p2pdma patch headers to match the format of other p2pdma patches (Bjorn) - Collect Ira's reviewed-by [1]: https://lore.kernel.org/lkml/155387324370.2443841.574715745262628837.stgit@dwillia2-desk3.amr.corp.intel.com/ Reviewed-by: Logan Gunthorpe --- Logan audited the devm_memremap_pages() shutdown path and noticed that it was possible to proceed to arch_remove_memory() before all potential page references have been reaped. Introduce a new ->cleanup() callback to do the work of waiting for any straggling page references and then perform the percpu_ref_exit() in devm_memremap_pages_release() context. For p2pdma this involves some deeper reworks to reference count resources on a per-instance basis rather than a per pci-device basis. A modified genalloc api is introduced to convey a driver-private pointer through gen_pool_{alloc,free}() interfaces. Also, a devm_memunmap_pages() api is introduced since p2pdma does not auto-release resources on a setup failure. The dax and pmem changes pass the nvdimm unit tests, and the p2pdma changes should now pass testing with the pci_p2pdma_release() fix. Jérôme, how does this look for HMM? In general, I think these patches / fixes are suitable for v5.2-rc1 or v5.2-rc2, and since they touch kernel/memremap.c, and other various pieces of the core, they should go through the -mm tree. These patches merge cleanly with the current state of -next, pass the nvdimm unit tests, and are exposed to the 0day robot with no issues reported (https://git.kernel.org/pub/scm/linux/kernel/git/djbw/nvdimm.git/log/?h=libnvdimm-pending). --- Dan Williams (6): drivers/base/devres: Introduce devm_release_action() mm/devm_memremap_pages: Introduce devm_memunmap_pages PCI/P2PDMA: Fix the gen_pool_add_virt() failure path lib/genalloc: Introduce chunk owners PCI/P2PDMA: Track pgmap references per resource, not globally mm/devm_memremap_pages: Fix final page put race drivers/base/devres.c | 24 +++++++- drivers/dax/device.c | 13 +--- drivers/nvdimm/pmem.c | 17 ++++- drivers/pci/p2pdma.c | 115 +++++++++++++++++++++++-------------- include/linux/device.h | 1 include/linux/genalloc.h | 55 ++++++++++++++++-- include/linux/memremap.h | 8 +++ kernel/memremap.c | 23 ++++++- lib/genalloc.c | 51 ++++++++-------- mm/hmm.c | 14 +---- tools/testing/nvdimm/test/iomap.c | 2 + 11 files changed, 217 insertions(+), 106 deletions(-)