libnvdimm for 6.5

- DAX fixes and cleanups including a use after free, extra references,
   and device unregistration, and a redundant variable.
 
 - Allow the DAX fault handler to return VM_FAULT_HWPOISON
 
 - A few libnvdimm cleanups such as making some functions and variables
 static where sufficient.
 
 - Add a few missing prototypes for wrapped functions in
 tools/testing/nvdimm
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQT9vPEBxh63bwxRYEEPzq5USduLdgUCZJ6AdAAKCRAPzq5USduL
 dtGnAP9uh+DxVKLnp/Q0977pLZKYVHYU32C/pG3hFnjS5tAp6QEAke/uF+wxcTGr
 EZdnDJuTGt2sAMQsQ34NdDJUzwqQEgw=
 =7l6z
 -----END PGP SIGNATURE-----

Merge tag 'libnvdimm-for-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm

Pull nvdimm and DAX updates from Vishal Verma:
 "This is mostly small cleanups and fixes, with the biggest change being
  the change to the DAX fault handler allowing it to return
  VM_FAULT_HWPOISON.

  Summary:

   - DAX fixes and cleanups including a use after free, extra
     references, and device unregistration, and a redundant variable.

   - Allow the DAX fault handler to return VM_FAULT_HWPOISON

   - A few libnvdimm cleanups such as making some functions and
     variables static where sufficient.

   - Add a few missing prototypes for wrapped functions in
     tools/testing/nvdimm"

* tag 'libnvdimm-for-6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm/nvdimm:
  dax: enable dax fault handler to report VM_FAULT_HWPOISON
  nvdimm: make security_show static
  nvdimm: make nd_class variable static
  dax/kmem: Pass valid argument to memory_group_register_static
  fsdax: remove redundant variable 'error'
  dax: Cleanup extra dax_region references
  dax: Introduce alloc_dev_dax_id()
  dax: Use device_unregister() in unregister_dax_mapping()
  dax: Fix dax_mapping_release() use after free
  tools/testing/nvdimm: Drop empty platform remove function
  libnvdimm: mark 'security_show' static again
  testing: nvdimm: add missing prototypes for wrapped functions
  dax: fix missing-prototype warnings
This commit is contained in:
Linus Torvalds 2023-07-01 08:48:02 -07:00
commit 0a1c979c6b
19 changed files with 116 additions and 78 deletions

View File

