From patchwork Tue May 22 14:39:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10418761 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 2C49F60224 for ; Tue, 22 May 2018 14:49:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A06628D05 for ; Tue, 22 May 2018 14:49:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0D1E328D13; Tue, 22 May 2018 14:49:48 +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 86EFC28D05 for ; Tue, 22 May 2018 14:49:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21F3A6B0007; Tue, 22 May 2018 10:49:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 1A5C86B0008; Tue, 22 May 2018 10:49:46 -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 0BD606B000A; Tue, 22 May 2018 10:49:46 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f69.google.com (mail-pg0-f69.google.com [74.125.83.69]) by kanga.kvack.org (Postfix) with ESMTP id BEF296B0007 for ; Tue, 22 May 2018 10:49:45 -0400 (EDT) Received: by mail-pg0-f69.google.com with SMTP id t11-v6so5600800pgn.9 for ; Tue, 22 May 2018 07:49:45 -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=eZ5EdGRN7Vcg1J7GthE51fHZqL3iWBHfe6Gmxo9pLYQ=; b=OF+yLkKSJ9cBcl6qrqHmNDrkfkfhrQzss5wg41pHx+faF54jit1641Rs8xl0VHWqXb H4JkLYBE596o/XF2SyB4HPefeItCaM+4hnc0JkulrAZMxQmnniJarhKph03GVIt4WdaM eT4GMw1hwreNaaQe66AVJ8JshWldL2xAb0C8fjYVGZUWsImY8nyhj7iVLdnO/t0/QzRk sGW3tfwEMDuxnDmBLxh4XcMldFiol/oS4le6gxEd9M1VSzpwQ64IIHu8njRl3PJHceab /JAdkTM6Oy6TprlpI5tdEq8d8LxAyxxg/VR7TCO+ITZJbXx3RLVdEfG3DzMenrj/oC+E Xcsg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.20 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: ALKqPwd1pIXr4cynyXU+ClFeTxuffD6gxZCOht5PWIwq99ecaYDKw64Y SmgjRhHIOCDdiEJjaOTqFcrM1P9Qn09+vIUXwoARaHCKrlDbvlEQSJlgAxdxQiI0laVTrj43QuA FN5eDhgZx6ImNhfs9WgF1zRntYvBs/X3IpJ2MR/Bnhzk6FoCdKi5nAPfs3CcJVxBHew== X-Received: by 2002:a17:902:9344:: with SMTP id g4-v6mr25388615plp.10.1527000585474; Tue, 22 May 2018 07:49:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpktSl72+bKNEFTerADOKa1CDk2jH0vktouoo0I7CPqA0JKkG637hE9g2FIe+Ype/Vkk2or X-Received: by 2002:a17:902:9344:: with SMTP id g4-v6mr25388579plp.10.1527000584764; Tue, 22 May 2018 07:49:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527000584; cv=none; d=google.com; s=arc-20160816; b=DXqHU+6xo/Iz9RkdFfDJsE/VIWxDox5yWbKp176PRTgHnRUO8+fKfLlj6tkzCNSyik ZbsTq9o/sPpMIIykIOxl0V+iH+EgPLO6o+6OxCSPkiKR2Svytl9rrn+/+Xl67qInL0Os NMst6eVdKocSsdtyx8j7nH8njVD0UQ8/2cOZFeYf8tcn6UuTXnXZIVmvjTtTuw5b8F4H x+JWiqOozDWATSmss+m4W5//mFDVJYCOhlX5+zQZ94DkNwhcMwVRaCSiG/G8mM5BOMLA x8djahcnREmn6ViKFpYJzOov5IFLYI7qPEniLZuEgFouJ+RPosS/fB2XSWDGXTX5Nr5l IW6w== 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=eZ5EdGRN7Vcg1J7GthE51fHZqL3iWBHfe6Gmxo9pLYQ=; b=ygcMNd55iyCKzmdV+qp9ZtD6cxq7dzGF+HRNsNTgZ9mFQ0XvrxYVufBsBTQ0+R0weP z8Gj3+rfhWZFKFSADsBd2c+7vJvddvoI6MbpolrwAy5OfNttS6KkiqbAkqWSNwzyiTJl rttuTmceUPDPn3um2vgqi+mZbBdiWBEZ+tWrokwRmvjeq+Pnqrdz49s74wmdr6oYTRaI hShYSZSux2RklLKpmxeDXT5jQfn9lgcHHM119EDSjqqvcI/35ZBPO2yPIPux0BNMGpBg 63k/GbCqnELWncaLoCvCK+H4dxBKLICsEFZsphUbjKBPVWjrXRFXHE0Wt5aj5Pk3yHHy JRaA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga02.intel.com (mga02.intel.com. [134.134.136.20]) by mx.google.com with ESMTPS id bc11-v6si16081889plb.544.2018.05.22.07.49.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 07:49:44 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.20 as permitted sender) client-ip=134.134.136.20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.20 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 orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2018 07:49:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,430,1520924400"; d="scan'208";a="43851438" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga006.jf.intel.com with ESMTP; 22 May 2018 07:49:44 -0700 Subject: [PATCH 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, tony.luck@intel.com Date: Tue, 22 May 2018 07:39:47 -0700 Message-ID: <152699998750.24093.5270058390086110946.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152699997165.24093.12194490924829406111.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152699997165.24093.12194490924829406111.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 | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/drivers/dax/device.c b/drivers/dax/device.c index 686de08e120b..8e986478d48d 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,33 @@ 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; + + 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;