From patchwork Wed Jul 4 21:41:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10507671 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 1E3DB602BC for ; Wed, 4 Jul 2018 21:51:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1472928DAA for ; Wed, 4 Jul 2018 21:51:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07B6728DAF; Wed, 4 Jul 2018 21:51:23 +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 9ADC328DAA for ; Wed, 4 Jul 2018 21:51:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C69B6B0273; Wed, 4 Jul 2018 17:51:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 774F66B0275; Wed, 4 Jul 2018 17:51:21 -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 664516B0276; Wed, 4 Jul 2018 17:51:21 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf0-f198.google.com (mail-pf0-f198.google.com [209.85.192.198]) by kanga.kvack.org (Postfix) with ESMTP id 21ED26B0273 for ; Wed, 4 Jul 2018 17:51:21 -0400 (EDT) Received: by mail-pf0-f198.google.com with SMTP id b17-v6so2051379pff.17 for ; Wed, 04 Jul 2018 14:51:21 -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=H1vP0miwF2Jlt+IzGkwk4JWxb4p4icCe0ihMmsck/xQ=; b=h0spWffFiDo1+JNghXQ14KN1RG8xLe1TWuiLMHzxbLHupjn+IN94ArdGArCizUj1V8 XZT2xPR8g5MoGhm5RC2dwFodFLMatmKMXqFBX8xVOJhNwsBCuLkAN8WEFxtS9jBP0pM6 hmQHjsKZXoG2NEIBN0tA0K3Jn4AURDHeGE0QK9j02+g7gabSCmDXFwAXVdBrKp/zF39h 3sRAvLilHCXLi8ycJSjsJWr3oH6DHrXKmD8p8od3Vj4QeYb0mbVCaf1Vzat6VliBJUi0 90ghdEoOt+DdMSPbhVaTkAfXi4WHA/DIkrnpQ1Mt5Cb94ng8wHH9lKQ9JgT1pkdSod6a qP8Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 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: APt69E2WG2y+fEktEuxSBk85SD6SgygK96Q463B7q8PG2eyBlFagriGQ M1yRtb/3mXBv8x8CgfbBAZexfFjkpubO2sH2oxh7OJXdQgg5gvsz/+pgMZnSZ5daxPOzoCAeNeP C92MCr9KSzmqVg35eeCvhwv1EOyEKY6Oasxk6cVh4DKEszA01coMFTnBmvoIIwEbiVw== X-Received: by 2002:a62:5f81:: with SMTP id t123-v6mr3712706pfb.15.1530741080777; Wed, 04 Jul 2018 14:51:20 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcJa75hpz774I/dXObcv6Zzsh+s+cLAYPpmFAJ2y7+JV+Kw3LeoKTKvvcCUACsVjqioBGKh X-Received: by 2002:a62:5f81:: with SMTP id t123-v6mr3712672pfb.15.1530741079835; Wed, 04 Jul 2018 14:51:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530741079; cv=none; d=google.com; s=arc-20160816; b=x3AkFPmfyu4HOFSi+aqLg953NJPDpl9EJnoxkO595biogsAO7jcPdqkvNwm3wxwp8d VQDCsnaaK+F+vkA06HqkR6fOnazYLMal8g8ww8gNlLCOOGuk9ZZwM3Zz0til2SsoDHUR /4ug8ZLtDvEcMBihsvw4euTUlXJL5s+d6vstmq8fzG0cQNWP7nEGQH/+Nik/UAQ/yctN zV2+aRlEZimZc/enPZuzW3W9r0/GIKj2P34yMkv6arlYWPoJNe4p5OndWFtzAuu8gmL3 A2ja+Sjs+T2pI/vHud/tD0oAHXl3KmxkULK1RHjYXanv60nRfL1cMwcKtKr2yUbeCS6I L9rw== 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=H1vP0miwF2Jlt+IzGkwk4JWxb4p4icCe0ihMmsck/xQ=; b=eu0dO7QXlFU53STh/oImSF2mATerKQ8YvpeJa0BPbn8b/RP5ipfKVsBwWMRetVewM0 qd/sACiUji8l1CN8b057qWFZkdGtuIsgml6B+ZzwAjKw5IeMC/pQTjvyhGyGbD4KzRlq 0C6b/kZW2yGPOvTAObnQk5hEOJUSioBoynbyyHgNu6riZPNiieUWEuvl24dsB7XexMK0 QKQQYBub2aWTE1SMmZIh9QA1W6qSyD4anmV/s6UImCWq+RF3WL/vztm5D6KIiIKey05j AaD/u85i2/TyDNIJE7WupSG691TwbNv9Ch+IBmw26lQnyROCq2ZjgP4aY/ENug/53Hxi dpWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga01.intel.com (mga01.intel.com. [192.55.52.88]) by mx.google.com with ESMTPS id b2-v6si4322526plz.118.2018.07.04.14.51.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 14:51:19 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 as permitted sender) client-ip=192.55.52.88; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.88 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 orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jul 2018 14:51:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,309,1526367600"; d="scan'208";a="55172418" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga006.jf.intel.com with ESMTP; 04 Jul 2018 14:51:19 -0700 Subject: [PATCH v5 11/11] libnvdimm, pmem: Restore page attributes when clearing errors From: Dan Williams To: linux-nvdimm@lists.01.org Cc: hch@lst.de, hch@lst.de, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, jack@suse.cz, ross.zwisler@linux.intel.com Date: Wed, 04 Jul 2018 14:41:21 -0700 Message-ID: <153074048162.27838.14847952115074744540.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <153074042316.27838.17319837331947007626.stgit@dwillia2-desk3.amr.corp.intel.com> References: <153074042316.27838.17319837331947007626.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 8b1fd7f1a224..55c7a69751d3 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__ */