@ -446,18 +446,33 @@ static void unregister_dev_dax(void *dev)
put_device(dev); put_device(dev);
} }
static void dax_region_free(struct kref *kref)
{
struct dax_region *dax_region;
dax_region = container_of(kref, struct dax_region, kref);
kfree(dax_region);
}
static void dax_region_put(struct dax_region *dax_region)
{
kref_put(&dax_region->kref, dax_region_free);
}
/* a return value >= 0 indicates this invocation invalidated the id */ /* a return value >= 0 indicates this invocation invalidated the id */
static int __free_dev_dax_id(struct dev_dax *dev_dax) static int __free_dev_dax_id(struct dev_dax *dev_dax)
{ {
struct dax_region *dax_region = dev_dax->region;
struct device *dev = &dev_dax->dev; struct device *dev = &dev_dax->dev;
struct dax_region *dax_region;
int rc = dev_dax->id; int rc = dev_dax->id;
device_lock_assert(dev); device_lock_assert(dev);
if (is_static(dax_region) || dev_dax->id < 0) if (!dev_dax->dyn_id || dev_dax->id < 0)
return -1; return -1;
dax_region = dev_dax->region;
ida_free(&dax_region->ida, dev_dax->id); ida_free(&dax_region->ida, dev_dax->id);
dax_region_put(dax_region);
dev_dax->id = -1; dev_dax->id = -1;
return rc; return rc;
} }
@ -473,6 +488,20 @@ static int free_dev_dax_id(struct dev_dax *dev_dax)
return rc; return rc;
} }
static int alloc_dev_dax_id(struct dev_dax *dev_dax)
{
struct dax_region *dax_region = dev_dax->region;
int id;
id = ida_alloc(&dax_region->ida, GFP_KERNEL);
if (id < 0)
return id;
kref_get(&dax_region->kref);
dev_dax->dyn_id = true;
dev_dax->id = id;
return id;
}
static ssize_t delete_store(struct device *dev, struct device_attribute *attr, static ssize_t delete_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t len) const char *buf, size_t len)
{ {
@ -560,20 +589,6 @@ static const struct attribute_group *dax_region_attribute_groups[] = {
NULL, NULL,
}; };
static void dax_region_free(struct kref *kref)
{
struct dax_region *dax_region;
dax_region = container_of(kref, struct dax_region, kref);
kfree(dax_region);
}
void dax_region_put(struct dax_region *dax_region)
{
kref_put(&dax_region->kref, dax_region_free);
}
EXPORT_SYMBOL_GPL(dax_region_put);
static void dax_region_unregister(void *region) static void dax_region_unregister(void *region)
{ {
struct dax_region *dax_region = region; struct dax_region *dax_region = region;
@ -625,7 +640,6 @@ struct dax_region *alloc_dax_region(struct device *parent, int region_id,
return NULL; return NULL;
} }
kref_get(&dax_region->kref);
if (devm_add_action_or_reset(parent, dax_region_unregister, dax_region)) if (devm_add_action_or_reset(parent, dax_region_unregister, dax_region))
return NULL; return NULL;
return dax_region; return dax_region;
@ -635,10 +649,12 @@ EXPORT_SYMBOL_GPL(alloc_dax_region);
static void dax_mapping_release(struct device *dev) static void dax_mapping_release(struct device *dev)
{ {
struct dax_mapping *mapping = to_dax_mapping(dev); struct dax_mapping *mapping = to_dax_mapping(dev);
struct dev_dax *dev_dax = to_dev_dax(dev->parent); struct device *parent = dev->parent;
struct dev_dax *dev_dax = to_dev_dax(parent);
ida_free(&dev_dax->ida, mapping->id); ida_free(&dev_dax->ida, mapping->id);
kfree(mapping); kfree(mapping);
put_device(parent);
} }
static void unregister_dax_mapping(void *data) static void unregister_dax_mapping(void *data)
@ -655,8 +671,7 @@ static void unregister_dax_mapping(void *data)
dev_dax->ranges[mapping->range_id].mapping = NULL; dev_dax->ranges[mapping->range_id].mapping = NULL;
mapping->range_id = -1; mapping->range_id = -1;
device_del(dev); device_unregister(dev);
put_device(dev);
} }
static struct dev_dax_range *get_dax_range(struct device *dev) static struct dev_dax_range *get_dax_range(struct device *dev)
@ -778,6 +793,7 @@ static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id)
dev = &mapping->dev; dev = &mapping->dev;
device_initialize(dev); device_initialize(dev);
dev->parent = &dev_dax->dev; dev->parent = &dev_dax->dev;
get_device(dev->parent);
dev->type = &dax_mapping_type; dev->type = &dax_mapping_type;
dev_set_name(dev, "mapping%d", mapping->id); dev_set_name(dev, "mapping%d", mapping->id);
rc = device_add(dev); rc = device_add(dev);
@ -1295,12 +1311,10 @@ static const struct attribute_group *dax_attribute_groups[] = {
static void dev_dax_release(struct device *dev) static void dev_dax_release(struct device *dev)
{ {
struct dev_dax *dev_dax = to_dev_dax(dev); struct dev_dax *dev_dax = to_dev_dax(dev);
struct dax_region *dax_region = dev_dax->region;
struct dax_device *dax_dev = dev_dax->dax_dev; struct dax_device *dax_dev = dev_dax->dax_dev;
put_dax(dax_dev); put_dax(dax_dev);
free_dev_dax_id(dev_dax); free_dev_dax_id(dev_dax);
dax_region_put(dax_region);
kfree(dev_dax->pgmap); kfree(dev_dax->pgmap);
kfree(dev_dax); kfree(dev_dax);
} }
@ -1324,6 +1338,7 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data)
if (!dev_dax) if (!dev_dax)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
dev_dax->region = dax_region;
if (is_static(dax_region)) { if (is_static(dax_region)) {
if (dev_WARN_ONCE(parent, data->id < 0, if (dev_WARN_ONCE(parent, data->id < 0,
"dynamic id specified to static region\n")) { "dynamic id specified to static region\n")) {
@ -1339,13 +1354,11 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data)
goto err_id; goto err_id;
} }
rc = ida_alloc(&dax_region->ida, GFP_KERNEL); rc = alloc_dev_dax_id(dev_dax);
if (rc < 0) if (rc < 0)
goto err_id; goto err_id;
dev_dax->id = rc;
} }
dev_dax->region = dax_region;
dev = &dev_dax->dev; dev = &dev_dax->dev;
device_initialize(dev); device_initialize(dev);
dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id); dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id);
@ -1386,7 +1399,6 @@ struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data)
dev_dax->target_node = dax_region->target_node; dev_dax->target_node = dax_region->target_node;
dev_dax->align = dax_region->align; dev_dax->align = dax_region->align;
ida_init(&dev_dax->ida); ida_init(&dev_dax->ida);
kref_get(&dax_region->kref);
inode = dax_inode(dax_dev); inode = dax_inode(dax_dev);
dev->devt = inode->i_rdev; dev->devt = inode->i_rdev;

