From patchwork Fri Jun 8 23:51:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Williams X-Patchwork-Id: 10455395 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 4962B6032D for ; Sat, 9 Jun 2018 00:01:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 453EA294D1 for ; Sat, 9 Jun 2018 00:01:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3931E2955E; Sat, 9 Jun 2018 00:01:26 +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 C59D62955D for ; Sat, 9 Jun 2018 00:01:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 368616B0277; Fri, 8 Jun 2018 20:01:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2EFB86B0278; Fri, 8 Jun 2018 20:01:24 -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 16B286B0279; Fri, 8 Jun 2018 20:01:24 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f70.google.com (mail-pl0-f70.google.com [209.85.160.70]) by kanga.kvack.org (Postfix) with ESMTP id C032D6B0277 for ; Fri, 8 Jun 2018 20:01:23 -0400 (EDT) Received: by mail-pl0-f70.google.com with SMTP id b31-v6so8182135plb.5 for ; Fri, 08 Jun 2018 17:01:23 -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=C/i5XVydZMWut98CBdEcoXflMKiocwMVnEFjOw/WWnulP94bQBUq8aaKFNHVg6G6IZ dv6yXUilzBagDZiuhP+Zu3VzA3h+dRh2wUVRI5bffY7yc3bGHMlA+mavGHRdyyGYWb8n hmCJu9w9RXwr69f/3lyO5pSh4QsuN/yTYKh2jlyxWqa3ZR7jQkVyf6hLeQypBk6UuZDE 0du52CC9F9fhV1ulBHzGBjb18K3MKTBuy9FEx26317oMuWrVymtW3PuQcd6XTCsrEwpa krSI9SNv4mME+aokACCVKT/8TKlAGxLnVLIaln5S3tgCVynZILkj1ihGJFe2pSThfTgJ ZZ3Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 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: APt69E0ZWaBmLGJZIBGI/PkinZdzJ0GpmXVot3kQxd1s5WfuH5oOK8qJ +nbugyJ/tkkNGNZeLrgKKTNoeuHF4/JcfLcbsBzhW0/tHe1ojiCHy8hBUraD0PD0AFgb0FV7cz1 srv5YLlKh96xpLXQ8pY//sGFtMJ/dYoN/MoFfMX/1Yyuj83bUo4mguvywgOOzX/29sQ== X-Received: by 2002:a63:3807:: with SMTP id f7-v6mr6920543pga.446.1528502483458; Fri, 08 Jun 2018 17:01:23 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIliPVtzwQaZGovj/6NaJGN4n+F5ZcJTjLpODelv1bwj4s/HCCp6G3NY8ydNYkEruZ2gtwC X-Received: by 2002:a63:3807:: with SMTP id f7-v6mr6920495pga.446.1528502482648; Fri, 08 Jun 2018 17:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528502482; cv=none; d=google.com; s=arc-20160816; b=OeWrvMT8/IeWKEV4G33nW8SZazE9wCCdjArfj2Sj5dJtdC0fIv1/xFT2xcaj2fQaIa 0WlZBW/SAUaMlxBZGDBQiqScxSqm0Qc9gTDbovm3H6ez7zvFnOLKxzfCxirEoAPAcafh abPI0Eg1VgREs0qjAsYI0aKGyTZnTRzQ2YX82TXdaIoiiS/fxUEQbl9eWc3esi5nBqKb Eg6oiDvzxTd9mCKUjparE7aQ+KhMttWdPKnBPEjk9ZgY1Vgk1ivNPCnzaSoh/Sr9W6Qz kHMZreJHTwQyr8ptGiF3kt/mqhQ5zIOrmRvdN6hsYVmIXn/Bm7yIlTRKOfy6RD/ThIvT jylQ== 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=Pa8rMcy+YI+Lj7oqYqwRyV+NwUEjNIwezH+TVGW/Mfv0WFXx+ikrBIi4GHHEGXUmQ/ uht5GamisgwC0kVbKs7qj4oziIKJaaFK/Q98deIGcyQbRQI65y7lY825RR8X0IhwJa7G aVuAloOFYD/ZDi4e4ezWn+gnikiSsO3lX4gV946e1xFsYua7BLLfd17Rr/wFlnvammtV w4azBpZye4rs2JgJ+sJwr5dyX/mgyCwpkcgnUrEXdBeo9kOA+kutRpgVZR+2a/syKkyH 5KUqeTrQX6ezRGXHXxF4YjFBiNiStR7Br5QPMaVio8T4x6J0Y8GFJ5eGZ/J2CgVyr0OE JUzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 as permitted sender) smtp.mailfrom=dan.j.williams@intel.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from mga14.intel.com (mga14.intel.com. [192.55.52.115]) by mx.google.com with ESMTPS id c7-v6si19469918pgt.220.2018.06.08.17.01.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 Jun 2018 17:01:22 -0700 (PDT) Received-SPF: pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 as permitted sender) client-ip=192.55.52.115; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dan.j.williams@intel.com designates 192.55.52.115 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 orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Jun 2018 17:01:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,492,1520924400"; d="scan'208";a="231117894" Received: from dwillia2-desk3.jf.intel.com (HELO dwillia2-desk3.amr.corp.intel.com) ([10.54.39.16]) by orsmga005.jf.intel.com with ESMTP; 08 Jun 2018 17:01:21 -0700 Subject: [PATCH v4 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: Fri, 08 Jun 2018 16:51:24 -0700 Message-ID: <152850188462.38390.4202931981794505577.stgit@dwillia2-desk3.amr.corp.intel.com> In-Reply-To: <152850182079.38390.8280340535691965744.stgit@dwillia2-desk3.amr.corp.intel.com> References: <152850182079.38390.8280340535691965744.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__ */