Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp211457imm; Fri, 13 Jul 2018 22:03:16 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdJssmQ6gRn11E6SXV6/2wV+uzx0BTn1GCPOVuhnaAoplmTSylYaT6KCE8EDZRNWyfoAbVE X-Received: by 2002:a62:e106:: with SMTP id q6-v6mr9928957pfh.75.1531544596634; Fri, 13 Jul 2018 22:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531544596; cv=none; d=google.com; s=arc-20160816; b=Qbo8nTh/o6T0CvTdmo++hsLeRAqiXTvBu1YwwwuzsQrOzD9EVvGencSZYBrDRq/idn WRJpo8QVZDIz0nrWb9wP8f+9iNTSf8y30+cJcyAQMx+TKugMvOcRQxhfhzYZOA6w3hUf UPYP2fuG6k3zywXY/Qbzj8ZUXMY/Kfl0HpcBXeFgZNZMZXiFPJiwyDHEewEDAvTEj342 Q/0ymQ3wPrbca8lai+LNcGcNrR72oa3kGcUURRjt22YmQzvuy9p0syx3zWvxjtz0VIkf INTdynx1U8lHXVUHZzDKJgIMnc1cmWR6l4/Zk110O4pDT6dblLuGehWv+3lm4MZsQoPH 33Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:arc-authentication-results; bh=xVWC9ICL0OiJz0L80JF3RcNjbYQUg9dS8+Bvpg0rZuA=; b=wmn0YJiQgfiDuYB7MrrYMyMZCK79mNioImy6fn839jKmTAq5kANh+Zvzz4VBBZrKsV UH6vpGgm3rGCypbRAoQM/OZLEelqye2i/Al+foC6ReoIMZN9GWKsLXOC9D2nIUeO1EgI /IuK8UQruGNSpkdbTiPdmnFPWL+RIQEhhsIpfPAjaQ8P8SgRfnkHu9Tg0wSgwfaNU+jK umOJpq9rlLCAGFU6G/kEG2Df6y4X8Y0b80AXYC4FbzXxvS4TJgEb659j91ralvZ+o0Mh sXkUufvljVClhNHR44gETkpRCkjOylpDYwKw7kVDp5U8/mae/pa2/wkHeB9i8Ee14Etl gRWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g87-v6si18473946pfg.225.2018.07.13.22.03.01; Fri, 13 Jul 2018 22:03:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727580AbeGNFSU (ORCPT + 99 others); Sat, 14 Jul 2018 01:18:20 -0400 Received: from mga09.intel.com ([134.134.136.24]:7998 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725986AbeGNFSU (ORCPT ); Sat, 14 Jul 2018 01:18:20 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jul 2018 22:00:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,350,1526367600"; d="scan'208";a="66888740" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by fmsmga002.fm.intel.com with ESMTP; 13 Jul 2018 22:00:35 -0700 Subject: [PATCH v6 13/13] libnvdimm, pmem: Restore page attributes when clearing errors From: Dan Williams To: linux-nvdimm@lists.01.org Cc: hch@lst.de, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Fri, 13 Jul 2018 21:50:37 -0700 Message-ID: <153154383784.34503.6412760695151314711.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use clear_mce_nospec() to restore WB mode for the kernel linear mapping of a pmem page that was marked 'HWPoison'. A page with 'HWPoison' set has also been marked UC in PAT (page attribute table) via set_mce_nospec() to prevent speculative retrievals of poison. The 'HWPoison' flag is only cleared when overwriting an entire page. Signed-off-by: Dan Williams --- drivers/nvdimm/pmem.c | 26 ++++++++++++++++++++++++++ drivers/nvdimm/pmem.h | 13 +++++++++++++ 2 files changed, 39 insertions(+) diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index 68940356cad3..bdaaa7ed49fd 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,30 @@ static struct nd_region *to_region(struct pmem_device *pmem) return to_nd_region(to_dev(pmem)->parent); } +static void hwpoison_clear(struct pmem_device *pmem, + phys_addr_t phys, unsigned int len) +{ + unsigned long pfn_start, pfn_end, pfn; + + /* only pmem in the linear map supports HWPoison */ + if (is_vmalloc_addr(pmem->virt_addr)) + return; + + pfn_start = PHYS_PFN(phys); + pfn_end = pfn_start + PHYS_PFN(len); + for (pfn = pfn_start; pfn < pfn_end; pfn++) { + struct page *page = pfn_to_page(pfn); + + /* + * Note, no need to hold a get_dev_pagemap() reference + * here since we're in the driver I/O path and + * outstanding I/O requests pin the dev_pagemap. + */ + if (test_and_clear_pmem_poison(page)) + clear_mce_nospec(pfn); + } +} + static blk_status_t pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset, unsigned int len) { @@ -65,6 +90,7 @@ static blk_status_t pmem_clear_poison(struct pmem_device *pmem, if (cleared < len) rc = BLK_STS_IOERR; if (cleared > 0 && cleared / 512) { + hwpoison_clear(pmem, pmem->phys_addr + offset, cleared); cleared /= 512; dev_dbg(dev, "%#llx clear %ld sector%s\n", (unsigned long long) sector, cleared, diff --git a/drivers/nvdimm/pmem.h b/drivers/nvdimm/pmem.h index a64ebc78b5df..59cfe13ea8a8 100644 --- a/drivers/nvdimm/pmem.h +++ b/drivers/nvdimm/pmem.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ #ifndef __NVDIMM_PMEM_H__ #define __NVDIMM_PMEM_H__ +#include #include #include #include @@ -27,4 +28,16 @@ struct pmem_device { long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff, long nr_pages, void **kaddr, pfn_t *pfn); + +#ifdef CONFIG_MEMORY_FAILURE +static inline bool test_and_clear_pmem_poison(struct page *page) +{ + return TestClearPageHWPoison(page); +} +#else +static inline bool test_and_clear_pmem_poison(struct page *page) +{ + return false; +} +#endif #endif /* __NVDIMM_PMEM_H__ */