From patchwork Tue May 22 14:40:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10418803 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 8C0EC6053B for ; Tue, 22 May 2018 14:50:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7124928E3E for ; Tue, 22 May 2018 14:50:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F6E228F21; Tue, 22 May 2018 14:50: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 94C6028E3E for ; Tue, 22 May 2018 14:50:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 861186B0269; Tue, 22 May 2018 10:50:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 80D206B026A; Tue, 22 May 2018 10:50:23 -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 6FD186B026B; Tue, 22 May 2018 10:50:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f200.google.com (mail-pf0-f200.google.com [209.85.192.200]) by kanga.kvack.org (Postfix) with ESMTP id 30C896B0269 for ; Tue, 22 May 2018 10:50:23 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id c187-v6so11337383pfa.20 for ; Tue, 22 May 2018 07:50:23 -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=haJsmjMs/SLT6mtyLxNuRo/MdAj/Xufc1CThvPcRpCk=; b=bNbFs+ykeu9V+IehBGbQA/V0+nTmxkeNGSTP9HcyPRtKHD6fcouZICgeLGi+5Ei/RX 2NtCj22NRaOZWbuDIMiZs5Hu/gRiz6vJSBOJPKgFSHEQDJlk6JiCmnJYdWI3PV9xpNNk MEcVDO0j3f5BeU/xqhxnARWK4mDX26F6nPhJei6DDrgQn6hX72+TCXR1W1QXnVJkqOkP bsVdd0fZW/uWbM3W8zzXO3h1VwgtaoVvBwQEi0FjrGOy4zl/gkptfFdpyL3Zo6nKPVkU b4iCDPsx7XIeWawIvzsp76N41IFsMQ4EvKUSGtszOJccm7K8Dt7YSc1GqGvOLpsiA3YR 193g== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.31 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: ALKqPwf4s0dFnllWz3XrMB8HodVYW5Jrv2WhB83dU9MdnrIWNt8bHdYi VoBegP9YQqCbZRVYdl1DQva56KIQAS7E11YKGGWjSg0ARtYJhC1bSr59G9OpeydGX3xaFIAgLQi YmGiWjyC5bUrOm7pqfkL8VCh57U3SqHLkP3xJXUNFKqA0A4uEenMDyGDJcbjqFz8mUg== X-Received: by 2002:a63:7405:: with SMTP id p5-v6mr19164655pgc.289.1527000622794; Tue, 22 May 2018 07:50:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo2+ja5GzsybdwwJ7nWv1iHcKvcWwRpi6+Kx6vtEe/Pxiu4q+hpX+rh70Kz4HOjua61D6FE X-Received: by 2002:a63:7405:: with SMTP id p5-v6mr19164615pgc.289.1527000621851; Tue, 22 May 2018 07:50:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527000621; cv=none; d=google.com; s=arc-20160816; b=dOiCf2f8ltc+37mppiDS+MVh8VfrzF54XWaDMwBIO92845LhmFrqedjREUyR21ICUR 78GfYk2/qUnccDnFIBw2roLVJsnt1O4AHAMAf6drtfBbgEsz0yKNLItfNLXslCc88HHr 82LOR79mBOcEQB01JrL31KYAvCaNbOzQPKswKGxy0lz5XHlyRKCr4nhwTvPGmUXnhT3Q 1vlRqHxhs6dAyTdajcR/zxwYOsTnAPbqsX0OflFAuIN+AzTDIFG38iLaPWyMEaJRLcK5 kr2wjtbFbdRODDDRkUS/N7+6IdGBaM3iT2Mle+kKENVZi/XKLTNHiJnfDwrJBKcYyHrz 9mEA== 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=haJsmjMs/SLT6mtyLxNuRo/MdAj/Xufc1CThvPcRpCk=; b=RIfi19kF5UO2oB4YPXHcF/jCKTA6dztyWV3zx4VZd8EhMvHi974WIY5CIotcxa/axm yZaUaHNJK7uLYlh2/B/qIzMX4efdIG1QNuzLtqRqrdil/b9kLmmZxiFZBPGubdozYWPF iuQRbUYfPHj50EofW3SX1Jq9u9OkRGVvkpjROAz+Kx48LjmYNEo/nkaYwxImh+XiedYK p9+AYXudC8+MZKCqHPRi1H/98f8O9AshPrOv6+OYc+31vF7BBCaPnZKY472M1f8a/mNA Lx4R/+p+Ff2F7DHXLdvH0PUqCnFyzNraE0hLDoDDbO5fLFqmPETfm0Y9LKTN+sAkyESB Ksrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.31 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga06.intel.com (mga06.intel.com. [134.134.136.31]) by mx.google.com with ESMTPS id w2-v6si13148437pgs.676.2018.05.22.07.50.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 07:50:21 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.31 as permitted sender) client-ip=134.134.136.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.31 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 orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 May 2018 07:50:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,430,1520924400"; d="scan'208";a="43007708" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga007.jf.intel.com with ESMTP; 22 May 2018 07:50:21 -0700 Subject: [PATCH 10/11] mm, memory_failure: teach memory_failure() about dev_pagemap pages From: Dan Williams To: linux-nvdimm@lists.01.org Cc: Jan Kara , Christoph Hellwig , =?utf-8?b?SsOpcsO0bWU=?= Glisse , Matthew Wilcox , Naoya Horiguchi , Ross Zwisler , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, tony.luck@intel.com Date: Tue, 22 May 2018 07:40:24 -0700 Message-ID: <152700002461.24093.13281217260996107277.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 mce: Uncorrected hardware memory error in user-access at af34214200 {1}[Hardware Error]: It has been corrected by h/w and requires no further action mce: [Hardware Error]: Machine check events logged {1}[Hardware Error]: event severity: corrected Memory failure: 0xaf34214: reserved kernel page still referenced by 1 users [..] Memory failure: 0xaf34214: recovery action for reserved kernel page: Failed mce: Memory error not recovered In contrast to typical memory, dev_pagemap pages may be dax mapped. With dax there is no possibility to map in another page dynamically since dax establishes 1:1 physical address to file offset associations. Also dev_pagemap pages associated with NVDIMM / persistent memory devices can internal remap/repair addresses with poison. While memory_failure() assumes that it can discard typical poisoned pages and keep them unmapped indefinitely, dev_pagemap pages may be returned to service after the error is cleared. Teach memory_failure() to detect and handle MEMORY_DEVICE_HOST dev_pagemap pages that have poison consumed by userspace. Mark the memory as UC instead of unmapping it completely to allow ongoing access via the device driver (nd_pmem). Later, nd_pmem will grow support for marking the page back to WB when the error is cleared. Cc: Jan Kara Cc: Christoph Hellwig Cc: Jérôme Glisse Cc: Matthew Wilcox Cc: Naoya Horiguchi Cc: Ross Zwisler Signed-off-by: Dan Williams --- mm/memory-failure.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 42a193ee14d3..f95036f99a79 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -1112,6 +1113,117 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags) return res; } +static unsigned long dax_mapping_size(struct page *page) +{ + struct address_space *mapping = page->mapping; + pgoff_t pgoff = page_to_pgoff(page); + struct vm_area_struct *vma; + unsigned long size = 0; + + i_mmap_lock_read(mapping); + vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff, pgoff) { + unsigned long address = vma_address(page, vma); + pgd_t *pgd; + p4d_t *p4d; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + pgd = pgd_offset(vma->vm_mm, address); + if (!pgd_present(*pgd)) + continue; + p4d = p4d_offset(pgd, address); + if (!p4d_present(*p4d)) + continue; + pud = pud_offset(p4d, address); + if (!pud_present(*pud)) + continue; + if (pud_devmap(*pud)) { + size = PUD_SIZE; + break; + } + pmd = pmd_offset(pud, address); + if (!pmd_present(*pmd)) + continue; + if (pmd_devmap(*pmd)) { + size = PMD_SIZE; + break; + } + pte = pte_offset_map(pmd, address); + if (!pte_present(*pte)) + continue; + if (pte_devmap(*pte)) { + size = PAGE_SIZE; + break; + } + } + i_mmap_unlock_read(mapping); + return size; +} + +static int memory_failure_dev_pagemap(unsigned long pfn, int flags, + struct dev_pagemap *pgmap) +{ + struct page *page = pfn_to_page(pfn); + const bool unmap_success = true; + unsigned long size; + LIST_HEAD(tokill); + int rc = -EBUSY; + loff_t start; + + lock_page(page); + if (hwpoison_filter(page)) { + rc = 0; + goto out; + } + + switch (pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_PUBLIC: + /* + * TODO: Handle HMM pages which may need coordination + * with device-side memory. + */ + goto out; + default: + if (!page->mapping) + goto out; + break; + } + + /* + * If the page is not mapped in userspace then report it as + * unhandled. + */ + size = dax_mapping_size(page); + if (!size) { + pr_err("Memory failure: %#lx: failed to unmap page\n", pfn); + goto out; + } + + SetPageHWPoison(page); + + /* + * Unlike System-RAM there is no possibility to swap in a + * different physical page at a given virtual address, so all + * userspace consumption of ZONE_DEVICE memory necessitates + * SIGBUS (i.e. MF_MUST_KILL) + */ + flags |= MF_ACTION_REQUIRED | MF_MUST_KILL; + collect_procs(page, &tokill, flags & MF_ACTION_REQUIRED); + + start = (page->index << PAGE_SHIFT) & ~(size - 1); + unmap_mapping_range(page->mapping, start, start + size, 0); + + kill_procs(&tokill, flags & MF_MUST_KILL, !unmap_success, ilog2(size), + pfn, flags); + rc = 0; +out: + unlock_page(page); + put_dev_pagemap(pgmap); + return rc; +} + /** * memory_failure - Handle memory failure of a page. * @pfn: Page Number of the corrupted page @@ -1134,6 +1246,7 @@ int memory_failure(unsigned long pfn, int flags) struct page *p; struct page *hpage; struct page *orig_head; + struct dev_pagemap *pgmap; int res; unsigned long page_flags; @@ -1146,6 +1259,10 @@ int memory_failure(unsigned long pfn, int flags) return -ENXIO; } + pgmap = get_dev_pagemap(pfn, NULL); + if (pgmap) + return memory_failure_dev_pagemap(pfn, flags, pgmap); + p = pfn_to_page(pfn); if (PageHuge(p)) return memory_failure_hugetlb(pfn, flags);