From patchwork Sat Jul 14 04:50:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10524525 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 3F67C601C2 for ; Sat, 14 Jul 2018 05:00:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F9C3294E8 for ; Sat, 14 Jul 2018 05:00:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 242F92959F; Sat, 14 Jul 2018 05:00:28 +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 756E629571 for ; Sat, 14 Jul 2018 05:00:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EBEB6B026F; Sat, 14 Jul 2018 01:00:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7720F6B0270; Sat, 14 Jul 2018 01:00:26 -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 5C5AC6B0271; Sat, 14 Jul 2018 01:00:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f199.google.com (mail-pf0-f199.google.com [209.85.192.199]) by kanga.kvack.org (Postfix) with ESMTP id 1554C6B026F for ; Sat, 14 Jul 2018 01:00:26 -0400 (EDT) Received: by mail-pf0-f199.google.com with SMTP id g20-v6so21917714pfi.2 for ; Fri, 13 Jul 2018 22:00:26 -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=v/+JbUTpvUTVmeyc3h0ZNtNjZIygpTTqO1Nqh3CKR2Q=; b=tq1RJsMl612Hkm9UR5CUKbfaoqc1ofVapF/4QNmxKXOoXmppoXyrE+QlhkGHLEvF4l 6Mq9G7s5xJqlyzPzSa5qktHHW94DAYpnrfyuqgAMJ/TbrsxxNrKExXZw2wqmfMa/tTA0 UQzGuUZV1E/9Xjp7Rb0yFg9ffxMAWjwaFR2bvF88GFJdCTdgB1qGCz8TesNBx02TL7IX lwkL+lJLNFgSjXpBafoP0LdMmhSG/mcYD8R5boDu9A/bYbTiNrP5S2b4JVVb3w+y+Dah EgYRw9/haEMRtTnWoRMRHZ1t3TZCoyZ9Y/7wW0zGlAj/3tjMvio1yKf/CweAyAyjF68C cDFA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 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: AOUpUlGSsrq1t7qvCD1woxL2uyoaQ2kC/uzxaCjQWJPpLwLxAuQTbiWH cegI1Z8vXRqH7ygfEYZuJmnRKrBTlCuzPYKgrxiCMuRgYy2Ja5KZHlhlomJfT5vz5oUFQtLPVDb oed6hqddvz4SurL/u2dAN6LDjnoBq6Sgqrh0waNBMl4HwCmfSeNkjB2VppR2VEhmTkQ== X-Received: by 2002:a63:7c18:: with SMTP id x24-v6mr8525077pgc.311.1531544425717; Fri, 13 Jul 2018 22:00:25 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcyih4CT93D2k6suIZyKXtSukY1iQ3pknxUnhgTwI3eEvppGi0UxSBAQmCqjwXzuOgFZUfY X-Received: by 2002:a63:7c18:: with SMTP id x24-v6mr8525040pgc.311.1531544424800; Fri, 13 Jul 2018 22:00:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531544424; cv=none; d=google.com; s=arc-20160816; b=qT2Xx70Hyj/On+L+B4X5XcjG1lglkc4qbzXhGtSCfGIlJDgU0aoj5yhWx0xoqfCD7q ZFTM++N2132UwQyi7ql19btI1PFanVZJk1s4BU+ajGV6hbz/lx0MWnMkz8uxgwbKVf9G vSLZ7Oj3uMdOkDHDaCYDLqrRCD3TIKUwevo9Xjfz49luFCMOP3O19wWz6VYTW0BdSSUD uWwcVzPRi4jMC8yG/xqpJmAzvV2YSsG59kpW97NphJOAREtGKqwndvk2ZYg/TUBa0WiN N+qraHRuOEPyX3IS+v6f+kkms7FZkJk6z+AiatchnEifwTgGC6li7GUgKkw13Y5aypNy CE0A== 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=v/+JbUTpvUTVmeyc3h0ZNtNjZIygpTTqO1Nqh3CKR2Q=; b=tP+QL2J0Pa6NrPFBh6YU1enLI3d78mpaIIYzEkcoL6f6fjiMcdo6ujARSGqVLge80U AlYuelrHeU3l6WX1JhkK+UeatxVc7c5lEIREr7m25HdupoN8zXDDSM3Hj818YXMle1hp L3NTkNk7CMqj6UyUy/pw0eOTozhEJuj2U+nivkdogh6UA5+ATOOkP3qsHzpUE3SEMk/t ecCJVzJzCJT3OB5doFONDan2Ggom/7CiIKf6ahliUArRZRLVr4LUk0indsNqKH9TYsK7 vBYPOMc5abJ9wHfALaydc8vmrUEBn3y8T7OsZ9Uynii2cs0ezscJzY9WzJ1uu7sZZZhe MCog== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga18.intel.com (mga18.intel.com. [134.134.136.126]) by mx.google.com with ESMTPS id x62-v6si29065199pfd.124.2018.07.13.22.00.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 Jul 2018 22:00:24 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 as permitted sender) client-ip=134.134.136.126; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.126 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 orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jul 2018 22:00:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,350,1526367600"; d="scan'208";a="56445042" 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; 13 Jul 2018 22:00:19 -0700 Subject: [PATCH v6 10/13] 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-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Fri, 13 Jul 2018 21:50:21 -0700 Message-ID: <153154382187.34503.3838107575957710423.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153154376846.34503.15480221419473501643.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153154376846.34503.15480221419473501643.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 | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 124 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index a0fbb9ffe380..374e5e9284f7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2725,6 +2725,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 8a81680d00dd..effaa7c7a1a4 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include "internal.h" @@ -263,6 +264,40 @@ void shake_page(struct page *p, int access) } EXPORT_SYMBOL_GPL(shake_page); +static unsigned long dev_pagemap_mapping_size(struct page *page, + struct vm_area_struct *vma) +{ + 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)) + return 0; + p4d = p4d_offset(pgd, address); + if (!p4d_present(*p4d)) + return 0; + pud = pud_offset(p4d, address); + if (!pud_present(*pud)) + return 0; + if (pud_devmap(*pud)) + return PUD_SIZE; + pmd = pmd_offset(pud, address); + if (!pmd_present(*pmd)) + return 0; + if (pmd_devmap(*pmd)) + return PMD_SIZE; + pte = pte_offset_map(pmd, address); + if (!pte_present(*pte)) + return 0; + if (pte_devmap(*pte)) + return PAGE_SIZE; + return 0; +} + /* * Failure handling: if we can't find or can't kill a process there's * not much we can do. We just print a message and ignore otherwise. @@ -292,7 +327,10 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, } tk->addr = page_address_in_vma(p, vma); tk->addr_valid = 1; - tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT; + if (is_zone_device_page(p)) + tk->size_shift = ilog2(dev_pagemap_mapping_size(p, vma)); + else + tk->size_shift = compound_order(compound_head(p)) + PAGE_SHIFT; /* * In theory we don't have to kill when the page was @@ -300,7 +338,7 @@ static void add_to_kill(struct task_struct *tsk, struct page *p, * likely very rare kill anyways just out of paranoia, but use * a SIGKILL because the error is not contained anymore. */ - if (tk->addr == -EFAULT) { + if (tk->addr == -EFAULT || tk->size_shift == 0) { pr_info("Memory failure: Unable to find user space address %lx in %s\n", page_to_pfn(p), tsk->comm); tk->addr_valid = 0; @@ -514,6 +552,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", }; @@ -1111,6 +1150,83 @@ static int memory_failure_hugetlb(unsigned long pfn, int flags) return res; } +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 = 0; + struct to_kill *tk; + 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. This + * also prevents changes to the mapping of this pfn until + * poison signaling is complete. + */ + if (!dax_lock_mapping_entry(page)) + goto out; + + if (hwpoison_filter(page)) { + rc = 0; + goto unlock; + } + + switch (pgmap->type) { + case MEMORY_DEVICE_PRIVATE: + case MEMORY_DEVICE_PUBLIC: + /* + * TODO: Handle HMM pages which may need coordination + * with device-side memory. + */ + goto unlock; + default: + break; + } + + /* + * Use this flag as an indication that the dax page has been + * remapped UC to prevent speculative consumption of poison. + */ + 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); + + list_for_each_entry(tk, &tokill, nd) + if (tk->size_shift) + size = max(size, 1UL << tk->size_shift); + if (size) { + /* + * Unmap the largest mapping to avoid breaking up + * device-dax mappings which are constant size. The + * actual size of the mapping being torn down is + * communicated in siginfo, see kill_proc() + */ + 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, pfn, flags); + rc = 0; +unlock: + dax_unlock_mapping_entry(page); +out: + /* drop pgmap ref acquired in caller */ + 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 @@ -1133,6 +1249,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; @@ -1145,6 +1262,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);