Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c953cc98 authored by Dan Williams's avatar Dan Williams Committed by Dave Jiang
Browse files

libnvdimm, pmem: Restore page attributes when clearing errors



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: default avatarDan Williams <dan.j.williams@intel.com>
Signed-off-by: default avatarDave Jiang <dave.jiang@intel.com>
parent 284ce401
Loading
Loading
Loading
Loading
+26 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <linux/hdreg.h>
#include <linux/hdreg.h>
#include <linux/init.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/platform_device.h>
#include <linux/set_memory.h>
#include <linux/module.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/moduleparam.h>
#include <linux/badblocks.h>
#include <linux/badblocks.h>
@@ -51,6 +52,30 @@ static struct nd_region *to_region(struct pmem_device *pmem)
	return to_nd_region(to_dev(pmem)->parent);
	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,
static blk_status_t pmem_clear_poison(struct pmem_device *pmem,
		phys_addr_t offset, unsigned int len)
		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)
	if (cleared < len)
		rc = BLK_STS_IOERR;
		rc = BLK_STS_IOERR;
	if (cleared > 0 && cleared / 512) {
	if (cleared > 0 && cleared / 512) {
		hwpoison_clear(pmem, pmem->phys_addr + offset, cleared);
		cleared /= 512;
		cleared /= 512;
		dev_dbg(dev, "%#llx clear %ld sector%s\n",
		dev_dbg(dev, "%#llx clear %ld sector%s\n",
				(unsigned long long) sector, cleared,
				(unsigned long long) sector, cleared,
+13 −0
Original line number Original line Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __NVDIMM_PMEM_H__
#ifndef __NVDIMM_PMEM_H__
#define __NVDIMM_PMEM_H__
#define __NVDIMM_PMEM_H__
#include <linux/page-flags.h>
#include <linux/badblocks.h>
#include <linux/badblocks.h>
#include <linux/types.h>
#include <linux/types.h>
#include <linux/pfn_t.h>
#include <linux/pfn_t.h>
@@ -27,4 +28,16 @@ struct pmem_device {


long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
		long nr_pages, void **kaddr, pfn_t *pfn);
		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__ */
#endif /* __NVDIMM_PMEM_H__ */