From patchwork Sun Jun 3 05:22:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10445165 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 B647160234 for ; Sun, 3 Jun 2018 05:33:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A84E2289D6 for ; Sun, 3 Jun 2018 05:33:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D4D528A4D; Sun, 3 Jun 2018 05:33:00 +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 2476428AFC for ; Sun, 3 Jun 2018 05:33:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F3B896B000C; Sun, 3 Jun 2018 01:32:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id EEAB96B000D; Sun, 3 Jun 2018 01:32:58 -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 D8D6A6B000E; Sun, 3 Jun 2018 01:32:58 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id 947906B000C for ; Sun, 3 Jun 2018 01:32:58 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id u21-v6so5036594pfn.0 for ; Sat, 02 Jun 2018 22:32:58 -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=d1R+qo4MajN0juEXD4SBjeWenliNuuMdYwQLoUWy9AA=; b=G5W5PuTyK5/We9ZFnHJxNR1Vx/8mi1sK/0ORfAzcNlR1njCpkRTSn1wYKPt6vPzzVI ChMOIVCvp+yUCOFIcEg/II18HNObIrujrZUWe1knV6gEz6YIOA1Vm8nY3zw5GPI2xnWB M7QsV3/PsbOtb6TFYwQ2wnYkskDAYnFAuvK+SG9XRVfGl8PLktwmGseXjJpA3/GIHJpE VHUwMnsmD+NuQcOot7ucj4VDOOuPKRJkMXP50HBmj1P2lPHNG7riAVaKBdOSsreNmMV3 PIrlytILHavN+BaXjAqyMO/hmS6r23GViCmDX2Xob2UxQlnldXRONiS+SnKxZKOtDUV+ NC3A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 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: ALKqPwdV80Aj2LQBXGnVB7HfIapiHaHDe4gAlCoyLCW+3Qj/6x/wImRH vz0zuaJBY3/L6amQtNQq6MvoS5C/nhCVg8UjUmLkn24YprdBe5623Lq/jsTgK77F+8ejV/xIlcj 4tmDeABaIx8DTnvqqJBtEE01RVXrn7IOtgUYIMGhwo6cLc+PIJMxGR4SFQXHkbjJ2MQ== X-Received: by 2002:a62:3d05:: with SMTP id k5-v6mr16343540pfa.122.1528003978282; Sat, 02 Jun 2018 22:32:58 -0700 (PDT) X-Google-Smtp-Source: ADUXVKK/95/Ia5A0tJ6R3tevxgDnK+WhezTWq+fhUsBSJjzgvAXJkUK6f5grMdd8d+jIOD8nJMps X-Received: by 2002:a62:3d05:: with SMTP id k5-v6mr16343521pfa.122.1528003977403; Sat, 02 Jun 2018 22:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528003977; cv=none; d=google.com; s=arc-20160816; b=SjBci1cwyS1JVbUoAEIjSRBU/NYlVAmG2JcMLviwO9KhwYHFwbbaSNuzrNEnJJdUMa rXVQfi7ZnkS71G7+IML+AJdDbU83FCPOPzzzBTjdOht0b5Fcul4aGlkZYZB7tVlwCxQ9 RQXkxH5KCt/84wiUl7cWfpt9gv+sYtGKVSV8LKSWrHKC0lFmfOdepCFkhf1cYepCBL3U bT55x3+GBfpHlVo2HIR1w6s+m0eqVPzgLS7S8bKt2A68wdjMZ28arDGMVKdqlQl+ALXv AAAWGm4TczuzR/ipJOWpnDWBc2Ylsj/PfNCG54Uml7HhO+NF0X9TvoyJ7MksL5gP3pkm TkiA== 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=d1R+qo4MajN0juEXD4SBjeWenliNuuMdYwQLoUWy9AA=; b=RtJovWoYcWhvxpjMJN/Fe9Q3ufz4+IqdxQ1Rdx5XZdPLjeEXnfZlYlS4MGHhY69Bsk oUQ+t6MD+hIX1kXLBk77PvWjo+v8ICxQNZLA+r7SuBPep0CtdUHFu1vS96h+19AEkcuq W4zC6kyLMUQdnIZ3CwFr5al0m5w/4O3Rfi8fjRAtyY7VIwwj5ed/TsSDNwR/gPah2Rof H0tbONZY73dSKTd+SiLuPbG4ug9GXW8tQyTyiCg46V3Y/XlvIzoCCkhattyzTSa+H+X+ PWrhmEdteFHKPHWUhoMpCkd/oMlmc0LrOZurmS71r5w/6rJQetpRg7VXAzUBwfTO7KXb petg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga17.intel.com (mga17.intel.com. [192.55.52.151]) by mx.google.com with ESMTPS id s7-v6si2282901pfh.303.2018.06.02.22.32.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Jun 2018 22:32:57 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 as permitted sender) client-ip=192.55.52.151; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.151 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 fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jun 2018 22:32:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,472,1520924400"; d="scan'208";a="44247149" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga007.fm.intel.com with ESMTP; 02 Jun 2018 22:32:55 -0700 Subject: [PATCH v2 03/11] 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: Sat, 02 Jun 2018 22:22:59 -0700 Message-ID: <152800337974.17112.9294212013929043806.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152800336321.17112.3300876636370683279.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152800336321.17112.3300876636370683279.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 --- drivers/dax/device.c | 53 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 686de08e120b..f7e926f4ec12 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,9 +371,9 @@ 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 @@ -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;