From patchwork Mon Jun 4 23:11:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10447443 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 E583B603D7 for ; Mon, 4 Jun 2018 23:21:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D7F3F29210 for ; Mon, 4 Jun 2018 23:21:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC2E729226; Mon, 4 Jun 2018 23:21:56 +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=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F5DC29210 for ; Mon, 4 Jun 2018 23:21:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25EFA6B000D; Mon, 4 Jun 2018 19:21:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 20DD76B000E; Mon, 4 Jun 2018 19:21:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D75E6B0010; Mon, 4 Jun 2018 19:21:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id BCE066B000D for ; Mon, 4 Jun 2018 19:21:54 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id 89-v6so226832plb.18 for ; Mon, 04 Jun 2018 16:21:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:cc:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=AZLjlX2M8jHDc1rb20WR1Xwctb2PwJFdmg7olWSgQ/Y=; b=UjVaRdfDKAZ+e2rwJLzjp+dvH8ugkX3lRPBQ+nkhxot6c7txA4MOVGf0oFDGesvPXU P6tTgWWqnJXSM1T/m0vyZ8G9GeBrWOxGngXC+6IeCMZkzA1vits9NFrkkaTTvzmT/4hX XMwN07hGBVMRA7WbxBd0cTOrPyQHp14I6annCkYTugFnZy0SfC3E0VkAQhC3S0dg1vMn N0Ge0zBc265w8ZXFctJgDV5HTY3uPn3RCb0FTe8i0Vi3sJeD9xal+A81quChvGdknrEf IF1CZhIfI11vK640LPc7jLaZEBSYnprmdVUXMRWpQfhp/b2lb+Dtd/MSAzBPQkRZ/6vj 1nPg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Gm-Message-State: ALKqPweUvWzFA9Z535wsU82DjneRmr+IZ45l9DgYtXEiIRiKOkIXPMUC EFlYfrGVOniw1YVqxaikDK9A1z0kvw0T2jlejgetMdk/P7g9St7c+Va2uw+OV3AD/T9rMyZBVve rUtiCF+lnDkv/iqbpB6K1oayBjLSq9gfbYqET+k91aLh6rshSMZfFjIJizdeJtLcEZA== X-Received: by 2002:a65:4a87:: with SMTP id b7-v6mr18737000pgu.271.1528154514448; Mon, 04 Jun 2018 16:21:54 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKgdgc+c5ucuhxSpR5afXl2EKUnxpPxEvsqZuxAxbf96Wz4Rbv51etD203zEtDd1QXBV18a X-Received: by 2002:a65:4a87:: with SMTP id b7-v6mr18736966pgu.271.1528154513533; Mon, 04 Jun 2018 16:21:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528154513; cv=none; d=google.com; s=arc-20160816; b=wxW+m4KtJxWz2+Qb2QTbIOw73vSSojPo7fF34eUhOKODMJJmuU/PY20OoqGTORXm1o erDd6t82JpIrggalEbQQadzz51M6PFod4zshD046Ak49EsereVFSVJZRiuCtT6kcENcM aPGdyYXpgh52IkyhJxjJg1ZOseBHlV0WUEKobnjfoo3Qrx7lTJ5xVel3LW5v6T6cRydw dZ6L3v3ag4C2R3vUSyOJ/70qT2bQg09qCjTBbv0uqx++ITbXKIat/LZuDGNiZsl6+4NZ hBkkcd1j8pN+SKOUCkDeAVF4HEQSwK4ADfr5grjTo5vrZ5/SQXo5pSPSAcHDLDO2XOiD LK0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject :arc-authentication-results; bh=AZLjlX2M8jHDc1rb20WR1Xwctb2PwJFdmg7olWSgQ/Y=; b=Y/sSIwqvblmAF2EMTXsW9myQOnOwnByBHdWpqTBTC37m7YlOSq4T6x6a7kT+fM8Ltt 4eCYm4mo1TbKfZ2KMTKWmuJmYI7t/ddyLfCWbFhJriBVIh7xo4sZ4molbqni1lj0OpKq 6b6jUzN2CtIj/Ap/URtip/1UdPLqNYAuEjcl4GObUn9yNcXRvVY9UbAxtTwprpWDsHnB OLZUSFOa7UnPHE453XoXg5hm1JCNNFALRdPsoD9dcMpqRENWVxlobIM6o25tYkE5/O3W pngn83qreyEJgwGIsF4yyq/IMV/4R4i4ML3Xk+VNKxJkSTPC+4Y1zFz/FdKJsrR7c7zZ mG+g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga12.intel.com (mga12.intel.com. [192.55.52.136]) by mx.google.com with ESMTPS id l9-v6si16734359pgr.287.2018.06.04.16.21.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 16:21:53 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 as permitted sender) client-ip=192.55.52.136; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2018 16:21:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,477,1520924400"; d="scan'208";a="54730738" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by FMSMGA003.fm.intel.com with ESMTP; 04 Jun 2018 16:21:52 -0700 Subject: [PATCH v3 03/12] device-dax: Enable page_mapping() From: Dan Williams To: linux-nvdimm@lists.01.org Cc: hch@lst.de, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, jack@suse.cz Date: Mon, 04 Jun 2018 16:11:55 -0700 Message-ID: <152815391576.39010.14402839848074832654.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152815389835.39010.13253559944508110923.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152815389835.39010.13253559944508110923.stgit@dwillia2-desk3.amr.corp.intel.com> User-Agent: StGit/0.18-2-gc94f MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP In support of enabling memory_failure() handling for device-dax mappings, set the ->mapping association of pages backing device-dax mappings. The rmap implementation requires page_mapping() to return the address_space hosting the vmas that map the page. The ->mapping pointer is never cleared. There is no possibility for the page to become associated with another address_space while the device is enabled. When the device is disabled the 'struct page' array for the device is destroyed / later reinitialized to zero. Signed-off-by: Dan Williams Reviewed-by: Jan Kara --- drivers/dax/device.c | 55 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 686de08e120b..7ec246549721 100644 --- a/drivers/dax/device.c +++ b/drivers/dax/device.c @@ -245,13 +245,12 @@ __weak phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, } static vm_fault_t __dev_dax_pte_fault(struct dev_dax *dev_dax, - struct vm_fault *vmf) + struct vm_fault *vmf, pfn_t *pfn) { struct vm_area_struct *vma = vmf->vma; struct device *dev = &dev_dax->dev; struct dax_region *dax_region; phys_addr_t phys; - pfn_t pfn; unsigned int fault_size = PAGE_SIZE; if (check_vma(dev_dax, vma, __func__)) @@ -273,13 +272,13 @@ static vm_fault_t __dev_dax_pte_fault(struct dev_dax *dev_dax, return VM_FAULT_SIGBUS; } - pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); + *pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); - return vmf_insert_mixed(vma, vmf->address, pfn); + return vmf_insert_mixed(vma, vmf->address, *pfn); } static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax, - struct vm_fault *vmf) + struct vm_fault *vmf, pfn_t *pfn) { unsigned long pmd_addr = vmf->address & PMD_MASK; struct vm_area_struct *vma = vmf->vma; @@ -287,7 +286,6 @@ static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax, struct dax_region *dax_region; phys_addr_t phys; pgoff_t pgoff; - pfn_t pfn; unsigned int fault_size = PMD_SIZE; if (check_vma(dev_dax, vma, __func__)) @@ -322,15 +320,15 @@ static vm_fault_t __dev_dax_pmd_fault(struct dev_dax *dev_dax, return VM_FAULT_SIGBUS; } - pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); + *pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); - return vmf_insert_pfn_pmd(vma, vmf->address, vmf->pmd, pfn, + return vmf_insert_pfn_pmd(vma, vmf->address, vmf->pmd, *pfn, vmf->flags & FAULT_FLAG_WRITE); } #ifdef CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, - struct vm_fault *vmf) + struct vm_fault *vmf, pfn_t *pfn) { unsigned long pud_addr = vmf->address & PUD_MASK; struct vm_area_struct *vma = vmf->vma; @@ -338,7 +336,6 @@ static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, struct dax_region *dax_region; phys_addr_t phys; pgoff_t pgoff; - pfn_t pfn; unsigned int fault_size = PUD_SIZE; @@ -374,14 +371,14 @@ static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, return VM_FAULT_SIGBUS; } - pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); + *pfn = phys_to_pfn_t(phys, dax_region->pfn_flags); - return vmf_insert_pfn_pud(vma, vmf->address, vmf->pud, pfn, + return vmf_insert_pfn_pud(vma, vmf->address, vmf->pud, *pfn, vmf->flags & FAULT_FLAG_WRITE); } #else static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, - struct vm_fault *vmf) + struct vm_fault *vmf, pfn_t *pfn) { return VM_FAULT_FALLBACK; } @@ -390,9 +387,11 @@ static vm_fault_t __dev_dax_pud_fault(struct dev_dax *dev_dax, static vm_fault_t dev_dax_huge_fault(struct vm_fault *vmf, enum page_entry_size pe_size) { - int rc, id; struct vm_area_struct *vma = vmf->vma; struct file *filp = vma->vm_file; + unsigned long fault_size; + int rc, id; + pfn_t pfn; struct dev_dax *dev_dax = filp->private_data; dev_dbg(&dev_dax->dev, "%s: %s (%#lx - %#lx) size = %d\n", current->comm, @@ -402,17 +401,39 @@ static vm_fault_t dev_dax_huge_fault(struct vm_fault *vmf, id = dax_read_lock(); switch (pe_size) { case PE_SIZE_PTE: - rc = __dev_dax_pte_fault(dev_dax, vmf); + fault_size = PAGE_SIZE; + rc = __dev_dax_pte_fault(dev_dax, vmf, &pfn); break; case PE_SIZE_PMD: - rc = __dev_dax_pmd_fault(dev_dax, vmf); + fault_size = PMD_SIZE; + rc = __dev_dax_pmd_fault(dev_dax, vmf, &pfn); break; case PE_SIZE_PUD: - rc = __dev_dax_pud_fault(dev_dax, vmf); + fault_size = PUD_SIZE; + rc = __dev_dax_pud_fault(dev_dax, vmf, &pfn); break; default: rc = VM_FAULT_SIGBUS; } + + if (rc == VM_FAULT_NOPAGE) { + unsigned long i; + + /* + * In the device-dax case the only possibility for a + * VM_FAULT_NOPAGE result is when device-dax capacity is + * mapped. No need to consider the zero page, or racing + * conflicting mappings. + */ + for (i = 0; i < fault_size / PAGE_SIZE; i++) { + struct page *page; + + page = pfn_to_page(pfn_t_to_pfn(pfn) + i); + if (page->mapping) + continue; + page->mapping = filp->f_mapping; + } + } dax_read_unlock(id); return rc;