View File

@ -9,7 +9,6 @@ struct dev_dax;
struct resource; struct resource;
struct dax_device; struct dax_device;
struct dax_region; struct dax_region;
void dax_region_put(struct dax_region *dax_region);
/* dax bus specific ioresource flags */ /* dax bus specific ioresource flags */
#define IORESOURCE_DAX_STATIC BIT(0) #define IORESOURCE_DAX_STATIC BIT(0)
@ -49,13 +48,6 @@ void dax_driver_unregister(struct dax_device_driver *dax_drv);
void kill_dev_dax(struct dev_dax *dev_dax); void kill_dev_dax(struct dev_dax *dev_dax);
bool static_dev_dax(struct dev_dax *dev_dax); bool static_dev_dax(struct dev_dax *dev_dax);
/*
* While run_dax() is potentially a generic operation that could be
* defined in include/linux/dax.h we don't want to grow any users
* outside of drivers/dax/
*/
void run_dax(struct dax_device *dax_dev);
#define MODULE_ALIAS_DAX_DEVICE(type) \ #define MODULE_ALIAS_DAX_DEVICE(type) \
MODULE_ALIAS("dax:t" __stringify(type) "*") MODULE_ALIAS("dax:t" __stringify(type) "*")
#define DAX_DEVICE_MODALIAS_FMT "dax:t%d" #define DAX_DEVICE_MODALIAS_FMT "dax:t%d"

View File

