From patchwork Sun Jun 3 05:23:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10445213 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 ACD5A60234 for ; Sun, 3 Jun 2018 05:33:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F47F27E63 for ; Sun, 3 Jun 2018 05:33:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93879289E4; Sun, 3 Jun 2018 05:33:42 +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 3CB5627E63 for ; Sun, 3 Jun 2018 05:33:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A575F6B0274; Sun, 3 Jun 2018 01:33:40 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9E1136B0275; Sun, 3 Jun 2018 01:33:40 -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 883C76B0276; Sun, 3 Jun 2018 01:33:40 -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 451FC6B0274 for ; Sun, 3 Jun 2018 01:33:40 -0400 (EDT) Received: by mail-pf0-f200.google.com with SMTP id p29-v6so5731920pfi.19 for ; Sat, 02 Jun 2018 22:33:40 -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=ezSoGJHO3TYEHP9BvzIp+6lwlyoQ1QFLo2iNQJ+kY58=; b=BATbs9pucnJCEBfSn7jFKuc+Fu6CWMEszdsG7KhOoyh05oW/q+BBWekJB+a7EXGhsI p7Ys1HSGyZ+ZEeWoQjUifwTpDZl8Wn7c8b9m/c5Pm1WASxdopbb4W5qQEQzhoZKqKu3Z zY6lVak0a6ZpEVRUhBKisusyKt4XbjLFvSymA+fS1gPWWJ5YP3/E5HUNuzyDQMvSZHRC Lb3dxizq/AUdR1wjZ878E5a7cxQJrZPZ7AG7TrFe0JJ4i39qqP++Ng+OgSnVNagyhVSK 3wTi4lvUCwXsYMpMwNRxN1T7WzfpXhOogGswQZy++1AFowxhr6G6XddcU9xC0DQM86kE 5uHA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 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: APt69E2AJhxuklAzyH+RaqE9LKxn85LdR4/uG8spOf2ZLNIFw49FZY9/ wMMrvbqDX+SOumghlUg+2I2ABXDLMyi1sb094CLQ/FYdW/jH28eKMagKm9LppMzL60kJMDJ3Nqp h0Jyan3gztZQXuscDdoC/72l8UvBbF8RxnhZZvYTYkKqhmX22idpyg68RO3VSNSKNAg== X-Received: by 2002:a65:4607:: with SMTP id v7-v6mr244791pgq.31.1528004019961; Sat, 02 Jun 2018 22:33:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKL/qO5Kb7dhg7a1CrTJqxrrHtx7JkpdvDMv2/nqUPwRIP1Prsy1KId2qWxMbJWvcnbTzBm3 X-Received: by 2002:a65:4607:: with SMTP id v7-v6mr244769pgq.31.1528004018950; Sat, 02 Jun 2018 22:33:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528004018; cv=none; d=google.com; s=arc-20160816; b=AfkUa/8rJeiP+O2aD1wprREIlcAbKwZLm80hKAcjNU3s8jwXVdDvXBsCX64IYDGava mhgvPW46BXTmfHoWKuSU3hPzbpiLPp+NbKeGlytFL3QznXqWIb+SdV1YPx8w3y564E7l 7jJeja6MPiszm6xSi+y5+AUIeEZKrZ/XBgbPUs7/suSY10EwUTnOYgnNMIHSPOii7hv2 rQ1CkiNpP84n0nH5f7TsONkiPFOFziIhhBKjV9JlXHLA8w5hx7Y3tmKolEi/JCi01C3Z s7BhoQD8htN1yYczncrzqvHFsdmal6SlNSYq3fXgRF6oHgM3YyeBHmqsqEWRadZSaS8O Ikzg== 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=ezSoGJHO3TYEHP9BvzIp+6lwlyoQ1QFLo2iNQJ+kY58=; b=JrTx/JE5fJbv/5jEzNOC+JyohVjlE4rFtyMUtAdaif8qMB4de3lKVAMOuzrVyA09+y mGwRQ/uQqqNjnZGaVMxk9Oy9vkZSXu35KyQ846P2Uv9W5CzOhxjI81qYeIa4eqzsnTo1 t/XVf7oVeTnVA3ZcKiF5Mw+Hk8eWgnhpzGwUPCV29ngATkIF7gwE3uLuE4IAyXEc95To 6OCzJ3xnrLOnLSeFlU4bne9whMWbFT0kGPfFDcZC8EU8S40vXwmLCZ7qfeG0WBuSv33c adjKP3chucIYr+9+HMIdqNd7wQaBvQRPJr6hADZxNIRNF72G0+b2CFjcNYJBJBmwVacT 4L2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga12.intel.com (mga12.intel.com. [192.55.52.136]) by mx.google.com with ESMTPS id c5-v6si7622738pll.529.2018.06.02.22.33.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Jun 2018 22:33:38 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 as permitted sender) client-ip=192.55.52.136; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.136 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 orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jun 2018 22:33:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,472,1520924400"; d="scan'208";a="204879392" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga004.jf.intel.com with ESMTP; 02 Jun 2018 22:33:38 -0700 Subject: [PATCH v2 11/11] libnvdimm, pmem: Restore page attributes when clearing errors From: Dan Williams To: linux-nvdimm@lists.01.org Cc: hch@lst.de, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, jack@suse.cz Date: Sat, 02 Jun 2018 22:23:41 -0700 Message-ID: <152800342137.17112.17757085615233828006.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152800336321.17112.3300876636370683279.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152800336321.17112.3300876636370683279.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 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 9d714926ecf5..04ee1fdee219 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__ */