From patchwork Mon Jun 4 23:12:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10447497 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 81082600CA for ; Mon, 4 Jun 2018 23:22:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7391729222 for ; Mon, 4 Jun 2018 23:22:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 682E129227; Mon, 4 Jun 2018 23:22:44 +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 0DE0B29222 for ; Mon, 4 Jun 2018 23:22:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A502E6B0276; Mon, 4 Jun 2018 19:22:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9FD236B0277; Mon, 4 Jun 2018 19:22:42 -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 8EC5F6B0278; Mon, 4 Jun 2018 19:22:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f70.google.com (mail-pg0-f70.google.com [74.125.83.70]) by kanga.kvack.org (Postfix) with ESMTP id 4E95B6B0276 for ; Mon, 4 Jun 2018 19:22:42 -0400 (EDT) Received: by mail-pg0-f70.google.com with SMTP id w1-v6so99111pgr.7 for ; Mon, 04 Jun 2018 16:22:42 -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=K8k4SYH98hilSRydbPWtHWROJGh5r0yG0jd1QI24ymKcsdwLBRe3gxwinJRqfzazhf UMdAkmMntx/wKfliHkLL12qdYhta3lwbH04L34mN3mVwrz3rNNrDVDRbPvMZU6VdZmO2 1dcfbJ1vq5OV0p7NiKRinAMwpoyBEGE7Os2wIrW9vPwwg5l7bmcMDeAXbPIa2EVDfKCI Tbr79lNCsTkNKSA2c8RnbwjZdZ9NODENn8vVfiW7/SjZBdNNyH81B48WESCoP2pXYye0 cj1FPSeKp7v85BwLouKTWnApxrUMkl4BGg6Lr8BnsaqsJjqV/u0UDM35sYcDn47XqVyc XM/Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.100 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: ALKqPwc8i7rY4hJS4QldSiaGFN5vq/9mioyEOtGNYnDkgEJeTLRazvRi Bqv5JUo3nDRVp3gbONX0DCREpMfeCUVGhC+CyZiFgt8QJ0zrH3dC6g4tlTX1mGDZ5ra/bRlD+Vs C94bGqlEuhNga1ShKSrGk4W9sytTYO/vGbUOX3WpukcG9GLCLDmFBh07ghoF2dbaVxw== X-Received: by 2002:a17:902:bd8f:: with SMTP id q15-v6mr23167399pls.161.1528154562008; Mon, 04 Jun 2018 16:22:42 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIgEEilqRyJ9VnN8GRRgrmUGyClK02RVTI0q0gAhv8Ly5QRizE6dzaWcNvdkiQ6F3iRrBLt X-Received: by 2002:a17:902:bd8f:: with SMTP id q15-v6mr23167355pls.161.1528154561187; Mon, 04 Jun 2018 16:22:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528154561; cv=none; d=google.com; s=arc-20160816; b=KsX8i9g6n6bsYp9SbVUubfwBS6wbAsaURHuA92WWKNPa89u+1fOwj59QfcVuKWsdBA LT2XcJq3RJ3z9HI+F/axx8NYjYJ9Do1mWnGk4RjSI6Xn+c4wmhw9bs9YlkjoVUS3oAc0 IdM5ffUZpQGS8Z8/64sOn6m8kTB7ORDnpmIkZC869KA0RlcRdfCugfNG0g87Y+0MfopM 2qEi9lY6RP0uDTF63M0zkOKoqj+rViYo7mlYLMxNWzmJDogwlj7p2Z3IIYUpj95GgzvR /oBFzT7pvg+m3qggEKlz+xKipvq85E9dsGqtdlzOyawEKydPJTvIjgsEqlCvfn1DLwQZ p+ng== 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=xTEfQ1yLVGNQC50m5Pc44s0D/ggbtC4PC00AkXyEdFiFacNsSsTUgf6Sogh/SUYeaO YgxD6vstRjVS995StuMaKnKQaKj098/GLl9jt28YkIB9Sdkg0SUy3Pj+nYO4WGynvPX7 IZtZDpY+//9/dvZX7qf825FSWLXsi8qTwsjtRZ0mP3eW5UWIBhs5Oq+8ZMSQ4OfdAa1d +0n9aJV514vok6VWjdSSbzHfeRYMzCBhdAV/3BHELaqcFq0297ThQZHd5KegzdtZlOeU JyrOfl+iw5RZh7LHnGQVKEjFKc0fbK6rFFp8qXvl8WR8N6DEJa7AbON8SNh6D4uSiuDm B7uQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.100 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga07.intel.com (mga07.intel.com. [134.134.136.100]) by mx.google.com with ESMTPS id i88-v6si20450019pfa.219.2018.06.04.16.22.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Jun 2018 16:22:41 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.100 as permitted sender) client-ip=134.134.136.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 134.134.136.100 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 fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2018 16:22:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,477,1520924400"; d="scan'208";a="54730924" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by FMSMGA003.fm.intel.com with ESMTP; 04 Jun 2018 16:22:40 -0700 Subject: [PATCH v3 12/12] 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: Mon, 04 Jun 2018 16:12:43 -0700 Message-ID: <152815396335.39010.17157370539429298762.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 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__ */