@ -13,7 +13,6 @@ static int cxl_dax_region_probe(struct device *dev)
struct cxl_region *cxlr = cxlr_dax->cxlr; struct cxl_region *cxlr = cxlr_dax->cxlr;
struct dax_region *dax_region; struct dax_region *dax_region;
struct dev_dax_data data; struct dev_dax_data data;
struct dev_dax *dev_dax;
if (nid == NUMA_NO_NODE) if (nid == NUMA_NO_NODE)
nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start); nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start);
@ -28,13 +27,8 @@ static int cxl_dax_region_probe(struct device *dev)
.id = -1, .id = -1,
.size = range_len(&cxlr_dax->hpa_range), .size = range_len(&cxlr_dax->hpa_range),
}; };
dev_dax = devm_create_dev_dax(&data);
if (IS_ERR(dev_dax))
return PTR_ERR(dev_dax);
/* child dev_dax instances now own the lifetime of the dax_region */ return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data));
dax_region_put(dax_region);
return 0;
} }
static struct cxl_driver cxl_dax_region_driver = { static struct cxl_driver cxl_dax_region_driver = {

View File

@ -52,7 +52,8 @@ struct dax_mapping {
* @region - parent region * @region - parent region
* @dax_dev - core dax functionality * @dax_dev - core dax functionality
* @target_node: effective numa node if dev_dax memory range is onlined * @target_node: effective numa node if dev_dax memory range is onlined
* @id: ida allocated id * @dyn_id: is this a dynamic or statically created instance
* @id: ida allocated id when the dax_region is not static
* @ida: mapping id allocator * @ida: mapping id allocator
* @dev - device core * @dev - device core
* @pgmap - pgmap for memmap setup / lifetime (driver owned) * @pgmap - pgmap for memmap setup / lifetime (driver owned)
@ -64,6 +65,7 @@ struct dev_dax {
struct dax_device *dax_dev; struct dax_device *dax_dev;
unsigned int align; unsigned int align;
int target_node; int target_node;
bool dyn_id;
int id; int id;
struct ida ida; struct ida ida;
struct device dev; struct device dev;
@ -76,6 +78,13 @@ struct dev_dax {
} *ranges; } *ranges;
}; };
/*
* While run_dax() is potentially a generic operation that could be
* defined in include/linux/dax.h we don't want to grow any users
* outside of drivers/dax/
*/
void run_dax(struct dax_device *dax_dev);
static inline struct dev_dax *to_dev_dax(struct device *dev) static inline struct dev_dax *to_dev_dax(struct device *dev)
{ {
return container_of(dev, struct dev_dax, dev); return container_of(dev, struct dev_dax, dev);

View File

@ -396,7 +396,7 @@ static void dev_dax_kill(void *dev_dax)
kill_dev_dax(dev_dax); kill_dev_dax(dev_dax);
} }
int dev_dax_probe(struct dev_dax *dev_dax) static int dev_dax_probe(struct dev_dax *dev_dax)
{ {
struct dax_device *dax_dev = dev_dax->dax_dev; struct dax_device *dax_dev = dev_dax->dax_dev;
struct device *dev = &dev_dax->dev; struct device *dev = &dev_dax->dev;
@ -471,7 +471,6 @@ int dev_dax_probe(struct dev_dax *dev_dax)
run_dax(dax_dev); run_dax(dax_dev);
return devm_add_action_or_reset(dev, dev_dax_kill, dev_dax); return devm_add_action_or_reset(dev, dev_dax_kill, dev_dax);
} }
EXPORT_SYMBOL_GPL(dev_dax_probe);
static struct dax_device_driver device_dax_driver = { static struct dax_device_driver device_dax_driver = {
.probe = dev_dax_probe, .probe = dev_dax_probe,

View File

@ -16,7 +16,6 @@ static int dax_hmem_probe(struct platform_device *pdev)
struct dax_region *dax_region; struct dax_region *dax_region;
struct memregion_info *mri; struct memregion_info *mri;
struct dev_dax_data data; struct dev_dax_data data;
struct dev_dax *dev_dax;
/* /*
* @region_idle == true indicates that an administrative agent * @region_idle == true indicates that an administrative agent
@ -38,13 +37,8 @@ static int dax_hmem_probe(struct platform_device *pdev)
.id = -1, .id = -1,
.size = region_idle ? 0 : range_len(&mri->range), .size = region_idle ? 0 : range_len(&mri->range),
}; };
dev_dax = devm_create_dev_dax(&data);
if (IS_ERR(dev_dax))
return PTR_ERR(dev_dax);
/* child dev_dax instances now own the lifetime of the dax_region */ return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data));
dax_region_put(dax_region);
return 0;
} }
static struct platform_driver dax_hmem_driver = { static struct platform_driver dax_hmem_driver = {

View File

@ -99,7 +99,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax)
if (!data->res_name) if (!data->res_name)
goto err_res_name; goto err_res_name;
rc = memory_group_register_static(numa_node, total_len); rc = memory_group_register_static(numa_node, PFN_UP(total_len));
if (rc < 0) if (rc < 0)
goto err_reg_mgid; goto err_reg_mgid;
data->mgid = rc; data->mgid = rc;

View File

@ -13,7 +13,6 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev)
int rc, id, region_id; int rc, id, region_id;
resource_size_t offset; resource_size_t offset;
struct nd_pfn_sb *pfn_sb; struct nd_pfn_sb *pfn_sb;
struct dev_dax *dev_dax;
struct dev_dax_data data; struct dev_dax_data data;
struct nd_namespace_io *nsio; struct nd_namespace_io *nsio;
struct dax_region *dax_region; struct dax_region *dax_region;
@ -65,12 +64,8 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev)
.pgmap = &pgmap, .pgmap = &pgmap,
.size = range_len(&range), .size = range_len(&range),
}; };
dev_dax = devm_create_dev_dax(&data);
/* child dev_dax instances now own the lifetime of the dax_region */ return devm_create_dev_dax(&data);
dax_region_put(dax_region);
return dev_dax;
} }
static int dax_pmem_probe(struct device *dev) static int dax_pmem_probe(struct device *dev)

