From patchwork Mon Jun 4 23:12:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10447491 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 4E73C600CA for ; Mon, 4 Jun 2018 23:22:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 40F5B29222 for ; Mon, 4 Jun 2018 23:22:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 35A2929227; Mon, 4 Jun 2018 23:22:39 +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 95B6F29222 for ; Mon, 4 Jun 2018 23:22:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51D206B0273; Mon, 4 Jun 2018 19:22:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4F2606B0274; Mon, 4 Jun 2018 19:22:37 -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 3BE4C6B0275; Mon, 4 Jun 2018 19:22:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f71.google.com (mail-pg0-f71.google.com [74.125.83.71]) by kanga.kvack.org (Postfix) with ESMTP id EDE796B0273 for ; Mon, 4 Jun 2018 19:22:36 -0400 (EDT) Received: by mail-pg0-f71.google.com with SMTP id b7-v6so101705pgv.5 for ; Mon, 04 Jun 2018 16:22:36 -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=ug3yQgYWdf5Dp4JmuShKeOMkRa0Ni6WNriuK+gTnV9M=; b=KemHTuvPxXUOA8rz4UXhxiYtNuBGuT8ntqePHxIU1SCiHvhduPqQ7WrqsjGNRP+YS7 NDUy8VqONh9uHhq0hlJsdSXYNWT9YAwfvjKhPBr4NPpCY5fzVZpkHsya6oAk8XyF+RsL B9BQ80stIJROYAvFD6cgwzo2oPxu1bmufqmKF1HrLWVhzN3NOjuH/C7i4rMxBcmQlh0H ZTeNU/JGmx0Hl6lPKwxzPVa4iYEWEoksY1ubv/WFxLeKEizjFWbW1/hPwHca0pjvaM/9 /54hq30JF/MtTur8EyB41ZZr9Ufna0rJi6v4ziRBAeuZzJd9/d7LX9BmVitOxM5urY0A qW1g== 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: APt69E16W1bagwbvs1e+AX5CfkkY0/0T7ZgLe4NYoHvTyz5Ox7djBR6I s7VUA8bp7n14lkrKHAZUTTLMjjnuWkEZp13XOitP6/I0Vd9Z/ddTv5ljiUC+EBxT1hZAyz3ixBm HBxfDo1TOiSiElvWHN/qd3QFFQ1HjUhkx4sd15OQozTJP0ZSE03c0hig6e4Awdzo2Uw== X-Received: by 2002:a63:842:: with SMTP id 63-v6mr9493539pgi.406.1528154556624; Mon, 04 Jun 2018 16:22:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJeN9NnT39FHEhtztL4EMnHzm/ct7rQ/sp/SjoatMaW4OWkMhf63tXKbw+lDyj406m6iGWU X-Received: by 2002:a63:842:: with SMTP id 63-v6mr9493511pgi.406.1528154555680; Mon, 04 Jun 2018 16:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528154555; cv=none; d=google.com; s=arc-20160816; b=em+kAUsns1V339Z/b6QfnsEU3GIFlUJF37RU+wFdOdVUZskt9+Za22yOkrP4aTvKw+ BAn2IdjELioJkcLSiwJDgNXcaF/F9i8c5yRLL3bdFP+R6YoA16KdO3aVoYwoQ4vOqdak HvoSz/2lSYSWawYFGO/Yn2xtopkhPw5MRR1zN4SQltimpRUcX6KX6qiRRMLrsUCZfka5 tYUAmeiVPknCAVwTIarrUNWeg4sdhgxDFK1t8JrcAjUgtssfflyouePEqqTNH77HMM/x RMNebaBGmLESgQUovueHTGBZ8wV9uxMnspsmKeDm7xUIGzYz3upHB/qbmx6smSFsUSrz NYdg== 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=ug3yQgYWdf5Dp4JmuShKeOMkRa0Ni6WNriuK+gTnV9M=; b=hnE235eV2sNyodiQm/Rbv8oTOzxqOafkeJrzrDsJSbanz8AxlVN4v6lL+8MlZDeWa4 RPFqwRhOZwt2M51SI3ewsW+gaD2iiNgklrwgimiusKFwHhqn8vyxBXCN3uW9QD9nwjvG cc9iJGnle1v3o8RnO7wcWshdXZC1ge2dC6TMv0loaHMdjc9p3HYq5ba3T3hP4jLBZIso nVtfTw02eS3NF2T3kzglVwxvZHNknlLUZN4PtrNtezA/eeqmWrqgFtbc7mK7Tk8atqf/ 9ita356t3HgMj3Mp924R5M6UVpfprKK9gJIao33oBBAhSDeOisQKYeoXHAsWeSxhmX5S x+HQ== 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 e9-v6si6300333pff.30.2018.06.04.16.22.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 16:22:35 -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 fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2018 16:22:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,477,1520924400"; d="scan'208";a="61263549" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga001.fm.intel.com with ESMTP; 04 Jun 2018 16:22:34 -0700 Subject: [PATCH v3 11/12] 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, jack@suse.cz Date: Mon, 04 Jun 2018 16:12:37 -0700 Message-ID: <152815395775.39010.9355109660470832490.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 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 --- include/linux/mm.h | 1 mm/memory-failure.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 1ac1f06a4be6..566c972e03e7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2669,6 +2669,7 @@ enum mf_action_page_type { MF_MSG_TRUNCATED_LRU, MF_MSG_BUDDY, MF_MSG_BUDDY_2ND, + MF_MSG_DAX, MF_MSG_UNKNOWN, }; diff --git a/mm/memory-failure.c b/mm/memory-failure.c index b6efb78ba49b..de0bc897d6e7 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -531,6 +532,7 @@ static const char * const action_page_types[] = { [MF_MSG_TRUNCATED_LRU] = "already truncated LRU page", [MF_MSG_BUDDY] = "free buddy page", [MF_MSG_BUDDY_2ND] = "free buddy page (2nd try)", + [MF_MSG_DAX] = "dax page", [MF_MSG_UNKNOWN] = "unknown page", }; @@ -1132,6 +1134,144 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags) return res; } +static unsigned long dax_mapping_size(struct address_space *mapping, + struct page *page) +{ + pgoff_t pgoff = page_to_pgoff(page); + struct vm_area_struct *vma; + unsigned long size = 0; + + i_mmap_lock_read(mapping); + xa_lock_irq(&mapping->i_pages); + /* validate that @page is still linked to @mapping */ + if (page->mapping != mapping) { + xa_unlock_irq(&mapping->i_pages); + i_mmap_unlock_read(mapping); + return 0; + } + 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; + } + } + xa_unlock_irq(&mapping->i_pages); + 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; + struct address_space *mapping; + unsigned long size; + LIST_HEAD(tokill); + int rc = -EBUSY; + loff_t start; + + /* + * Prevent the inode from being freed while we are interrogating + * the address_space, typically this would be handled by + * lock_page(), but dax pages do not use the page lock. + */ + rcu_read_lock(); + mapping = page->mapping; + if (!mapping) { + rcu_read_unlock(); + goto out; + } + if (!igrab(mapping->host)) { + mapping = NULL; + rcu_read_unlock(); + goto out; + } + rcu_read_unlock(); + + 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: + break; + } + + /* + * If the page is not mapped in userspace then report it as + * unhandled. + */ + size = dax_mapping_size(mapping, 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(mapping, 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), + mapping, page, flags); + rc = 0; +out: + if (mapping) + iput(mapping->host); + put_dev_pagemap(pgmap); + action_result(pfn, MF_MSG_DAX, rc ? MF_FAILED : MF_RECOVERED); + return rc; +} + /** * memory_failure - Handle memory failure of a page. * @pfn: Page Number of the corrupted page @@ -1154,6 +1294,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; @@ -1166,6 +1307,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);