View File

@ -203,6 +203,8 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff, int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
size_t nr_pages) size_t nr_pages)
{ {
int ret;
if (!dax_alive(dax_dev)) if (!dax_alive(dax_dev))
return -ENXIO; return -ENXIO;
/* /*
@ -213,7 +215,8 @@ int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
if (nr_pages != 1) if (nr_pages != 1)
return -EIO; return -EIO;
return dax_dev->ops->zero_page_range(dax_dev, pgoff, nr_pages); ret = dax_dev->ops->zero_page_range(dax_dev, pgoff, nr_pages);
return dax_mem2blk_err(ret);
} }
EXPORT_SYMBOL_GPL(dax_zero_page_range); EXPORT_SYMBOL_GPL(dax_zero_page_range);

View File

@ -25,7 +25,7 @@
int nvdimm_major; int nvdimm_major;
static int nvdimm_bus_major; static int nvdimm_bus_major;
struct class *nd_class; static struct class *nd_class;
static DEFINE_IDA(nd_ida); static DEFINE_IDA(nd_ida);
static int to_nd_device_type(const struct device *dev) static int to_nd_device_type(const struct device *dev)

View File

@ -349,8 +349,8 @@ static ssize_t available_slots_show(struct device *dev,
} }
static DEVICE_ATTR_RO(available_slots); static DEVICE_ATTR_RO(available_slots);
ssize_t security_show(struct device *dev, static ssize_t security_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct nvdimm *nvdimm = to_nvdimm(dev); struct nvdimm *nvdimm = to_nvdimm(dev);

View File

@ -260,7 +260,7 @@ __weak long __pmem_direct_access(struct pmem_device *pmem, pgoff_t pgoff,
long actual_nr; long actual_nr;
if (mode != DAX_RECOVERY_WRITE) if (mode != DAX_RECOVERY_WRITE)
return -EIO; return -EHWPOISON;
/* /*
* Set the recovery stride is set to kernel page size because * Set the recovery stride is set to kernel page size because

View File

@ -54,7 +54,8 @@ static int dcssblk_dax_zero_page_range(struct dax_device *dax_dev,
rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS, rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS,
&kaddr, NULL); &kaddr, NULL);
if (rc < 0) if (rc < 0)
return rc; return dax_mem2blk_err(rc);
memset(kaddr, 0, nr_pages << PAGE_SHIFT); memset(kaddr, 0, nr_pages << PAGE_SHIFT);
dax_flush(dax_dev, kaddr, nr_pages << PAGE_SHIFT); dax_flush(dax_dev, kaddr, nr_pages << PAGE_SHIFT);
return 0; return 0;

View File

@ -1148,7 +1148,7 @@ static int dax_iomap_copy_around(loff_t pos, uint64_t length, size_t align_size,
if (!zero_edge) { if (!zero_edge) {
ret = dax_iomap_direct_access(srcmap, pos, size, &saddr, NULL); ret = dax_iomap_direct_access(srcmap, pos, size, &saddr, NULL);
if (ret) if (ret)
return ret; return dax_mem2blk_err(ret);
} }
if (copy_all) { if (copy_all) {
@ -1310,7 +1310,7 @@ static s64 dax_unshare_iter(struct iomap_iter *iter)
out_unlock: out_unlock:
dax_read_unlock(id); dax_read_unlock(id);
return ret; return dax_mem2blk_err(ret);
} }
int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len, int dax_file_unshare(struct inode *inode, loff_t pos, loff_t len,
@ -1342,7 +1342,8 @@ static int dax_memzero(struct iomap_iter *iter, loff_t pos, size_t size)
ret = dax_direct_access(iomap->dax_dev, pgoff, 1, DAX_ACCESS, &kaddr, ret = dax_direct_access(iomap->dax_dev, pgoff, 1, DAX_ACCESS, &kaddr,
NULL); NULL);
if (ret < 0) if (ret < 0)
return ret; return dax_mem2blk_err(ret);
memset(kaddr + offset, 0, size); memset(kaddr + offset, 0, size);
if (iomap->flags & IOMAP_F_SHARED) if (iomap->flags & IOMAP_F_SHARED)
ret = dax_iomap_copy_around(pos, size, PAGE_SIZE, srcmap, ret = dax_iomap_copy_around(pos, size, PAGE_SIZE, srcmap,
@ -1498,7 +1499,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size), map_len = dax_direct_access(dax_dev, pgoff, PHYS_PFN(size),
DAX_ACCESS, &kaddr, NULL); DAX_ACCESS, &kaddr, NULL);
if (map_len == -EIO && iov_iter_rw(iter) == WRITE) { if (map_len == -EHWPOISON && iov_iter_rw(iter) == WRITE) {
map_len = dax_direct_access(dax_dev, pgoff, map_len = dax_direct_access(dax_dev, pgoff,
PHYS_PFN(size), DAX_RECOVERY_WRITE, PHYS_PFN(size), DAX_RECOVERY_WRITE,
&kaddr, NULL); &kaddr, NULL);
@ -1506,7 +1507,7 @@ static loff_t dax_iomap_iter(const struct iomap_iter *iomi,
recovery = true; recovery = true;
} }
if (map_len < 0) { if (map_len < 0) {
ret = map_len; ret = dax_mem2blk_err(map_len);
break; break;
} }
@ -1830,7 +1831,6 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
vm_fault_t ret = VM_FAULT_FALLBACK; vm_fault_t ret = VM_FAULT_FALLBACK;
pgoff_t max_pgoff; pgoff_t max_pgoff;
void *entry; void *entry;
int error;
if (vmf->flags & FAULT_FLAG_WRITE) if (vmf->flags & FAULT_FLAG_WRITE)
iter.flags |= IOMAP_WRITE; iter.flags |= IOMAP_WRITE;
@ -1877,7 +1877,7 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
} }
iter.pos = (loff_t)xas.xa_index << PAGE_SHIFT; iter.pos = (loff_t)xas.xa_index << PAGE_SHIFT;
while ((error = iomap_iter(&iter, ops)) > 0) { while (iomap_iter(&iter, ops) > 0) {
if (iomap_length(&iter) < PMD_SIZE) if (iomap_length(&iter) < PMD_SIZE)
continue; /* actually breaks out of the loop */ continue; /* actually breaks out of the loop */

View File

@ -775,7 +775,8 @@ static int virtio_fs_zero_page_range(struct dax_device *dax_dev,
rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS, &kaddr, rc = dax_direct_access(dax_dev, pgoff, nr_pages, DAX_ACCESS, &kaddr,
NULL); NULL);
if (rc < 0) if (rc < 0)
return rc; return dax_mem2blk_err(rc);
memset(kaddr, 0, nr_pages << PAGE_SHIFT); memset(kaddr, 0, nr_pages << PAGE_SHIFT);
dax_flush(dax_dev, kaddr, nr_pages << PAGE_SHIFT); dax_flush(dax_dev, kaddr, nr_pages << PAGE_SHIFT);
return 0; return 0;

View File

@ -261,6 +261,19 @@ static inline bool dax_mapping(struct address_space *mapping)
return mapping->host && IS_DAX(mapping->host); return mapping->host && IS_DAX(mapping->host);
} }
/*
* Due to dax's memory and block duo personalities, hwpoison reporting
* takes into consideration which personality is presently visible.
* When dax acts like a block device, such as in block IO, an encounter of
* dax hwpoison is reported as -EIO.
* When dax acts like memory, such as in page fault, a detection of hwpoison
* is reported as -EHWPOISON which leads to VM_FAULT_HWPOISON.
*/
static inline int dax_mem2blk_err(int err)
{
return (err == -EHWPOISON) ? -EIO : err;
}
#ifdef CONFIG_DEV_DAX_HMEM_DEVICES #ifdef CONFIG_DEV_DAX_HMEM_DEVICES
void hmem_register_resource(int target_nid, struct resource *r); void hmem_register_resource(int target_nid, struct resource *r);
#else #else

View File

@ -3379,6 +3379,8 @@ static inline vm_fault_t vmf_error(int err)
{ {
if (err == -ENOMEM) if (err == -ENOMEM)
return VM_FAULT_OOM; return VM_FAULT_OOM;
else if (err == -EHWPOISON)
return VM_FAULT_HWPOISON;
return VM_FAULT_SIGBUS; return VM_FAULT_SIGBUS;
} }

View File

@ -3240,11 +3240,6 @@ static int nfit_test_probe(struct platform_device *pdev)
return 0; return 0;
} }
static int nfit_test_remove(struct platform_device *pdev)
{
return 0;
}
static void nfit_test_release(struct device *dev) static void nfit_test_release(struct device *dev)
{ {
struct nfit_test *nfit_test = to_nfit_test(dev); struct nfit_test *nfit_test = to_nfit_test(dev);
@ -3259,7 +3254,6 @@ static const struct platform_device_id nfit_test_id[] = {
static struct platform_driver nfit_test_driver = { static struct platform_driver nfit_test_driver = {
.probe = nfit_test_probe, .probe = nfit_test_probe,
.remove = nfit_test_remove,
.driver = { .driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
}, },

View File

@ -207,7 +207,36 @@ typedef struct nfit_test_resource *(*nfit_test_lookup_fn)(resource_size_t);
typedef union acpi_object *(*nfit_test_evaluate_dsm_fn)(acpi_handle handle, typedef union acpi_object *(*nfit_test_evaluate_dsm_fn)(acpi_handle handle,
const guid_t *guid, u64 rev, u64 func, const guid_t *guid, u64 rev, u64 func,
union acpi_object *argv4); union acpi_object *argv4);
void __iomem *__wrap_devm_ioremap(struct device *dev,
resource_size_t offset, unsigned long size);
void *__wrap_devm_memremap(struct device *dev, resource_size_t offset,
size_t size, unsigned long flags);
void *__wrap_devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap);
pfn_t __wrap_phys_to_pfn_t(phys_addr_t addr, unsigned long flags);
void *__wrap_memremap(resource_size_t offset, size_t size,
unsigned long flags);
void __wrap_devm_memunmap(struct device *dev, void *addr);
void __iomem *__wrap_ioremap(resource_size_t offset, unsigned long size);
void __iomem *__wrap_ioremap_wc(resource_size_t offset, unsigned long size);
void __wrap_iounmap(volatile void __iomem *addr); void __wrap_iounmap(volatile void __iomem *addr);
void __wrap_memunmap(void *addr);
struct resource *__wrap___request_region(struct resource *parent,
resource_size_t start, resource_size_t n, const char *name,
int flags);
int __wrap_insert_resource(struct resource *parent, struct resource *res);
int __wrap_remove_resource(struct resource *res);
struct resource *__wrap___devm_request_region(struct device *dev,
struct resource *parent, resource_size_t start,
resource_size_t n, const char *name);
void __wrap___release_region(struct resource *parent, resource_size_t start,
resource_size_t n);
void __wrap___devm_release_region(struct device *dev, struct resource *parent,
resource_size_t start, resource_size_t n);
acpi_status __wrap_acpi_evaluate_object(acpi_handle handle, acpi_string path,
struct acpi_object_list *p, struct acpi_buffer *buf);
union acpi_object * __wrap_acpi_evaluate_dsm(acpi_handle handle, const guid_t *guid,
u64 rev, u64 func, union acpi_object *argv4);
void nfit_test_setup(nfit_test_lookup_fn lookup, void nfit_test_setup(nfit_test_lookup_fn lookup,
nfit_test_evaluate_dsm_fn evaluate); nfit_test_evaluate_dsm_fn evaluate);
void nfit_test_teardown(void); void nfit_test_teardown(void);